summaryrefslogtreecommitdiff
path: root/source3/smbd/server.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-11 13:55:53 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-11 13:55:53 +0000
commit2fa922611bf7160e2c1ce80c11b50006448bf98d (patch)
treeed29a6f6c0364ee631b049b26031139b9e74a4ec /source3/smbd/server.c
parent03630a9aa9ce5c00619ad3c4bb498d95054ae03a (diff)
downloadsamba-2fa922611bf7160e2c1ce80c11b50006448bf98d.tar.gz
samba-2fa922611bf7160e2c1ce80c11b50006448bf98d.tar.bz2
samba-2fa922611bf7160e2c1ce80c11b50006448bf98d.zip
finally got sick of the "extern int Client" code and the stupid
assumption that we have one socket everywhere while doing so I discovered a few bugs! 1) the clientgen session retarget code if used from smbd or nmbd would cause a crash as it called close_sockets() which closed our main socket! fixed by removing close_sockets() completely - it is unnecessary 2) the caching in client_addr() and client_name() was bogus - it could easily get fooled and give the wrong result. fixed. 3) the retarget could could recurse, allowing an easy denial of service attack on nmbd. fixed. (This used to be commit 5937ab14d222696e40a3fc6f0e6a536f2d7305d3)
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r--source3/smbd/server.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 401c236374..576f6d14d2 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -47,6 +47,26 @@ extern int dcelogin_atmost_once;
extern fstring remote_machine;
extern pstring OriginalDir;
+
+/* really we should have a top level context structure that has the
+ client file descriptor as an element. That would require a major rewrite :(
+
+ the following 2 functions are an alternative - they make the file
+ descriptor private to smbd
+ */
+static int server_fd;
+
+int smbd_server_fd(void)
+{
+ return server_fd;
+}
+
+void smbd_set_server_fd(int fd)
+{
+ server_fd = fd;
+ client_setfd(fd);
+}
+
/****************************************************************************
when exiting, take the whole family
****************************************************************************/
@@ -70,18 +90,16 @@ static void killkids(void)
****************************************************************************/
static BOOL open_sockets_inetd(void)
{
- extern int Client;
-
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
- Client = dup(0);
+ smbd_set_server_fd(dup(0));
/* close our standard file descriptors */
close_low_fds();
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
return True;
}
@@ -92,7 +110,6 @@ static BOOL open_sockets_inetd(void)
****************************************************************************/
static BOOL open_sockets(BOOL is_daemon,int port)
{
- extern int Client;
int num_interfaces = iface_count();
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
@@ -211,18 +228,18 @@ max can be %d\n",
}
}
- Client = accept(s,&addr,&in_addrlen);
+ smbd_set_server_fd(accept(s,&addr,&in_addrlen));
- if (Client == -1 && errno == EINTR)
+ if (smbd_server_fd() == -1 && errno == EINTR)
continue;
- if (Client == -1) {
+ if (smbd_server_fd() == -1) {
DEBUG(0,("open_sockets: accept: %s\n",
strerror(errno)));
continue;
}
- if (Client != -1 && fork()==0) {
+ if (smbd_server_fd() != -1 && fork()==0) {
/* Child code ... */
/* close the listening socket(s) */
@@ -234,8 +251,8 @@ max can be %d\n",
close_low_fds();
am_parent = 0;
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
/* Reset global variables in util.c so
that client substitutions will be
@@ -252,7 +269,7 @@ max can be %d\n",
return True;
}
/* The parent doesn't need this socket */
- close(Client);
+ close(smbd_server_fd());
/* Force parent to check log size after
* spawning child. Fix from
@@ -320,10 +337,9 @@ BOOL reload_services(BOOL test)
load_interfaces();
{
- extern int Client;
- if (Client != -1) {
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ if (smbd_server_fd() != -1) {
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
}
}
@@ -776,7 +792,6 @@ static void usage(char *pname)
exit(1);
smbd_process();
- close_sockets();
exit_server("normal exit");
return(0);