s3-smbd: expose smbd_set_server_fd()
[samba.git] / source3 / smbd / server.c
index 81283f0ec956551fb6f59dd6c2652be348a4639d..29acf8d2219790e203fb4554bfbd45f68b308958 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "popt_common.h"
+#include "smbd/smbd.h"
 #include "smbd/globals.h"
-#include "librpc/gen_ndr/messaging.h"
-#include "registry.h"
 #include "registry/reg_init_full.h"
 #include "libcli/auth/schannel.h"
 #include "secrets.h"
 #include "rpc_server/rpc_ep_setup.h"
 #include "printing/pcap.h"
 #include "printing.h"
+#include "serverid.h"
+#include "passdb.h"
+#include "auth.h"
+#include "messages.h"
+#include "smbprofile.h"
+
+extern void start_epmd(struct tevent_context *ev_ctx,
+                      struct messaging_context *msg_ctx);
+
+extern void start_spoolssd(struct event_context *ev_ctx,
+                          struct messaging_context *msg_ctx);
 
 #ifdef WITH_DFS
 extern int dcelogin_atmost_once;
 #endif /* WITH_DFS */
 
-static void smbd_set_server_fd(int fd)
-{
-       struct smbd_server_connection *sconn = smbd_server_conn;
-       char addr[INET6_ADDRSTRLEN];
-       const char *name;
-
-       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;
-
-       sub_set_socket_ids(sconn->client_id.addr, sconn->client_id.name,
-                          client_socket_addr(sconn->sock, addr,
-                                             sizeof(addr)));
-}
-
 struct event_context *smbd_event_context(void)
 {
        return server_event_context();
@@ -84,12 +66,15 @@ static void smb_conf_updated(struct messaging_context *msg,
                             struct server_id server_id,
                             DATA_BLOB *data)
 {
+       struct tevent_context *ev_ctx =
+               talloc_get_type_abort(private_data, struct tevent_context);
+
        DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
                  "updated. Reloading.\n"));
        change_to_root_user();
        reload_services(msg, smbd_server_conn->sock, False);
        if (am_parent) {
-               pcap_cache_reload(server_event_context(), msg,
+               pcap_cache_reload(ev_ctx, msg,
                                  &reload_pcap_change_notify);
        }
 }
@@ -104,9 +89,12 @@ static void smb_pcap_updated(struct messaging_context *msg,
                             struct server_id server_id,
                             DATA_BLOB *data)
 {
+       struct tevent_context *ev_ctx =
+               talloc_get_type_abort(private_data, struct tevent_context);
+
        DEBUG(10,("Got message saying pcap was updated. Reloading.\n"));
        change_to_root_user();
-       reload_printers(server_event_context(), msg);
+       reload_printers(ev_ctx, msg);
 }
 
 /*******************************************************************
@@ -664,6 +652,13 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
                                        continue;
                                }
 
+                               /* Keep the first port for mDNS service
+                                * registration.
+                                */
+                               if (dns_port == 0) {
+                                       dns_port = port;
+                               }
+
                                if (!smbd_open_one_socket(parent, ifss, port)) {
                                        return false;
                                }
@@ -752,14 +747,17 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
        messaging_register(msg_ctx, NULL, MSG_SHUTDOWN, msg_exit_server);
        messaging_register(msg_ctx, NULL, MSG_SMB_FILE_RENAME,
                           msg_file_was_renamed);
-       messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED,
+       messaging_register(msg_ctx, server_event_context(), MSG_SMB_CONF_UPDATED,
                           smb_conf_updated);
        messaging_register(msg_ctx, NULL, MSG_SMB_STAT_CACHE_DELETE,
                           smb_stat_cache_delete);
        messaging_register(msg_ctx, NULL, MSG_DEBUG, smbd_msg_debug);
-       messaging_register(msg_ctx, NULL, MSG_PRINTER_PCAP, smb_pcap_updated);
+       messaging_register(msg_ctx, server_event_context(), MSG_PRINTER_PCAP,
+                          smb_pcap_updated);
        brl_register_msgs(msg_ctx);
 
+       msg_idmap_register_msgs(msg_ctx);
+
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
                ctdbd_register_reconfigure(messaging_ctdbd_connection());
@@ -973,8 +971,8 @@ extern void build_options(bool screen);
        gain_root_privilege();
        gain_root_group_privilege();
 
-       fault_setup((void (*)(void *))exit_server_fault);
-       dump_core_setup("smbd");
+       fault_setup();
+       dump_core_setup("smbd", lp_logfile());
 
        /* we are never interested in SIGPIPE */
        BlockSignals(True,SIGPIPE);
@@ -1021,7 +1019,7 @@ extern void build_options(bool screen);
        }
 
        if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
-               DEBUG(0, ("error opening config file\n"));
+               DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE()));
                exit(1);
        }
 
@@ -1198,6 +1196,18 @@ extern void build_options(bool screen);
                return -1;
        }
 
+       if (is_daemon && !interactive) {
+               const char *rpcsrv_type;
+
+               rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                                  "rpc_server", "epmapper",
+                                                  "none");
+               if (StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+                       start_epmd(smbd_event_context(),
+                                  smbd_server_conn->msg_ctx);
+               }
+       }
+
        if (!dcesrv_ep_setup(smbd_event_context(), smbd_server_conn->msg_ctx)) {
                exit(1);
        }
@@ -1217,6 +1227,20 @@ extern void build_options(bool screen);
                                       smbd_messaging_context());
        }
 
+       if (is_daemon && !_lp_disable_spoolss()) {
+               const char *rpcsrv_type;
+
+               /* start spoolss daemon */
+               /* start as a separate daemon only if enabled */
+               rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                                  "rpc_server", "spoolss",
+                                                  "embedded");
+               if (StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+                       start_spoolssd(smbd_event_context(),
+                                      smbd_messaging_context());
+               }
+       }
+
        if (!is_daemon) {
                /* inetd mode */
                TALLOC_FREE(frame);