svn commit: r202215 - in head: . lib/libulog

Ed Schouten ed at FreeBSD.org
Wed Jan 13 18:53:07 UTC 2010


Author: ed
Date: Wed Jan 13 18:53:06 2010
New Revision: 202215
URL: http://svn.freebsd.org/changeset/base/202215

Log:
  Remove utmpx stub from libulog.
  
  I'm not increasing the shlib major version for this, because not a
  single application outside the base system should have used these
  functions in such a short timespan.
  
  Rewrite ulog_login(3) and ulog_logout(3) to build on top of the utmpx
  implementation in libc.

Deleted:
  head/lib/libulog/ulog_getutxent.3
  head/lib/libulog/ulog_getutxent.c
  head/lib/libulog/ulog_internal.h
  head/lib/libulog/ulog_pututxline.c
  head/lib/libulog/ulog_setutxfile.3
  head/lib/libulog/ulog_util.c
Modified:
  head/ObsoleteFiles.inc
  head/lib/libulog/Makefile
  head/lib/libulog/Symbol.map
  head/lib/libulog/ulog.h
  head/lib/libulog/ulog_login.3
  head/lib/libulog/ulog_login.c
  head/lib/libulog/ulog_login_pseudo.c
  head/lib/libulog/utempter.c
  head/lib/libulog/utempter_add_record.3

Modified: head/ObsoleteFiles.inc
==============================================================================
--- head/ObsoleteFiles.inc	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/ObsoleteFiles.inc	Wed Jan 13 18:53:06 2010	(r202215)
@@ -14,6 +14,14 @@
 # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
 #
 
+# 20100113: remove utmp.h, replace it by utmpx.h
+OLD_FILES+=usr/share/man/man3/ulog_endutxent.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_getutxent.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_getutxline.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_getutxuser.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_pututxline.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_setutxent.3.gz
+OLD_FILES+=usr/share/man/man3/ulog_setutxfile.3.gz
 # 20100105: new userland semaphore implementation
 OLD_FILES+=usr/include/sys/semaphore.h
 # 20100103: ntptrace(8) removed

Modified: head/lib/libulog/Makefile
==============================================================================
--- head/lib/libulog/Makefile	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/Makefile	Wed Jan 13 18:53:06 2010	(r202215)
@@ -7,25 +7,21 @@ SHLIBDIR?=/lib
 LIB=	ulog
 SHLIB_MAJOR= 0
 INCS=	ulog.h utempter.h
-SRCS=	ulog.h ulog_getutxent.c ulog_internal.h ulog_login.c \
-	ulog_login_pseudo.c ulog_pututxline.c ulog_util.c utempter.c
+SRCS=	ulog.h ulog_login.c ulog_login_pseudo.c utempter.c
 
-MAN=	ulog_getutxent.3 ulog_login.3 ulog_setutxfile.3 \
-	utempter_add_record.3
-MLINKS+=ulog_getutxent.3 ulog_endutxent.3 \
-	ulog_getutxent.3 ulog_getutxline.3 \
-	ulog_getutxent.3 ulog_pututxline.3 \
-	ulog_getutxent.3 ulog_setutxent.3 \
-	ulog_login.3 ulog_login_pseudo.3 \
+MAN=	ulog_login.3 utempter_add_record.3
+MLINKS+=ulog_login.3 ulog_login_pseudo.3 \
 	ulog_login.3 ulog_logout.3 \
 	ulog_login.3 ulog_logout_pseudo.3 \
-	ulog_setutxfile.3 ulog_getutxuser.3 \
 	utempter_add_record.3 utempter_remove_added_record.3 \
 	utempter_add_record.3 utempter_remove_record.3 \
 	utempter_add_record.3 addToUtmp.3 \
 	utempter_remove_added_record.3 removeFromUtmp.3 \
 	utempter_remove_record.3 removeLineFromUtmp.3
 
+DPADD=	${LIBMD}
+LDADD=	-lmd
+
 VERSION_DEF= ${.CURDIR}/../libc/Versions.def
 SYMBOL_MAPS= ${.CURDIR}/Symbol.map
 

Modified: head/lib/libulog/Symbol.map
==============================================================================
--- head/lib/libulog/Symbol.map	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/Symbol.map	Wed Jan 13 18:53:06 2010	(r202215)
@@ -3,17 +3,10 @@
  */	
 
 FBSD_1.2 {
-	ulog_endutxent;
-	ulog_getutxent;
-	ulog_getutxline;
-	ulog_getutxuser;
 	ulog_login;
 	ulog_login_pseudo;
 	ulog_logout;
 	ulog_logout_pseudo;
-	ulog_pututxline;
-	ulog_setutxent;
-	ulog_setutxfile;
 
 	addToUtmp;
 	removeFromUtmp;

Modified: head/lib/libulog/ulog.h
==============================================================================
--- head/lib/libulog/ulog.h	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/ulog.h	Wed Jan 13 18:53:06 2010	(r202215)
@@ -30,79 +30,12 @@
 #define	_ULOG_H_
 
 #include <sys/cdefs.h>
-#include <sys/_timeval.h>
-#include <sys/_types.h>
-
-#ifndef _PID_T_DECLARED
-typedef	__pid_t		pid_t;
-#define	_PID_T_DECLARED
-#endif
-
-/*
- * libulog.
- *
- * This library is provided as a migratory tool towards <utmpx.h>.  We
- * cannot yet implement <utmpx.h>, because our on-disk file format lacks
- * various fields.  <utmpx.h> also has some shortcomings.  Ideally we
- * want to allow logging of user login records generated by unprivileged
- * processes as well, provided that they hold a file descriptor to a
- * pseudo-terminal master device.
- *
- * This library (or at least parts of it) will hopefully deprecate over
- * time, when we provide the <utmpx.h> API.
- */
-
-struct ulog_utmpx {
-	char		ut_user[32];
-	char		ut_id[8];	/* XXX: unsupported. */
-	char		ut_line[32];
-	char		ut_host[256];
-	pid_t		ut_pid;		/* XXX: unsupported. */
-	short		ut_type;
-#define	EMPTY		0
-#define	BOOT_TIME	1
-#define	OLD_TIME	2
-#define	NEW_TIME	3
-#define	USER_PROCESS	4
-#define	INIT_PROCESS	5		/* XXX: unsupported. */
-#define	LOGIN_PROCESS	6		/* XXX: unsupported. */
-#define	DEAD_PROCESS	7
-#define	SHUTDOWN_TIME	8
-	struct timeval	ut_tv;
-};
 
 __BEGIN_DECLS
-/* POSIX routines. */
-void	ulog_endutxent(void);
-struct ulog_utmpx *ulog_getutxent(void);
-#if 0
-struct ulog_utmpx *ulog_getutxid(const struct ulog_utmpx *);
-#endif
-struct ulog_utmpx *ulog_getutxline(const struct ulog_utmpx *);
-struct ulog_utmpx *ulog_pututxline(const struct ulog_utmpx *);
-void	ulog_setutxent(void);
-
-/* Extensions. */
-struct ulog_utmpx *ulog_getutxuser(const char *);
-int	ulog_setutxfile(int, const char *);
-#define	UTXI_TTY	0
-#define	UTXI_TIME	1
-#define	UTXI_USER	2
-
-/* Login/logout utility functions. */
 void	ulog_login(const char *, const char *, const char *);
 void	ulog_login_pseudo(int, const char *);
 void	ulog_logout(const char *);
 void	ulog_logout_pseudo(int);
 __END_DECLS
 
-#ifdef _ULOG_POSIX_NAMES
-#define	utmpx		ulog_utmpx
-#define	endutxent	ulog_endutxent
-#define	getutxent	ulog_getutxent
-#define	getutxline	ulog_getutxline
-#define	pututxline	ulog_pututxline
-#define	setutxent	ulog_setutxent
-#endif /* _ULOG_POSIX_NAMES */
-
 #endif /* !_ULOG_H_ */

Modified: head/lib/libulog/ulog_login.3
==============================================================================
--- head/lib/libulog/ulog_login.3	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/ulog_login.3	Wed Jan 13 18:53:06 2010	(r202215)
@@ -90,13 +90,10 @@ and
 .Fn ulog_logout_pseudo
 functions spawn a privileged process to perform the actual logging.
 .Sh SEE ALSO
-.Xr getuid 3 ,
-.Xr login 3 ,
-.Xr logout 3 ,
 .Xr posix_openpt 2 ,
+.Xr getuid 3 ,
 .Xr ptsname 3 ,
-.Xr ulog_getutxent 3 ,
-.Xr utmp 5
+.Xr pututxline 3
 .Sh HISTORY
 These functions appeared in
 .Fx 9.0 .

Modified: head/lib/libulog/ulog_login.c
==============================================================================
--- head/lib/libulog/ulog_login.c	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/ulog_login.c	Wed Jan 13 18:53:06 2010	(r202215)
@@ -27,49 +27,58 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/param.h>
 #include <sys/time.h>
 #include <paths.h>
+#include <sha.h>
 #include <string.h>
+#include <unistd.h>
+#include <utmpx.h>
+#include "ulog.h"
 
-#include "ulog_internal.h"
-
-void
-ulog_login(const char *line, const char *user, const char *host)
+static void
+ulog_fill(struct utmpx *utx, const char *line)
 {
-	struct ulog_utmpx utx;
+	SHA_CTX c;
+	char id[SHA_DIGEST_LENGTH];
 
 	/* Remove /dev/ component. */
 	if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
 		line += sizeof _PATH_DEV - 1;
 
-	memset(&utx, 0, sizeof utx);
+	memset(utx, 0, sizeof *utx);
 
-	/* XXX: ut_id, ut_pid missing. */
+	utx->ut_pid = getpid();
+	gettimeofday(&utx->ut_tv, NULL);
+	strncpy(utx->ut_line, line, sizeof utx->ut_line);
+
+	SHA1_Init(&c);
+	SHA1_Update(&c, "libulog", 7);
+	SHA1_Update(&c, utx->ut_line, sizeof utx->ut_line);
+	SHA_Final(id, &c);
+
+	memcpy(utx->ut_id, id, MIN(sizeof utx->ut_id, sizeof id));
+}
+
+void
+ulog_login(const char *line, const char *user, const char *host)
+{
+	struct utmpx utx;
+
+	ulog_fill(&utx, line);
 	utx.ut_type = USER_PROCESS;
-	strncpy(utx.ut_line, line, sizeof utx.ut_line);
 	strncpy(utx.ut_user, user, sizeof utx.ut_user);
 	if (host != NULL)
 		strncpy(utx.ut_host, host, sizeof utx.ut_host);
-	gettimeofday(&utx.ut_tv, NULL);
-
-	ulog_pututxline(&utx);
+	pututxline(&utx);
 }
 
 void
 ulog_logout(const char *line)
 {
-	struct ulog_utmpx utx;
-
-	/* Remove /dev/ component. */
-	if (strncmp(line, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
-		line += sizeof _PATH_DEV - 1;
+	struct utmpx utx;
 
-	memset(&utx, 0, sizeof utx);
-
-	/* XXX: ut_id, ut_pid missing. ut_line not needed */
+	ulog_fill(&utx, line);
 	utx.ut_type = DEAD_PROCESS;
-	strncpy(utx.ut_line, line, sizeof utx.ut_line);
-	gettimeofday(&utx.ut_tv, NULL);
-
-	ulog_pututxline(&utx);
+	pututxline(&utx);
 }

Modified: head/lib/libulog/ulog_login_pseudo.c
==============================================================================
--- head/lib/libulog/ulog_login_pseudo.c	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/ulog_login_pseudo.c	Wed Jan 13 18:53:06 2010	(r202215)
@@ -34,8 +34,7 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <sysexits.h>
 #include <unistd.h>
-
-#include "ulog_internal.h"
+#include "ulog.h"
 
 #define	_PATH_ULOG_HELPER	"/usr/libexec/ulog-helper"
 

Modified: head/lib/libulog/utempter.c
==============================================================================
--- head/lib/libulog/utempter.c	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/utempter.c	Wed Jan 13 18:53:06 2010	(r202215)
@@ -27,7 +27,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include "ulog_internal.h"
+#include "ulog.h"
 #include "utempter.h"
 
 static int last_fd = -1;

Modified: head/lib/libulog/utempter_add_record.3
==============================================================================
--- head/lib/libulog/utempter_add_record.3	Wed Jan 13 18:46:50 2010	(r202214)
+++ head/lib/libulog/utempter_add_record.3	Wed Jan 13 18:53:06 2010	(r202215)
@@ -98,9 +98,8 @@ and
 .Fn utempter_remove_record
 always return a value of 0.
 .Sh SEE ALSO
-.Xr ulog_login_pseudo 3 ,
-.Xr ulog_setutxfile 3 ,
-.Xr utmp 5
+.Xr pututxline 3 ,
+.Xr ulog_login_pseudo 3
 .Sh HISTORY
 These functions appeared in
 .Fx 9.0 .


More information about the svn-src-all mailing list