- (djm) [configure.ac loginrec.c] bz#1421: fix lastlog support for OSX.

OSX provides a getlastlogxbyname function that automates the reading of
   a lastlog file. Also, the pututxline function will update lastlog so
   there is no need for loginrec.c to do it explicitly. Collapse some
   overly verbose code while I'm in there.
This commit is contained in:
Damien Miller 2009-02-12 13:12:21 +11:00
parent 2de762456e
commit 20e231f9f8
3 changed files with 82 additions and 80 deletions

View File

@ -1,6 +1,11 @@
20090212 20090205
- (djm) [sshpty.c] bz#1419: OSX uses cloning ptys that automagically - (djm) [sshpty.c] bz#1419: OSX uses cloning ptys that automagically
set ownership and modes, so avoid explicitly setting them set ownership and modes, so avoid explicitly setting them
- (djm) [configure.ac loginrec.c] bz#1421: fix lastlog support for OSX.
OSX provides a getlastlogxbyname function that automates the reading of
a lastlog file. Also, the pututxline function will update lastlog so
there is no need for loginrec.c to do it explicitly. Collapse some
overly verbose code while I'm in there.
20090201 20090201
- (dtucker) [defines.h sshconnect.c] INET6_ADDRSTRLEN is now needed in - (dtucker) [defines.h sshconnect.c] INET6_ADDRSTRLEN is now needed in
@ -5118,5 +5123,5 @@
OpenServer 6 and add osr5bigcrypt support so when someone migrates OpenServer 6 and add osr5bigcrypt support so when someone migrates
passwords between UnixWare and OpenServer they will still work. OK dtucker@ passwords between UnixWare and OpenServer they will still work. OK dtucker@
$Id: ChangeLog,v 1.5184 2009/02/12 01:19:20 djm Exp $ $Id: ChangeLog,v 1.5185 2009/02/12 02:12:21 djm Exp $

View File

@ -1,4 +1,4 @@
# $Id: configure.ac,v 1.413 2009/01/08 04:50:09 tim Exp $ # $Id: configure.ac,v 1.414 2009/02/12 02:12:22 djm Exp $
# #
# Copyright (c) 1999-2004 Damien Miller # Copyright (c) 1999-2004 Damien Miller
# #
@ -15,7 +15,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org)
AC_REVISION($Revision: 1.413 $) AC_REVISION($Revision: 1.414 $)
AC_CONFIG_SRCDIR([ssh.c]) AC_CONFIG_SRCDIR([ssh.c])
AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(config.h)
@ -477,6 +477,8 @@ main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
AC_CHECK_DECL(AU_IPv4, [], AC_CHECK_DECL(AU_IPv4, [],
AC_DEFINE(AU_IPv4, 0, [System only supports IPv4 audit records]) AC_DEFINE(AU_IPv4, 0, [System only supports IPv4 audit records])
[#include <bsm/audit.h>] [#include <bsm/audit.h>]
AC_DEFINE(LASTLOG_WRITE_PUTUTXLINE, 1,
[Define if pututxline updates lastlog too])
) )
;; ;;
*-*-dragonfly*) *-*-dragonfly*)
@ -1508,6 +1510,8 @@ AC_CHECK_FUNCS(utmpname)
dnl Checks for utmpx functions dnl Checks for utmpx functions
AC_CHECK_FUNCS(endutxent getutxent getutxid getutxline pututxline ) AC_CHECK_FUNCS(endutxent getutxent getutxid getutxline pututxline )
AC_CHECK_FUNCS(setutxent utmpxname) AC_CHECK_FUNCS(setutxent utmpxname)
dnl Checks for lastlog functions
AC_CHECK_FUNCS(getlastlogxbyname)
AC_CHECK_FUNC(daemon, AC_CHECK_FUNC(daemon,
[AC_DEFINE(HAVE_DAEMON, 1, [Define if your libraries define daemon()])], [AC_DEFINE(HAVE_DAEMON, 1, [Define if your libraries define daemon()])],

View File

@ -1456,25 +1456,14 @@ syslogin_write_entry(struct logininfo *li)
**/ **/
#ifdef USE_LASTLOG #ifdef USE_LASTLOG
#define LL_FILE 1
#define LL_DIR 2
#define LL_OTHER 3
static void
lastlog_construct(struct logininfo *li, struct lastlog *last)
{
/* clear the structure */
memset(last, '\0', sizeof(*last));
line_stripname(last->ll_line, li->line, sizeof(last->ll_line));
strlcpy(last->ll_host, li->hostname,
MIN_SIZEOF(last->ll_host, li->hostname));
last->ll_time = li->tv_sec;
}
#if !defined(LASTLOG_WRITE_PUTUTXLINE) || !defined(HAVE_GETLASTLOGXBYNAME)
/* open the file (using filemode) and seek to the login entry */
static int static int
lastlog_filetype(char *filename) lastlog_openseek(struct logininfo *li, int *fd, int filemode)
{ {
off_t offset;
char lastlog_file[1024];
struct stat st; struct stat st;
if (stat(LASTLOG_FILE, &st) != 0) { if (stat(LASTLOG_FILE, &st) != 0) {
@ -1482,34 +1471,12 @@ lastlog_filetype(char *filename)
LASTLOG_FILE, strerror(errno)); LASTLOG_FILE, strerror(errno));
return (0); return (0);
} }
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode)) {
return (LL_DIR);
else if (S_ISREG(st.st_mode))
return (LL_FILE);
else
return (LL_OTHER);
}
/* open the file (using filemode) and seek to the login entry */
static int
lastlog_openseek(struct logininfo *li, int *fd, int filemode)
{
off_t offset;
int type;
char lastlog_file[1024];
type = lastlog_filetype(LASTLOG_FILE);
switch (type) {
case LL_FILE:
strlcpy(lastlog_file, LASTLOG_FILE,
sizeof(lastlog_file));
break;
case LL_DIR:
snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s", snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s",
LASTLOG_FILE, li->username); LASTLOG_FILE, li->username);
break; } else if (S_ISREG(st.st_mode)) {
default: strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file));
} else {
logit("%s: %.100s is not a file or directory!", __func__, logit("%s: %.100s is not a file or directory!", __func__,
LASTLOG_FILE); LASTLOG_FILE);
return (0); return (0);
@ -1522,7 +1489,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
return (0); return (0);
} }
if (type == LL_FILE) { if (S_ISREG(st.st_mode)) {
/* find this uid's offset in the lastlog file */ /* find this uid's offset in the lastlog file */
offset = (off_t) ((long)li->uid * sizeof(struct lastlog)); offset = (off_t) ((long)li->uid * sizeof(struct lastlog));
@ -1535,52 +1502,74 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
return (1); return (1);
} }
#endif /* !LASTLOG_WRITE_PUTUTXLINE || !HAVE_GETLASTLOGXBYNAME */
static int #ifdef LASTLOG_WRITE_PUTUTXLINE
lastlog_perform_login(struct logininfo *li)
{
struct lastlog last;
int fd;
/* create our struct lastlog */
lastlog_construct(li, &last);
if (!lastlog_openseek(li, &fd, O_RDWR|O_CREAT))
return (0);
/* write the entry */
if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
close(fd);
logit("%s: Error writing to %s: %s", __func__,
LASTLOG_FILE, strerror(errno));
return (0);
}
close(fd);
return (1);
}
int int
lastlog_write_entry(struct logininfo *li) lastlog_write_entry(struct logininfo *li)
{ {
switch(li->type) { switch(li->type) {
case LTYPE_LOGIN: case LTYPE_LOGIN:
return (lastlog_perform_login(li)); return 1; /* lastlog written by pututxline */
default:
logit("lastlog_write_entry: Invalid type field");
return 0;
}
}
#else /* LASTLOG_WRITE_PUTUTXLINE */
int
lastlog_write_entry(struct logininfo *li)
{
struct lastlog last;
int fd;
switch(li->type) {
case LTYPE_LOGIN:
/* create our struct lastlog */
memset(&last, '\0', sizeof(last));
line_stripname(last.ll_line, li->line, sizeof(last.ll_line));
strlcpy(last.ll_host, li->hostname,
MIN_SIZEOF(last.ll_host, li->hostname));
last.ll_time = li->tv_sec;
if (!lastlog_openseek(li, &fd, O_RDWR|O_CREAT))
return (0);
/* write the entry */
if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
close(fd);
logit("%s: Error writing to %s: %s", __func__,
LASTLOG_FILE, strerror(errno));
return (0);
}
close(fd);
return (1);
default: default:
logit("%s: Invalid type field", __func__); logit("%s: Invalid type field", __func__);
return (0); return (0);
} }
} }
#endif /* LASTLOG_WRITE_PUTUTXLINE */
static void #ifdef HAVE_GETLASTLOGXBYNAME
lastlog_populate_entry(struct logininfo *li, struct lastlog *last) int
lastlog_get_entry(struct logininfo *li)
{ {
line_fullname(li->line, last->ll_line, sizeof(li->line)); struct lastlogx l, *ll;
strlcpy(li->hostname, last->ll_host,
MIN_SIZEOF(li->hostname, last->ll_host));
li->tv_sec = last->ll_time;
}
if ((ll = getlastlogxbyname(li->username, &l)) == NULL) {
memset(&l, '\0', sizeof(l));
ll = &l;
}
line_fullname(li->line, ll->ll_line, sizeof(li->line));
strlcpy(li->hostname, ll->ll_host,
MIN_SIZEOF(li->hostname, ll->ll_host));
li->tv_sec = ll->ll_tv.tv_sec;
li->tv_usec = ll->ll_tv.tv_usec;
return (1);
}
#else /* HAVE_GETLASTLOGXBYNAME */
int int
lastlog_get_entry(struct logininfo *li) lastlog_get_entry(struct logininfo *li)
{ {
@ -1598,7 +1587,10 @@ lastlog_get_entry(struct logininfo *li)
memset(&last, '\0', sizeof(last)); memset(&last, '\0', sizeof(last));
/* FALLTHRU */ /* FALLTHRU */
case sizeof(last): case sizeof(last):
lastlog_populate_entry(li, &last); line_fullname(li->line, last.ll_line, sizeof(li->line));
strlcpy(li->hostname, last.ll_host,
MIN_SIZEOF(li->hostname, last.ll_host));
li->tv_sec = last.ll_time;
return (1); return (1);
case -1: case -1:
error("%s: Error reading from %s: %s", __func__, error("%s: Error reading from %s: %s", __func__,
@ -1613,6 +1605,7 @@ lastlog_get_entry(struct logininfo *li)
/* NOTREACHED */ /* NOTREACHED */
return (0); return (0);
} }
#endif /* HAVE_GETLASTLOGXBYNAME */
#endif /* USE_LASTLOG */ #endif /* USE_LASTLOG */
#ifdef USE_BTMP #ifdef USE_BTMP