]> git.sur5r.net Git - openldap/commitdiff
create IPC sockets with wide-open permissions (0222 might suffice; ITS#4709)
authorPierangelo Masarati <ando@openldap.org>
Sat, 14 Oct 2006 17:35:50 +0000 (17:35 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 14 Oct 2006 17:35:50 +0000 (17:35 +0000)
servers/slapd/daemon.c

index f1c535014a0d9880b400953a8fbd7c4fd283ba42..8ad1f77e786903ef0934ad0e3b1860307ce0e319 100644 (file)
@@ -1310,24 +1310,39 @@ slap_open_listener(
 #ifdef LOCAL_CREDS
                {
                        int one = 1;
-                       setsockopt(l.sl_sd, 0, LOCAL_CREDS, &one, sizeof one);
+                       setsockopt( l.sl_sd, 0, LOCAL_CREDS, &one, sizeof( one ) );
                }
 #endif /* LOCAL_CREDS */
-               addrlen = sizeof(struct sockaddr_un);
+
+               addrlen = sizeof( struct sockaddr_un );
+
+               /* create socket with all permissions set for those systems
+                * that honor permissions on sockets (e.g. Linux); typically,
+                * only write is required.  To exploit filesystem permissions,
+                * place the socket in a directory and use directory's
+                * permissions.  Need write perms to the directory to 
+                * create/unlink the socket; likely need exec perms to access
+                * the socket */
+               {
+                       mode_t old_umask;
+
+                       old_umask = umask( 0 );
+                       rc = bind( l.sl_sd, *sal, addrlen );
+                       umask( old_umask );
+                       if ( rc ) {
+                               err = sock_errno();
+                               Debug( LDAP_DEBUG_ANY,
+                                       "daemon: bind(%ld) failed errno=%d (%s)\n",
+                                       (long)l.sl_sd, err, sock_errstr( err ) );
+                               tcp_close( l.sl_sd );
+                               sal++;
+                               continue;
+                       }
+               }
                break;
 #endif /* LDAP_PF_LOCAL */
                }
 
-               if (bind(l.sl_sd, *sal, addrlen)) {
-                       err = sock_errno();
-                       Debug( LDAP_DEBUG_ANY,
-                               "daemon: bind(%ld) failed errno=%d (%s)\n",
-                               (long) l.sl_sd, err, sock_errstr(err) );
-                       tcp_close( l.sl_sd );
-                       sal++;
-                       continue;
-               }
-
                switch ( (*sal)->sa_family ) {
 #ifdef LDAP_PF_LOCAL
                case AF_LOCAL: {