mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-24 07:40:52 +00:00
syslogd: Fix handling of unix socket modes
When bind() is called, the process umask is applied, so one has to
either clear the umask before binding or call chmod() to add permissions
after the fact. Do the former here to ensure that the socket always has
the correct mode.
Reported by: Lexi Winter <lexi@le-fay.org>
Fixes: 2b8c3a05e0
("syslogd: Set unix socket modes atomically")
This commit is contained in:
parent
d14c38ceb8
commit
88dd055092
@ -3721,12 +3721,24 @@ socksetup(struct addrinfo *ai, const char *name, mode_t mode)
|
||||
if (ai->ai_family == AF_LOCAL)
|
||||
unlink(name);
|
||||
if (ai->ai_family == AF_LOCAL || NoBind == 0 || name != NULL) {
|
||||
mode_t mask;
|
||||
int error;
|
||||
|
||||
if (ai->ai_family == AF_LOCAL && fchmod(s, mode) < 0) {
|
||||
dprintf("fchmod %s: %s\n", name, strerror(errno));
|
||||
close(s);
|
||||
return (NULL);
|
||||
}
|
||||
if (bind(s, ai->ai_addr, ai->ai_addrlen) < 0) {
|
||||
|
||||
/*
|
||||
* For AF_LOCAL sockets, the process umask is applied to the
|
||||
* mode set above, so temporarily clear it to ensure that the
|
||||
* socket always has the correct permissions.
|
||||
*/
|
||||
mask = umask(0);
|
||||
error = bind(s, ai->ai_addr, ai->ai_addrlen);
|
||||
(void)umask(mask);
|
||||
if (error < 0) {
|
||||
logerror("bind");
|
||||
close(s);
|
||||
return (NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user