diff options
Diffstat (limited to 'src/login.c')
-rw-r--r-- | src/login.c | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/src/login.c b/src/login.c index 7ec2401e..bb85c758 100644 --- a/src/login.c +++ b/src/login.c @@ -1,33 +1,10 @@ /* - * Copyright (c) 1989 - 1994, Julianne Frances Haugh - * Copyright (c) 1996 - 2001, Marek Michałkiewicz - * Copyright (c) 2001 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2012, Nicolas François - * All rights reserved. + * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1996 - 2001, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2001 - 2006, Tomasz Kłoczko + * SPDX-FileCopyrightText: 2007 - 2012, Nicolas François * - * 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. The name of the copyright holders or contributors may not be used to - * endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT - * HOLDERS 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. + * SPDX-License-Identifier: BSD-3-Clause */ #include <config.h> @@ -53,6 +30,7 @@ #include "pwauth.h" /*@-exitarg@*/ #include "exitcodes.h" +#include "shadowlog.h" #ifdef USE_PAM #include "pam_defs.h" @@ -83,7 +61,6 @@ static pam_handle_t *pamh = NULL; * Global variables */ const char *Prog; -FILE *shadow_logfd = NULL; static const char *hostname = ""; static /*@null@*/ /*@only@*/char *username = NULL; @@ -217,7 +194,7 @@ static void setup_tty (void) /* * ttymon invocation prefers this, but these settings - * won't come into effect after the first username login + * won't come into effect after the first username login */ (void) STTY (0, &termio); } @@ -401,7 +378,7 @@ static void init_env (void) } } #endif /* !USE_PAM */ - /* + /* * Add the clock frequency so that profiling commands work * correctly. */ @@ -520,7 +497,7 @@ static void update_utmp (const char *user, * of reasons, such as X servers or network logins. * * the flags which login supports are - * + * * -p - preserve the environment * -r - perform autologin protocol for rlogin * -f - do not perform authentication, user is preauthenticated @@ -534,7 +511,7 @@ int main (int argc, char **argv) #ifdef RLOGIN char term[128] = ""; #endif /* RLOGIN */ -#if defined(HAVE_STRFTIME) && !defined(USE_PAM) +#if !defined(USE_PAM) char ptime[80]; #endif unsigned int delay; @@ -578,7 +555,8 @@ int main (int argc, char **argv) amroot = (getuid () == 0); Prog = Basename (argv[0]); - shadow_logfd = stderr; + log_set_progname(Prog); + log_set_logfd(stderr); if (geteuid() != 0) { fprintf (stderr, _("%s: Cannot possibly work without effective root\n"), Prog); @@ -650,7 +628,7 @@ int main (int argc, char **argv) (void) umask (getdef_num ("UMASK", GETDEF_DEFAULT_UMASK)); { - /* + /* * Use the ULIMIT in the login.defs file, and if * there isn't one, use the default value. The * user may have one for themselves, but otherwise, @@ -983,12 +961,12 @@ int main (int argc, char **argv) if (strcmp (user_passwd, "") == 0) { char *prevent_no_auth = getdef_str("PREVENT_NO_AUTH"); - if(prevent_no_auth == NULL) { + if (prevent_no_auth == NULL) { prevent_no_auth = "superuser"; } - if(strcmp(prevent_no_auth, "yes") == 0) { + if (strcmp(prevent_no_auth, "yes") == 0) { failed = true; - } else if( (pwd->pw_uid == 0) + } else if ((pwd->pw_uid == 0) && (strcmp(prevent_no_auth, "superuser") == 0)) { failed = true; } @@ -1288,6 +1266,7 @@ int main (int argc, char **argv) env++; } } + (void) pam_end (pamh, PAM_SUCCESS | PAM_DATA_SILENT); #endif (void) setlocale (LC_ALL, ""); @@ -1319,16 +1298,11 @@ int main (int argc, char **argv) && (ll.ll_time != 0)) { time_t ll_time = ll.ll_time; -#ifdef HAVE_STRFTIME (void) strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", localtime (&ll_time)); printf (_("Last login: %s on %s"), ptime, ll.ll_line); -#else - printf (_("Last login: %.19s on %s"), - ctime (&ll_time), ll.ll_line); -#endif #ifdef HAVE_LL_HOST /* __linux__ || SUN4 */ if ('\0' != ll.ll_host[0]) { printf (_(" from %.*s"), |