diff --git a/lib/libc/gen/getutxent.3 b/lib/libc/gen/getutxent.3 index 2707ee85513c..2ea09712d8d4 100644 --- a/lib/libc/gen/getutxent.3 +++ b/lib/libc/gen/getutxent.3 @@ -423,7 +423,7 @@ The file format is invalid. .Xr tty 4 , .Xr ac 8 , .Xr newsyslog 8 , -.Xr utxrm 8 +.Xr utx 8 .Sh STANDARDS The .Fn endutxent , diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index bcbae9c542e6..5aab001915e8 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -3407,6 +3407,7 @@ OLD_FILES+=usr/bin/who OLD_FILES+=usr/bin/wtmpcvt OLD_FILES+=usr/sbin/ac OLD_FILES+=usr/sbin/lastlogin +OLD_FILES+=usr/sbin/utx OLD_FILES+=usr/sbin/utxrm OLD_FILES+=usr/share/man/man1/last.1.gz OLD_FILES+=usr/share/man/man1/users.1.gz @@ -3414,6 +3415,7 @@ OLD_FILES+=usr/share/man/man1/who.1.gz OLD_FILES+=usr/share/man/man1/wtmpcvt.1.gz OLD_FILES+=usr/share/man/man8/ac.8.gz OLD_FILES+=usr/share/man/man8/lastlogin.8.gz +OLD_FILES+=usr/share/man/man8/utx.8.gz OLD_FILES+=usr/share/man/man8/utxrm.8.gz .endif diff --git a/tools/build/options/WITHOUT_UTMPX b/tools/build/options/WITHOUT_UTMPX index 3c98f28b4087..80be74ebf02b 100644 --- a/tools/build/options/WITHOUT_UTMPX +++ b/tools/build/options/WITHOUT_UTMPX @@ -6,4 +6,4 @@ Set to not build user accounting tools such as .Xr ac 8 , .Xr lastlogin 8 and -.Xr utxrm 8 . +.Xr utx 8 . diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile index b7ea932b84bf..fa9883d1e90c 100644 --- a/usr.sbin/Makefile +++ b/usr.sbin/Makefile @@ -306,7 +306,7 @@ SUBDIR+= usbdump .if ${MK_UTMPX} != "no" SUBDIR+= ac SUBDIR+= lastlogin -SUBDIR+= utxrm +SUBDIR+= utx .endif .if ${MK_WIRELESS} != "no" diff --git a/usr.sbin/utx/Makefile b/usr.sbin/utx/Makefile new file mode 100644 index 000000000000..a70c71c508e8 --- /dev/null +++ b/usr.sbin/utx/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD$ + +PROG= utx +MAN= utx.8 + +LINKS= ${BINDIR}/utx ${BINDIR}/utxrm +MLINKS= utx.8 utxrm.8 + +.include diff --git a/usr.sbin/utxrm/utxrm.8 b/usr.sbin/utx/utx.8 similarity index 72% rename from usr.sbin/utxrm/utxrm.8 rename to usr.sbin/utx/utx.8 index 8b43f1aeaac4..d4e043989720 100644 --- a/usr.sbin/utxrm/utxrm.8 +++ b/usr.sbin/utx/utx.8 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2011 Ed Schouten +.\" Copyright (c) 2011-2012 Ed Schouten .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,20 +24,46 @@ .\" .\" $FreeBSD$ .\" -.Dd February 19, 2011 -.Dt UTXRM 8 +.Dd February 11, 2012 +.Dt UTX 8 .Os .Sh NAME +.Nm utx , .Nm utxrm -.Nd remove sessions from the user accounting database +.Nd manage the user accounting database .Sh SYNOPSIS .Nm +.Cm boot +.Nm +.Cm shutdown +.Nm +.Cm rm +.Ar identifier +.Ar ... +.Nm utxrm .Ar identifier .Ar ... .Sh DESCRIPTION The .Nm -utility can be used to remove stale sessions from the user accounting +utility can be used to perform operations on the user accounting +database, as done by +.Xr pututxline 3 . +.Pp +The first argument to +.Nm +indicates an action to be performed: +.Bl -tag -width ".Cm shutdown" +.It Cm boot +Write a boot time record to the user accounting database. +This option should typically only be used by +.Xr rc 8 . +.It Cm shutdown +Write a shutdown time record to the user accounting database. +This option should typically only be used by +.Xr rc 8 . +.It Cm rm +Remove stale sessions from the user accounting database, by referring to their .Ar identifier . Stale sessions can occur if a login service exits prematurely or fails @@ -57,6 +83,13 @@ Identifiers can either be supplied in hexadecimal form as displayed by .Xr getent 1 , or as a string if the identifier allows such a representation. .Pp +To remain backward compatible, this action can also be invoked directly +by using the +.Nm utxrm +command. +.El +.Pp +.Pp Because this utility requires write-access to the user accounting database, its use is limited to the super-user. .Sh SEE ALSO @@ -66,7 +99,9 @@ database, its use is limited to the super-user. .Sh HISTORY The .Nm -utility appeared in -.Fx 9.0 . +utility replaced +.Nm utxrm +in +.Fx 10.0 . .Sh AUTHORS .An Ed Schouten Aq ed@FreeBSD.org diff --git a/usr.sbin/utxrm/utxrm.c b/usr.sbin/utx/utx.c similarity index 65% rename from usr.sbin/utxrm/utxrm.c rename to usr.sbin/utx/utx.c index 3c2eadddef65..99d9591ff3fe 100644 --- a/usr.sbin/utxrm/utxrm.c +++ b/usr.sbin/utx/utx.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2011 Ed Schouten + * Copyright (c) 2011-2012 Ed Schouten * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -47,38 +48,67 @@ b16_pton(const char *in, char *out, size_t len) return (0); } -int -main(int argc, char *argv[]) +static int +rm(char *id[]) { struct utmpx utx = { .ut_type = DEAD_PROCESS }; size_t len; - int i, ret = 0; + int ret = 0; - if (argc < 2) { - fprintf(stderr, "usage: utxrm identifier ...\n"); - return (1); - } - - gettimeofday(&utx.ut_tv, NULL); - for (i = 1; i < argc; i++) { - len = strlen(argv[i]); + (void)gettimeofday(&utx.ut_tv, NULL); + for (; *id != NULL; id++) { + len = strlen(*id); if (len <= sizeof(utx.ut_id)) { /* Identifier as string. */ - strncpy(utx.ut_id, argv[i], sizeof(utx.ut_id)); + strncpy(utx.ut_id, *id, sizeof(utx.ut_id)); } else if (len != sizeof(utx.ut_id) * 2 || - b16_pton(argv[i], utx.ut_id, sizeof(utx.ut_id)) != 0) { + b16_pton(*id, utx.ut_id, sizeof(utx.ut_id)) != 0) { /* Also not hexadecimal. */ - fprintf(stderr, "%s: Invalid identifier format\n", - argv[i]); + fprintf(stderr, "%s: Invalid identifier format\n", *id); ret = 1; continue; } /* Zap the entry. */ if (pututxline(&utx) == NULL) { - perror(argv[i]); + perror(*id); ret = 1; } } return (ret); } + +static int +boot(short type) +{ + struct utmpx utx = { .ut_type = type }; + + (void)gettimeofday(&utx.ut_tv, NULL); + if (pututxline(&utx) == NULL) { + perror("pututxline"); + return (1); + } + return (0); +} + +int +main(int argc, char *argv[]) +{ + + if (argc >= 2 && strcmp(getprogname(), "utxrm") == 0) + /* For compatibility. */ + return (rm(&argv[1])); + else if (argc == 2 && strcmp(argv[1], "boot") == 0) + return (boot(BOOT_TIME)); + else if (argc == 2 && strcmp(argv[1], "shutdown") == 0) + return (boot(SHUTDOWN_TIME)); + else if (argc >= 3 && strcmp(argv[1], "rm") == 0) + return (rm(&argv[2])); + + fprintf(stderr, + "usage: utx boot\n" + " utx shutdown\n" + " utx rm identifier ...\n" + " utxrm identifier ...\n"); + exit(1); +} diff --git a/usr.sbin/utxrm/Makefile b/usr.sbin/utxrm/Makefile deleted file mode 100644 index cf38b816f2e5..000000000000 --- a/usr.sbin/utxrm/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= utxrm -MAN= utxrm.8 - -.include