CVS commit: src/libexec/utmp_update
Module Name:src Committed By: sevan Date: Sat Apr 18 22:03:51 UTC 2020 Modified Files: src/libexec/utmp_update: utmp_update.8 Log Message: document history To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/libexec/utmp_update/utmp_update.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/utmp_update.8 diff -u src/libexec/utmp_update/utmp_update.8:1.2 src/libexec/utmp_update/utmp_update.8:1.3 --- src/libexec/utmp_update/utmp_update.8:1.2 Wed Apr 30 13:10:52 2008 +++ src/libexec/utmp_update/utmp_update.8 Sat Apr 18 22:03:51 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: utmp_update.8,v 1.2 2008/04/30 13:10:52 martin Exp $ +.\" $NetBSD: utmp_update.8,v 1.3 2020/04/18 22:03:51 sevan Exp $ .\" .\" Copyright (c) 2002 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 12, 2002 +.Dd April 18, 2020 .Dt UTMP_UPDATE 8 .Os .Sh NAME @@ -59,3 +59,8 @@ returns 0 on success, and 1 if an error .Sh SEE ALSO .Xr pututxline 3 , .Xr utmpx 5 +.Sh HISTORY +A +.Nm +utility appeared in +.Nx 2.0 .
CVS commit: src/libexec/utmp_update
Module Name:src Committed By: mlelstv Date: Sun Apr 26 08:56:19 UTC 2015 Modified Files: src/libexec/utmp_update: utmp_update.c Log Message: Use verrx with a va_list. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/libexec/utmp_update/utmp_update.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/utmp_update.c diff -u src/libexec/utmp_update/utmp_update.c:1.12 src/libexec/utmp_update/utmp_update.c:1.13 --- src/libexec/utmp_update/utmp_update.c:1.12 Sun Apr 26 08:03:05 2015 +++ src/libexec/utmp_update/utmp_update.c Sun Apr 26 08:56:19 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: utmp_update.c,v 1.12 2015/04/26 08:03:05 mlelstv Exp $ */ +/* $NetBSD: utmp_update.c,v 1.13 2015/04/26 08:56:19 mlelstv Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: utmp_update.c,v 1.12 2015/04/26 08:03:05 mlelstv Exp $"); +__RCSID("$NetBSD: utmp_update.c,v 1.13 2015/04/26 08:56:19 mlelstv Exp $"); #include #include @@ -65,7 +65,7 @@ logerr(int e, const char *fmt, ...) va_copy(eap, sap); vsyslog(LOG_ERR, fmt, sap); va_end(sap); - errx(1, fmt, eap); + verrx(1, fmt, eap); va_end(eap); }
CVS commit: src/libexec/utmp_update
Module Name:src Committed By: mlelstv Date: Sun Apr 26 08:03:05 UTC 2015 Modified Files: src/libexec/utmp_update: utmp_update.c Log Message: size output buffer for strunvis to include the trailing NUL character. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/libexec/utmp_update/utmp_update.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/utmp_update.c diff -u src/libexec/utmp_update/utmp_update.c:1.11 src/libexec/utmp_update/utmp_update.c:1.12 --- src/libexec/utmp_update/utmp_update.c:1.11 Sat Sep 17 14:25:43 2011 +++ src/libexec/utmp_update/utmp_update.c Sun Apr 26 08:03:05 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: utmp_update.c,v 1.11 2011/09/17 14:25:43 christos Exp $ */ +/* $NetBSD: utmp_update.c,v 1.12 2015/04/26 08:03:05 mlelstv Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: utmp_update.c,v 1.11 2011/09/17 14:25:43 christos Exp $"); +__RCSID("$NetBSD: utmp_update.c,v 1.12 2015/04/26 08:03:05 mlelstv Exp $"); #include #include @@ -99,8 +99,8 @@ main(int argc, char *argv[]) if (len > sizeof(*utx) * 4 + 1 || len < sizeof(*utx)) logerr(0, "Bad argument size %zu", len); - if ((utx = malloc(len)) == NULL) - logerr(errno, "Can't allocate %zu", len); + if ((utx = malloc(len+1)) == NULL) + logerr(errno, "Can't allocate %zu", len+1); res = strunvis((char *)utx, argv[1]); if (res != (int)sizeof(*utx))
CVS commit: src/libexec/utmp_update
Module Name:src Committed By: christos Date: Sat Sep 17 14:25:43 UTC 2011 Modified Files: src/libexec/utmp_update: utmp_update.c Log Message: add printflike To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/libexec/utmp_update/utmp_update.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/utmp_update.c diff -u src/libexec/utmp_update/utmp_update.c:1.10 src/libexec/utmp_update/utmp_update.c:1.11 --- src/libexec/utmp_update/utmp_update.c:1.10 Fri Sep 16 21:50:54 2011 +++ src/libexec/utmp_update/utmp_update.c Sat Sep 17 10:25:43 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: utmp_update.c,v 1.10 2011/09/17 01:50:54 christos Exp $ */ +/* $NetBSD: utmp_update.c,v 1.11 2011/09/17 14:25:43 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: utmp_update.c,v 1.10 2011/09/17 01:50:54 christos Exp $"); +__RCSID("$NetBSD: utmp_update.c,v 1.11 2011/09/17 14:25:43 christos Exp $"); #include #include @@ -50,7 +50,7 @@ #include #include -static __dead void +static __dead __printflike(2, 3) void logerr(int e, const char *fmt, ...) { va_list sap, eap;
CVS commit: src/libexec/utmp_update
Module Name:src Committed By: christos Date: Sat Sep 17 01:50:54 UTC 2011 Modified Files: src/libexec/utmp_update: Makefile utmp_update.c Log Message: log to both syslog and stderr. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/libexec/utmp_update/Makefile cvs rdiff -u -r1.9 -r1.10 src/libexec/utmp_update/utmp_update.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/Makefile diff -u src/libexec/utmp_update/Makefile:1.3 src/libexec/utmp_update/Makefile:1.4 --- src/libexec/utmp_update/Makefile:1.3 Mon Dec 16 17:45:15 2002 +++ src/libexec/utmp_update/Makefile Fri Sep 16 21:50:54 2011 @@ -1,8 +1,10 @@ -# $NetBSD: Makefile,v 1.3 2002/12/16 22:45:15 wiz Exp $ +# $NetBSD: Makefile,v 1.4 2011/09/17 01:50:54 christos Exp $ PROG= utmp_update MAN= utmp_update.8 BINOWN= root BINMODE=4555 +COPTS.utmp_update.c += -Wno-format-nonliteral + .include Index: src/libexec/utmp_update/utmp_update.c diff -u src/libexec/utmp_update/utmp_update.c:1.9 src/libexec/utmp_update/utmp_update.c:1.10 --- src/libexec/utmp_update/utmp_update.c:1.9 Sun Apr 12 23:38:15 2009 +++ src/libexec/utmp_update/utmp_update.c Fri Sep 16 21:50:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: utmp_update.c,v 1.9 2009/04/13 03:38:15 christos Exp $ */ +/* $NetBSD: utmp_update.c,v 1.10 2011/09/17 01:50:54 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: utmp_update.c,v 1.9 2009/04/13 03:38:15 christos Exp $"); +__RCSID("$NetBSD: utmp_update.c,v 1.10 2011/09/17 01:50:54 christos Exp $"); #include #include @@ -46,8 +46,28 @@ #include #include #include +#include +#include +#include -int main(int, char *[]); +static __dead void +logerr(int e, const char *fmt, ...) +{ + va_list sap, eap; + char *s = NULL; + + if (e) + (void)asprintf(&s, "%s (%s)", fmt, strerror(e)); + if (s) + fmt = s; + + va_start(sap, fmt); + va_copy(eap, sap); + vsyslog(LOG_ERR, fmt, sap); + va_end(sap); + errx(1, fmt, eap); + va_end(eap); +} int main(int argc, char *argv[]) @@ -63,42 +83,45 @@ euid = geteuid(); ruid = getuid(); - if (seteuid(ruid) == -1) - err(1, "seteuid"); if (argc != 2) { (void)fprintf(stderr, "Usage: %s \n", - getprogname()); - exit(1); + getprogname()); + return 1; } + openlog(getprogname(), LOG_PID | LOG_NDELAY, LOG_AUTH); + if (seteuid(ruid) == -1) + logerr(errno, "Can't setuid %ld", (long)ruid); + len = strlen(argv[1]); if (len > sizeof(*utx) * 4 + 1 || len < sizeof(*utx)) - errx(1, "Bad argument"); + logerr(0, "Bad argument size %zu", len); if ((utx = malloc(len)) == NULL) - err(1, NULL); + logerr(errno, "Can't allocate %zu", len); res = strunvis((char *)utx, argv[1]); if (res != (int)sizeof(*utx)) - errx(1, "Decoding error %s %d != %zu", argv[1], res, sizeof(*utx)); + logerr(0, "Decoding error %s %d != %zu", argv[1], res, + sizeof(*utx)); switch (utx->ut_type) { case USER_PROCESS: case DEAD_PROCESS: break; default: - errx(1, "Invalid utmpx type %d", (int)utx->ut_type); + logerr(0, "Invalid utmpx type %d", (int)utx->ut_type); } if (ruid != 0) { if ((pwd = getpwuid(ruid)) == NULL) - errx(1, "User %lu does not exist in password database", - (long)ruid); + logerr(0, "User %ld does not exist in password" + " database", (long)ruid); if (strcmp(pwd->pw_name, utx->ut_name) != 0) - errx(1, "Current user `%s' does not match " + logerr(0, "Current user `%s' does not match " "`%s' in utmpx entry", pwd->pw_name, utx->ut_name); } @@ -106,34 +129,39 @@ fd = open(tty, O_RDONLY|O_NONBLOCK, 0); if (fd != -1) { if (fstat(fd, &st) == -1) - err(1, "Cannot stat `%s'", tty); + logerr(errno, "Cannot stat `%s'", tty); if (ruid != 0 && st.st_uid != ruid) - errx(1, "%s: Is not owned by you", tty); + logerr(0, "%s: Is not owned by you", tty); if (!isatty(fd)) - errx(1, "%s: Not a tty device", tty); + logerr(0, "%s: Not a tty device", tty); (void)close(fd); if (access(tty, W_OK|R_OK) == -1) - err(1, "%s", tty); + logerr(errno, "Can't access `%s'", tty); } else { struct utmpx utold, *utoldp; + pid_t ppid; + /* * A daemon like ftpd that does not use a tty line? * We only allow it to kill its own existing entries */ if (utx->ut_type != DEAD_PROCESS) - err(1, "Cannot open `%s'", tty); + logerr(errno, "Cannot open `%s'", tty); (void)memcpy(utold.ut_line, utx->ut_line, sizeof(utx->ut_line)); if ((utoldp = getutxline(&utold)) == NULL) - err(1, "Cannot find existing entry for `%s'", + logerr(0, "Cannot find existing entry for `%s'", utx->ut_line); - if (utoldp->ut_pid != getppid()) - err(1, "Cannot modify entry for `%s'", tty); + if (utoldp->ut_pid != (ppid = getppid())) + logerr(0, "Cannot modify entry for `%s' " + "utmp pid %ld !=
CVS commit: src/libexec/utmp_update
Module Name:src Committed By: christos Date: Mon Apr 13 03:38:15 UTC 2009 Modified Files: src/libexec/utmp_update: utmp_update.c Log Message: provide more info on decoding errors. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/libexec/utmp_update/utmp_update.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/libexec/utmp_update/utmp_update.c diff -u src/libexec/utmp_update/utmp_update.c:1.8 src/libexec/utmp_update/utmp_update.c:1.9 --- src/libexec/utmp_update/utmp_update.c:1.8 Mon Apr 28 16:23:04 2008 +++ src/libexec/utmp_update/utmp_update.c Sun Apr 12 23:38:15 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: utmp_update.c,v 1.8 2008/04/28 20:23:04 martin Exp $ */ +/* $NetBSD: utmp_update.c,v 1.9 2009/04/13 03:38:15 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: utmp_update.c,v 1.8 2008/04/28 20:23:04 martin Exp $"); +__RCSID("$NetBSD: utmp_update.c,v 1.9 2009/04/13 03:38:15 christos Exp $"); #include #include @@ -57,6 +57,7 @@ struct passwd *pwd; struct stat st; int fd; + int res; uid_t euid, ruid; char tty[MAXPATHLEN]; @@ -79,8 +80,9 @@ if ((utx = malloc(len)) == NULL) err(1, NULL); - if (strunvis((char *)utx, argv[1]) != sizeof(*utx)) - errx(1, "Decoding error"); + res = strunvis((char *)utx, argv[1]); + if (res != (int)sizeof(*utx)) + errx(1, "Decoding error %s %d != %zu", argv[1], res, sizeof(*utx)); switch (utx->ut_type) { case USER_PROCESS: