diff options
| author | Philip Prindeville <philipp@redfish-solutions.com> | 2018-01-04 17:57:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-04 17:57:24 -0700 |
| commit | 81e942c82564e0577e8ecf490b75ed99268a89cc (patch) | |
| tree | b8aa4bea9508fc3a315a7e1ac7d12c78d4ca2b8a | |
| parent | 4c0616f2f0f6f7f24a265d46c861da006e4c3175 (diff) | |
| parent | 3337b95461bbea20407b321829e9a139ef077946 (diff) | |
| download | pam_tacplus-81e942c82564e0577e8ecf490b75ed99268a89cc.tar.gz pam_tacplus-81e942c82564e0577e8ecf490b75ed99268a89cc.zip | |
Merge pull request #107 from pprindeville/fix-logwtmp
Retire logwtmp() in favor of POSIX pututxline()
| -rw-r--r-- | configure.ac | 4 | ||||
| -rw-r--r-- | tacc.c | 52 |
2 files changed, 48 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac index ac7c692..ff1b44e 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,9 @@ AC_CHECK_LIB(crypto, RAND_pseudo_bytes, [AC_DEFINE([HAVE_RAND_PSEUDO_BYTES], [1], [Define to 1 if you have the `RAND_pseudo_bytes' function.])]) AC_CHECK_LIB(crypto, RAND_bytes, [AC_DEFINE([HAVE_RAND_BYTES], [1], [Define to 1 if you have the `RAND_bytes' function.])]) -AC_CHECK_LIB(util, logwtmp) +AC_CHECK_LIB(c, pututxline, + [AC_DEFINE([HAVE_PUTUTXLINE], [1], [Define to 1 if you have the `pututxline' function.])], + [AC_CHECK_LIB(util, logwtmp)]) case "$host" in sparc-* | sparc64-*) @@ -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" @@ -78,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[] = { @@ -176,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; @@ -354,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; @@ -436,10 +465,19 @@ 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); } |
