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.
This commit is contained in:
Ed Schouten 2012-02-11 20:28:42 +00:00
parent 8211bd45bc
commit 71d8432f98
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=231530
8 changed files with 103 additions and 33 deletions

View File

@ -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 ,

View File

@ -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

View File

@ -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 .

View File

@ -306,7 +306,7 @@ SUBDIR+= usbdump
.if ${MK_UTMPX} != "no"
SUBDIR+= ac
SUBDIR+= lastlogin
SUBDIR+= utxrm
SUBDIR+= utx
.endif
.if ${MK_WIRELESS} != "no"

9
usr.sbin/utx/Makefile Normal file
View File

@ -0,0 +1,9 @@
# $FreeBSD$
PROG= utx
MAN= utx.8
LINKS= ${BINDIR}/utx ${BINDIR}/utxrm
MLINKS= utx.8 utxrm.8
.include <bsd.prog.mk>

View File

@ -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

View File

@ -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;
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);
}

View File

@ -1,6 +0,0 @@
# $FreeBSD$
PROG= utxrm
MAN= utxrm.8
.include <bsd.prog.mk>