r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[sfrench/samba-autobuild/.git] / source3 / smbd / sockinit.c
index 8fd76f84b744a916ef7723d2f51f9810a51a58ff..598bbd1bda7a2993fc3e4b96d586ee035e11df50 100644 (file)
@@ -1,22 +1,21 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
 
    Copyright (C) Andrew Tridgell               1992-1998
    Copyright (C) James Peach                   2007
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -44,11 +43,11 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE])
        }
 
        if (lp_interfaces() && lp_bind_interfaces_only()) {
-               /* We have been given an interfaces line, and been 
+               /* We have been given an interfaces line, and been
                   told to only bind to those interfaces. Create a
                   socket per interface and bind to only these.
                */
-               
+
                /* Now open a listen socket for each of the
                   interfaces. */
                for(i = 0; i < num_interfaces; i++) {
@@ -57,35 +56,45 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE])
                        const char *ptr;
 
                        if(ifip == NULL) {
-                               DEBUG(0,("init_sockets_smbd: interface %d has NULL IP address !\n", i));
+                               DEBUG(0,("init_sockets_smbd: interface %d has "
+                                       "NULL IP address !\n", i));
                                continue;
                        }
 
-                       for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) {
+                       for (ptr=ports; next_token(&ptr, tok, " \t,",
+                                               sizeof(tok)); ) {
                                unsigned port = atoi(tok);
                                if (port == 0 || port > 0xffff) {
                                        continue;
                                }
-                               s = listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
+                               s = listenset[num_sockets] =
+                                       open_socket_in(SOCK_STREAM,
+                                                       port,
+                                                       0,
+                                                       ifip->s_addr,
+                                                       True);
                                if(s == -1)
                                        return 0;
 
                                /* ready to listen */
-                               set_socket_options(s,"SO_KEEPALIVE"); 
+                               set_socket_options(s,"SO_KEEPALIVE");
                                set_socket_options(s,user_socket_options);
-     
-                               /* Set server socket to non-blocking for the accept. */
-                               set_blocking(s,False); 
+
+                               /* Set server socket to non-blocking
+                                * for the accept. */
+                               set_blocking(s,False);
+
                                if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
-                                       DEBUG(0,("listen: %s\n",strerror(errno)));
+                                       DEBUG(0,("listen: %s\n",
+                                               strerror(errno)));
                                        close(s);
                                        return 0;
                                }
 
                                num_sockets++;
                                if (num_sockets >= FD_SETSIZE) {
-                                       DEBUG(0,("init_sockets_smbd: Too many sockets to bind to\n"));
+                                       DEBUG(0,("init_sockets_smbd: "
+                                       "Too many sockets to bind to\n"));
                                        return 0;
                                }
                        }
@@ -98,23 +107,24 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE])
                const char *ptr;
 
                num_interfaces = 1;
-               
+
                for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) {
                        unsigned port = atoi(tok);
                        if (port == 0  || port > 0xffff) continue;
                        /* open an incoming socket */
                        s = open_socket_in(SOCK_STREAM, port, 0,
-                                          interpret_addr(lp_socket_address()),True);
+                                          interpret_addr(lp_socket_address()),
+                                          True);
                        if (s == -1)
                                return 0;
-               
+
                        /* ready to listen */
-                       set_socket_options(s,"SO_KEEPALIVE"); 
+                       set_socket_options(s,"SO_KEEPALIVE");
                        set_socket_options(s,user_socket_options);
-                       
+
                        /* Set server socket to non-blocking for the accept. */
-                       set_blocking(s,False); 
+                       set_blocking(s,False);
+
                        if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
                                DEBUG(0,("init_sockets_smbd: listen: %s\n",
                                         strerror(errno)));
@@ -126,11 +136,12 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE])
                        num_sockets++;
 
                        if (num_sockets >= FD_SETSIZE) {
-                               DEBUG(0,("init_sockets_smbd: Too many sockets to bind to\n"));
+                               DEBUG(0,("init_sockets_smbd: "
+                                       "Too many sockets to bind to\n"));
                                return 0;
                        }
                }
-       } 
+       }
 
        SAFE_FREE(ports);
        return num_sockets;
@@ -198,4 +209,3 @@ int smbd_sockinit(const char *cmdline_ports, int listenset[FD_SETSIZE],
 
        return num_sockets;
 }
-