]> err.no Git - systemd/commitdiff
util: user parse_uid() wherever applicable
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Jul 2011 22:47:17 +0000 (00:47 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Jul 2011 22:47:17 +0000 (00:47 +0200)
TODO
src/execute.c
src/loginctl.c
src/logind.c
src/pam-module.c
src/sd-login.c
src/tmpfiles.c
src/util.c

diff --git a/TODO b/TODO
index ca8f1f16cf1001d10620f0b178c853fc3a626dc3..62bea4109d4a3ec1b30b0e242ea9366ad37c4d97 100644 (file)
--- a/TODO
+++ b/TODO
@@ -20,6 +20,8 @@ F15 External:
 
 Features:
 
+* fix CUPS .path unit for globbing
+
 * move PAM code into its own binary
 
 * logind: ensure ACLs are updated on login and logout
index 92f4eafd3570287b5e42f8e7cc4dc5ce06fd51c8..40af7d65f1864717f2ce34f72307c434256cbfd1 100644 (file)
@@ -551,7 +551,7 @@ static int restore_confirm_stdio(const ExecContext *context,
 
 static int get_group_creds(const char *groupname, gid_t *gid) {
         struct group *g;
-        unsigned long lu;
+        gid_t id;
 
         assert(groupname);
         assert(gid);
@@ -564,9 +564,9 @@ static int get_group_creds(const char *groupname, gid_t *gid) {
                 return 0;
         }
 
-        if (safe_atolu(groupname, &lu) >= 0) {
+        if (parse_gid(groupname, &id) >= 0) {
                 errno = 0;
-                g = getgrgid((gid_t) lu);
+                g = getgrgid(id);
         } else {
                 errno = 0;
                 g = getgrnam(groupname);
index 829213e3d0c97f3d821ad60104ce31a888bd8499..08ee804f438937e23c22242967080d290a2a01a1 100644 (file)
@@ -1058,9 +1058,10 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                         }
 
                 } else if (strstr(args[0], "user")) {
-                        uint32_t uid;
+                        uid_t uid;
+                        uint32_t u;
 
-                        if (safe_atou(args[i], &uid) < 0) {
+                        if (parse_uid(args[i], &uid) < 0) {
                                 struct passwd *pw;
 
                                 pw = getpwnam(args[i]);
@@ -1084,8 +1085,9 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                                 goto finish;
                         }
 
+                        u = (uint32_t) uid;
                         if (!dbus_message_append_args(m,
-                                                      DBUS_TYPE_UINT32, &uid,
+                                                      DBUS_TYPE_UINT32, &u,
                                                       DBUS_TYPE_INVALID)) {
                                 log_error("Could not append arguments to message.");
                                 ret = -ENOMEM;
@@ -1282,7 +1284,8 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
         b = streq(args[0], "enable-linger");
 
         for (i = 1; i < n; i++) {
-                uint32_t uid;
+                uint32_t u;
+                uid_t uid;
 
                 m = dbus_message_new_method_call(
                                 "org.freedesktop.login1",
@@ -1295,7 +1298,7 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
                         goto finish;
                 }
 
-                if (safe_atou32(args[i], &uid) < 0) {
+                if (parse_uid(args[i], &uid) < 0) {
                         struct passwd *pw;
 
                         errno = 0;
@@ -1309,8 +1312,9 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
                         uid = pw->pw_uid;
                 }
 
+                u = (uint32_t) uid;
                 if (!dbus_message_append_args(m,
-                                              DBUS_TYPE_UINT32, &uid,
+                                              DBUS_TYPE_UINT32, &u,
                                               DBUS_TYPE_BOOLEAN, &b,
                                               DBUS_TYPE_BOOLEAN, &interactive,
                                               DBUS_TYPE_INVALID)) {
@@ -1356,6 +1360,7 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
 
         for (i = 1; i < n; i++) {
                 uint32_t u;
+                uid_t uid;
 
                 m = dbus_message_new_method_call(
                                 "org.freedesktop.login1",
@@ -1368,7 +1373,7 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
                         goto finish;
                 }
 
-                if (safe_atou32(args[i], &u) < 0) {
+                if (parse_uid(args[i], &uid) < 0) {
                         struct passwd *pw;
 
                         errno = 0;
@@ -1379,9 +1384,10 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
                                 goto finish;
                         }
 
-                        u = pw->pw_uid;
+                        uid = pw->pw_uid;
                 }
 
+                u = (uint32_t) uid;
                 if (!dbus_message_append_args(m,
                                               DBUS_TYPE_UINT32, &u,
                                               DBUS_TYPE_INVALID)) {
@@ -1429,6 +1435,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
                 arg_kill_who = "all";
 
         for (i = 1; i < n; i++) {
+                uid_t uid;
                 uint32_t u;
 
                 m = dbus_message_new_method_call(
@@ -1442,7 +1449,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
                         goto finish;
                 }
 
-                if (safe_atou32(args[i], &u) < 0) {
+                if (parse_uid(args[i], &uid) < 0) {
                         struct passwd *pw;
 
                         errno = 0;
@@ -1453,9 +1460,10 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
                                 goto finish;
                         }
 
-                        u = pw->pw_uid;
+                        uid = pw->pw_uid;
                 }
 
+                u = (uint32_t) uid;
                 if (!dbus_message_append_args(m,
                                               DBUS_TYPE_UINT32, &u,
                                               DBUS_TYPE_INT32, arg_signal,
index f96ace2315734b4dcd99b14a2d8c6f015cc369e6..a081501a8cefce1da2a0c324ef7556fc66765bb8 100644 (file)
@@ -509,19 +509,19 @@ int manager_enumerate_users(Manager *m) {
         }
 
         while ((de = readdir(d))) {
-                unsigned long ul;
+                uid_t uid;
                 User *u;
 
                 if (!dirent_is_file(de))
                         continue;
 
-                k = safe_atolu(de->d_name, &ul);
+                k = parse_uid(de->d_name, &uid);
                 if (k < 0) {
                         log_error("Failed to parse file name %s: %s", de->d_name, strerror(-k));
                         continue;
                 }
 
-                u = hashmap_get(m->users, ULONG_TO_PTR(ul));
+                u = hashmap_get(m->users, ULONG_TO_PTR(uid));
                 if (!u) {
                         unlinkat(dirfd(d), de->d_name, 0);
                         continue;
index dfeab97f53b7752a060a1f5dff20da0247c5d24f..a3ce2468d57ed6e1861121988b59b2c0e4d26f03 100644 (file)
@@ -180,14 +180,14 @@ static int get_user_data(
                  * it probably contains a uid of the host system. */
 
                 if (read_one_line_file("/proc/self/loginuid", &s) >= 0) {
-                        uint32_t u;
+                        uid_t uid;
 
-                        r = safe_atou32(s, &u);
+                        r = parse_uid(s, &uid);
                         free(s);
 
-                        if (r >= 0 && u != (uint32_t) -1 && u > 0) {
+                        if (r >= 0 && uid != (uint32_t) -1) {
                                 have_loginuid = true;
-                                pw = pam_modutil_getpwuid(handle, u);
+                                pw = pam_modutil_getpwuid(handle, uid);
                         }
                 }
         }
@@ -239,10 +239,10 @@ static bool check_user_lists(
         }
 
         STRV_FOREACH(l, kill_exclude_users) {
-                uint32_t id;
+                uid_t u;
 
-                if (safe_atou32(*l, &id) >= 0)
-                        if ((uid_t) id == uid)
+                if (parse_uid(*l, &u) >= 0)
+                        if (u == uid)
                                 return false;
 
                 if (name && streq(name, *l))
@@ -253,10 +253,10 @@ static bool check_user_lists(
                 return true;
 
         STRV_FOREACH(l, kill_only_users) {
-                uint32_t id;
+                uid_t u;
 
-                if (safe_atou32(*l, &id) >= 0)
-                        if ((uid_t) id == uid)
+                if (parse_uid(*l, &u) >= 0)
+                        if (u == uid)
                                 return true;
 
                 if (name && streq(name, *l))
index 6dfc2d086e4ff9d0895929d62859389d5cf3da39..b7ae870af4d7577882a88441ac2412aeb9c10557 100644 (file)
@@ -349,14 +349,10 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
         if (!s)
                 return -EIO;
 
-        r = safe_atolu(s, &ul);
+        r = parse_uid(s, uid);
         free(s);
 
-        if (r < 0)
-                return r;
-
-        *uid = (uid_t) ul;
-        return 0;
+        return r;
 }
 
 _public_ int sd_session_get_seat(const char *session, char **seat) {
index feb2a214638f3264083cf653a949508ea4340dff..a1b2f8b1d27ef3cc9236f8ea1c224cf556b6c318 100644 (file)
@@ -757,13 +757,13 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         }
 
         if (user && !streq(user, "-")) {
-                unsigned long lu;
+                uid_t uid;
                 struct passwd *p;
 
                 if (streq(user, "root") || streq(user, "0"))
                         i->uid = 0;
-                else if (safe_atolu(user, &lu) >= 0)
-                        i->uid = (uid_t) lu;
+                else if (parse_uid(user, &uid) >= 0)
+                        i->uid = uid;
                 else if ((p = getpwnam(user)))
                         i->uid = p->pw_uid;
                 else {
@@ -776,13 +776,13 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         }
 
         if (group && !streq(group, "-")) {
-                unsigned long lu;
+                gid_t gid;
                 struct group *g;
 
                 if (streq(group, "root") || streq(group, "0"))
                         i->gid = 0;
-                else if (safe_atolu(group, &lu) >= 0)
-                        i->gid = (gid_t) lu;
+                else if (parse_gid(group, &gid) >= 0)
+                        i->gid = gid;
                 else if ((g = getgrnam(group)))
                         i->gid = g->gr_gid;
                 else {
index 2d4f2291932963fdfade7286741efe0d6d49deee..3a82ef7600f53453416eb487b076c4415c1172a4 100644 (file)
@@ -5262,7 +5262,7 @@ int socket_from_display(const char *display, char **path) {
 
 int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home) {
         struct passwd *p;
-        unsigned long lu;
+        uid_t u;
 
         assert(username);
         assert(*username);
@@ -5281,9 +5281,9 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h
                 return 0;
         }
 
-        if (safe_atolu(*username, &lu) >= 0) {
+        if (parse_uid(*username, &u) >= 0) {
                 errno = 0;
-                p = getpwuid((uid_t) lu);
+                p = getpwuid(u);
 
                 /* If there are multiple users with the same id, make
                  * sure to leave $USER to the configured value instead