Minor cleanups to ulog-helper:
- Remove unneeded linking against libmd. libulog depends on this library, but the ulog-helper tool itself does not. - Change the comment at the top to mention utmpx instead of utmp, wtmp and lastlog. - Simply use user_from_uid() to translate to a username string. - Put variable declarations together.
This commit is contained in:
parent
9ed9322551
commit
0ea9a5ddd4
@ -5,7 +5,7 @@ BINOWN= root
|
|||||||
BINMODE=4555
|
BINMODE=4555
|
||||||
NO_MAN=
|
NO_MAN=
|
||||||
|
|
||||||
DPADD= ${LIBULOG} ${LIBMD}
|
DPADD= ${LIBULOG}
|
||||||
LDADD= -lulog -lmd
|
LDADD= -lulog
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -36,11 +36,11 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This setuid helper utility writes user login records to disk.
|
* This setuid helper utility writes user login records to disk.
|
||||||
* Unprivileged processes are not capable of writing records to utmp,
|
* Unprivileged processes are not capable of writing records to utmpx,
|
||||||
* wtmp and lastlog, but we do want to allow this for pseudo-terminals.
|
* but we do want to allow this for pseudo-terminals. Because a file
|
||||||
* Because a file descriptor to a pseudo-terminal master device can only
|
* descriptor to a pseudo-terminal master device can only be obtained by
|
||||||
* be obtained by processes using the pseudo-terminal, we expect such a
|
* processes using the pseudo-terminal, we expect such a descriptor on
|
||||||
* descriptor on stdin.
|
* stdin.
|
||||||
*
|
*
|
||||||
* It uses the real user ID of the calling process to determine the
|
* It uses the real user ID of the calling process to determine the
|
||||||
* username. It does allow users to log arbitrary hostnames.
|
* username. It does allow users to log arbitrary hostnames.
|
||||||
@ -49,26 +49,22 @@ __FBSDID("$FreeBSD$");
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *line;
|
const char *line, *user, *host;
|
||||||
|
|
||||||
/* Device line name. */
|
/* Device line name. */
|
||||||
if ((line = ptsname(STDIN_FILENO)) == NULL)
|
if ((line = ptsname(STDIN_FILENO)) == NULL)
|
||||||
return (EX_USAGE);
|
return (EX_USAGE);
|
||||||
|
|
||||||
if ((argc == 2 || argc == 3) && strcmp(argv[1], "login") == 0) {
|
if ((argc == 2 || argc == 3) && strcmp(argv[1], "login") == 0) {
|
||||||
struct passwd *pwd;
|
|
||||||
const char *host = NULL;
|
|
||||||
|
|
||||||
/* Username. */
|
/* Username. */
|
||||||
pwd = getpwuid(getuid());
|
user = user_from_uid(getuid(), 1);
|
||||||
if (pwd == NULL)
|
if (user == NULL)
|
||||||
return (EX_OSERR);
|
return (EX_OSERR);
|
||||||
|
|
||||||
/* Hostname. */
|
/* Hostname. */
|
||||||
if (argc == 3)
|
host = argc == 3 ? argv[2] : NULL;
|
||||||
host = argv[2];
|
|
||||||
|
|
||||||
ulog_login(line, pwd->pw_name, host);
|
ulog_login(line, user, host);
|
||||||
return (EX_OK);
|
return (EX_OK);
|
||||||
} else if (argc == 2 && strcmp(argv[1], "logout") == 0) {
|
} else if (argc == 2 && strcmp(argv[1], "logout") == 0) {
|
||||||
ulog_logout(line);
|
ulog_logout(line);
|
||||||
|
Loading…
Reference in New Issue
Block a user