aboutsummaryrefslogtreecommitdiff
path: root/seatd
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2021-08-06 00:45:25 +0200
committerKenny Levinsen <kl@kl.wtf>2021-08-06 01:15:55 +0200
commitc8b3a22d4ef0f69c3d22f0ec1170b89c93ef1dc3 (patch)
treee78991c11553d4151403de09373b09d9111c6f6c /seatd
parent312d6906aef9c9ae7aba62f0ad60c83bb5f95b00 (diff)
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.
Diffstat (limited to 'seatd')
-rw-r--r--seatd/seatd.c8
1 files 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) {