put utmpx/wtmpx routines to separate files, so that programs overriding the

utmp/wtmp routines could still be linked static
fixes e.g. static build of ftpd
This commit is contained in:
jdolecek 2002-09-27 20:42:46 +00:00
parent bf97c13c6c
commit 961e3a840f
7 changed files with 224 additions and 63 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.38 2002/09/27 15:02:26 wiz Exp $
# $NetBSD: Makefile,v 1.39 2002/09/27 20:42:46 jdolecek Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@ -8,7 +8,8 @@ USE_SHLIBDIR= yes
LIB= util
CPPFLAGS+=-DLIBC_SCCS
SRCS= fparseln.c getbootfile.c getmaxpartitions.c getrawpartition.c \
login.c login_cap.c login_tty.c logout.c logwtmp.c opendisk.c \
login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
logwtmp.c logwtmpx.c opendisk.c \
passwd.c pw_scan.c pidfile.c pidlock.c pty.c secure_path.c \
snprintb.c ttyaction.c ttymsg.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: login.c,v 1.14 2002/07/27 23:49:23 christos Exp $ */
/* $NetBSD: login.c,v 1.15 2002/09/27 20:42:47 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: login.c,v 1.14 2002/07/27 23:49:23 christos Exp $");
__RCSID("$NetBSD: login.c,v 1.15 2002/09/27 20:42:47 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -52,7 +52,6 @@ __RCSID("$NetBSD: login.c,v 1.14 2002/07/27 23:49:23 christos Exp $");
#include <unistd.h>
#include <util.h>
#include <utmp.h>
#include <utmpx.h>
void
login(const struct utmp *ut)
@ -73,10 +72,3 @@ login(const struct utmp *ut)
(void)close(fd);
}
}
void
loginx(const struct utmpx *ut)
{
(void)pututxline(ut);
(void)updwtmpx(_PATH_WTMPX, ut);
}

58
lib/libutil/loginx.c Normal file
View File

@ -0,0 +1,58 @@
/* $NetBSD: loginx.c,v 1.1 2002/09/27 20:42:48 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: loginx.c,v 1.1 2002/09/27 20:42:48 jdolecek Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <util.h>
#include <utmp.h>
#include <utmpx.h>
void
loginx(const struct utmpx *ut)
{
(void)pututxline(ut);
(void)updwtmpx(_PATH_WTMPX, ut);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $ */
/* $NetBSD: logout.c,v 1.14 2002/09/27 20:42:48 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
@ -38,13 +38,12 @@
#if 0
static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $");
__RCSID("$NetBSD: logout.c,v 1.14 2002/09/27 20:42:48 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <assert.h>
#include <fcntl.h>
@ -54,7 +53,6 @@ __RCSID("$NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $");
#include <unistd.h>
#include <util.h>
#include <utmp.h>
#include <utmpx.h>
int
logout(const char *line)
@ -80,23 +78,3 @@ logout(const char *line)
(void)close(fd);
return(rval);
}
int
logoutx(const char *line, int status, int type)
{
struct utmpx *utp, ut;
(void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
if ((utp = getutxline(&ut)) == NULL) {
endutxent();
return 0;
}
utp->ut_type = type;
if (WIFEXITED(status))
utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
if (WIFSIGNALED(status))
utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status);
(void)gettimeofday(&utp->ut_tv, NULL);
(void)pututxline(utp);
endutxent();
return 1;
}

77
lib/libutil/logoutx.c Normal file
View File

@ -0,0 +1,77 @@
/* $NetBSD: logoutx.c,v 1.1 2002/09/27 20:42:48 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: logoutx.c,v 1.1 2002/09/27 20:42:48 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <util.h>
#include <utmp.h>
#include <utmpx.h>
int
logoutx(const char *line, int status, int type)
{
struct utmpx *utp, ut;
(void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
if ((utp = getutxline(&ut)) == NULL) {
endutxent();
return 0;
}
utp->ut_type = type;
if (WIFEXITED(status))
utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
if (WIFSIGNALED(status))
utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status);
(void)gettimeofday(&utp->ut_tv, NULL);
(void)pututxline(utp);
endutxent();
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: logwtmp.c,v 1.12 2002/07/27 23:49:23 christos Exp $ */
/* $NetBSD: logwtmp.c,v 1.13 2002/09/27 20:42:49 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: logwtmp.c,v 1.12 2002/07/27 23:49:23 christos Exp $");
__RCSID("$NetBSD: logwtmp.c,v 1.13 2002/09/27 20:42:49 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -46,14 +46,12 @@ __RCSID("$NetBSD: logwtmp.c,v 1.12 2002/07/27 23:49:23 christos Exp $");
#include <sys/file.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
#include <utmpx.h>
#include <util.h>
void
@ -79,26 +77,3 @@ logwtmp(const char *line, const char *name, const char *host)
}
(void) close(fd);
}
void
logwtmpx(const char *line, const char *name, const char *host, int status,
int type)
{
struct utmpx ut;
_DIAGASSERT(line != NULL);
_DIAGASSERT(name != NULL);
_DIAGASSERT(host != NULL);
(void)memset(&ut, 0, sizeof(ut));
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
ut.ut_type = type;
if (WIFEXITED(status))
ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
if (WIFSIGNALED(status))
ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
(void)gettimeofday(&ut.ut_tv, NULL);
(void)updwtmpx(_PATH_WTMPX, &ut);
}

80
lib/libutil/logwtmpx.c Normal file
View File

@ -0,0 +1,80 @@
/* $NetBSD: logwtmpx.c,v 1.1 2002/09/27 20:42:50 jdolecek Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: logwtmpx.c,v 1.1 2002/09/27 20:42:50 jdolecek Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/file.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
#include <utmpx.h>
#include <util.h>
void
logwtmpx(const char *line, const char *name, const char *host, int status,
int type)
{
struct utmpx ut;
_DIAGASSERT(line != NULL);
_DIAGASSERT(name != NULL);
_DIAGASSERT(host != NULL);
(void)memset(&ut, 0, sizeof(ut));
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
ut.ut_type = type;
if (WIFEXITED(status))
ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
if (WIFSIGNALED(status))
ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
(void)gettimeofday(&ut.ut_tv, NULL);
(void)updwtmpx(_PATH_WTMPX, &ut);
}