summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-19 01:55:29 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-22 16:31:32 +0200
commitc077529ba6852192c464772ce907670850210dfe (patch)
treee067689b021c42cb9c7ef57504e842dd6f0ac4de
parentf6c2284ad340a450ac0e4f9b252aadf67e5618eb (diff)
util: drop UID_IS_INVALID() in favour of uid_is_valid()
No need to keep both functions, settle on uid_is_valid() for everything.
-rw-r--r--src/basic/macro.h12
-rw-r--r--src/basic/util.h5
-rw-r--r--src/login/loginctl.c2
-rw-r--r--src/machine/machined-dbus.c16
-rw-r--r--src/nss-mymachines/nss-mymachines.c4
5 files changed, 15 insertions, 24 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index 248f7a86dd..f55d65e2f1 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -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) \
diff --git a/src/basic/util.h b/src/basic/util.h
index 3e25ee4687..f37efd0a91 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -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);
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 405df49a7c..be52518161 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -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;
}
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index eef9c5fa5f..41bb106d28 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -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);
diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c
index 5758ea1569..604130ed25 100644
--- a/src/nss-mymachines/nss-mymachines.c
+++ b/src/nss-mymachines/nss-mymachines.c
@@ -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;
}