chiark / gitweb /
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 ca8f1f1..62bea41 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 92f4eaf..40af7d6 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 829213e..08ee804 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 f96ace2..a081501 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 dfeab97..a3ce246 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 6dfc2d0..b7ae870 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 feb2a21..a1b2f8b 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 2d4f229..3a82ef7 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