s3: Use pid_to_procid
[nivanova/samba-autobuild/.git] / source3 / smbd / server.c
index f6d26572891c50cfa6596d246bbe746fa88084dd..cc51979c34c3d86906c291a1a055a52802c6ca8d 100644 (file)
 #include "ctdbd_conn.h"
 #include "printing/queue_process.h"
 #include "rpc_server/rpc_service_setup.h"
+#include "rpc_server/rpc_config.h"
 #include "serverid.h"
 #include "passdb.h"
 #include "auth.h"
 #include "messages.h"
 #include "smbprofile.h"
+#include "lib/id_cache.h"
+#include "lib/param/param.h"
 
 extern void start_epmd(struct tevent_context *ev_ctx,
                       struct messaging_context *msg_ctx);
@@ -61,11 +64,12 @@ static void smb_conf_updated(struct messaging_context *msg,
 {
        struct tevent_context *ev_ctx =
                talloc_get_type_abort(private_data, struct tevent_context);
+       struct smbd_server_connection *sconn = msg_ctx_to_sconn(msg);
 
        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);
+       reload_services(msg, sconn->sock, False);
        if (am_parent) {
                printing_subsystem_update(ev_ctx, msg, false);
        }
@@ -86,7 +90,7 @@ static void smb_pcap_updated(struct messaging_context *msg,
 
        DEBUG(10,("Got message saying pcap was updated. Reloading.\n"));
        change_to_root_user();
-       reload_printers(ev_ctx, msg);
+       delete_and_reload_printers(ev_ctx, msg);
 }
 
 /*******************************************************************
@@ -170,6 +174,22 @@ static void msg_inject_fault(struct messaging_context *msg,
 }
 #endif /* DEVELOPER */
 
+NTSTATUS messaging_send_to_children(struct messaging_context *msg_ctx,
+                                   uint32_t msg_type, DATA_BLOB* data)
+{
+       NTSTATUS status;
+       struct child_pid *child;
+
+       for (child = children; child != NULL; child = child->next) {
+               status = messaging_send(msg_ctx, pid_to_procid(child->pid),
+                                       msg_type, data);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+       }
+       return NT_STATUS_OK;
+}
+
 /*
  * Parent smbd process sets its own debug level first and then
  * sends a message to all the smbd children to adjust their debug
@@ -182,16 +202,9 @@ static void smbd_msg_debug(struct messaging_context *msg_ctx,
                           struct server_id server_id,
                           DATA_BLOB *data)
 {
-       struct child_pid *child;
-
        debug_message(msg_ctx, private_data, MSG_DEBUG, server_id, data);
 
-       for (child = children; child != NULL; child = child->next) {
-               messaging_send_buf(msg_ctx, pid_to_procid(child->pid),
-                                  MSG_DEBUG,
-                                  data->data,
-                                  strlen((char *) data->data) + 1);
-       }
+       messaging_send_to_children(msg_ctx, MSG_DEBUG, data);
 }
 
 static void add_child_pid(pid_t pid)
@@ -225,10 +238,11 @@ static void cleanup_timeout_fn(struct event_context *event_ctx,
                                void *private_data)
 {
        struct timed_event **cleanup_te = (struct timed_event **)private_data;
+       struct messaging_context *msg = smbd_messaging_context();
 
        DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n"));
-       message_send_all(smbd_messaging_context(), MSG_SMB_UNLOCK, NULL, 0, NULL);
-       messaging_send_buf(smbd_messaging_context(), procid_self(),
+       message_send_all(msg, MSG_SMB_UNLOCK, NULL, 0, NULL);
+       messaging_send_buf(msg, messaging_server_id(msg),
                                MSG_SMB_BRL_VALIDATE, NULL, 0);
        /* mark the cleanup as having been done */
        (*cleanup_te) = NULL;
@@ -260,8 +274,7 @@ static void remove_child_pid(struct tevent_context *ev_ctx,
                }
        }
 
-       child_id = procid_self(); /* Just initialize pid and potentially vnn */
-       child_id.pid = pid;
+       child_id = pid_to_procid(pid);
 
        if (!serverid_deregister(child_id)) {
                DEBUG(1, ("Could not remove pid %d from serverid.tdb\n",
@@ -371,10 +384,10 @@ static void smbd_accept_connection(struct tevent_context *ev,
                                   uint16_t flags,
                                   void *private_data)
 {
-       struct smbd_server_connection *sconn = smbd_server_conn;
        struct smbd_open_socket *s = talloc_get_type_abort(private_data,
                                     struct smbd_open_socket);
        struct messaging_context *msg_ctx = s->msg_ctx;
+       struct smbd_server_connection *sconn = msg_ctx_to_sconn(msg_ctx);
        struct sockaddr_storage addr;
        socklen_t in_addrlen = sizeof(addr);
        int fd;
@@ -438,7 +451,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
 
                status = reinit_after_fork(msg_ctx,
                                           ev,
-                                          procid_self(),
                                           true);
                if (!NT_STATUS_IS_OK(status)) {
                        if (NT_STATUS_EQUAL(status,
@@ -464,7 +476,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
                smbd_setup_sig_hup_handler(ev,
                                           msg_ctx);
 
-               if (!serverid_register(procid_self(),
+               if (!serverid_register(messaging_server_id(msg_ctx),
                                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD
                                       |FLAG_MSG_DBWRAP
                                       |FLAG_MSG_PRINT_GENERAL)) {
@@ -472,7 +484,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
                                            "serverid.tdb");
                }
 
-               smbd_process(ev, smbd_server_conn);
+               smbd_process(ev, sconn);
         exit:
                exit_server_cleanly("end of child");
                return;
@@ -724,8 +736,9 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
           operations until it has gone thru a full startup, which
           includes checking to see that smbd is listening. */
 
-       if (!serverid_register(procid_self(),
+       if (!serverid_register(messaging_server_id(msg_ctx),
                               FLAG_MSG_GENERAL|FLAG_MSG_SMBD
+                              |FLAG_MSG_PRINT_GENERAL
                               |FLAG_MSG_DBWRAP)) {
                DEBUG(0, ("open_sockets_smbd: Failed to register "
                          "myself in serverid.tdb\n"));
@@ -747,7 +760,7 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
                           smb_pcap_updated);
        brl_register_msgs(msg_ctx);
 
-       msg_idmap_register_msgs(msg_ctx);
+       msg_idmap_register_msg(msg_ctx);
 
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
@@ -1106,7 +1119,7 @@ extern void build_options(bool screen);
 
        status = reinit_after_fork(msg_ctx,
                                   ev_ctx,
-                                  procid_self(), false);
+                                  false);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                exit(1);
@@ -1138,10 +1151,12 @@ extern void build_options(bool screen);
        }
 
        if (lp_server_role() == ROLE_DOMAIN_BDC || lp_server_role() == ROLE_DOMAIN_PDC) {
-               if (!open_schannel_session_store(NULL, lp_private_dir())) {
+               struct loadparm_context *lp_ctx = loadparm_init_s3(NULL, loadparm_s3_context());
+               if (!open_schannel_session_store(NULL, lp_ctx)) {
                        DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
                        exit(1);
                }
+               TALLOC_FREE(lp_ctx);
        }
 
        if(!get_global_sam_sid()) {
@@ -1210,9 +1225,7 @@ extern void build_options(bool screen);
        }
 
        if (is_daemon && !interactive) {
-               enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
-
-               if (epm_mode == RPC_SERVICE_MODE_DAEMON) {
+               if (rpc_epmapper_daemon() == RPC_DAEMON_FORK) {
                        start_epmd(ev_ctx, msg_ctx);
                }
        }
@@ -1225,20 +1238,21 @@ extern void build_options(bool screen);
         * -- bad things will happen if smbd is launched via inetd
         *  and we fork a copy of ourselves here */
        if (is_daemon && !interactive) {
-               enum rpc_service_mode_e lsarpc_mode = rpc_lsarpc_mode();
 
-               if (lsarpc_mode == RPC_SERVICE_MODE_DAEMON) {
+               if (rpc_lsasd_daemon() == RPC_DAEMON_FORK) {
                        start_lsasd(ev_ctx, msg_ctx);
                }
 
-               if (!_lp_disable_spoolss()) {
+               if (!_lp_disable_spoolss() &&
+                   (rpc_spoolss_daemon() != RPC_DAEMON_DISABLED)) {
                        bool bgq = lp_parm_bool(-1, "smbd", "backgroundqueue", true);
 
                        if (!printing_subsystem_init(ev_ctx, msg_ctx, true, bgq)) {
                                exit(1);
                        }
                }
-       } else if (!_lp_disable_spoolss()) {
+       } else if (!_lp_disable_spoolss() &&
+                  (rpc_spoolss_daemon() != RPC_DAEMON_DISABLED)) {
                if (!printing_subsystem_init(ev_ctx, msg_ctx, false, false)) {
                        exit(1);
                }