summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-09-08 19:37:45 +0000
committerLuke Leighton <lkcl@samba.org>1999-09-08 19:37:45 +0000
commit7f8f5e15bdffec00454168c0591fa39a88d191c2 (patch)
tree25faae6d6dc80106bd4dacf323488af4517e0583
parent58f8159566e49df82be1ed0ade83821a184b9203 (diff)
downloadsamba-7f8f5e15bdffec00454168c0591fa39a88d191c2.tar.gz
samba-7f8f5e15bdffec00454168c0591fa39a88d191c2.tar.bz2
samba-7f8f5e15bdffec00454168c0591fa39a88d191c2.zip
bertl <bs@niggard.org> patch for making samba listen on port 445, just like
nt 5 does. cool! (This used to be commit 727e1421b2c0f8c72c428776593498103304082b)
-rw-r--r--source3/lib/util_sock.c3
-rw-r--r--source3/smbd/process.c28
-rw-r--r--source3/smbd/server.c76
3 files changed, 79 insertions, 28 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index e9859dfa17..50c295f2bd 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -35,6 +35,9 @@ BOOL passive = False;
/* the client file descriptor */
int Client = -1;
+/* the port, where client connected */
+int ClientPort = 0;
+
/* the last IP received from */
struct in_addr lastip;
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index bc60cb474d..13dd932a57 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -746,6 +746,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize)
void smbd_process(void)
{
extern int Client;
+ extern int ClientPort;
InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
@@ -772,6 +773,33 @@ void smbd_process(void)
/* re-initialise the timezone */
TimeInit();
+ /* if connection on port 445, fake session setup... */
+ if(ClientPort == 445)
+ {
+ extern fstring remote_machine;
+ extern fstring local_machine;
+ char *s;
+
+ fstrcpy(remote_machine, dns_to_netbios_name(client_name(Client)));
+ fstrcpy(local_machine, global_myname);
+ remote_machine[15] = 0;
+ local_machine[15] = 0;
+ strlower(remote_machine);
+ strlower(local_machine);
+
+ DEBUG(2, ("smbd_process(): faking session setup\n"
+ "client_name: %s my_name: %s\n", remote_machine, local_machine));
+
+ add_session_user(remote_machine);
+
+ reload_services(True);
+ reopen_logs();
+
+ if(lp_status(-1)) {
+ claim_connection(NULL,"STATUS.",MAXSTATUS,True);
+ }
+ }
+
while (True)
{
int deadtime = lp_deadtime()*60;
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 4ea39e14c6..036ca9353c 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -76,11 +76,13 @@ static void killkids(void)
static BOOL open_sockets_inetd(void)
{
extern int Client;
+ extern int ClientPort;
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
Client = dup(0);
+ ClientPort = 138;
/* close our standard file descriptors */
close_low_fds();
@@ -91,13 +93,32 @@ static BOOL open_sockets_inetd(void)
return True;
}
+/****************************************************************************
+ open and listen to a socket
+****************************************************************************/
+static int open_server_socket(int port, ulong ipaddr)
+{
+ int s;
+
+ s = open_socket_in(SOCK_STREAM, port, 0, ipaddr);
+ if(s == -1)
+ return -1;
+ /* ready to listen */
+ if (listen(s, 5) == -1) {
+ DEBUG(0,("listen: %s\n", strerror(errno)));
+ close(s);
+ return -1;
+ }
+ return s;
+}
/****************************************************************************
open the socket communication
****************************************************************************/
-static BOOL open_sockets(BOOL is_daemon,int port)
+static BOOL open_sockets(BOOL is_daemon,int port,int port445)
{
extern int Client;
+ extern int ClientPort;
int num_interfaces = iface_count();
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
@@ -131,7 +152,7 @@ static BOOL open_sockets(BOOL is_daemon,int port)
socket per interface and bind to only these.
*/
- if(num_interfaces > FD_SETSIZE) {
+ if(num_interfaces * 2 > FD_SETSIZE) {
DEBUG(0,("open_sockets: Too many interfaces specified to bind to. Number was %d \
max can be %d\n",
num_interfaces, FD_SETSIZE));
@@ -147,15 +168,11 @@ max can be %d\n",
DEBUG(0,("open_sockets: interface %d has NULL IP address !\n", i));
continue;
}
- s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr);
- if(s == -1)
- return False;
- /* ready to listen */
- if (listen(s, 5) == -1) {
- DEBUG(0,("listen: %s\n",strerror(errno)));
- close(s);
- return False;
- }
+ s = fd_listenset[i * 2] = open_server_socket(port, ifip->s_addr);
+ if(s == -1) return False;
+ FD_SET(s,&listen_set);
+ s = fd_listenset[i * 2 + 1] = open_server_socket(port445, ifip->s_addr);
+ if(s == -1) return False;
FD_SET(s,&listen_set);
}
} else {
@@ -164,21 +181,16 @@ max can be %d\n",
num_interfaces = 1;
/* open an incoming socket */
- s = open_socket_in(SOCK_STREAM, port, 0,
- interpret_addr(lp_socket_address()));
+ s = open_server_socket(port, interpret_addr(lp_socket_address()));
if (s == -1)
return(False);
-
- /* ready to listen */
- if (listen(s, 5) == -1) {
- DEBUG(0,("open_sockets: listen: %s\n",
- strerror(errno)));
- close(s);
- return False;
- }
-
fd_listenset[0] = s;
FD_SET(s,&listen_set);
+ s = open_server_socket(port445, interpret_addr(lp_socket_address()));
+ if (s == -1)
+ return(False);
+ fd_listenset[1] = s;
+ FD_SET(s,&listen_set);
}
/* now accept incoming connections - forking a new process
@@ -204,15 +216,22 @@ max can be %d\n",
s = -1;
for(i = 0; i < num_interfaces; i++) {
- if(FD_ISSET(fd_listenset[i],&lfds)) {
- s = fd_listenset[i];
- /* Clear this so we don't look
- at it again. */
- FD_CLR(fd_listenset[i],&lfds);
+ if(FD_ISSET(fd_listenset[i * 2],&lfds)) {
+ s = fd_listenset[i * 2];
+ ClientPort = 138;
+ break;
+ }
+ if(FD_ISSET(fd_listenset[i * 2 + 1],&lfds)) {
+ s = fd_listenset[i * 2 + 1];
+ ClientPort = 445;
break;
}
}
+ /* Clear this so we don't look
+ at it again. */
+ FD_CLR(s,&lfds);
+
Client = accept(s,&addr,&in_addrlen);
if (Client == -1 && errno == EINTR)
@@ -489,6 +508,7 @@ static void usage(char *pname)
/* shall I run as a daemon */
BOOL is_daemon = False;
int port = SMB_PORT;
+ int port445 = 455;
int opt;
extern char *optarg;
@@ -728,7 +748,7 @@ static void usage(char *pname)
pidfile_create("smbd");
}
- if (!open_sockets(is_daemon,port))
+ if (!open_sockets(is_daemon,port,port445))
exit(1);
if (!locking_init(0))