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: <https://github.com/shadow-maint/shadow/pull/908> Suggested-by: Samanta Navarro <ferivoz@riseup.net> Cc: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
2e56af1902
commit
8679878c8b
@@ -50,7 +50,6 @@ libshadow_la_SOURCES = \
|
||||
date_to_str.c \
|
||||
defines.h \
|
||||
encrypt.c \
|
||||
entry.c \
|
||||
env.c \
|
||||
exitcodes.h \
|
||||
faillog.h \
|
||||
|
||||
-47
@@ -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 <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
+34
-1
@@ -16,8 +16,10 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user