diff options
author | ed <ed@FreeBSD.org> | 2012-02-11 20:28:42 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2012-02-11 20:28:42 +0000 |
commit | 6d383df7bbf4128ee89ccfd6cf0af3ab50607ab2 (patch) | |
tree | b5e969c649f6d4459953e3a03fc43fbde8207e41 | |
parent | dacbfe950a81e3904fb15609934754d23432a328 (diff) | |
download | FreeBSD-src-6d383df7bbf4128ee89ccfd6cf0af3ab50607ab2.zip FreeBSD-src-6d383df7bbf4128ee89ccfd6cf0af3ab50607ab2.tar.gz |
Replace utxrm(8) by utx(8).
At first, I added a utility called utxrm(8) to remove stale entries from
the user accounting database. It seems there are cases in which we need
to perform different operations on the database as well. Simply rename
utxrm(8) to utx(8) and place the old code under the "rm" command.
In addition to "rm", this tool supports "boot" and "shutdown", which are
going to be used by an rc-script which I am going to commit separately.
-rw-r--r-- | lib/libc/gen/getutxent.3 | 2 | ||||
-rw-r--r-- | tools/build/mk/OptionalObsoleteFiles.inc | 2 | ||||
-rw-r--r-- | tools/build/options/WITHOUT_UTMPX | 2 | ||||
-rw-r--r-- | usr.sbin/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/utx/Makefile | 9 | ||||
-rw-r--r-- | usr.sbin/utx/utx.8 (renamed from usr.sbin/utxrm/utxrm.8) | 49 | ||||
-rw-r--r-- | usr.sbin/utx/utx.c (renamed from usr.sbin/utxrm/utxrm.c) | 64 | ||||
-rw-r--r-- | usr.sbin/utxrm/Makefile | 6 |
8 files changed, 103 insertions, 33 deletions
diff --git a/lib/libc/gen/getutxent.3 b/lib/libc/gen/getutxent.3 index 2707ee8..2ea0971 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 bcbae9c..5aab001 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 3c98f28..80be74eb 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 b7ea932..fa9883d 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 0000000..a70c71c --- /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 <bsd.prog.mk> diff --git a/usr.sbin/utxrm/utxrm.8 b/usr.sbin/utx/utx.8 index 8b43f1a..d4e0439 100644 --- a/usr.sbin/utxrm/utxrm.8 +++ b/usr.sbin/utx/utx.8 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org> +.\" Copyright (c) 2011-2012 Ed Schouten <ed@FreeBSD.org> .\" 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 index 3c2eadd..99d9591 100644 --- a/usr.sbin/utxrm/utxrm.c +++ b/usr.sbin/utx/utx.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org> + * Copyright (c) 2011-2012 Ed Schouten <ed@FreeBSD.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <ctype.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <utmpx.h> @@ -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; - - if (argc < 2) { - fprintf(stderr, "usage: utxrm identifier ...\n"); - return (1); - } + int ret = 0; - 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 cf38b81..0000000 --- a/usr.sbin/utxrm/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= utxrm -MAN= utxrm.8 - -.include <bsd.prog.mk> |