From 961e3a840fd28dbce27c3b900ed458aee6872213 Mon Sep 17 00:00:00 2001 From: jdolecek Date: Fri, 27 Sep 2002 20:42:46 +0000 Subject: [PATCH] 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 --- lib/libutil/Makefile | 5 +-- lib/libutil/login.c | 12 ++----- lib/libutil/loginx.c | 58 ++++++++++++++++++++++++++++++ lib/libutil/logout.c | 26 ++------------ lib/libutil/logoutx.c | 77 ++++++++++++++++++++++++++++++++++++++++ lib/libutil/logwtmp.c | 29 ++------------- lib/libutil/logwtmpx.c | 80 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 224 insertions(+), 63 deletions(-) create mode 100644 lib/libutil/loginx.c create mode 100644 lib/libutil/logoutx.c create mode 100644 lib/libutil/logwtmpx.c diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index a9687400339b..c4bab48931c9 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -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 diff --git a/lib/libutil/login.c b/lib/libutil/login.c index 04f9b65a2422..38c7b5c9a0ed 100644 --- a/lib/libutil/login.c +++ b/lib/libutil/login.c @@ -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 #include #include -#include 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); -} diff --git a/lib/libutil/loginx.c b/lib/libutil/loginx.c new file mode 100644 index 000000000000..9ee6a6cb4066 --- /dev/null +++ b/lib/libutil/loginx.c @@ -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 +#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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void +loginx(const struct utmpx *ut) +{ + (void)pututxline(ut); + (void)updwtmpx(_PATH_WTMPX, ut); +} diff --git a/lib/libutil/logout.c b/lib/libutil/logout.c index c824fd5ec617..ff06d3d6956a 100644 --- a/lib/libutil/logout.c +++ b/lib/libutil/logout.c @@ -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 #include -#include #include #include @@ -54,7 +53,6 @@ __RCSID("$NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $"); #include #include #include -#include 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; -} diff --git a/lib/libutil/logoutx.c b/lib/libutil/logoutx.c new file mode 100644 index 000000000000..16e51b475860 --- /dev/null +++ b/lib/libutil/logoutx.c @@ -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 +#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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index 4be0e54e11b7..bcf6cccd6f32 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -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 #include #include -#include #include #include #include #include #include -#include #include 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); -} diff --git a/lib/libutil/logwtmpx.c b/lib/libutil/logwtmpx.c new file mode 100644 index 000000000000..a0aaef51668e --- /dev/null +++ b/lib/libutil/logwtmpx.c @@ -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 +#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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +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); +}