s3-librpc: Register NCALRPC pipes.
authorAndreas Schneider <asn@samba.org>
Wed, 2 Mar 2011 14:28:25 +0000 (15:28 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 8 Mar 2011 10:41:30 +0000 (11:41 +0100)
Signed-off-by: Günther Deschner <gd@samba.org>
source3/librpc/rpc/dcerpc_ep.c
source3/librpc/rpc/dcerpc_ep.h
source3/rpc_server/rpc_ep_setup.c

index f183efeb807130fcd3f2ccd738c766fef432dee7..e207b62b5486cf4ad6bd32a0e5e9e0f015a84121 100644 (file)
@@ -28,6 +28,7 @@
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,
+                                     const char *ncalrpc,
                                      struct dcerpc_binding_vector **pbvec)
 {
        struct dcerpc_binding_vector *bvec;
@@ -95,7 +96,20 @@ NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
 
                                break;
                        case NCALRPC:
-                               /* TODO */
+                               if (ncalrpc == NULL) {
+                                       talloc_free(b);
+                                       continue;
+                               }
+
+                               b->endpoint = talloc_asprintf(b,
+                                                             "%s/%s",
+                                                             lp_ncalrpc_dir(),
+                                                             ncalrpc);
+                               if (b->endpoint == NULL) {
+                                       status = NT_STATUS_NO_MEMORY;
+                                       goto done;
+                               }
+                               break;
                        default:
                                talloc_free(b);
                                continue;
index f88f468611985bc1033933544402b397fb4d8a36..99682beb9a3008629a10b9e252061d0fd2de103c 100644 (file)
@@ -28,6 +28,7 @@ struct dcerpc_binding_vector {
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,
+                                     const char *ncalrpc,
                                      struct dcerpc_binding_vector **pbvec);
 
 /**
index e080765da4f1a6e45603e981d054a7a44cc127b0..d6efb0e3c3f975efe7fad61af8a730bcecc1bf1d 100644 (file)
@@ -122,20 +122,11 @@ static NTSTATUS _rpc_ep_register(struct tevent_context *ev_ctx,
 {
        struct dcerpc_binding_vector *v = NULL;
        NTSTATUS status;
-       const char *rpcsrv_type;
-
-       /* start endpoint mapper only if enabled */
-       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
-                                          "rpc_server",
-                                          "epmapper",
-                                          "none");
-       if (StrCaseCmp(rpcsrv_type, "none") == 0) {
-               return NT_STATUS_OK;
-       }
 
        status = dcerpc_binding_vector_create(talloc_tos(),
                                              iface,
                                              port,
+                                             name,
                                              &v);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -156,20 +147,11 @@ static NTSTATUS _rpc_ep_unregister(const struct ndr_interface_table *iface)
 {
        struct dcerpc_binding_vector *v = NULL;
        NTSTATUS status;
-       const char *rpcsrv_type;
-
-       /* start endpoint mapper only if enabled */
-       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
-                                          "rpc_server",
-                                          "epmapper",
-                                          "none");
-       if (StrCaseCmp(rpcsrv_type, "none") == 0) {
-               return NT_STATUS_OK;
-       }
 
        status = dcerpc_binding_vector_create(talloc_tos(),
                                              iface,
                                              0,
+                                             NULL,
                                              &v);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -190,12 +172,6 @@ static bool epmapper_init_cb(void *ptr)
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
        uint16_t port;
-       const char *rpcsrv_type;
-
-       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
-                                          "rpc_server",
-                                          "epmapper",
-                                          "none");
 
        port = _open_sockets(ep_ctx->ev_ctx,
                             ep_ctx->msg_ctx,
@@ -221,10 +197,19 @@ static bool winreg_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -233,25 +218,39 @@ static bool winreg_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                               ep_ctx->msg_ctx,
+                                               &ndr_table_winreg,
+                                               pipe_name,
+                                               port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_winreg,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool winreg_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_winreg));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_winreg);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool srvsvc_init_cb(void *ptr)
@@ -267,10 +266,20 @@ static bool srvsvc_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -279,25 +288,39 @@ static bool srvsvc_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_srvsvc,
+                                         pipe_name,
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_srvsvc,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool srvsvc_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_srvsvc));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status =_rpc_ep_unregister(&ndr_table_srvsvc);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool lsarpc_init_cb(void *ptr)
@@ -313,10 +336,20 @@ static bool lsarpc_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -325,25 +358,39 @@ static bool lsarpc_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_lsarpc,
+                                         pipe_name,
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_lsarpc,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool lsarpc_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_lsarpc));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_lsarpc);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool samr_init_cb(void *ptr)
@@ -359,10 +406,20 @@ static bool samr_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -371,25 +428,39 @@ static bool samr_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_samr,
+                                         pipe_name,
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_samr,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool samr_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_samr));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_samr);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool netlogon_init_cb(void *ptr)
@@ -405,10 +476,20 @@ static bool netlogon_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -417,34 +498,53 @@ static bool netlogon_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_netlogon,
+                                         pipe_name,
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_netlogon,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool netlogon_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_netlogon));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_netlogon);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool spoolss_init_cb(void *ptr)
 {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
-       NTSTATUS status;
+       const char *rpcsrv_type;
        bool ok;
 
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
        /*
         * Migrate the printers first.
         */
@@ -453,33 +553,59 @@ static bool spoolss_init_cb(void *ptr)
                return false;
        }
 
-       status =_rpc_ep_register(ep_ctx->ev_ctx,
-                                ep_ctx->msg_ctx,
-                                &ndr_table_spoolss,
-                                "spoolss",
-                                0);
-       if (!NT_STATUS_IS_OK(status)) {
-               return false;
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status =_rpc_ep_register(ep_ctx->ev_ctx,
+                                        ep_ctx->msg_ctx,
+                                        &ndr_table_spoolss,
+                                        "spoolss",
+                                        0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
        }
 
        return true;
 }
 
-
-
 static bool spoolss_shutdown_cb(void *ptr)
 {
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
        srv_spoolss_cleanup();
 
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_spoolss));
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_spoolss);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool svcctl_init_cb(void *ptr)
 {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
+       const char *rpcsrv_type;
        bool ok;
 
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
        ok = svcctl_init_winreg(ep_ctx->msg_ctx);
        if (!ok) {
                return false;
@@ -488,101 +614,259 @@ static bool svcctl_init_cb(void *ptr)
        /* initialize the control hooks */
        init_service_op_table();
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_svcctl,
-                                               "svcctl",
-                                               0));
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_svcctl,
+                                         "svcctl",
+                                         0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool svcctl_shutdown_cb(void *ptr)
 {
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
        shutdown_service_op_table();
 
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_svcctl));
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_svcctl);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool ntsvcs_init_cb(void *ptr)
 {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
+       const char *rpcsrv_type;
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_ntsvcs,
-                                               "ntsvcs",
-                                               0));
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_ntsvcs,
+                                         "ntsvcs",
+                                         0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool ntsvcs_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_ntsvcs));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_ntsvcs);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool eventlog_init_cb(void *ptr)
 {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
-       NTSTATUS status;
+       const char *rpcsrv_type;
+       bool ok;
 
-       status =_rpc_ep_register(ep_ctx->ev_ctx,
-                                ep_ctx->msg_ctx,
-                                &ndr_table_eventlog,
-                                "eventlog",
-                                0);
-       if (!NT_STATUS_IS_OK(status)) {
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       ok = eventlog_init_winreg(ep_ctx->msg_ctx);
+       if (!ok) {
                return false;
        }
 
-       return eventlog_init_winreg(ep_ctx->msg_ctx);
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status =_rpc_ep_register(ep_ctx->ev_ctx,
+                                        ep_ctx->msg_ctx,
+                                        &ndr_table_eventlog,
+                                        "eventlog",
+                                        0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool eventlog_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_eventlog));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_eventlog);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool initshutdown_init_cb(void *ptr)
 {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
+       const char *rpcsrv_type;
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_initshutdown,
-                                               "initshutdown",
-                                               0));
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_initshutdown,
+                                         "initshutdown",
+                                         0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool initshutdown_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_initshutdown));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_initshutdown);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 #ifdef DEVELOPER
 static bool rpcecho_init_cb(void *ptr) {
        struct dcesrv_ep_context *ep_ctx =
                talloc_get_type_abort(ptr, struct dcesrv_ep_context);
+       const char *rpcsrv_type;
        uint16_t port;
 
-       port = _open_sockets(ep_ctx->ev_ctx,
-                            ep_ctx->msg_ctx,
-                            ndr_table_rpcecho.syntax_id,
-                            0);
-       if (port == 0) {
-               return false;
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               port = _open_sockets(ep_ctx->ev_ctx,
+                                    ep_ctx->msg_ctx,
+                                    ndr_table_rpcecho.syntax_id,
+                                    0);
+               if (port == 0) {
+                       return false;
+               }
+
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_rpcecho,
+                                         "rpcecho",
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_rpcecho,
-                                               "rpcecho",
-                                               port));
+       return true;
 }
 
 static bool rpcecho_shutdown_cb(void *ptr)
 {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_rpcecho));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_rpcecho);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 #endif
 
@@ -601,8 +885,17 @@ static bool netdfs_init_cb(void *ptr)
                                           "none");
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -611,24 +904,38 @@ static bool netdfs_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_netdfs,
+                                         pipe_name,
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_netdfs,
-                                               pipe_name,
-                                               port));
+       return true;
 }
 
 static bool netdfs_shutdown_cb(void *ptr) {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_netdfs));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_netdfs);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool dssetup_init_cb(void *ptr)
@@ -644,10 +951,20 @@ static bool dssetup_init_cb(void *ptr)
                                           "rpc_server",
                                           "epmapper",
                                           "none");
+
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -656,24 +973,38 @@ static bool dssetup_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_dssetup,
+                                         "dssetup",
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_dssetup,
-                                               "dssetup",
-                                               port));
+       return true;
 }
 
 static bool dssetup_shutdown_cb(void *ptr) {
-       return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_dssetup));
+       const char *rpcsrv_type;
+
+       rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                          "rpc_server",
+                                          "epmapper",
+                                          "none");
+
+       if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
+           StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
+
+               status = _rpc_ep_unregister(&ndr_table_dssetup);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 static bool wkssvc_init_cb(void *ptr)
@@ -691,8 +1022,17 @@ static bool wkssvc_init_cb(void *ptr)
                                           "none");
        if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
            StrCaseCmp(rpcsrv_type, "daemon") == 0) {
+               NTSTATUS status;
                bool ok;
 
+               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
+                                                ep_ctx->msg_ctx,
+                                                abstract_syntax,
+                                                pipe_name);
+               if (!ok) {
+                       return false;
+               }
+
                port = _open_sockets(ep_ctx->ev_ctx,
                                     ep_ctx->msg_ctx,
                                     abstract_syntax,
@@ -701,20 +1041,17 @@ static bool wkssvc_init_cb(void *ptr)
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
-                                                ep_ctx->msg_ctx,
-                                                abstract_syntax,
-                                                pipe_name);
-               if (!ok) {
+               status = _rpc_ep_register(ep_ctx->ev_ctx,
+                                         ep_ctx->msg_ctx,
+                                         &ndr_table_wkssvc,
+                                         "wkssvc",
+                                         port);
+               if (!NT_STATUS_IS_OK(status)) {
                        return false;
                }
        }
 
-       return NT_STATUS_IS_OK(_rpc_ep_register(ep_ctx->ev_ctx,
-                                               ep_ctx->msg_ctx,
-                                               &ndr_table_wkssvc,
-                                               "wkssvc",
-                                               port));
+       return true;
 }
 
 static bool wkssvc_shutdown_cb(void *ptr) {