summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2013-01-09 09:02:54 +0100
committerAndrew Bartlett <abartlet@samba.org>2013-01-09 10:55:23 +0100
commit3a7c2777ee0de37d758fe81d67d6836a8354825e (patch)
treebdd75e2f500deaad77a83c6057d787f4f5895e5c /source3
parent1aa0503401d41fec48d4d4e30d8bbcbd847ff807 (diff)
downloadsamba-3a7c2777ee0de37d758fe81d67d6836a8354825e.tar.gz
samba-3a7c2777ee0de37d758fe81d67d6836a8354825e.tar.bz2
samba-3a7c2777ee0de37d758fe81d67d6836a8354825e.zip
s3-lib: Use new strict directory create function in create_pipe_sock().
Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Wed Jan 9 10:55:23 CET 2013 on sn-devel-104
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_sock.c50
1 files changed, 6 insertions, 44 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 2063a58310..e45efea69b 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