* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c, libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c: Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(), xgetgrgid(), and xgetspnam(). They allocate memory for the returned structure and are more robust to successive calls. They are implemented with the libc's getxxyyy_r() functions if available. * libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c, libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c, libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c, src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c, src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c, src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c, src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/groupadd.c, src/chage.c, src/login.c, src/suauth.c, src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the usage of one of the getpwnam(), getpwuid(), getgrnam(), getgrgid(), and getspnam() functions. It was noticed on http://bugs.debian.org/341230 that chfn and chsh use a passwd structure after calling a pam function, which result in using information from the passwd structure requested by pam, not the original one. It is much easier to use the new xget... functions to avoid these issues. I've checked which call to the original get... functions could be left (reducing the scope of the structure if possible), and I've left comments to ease future reviews (e.g. /* local, no need for xgetpwnam */). Note: the getpwent/getgrent calls should probably be checked also. * src/groupdel.c, src/expiry.c: Fix typos in comments. * src/groupmod.c: Re-indent. * libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c, lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup functions (used by the xget... functions) from the <xx>io.c files to the new <xx>mem.c files. This avoid linking some utils against the SELinux library.
This commit is contained in:
@@ -10,32 +10,6 @@
|
||||
extern int putgrent (const struct group *, FILE *);
|
||||
extern struct group *sgetgrent (const char *);
|
||||
|
||||
struct group *__gr_dup (const struct group *grent)
|
||||
{
|
||||
struct group *gr;
|
||||
int i;
|
||||
|
||||
if (!(gr = (struct group *) malloc (sizeof *gr)))
|
||||
return NULL;
|
||||
*gr = *grent;
|
||||
if (!(gr->gr_name = strdup (grent->gr_name)))
|
||||
return NULL;
|
||||
if (!(gr->gr_passwd = strdup (grent->gr_passwd)))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; grent->gr_mem[i]; i++);
|
||||
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
||||
if (!gr->gr_mem)
|
||||
return NULL;
|
||||
for (i = 0; grent->gr_mem[i]; i++) {
|
||||
gr->gr_mem[i] = strdup (grent->gr_mem[i]);
|
||||
if (!gr->gr_mem[i])
|
||||
return NULL;
|
||||
}
|
||||
gr->gr_mem[i] = NULL;
|
||||
return gr;
|
||||
}
|
||||
|
||||
static void *group_dup (const void *ent)
|
||||
{
|
||||
const struct group *gr = ent;
|
||||
|
35
lib/groupmem.c
Normal file
35
lib/groupmem.c
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id: groupio.c 1342 2007-11-10 23:46:11Z nekral-guest $"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "groupio.h"
|
||||
|
||||
struct group *__gr_dup (const struct group *grent)
|
||||
{
|
||||
struct group *gr;
|
||||
int i;
|
||||
|
||||
if (!(gr = (struct group *) malloc (sizeof *gr)))
|
||||
return NULL;
|
||||
*gr = *grent;
|
||||
if (!(gr->gr_name = strdup (grent->gr_name)))
|
||||
return NULL;
|
||||
if (!(gr->gr_passwd = strdup (grent->gr_passwd)))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; grent->gr_mem[i]; i++);
|
||||
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
||||
if (!gr->gr_mem)
|
||||
return NULL;
|
||||
for (i = 0; grent->gr_mem[i]; i++) {
|
||||
gr->gr_mem[i] = strdup (grent->gr_mem[i]);
|
||||
if (!gr->gr_mem[i])
|
||||
return NULL;
|
||||
}
|
||||
gr->gr_mem[i] = NULL;
|
||||
return gr;
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include "shadowio.h"
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
@@ -179,4 +180,15 @@ extern int valid (const char *, const struct passwd *);
|
||||
extern char *xmalloc (size_t);
|
||||
extern char *xstrdup (const char *);
|
||||
|
||||
/* xgetpwnam.c */
|
||||
extern struct passwd *xgetpwnam (const char *);
|
||||
/* xgetpwuid.c */
|
||||
extern struct passwd *xgetpwuid (uid_t);
|
||||
/* xgetgrnam.c */
|
||||
extern struct group *xgetgrnam (const char *);
|
||||
/* xgetgrgid.c */
|
||||
extern struct group *xgetgrgid (gid_t);
|
||||
/* xgetspnam.c */
|
||||
extern struct spwd *xgetspnam(const char *);
|
||||
|
||||
#endif /* _PROTOTYPES_H */
|
||||
|
20
lib/pwio.c
20
lib/pwio.c
@@ -12,26 +12,6 @@
|
||||
extern struct passwd *sgetpwent (const char *);
|
||||
extern int putpwent (const struct passwd *, FILE *);
|
||||
|
||||
struct passwd *__pw_dup (const struct passwd *pwent)
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
||||
if (!(pw = (struct passwd *) malloc (sizeof *pw)))
|
||||
return NULL;
|
||||
*pw = *pwent;
|
||||
if (!(pw->pw_name = strdup (pwent->pw_name)))
|
||||
return NULL;
|
||||
if (!(pw->pw_passwd = strdup (pwent->pw_passwd)))
|
||||
return NULL;
|
||||
if (!(pw->pw_gecos = strdup (pwent->pw_gecos)))
|
||||
return NULL;
|
||||
if (!(pw->pw_dir = strdup (pwent->pw_dir)))
|
||||
return NULL;
|
||||
if (!(pw->pw_shell = strdup (pwent->pw_shell)))
|
||||
return NULL;
|
||||
return pw;
|
||||
}
|
||||
|
||||
static void *passwd_dup (const void *ent)
|
||||
{
|
||||
const struct passwd *pw = ent;
|
||||
|
31
lib/pwmem.c
Normal file
31
lib/pwmem.c
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id: pwio.c 1342 2007-11-10 23:46:11Z nekral-guest $"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include "pwio.h"
|
||||
|
||||
struct passwd *__pw_dup (const struct passwd *pwent)
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
||||
if (!(pw = (struct passwd *) malloc (sizeof *pw)))
|
||||
return NULL;
|
||||
*pw = *pwent;
|
||||
if (!(pw->pw_name = strdup (pwent->pw_name)))
|
||||
return NULL;
|
||||
if (!(pw->pw_passwd = strdup (pwent->pw_passwd)))
|
||||
return NULL;
|
||||
if (!(pw->pw_gecos = strdup (pwent->pw_gecos)))
|
||||
return NULL;
|
||||
if (!(pw->pw_dir = strdup (pwent->pw_dir)))
|
||||
return NULL;
|
||||
if (!(pw->pw_shell = strdup (pwent->pw_shell)))
|
||||
return NULL;
|
||||
return pw;
|
||||
}
|
||||
|
@@ -11,19 +11,6 @@
|
||||
#include <stdio.h>
|
||||
#include "commonio.h"
|
||||
#include "shadowio.h"
|
||||
struct spwd *__spw_dup (const struct spwd *spent)
|
||||
{
|
||||
struct spwd *sp;
|
||||
|
||||
if (!(sp = (struct spwd *) malloc (sizeof *sp)))
|
||||
return NULL;
|
||||
*sp = *spent;
|
||||
if (!(sp->sp_namp = strdup (spent->sp_namp)))
|
||||
return NULL;
|
||||
if (!(sp->sp_pwdp = strdup (spent->sp_pwdp)))
|
||||
return NULL;
|
||||
return sp;
|
||||
}
|
||||
|
||||
static void *shadow_dup (const void *ent)
|
||||
{
|
||||
|
27
lib/shadowmem.c
Normal file
27
lib/shadowmem.c
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id: shadowio.c 1342 2007-11-10 23:46:11Z nekral-guest $"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#ifdef HAVE_SHADOW_H
|
||||
# include <shadow.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include "shadowio.h"
|
||||
|
||||
struct spwd *__spw_dup (const struct spwd *spent)
|
||||
{
|
||||
struct spwd *sp;
|
||||
|
||||
if (!(sp = (struct spwd *) malloc (sizeof *sp)))
|
||||
return NULL;
|
||||
*sp = *spent;
|
||||
if (!(sp->sp_namp = strdup (spent->sp_namp)))
|
||||
return NULL;
|
||||
if (!(sp->sp_pwdp = strdup (spent->sp_pwdp)))
|
||||
return NULL;
|
||||
return sp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user