1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

util: drop UID_IS_INVALID() in favour of uid_is_valid()

No need to keep both functions, settle on uid_is_valid() for everything.
This commit is contained in:
Lennart Poettering 2015-09-19 01:55:29 +02:00
parent f6c2284ad3
commit c077529ba6
5 changed files with 15 additions and 24 deletions

View File

@ -470,18 +470,6 @@ do { \
#define GID_INVALID ((gid_t) -1)
#define MODE_INVALID ((mode_t) -1)
static inline bool UID_IS_INVALID(uid_t uid) {
/* We consider both the old 16bit -1 user and the newer 32bit
* -1 user invalid, since they are or used to be incompatible
* with syscalls such as setresuid() or chown(). */
return uid == (uid_t) ((uint32_t) -1) || uid == (uid_t) ((uint16_t) -1);
}
static inline bool GID_IS_INVALID(gid_t gid) {
return gid == (gid_t) ((uint32_t) -1) || gid == (gid_t) ((uint16_t) -1);
}
#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
static inline void func##p(type *p) { \
if (*p) \

View File

@ -161,7 +161,10 @@ int parse_uid(const char *s, uid_t* ret_uid);
#define parse_gid(s, ret_gid) parse_uid(s, ret_gid)
bool uid_is_valid(uid_t uid);
#define gid_is_valid(gid) uid_is_valid(gid)
static inline bool gid_is_valid(gid_t gid) {
return uid_is_valid((uid_t) gid);
}
int safe_atou(const char *s, unsigned *ret_u);
int safe_atoi(const char *s, int *ret_i);

View File

@ -720,7 +720,7 @@ static int print_property(const char *name, sd_bus_message *m, const char *conte
if (r < 0)
return bus_log_parse_error(r);
if (UID_IS_INVALID(uid)) {
if (!uid_is_valid(uid)) {
log_error("Invalid user ID: " UID_FMT, uid);
return -EINVAL;
}

View File

@ -876,7 +876,7 @@ static int method_map_from_machine_user(sd_bus_message *message, void *userdata,
if (r < 0)
return r;
if (UID_IS_INVALID(uid))
if (!uid_is_valid(uid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
machine = hashmap_get(m->machines, name);
@ -910,7 +910,7 @@ static int method_map_from_machine_user(sd_bus_message *message, void *userdata,
continue;
converted = uid - uid_base + uid_shift;
if (UID_IS_INVALID(converted))
if (!uid_is_valid(converted))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
@ -929,7 +929,7 @@ static int method_map_to_machine_user(sd_bus_message *message, void *userdata, s
r = sd_bus_message_read(message, "u", &uid);
if (r < 0)
return r;
if (UID_IS_INVALID(uid))
if (!uid_is_valid(uid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
if (uid < 0x10000)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "User " UID_FMT " belongs to host UID range", uid);
@ -968,7 +968,7 @@ static int method_map_to_machine_user(sd_bus_message *message, void *userdata, s
continue;
converted = (uid - uid_shift + uid_base);
if (UID_IS_INVALID(converted))
if (!uid_is_valid(converted))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
o = machine_bus_path(machine);
@ -994,7 +994,7 @@ static int method_map_from_machine_group(sd_bus_message *message, void *groupdat
if (r < 0)
return r;
if (GID_IS_INVALID(gid))
if (!gid_is_valid(gid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
machine = hashmap_get(m->machines, name);
@ -1028,7 +1028,7 @@ static int method_map_from_machine_group(sd_bus_message *message, void *groupdat
continue;
converted = gid - gid_base + gid_shift;
if (GID_IS_INVALID(converted))
if (!gid_is_valid(converted))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
@ -1047,7 +1047,7 @@ static int method_map_to_machine_group(sd_bus_message *message, void *groupdata,
r = sd_bus_message_read(message, "u", &gid);
if (r < 0)
return r;
if (GID_IS_INVALID(gid))
if (!gid_is_valid(gid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
if (gid < 0x10000)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "Group " GID_FMT " belongs to host GID range", gid);
@ -1086,7 +1086,7 @@ static int method_map_to_machine_group(sd_bus_message *message, void *groupdata,
continue;
converted = (gid - gid_shift + gid_base);
if (GID_IS_INVALID(converted))
if (!gid_is_valid(converted))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
o = machine_bus_path(machine);

View File

@ -485,7 +485,7 @@ enum nss_status _nss_mymachines_getpwuid_r(
uint32_t mapped;
int r;
if (UID_IS_INVALID(uid)) {
if (!uid_is_valid(uid)) {
r = -EINVAL;
goto fail;
}
@ -640,7 +640,7 @@ enum nss_status _nss_mymachines_getgrgid_r(
uint32_t mapped;
int r;
if (GID_IS_INVALID(gid)) {
if (!gid_is_valid(gid)) {
r = -EINVAL;
goto fail;
}