Add utmp_update
This commit is contained in:
parent
08a69f7d15
commit
aa3ec0641b
libexec
@ -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
|
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||||
|
|
||||||
.include <bsd.own.mk>
|
.include <bsd.own.mk>
|
||||||
@ -6,7 +6,7 @@
|
|||||||
SUBDIR= atrun comsat fingerd ftpd getNAME getty identd ld.aout_so \
|
SUBDIR= atrun comsat fingerd ftpd getNAME getty identd ld.aout_so \
|
||||||
ld.elf_so lfs_cleanerd mail.local makekey makewhatis rexecd \
|
ld.elf_so lfs_cleanerd mail.local makekey makewhatis rexecd \
|
||||||
rlogind rmail rshd rpc.rquotad rpc.rstatd rpc.rusersd rpc.rwalld \
|
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")
|
.if (${MKKERBEROS} != "no")
|
||||||
# Heimdal/KTH Kerberos
|
# Heimdal/KTH Kerberos
|
||||||
|
8
libexec/utmp_update/Makefile
Normal file
8
libexec/utmp_update/Makefile
Normal file
@ -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>
|
107
libexec/utmp_update/utmp_update.c
Normal file
107
libexec/utmp_update/utmp_update.c
Normal file
@ -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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user