r1233: -move smb related code to smb_server/*
authorStefan Metzmacher <metze@samba.org>
Wed, 23 Jun 2004 23:44:50 +0000 (23:44 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:56:46 +0000 (12:56 -0500)
-move process_model code to smbd/process_model.c
-remove some used code

metze
(This used to be commit 10dd8487290a2876253ce69033e374d23b42e704)

source4/smb_server/smb_server.c
source4/smbd/config.mk
source4/smbd/process.c [deleted file]
source4/smbd/process_model.c
source4/smbd/rewrite.c
source4/smbd/server.c

index 5eded2b85bf26324cda8f3ccb8edcf22c24069f2..e2ce4182a1771b989e7a2fbce6621f4284a6d4ae 100644 (file)
@@ -677,6 +677,104 @@ void server_terminate(struct server_context *smb)
        talloc_destroy(smb->mem_ctx);
 }
 
+/*
+  called on a fatal error that should cause this server to terminate
+*/
+void exit_server(struct server_context *smb, const char *reason)
+{
+       smb->model_ops->terminate_connection(smb, reason);
+}
+
+/*
+  setup a single listener of any type
+ */
+static void setup_listen(struct event_context *events,
+                        const struct model_ops *model_ops, 
+                        void (*accept_handler)(struct event_context *,struct fd_event *,time_t,uint16_t),
+                        struct in_addr *ifip, uint_t port)
+{
+       struct fd_event fde;
+       fde.fd = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
+       if (fde.fd == -1) {
+               DEBUG(0,("Failed to open socket on %s:%u - %s\n",
+                        inet_ntoa(*ifip), port, strerror(errno)));
+               return;
+       }
+
+       /* ready to listen */
+       set_socket_options(fde.fd, "SO_KEEPALIVE"); 
+       set_socket_options(fde.fd, lp_socket_options());
+      
+       if (listen(fde.fd, SMBD_LISTEN_BACKLOG) == -1) {
+               DEBUG(0,("Failed to listen on %s:%d - %s\n",
+                        inet_ntoa(*ifip), port, strerror(errno)));
+               close(fde.fd);
+               return;
+       }
+
+       /* we are only interested in read events on the listen socket */
+       fde.flags = EVENT_FD_READ;
+       fde.private = model_ops;
+       fde.handler = accept_handler;
+       
+       event_add_fd(events, &fde);
+}
+
+/*
+  add a socket address to the list of events, one event per port
+*/
+static void add_socket(struct event_context *events, 
+                      const struct model_ops *model_ops, 
+                      struct in_addr *ifip)
+{
+       char *ptr, *tok;
+       const char *delim = ", ";
+
+       for (tok=strtok_r(lp_smb_ports(), delim, &ptr); 
+            tok; 
+            tok=strtok_r(NULL, delim, &ptr)) {
+               uint_t port = atoi(tok);
+               if (port == 0) continue;
+               setup_listen(events, model_ops, model_ops->accept_connection, ifip, port);
+       }
+}
+
+/****************************************************************************
+ Open the socket communication.
+****************************************************************************/
+void open_sockets_smbd(struct event_context *events,
+                             const struct model_ops *model_ops)
+{
+       if (lp_interfaces() && lp_bind_interfaces_only()) {
+               int num_interfaces = iface_count();
+               int i;
+
+               /* 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.
+               */
+               for(i = 0; i < num_interfaces; i++) {
+                       struct in_addr *ifip = iface_n_ip(i);
+
+                       if (ifip == NULL) {
+                               DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
+                               continue;
+                       }
+
+                       add_socket(events, model_ops, ifip);
+               }
+       } else {
+               TALLOC_CTX *mem_ctx = talloc_init("open_sockets_smbd");
+               
+               struct in_addr *ifip = interpret_addr2(mem_ctx, lp_socket_address());
+               /* Just bind to lp_socket_address() (usually 0.0.0.0) */
+               if (!mem_ctx) {
+                       smb_panic("No memory");
+               }
+               add_socket(events, model_ops, ifip);
+               talloc_destroy(mem_ctx);
+       } 
+}
 
 /*
   called when a SMB socket becomes readable
index d5fd9700b9f659a089e08fad96fbd6162dd55127..cd0d80150bb281fe4a71864aa2141d0a1dacfb49 100644 (file)
@@ -30,7 +30,6 @@ REQUIRED_SUBSYSTEMS = \
 INIT_OBJ_FILES = \
                smbd/server.o
 ADD_OBJ_FILES = \
-               smbd/process.o \
                smbd/build_options.o \
                smbd/rewrite.o
 REQUIRED_SUBSYSTEMS = \
diff --git a/source4/smbd/process.c b/source4/smbd/process.c
deleted file mode 100644 (file)
index 232c7c2..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   process incoming packets - main loop
-   Copyright (C) Andrew Tridgell 1992-2003
-   Copyright (C) James J Myers 2003 <myersjj@samba.org>
-   
-   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 2 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.
-*/
-
-#include "includes.h"
-
-/*
- * initialize an smb process
- */
-void smbd_process_init(void)
-{
-       TALLOC_CTX *mem_ctx;
-
-       mem_ctx = talloc_init("smbd_process_init talloc");
-       if (!mem_ctx) {
-               DEBUG(0,("smbd_process_init: ERROR: No memory\n"));
-               exit(1);
-       }
-       namecache_enable();
-
-       if (!share_info_db_init())
-               exit(1);
-
-       if (!init_registry())
-               exit(1);
-
-       /* possibly reload the services file. */
-       reload_services(NULL, True);
-
-       if (*lp_rootdir()) {
-               if (sys_chroot(lp_rootdir()) == 0)
-                       DEBUG(2,("Changed root to %s\n", lp_rootdir()));
-       }
-
-       /* Setup oplocks */
-       if (!init_oplocks())
-               exit(1);
-       
-       /* Setup change notify */
-       if (!init_change_notify())
-               exit(1);
-
-       talloc_destroy(mem_ctx);
-}
-
-void init_subsystems(void)
-{
-       /* Setup the PROCESS_MODEL subsystem */
-       if (!process_model_init())
-               exit(1);
-
-       /* Setup the AUTH subsystem */
-       if (!auth_init())
-               exit(1);
-
-       /* Setup the NTVFS subsystem */
-       if (!ntvfs_init())
-               exit(1);
-
-       /* Setup the DCERPC subsystem */
-       if (!dcesrv_init())
-               exit(1);
-
-}
index 121b35aba44b41d839a0656e4e619be373efe1b9..1947b37dc3fd117033f0b4c7c3fd27fd09175664 100644 (file)
 
 #include "includes.h"
 
+/*
+  setup the events for the chosen process model
+*/
+void process_model_startup(struct event_context *events, 
+                               const char *model)
+{
+       const struct model_ops *ops;
+
+       ops = process_model_byname(model);
+       if (!ops) {
+               DEBUG(0,("Unknown process model '%s'\n", model));
+               exit(-1);
+       }
+
+       ops->model_startup();
+
+       /* now setup the listening sockets, adding 
+          event handlers to the events structure */
+       open_sockets_smbd(events, ops);
+
+       /* setup any sockets we need to listen on for RPC over TCP */
+       open_sockets_rpc(events, ops);
+}
 
 /* the list of currently registered process models */
 static struct {
index e32cd96a0e9b73a799bad0b869101c71ed6cfd57..2250c5cc2771e180d69f8acc26330af4614eb24d 100644 (file)
@@ -35,18 +35,108 @@ BOOL init_change_notify(void)
 BOOL pcap_printername_ok(const char *service, const char *foo)
 { return True; }
 
-BOOL namecache_enable(void)
-{ return True; }
-
-BOOL share_info_db_init(void)
-{ return True; }
-
-BOOL init_registry(void)
-{ return True; }
-
 BOOL share_access_check(struct request_context *req, struct tcon_context *conn, int snum, uint32_t desired_access)
 { return True; }
 
 BOOL init_names(void)
 { return True; }
 
+/*
+ * initialize an smb process
+ */
+void smbd_process_init(void)
+{
+       TALLOC_CTX *mem_ctx;
+
+       mem_ctx = talloc_init("smbd_process_init talloc");
+       if (!mem_ctx) {
+               DEBUG(0,("smbd_process_init: ERROR: No memory\n"));
+               exit(1);
+       }
+
+       /* possibly reload the services file. */
+       reload_services(NULL, True);
+
+       if (*lp_rootdir()) {
+               if (sys_chroot(lp_rootdir()) == 0)
+                       DEBUG(2,("Changed root to %s\n", lp_rootdir()));
+       }
+
+       /* Setup oplocks */
+       if (!init_oplocks())
+               exit(1);
+       
+       /* Setup change notify */
+       if (!init_change_notify())
+               exit(1);
+
+       talloc_destroy(mem_ctx);
+}
+
+void init_subsystems(void)
+{
+       /* Setup the PROCESS_MODEL subsystem */
+       if (!process_model_init())
+               exit(1);
+
+       /* Setup the AUTH subsystem */
+       if (!auth_init())
+               exit(1);
+
+       /* Setup the NTVFS subsystem */
+       if (!ntvfs_init())
+               exit(1);
+
+       /* Setup the DCERPC subsystem */
+       if (!dcesrv_init())
+               exit(1);
+
+}
+
+/****************************************************************************
+ Reload the services file.
+**************************************************************************/
+BOOL reload_services(struct server_context *smb, BOOL test)
+{
+       BOOL ret;
+       
+       if (lp_loaded()) {
+               pstring fname;
+               pstrcpy(fname,lp_configfile());
+               if (file_exist(fname, NULL) &&
+                   !strcsequal(fname, dyn_CONFIGFILE)) {
+                       pstrcpy(dyn_CONFIGFILE, fname);
+                       test = False;
+               }
+       }
+
+       reopen_logs();
+
+       if (test && !lp_file_list_changed())
+               return(True);
+
+       if (smb) {
+               lp_killunused(smb, conn_snum_used);
+       }
+       
+       ret = lp_load(dyn_CONFIGFILE, False, False, True);
+
+       load_printers();
+
+       /* perhaps the config filename is now set */
+       if (!test)
+               reload_services(smb, True);
+
+       reopen_logs();
+
+       load_interfaces();
+
+       mangle_reset_cache();
+       reset_stat_cache();
+
+       /* this forces service parameters to be flushed */
+       set_current_service(NULL,True);
+
+       return(ret);
+}
+
index a753a2d6dbeb953714d9c9b838557e0013e32730..3a579b846a21e5b4df48dc7c713054d18133a34a 100644 (file)
 
 #include "includes.h"
 
-
-/*
-  called on a fatal error that should cause this server to terminate
-*/
-void exit_server(struct server_context *smb, const char *reason)
-{
-       smb->model_ops->terminate_connection(smb, reason);
-}
-
-
-/*
-  setup a single listener of any type
- */
-static void setup_listen(struct event_context *events,
-                        const struct model_ops *model_ops, 
-                        void (*accept_handler)(struct event_context *,struct fd_event *,time_t,uint16_t),
-                        struct in_addr *ifip, uint_t port)
-{
-       struct fd_event fde;
-       fde.fd = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
-       if (fde.fd == -1) {
-               DEBUG(0,("Failed to open socket on %s:%u - %s\n",
-                        inet_ntoa(*ifip), port, strerror(errno)));
-               return;
-       }
-
-       /* ready to listen */
-       set_socket_options(fde.fd, "SO_KEEPALIVE"); 
-       set_socket_options(fde.fd, lp_socket_options());
-      
-       if (listen(fde.fd, SMBD_LISTEN_BACKLOG) == -1) {
-               DEBUG(0,("Failed to listen on %s:%d - %s\n",
-                        inet_ntoa(*ifip), port, strerror(errno)));
-               close(fde.fd);
-               return;
-       }
-
-       /* we are only interested in read events on the listen socket */
-       fde.flags = EVENT_FD_READ;
-       fde.private = model_ops;
-       fde.handler = accept_handler;
-       
-       event_add_fd(events, &fde);
-}
-
-/*
-  add a socket address to the list of events, one event per port
-*/
-static void add_socket(struct event_context *events, 
-                      const struct model_ops *model_ops, 
-                      struct in_addr *ifip)
-{
-       char *ptr, *tok;
-       const char *delim = ", ";
-
-       for (tok=strtok_r(lp_smb_ports(), delim, &ptr); 
-            tok; 
-            tok=strtok_r(NULL, delim, &ptr)) {
-               uint_t port = atoi(tok);
-               if (port == 0) continue;
-               setup_listen(events, model_ops, model_ops->accept_connection, ifip, port);
-       }
-}
-
-/****************************************************************************
- Open the socket communication.
-****************************************************************************/
-static void open_sockets_smbd(struct event_context *events,
-                             const struct model_ops *model_ops)
-{
-       if (lp_interfaces() && lp_bind_interfaces_only()) {
-               int num_interfaces = iface_count();
-               int i;
-
-               /* 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.
-               */
-               for(i = 0; i < num_interfaces; i++) {
-                       struct in_addr *ifip = iface_n_ip(i);
-
-                       if (ifip == NULL) {
-                               DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
-                               continue;
-                       }
-
-                       add_socket(events, model_ops, ifip);
-               }
-       } else {
-               TALLOC_CTX *mem_ctx = talloc_init("open_sockets_smbd");
-               
-               struct in_addr *ifip = interpret_addr2(mem_ctx, lp_socket_address());
-               /* Just bind to lp_socket_address() (usually 0.0.0.0) */
-               if (!mem_ctx) {
-                       smb_panic("No memory");
-               }
-               add_socket(events, model_ops, ifip);
-               talloc_destroy(mem_ctx);
-       } 
-}
-
-/****************************************************************************
- Reload the services file.
-**************************************************************************/
-BOOL reload_services(struct server_context *smb, BOOL test)
-{
-       BOOL ret;
-       
-       if (lp_loaded()) {
-               pstring fname;
-               pstrcpy(fname,lp_configfile());
-               if (file_exist(fname, NULL) &&
-                   !strcsequal(fname, dyn_CONFIGFILE)) {
-                       pstrcpy(dyn_CONFIGFILE, fname);
-                       test = False;
-               }
-       }
-
-       reopen_logs();
-
-       if (test && !lp_file_list_changed())
-               return(True);
-
-       if (smb) {
-               lp_killunused(smb, conn_snum_used);
-       }
-       
-       ret = lp_load(dyn_CONFIGFILE, False, False, True);
-
-       load_printers();
-
-       /* perhaps the config filename is now set */
-       if (!test)
-               reload_services(smb, True);
-
-       reopen_logs();
-
-       load_interfaces();
-
-       mangle_reset_cache();
-       reset_stat_cache();
-
-       /* this forces service parameters to be flushed */
-       set_current_service(NULL,True);
-
-       return(ret);
-}
-
-/****************************************************************************
- Initialise connect, service and file structs.
-****************************************************************************/
-static BOOL init_structs(void)
-{
-       init_names();
-       file_init();
-       secrets_init();
-
-       /* we want to re-seed early to prevent time delays causing
-           client problems at a later date. (tridge) */
-       generate_random_buffer(NULL, 0, False);
-
-       return True;
-}
-
-
-/*
-  setup the events for the chosen process model
-*/
-static void setup_process_model(struct event_context *events, 
-                               const char *model)
-{
-       const struct model_ops *ops;
-
-       ops = process_model_byname(model);
-       if (!ops) {
-               DEBUG(0,("Unknown process model '%s'\n", model));
-               exit(-1);
-       }
-
-       ops->model_startup();
-
-       /* now setup the listening sockets, adding 
-          event handlers to the events structure */
-       open_sockets_smbd(events, ops);
-
-       /* setup any sockets we need to listen on for RPC over TCP */
-       open_sockets_rpc(events, ops);
-}
-
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -311,8 +122,6 @@ static void setup_process_model(struct event_context *events,
        if (!reload_services(NULL, False))
                return(-1);     
 
-       init_structs();
-
        if (!is_daemon && !is_a_socket(0)) {
                if (!interactive)
                        DEBUG(0,("standard input is not a socket, assuming -D option\n"));
@@ -338,12 +147,9 @@ static void setup_process_model(struct event_context *events,
                pidfile_create("smbd");
        }
 
-       register_msg_pool_usage();
-       register_dmalloc_msgs();
-
        init_subsystems();
 
-       setup_process_model(events, model);
+       process_model_startup(events, model);
 
        /* wait for events */
        return event_loop_wait(events);