PATCH: UseLogin fix for 2.9p1 (w/improved last-login time)
Wayne Davison
wayne at blorf.net
Mon Apr 30 06:05:26 EST 2001
Attached is the latest version of my UseLogin patch that makes
"UseLogin true" work on Solaris and UNICOS. As usual, I have provided
configure.in changes that set the appropriate defines for Solaris, but
I have not provided the configure.in changes for UNICOS (since they
would be incomplete, and Wendy is working on this).
This version fixes a problem with the last-login time always being
reported as the current time (I had to add a new record_*() function
since record_login() was changing other things than the {u,w}tmp{x,}
data). This version also changes less existing code, to hopefully
make it easier to maintain against the BSD source.
The patch is relative to the 2.9p1 source I just grabbed out of CVS.
..wayne..
-------------- next part --------------
Index: acconfig.h
--- acconfig.h 2001/04/05 17:15:08 1.110
+++ acconfig.h 2001/04/29 18:12:31
@@ -154,6 +154,12 @@
/* Define if you don't want to use wtmpx */
#undef DISABLE_WTMPX
+/* Some systems need a utmpx entry for /bin/login to work */
+#undef LOGIN_NEEDS_UTMPX
+
+/* Some versions of /bin/login need the TERM supplied on the commandline */
+#undef LOGIN_NEEDS_TERM
+
/* Define if you want to specify the path to your lastlog file */
#undef CONF_LASTLOG_FILE
Index: configure.in
--- configure.in 2001/04/26 04:40:28 1.282
+++ configure.in 2001/04/29 18:12:36
@@ -153,6 +153,8 @@
LDFLAGS="$LDFLAGS -L/usr/local/lib -R/usr/local/lib"
need_dash_r=1
AC_DEFINE(PAM_SUN_CODEBASE)
+ AC_DEFINE(LOGIN_NEEDS_UTMPX)
+ AC_DEFINE(LOGIN_NEEDS_TERM)
# hardwire lastlog location (can't detect it on some versions)
conf_lastlog_location="/var/adm/lastlog"
AC_MSG_CHECKING(for obsolete utmp and wtmp in solaris2.x)
Index: loginrec.c
--- loginrec.c 2001/02/22 21:23:21 1.32
+++ loginrec.c 2001/04/29 18:12:40
@@ -443,6 +443,27 @@
return 0;
}
+#ifdef LOGIN_NEEDS_UTMPX
+int
+login_utmp_only(struct logininfo *li)
+{
+ li->type = LTYPE_LOGIN;
+# ifdef USE_UTMP
+ utmp_write_entry(li);
+# endif
+# ifdef USE_WTMP
+ wtmp_write_entry(li);
+# endif
+# ifdef USE_UTMPX
+ utmpx_write_entry(li);
+# endif
+# ifdef USE_WTMPX
+ wtmpx_write_entry(li);
+# endif
+ return 0;
+}
+#endif
+
/**
** getlast_entry: Call low-level functions to retrieve the last login
** time.
Index: loginrec.h
--- loginrec.h 2001/02/05 12:42:18 1.5
+++ loginrec.h 2001/04/29 18:12:41
@@ -110,6 +110,9 @@
/* record the entry */
int login_login (struct logininfo *li);
int login_logout(struct logininfo *li);
+#ifdef LOGIN_NEEDS_UTMPX
+int login_utmp_only(struct logininfo *li);
+#endif
/** End of public functions */
Index: session.c
--- session.c 2001/04/18 15:29:34 1.111
+++ session.c 2001/04/29 18:12:41
@@ -127,6 +127,9 @@
void do_exec_pty(Session *s, const char *command);
void do_exec_no_pty(Session *s, const char *command);
void do_login(Session *s, const char *command);
+#ifdef LOGIN_NEEDS_UTMPX
+void do_pre_login(Session *s);
+#endif
void do_child(Session *s, const char *command);
void do_motd(void);
int check_quietlogin(Session *s, const char *command);
@@ -644,6 +647,10 @@
#ifndef HAVE_OSF_SIA
if (!(options.use_login && command == NULL))
do_login(s, command);
+# ifdef LOGIN_NEEDS_UTMPX
+ else
+ do_pre_login(s);
+# endif
#endif
/* Do common processing for the child, such as execing the command. */
@@ -687,6 +694,34 @@
}
}
+#ifdef LOGIN_NEEDS_UTMPX
+void
+do_pre_login(Session *s)
+{
+ socklen_t fromlen;
+ struct sockaddr_storage from;
+ pid_t pid = getpid();
+
+ /*
+ * Get IP address of client. If the connection is not a socket, let
+ * the address be 0.0.0.0.
+ */
+ memset(&from, 0, sizeof(from));
+ if (packet_connection_is_on_socket()) {
+ fromlen = sizeof(from);
+ if (getpeername(packet_get_connection_in(),
+ (struct sockaddr *) & from, &fromlen) < 0) {
+ debug("getpeername: %.100s", strerror(errno));
+ fatal_cleanup();
+ }
+ }
+
+ record_utmp_only(pid, s->tty, s->pw->pw_name,
+ get_remote_name_or_ip(utmp_len, options.reverse_mapping_check),
+ (struct sockaddr *)&from);
+}
+#endif
+
/* administrative, login(1)-like work */
void
do_login(Session *s, const char *command)
@@ -1511,6 +1546,9 @@
/* Launch login(1). */
execl(LOGIN_PROGRAM, "login", "-h", hostname,
+#ifdef LOGIN_NEEDS_TERM
+ s->term? s->term : "unknown",
+#endif
"-p", "-f", "--", pw->pw_name, NULL);
/* Login couldn't be executed, die. */
Index: sshlogin.c
--- sshlogin.c 2001/03/26 05:32:17 1.3
+++ sshlogin.c 2001/04/29 18:12:41
@@ -77,6 +77,20 @@
login_free_entry(li);
}
+#ifdef LOGIN_NEEDS_UTMPX
+void
+record_utmp_only(pid_t pid, const char *ttyname, const char *user,
+ const char *host, struct sockaddr * addr)
+{
+ struct logininfo *li;
+
+ li = login_alloc_entry(pid, user, host, ttyname);
+ login_set_addr(li, addr, sizeof(struct sockaddr));
+ login_utmp_only(li);
+ login_free_entry(li);
+}
+#endif
+
/* Records that the user has logged out. */
void
Index: sshlogin.h
--- sshlogin.h 2001/03/05 03:53:03 1.2
+++ sshlogin.h 2001/04/29 18:12:41
@@ -31,6 +31,15 @@
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
const char *host, struct sockaddr *addr);
+#ifdef LOGIN_NEEDS_UTMPX
+/*
+ * Record just the utmp info for /bin/login.
+ */
+void
+record_utmp_only(pid_t pid, const char *ttyname, const char *user,
+ const char *host, struct sockaddr * addr);
+#endif
+
/*
* Records that the user has logged out. This does many thigs normally done
* by login(1) or init.
More information about the openssh-unix-dev
mailing list