Solaris wtmpx patch

Martin Siegert siegert at sfu.ca
Tue Jan 30 08:47:40 EST 2001


Hi,

Solaris (tested with 2.6) needs a username in the logout record in the wtmpx
file. Currently openssh (version 2.3.0p1) leaves the username (utmpx.ut_user)
empty in logout records, which leads to conflicting results from the last
command. Example:

# last -5 siegert
siegert   pts/186      stikine.ucs.sfu. Mon Jan 15 14:26   still logged in
siegert   pts/105      stikine.ucs.sfu. Mon Jan 15 13:48   still logged in
siegert   pts/141      stikine.ucs.sfu. Mon Jan 15 10:23   still logged in
siegert   pts/94       stikine.ucs.sfu. Mon Jan 15 10:14   still logged in
siegert   pts/97       stikine.ucs.sfu. Mon Jan 15 10:10   still logged in
# last -4000 | grep siegert
siegert   pts/186      stikine.ucs.sfu. Mon Jan 15 14:26 - 14:31  (00:05)
siegert   pts/105      stikine.ucs.sfu. Mon Jan 15 13:48 - 13:50  (00:01)
siegert   pts/141      stikine.ucs.sfu. Mon Jan 15 10:23   still logged in
siegert   pts/94       stikine.ucs.sfu. Mon Jan 15 10:14 - 10:29  (00:14)
siegert   pts/97       stikine.ucs.sfu. Mon Jan 15 10:10 - 10:16  (00:05)

The result from "last -5 siegert" is nonsense. To see that the missing
username is the reason for this one can use bvi to enter the username
manually in the logout records. This indeed fixes the problem.
I append a patch. This will enter the username in any utmpx/wtmpx logout
record on any operating system. I believe that that won't be a problem (?).

Cheers,
Martin

========================================================================
Martin Siegert
Academic Computing Services                        phone: (604) 291-4691
Simon Fraser University                            fax:   (604) 291-4242
Burnaby, British Columbia                          email: siegert at sfu.ca
Canada  V5A 1S6
========================================================================

solaris-wtmpx patch
=<cut here>=============================================================
diff -u -r openssh-2.3.0p1.orig/login.c openssh-2.3.0p1/login.c
--- openssh-2.3.0p1.orig/login.c	Fri Sep 15 19:29:09 2000
+++ openssh-2.3.0p1/login.c	Fri Jan 26 15:48:26 2001
@@ -80,11 +80,11 @@
 /* Records that the user has logged out. */
 
 void
-record_logout(pid_t pid, const char *ttyname)
+record_logout(pid_t pid, const char *ttyname, const char *user)
 {
   struct logininfo *li;
 
-  li = login_alloc_entry(pid, NULL, NULL, ttyname);
+  li = login_alloc_entry(pid, user, NULL, ttyname);
   login_logout(li);
   login_free_entry(li);
 }
diff -u -r openssh-2.3.0p1.orig/loginrec.c openssh-2.3.0p1/loginrec.c
--- openssh-2.3.0p1.orig/loginrec.c	Sat Sep 30 03:34:44 2000
+++ openssh-2.3.0p1/loginrec.c	Tue Jan 23 18:24:25 2001
@@ -674,6 +674,9 @@
 	set_utmpx_time(li, utx);
 	utx->ut_pid = li->pid;
 
+	/* strncpy(): Don't necessarily want null termination */
+	strncpy(utx->ut_name, li->username, MIN_SIZEOF(utx->ut_name, li->username));
+
 	if (li->type == LTYPE_LOGOUT)
 		return;
 
@@ -682,8 +685,6 @@
 	 * for logouts. 
 	 */
 
-	/* strncpy(): Don't necessarily want null termination */
-	strncpy(utx->ut_name, li->username, MIN_SIZEOF(utx->ut_name, li->username));
 # ifdef HAVE_HOST_IN_UTMPX
 	strncpy(utx->ut_host, li->hostname, MIN_SIZEOF(utx->ut_host, li->hostname));
 # endif
diff -u -r openssh-2.3.0p1.orig/session.c openssh-2.3.0p1/session.c
--- openssh-2.3.0p1.orig/session.c	Fri Oct 27 20:19:58 2000
+++ openssh-2.3.0p1/session.c	Fri Jan 26 14:31:22 2001
@@ -194,7 +194,7 @@
 
 	if (s->pid != 0) {
 		/* Record that the user has logged out. */
-		record_logout(s->pid, s->tty);
+		record_logout(s->pid, s->tty, s->pw->pw_name);
 	}
 
 	/* Release the pseudo-tty. */
@@ -1796,7 +1796,7 @@
 	fatal_remove_cleanup(pty_cleanup_proc, (void *)s);
 
 	/* Record that the user has logged out. */
-	record_logout(s->pid, s->tty);
+	record_logout(s->pid, s->tty, s->pw->pw_name);
 
 	/* Release the pseudo-tty. */
 	pty_release(s->tty);
diff -u -r openssh-2.3.0p1.orig/ssh.h openssh-2.3.0p1/ssh.h
--- openssh-2.3.0p1.orig/ssh.h	Fri Oct 13 22:23:12 2000
+++ openssh-2.3.0p1/ssh.h	Fri Jan 26 14:58:01 2001
@@ -310,7 +310,7 @@
  * Records that the user has logged out.  This does many thigs normally done
  * by login(1) or init.
  */
-void    record_logout(pid_t pid, const char *ttyname);
+void    record_logout(pid_t pid, const char *ttyname, const char *user);
 
 /*------------ definitions for sshconnect.c ----------*/
 





More information about the openssh-unix-dev mailing list