s3-build: only include memcache.h where needed.
[nivanova/samba-autobuild/.git] / source3 / smbd / server.c
index c41ad6fbafd82979ef1badcfe40ea493de59bf52..3797ae93da94afb57e372b2fd3a2fe87cf51d9e0 100644 (file)
 #include "registry.h"
 #include "libcli/auth/schannel.h"
 #include "secrets.h"
+#include "memcache.h"
+
+#include "../librpc/gen_ndr/srv_dfs.h"
+#include "../librpc/gen_ndr/srv_dssetup.h"
+#include "../librpc/gen_ndr/srv_echo.h"
+#include "../librpc/gen_ndr/srv_eventlog.h"
+#include "../librpc/gen_ndr/srv_initshutdown.h"
+#include "../librpc/gen_ndr/srv_lsa.h"
+#include "../librpc/gen_ndr/srv_netlogon.h"
+#include "../librpc/gen_ndr/srv_ntsvcs.h"
+#include "../librpc/gen_ndr/srv_samr.h"
+#include "../librpc/gen_ndr/srv_spoolss.h"
+#include "../librpc/gen_ndr/srv_srvsvc.h"
+#include "../librpc/gen_ndr/srv_svcctl.h"
+#include "../librpc/gen_ndr/srv_winreg.h"
+#include "../librpc/gen_ndr/srv_wkssvc.h"
+
+#include "printing/nt_printing_migrate.h"
 
 static_decl_rpc;
 
@@ -42,12 +60,28 @@ int smbd_server_fd(void)
 
 static void smbd_set_server_fd(int fd)
 {
+       struct smbd_server_connection *sconn = smbd_server_conn;
+       const char *name;
+
        server_fd = fd;
-}
 
-int get_client_fd(void)
-{
-       return server_fd;
+       sconn->sock = fd;
+
+       /*
+        * Initialize sconn->client_id: If we can't find the client's
+        * name, default to its address.
+        */
+
+       client_addr(fd, sconn->client_id.addr, sizeof(sconn->client_id.addr));
+
+       name = client_name(sconn->sock);
+       if (strcmp(name, "UNKNOWN") != 0) {
+               name = talloc_strdup(sconn, name);
+       } else {
+               name = NULL;
+       }
+       sconn->client_id.name =
+               (name != NULL) ? name : sconn->client_id.addr;
 }
 
 struct event_context *smbd_event_context(void)
@@ -68,7 +102,7 @@ static void smb_conf_updated(struct messaging_context *msg,
        DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
                  "updated. Reloading.\n"));
        change_to_root_user();
-       reload_services(msg, False);
+       reload_services(msg, smbd_server_fd(), False);
 }
 
 
@@ -767,6 +801,13 @@ static bool init_structs(void )
        return True;
 }
 
+static bool spoolss_init_cb(void *ptr)
+{
+       struct messaging_context *msg_ctx = talloc_get_type_abort(
+               ptr, struct messaging_context);
+       return nt_printing_tdb_migrate(msg_ctx);
+}
+
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -815,6 +856,7 @@ extern void build_options(bool screen);
        TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */
        NTSTATUS status;
        uint64_t unique_id;
+       struct rpc_srv_callbacks spoolss_cb;
 
        /* Initialize the event context, it will panic on error */
        smbd_event_context();
@@ -957,8 +999,18 @@ extern void build_options(bool screen);
        if (smbd_messaging_context() == NULL)
                exit(1);
 
-       if (!reload_services(smbd_messaging_context(), False))
-               return(-1);     
+       /*
+        * Reloading of the printers will not work here as we don't have a
+        * server info and rpc services set up. It will be called later.
+        */
+       if (!reload_services(smbd_messaging_context(), smbd_server_fd(),
+                            False)) {
+               exit(1);
+       }
+
+       /* ...NOTE... Log files are working from this point! */
+
+       DEBUG(3,("loaded services\n"));
 
        init_structs();
 
@@ -977,8 +1029,6 @@ extern void build_options(bool screen);
        }
 #endif
 
-       DEBUG(3,( "loaded services\n"));
-
        if (!is_daemon && !is_a_socket(0)) {
                if (!interactive)
                        DEBUG(0,("standard input is not a socket, assuming -D option\n"));
@@ -1084,33 +1134,56 @@ extern void build_options(bool screen);
        if (!W_ERROR_IS_OK(registry_init_full()))
                exit(1);
 
+       if (!print_backend_init(smbd_messaging_context()))
+               exit(1);
+
 #if 0
        if (!init_svcctl_db())
                 exit(1);
 #endif
 
+       /* Open the share_info.tdb here, so we don't have to open
+          after the fork on every single connection.  This is a small
+          performance improvment and reduces the total number of system
+          fds used. */
+       if (!share_info_db_init()) {
+               DEBUG(0,("ERROR: failed to load share info db.\n"));
+               exit(1);
+       }
+
        if (!init_system_info()) {
                DEBUG(0,("ERROR: failed to setup system user info.\n"));
                return -1;
        }
 
-       if (!print_backend_init(smbd_messaging_context()))
-               exit(1);
-
        if (!init_guest_info()) {
                DEBUG(0,("ERROR: failed to setup guest info.\n"));
                return -1;
        }
 
-       /* Open the share_info.tdb here, so we don't have to open
-          after the fork on every single connection.  This is a small
-          performance improvment and reduces the total number of system
-          fds used. */
-       if (!share_info_db_init()) {
-               DEBUG(0,("ERROR: failed to load share info db.\n"));
+       /*
+        * Initialize spoolss with an init function to convert printers first.
+        * static_init_rpc will try to initialize the spoolss server too but you
+        * can't register it twice.
+        */
+       spoolss_cb.init = spoolss_init_cb;
+       spoolss_cb.shutdown = NULL;
+       spoolss_cb.private_data = smbd_server_conn->msg_ctx;
+
+       /* Spoolss depends on a winreg pipe, so start it first. */
+       if (!NT_STATUS_IS_OK(rpc_winreg_init(NULL))) {
+               exit(1);
+       }
+
+       if (!NT_STATUS_IS_OK(rpc_spoolss_init(&spoolss_cb))) {
                exit(1);
        }
 
+       static_init_rpc;
+
+       /* Publish nt printers, this requires a working winreg pipe */
+       reload_printers(smbd_messaging_context());
+
        /* only start the background queue daemon if we are 
           running as a daemon -- bad things will happen if
           smbd is launched via inetd and we fork a copy of