Skip to content

Commit

Permalink
lib/, src/: get_uid(): Use the usual -1 as an error code
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Jan 5, 2024
1 parent 470baea commit 18c428a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/get_uid.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/


#include <config.h>

#ident "$Id$"

#include "prototypes.h"
#include "defines.h"

int get_uid (const char *uidstr, uid_t *uid)

int
get_uid(const char *uidstr, uid_t *uid)
{
long long val;
char *endptr;
Expand All @@ -22,10 +25,10 @@ int get_uid (const char *uidstr, uid_t *uid)
|| ('\0' != *endptr)
|| (0 != errno)
|| (/*@+longintegral@*/val != (uid_t)val)/*@=longintegral@*/) {
return 0;
return -1;
}

*uid = val;
return 1;
return 0;
}

2 changes: 1 addition & 1 deletion lib/sgetpwent.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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) == -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static int get_user_id (const char *uid, uid_t *nuid) {
* caller provided, or the next available UID.
*/
if (isdigit (uid[0])) {
if ((get_uid (uid, nuid) == 0) || (*nuid == (uid_t)-1)) {
if ((get_uid(uid, nuid) == -1) || (*nuid == (uid_t)-1)) {
fprintf (stderr,
_("%s: invalid user ID '%s'\n"),
Prog, uid);
Expand Down
2 changes: 1 addition & 1 deletion src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ static void process_flags (int argc, char **argv)
sflg = true;
break;
case 'u':
if ( (get_uid (optarg, &user_id) == 0)
if ( (get_uid(optarg, &user_id) == -1)
|| (user_id == (gid_t)-1)) {
fprintf (stderr,
_("%s: invalid user ID '%s'\n"),
Expand Down
2 changes: 1 addition & 1 deletion src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ static void process_flags (int argc, char **argv)
sflg = true;
break;
case 'u':
if ( (get_uid (optarg, &user_newid) ==0)
if ( (get_uid(optarg, &user_newid) == -1)
|| (user_newid == (uid_t)-1)) {
fprintf (stderr,
_("%s: invalid user ID '%s'\n"),
Expand Down

0 comments on commit 18c428a

Please sign in to comment.