diff options
| author | christos <christos@NetBSD.org> | 2002-07-28 22:38:50 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2002-07-28 22:38:50 +0000 |
| commit | aa3ec0641b6d34c8a99614781109068aaa263a0a (patch) | |
| tree | a98907e575e88a9f9ad652fd136a1ee2dee69c84 /libexec | |
| parent | 08a69f7d150c2caae6052fb79b9a29bcdce1399c (diff) | |
Add utmp_update
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/Makefile | 4 | ||||
| -rw-r--r-- | libexec/utmp_update/Makefile | 8 | ||||
| -rw-r--r-- | libexec/utmp_update/utmp_update.c | 107 |
3 files changed, 117 insertions, 2 deletions
diff --git a/libexec/Makefile b/libexec/Makefile index e3745ed3f91..119c44857fb 100644 --- a/libexec/Makefile +++ b/libexec/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.41 2002/03/22 18:10:21 thorpej Exp $ +# $NetBSD: Makefile,v 1.42 2002/07/28 22:38:50 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/4/93 .include <bsd.own.mk> @@ -6,7 +6,7 @@ SUBDIR= atrun comsat fingerd ftpd getNAME getty identd ld.aout_so \ ld.elf_so lfs_cleanerd mail.local makekey makewhatis rexecd \ rlogind rmail rshd rpc.rquotad rpc.rstatd rpc.rusersd rpc.rwalld \ - rpc.sprayd talkd telnetd tftpd uucpd + rpc.sprayd talkd telnetd tftpd utmp_update uucpd .if (${MKKERBEROS} != "no") # Heimdal/KTH Kerberos diff --git a/libexec/utmp_update/Makefile b/libexec/utmp_update/Makefile new file mode 100644 index 00000000000..3ed5fcfa8cd --- /dev/null +++ b/libexec/utmp_update/Makefile @@ -0,0 +1,8 @@ +# $NetBSD: Makefile,v 1.1 2002/07/28 22:38:50 christos Exp $ + +PROG= utmp_update +NOMAN= 1 +BINOWN= root +BINMODE=4555 + +.include <bsd.prog.mk> diff --git a/libexec/utmp_update/utmp_update.c b/libexec/utmp_update/utmp_update.c new file mode 100644 index 00000000000..cdcdbfb0cc3 --- /dev/null +++ b/libexec/utmp_update/utmp_update.c @@ -0,0 +1,107 @@ +/* $NetBSD: utmp_update.c,v 1.1 2002/07/28 22:38:51 christos Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/stat.h> + +#include <stdio.h> +#include <vis.h> +#include <err.h> +#include <pwd.h> +#include <utmpx.h> +#include <stdlib.h> +#include <unistd.h> + +int main(int, char *[]); + +int +main(int argc, char *argv[]) +{ + struct utmpx *utx; + size_t len; + struct passwd *pwd; + struct stat st; + + if (argc != 1) { + (void)fprintf(stderr, "Usage: %s <vis-utmpx-entry>\n", + getprogname()); + exit(1); + } + + len = strlen(argv[1]); + + if (len > sizeof(*utx) * 4 + 1 || len < sizeof(*utx)) + errx(1, "Bad argument"); + + if ((utx = malloc(len)) == NULL) + err(1, NULL); + + if (strunvis((char *)utx, argv[1]) != sizeof(*utx)) + errx(1, "Decoding error"); + + switch (utx->ut_type) { + case USER_PROCESS: + case DEAD_PROCESS: + break; + default: + errx(1, "Invalid utmpx type %d\n", (int)utx->ut_type); + } + + if ((pwd = getpwuid(getuid())) == NULL) + errx(1, "User %lu does not exist in password database", + (long)getuid()); + + if (strcmp(pwd->pw_name, utx->ut_name) != 0) + errx(1, "Current user `%s' does not match `%s' in utmpx entry", + pwd->pw_name, utx->ut_name); + + if (stat(utx->ut_line, &st) == -1) + err(1, "Cannot stat `%s'", utx->ut_line); + + if (!S_ISCHR(st.st_mode)) + errx(1, "%s: Not a character device", utx->ut_line); + + /* + * to check if the tty is writable here is problematic. First we + * don't even know if it is a tty, secondly we are setuid so it + * is not trivial to use access + */ + + pututxline(utx); + + return 0; +} |
