mirror of
https://github.com/shadow-maint/shadow.git
synced 2024-11-28 04:23:56 +08:00
9adfc136b6
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.
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
/*
|
|
* myname.c - determine the current username and get the passwd entry
|
|
*
|
|
* Copyright (C) 1996 Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>
|
|
*
|
|
* This code may be freely used, modified and distributed for any purpose.
|
|
* There is no warranty, if it breaks you have to keep both pieces, etc.
|
|
* If you improve it, please send me your changes. Thanks!
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#ident "$Id$"
|
|
|
|
#include "defines.h"
|
|
#include <pwd.h>
|
|
#include "prototypes.h"
|
|
struct passwd *get_my_pwent (void)
|
|
{
|
|
struct passwd *pw;
|
|
const char *cp = getlogin ();
|
|
uid_t ruid = getuid ();
|
|
|
|
/*
|
|
* Try getlogin() first - if it fails or returns a non-existent
|
|
* username, or a username which doesn't match the real UID, fall
|
|
* back to getpwuid(getuid()). This should work reasonably with
|
|
* usernames longer than the utmp limit (8 characters), as well as
|
|
* shared UIDs - but not both at the same time...
|
|
*
|
|
* XXX - when running from su, will return the current user (not
|
|
* the original user, like getlogin() does). Does this matter?
|
|
*/
|
|
if (cp && *cp && (pw = xgetpwnam (cp)) && pw->pw_uid == ruid)
|
|
return pw;
|
|
|
|
return xgetpwuid (ruid);
|
|
}
|
|
|