From: Alejandro Colomar Date: Wed, 17 Jan 2024 15:48:53 +0000 (+0100) Subject: lib/, src/, po/: pw_entry(): Move function to src/sulogin.c X-Git-Tag: 4.15.0-rc1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8679878c8b12ab8b3c7a219e821bdd6bbc468ec7;p=thirdparty%2Fshadow.git lib/, src/, po/: pw_entry(): Move function to src/sulogin.c That's the only file where it's called, and it's a delicate function. Reduce the chances that other files call it. Link: Suggested-by: Samanta Navarro Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index b437bbd39..308099fc2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -50,7 +50,6 @@ libshadow_la_SOURCES = \ date_to_str.c \ defines.h \ encrypt.c \ - entry.c \ env.c \ exitcodes.h \ faillog.h \ diff --git a/lib/entry.c b/lib/entry.c deleted file mode 100644 index 88a06b246..000000000 --- a/lib/entry.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2007 - 2008, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#ident "$Id$" - -#include -#include - -#include "alloc.h" -#include "prototypes.h" -#include "defines.h" -#include - -void pw_entry (const char *name, struct passwd *pwent) -{ - struct passwd *passwd; - - struct spwd *spwd; - - if (!(passwd = getpwnam (name))) { /* local, no need for xgetpwnam */ - pwent->pw_name = NULL; - return; - } else { - pwent->pw_name = xstrdup (passwd->pw_name); - pwent->pw_uid = passwd->pw_uid; - pwent->pw_gid = passwd->pw_gid; - pwent->pw_gecos = xstrdup (passwd->pw_gecos); - pwent->pw_dir = xstrdup (passwd->pw_dir); - pwent->pw_shell = xstrdup (passwd->pw_shell); -#if !defined(AUTOSHADOW) - /* local, no need for xgetspnam */ - if ((spwd = getspnam (name))) { - pwent->pw_passwd = xstrdup (spwd->sp_pwdp); - return; - } -#endif - pwent->pw_passwd = xstrdup (passwd->pw_passwd); - } -} diff --git a/lib/prototypes.h b/lib/prototypes.h index 0f709bdd6..6aa48e9b0 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -114,9 +114,6 @@ extern void date_to_str (size_t size, char buf[size], long date); /* encrypt.c */ extern /*@exposed@*//*@null@*/char *pw_encrypt (const char *, const char *); -/* entry.c */ -extern void pw_entry (const char *, struct passwd *); - /* env.c */ extern void addenv (const char *, /*@null@*/const char *); extern void initenv (void); diff --git a/po/POTFILES.in b/po/POTFILES.in index d6c877519..d49a54606 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -15,7 +15,6 @@ lib/console.c lib/copydir.c lib/date_to_str.c lib/encrypt.c -lib/entry.c lib/env.c lib/failure.c lib/fields.c diff --git a/src/sulogin.c b/src/sulogin.c index 0bb9d900b..95b1a48af 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -16,8 +16,10 @@ #include #include #include +#include #include "agetpass.h" +#include "alloc.h" #include "attr.h" #include "defines.h" #include "getdef.h" @@ -29,6 +31,7 @@ #include "shadowlog.h" #include "string/strtcpy.h" + /* * Global variables */ @@ -45,8 +48,10 @@ extern size_t newenvc; #define ALARM 60 #endif -/* local function prototypes */ + static void catch_signals (int); +static void pw_entry(const char *name, struct passwd *pwent); + static void catch_signals (unused int sig) { @@ -184,3 +189,31 @@ static void catch_signals (unused int sig) return ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); } + +static void +pw_entry(const char *name, struct passwd *pwent) +{ + struct passwd *passwd; + + struct spwd *spwd; + + if (!(passwd = getpwnam (name))) { /* local, no need for xgetpwnam */ + pwent->pw_name = NULL; + return; + } else { + pwent->pw_name = xstrdup (passwd->pw_name); + pwent->pw_uid = passwd->pw_uid; + pwent->pw_gid = passwd->pw_gid; + pwent->pw_gecos = xstrdup (passwd->pw_gecos); + pwent->pw_dir = xstrdup (passwd->pw_dir); + pwent->pw_shell = xstrdup (passwd->pw_shell); +#if !defined(AUTOSHADOW) + /* local, no need for xgetspnam */ + if ((spwd = getspnam (name))) { + pwent->pw_passwd = xstrdup (spwd->sp_pwdp); + return; + } +#endif + pwent->pw_passwd = xstrdup (passwd->pw_passwd); + } +}