netcmd/ldapcmp: use set instead of list to find missing DNs
[amitay/samba.git] / source3 / rpc_server / lsasd.c
index 0a7e4ff312fec48b70c3f1e8542ccd08936cb247..4b9403036de91c3fbce6426e9d0cf54d5fd290a2 100644 (file)
  */
 
 #include "includes.h"
-#include "serverid.h"
 #include "messages.h"
 #include "ntdomain.h"
-
-#include "lib/util/util_process.h"
+#include "passdb.h"
 
 #include "lib/id_cache.h"
 
@@ -116,7 +114,7 @@ static void lsasd_smb_conf_updated(struct messaging_context *msg,
        ev_ctx = talloc_get_type_abort(private_data, struct tevent_context);
 
        change_to_root_user();
-       lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
+       lp_load_global(get_dyn_CONFIGFILE());
 
        lsasd_reopen_logs(lsasd_child_id);
        if (lsasd_child_id == 0) {
@@ -166,7 +164,7 @@ static void lsasd_sig_hup_handler(struct tevent_context *ev,
 {
 
        change_to_root_user();
-       lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
+       lp_load_global(get_dyn_CONFIGFILE());
 
        lsasd_reopen_logs(lsasd_child_id);
        pfh_daemon_config(DAEMON_NAME,
@@ -245,17 +243,16 @@ static bool lsasd_child_init(struct tevent_context *ev_ctx,
                             struct pf_worker_data *pf)
 {
        NTSTATUS status;
-       struct messaging_context *msg_ctx = server_messaging_context();
+       struct messaging_context *msg_ctx = global_messaging_context();
        bool ok;
 
        status = reinit_after_fork(msg_ctx, ev_ctx,
-                                  true);
+                                  true, "lsasd-child");
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                smb_panic("reinit_after_fork() failed");
        }
-
-       prctl_set_comment("lsasd-child");
+       initialize_password_db(true, ev_ctx);
 
        lsasd_child_id = child_id;
        lsasd_reopen_logs(child_id);
@@ -265,11 +262,6 @@ static bool lsasd_child_init(struct tevent_context *ev_ctx,
                return false;
        }
 
-       if (!serverid_register(messaging_server_id(msg_ctx),
-                              FLAG_MSG_GENERAL)) {
-               return false;
-       }
-
        messaging_register(msg_ctx, ev_ctx,
                           MSG_SMB_CONF_UPDATED, lsasd_smb_conf_updated);
        messaging_register(msg_ctx, ev_ctx,
@@ -278,21 +270,21 @@ static bool lsasd_child_init(struct tevent_context *ev_ctx,
 
        status = rpc_lsarpc_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register lsarpc rpc inteface! (%s)\n",
+               DEBUG(0, ("Failed to register lsarpc rpc interface! (%s)\n",
                          nt_errstr(status)));
                return false;
        }
 
        status = rpc_samr_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register samr rpc inteface! (%s)\n",
+               DEBUG(0, ("Failed to register samr rpc interface! (%s)\n",
                          nt_errstr(status)));
                return false;
        }
 
        status = rpc_netlogon_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register netlogon rpc inteface! (%s)\n",
+               DEBUG(0, ("Failed to register netlogon rpc interface! (%s)\n",
                          nt_errstr(status)));
                return false;
        }
@@ -446,7 +438,7 @@ static void lsasd_handle_client(struct tevent_req *req)
                  (int)(data->pf->pid)));
 
        if (tsocket_address_is_inet(srv_addr, "ip")) {
-               DEBUG(3, ("Got a tcpip client connection from %s on inteface %s\n",
+               DEBUG(3, ("Got a tcpip client connection from %s on interface %s\n",
                           tsocket_address_string(cli_addr, tmp_ctx),
                           tsocket_address_string(srv_addr, tmp_ctx)));
 
@@ -604,7 +596,7 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        uint32_t i;
        int fd = -1;
        int rc;
-       bool ok = true;
+       bool ok = false;
 
        tmp_ctx = talloc_stackframe();
        if (tmp_ctx == NULL) {
@@ -613,7 +605,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        status = dcerpc_binding_vector_new(tmp_ctx, &v_orig);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
@@ -624,7 +615,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
                                          listen_fd,
                                          listen_fd_size);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
@@ -634,7 +624,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
                if (rc == -1) {
                        DEBUG(0, ("Failed to listen on tcpip socket - %s\n",
                                  strerror(errno)));
-                       ok = false;
                        goto done;
                }
        }
@@ -642,7 +631,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        /* LSARPC */
        fd = create_named_pipe_socket("lsarpc");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -650,7 +638,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on lsarpc pipe - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -658,7 +645,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        fd = create_named_pipe_socket("lsass");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -666,7 +652,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on lsass pipe - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -674,7 +659,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        fd = create_dcerpc_ncalrpc_socket("lsarpc");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -682,7 +666,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on lsarpc ncalrpc - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -691,37 +674,32 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
        if (v == NULL) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_replace_iface(&ndr_table_lsarpc, v);
        if (!NT_STATUS_IS_OK(status)) {
-               return false;
+               goto done;
        }
 
        status = dcerpc_binding_vector_add_np_default(&ndr_table_lsarpc, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_add_unix(&ndr_table_lsarpc, v, "lsarpc");
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_lsarpc, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        /* SAMR */
        fd = create_named_pipe_socket("samr");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -729,7 +707,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on samr pipe - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -737,7 +714,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        fd = create_dcerpc_ncalrpc_socket("samr");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -745,7 +721,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on samr ncalrpc - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -754,37 +729,32 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
        if (v == NULL) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_replace_iface(&ndr_table_samr, v);
        if (!NT_STATUS_IS_OK(status)) {
-               return false;
+               goto done;
        }
 
        status = dcerpc_binding_vector_add_np_default(&ndr_table_samr, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_add_unix(&ndr_table_lsarpc, v, "samr");
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_samr, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        /* NETLOGON */
        fd = create_named_pipe_socket("netlogon");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -792,7 +762,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on samr pipe - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -800,7 +769,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        fd = create_dcerpc_ncalrpc_socket("netlogon");
        if (fd < 0) {
-               ok = false;
                goto done;
        }
 
@@ -808,7 +776,6 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        if (rc == -1) {
                DEBUG(0, ("Failed to listen on netlogon ncalrpc - %s\n",
                          strerror(errno)));
-               ok = false;
                goto done;
        }
        listen_fd[*listen_fd_size] = fd;
@@ -817,33 +784,30 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
 
        v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
        if (v == NULL) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_replace_iface(&ndr_table_netlogon, v);
        if (!NT_STATUS_IS_OK(status)) {
-               return false;
+               goto done;
        }
 
        status = dcerpc_binding_vector_add_np_default(&ndr_table_netlogon, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = dcerpc_binding_vector_add_unix(&ndr_table_lsarpc, v, "netlogon");
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
        status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_netlogon, v);
        if (!NT_STATUS_IS_OK(status)) {
-               ok = false;
                goto done;
        }
 
+       ok = true;
 done:
        if (fd != -1) {
                close(fd);
@@ -889,15 +853,12 @@ void start_lsasd(struct tevent_context *ev_ctx,
                return;
        }
 
-       status = reinit_after_fork(msg_ctx,
-                                  ev_ctx,
-                                  true);
+       status = smbd_reinit_after_fork(msg_ctx, ev_ctx, true, "lsasd-master");
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                smb_panic("reinit_after_fork() failed");
        }
-
-       prctl_set_comment("lsasd-master");
+       initialize_password_db(true, ev_ctx);
 
        /* save the parent process id so the children can use it later */
        parent_id = messaging_server_id(msg_ctx);
@@ -933,11 +894,6 @@ void start_lsasd(struct tevent_context *ev_ctx,
                exit(1);
        }
 
-       if (!serverid_register(messaging_server_id(msg_ctx),
-                              FLAG_MSG_GENERAL)) {
-               exit(1);
-       }
-
        messaging_register(msg_ctx,
                           ev_ctx,
                           MSG_SMB_CONF_UPDATED,
@@ -947,21 +903,21 @@ void start_lsasd(struct tevent_context *ev_ctx,
 
        status = rpc_lsarpc_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register lsarpc rpc inteface in lsasd! (%s)\n",
+               DEBUG(0, ("Failed to register lsarpc rpc interface in lsasd! (%s)\n",
                          nt_errstr(status)));
                exit(1);
        }
 
        status = rpc_samr_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register samr rpc inteface in lsasd! (%s)\n",
+               DEBUG(0, ("Failed to register samr rpc interface in lsasd! (%s)\n",
                          nt_errstr(status)));
                exit(1);
        }
 
        status = rpc_netlogon_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to register netlogon rpc inteface in lsasd! (%s)\n",
+               DEBUG(0, ("Failed to register netlogon rpc interface in lsasd! (%s)\n",
                          nt_errstr(status)));
                exit(1);
        }