]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: port one use of SO_PEERCRED by getpeercred()
authorLennart Poettering <lennart@poettering.net>
Sat, 30 Dec 2017 14:20:38 +0000 (15:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 4 Jan 2018 12:28:24 +0000 (13:28 +0100)
src/shared/bus-util.c

index 7a185461a3ebd5e3e347b08b670c2603d90ab53f..50731fa5ff0990d1589d2b91f5470a276df1c6fe 100644 (file)
@@ -560,8 +560,7 @@ void bus_verify_polkit_async_registry_free(Hashmap *registry) {
 
 int bus_check_peercred(sd_bus *c) {
         struct ucred ucred;
-        socklen_t l;
-        int fd;
+        int fd, r;
 
         assert(c);
 
@@ -569,12 +568,9 @@ int bus_check_peercred(sd_bus *c) {
         if (fd < 0)
                 return fd;
 
-        l = sizeof(struct ucred);
-        if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l) < 0)
-                return -errno;
-
-        if (l != sizeof(struct ucred))
-                return -E2BIG;
+        r = getpeercred(fd, &ucred);
+        if (r < 0)
+                return r;
 
         if (ucred.uid != 0 && ucred.uid != geteuid())
                 return -EPERM;