From owner-svn-src-all@FreeBSD.ORG Fri Dec 11 14:15:55 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DE95C106566B; Fri, 11 Dec 2009 14:15:55 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CC36B8FC08; Fri, 11 Dec 2009 14:15:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBBEFtvP011308; Fri, 11 Dec 2009 14:15:55 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBBEFtFg011303; Fri, 11 Dec 2009 14:15:55 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912111415.nBBEFtFg011303@svn.freebsd.org> From: Ed Schouten Date: Fri, 11 Dec 2009 14:15:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200413 - in head: . lib lib/libpam/modules/pam_lastlog X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2009 14:15:56 -0000 Author: ed Date: Fri Dec 11 14:15:55 2009 New Revision: 200413 URL: http://svn.freebsd.org/changeset/base/200413 Log: Convert pam_lastlog(8) to libulog. The information used by the "Last login:"-line is obtained by using ulog_setutxfile(3) to switch to the lastlog database. Login and logout are performed using the utility functions ulog_login(3) and ulog_logout(3). This also means we must build libulog during bootstrap. Approved by: des Modified: head/Makefile.inc1 head/lib/Makefile head/lib/libpam/modules/pam_lastlog/Makefile head/lib/libpam/modules/pam_lastlog/pam_lastlog.c Modified: head/Makefile.inc1 ============================================================================== --- head/Makefile.inc1 Fri Dec 11 13:05:09 2009 (r200412) +++ head/Makefile.inc1 Fri Dec 11 14:15:55 2009 (r200413) @@ -1103,8 +1103,8 @@ _prebuild_libs= ${_kerberos5_lib_libasn1 lib/libkiconv lib/libkvm lib/libmd \ lib/ncurses/ncurses lib/ncurses/ncursesw \ lib/libopie lib/libpam ${_lib_libthr} \ - lib/libradius lib/libsbuf lib/libtacplus lib/libutil \ - ${_lib_libypclnt} lib/libz lib/msun \ + lib/libradius lib/libsbuf lib/libtacplus lib/libulog \ + lib/libutil ${_lib_libypclnt} lib/libz lib/msun \ ${_secure_lib_libcrypto} ${_secure_lib_libssh} \ ${_secure_lib_libssl} lib/libdwarf lib/libproc Modified: head/lib/Makefile ============================================================================== --- head/lib/Makefile Fri Dec 11 13:05:09 2009 (r200412) +++ head/lib/Makefile Fri Dec 11 14:15:55 2009 (r200413) @@ -21,6 +21,7 @@ # librpcsvc must be built before libpam. # libsbuf must be built before libcam. # libtacplus must be built before libpam. +# libulog must be built before libpam. # libutil must be built before libpam. # libypclnt must be built before libpam. # libgssapi must be built before librpcsec_gss @@ -30,8 +31,8 @@ SUBDIR= ${_csu} libc libbsm libauditd libcom_err libcrypt libelf libkvm msun \ libmd \ ncurses ${_libnetgraph} libradius librpcsvc libsbuf \ - libtacplus libutil ${_libypclnt} libalias libarchive ${_libatm} \ - libbegemot ${_libbluetooth} ${_libbsnmp} libbz2 \ + libtacplus libulog libutil ${_libypclnt} libalias libarchive \ + ${_libatm} libbegemot ${_libbluetooth} ${_libbsnmp} libbz2 \ libcalendar libcam libcompat libdevinfo libdevstat libdisk \ libdwarf libedit libexpat libfetch libftpio libgeom ${_libgpib} \ ${_libgssapi} ${_librpcsec_gss} libipsec \ @@ -40,8 +41,8 @@ SUBDIR= ${_csu} libc libbsm libauditd li ${_libpmc} libproc librt ${_libsdp} ${_libsm} ${_libsmb} \ ${_libsmdb} \ ${_libsmutil} libstand ${_libtelnet} ${_libthr} libthread_db libufs \ - libugidfw libulog ${_libusbhid} ${_libusb} ${_libvgl} libwrap \ - liby libz ${_bind} + libugidfw ${_libusbhid} ${_libusb} ${_libvgl} libwrap liby libz \ + ${_bind} .if exists(${.CURDIR}/csu/${MACHINE_ARCH}-elf) _csu=csu/${MACHINE_ARCH}-elf Modified: head/lib/libpam/modules/pam_lastlog/Makefile ============================================================================== --- head/lib/libpam/modules/pam_lastlog/Makefile Fri Dec 11 13:05:09 2009 (r200412) +++ head/lib/libpam/modules/pam_lastlog/Makefile Fri Dec 11 14:15:55 2009 (r200413) @@ -28,7 +28,7 @@ LIB= pam_lastlog SRCS= pam_lastlog.c MAN= pam_lastlog.8 -DPADD= ${LIBUTIL} -LDADD= -lutil +DPADD= ${LIBULOG} +LDADD= -lulog .include Modified: head/lib/libpam/modules/pam_lastlog/pam_lastlog.c ============================================================================== --- head/lib/libpam/modules/pam_lastlog/pam_lastlog.c Fri Dec 11 13:05:09 2009 (r200412) +++ head/lib/libpam/modules/pam_lastlog/pam_lastlog.c Fri Dec 11 14:15:55 2009 (r200413) @@ -46,19 +46,9 @@ __FBSDID("$FreeBSD$"); #define _BSD_SOURCE -#include - -#include -#include -#include #include -#include -#include -#include -#include #include -#include -#include +#include #define PAM_SM_SESSION @@ -71,13 +61,11 @@ pam_sm_open_session(pam_handle_t *pamh, int argc __unused, const char *argv[] __unused) { struct passwd *pwd; - struct utmp utmp; - struct lastlog ll; + struct ulog_utmpx *utx; time_t t; const char *user; const void *rhost, *tty; - off_t llpos; - int fd, pam_err; + int pam_err; pam_err = pam_get_user(pamh, &user, NULL); if (pam_err != PAM_SUCCESS) @@ -101,72 +89,29 @@ pam_sm_open_session(pam_handle_t *pamh, pam_err = PAM_SERVICE_ERR; goto err; } - if (strncmp(tty, _PATH_DEV, strlen(_PATH_DEV)) == 0) - tty = (const char *)tty + strlen(_PATH_DEV); - if (*(const char *)tty == '\0') - return (PAM_SERVICE_ERR); - fd = open(_PATH_LASTLOG, O_RDWR|O_CREAT, 0644); - if (fd == -1) { - PAM_LOG("Failed to open %s", _PATH_LASTLOG); - goto file_err; - } - - /* - * Record session in lastlog(5). - */ - llpos = (off_t)(pwd->pw_uid * sizeof(ll)); - if (lseek(fd, llpos, L_SET) != llpos) - goto file_err; if ((flags & PAM_SILENT) == 0) { - if (read(fd, &ll, sizeof ll) == sizeof ll && ll.ll_time != 0) { - t = ll.ll_time; - if (*ll.ll_host != '\0') - pam_info(pamh, "Last login: %.*s from %.*s", - 24 - 5, ctime(&t), - (int)sizeof(ll.ll_host), ll.ll_host); - else - pam_info(pamh, "Last login: %.*s on %.*s", - 24 - 5, ctime(&t), - (int)sizeof(ll.ll_line), ll.ll_line); + if (ulog_setutxfile(UTXF_LASTLOG, NULL) != 0) { + PAM_LOG("Failed to open lastlog database"); + } else { + utx = ulog_getutxuser(user); + if (utx != NULL && utx->ut_type == USER_PROCESS) { + t = utx->ut_tv.tv_sec; + if (*utx->ut_host != '\0') + pam_info(pamh, "Last login: %.*s from %s", + 24 - 5, ctime(&t), utx->ut_host); + else + pam_info(pamh, "Last login: %.*s on %s", + 24 - 5, ctime(&t), utx->ut_line); + } + ulog_endutxent(); } - if (lseek(fd, llpos, L_SET) != llpos) - goto file_err; } - bzero(&ll, sizeof(ll)); - ll.ll_time = time(NULL); - - /* note: does not need to be NUL-terminated */ - strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); - if (rhost != NULL && *(const char *)rhost != '\0') - /* note: does not need to be NUL-terminated */ - strncpy(ll.ll_host, rhost, sizeof(ll.ll_host)); - - if (write(fd, (char *)&ll, sizeof(ll)) != sizeof(ll) || close(fd) != 0) - goto file_err; - - PAM_LOG("Login recorded in %s", _PATH_LASTLOG); - - /* - * Record session in utmp(5) and wtmp(5). - */ - bzero(&utmp, sizeof(utmp)); - utmp.ut_time = time(NULL); - /* note: does not need to be NUL-terminated */ - strncpy(utmp.ut_name, user, sizeof(utmp.ut_name)); - if (rhost != NULL && *(const char *)rhost != '\0') - strncpy(utmp.ut_host, rhost, sizeof(utmp.ut_host)); - (void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line)); - login(&utmp); + ulog_login(tty, user, rhost); return (PAM_SUCCESS); -file_err: - syslog(LOG_ERR, "%s: %m", _PATH_LASTLOG); - if (fd != -1) - close(fd); - pam_err = PAM_SYSTEM_ERR; err: if (openpam_get_option(pamh, "no_fail")) return (PAM_SUCCESS); @@ -174,7 +119,7 @@ err: } PAM_EXTERN int -pam_sm_close_session(pam_handle_t *pamh __unused, int flags __unused, +pam_sm_close_session(pam_handle_t *pamh, int flags __unused, int argc __unused, const char *argv[] __unused) { const void *tty; @@ -188,14 +133,7 @@ pam_sm_close_session(pam_handle_t *pamh pam_err = PAM_SERVICE_ERR; goto err; } - if (strncmp(tty, _PATH_DEV, strlen(_PATH_DEV)) == 0) - tty = (const char *)tty + strlen(_PATH_DEV); - if (*(const char *)tty == '\0') - return (PAM_SERVICE_ERR); - if (logout(tty) != 1) - syslog(LOG_ERR, "%s(): no utmp record for %s", - __func__, (const char *)tty); - logwtmp(tty, "", ""); + ulog_logout(tty); return (PAM_SUCCESS); err: