From ee104e11e303499a637c5cd8157bd12ad5cc116d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 00:42:07 +0100 Subject: [PATCH] user-util: move UID/GID related macros from macro.h to user-util.h --- src/basic/fs-util.c | 1 + src/basic/macro.h | 10 ---------- src/basic/mkdir.c | 1 + src/basic/socket-util.c | 1 + src/basic/user-util.h | 11 +++++++++++ src/bus-proxyd/proxy.c | 1 + src/core/dbus-unit.c | 1 + src/core/dbus.c | 1 + src/core/mount-setup.c | 1 + src/core/namespace.c | 1 + src/hostname/hostnamed.c | 1 + src/import/importd.c | 1 + src/libsystemd/sd-bus/bus-control.c | 3 ++- src/libsystemd/sd-bus/bus-creds.c | 1 + src/libsystemd/sd-bus/bus-kernel.c | 1 + src/libsystemd/sd-device/device-private.c | 1 + src/locale/localed.c | 1 + src/login/logind-seat-dbus.c | 9 +++++---- src/login/logind-user.c | 1 + src/machine/image-dbus.c | 5 +++-- src/machine/machine-dbus.c | 1 + src/nspawn/nspawn-mount.c | 1 + src/shared/base-filesystem.c | 1 + src/shared/bus-util.c | 3 ++- src/shared/dev-setup.c | 5 +++-- src/shared/switch-root.c | 1 + src/test/test-cgroup-util.c | 1 + src/test/test-conf-files.c | 1 + src/test/test-uid-range.c | 3 ++- src/timedate/timedated.c | 1 + src/udev/udevd.c | 1 + 31 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index bd775b7..edb007f 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -27,6 +27,7 @@ #include "path-util.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" int unlink_noerrno(const char *path) { diff --git a/src/basic/macro.h b/src/basic/macro.h index f55d65e..eeb57ec 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -295,14 +295,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { #define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p))) #define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u))) -/* The following macros add 1 when converting things, since UID 0 is a - * valid UID, while the pointer NULL is special */ -#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1)) -#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) - -#define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1)) -#define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) - #define PTR_TO_PID(p) ((pid_t) ((uintptr_t) p)) #define PID_TO_PTR(p) ((void*) ((uintptr_t) p)) @@ -466,8 +458,6 @@ do { \ #endif #endif -#define UID_INVALID ((uid_t) -1) -#define GID_INVALID ((gid_t) -1) #define MODE_INVALID ((mode_t) -1) #define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \ diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 9410b33..0214c46 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -26,6 +26,7 @@ #include "mkdir.h" #include "path-util.h" #include "stat-util.h" +#include "user-util.h" #include "util.h" int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir) { diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index 71a52a8..ef5b764 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -40,6 +40,7 @@ #include "socket-util.h" #include "string-table.h" #include "string-util.h" +#include "user-util.h" #include "util.h" int socket_address_parse(SocketAddress *a, const char *s) { diff --git a/src/basic/user-util.h b/src/basic/user-util.h index 4496f58..11ff667 100644 --- a/src/basic/user-util.h +++ b/src/basic/user-util.h @@ -54,3 +54,14 @@ int get_shell(char **_ret); int reset_uid_gid(void); int take_etc_passwd_lock(const char *root); + +#define UID_INVALID ((uid_t) -1) +#define GID_INVALID ((gid_t) -1) + +/* The following macros add 1 when converting things, since UID 0 is a + * valid UID, while the pointer NULL is special */ +#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1)) +#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) + +#define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1)) +#define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1)) diff --git a/src/bus-proxyd/proxy.c b/src/bus-proxyd/proxy.c index ea2a01f..6c251b5 100644 --- a/src/bus-proxyd/proxy.c +++ b/src/bus-proxyd/proxy.c @@ -44,6 +44,7 @@ #include "set.h" #include "strv.h" #include "synthesize.h" +#include "user-util.h" #include "util.h" static int proxy_create_destination(Proxy *p, const char *destination, const char *local_sec, bool negotiate_fds) { diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 62086a7..10cd803 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -31,6 +31,7 @@ #include "special.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode); diff --git a/src/core/dbus.c b/src/core/dbus.c index 37410a9..bbab0ae 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -45,6 +45,7 @@ #include "string-util.h" #include "strv.h" #include "strxcpyx.h" +#include "user-util.h" #define CONNECTIONS_MAX 4096 diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 7486ec3..1ab4ee5 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -40,6 +40,7 @@ #include "set.h" #include "smack-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" #include "virt.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index 65cf140..6c49ff3 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -42,6 +42,7 @@ #include "string-util.h" #include "strv.h" #include "umask-util.h" +#include "user-util.h" #include "util.h" typedef enum MountMode { diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index a421242..5c63a02 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -34,6 +34,7 @@ #include "path-util.h" #include "selinux-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" #include "virt.h" diff --git a/src/import/importd.c b/src/import/importd.c index 6016522..65e2354 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -40,6 +40,7 @@ #include "string-table.h" #include "strv.h" #include "syslog-util.h" +#include "user-util.h" #include "util.h" #include "web-util.h" diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index dc4ac88..7c9dcf5 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -29,13 +29,14 @@ #include "sd-bus.h" #include "bus-bloom.h" +#include "bus-control.h" #include "bus-internal.h" #include "bus-message.h" #include "bus-util.h" #include "capability-util.h" #include "string-util.h" #include "strv.h" -#include "bus-control.h" +#include "user-util.h" _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) { int r; diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index d291da8..7c99904 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -38,6 +38,7 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" +#include "user-util.h" #include "util.h" enum { diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index a455259..a32b0ef 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -48,6 +48,7 @@ #include "parse-util.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" #define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t)) diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index daed321..69288b8 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -41,6 +41,7 @@ #include "string-util.h" #include "strv.h" #include "strxcpyx.h" +#include "user-util.h" #include "util.h" int device_add_property(sd_device *device, const char *key, const char *value) { diff --git a/src/locale/localed.c b/src/locale/localed.c index 343399a..1f25d23 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -44,6 +44,7 @@ #include "path-util.h" #include "selinux-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" enum { diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 346e1d2..66626b5 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -22,13 +22,14 @@ #include #include -#include "util.h" -#include "bus-util.h" -#include "strv.h" #include "bus-common-errors.h" #include "bus-label.h" -#include "logind.h" +#include "bus-util.h" #include "logind-seat.h" +#include "logind.h" +#include "strv.h" +#include "user-util.h" +#include "util.h" static int property_get_active_session( sd_bus *bus, diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 9692a86..1cf9be7 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -45,6 +45,7 @@ #include "special.h" #include "string-table.h" #include "unit-name.h" +#include "user-util.h" #include "util.h" User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) { diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index 2453a9f..a287b96 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -20,10 +20,11 @@ ***/ #include "bus-label.h" -#include "strv.h" #include "bus-util.h" -#include "machine-image.h" #include "image-dbus.h" +#include "machine-image.h" +#include "strv.h" +#include "user-util.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType); diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 0003b84..1132d75 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -48,6 +48,7 @@ #include "process-util.h" #include "strv.h" #include "terminal-util.h" +#include "user-util.h" static int property_get_id( sd_bus *bus, diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 865407e..81003df 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -36,6 +36,7 @@ #include "stat-util.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" CustomMount* custom_mount_add(CustomMount **l, unsigned *n, CustomMountType t) { diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 9ccf265..ff91c6b 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -30,6 +30,7 @@ #include "macro.h" #include "string-util.h" #include "umask-util.h" +#include "user-util.h" #include "util.h" typedef struct BaseFilesystem { diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index c854ff4..b253eb9 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -39,6 +39,7 @@ #include "missing.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "rlimit-util.h" #include "set.h" #include "signal-util.h" @@ -46,9 +47,9 @@ #include "strv.h" #include "syslog-util.h" #include "unit-name.h" +#include "user-util.h" #include "utf8.h" #include "util.h" -#include "proc-cmdline.h" static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { sd_event *e = userdata; diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index 25ad918..0d321af 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -23,10 +23,11 @@ #include #include -#include "util.h" +#include "dev-setup.h" #include "label.h" #include "path-util.h" -#include "dev-setup.h" +#include "user-util.h" +#include "util.h" int dev_setup(const char *prefix, uid_t uid, gid_t gid) { static const char symlinks[] = diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 60d7043..fc885f6 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -35,6 +35,7 @@ #include "rm-rf.h" #include "string-util.h" #include "switch-root.h" +#include "user-util.h" #include "util.h" int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, unsigned long mountflags) { diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index 104f632..e4f6d51 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -27,6 +27,7 @@ #include "process-util.h" #include "string-util.h" #include "test-helper.h" +#include "user-util.h" #include "util.h" static void check_p_d_u(const char *path, int code, const char *result) { diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c index d00517e..f4b2335 100644 --- a/src/test/test-conf-files.c +++ b/src/test/test-conf-files.c @@ -28,6 +28,7 @@ #include "rm-rf.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" static void setup_test_dir(char *tmp_dir, const char *files, ...) { diff --git a/src/test/test-uid-range.c b/src/test/test-uid-range.c index bc5baa2..9f69d71 100644 --- a/src/test/test-uid-range.c +++ b/src/test/test-uid-range.c @@ -21,8 +21,9 @@ #include -#include "util.h" #include "uid-range.h" +#include "user-util.h" +#include "util.h" int main(int argc, char *argv[]) { _cleanup_free_ UidRange *p = NULL; diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index e97dc97..507a83b 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -38,6 +38,7 @@ #include "path-util.h" #include "selinux-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n" diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 2dcdef9..64346a7 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -63,6 +63,7 @@ #include "terminal-util.h" #include "udev-util.h" #include "udev.h" +#include "user-util.h" static bool arg_debug = false; static int arg_daemonize = false; -- 2.7.4