summaryrefslogtreecommitdiff
path: root/tacc.c
diff options
context:
space:
mode:
Diffstat (limited to 'tacc.c')
-rw-r--r--tacc.c73
1 files changed, 56 insertions, 17 deletions
diff --git a/tacc.c b/tacc.c
index 8069323..f61e2d7 100644
--- a/tacc.c
+++ b/tacc.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <syslog.h>
#include <errno.h>
-#include <utmp.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -34,6 +33,12 @@
#include "config.h"
#endif
+#if defined(HAVE_PUTUTXLINE)
+#include <utmpx.h>
+#elif defined(HAVE_LOGWTMP)
+#include <utmp.h>
+#endif
+
#include "tacplus.h"
#include "libtac.h"
@@ -58,7 +63,6 @@
/* prototypes */
void sighandler(int sig);
-void showusage(char *argv0);
unsigned long getservername(char *serv);
void showusage(char *progname);
void showversion(char *progname);
@@ -79,6 +83,13 @@ typedef unsigned char flag;
flag quiet = 0;
char *user = NULL; /* global, because of signal handler */
+#if defined(HAVE_PUTUTXLINE)
+struct utmpx utmpx;
+#endif
+
+/* take the length of a string constant without the NUL */
+#define C_STRLEN(str) (sizeof("" str) - 1)
+
/* command line options */
static struct option long_options[] =
{
@@ -163,8 +174,12 @@ int main(int argc, char **argv) {
break;
case 'V':
showversion(argv[0]);
+ /*NOTREACHED*/
+ break;
case 'h':
showusage(argv[0]);
+ /*NOTREACHED*/
+ break;
case 'u':
user = optarg;
break;
@@ -173,8 +188,7 @@ int main(int argc, char **argv) {
break;
case 'L':
// tac_login is a global variable initialized in libtac
- bzero(tac_login, sizeof(tac_login));
- strncpy(tac_login, optarg, sizeof(tac_login) - 1);
+ xstrcpy(tac_login, optarg, sizeof(tac_login));
break;
case 'p':
pass = optarg;
@@ -316,7 +330,11 @@ int main(int argc, char **argv) {
struct tac_attrib *attr = NULL;
sprintf(buf, "%lu", time(0));
tac_add_attrib(&attr, "start_time", buf);
+#ifdef HAVE_RAND_BYTES
+ RAND_bytes((unsigned char *) &task_id, sizeof(task_id));
+#else
RAND_pseudo_bytes((unsigned char *) &task_id, sizeof(task_id));
+#endif
sprintf(buf, "%hu", task_id);
tac_add_attrib(&attr, "task_id", buf);
tac_add_attrib(&attr, "service", service);
@@ -347,10 +365,28 @@ int main(int argc, char **argv) {
}
/* log in local utmp */
-#ifdef HAVE_LOGWTMP
- if (log_wtmp)
+ if (log_wtmp) {
+#if defined(HAVE_PUTUTXLINE)
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ memset(&utmpx, 0, sizeof(utmpx));
+ utmpx.ut_type = USER_PROCESS;
+ utmpx.ut_pid = getpid();
+ xstrcpy(utmpx.ut_line, tty, sizeof(utmpx.ut_line));
+ strncpy(utmpx.ut_id, tty + C_STRLEN("tty"), sizeof(utmpx.ut_id));
+ xstrcpy(utmpx.ut_host, "dialup", sizeof(utmpx.ut_host));
+ utmpx.ut_tv.tv_sec = tv.tv_sec;
+ utmpx.ut_tv.tv_usec = tv.tv_usec;
+ xstrcpy(utmpx.ut_user, user, sizeof(utmpx.ut_user));
+ /* ut_addr unused ... */
+ setutxent();
+ pututxline(&utmpx);
+#elif defined(HAVE_LOGWTMP)
logwtmp(tty, user, "dialup");
#endif
+ }
if (command != NULL) {
int ret;
@@ -429,17 +465,24 @@ int main(int argc, char **argv) {
}
/* logout from utmp */
-#ifdef HAVE_LOGWTMP
- if (log_wtmp)
+ if (log_wtmp) {
+#if defined(HAVE_PUTUTXLINE)
+ utmpx.ut_type = DEAD_PROCESS;
+ memset(utmpx.ut_line, 0, sizeof(utmpx.ut_line));
+ memset(utmpx.ut_user, 0, sizeof(utmpx.ut_user));
+ memset(utmpx.ut_host, 0, sizeof(utmpx.ut_host));
+ utmpx.ut_tv.tv_sec = utmpx.ut_tv.tv_usec = 0;
+ setutxent();
+ pututxline(&utmpx);
+#elif defined(HAVE_LOGWTMP)
logwtmp(tty, "", "");
#endif
+ }
exit(EXIT_OK);
}
-void sighandler(int sig) {
- sig = sig; /* unused */
-
+void sighandler(int sig __Unused) {
TACDEBUG(LOG_DEBUG, "caught signal %d", sig);
}
@@ -565,19 +608,15 @@ unsigned long getservername(char *serv) {
return (-1);
}
-void timeout_handler(int signum) {
- signum = signum; /* unused */
-
+void timeout_handler(int signum __Unused) {
syslog(LOG_ERR, "timeout reading password from user %s", user);
}
#ifdef TACDEBUG_AT_RUNTIME
-void logmsg(int level, const char *fmt, ...)
+void logmsg(int level __Unused, const char *fmt, ...)
{
va_list ap;
- level = level; /* unused */
-
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);