From b1d5277372a26e5a5b9980174652e1e287ba6b14 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 25 Oct 2015 22:37:43 +0100 Subject: user-util: simplify uid parsing a bit --- src/basic/user-util.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/basic') 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; } -- cgit v1.2.3-54-g00ecf