diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-07-10 21:40:21 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-07-10 21:40:21 +0000 |
commit | c57d41bc25857a7693129acd24166a68eddf4482 (patch) | |
tree | 41ec99dbeada02aeb35d346925b19d34202be583 /lib/libutil | |
parent | 4fd3d6f52d265f3d3ff1edfd295834c788cd2ed8 (diff) |
Prevent luser from zero'ing out ut_host. If the new ut_line is
empty but the old one is not and ut_line and ut_name match, preserve
the old ut_line. Fixes PR #516
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/login.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/libutil/login.c b/lib/libutil/login.c index c70040701af..134d7ae8fa3 100644 --- a/lib/libutil/login.c +++ b/lib/libutil/login.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login.c,v 1.3 1996/06/17 07:46:02 downsj Exp $ */ +/* $OpenBSD: login.c,v 1.4 1998/07/10 21:40:20 millert Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -34,7 +34,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: login.c,v 1.3 1996/06/17 07:46:02 downsj Exp $"; +static char *rcsid = "$Id: login.c,v 1.4 1998/07/10 21:40:20 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -48,20 +48,33 @@ static char *rcsid = "$Id: login.c,v 1.3 1996/06/17 07:46:02 downsj Exp $"; #include "util.h" void -login(ut) - struct utmp *ut; +login(utp) + struct utmp *utp; { + struct utmp old_ut; register int fd; int tty; tty = ttyslot(); - if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) { + if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) { (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET); - (void)write(fd, ut, sizeof(struct utmp)); + /* + * Prevent luser from zero'ing out ut_host. + * If the new ut_line is empty but the old one is not + * and ut_line and ut_name match, preserve the old ut_line. + */ + if (read(fd, &old_ut, sizeof(struct utmp)) == + sizeof(struct utmp) && utp->ut_host[0] == '\0' && + old_ut.ut_host[0] != '\0' && + strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 && + strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0) + (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE); + (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET); + (void)write(fd, utp, sizeof(struct utmp)); (void)close(fd); } if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { - (void)write(fd, ut, sizeof(struct utmp)); + (void)write(fd, utp, sizeof(struct utmp)); (void)close(fd); } } |