diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-25 22:37:43 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-26 01:24:38 +0100 |
commit | b1d5277372a26e5a5b9980174652e1e287ba6b14 (patch) | |
tree | 640c02fb1da8ec399571d8dc48ef3116a6d84a2e | |
parent | b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1 (diff) |
user-util: simplify uid parsing a bit
-rw-r--r-- | src/basic/user-util.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 637391f4a7..ebeac99d31 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -31,40 +31,35 @@ bool uid_is_valid(uid_t uid) { /* Some libc APIs use UID_INVALID as special placeholder */ - if (uid == (uid_t) 0xFFFFFFFF) + if (uid == (uid_t) UINT32_C(0xFFFFFFFF)) return false; /* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */ - if (uid == (uid_t) 0xFFFF) + if (uid == (uid_t) UINT32_C(0xFFFF)) return false; return true; } -int parse_uid(const char *s, uid_t* ret_uid) { - unsigned long ul = 0; - uid_t uid; +int parse_uid(const char *s, uid_t *ret) { + uint32_t uid = 0; int r; assert(s); - r = safe_atolu(s, &ul); + assert_cc(sizeof(uid_t) == sizeof(uint32_t)); + r = safe_atou32(s, &uid); if (r < 0) return r; - uid = (uid_t) ul; - - if ((unsigned long) uid != ul) - return -ERANGE; - if (!uid_is_valid(uid)) return -ENXIO; /* we return ENXIO instead of EINVAL * here, to make it easy to distuingish * invalid numeric uids invalid * strings. */ - if (ret_uid) - *ret_uid = uid; + if (ret) + *ret = uid; return 0; } |