diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib/unix-socket-create.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/unix-socket-create.c')
-rw-r--r-- | src/lib/unix-socket-create.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/unix-socket-create.c b/src/lib/unix-socket-create.c new file mode 100644 index 0000000..3614df1 --- /dev/null +++ b/src/lib/unix-socket-create.c @@ -0,0 +1,36 @@ +/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "net.h" +#include "unix-socket-create.h" + +#include <unistd.h> +#include <sys/stat.h> + +int unix_socket_create(const char *path, int mode, + uid_t uid, gid_t gid, int backlog) +{ + mode_t old_umask; + int fd; + + old_umask = umask(0777 ^ mode); + fd = net_listen_unix_unlink_stale(path, backlog); + umask(old_umask); + + if (fd < 0) { + i_error("net_listen_unix(%s) failed: %m", path); + return -1; + } + + if (uid != (uid_t)-1 || gid != (gid_t)-1) { + /* set correct permissions */ + if (chown(path, uid, gid) < 0) { + i_error("chown(%s, %s, %s) failed: %m", + path, dec2str(uid), dec2str(gid)); + i_close_fd(&fd); + return -1; + } + } + return fd; +} + |