diff options
Diffstat (limited to 'src/utils/lib/pwdutils.c')
-rw-r--r-- | src/utils/lib/pwdutils.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/utils/lib/pwdutils.c b/src/utils/lib/pwdutils.c index d97020c..1c1f13e 100644 --- a/src/utils/lib/pwdutils.c +++ b/src/utils/lib/pwdutils.c @@ -3,6 +3,7 @@ * it what you wish. */ #include <stdlib.h> +#include <assert.h> #include "c.h" #include "pwdutils.h" @@ -17,8 +18,8 @@ struct passwd *xgetpwnam(const char *username, char **pwdbuf) struct passwd *pwd = NULL, *res = NULL; int rc; - if (!pwdbuf || !username) - return NULL; + assert(pwdbuf); + assert(username); *pwdbuf = xmalloc(UL_GETPW_BUFSIZ); pwd = xcalloc(1, sizeof(struct passwd)); @@ -49,8 +50,8 @@ struct group *xgetgrnam(const char *groupname, char **grpbuf) struct group *grp = NULL, *res = NULL; int rc; - if (!grpbuf || !groupname) - return NULL; + assert(grpbuf); + assert(groupname); *grpbuf = xmalloc(UL_GETPW_BUFSIZ); grp = xcalloc(1, sizeof(struct group)); @@ -77,8 +78,7 @@ struct passwd *xgetpwuid(uid_t uid, char **pwdbuf) struct passwd *pwd = NULL, *res = NULL; int rc; - if (!pwdbuf) - return NULL; + assert(pwdbuf); *pwdbuf = xmalloc(UL_GETPW_BUFSIZ); pwd = xcalloc(1, sizeof(struct passwd)); @@ -104,11 +104,6 @@ char *xgetlogin(void) { struct passwd *pw = NULL; uid_t ruid; - char *user; - - user = getlogin(); - if (user) - return xstrdup(user); /* GNU Hurd implementation has an extension where a process can exist in a * non-conforming environment, and thus be outside the realms of POSIX @@ -117,6 +112,9 @@ char *xgetlogin(void) * environment. * * http://austingroupbugs.net/view.php?id=511 + * + * The same implementation is useful for other systems, since getlogin(3) + * shouldn't be used as actual identification. */ errno = 0; ruid = getuid(); |