version 1.138, 2019/06/27 18:03:37 |
version 1.139, 2019/06/28 13:35:04 |
|
|
int val; |
int val; |
|
|
val = fcntl(fd, F_GETFL); |
val = fcntl(fd, F_GETFL); |
if (val < 0) { |
if (val == -1) { |
error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
|
|
int val; |
int val; |
|
|
val = fcntl(fd, F_GETFL); |
val = fcntl(fd, F_GETFL); |
if (val < 0) { |
if (val == -1) { |
error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
error("fcntl(%d, F_GETFL): %s", fd, strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
|
|
return -1; |
return -1; |
} |
} |
|
|
if (fd < 0) { |
if (fd == -1) { |
debug("%s: %s open: %s", __func__, name, strerror(errno)); |
debug("%s: %s open: %s", __func__, name, strerror(errno)); |
return -1; |
return -1; |
} |
} |
|
|
} |
} |
|
|
sock = socket(PF_UNIX, SOCK_STREAM, 0); |
sock = socket(PF_UNIX, SOCK_STREAM, 0); |
if (sock < 0) { |
if (sock == -1) { |
saved_errno = errno; |
saved_errno = errno; |
error("%s: socket: %.100s", __func__, strerror(errno)); |
error("%s: socket: %.100s", __func__, strerror(errno)); |
errno = saved_errno; |
errno = saved_errno; |
|
|
if (unlink(path) != 0 && errno != ENOENT) |
if (unlink(path) != 0 && errno != ENOENT) |
error("unlink(%s): %.100s", path, strerror(errno)); |
error("unlink(%s): %.100s", path, strerror(errno)); |
} |
} |
if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) { |
if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) { |
saved_errno = errno; |
saved_errno = errno; |
error("%s: cannot bind to path %s: %s", |
error("%s: cannot bind to path %s: %s", |
__func__, path, strerror(errno)); |
__func__, path, strerror(errno)); |
|
|
errno = saved_errno; |
errno = saved_errno; |
return -1; |
return -1; |
} |
} |
if (listen(sock, backlog) < 0) { |
if (listen(sock, backlog) == -1) { |
saved_errno = errno; |
saved_errno = errno; |
error("%s: cannot listen on path %s: %s", |
error("%s: cannot listen on path %s: %s", |
__func__, path, strerror(errno)); |
__func__, path, strerror(errno)); |
|
|
} |
} |
strlcpy(buf, cp, sizeof(buf)); |
strlcpy(buf, cp, sizeof(buf)); |
|
|
if (stat(buf, &st) < 0 || |
if (stat(buf, &st) == -1 || |
(st.st_uid != 0 && st.st_uid != uid) || |
(st.st_uid != 0 && st.st_uid != uid) || |
(st.st_mode & 022) != 0) { |
(st.st_mode & 022) != 0) { |
snprintf(err, errlen, |
snprintf(err, errlen, |
|
|
struct stat st; |
struct stat st; |
|
|
/* check the open file to avoid races */ |
/* check the open file to avoid races */ |
if (fstat(fd, &st) < 0) { |
if (fstat(fd, &st) == -1) { |
snprintf(err, errlen, "cannot stat file %s: %s", |
snprintf(err, errlen, "cannot stat file %s: %s", |
file, strerror(errno)); |
file, strerror(errno)); |
return -1; |
return -1; |