summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/smb.h4
-rw-r--r--source3/lib/util_sock.c2
-rw-r--r--source3/param/loadparm.c4
-rw-r--r--source3/smbd/server.c125
4 files changed, 88 insertions, 47 deletions
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 2911a991f2..263dd67c54 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -38,7 +38,9 @@
#define NMB_PORT 137
#define DGRAM_PORT 138
-#define SMB_PORT 139
+#define SMB_PORT1 445
+#define SMB_PORT2 139
+#define SMB_PORTS "445 139"
#define False (0)
#define True (1)
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 4f1f2a1470..5e2b7c5ed9 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -708,7 +708,7 @@ int open_socket_in( int type, int port, int dlevel, uint32 socket_addr, BOOL reb
/* now we've got a socket - we need to bind it */
if( bind( res, (struct sockaddr *)&sock, sizeof(sock) ) == -1 ) {
- if( DEBUGLVL(dlevel) && (port == SMB_PORT || port == NMB_PORT) ) {
+ if( DEBUGLVL(dlevel) && (port == SMB_PORT1 || port == SMB_PORT2 || port == NMB_PORT) ) {
dbgtext( "bind failed on port %d ", port );
dbgtext( "socket_addr = %s.\n", inet_ntoa( sock.sin_addr ) );
dbgtext( "Error = %s\n", strerror(errno) );
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 0cb9a48622..d329d7c0ce 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -87,6 +87,7 @@ static BOOL defaults_saved = False;
*/
typedef struct
{
+ char *smb_ports;
char *dos_charset;
char *unix_charset;
char *display_charset;
@@ -778,6 +779,7 @@ static struct parm_struct parm_table[] = {
{"Protocol Options", P_SEP, P_SEPARATOR},
+ {"smb ports", P_STRING, P_GLOBAL, &Globals.smb_ports, NULL, NULL, 0},
{"protocol", P_ENUM, P_GLOBAL, &Globals.maxprotocol, NULL, enum_protocol, 0},
{"large readwrite", P_BOOL, P_GLOBAL, &Globals.bLargeReadwrite, NULL, NULL, 0},
{"max protocol", P_ENUM, P_GLOBAL, &Globals.maxprotocol, NULL, enum_protocol, 0},
@@ -1369,6 +1371,7 @@ static void init_globals(void)
Globals.bUseSpnego = True;
+ string_set(&Globals.smb_ports, SMB_PORTS);
}
static TALLOC_CTX *lp_talloc;
@@ -1457,6 +1460,7 @@ static char *lp_string(const char *s)
#define FN_LOCAL_INTEGER(fn_name,val) \
int fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
+FN_GLOBAL_STRING(lp_smb_ports, &Globals.smb_ports)
FN_GLOBAL_STRING(lp_dos_charset, &Globals.dos_charset)
FN_GLOBAL_STRING(lp_unix_charset, &Globals.unix_charset)
FN_GLOBAL_STRING(lp_display_charset, &Globals.display_charset)
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);
/*