From 83621919cd34a46a51c274b1bf7d109880c00f13 Mon Sep 17 00:00:00 2001 From: "zodiac@gmail.com" Date: Thu, 8 Jul 2010 17:54:15 +0000 Subject: [PATCH] Added support for systems that have utmpx.h, but don't implement updwtmpx(). git-svn-id: https://shellinabox.googlecode.com/svn/trunk@207 0da03de8-d603-11dd-86c2-0f8696b7b6f9 --- ChangeLog | 5 +++++ config.h | 8 ++++++- config.h.in | 6 ++++++ configure | 39 ++++++++++++++++++++++++++++++++++- configure.ac | 12 ++++++++++- demo/vt100.js | 2 +- shellinabox/launcher.c | 36 ++++++++++++++++++++++++++++++++ shellinabox/shell_in_a_box.js | 2 +- shellinabox/vt100.js | 2 +- 9 files changed, 106 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a63b5c..fe29b31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-07-08 Markus Gutschke + + * Added support for systems that have utmpx.h, but don't implement + updwtmpx(). + 2010-07-02 Markus Gutschke * Fixed a NULL pointer dereference that can occur when hostnames diff --git a/config.h b/config.h index 34d2cd6..df0cfbb 100644 --- a/config.h +++ b/config.h @@ -106,6 +106,12 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 +/* Define to 1 if you have support for updwtmp */ +#define HAVE_UPDWTMP 1 + +/* Define to 1 if you have support for updwtmpx */ +#define HAVE_UPDWTMPX 1 + /* Define to 1 if you have the header file. */ /* #undef HAVE_UTIL_H */ @@ -147,7 +153,7 @@ #define STDC_HEADERS 1 /* Most recent revision number in the version control system */ -#define VCS_REVISION "206" +#define VCS_REVISION "207" /* Version number of package */ #define VERSION "2.10" diff --git a/config.h.in b/config.h.in index 7366ec3..483b00e 100644 --- a/config.h.in +++ b/config.h.in @@ -105,6 +105,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have support for updwtmp */ +#undef HAVE_UPDWTMP + +/* Define to 1 if you have support for updwtmpx */ +#undef HAVE_UPDWTMPX + /* Define to 1 if you have the header file. */ #undef HAVE_UTIL_H diff --git a/configure b/configure index 18d7ee8..75ae8f9 100755 --- a/configure +++ b/configure @@ -2328,7 +2328,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -VCS_REVISION=206 +VCS_REVISION=207 cat >>confdefs.h <<_ACEOF @@ -10729,6 +10729,43 @@ if ac_fn_c_try_link "$LINENO"; then : $as_echo "#define HAVE_ISNAN 1" >>confdefs.h +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +updwtmp(0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +$as_echo "#define HAVE_UPDWTMP 1" >>confdefs.h + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +updwtmpx(0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +$as_echo "#define HAVE_UPDWTMPX 1" >>confdefs.h + fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext diff --git a/configure.ac b/configure.ac index b1dbc31..77c23c3 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.57) dnl This is the one location where the authoritative version number is stored AC_INIT(shellinabox, 2.10, markus@shellinabox.com) -VCS_REVISION=206 +VCS_REVISION=207 AC_SUBST(VCS_REVISION) AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}", [Most recent revision number in the version control system]) @@ -61,6 +61,16 @@ AC_TRY_LINK([#include ], [AC_DEFINE(HAVE_ISNAN, 1, Define to 1 if you have support for isnan)]) +dnl Even if utmpx.h exists, not all systems have support for updwtmpx() +AC_TRY_LINK([#include ], + [updwtmp(0, 0);], + [AC_DEFINE(HAVE_UPDWTMP, 1, + Define to 1 if you have support for updwtmp)]) +AC_TRY_LINK([#include ], + [updwtmpx(0, 0);], + [AC_DEFINE(HAVE_UPDWTMPX, 1, + Define to 1 if you have support for updwtmpx)]) + dnl On some systems, calling /bin/login does not work. Disable the LOGIN dnl feature, if the user tells us that it does not do the right thing. AC_ARG_ENABLE(login, diff --git a/demo/vt100.js b/demo/vt100.js index d62cba0..2a382ac 100644 --- a/demo/vt100.js +++ b/demo/vt100.js @@ -1955,7 +1955,7 @@ VT100.prototype.toggleBell = function() { }; VT100.prototype.about = function() { - alert("VT100 Terminal Emulator " + "2.10 (revision 206)" + + alert("VT100 Terminal Emulator " + "2.10 (revision 207)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com"); }; diff --git a/shellinabox/launcher.c b/shellinabox/launcher.c index f3aff9e..4ff1c5a 100644 --- a/shellinabox/launcher.c +++ b/shellinabox/launcher.c @@ -495,6 +495,33 @@ struct Utmp *newUtmp(int useLogin, const char *ptyPath, return utmp; } +#if defined(HAVE_UPDWTMP) && !defined(HAVE_UPDWTMPX) +#define min(a,b) ({ typeof(a) _a=(a); typeof(b) _b=(b); _a < _b ? _a : _b; }) +#define updwtmpx x_updwtmpx + +static void updwtmpx(const char *wtmpx_file, const struct utmpx *utx) { + struct utmp ut = { 0 }; + ut.ut_type = utx->ut_type; + ut.ut_pid = utx->ut_pid; + ut.ut_session = utx->ut_session; + ut.ut_tv.tv_sec = utx->ut_tv.tv_sec; + ut.ut_tv.tv_usec = utx->ut_tv.tv_usec; + memcpy(&ut.ut_line, &utx->ut_line, + min(sizeof(ut.ut_line), sizeof(utx->ut_line))); + memcpy(&ut.ut_id, &utx->ut_id, + min(sizeof(ut.ut_id), sizeof(utx->ut_id))); + memcpy(&ut.ut_user, &utx->ut_user, + min(sizeof(ut.ut_user), sizeof(utx->ut_user))); + memcpy(&ut.ut_host, &utx->ut_host, + min(sizeof(ut.ut_host), sizeof(utx->ut_host))); + memcpy(&ut.ut_exit, &utx->ut_exit, + min(sizeof(ut.ut_exit), sizeof(utx->ut_exit))); + memcpy(&ut.ut_addr_v6, &utx->ut_addr_v6, + min(sizeof(ut.ut_addr_v6), sizeof(utx->ut_addr_v6))); + updwtmp(wtmpx_file, &ut); +} +#endif + void destroyUtmp(struct Utmp *utmp) { if (utmp) { if (utmp->pty >= 0) { @@ -518,9 +545,12 @@ void destroyUtmp(struct Utmp *utmp) { setutxent(); pututxline(&utmp->utmpx); endutxent(); + +#if defined(HAVE_UPDWTMP) || defined(HAVE_UPDWTMPX) if (!utmp->useLogin) { updwtmpx("/var/log/wtmp", &utmp->utmpx); } +#endif // Switch back to the lower privileges check(!setresgid(r_gid, e_gid, s_gid)); @@ -1043,7 +1073,10 @@ static pam_handle_t *internalLogin(struct Service *service, struct Utmp *utmp, setutxent(); pututxline(&utmp->utmpx); endutxent(); + +#if defined(HAVE_UPDWTMP) || defined(HAVE_UPDWTMPX) updwtmpx("/var/log/wtmp", &utmp->utmpx); +#endif } #endif @@ -1339,11 +1372,14 @@ static void childProcess(struct Service *service, int width, int height, } pututxline(&utmpx); endutxent(); + +#if defined(HAVE_UPDWTMP) || defined(HAVE_UPDWTMPX) if (!utmp->useLogin) { memset(&utmpx.ut_user, 0, sizeof(utmpx.ut_user)); strncat(&utmpx.ut_user[0], "LOGIN", sizeof(utmpx.ut_user)); updwtmpx("/var/log/wtmp", &utmpx); } +#endif #endif // Create session. We might have to fork another process as PAM wants us diff --git a/shellinabox/shell_in_a_box.js b/shellinabox/shell_in_a_box.js index cd07767..4cc7b5d 100644 --- a/shellinabox/shell_in_a_box.js +++ b/shellinabox/shell_in_a_box.js @@ -358,7 +358,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) { }; ShellInABox.prototype.about = function() { - alert("Shell In A Box version " + "2.10 (revision 206)" + + alert("Shell In A Box version " + "2.10 (revision 207)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com" + (typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ? diff --git a/shellinabox/vt100.js b/shellinabox/vt100.js index d62cba0..2a382ac 100644 --- a/shellinabox/vt100.js +++ b/shellinabox/vt100.js @@ -1955,7 +1955,7 @@ VT100.prototype.toggleBell = function() { }; VT100.prototype.about = function() { - alert("VT100 Terminal Emulator " + "2.10 (revision 206)" + + alert("VT100 Terminal Emulator " + "2.10 (revision 207)" + "\nCopyright 2008-2010 by Markus Gutschke\n" + "For more information check http://shellinabox.com"); };