]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
make sure the ctdb control socket is secure
authorAndrew Tridgell <tridge@samba.org>
Sat, 12 May 2007 23:20:16 +0000 (09:20 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 12 May 2007 23:20:16 +0000 (09:20 +1000)
(This used to be ctdb commit 2954f2e501a418af578e75e8705b0b39a77c1861)

ctdb/common/ctdb_daemon.c

index 8bbb07ec5913493822ec7dac5ae2654a2678fbd3..69c5005952bd2894b6abcfb23aba1584c40aea05 100644 (file)
@@ -600,10 +600,15 @@ static int ux_socket_bind(struct ctdb_context *ctdb)
 
        ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (ctdb->daemon.sd == -1) {
-               ctdb->daemon.sd = -1;
                return -1;
        }
 
+       if (fchown(ctdb->daemon.sd, geteuid(), getegid()) != 0 ||
+           fchmod(ctdb->daemon.sd, 0700) != 0) {
+               DEBUG(0,("Unable to secure ctdb socket '%s', ctdb->daemon.name\n"));
+               goto failed;
+       }
+
        set_non_blocking(ctdb->daemon.sd);
 
        memset(&addr, 0, sizeof(addr));
@@ -611,13 +616,20 @@ static int ux_socket_bind(struct ctdb_context *ctdb)
        strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path));
 
        if (bind(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-               close(ctdb->daemon.sd);
-               ctdb->daemon.sd = -1;
-               return -1;
+               DEBUG(0,("Unable to bind on ctdb socket '%s', ctdb->daemon.name\n"));
+               goto failed;
        }       
-       listen(ctdb->daemon.sd, 1);
+       if (listen(ctdb->daemon.sd, 10) != 0) {
+               DEBUG(0,("Unable to listen on ctdb socket '%s', ctdb->daemon.name\n"));
+               goto failed;
+       }
 
        return 0;
+
+failed:
+       close(ctdb->daemon.sd);
+       ctdb->daemon.sd = -1;
+       return -1;      
 }
 
 /*