Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec Add utmp_update



details:   https://anonhg.NetBSD.org/src/rev/1ebb297e95b4
branches:  trunk
changeset: 534514:1ebb297e95b4
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 28 22:38:50 2002 +0000

description:
Add utmp_update

diffstat:

 libexec/Makefile                  |    4 +-
 libexec/utmp_update/Makefile      |    8 ++
 libexec/utmp_update/utmp_update.c |  107 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 2 deletions(-)

diffs (141 lines):

diff -r 2b3d089168bd -r 1ebb297e95b4 libexec/Makefile
--- a/libexec/Makefile  Sun Jul 28 22:18:51 2002 +0000
+++ b/libexec/Makefile  Sun Jul 28 22:38:50 2002 +0000
@@ -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 -r 2b3d089168bd -r 1ebb297e95b4 libexec/utmp_update/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/libexec/utmp_update/Makefile      Sun Jul 28 22:38:50 2002 +0000
@@ -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 -r 2b3d089168bd -r 1ebb297e95b4 libexec/utmp_update/utmp_update.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/libexec/utmp_update/utmp_update.c Sun Jul 28 22:38:50 2002 +0000
@@ -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;
+}



Home | Main Index | Thread Index | Old Index