e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik/* gcc -Wall -fPIC -shared -o getsockopt_wrapper.so getsockopt_wrapper.c -ldl */
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik/* for RTLD_NEXT */
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik ret = getsockname(fd, (struct sockaddr *)&addr, &addrlen);
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik if (ret != 0) return false;
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik if (addr.ss_family != AF_UNIX) return false;
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik return NULL != strstr(unix_socket->sun_path, "system_bus_socket");
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnikstatic getsockopt_fn_t *orig_getsockopt = NULL;
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnikint getsockopt(int sockfd, int level, int optname,
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik orig_getsockopt = (getsockopt_fn_t *)dlsym(RTLD_NEXT, "getsockopt");
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik ret = orig_getsockopt(sockfd, level, optname, optval, optlen);
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik if (ret == 0 && level == SOL_SOCKET && optname == SO_PEERCRED
e64696e1fab85c42aaeda65ddf49ee1b7e3f07e1Lukas Slebodnik if (cr->uid != 0 && is_dbus_socket(sockfd)) {