summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-01 19:31:53 -0500
committerAnthony G. Basile <blueness@gentoo.org>2014-12-01 19:31:53 -0500
commit4e7269063d2884374f95f1e83023006e42296533 (patch)
treeb12957ed11dae36121b7569b19340374a649dd1a
parentf460aa149c21c920e1a3090a16877937c49b4813 (diff)
treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/shared/macro.h4
-rw-r--r--src/shared/mkdir.c4
-rw-r--r--src/shared/util.c10
3 files changed, 11 insertions, 7 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h
index cea13182ec..e2c519cf89 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -236,4 +236,8 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
#endif
#endif
+#define UID_INVALID ((uid_t) -1)
+#define GID_INVALID ((gid_t) -1)
+#define MODE_INVALID ((mode_t) -1)
+
#include "log.h"
diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c
index 3bc5131e40..dc400d9b91 100644
--- a/src/shared/mkdir.c
+++ b/src/shared/mkdir.c
@@ -42,8 +42,8 @@ int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkd
if ((st.st_mode & 0007) > (mode & 0007) ||
(st.st_mode & 0070) > (mode & 0070) ||
(st.st_mode & 0700) > (mode & 0700) ||
- (uid != (uid_t) -1 && st.st_uid != uid) ||
- (gid != (gid_t) -1 && st.st_gid != gid) ||
+ (uid != UID_INVALID && st.st_uid != uid) ||
+ (gid != GID_INVALID && st.st_gid != gid) ||
!S_ISDIR(st.st_mode)) {
errno = EEXIST;
return -errno;
diff --git a/src/shared/util.c b/src/shared/util.c
index ebf654a43e..23ecb1b462 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -260,7 +260,7 @@ int parse_uid(const char *s, uid_t* ret_uid) {
if ((unsigned long) uid != ul)
return -ERANGE;
- /* Some libc APIs use (uid_t) -1 as special placeholder */
+ /* Some libc APIs use UID_INVALID as special placeholder */
if (uid == (uid_t) 0xFFFFFFFF)
return -ENXIO;
@@ -949,11 +949,11 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) {
* first change the access mode and only then hand out
* ownership to avoid a window where access is too open. */
- if (mode != (mode_t) -1)
+ if (mode != MODE_INVALID)
if (chmod(path, mode) < 0)
return -errno;
- if (uid != (uid_t) -1 || gid != (gid_t) -1)
+ if (uid != UID_INVALID || gid != GID_INVALID)
if (chown(path, uid, gid) < 0)
return -errno;
@@ -1520,9 +1520,9 @@ int getpeercred(int fd, struct ucred *ucred) {
* to namespacing issues */
if (u.pid <= 0)
return -ENODATA;
- if (u.uid == (uid_t) -1)
+ if (u.uid == UID_INVALID)
return -ENODATA;
- if (u.gid == (gid_t) -1)
+ if (u.gid == GID_INVALID)
return -ENODATA;
*ucred = u;