From c8b3a22d4ef0f69c3d22f0ec1170b89c93ef1dc3 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Fri, 6 Aug 2021 00:45:25 +0200 Subject: seatd: Only set UID/GID when specified The UID/GID defaulted to 0, which results in trying to chown to root when a UID or GID isn't requested. Instead, deafult to -1 so that the unspecified values are left intact. --- seatd/seatd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/seatd/seatd.c b/seatd/seatd.c index 420847d..826b994 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -41,11 +41,11 @@ static int open_socket(const char *path, int uid, int gid) { close(fd); return -1; } - if (uid != 0 || gid != 0) { - if (chown(path, uid, gid) == -1) { + if (uid != -1 || gid != -1) { + if (fchown(fd, uid, gid) == -1) { log_errorf("Could not chown socket to uid %d, gid %d: %s", uid, gid, strerror(errno)); - } else if (chmod(path, 0770) == -1) { + } else if (fchmod(fd, 0770) == -1) { log_errorf("Could not chmod socket: %s", strerror(errno)); } } @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { "\n"; int c; - int uid = 0, gid = 0; + int uid = -1, gid = -1; int readiness = -1; const char *socket_path = getenv("SEATD_SOCK"); while ((c = getopt(argc, argv, "vhn:s:g:u:")) != -1) { -- cgit v1.2.3