lib/, src/: get_uid(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
470baeabbd
commit
18c428a6c9
+6
-3
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
@@ -11,7 +12,9 @@
|
||||
#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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -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"),
|
||||
|
||||
+1
-1
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user