From: Lennart Poettering Date: Sat, 30 Dec 2017 14:20:38 +0000 (+0100) Subject: sd-bus: port one use of SO_PEERCRED by getpeercred() X-Git-Tag: v237~146^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e641e361d8b62923bea3cd9786dbd5cfba26b89;p=thirdparty%2Fsystemd.git sd-bus: port one use of SO_PEERCRED by getpeercred() --- diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 7a185461a3e..50731fa5ff0 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -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;