[openssh-portable] utmpx and ut_name

Ed Schouten ed at 80386.nl
Sat Dec 26 03:54:35 EST 2009


Hello OpenSSH hackers,

The last couple of weeks I've been figuring out how hard it is to
replace FreeBSD's <utmp.h> with <utmpx.h>. I don't think utmpx is
perfect, but at least it's better than what we have now and at least it
has gone through some form of standardisation. I noticed POSIX says the
following [1]:

| The <utmpx.h> header shall define the utmpx structure that shall
| include at least the following members:
|
| char  ut_user[]  User login name.
| ...

Now ut_user deviates a bit from <utmp.h>, where this field is normally
called ut_name. I've noticed most (all?) implementations just #define
ut_name to ut_user to keep things happy, but I'd rather not put this
obfuscation in any new implementation.

I've noticed OpenSSH also uses ut_name, even when using utmpx. I've come
up with the following patch:

%%%
--- loginrec.c
+++ loginrec.c
@@ -758,8 +758,8 @@
 	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));
+	strncpy(utx->ut_user, li->username,
+	    MIN_SIZEOF(utx->ut_user, li->username));
 
 	if (li->type == LTYPE_LOGOUT)
 		return;
@@ -1316,8 +1316,8 @@
 static int
 wtmpx_islogin(struct logininfo *li, struct utmpx *utx)
 {
-	if (strncmp(li->username, utx->ut_name,
-	    MIN_SIZEOF(li->username, utx->ut_name)) == 0 ) {
+	if (strncmp(li->username, utx->ut_user,
+	    MIN_SIZEOF(li->username, utx->ut_user)) == 0 ) {
 # ifdef HAVE_TYPE_IN_UTMPX
 		if (utx->ut_type == USER_PROCESS)
 			return (1);
%%%

It changes all uses of ut_name on utmpx structures to ut_user. Any
chance this can go into CVS?

Merry christmas,
-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/

[1] http://www.opengroup.org/onlinepubs/9699919799/basedefs/utmpx.h.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20091225/eaa1565b/attachment.bin>


More information about the openssh-unix-dev mailing list