X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/e55761b186abf435d15e9e9229df76f0b6cd9a59..12a26b8b34df23103d4da6d7e40705485266a4d6:/server/admin.c diff --git a/server/admin.c b/server/admin.c index 228cce15..8eb5ec3c 100644 --- a/server/admin.c +++ b/server/admin.c @@ -2213,19 +2213,21 @@ void a_daemon(void) { flags |= F_DAEMON; } * Arguments: @const char *name@ = socket name to create * @uid_t u@ = user to own the socket * @gid_t g@ = group to own the socket + * @mode_t m@ = permissions to set on the socket * * Returns: --- * * Use: Creates the admin listening socket. */ -void a_init(const char *name, uid_t u, gid_t g) +void a_init(const char *name, uid_t u, gid_t g, mode_t m) { int fd; int n = 5; struct sockaddr_un sun; struct sigaction sa; size_t sz; + mode_t omask; /* --- Create services table --- */ @@ -2243,7 +2245,7 @@ void a_init(const char *name, uid_t u, gid_t g) /* --- Attempt to bind to the socket --- */ - umask(0077); + omask = umask(0077); again: if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) die(EXIT_FAILURE, "couldn't create socket: %s", strerror(errno)); @@ -2274,12 +2276,15 @@ again: close(fd); goto again; } - chmod(sun.sun_path, 0600); if (chown(sun.sun_path, u, g)) { - T( trace(T_ADMIN, - "admin: failed to give away socket: %s", - strerror(errno)); ) + die(EXIT_FAILURE, "failed to set socket owner: %s", + strerror(errno)); } + if (chmod(sun.sun_path, m)) { + die(EXIT_FAILURE, "failed to set socket permissions: %s", + strerror(errno)); + } + umask(omask); fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC); if (listen(fd, 5)) die(EXIT_FAILURE, "couldn't listen on socket: %s", strerror(errno));