HEADS UP: <utmp.h> gone. All welcome <utmpx.h>.

Ed Schouten ed at 80386.nl
Tue Jan 26 20:05:39 UTC 2010


Hi Dirk,

* Dirk Meyer <dirk.meyer at dinoex.sub.org> wrote:
> 1. POLA
> 
> http://www.freebsd.org/doc/en_US.ISO8859-1/articles/committers-guide/rules.html
> 
> $ man utmp
> does not mention that this interafce is deprectaed (see 11.4)

First of all, utmp(5) should no longer exist. Second of all, you clearly
seem to misread section 11.4, which says "whenever possible."

Instead of just screaming POLA, could you please explain how I could
have introduced utmpx into FreeBSD without causing any breakage or
confusion among our users. As someone else already quoted earlier, our
old utmp interface was a landmine we buried ourselves.

> 2. there is now new manpage?
> $ man -k utmp
> login(3)                 - log a new login record to the utmp and wtmp files
> logout(3)                - remove an entry from the utmp file
> utempter_add_record(3), utempter_remove_added_record(3), utempter_remove_record(3), addToUtmp(3), removeFromUtmp(3), removeLineFromUtmp(3) - utempter compatibility interface
> utmp(5), wtmp(5), lastlog(5) - login records
> wtmpcvt(1)               - convert wtmp files to the utmpx format

getutxent(3). There is no category 5 manpage, because I really don't
feel like explaining the on-disk format, just like we don't explain how
/etc/spwd.db works. People should not need to know this, because we now
have utility functions.

> 2. radiusd-cistron
> 
> http://pointyhat.freebsd.org/errorlogs/i386-9-latest/radiusd-cistron-1.6.8.log
> 
> Has support for sysv utmpx,
> but this differs with the freebsd implementaion.

Could you mind explaining me what this code is supposed to do?

> 3. vsftpd
> 
> http://pointyhat.freebsd.org/errorlogs/i386-9-latest/vsftpd-2.2.2.log
> 
> this needs updwtmpx which is not avialible.
> this seemms to differ from other implementations.

Well, we'd better just remove the updwtmpx() calls then, right?

--- sysdeputil.c
+++ sysdeputil.c
@@ -1213,7 +1213,6 @@
   setutxent();
   (void) pututxline(&s_utent);
   endutxent();
-  updwtmpx(WTMPX_FILE, &s_utent);
 }
 
 void
@@ -1232,7 +1231,6 @@
   (void) pututxline(&s_utent);
   endutxent();
   s_utent.ut_tv.tv_sec = vsf_sysutil_get_time_sec();
-  updwtmpx(WTMPX_FILE, &s_utent);
 }
 
 #endif /* !VSF_SYSDEP_HAVE_UTMPX */

> 4. freebsd-uucp
> 
> http://pointyhat.freebsd.org/errorlogs/i386-9-latest/freebsd-uucp-1.07.3_1.log
> 
> use of UT_NAMELEN can be fixed.
> 
> What is the replacement of "_PATH_LASTLOG" ?
> 
> What is the replacement of "logwtmp()" ?

All handled by pututxline().

--- uucpd/uucpd.c
+++ uucpd/uucpd.c
@@ -73,7 +73,7 @@
 #include <syslog.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include <utmpx.h>
 #include <libutil.h>
 
 #include "pathnames.h"
@@ -196,7 +196,7 @@
 	} while (user[0] == '\0');
 
 	/* truncate username to LOGNAMESIZE characters */
-	user[LOGNAMESIZE] = '\0';
+	user[sizeof user - 1] = '\0';
 
 	/* always ask for passwords to deter account guessing */
 	printf("Password: "); fflush(stdout);
@@ -468,11 +468,15 @@
 {
 	int status;
 	pid_t pid;
-	char line[32];
+	struct utmpx ut;
 
 	while ((pid=wait((int *)&status)) > 0) {
-		sprintf(line, "uucp%ld", (long)pid);
-		logwtmp(line, "", "");
+		memset(&ut, 0, sizeof ut);
+		ut.ut_type = DEAD_PROCESS;
+		gettimeofday(&ut.ut_tv, NULL);
+		ut.ut_pid = pid;
+		snprintf(ut.ut_id, sizeof ut.ut_id, "%xuucp", pid);
+		pututxline(&ut);
 	}
 }
 
@@ -481,26 +485,14 @@
  */
 void dologin(struct passwd *pw, struct sockaddr *sin)
 {
-	char line[32];
-	char remotehost[UT_HOSTSIZE + 1];
-	int f;
-	time_t cur_time;
+	struct utmpx ut;
 
-	realhostname_sa(remotehost, sizeof(remotehost) - 1, sin, sin->sa_len);
-	remotehost[sizeof remotehost - 1] = '\0';
-
-	/* hack, but must be unique and no tty line */
-	sprintf(line, "uucp%ld", (long)getpid());
-	time(&cur_time);
-	if ((f = open(_PATH_LASTLOG, O_RDWR)) >= 0) {
-		struct lastlog ll;
-
-		ll.ll_time = cur_time;
-		lseek(f, (off_t)pw->pw_uid * sizeof(struct lastlog), L_SET);
-		SCPYN(ll.ll_line, line);
-		SCPYN(ll.ll_host, remotehost);
-		(void) write(f, (char *) &ll, sizeof ll);
-		(void) close(f);
-	}
-	logwtmp(line, pw->pw_name, remotehost);
+	memset(&ut, 0, sizeof ut);
+	ut.ut_type = USER_PROCESS;
+	gettimeofday(&ut.ut_tv, NULL);
+	ut.ut_pid = getpid();
+	snprintf(ut.ut_id, sizeof ut.ut_id, "%xuucp", ut.ut_pid);
+	SCPYN(ut.ut_user, pw->pw_name);
+	realhostname_sa(ut.ut_host, sizeof ut.ut_host, sin, sin->sa_len);
+	pututxline(&ut);
 }

> 5. hylafax
> 
> http://pointyhat.freebsd.org/errorlogs/i386-9-latest/hylafax-6.0.4.log
> 
> ... configure use of <utmpx.h> (extended utmp interface)
> but fails.
> 
> Even forcing it to use the SysV interface fails:
> GettySysV.c++: In member function 'void SysVGetty::writeWtmp(utmpx*)':
> GettySysV.c++:177: error: '_PATH_WTMPX' was not declared in this scope
> GettySysV.c++:177: error: 'updwtmpx' was not declared in this scope
> GettySysV.c++: In member function 'void SysVGetty::loginAccount()':
> GettySysV.c++:200: error: 'struct utmpx' has no member named 'ut_xtime'
> GettySysV.c++: In member function 'virtual void SysVGetty::hangup()':
> GettySysV.c++:243: error: 'struct utmpx' has no member named 'ut_xtime'
> *** Error code 1

No need to call updwtmpx(). ut_xtime should be called ut_tv.tv_sec.

--- faxd/GettySysV.c++
+++ faxd/GettySysV.c++
@@ -44,13 +44,7 @@
 
 #define utmp          utmpx
 #undef  ut_time
-#ifdef __linux__
-#ifdef __GLIBC__
 #define ut_time       ut_tv.tv_sec
-#endif
-#else
-#define ut_time       ut_xtime
-#endif
 
 #define getutent      getutxent
 #define getutid       getutxid
@@ -172,16 +166,6 @@
 void
 SysVGetty::writeWtmp(utmp* ut)
 {
-    // append record of login to wtmp file
-#if HAS_UTMPX
-    updwtmpx(_PATH_WTMPX, ut);
-#else
-    int fd = Sys::open(_PATH_WTMP, O_WRONLY|O_APPEND);
-    if (fd >= 0) {
-	Sys::write(fd, (char *)ut, sizeof (*ut));
-	Sys::close(fd);
-    }
-#endif
 }
 
 /*

> 6. manpage
> 
> $ man getutxent
> 
> Please proivide some example here.

Well, the other get*ent(3) manpages don't provide examples either, but
if you can think of something you consider to be useful to be provided
as an example, be sure to send ideas, patches, etc.

-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20100126/64fcd7b5/attachment.pgp


More information about the freebsd-ports mailing list