diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:37 +0000 |
commit | b6b00dd55e035bfbe311a527b567962ffa77ee43 (patch) | |
tree | cafc4d13785448e5a78bd40a51697ee07f07ac12 /lib/sgetpwent.c | |
parent | Adding debian version 1:4.13+dfsg1-5. (diff) | |
download | shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.tar.xz shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.zip |
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/sgetpwent.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/sgetpwent.c b/lib/sgetpwent.c index 1c8c63e..75c9177 100644 --- a/lib/sgetpwent.c +++ b/lib/sgetpwent.c @@ -12,9 +12,11 @@ #ident "$Id$" #include <sys/types.h> -#include "defines.h" #include <stdio.h> #include <pwd.h> +#include <string.h> + +#include "defines.h" #include "prototypes.h" #include "shadowlog_internal.h" @@ -32,7 +34,8 @@ * performance reasons. I am going to come up with some conditional * compilation glarp to improve on this in the future. */ -struct passwd *sgetpwent (const char *buf) +struct passwd * +sgetpwent(const char *buf) { static struct passwd pwent; static char pwdbuf[PASSWD_ENTRY_MAX_LENGTH]; @@ -58,19 +61,8 @@ struct passwd *sgetpwent (const char *buf) * field. The fields are converted into NUL terminated strings. */ - for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) { - fields[i] = cp; - while (('\0' != *cp) && (':' != *cp)) { - cp++; - } - - if ('\0' != *cp) { - *cp = '\0'; - cp++; - } else { - cp = NULL; - } - } + for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) + fields[i] = strsep(&cp, ":"); /* something at the end, columns over shot */ if ( cp != NULL ) { @@ -94,10 +86,10 @@ struct passwd *sgetpwent (const char *buf) pwent.pw_name = fields[0]; pwent.pw_passwd = fields[1]; - if (get_uid (fields[2], &pwent.pw_uid) == 0) { + if (get_uid(fields[2], &pwent.pw_uid) == -1) { return NULL; } - if (get_gid (fields[3], &pwent.pw_gid) == 0) { + if (get_gid(fields[3], &pwent.pw_gid) == -1) { return NULL; } pwent.pw_gecos = fields[4]; |