From 3a7c2777ee0de37d758fe81d67d6836a8354825e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 9 Jan 2013 09:02:54 +0100 Subject: [PATCH] s3-lib: Use new strict directory create function in create_pipe_sock(). Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Wed Jan 9 10:55:23 CET 2013 on sn-devel-104 --- source3/lib/util_sock.c | 50 ++++++------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 2063a583105..e45efea69bd 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1236,53 +1236,18 @@ int create_pipe_sock(const char *socket_dir, { #ifdef HAVE_UNIXSOCKET struct sockaddr_un sunaddr; - struct stat st; + bool ok; int sock; - mode_t old_umask; char *path = NULL; - old_umask = umask(0); - - /* Create the socket directory or reuse the existing one */ - - if (lstat(socket_dir, &st) == -1) { - if (errno == ENOENT) { - /* Create directory */ - if (mkdir(socket_dir, dir_perms) == -1) { - DEBUG(0, ("error creating socket directory " - "%s: %s\n", socket_dir, - strerror(errno))); - goto out_umask; - } - } else { - DEBUG(0, ("lstat failed on socket directory %s: %s\n", - socket_dir, strerror(errno))); - goto out_umask; - } - } else { - /* Check ownership and permission on existing directory */ - if (!S_ISDIR(st.st_mode)) { - DEBUG(0, ("socket directory '%s' isn't a directory\n", - socket_dir)); - goto out_umask; - } - if (st.st_uid != sec_initial_uid()) { - DEBUG(0, ("invalid ownership on directory " - "'%s'\n", socket_dir)); - umask(old_umask); - goto out_umask; - } - if ((st.st_mode & 0777) != dir_perms) { - DEBUG(0, ("invalid permissions on directory " - "'%s': has 0%o should be 0%o\n", socket_dir, - (st.st_mode & 0777), dir_perms)); - umask(old_umask); - goto out_umask; - } + ok = directory_create_or_exist_strict(socket_dir, + sec_initial_uid(), + dir_perms); + if (!ok) { + return -1; } /* Create the socket file */ - sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock == -1) { @@ -1308,7 +1273,6 @@ int create_pipe_sock(const char *socket_dir, SAFE_FREE(path); - umask(old_umask); return sock; out_close: @@ -1316,8 +1280,6 @@ out_close: if (sock != -1) close(sock); -out_umask: - umask(old_umask); return -1; #else -- 2.11.4.GIT