summaryrefslogtreecommitdiff
path: root/source3/smbd/server.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-07-31 04:56:16 +0000
committerAndrew Tridgell <tridge@samba.org>2002-07-31 04:56:16 +0000
commit4516a14dbbc03f2ae2ce3c4d4e22e11e24a8a42f (patch)
tree25a6e27d0e4fe6e971089c9b6674181f31e60250 /source3/smbd/server.c
parent81b69dc79cccd575d33b62ddf7941c5b3c44fdfe (diff)
downloadsamba-4516a14dbbc03f2ae2ce3c4d4e22e11e24a8a42f.tar.gz
samba-4516a14dbbc03f2ae2ce3c4d4e22e11e24a8a42f.tar.bz2
samba-4516a14dbbc03f2ae2ce3c4d4e22e11e24a8a42f.zip
added support for smbd listening on port 445 and 139. It now listens
on both by default, and you can specify a list of ports to listen on either with "smb ports = " in smb.conf or using the -p option to smbd. this is needed for proper netbiosless operation. (This used to be commit 5dee0a7b5e0fcb298a9d36661c80e60d8b9bcc3a)
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r--source3/smbd/server.c125
1 files changed, 80 insertions, 45 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index fdc59f12c0..1eef3d98e8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -151,13 +151,15 @@ static void msg_exit_server(int msg_type, pid_t src, void *buf, size_t len)
Open the socket communication.
****************************************************************************/
-static BOOL open_sockets_smbd(BOOL is_daemon,int port)
+static BOOL open_sockets_smbd(BOOL is_daemon,const char *smb_ports)
{
int num_interfaces = iface_count();
+ int num_sockets = 0;
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
int s;
int i;
+ char *ports;
if (!is_daemon) {
return open_sockets_inetd();
@@ -176,73 +178,106 @@ static BOOL open_sockets_smbd(BOOL is_daemon,int port)
/* Stop zombies */
CatchChild();
-
-
+
FD_ZERO(&listen_set);
- if(lp_interfaces() && lp_bind_interfaces_only()) {
+ /* use a reasonable default set of ports - listing on 445 and 139 */
+ if (!smb_ports) {
+ ports = lp_smb_ports();
+ if (!ports || !*ports) {
+ ports = SMB_PORTS;
+ }
+ ports = strdup(ports);
+ } else {
+ ports = strdup(smb_ports);
+ }
+
+ if (lp_interfaces() && lp_bind_interfaces_only()) {
/* 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.
*/
- if(num_interfaces > FD_SETSIZE) {
- DEBUG(0,("open_sockets_smbd: Too many interfaces specified to bind to. Number was %d \
-max can be %d\n",
- num_interfaces, FD_SETSIZE));
- return False;
- }
-
/* Now open a listen socket for each of the
interfaces. */
for(i = 0; i < num_interfaces; i++) {
struct in_addr *ifip = iface_n_ip(i);
-
+ fstring tok;
+ char *ptr;
+
if(ifip == NULL) {
DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
continue;
}
- s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
- if(s == -1)
- return False;
- /* ready to listen */
- set_socket_options(s,"SO_KEEPALIVE");
- set_socket_options(s,user_socket_options);
+ for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
+ unsigned port = atoi(tok);
+ if (port == 0) continue;
+ s = fd_listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
+ if(s == -1)
+ return False;
+
+ /* ready to listen */
+ set_socket_options(s,"SO_KEEPALIVE");
+ set_socket_options(s,user_socket_options);
- if (listen(s, 5) == -1) {
- DEBUG(0,("listen: %s\n",strerror(errno)));
- close(s);
- return False;
+ if (listen(s, 5) == -1) {
+ DEBUG(0,("listen: %s\n",strerror(errno)));
+ close(s);
+ return False;
+ }
+ FD_SET(s,&listen_set);
+
+ num_sockets++;
+ if (num_sockets >= FD_SETSIZE) {
+ DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
+ return False;
+ }
}
- FD_SET(s,&listen_set);
}
} else {
/* Just bind to 0.0.0.0 - accept connections
from anywhere. */
+
+ fstring tok;
+ char *ptr;
+
num_interfaces = 1;
- /* open an incoming socket */
- s = open_socket_in(SOCK_STREAM, port, 0,
- interpret_addr(lp_socket_address()),True);
- if (s == -1)
- return(False);
+ for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
+ unsigned port = atoi(tok);
+ if (port == 0) continue;
+ /* open an incoming socket */
+ s = open_socket_in(SOCK_STREAM, port, 0,
+ interpret_addr(lp_socket_address()),True);
+ if (s == -1)
+ return(False);
- /* ready to listen */
- set_socket_options(s,"SO_KEEPALIVE");
- set_socket_options(s,user_socket_options);
-
- if (listen(s, 5) == -1) {
- DEBUG(0,("open_sockets_smbd: listen: %s\n",
- strerror(errno)));
- close(s);
- return False;
+ /* ready to listen */
+ set_socket_options(s,"SO_KEEPALIVE");
+ set_socket_options(s,user_socket_options);
+
+ if (listen(s, 5) == -1) {
+ DEBUG(0,("open_sockets_smbd: listen: %s\n",
+ strerror(errno)));
+ close(s);
+ return False;
+ }
+
+ fd_listenset[num_sockets] = s;
+ FD_SET(s,&listen_set);
+
+ num_sockets++;
+
+ if (num_sockets >= FD_SETSIZE) {
+ DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
+ return False;
+ }
}
-
- fd_listenset[0] = s;
- FD_SET(s,&listen_set);
}
+ SAFE_FREE(ports);
+
/* Listen to messages */
message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
@@ -293,7 +328,7 @@ max can be %d\n",
socklen_t in_addrlen = sizeof(addr);
s = -1;
- for(i = 0; i < num_interfaces; i++) {
+ for(i = 0; i < num_sockets; i++) {
if(FD_ISSET(fd_listenset[i],&lfds)) {
s = fd_listenset[i];
/* Clear this so we don't look
@@ -318,7 +353,7 @@ max can be %d\n",
/* Child code ... */
/* close the listening socket(s) */
- for(i = 0; i < num_interfaces; i++)
+ for(i = 0; i < num_sockets; i++)
close(fd_listenset[i]);
/* close our standard file
@@ -609,7 +644,7 @@ static void usage(char *pname)
BOOL is_daemon = False;
BOOL interactive = False;
BOOL specified_logfile = False;
- int port = SMB_PORT;
+ char *ports = NULL;
int opt;
pstring logfile;
@@ -664,7 +699,7 @@ static void usage(char *pname)
break;
case 'p':
- port = atoi(optarg);
+ ports = optarg;
break;
case 'h':
@@ -837,7 +872,7 @@ static void usage(char *pname)
start_background_queue();
*/
- if (!open_sockets_smbd(is_daemon,port))
+ if (!open_sockets_smbd(is_daemon,ports))
exit(1);
/*