s3-rpc_server: consolidate rpc server init routines
authorAndrew Bartlett <abartlet@samba.org>
Fri, 2 Mar 2012 05:11:55 +0000 (16:11 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 4 Mar 2012 22:33:05 +0000 (23:33 +0100)
This uses a helper function to reduce duplication.

Andrew Bartlett

source3/rpc_server/rpc_service_setup.c

index 29d7bf238a2b84c5f1806bd6218d1376e252b7c2..fc770c5ffcbd9e9636dfaeda518acd8b925bc2ff 100644 (file)
@@ -71,31 +71,34 @@ static bool rpc_setup_epmapper(struct tevent_context *ev_ctx,
        return true;
 }
 
-static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
-                            struct messaging_context *msg_ctx,
-                            const struct dcerpc_binding_vector *v)
+/* Common routine for embedded RPC servers */
+static bool rpc_setup_embedded(struct tevent_context *ev_ctx,
+                              struct messaging_context *msg_ctx,
+                              const struct dcerpc_binding_vector *v,
+                              const struct ndr_interface_table *t,
+                              const char *pipe_name)
 {
-       const struct ndr_interface_table *t = &ndr_table_winreg;
-       const char *pipe_name = "winreg";
        struct dcerpc_binding_vector *v2;
        enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
        bool ok;
 
-       status = rpc_winreg_init(NULL);
-       if (!NT_STATUS_IS_OK(status)) {
-               return false;
-       }
-
        if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
+               if (v) {
+                       v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
+                       if (v2 == NULL) {
+                               return false;
+                       }
+                       status = dcerpc_binding_vector_replace_iface(t, v2);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               return false;
+                       }
 
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
+               } else {
+                       status = dcerpc_binding_vector_new(talloc_tos(), &v2);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               return false;
+                       }
                }
 
                status = dcerpc_binding_vector_add_np_default(t, v2);
@@ -103,17 +106,19 @@ static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
                        return false;
                }
 
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
+               if (pipe_name) {
+                       ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
+                                                        msg_ctx,
+                                                        pipe_name,
+                                                        NULL);
+                       if (!ok) {
+                               return false;
+                       }
 
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
+                       status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               return false;
+                       }
                }
 
                status = rpc_ep_register(ev_ctx,
@@ -128,61 +133,36 @@ static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
        return true;
 }
 
-static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
+static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
                             struct messaging_context *msg_ctx,
                             const struct dcerpc_binding_vector *v)
 {
-       const struct ndr_interface_table *t = &ndr_table_srvsvc;
-       const char *pipe_name = "srvsvc";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
+       const struct ndr_interface_table *t = &ndr_table_winreg;
+       const char *pipe_name = "winreg";
        NTSTATUS status;
-       bool ok;
 
-       status = rpc_srvsvc_init(NULL);
+       status = rpc_winreg_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
+}
 
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
+static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
+                            struct messaging_context *msg_ctx,
+                            const struct dcerpc_binding_vector *v)
+{
+       const struct ndr_interface_table *t = &ndr_table_srvsvc;
+       const char *pipe_name = "srvsvc";
+       NTSTATUS status;
 
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
+       status = rpc_srvsvc_init(NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               return false;
        }
 
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
 }
 
 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
@@ -191,12 +171,9 @@ static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_lsarpc;
        const char *pipe_name = "lsarpc";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        enum rpc_service_mode_e lsarpc_mode = rpc_lsarpc_mode();
        enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_lsarpc_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
@@ -204,45 +181,9 @@ static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
        }
 
        if (lsarpc_mode == RPC_SERVICE_MODE_EMBEDDED &&
-           lsasd_type != RPC_DAEMON_DISABLED &&
-           epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
+           lsasd_type != RPC_DAEMON_DISABLED) {
+               return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
        }
-
        return true;
 }
 
@@ -252,12 +193,9 @@ static bool rpc_setup_samr(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_samr;
        const char *pipe_name = "samr";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        enum rpc_service_mode_e samr_mode = rpc_samr_mode();
        enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_samr_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
@@ -265,43 +203,8 @@ static bool rpc_setup_samr(struct tevent_context *ev_ctx,
        }
 
        if (samr_mode == RPC_SERVICE_MODE_EMBEDDED &&
-           lsasd_type != RPC_DAEMON_DISABLED &&
-           epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
+           lsasd_type != RPC_DAEMON_DISABLED) {
+               return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
        }
 
        return true;
@@ -313,12 +216,9 @@ static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_netlogon;
        const char *pipe_name = "netlogon";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        enum rpc_service_mode_e netlogon_mode = rpc_netlogon_mode();
        enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_netlogon_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
@@ -326,43 +226,8 @@ static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
        }
 
        if (netlogon_mode == RPC_SERVICE_MODE_EMBEDDED &&
-           lsasd_type != RPC_DAEMON_DISABLED &&
-           epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
+           lsasd_type != RPC_DAEMON_DISABLED) {
+               return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
        }
 
        return true;
@@ -374,55 +239,14 @@ static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_netdfs;
        const char *pipe_name = "netdfs";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_netdfs_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
 }
 
 #ifdef DEVELOPER
@@ -432,55 +256,14 @@ static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_rpcecho;
        const char *pipe_name = "rpcecho";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_rpcecho_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
 }
 #endif
 
@@ -490,55 +273,14 @@ static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_dssetup;
        const char *pipe_name = "dssetup";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_dssetup_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
 }
 
 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
@@ -547,55 +289,14 @@ static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_wkssvc;
        const char *pipe_name = "wkssvc";
-       struct dcerpc_binding_vector *v2;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
-       bool ok;
 
        status = rpc_wkssvc_init(NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
-               if (v2 == NULL) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_replace_iface(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
 }
 
 static bool spoolss_init_cb(void *ptr)
@@ -627,7 +328,6 @@ static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_spoolss;
        struct rpc_srv_callbacks spoolss_cb;
-       struct dcerpc_binding_vector *v;
        enum rpc_service_mode_e spoolss_mode = rpc_spoolss_mode();
        enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
@@ -652,27 +352,7 @@ static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
        }
 
        if (spoolss_type == RPC_DAEMON_EMBEDDED) {
-               enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
-
-               if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-                       status = dcerpc_binding_vector_new(talloc_tos(), &v);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               return false;
-                       }
-
-                       status = dcerpc_binding_vector_add_np_default(t, v);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               return false;
-                       }
-
-                       status = rpc_ep_register(ev_ctx,
-                                                msg_ctx,
-                                                t,
-                                                v);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               return false;
-                       }
-               }
+               return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
        }
 
        return true;
@@ -707,11 +387,8 @@ static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_svcctl;
        const char *pipe_name = "svcctl";
-       struct dcerpc_binding_vector *v;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        struct rpc_srv_callbacks svcctl_cb;
        NTSTATUS status;
-       bool ok;
 
        svcctl_cb.init         = svcctl_init_cb;
        svcctl_cb.shutdown     = svcctl_shutdown_cb;
@@ -722,48 +399,13 @@ static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               status = dcerpc_binding_vector_new(talloc_tos(), &v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
-                                                msg_ctx,
-                                                pipe_name,
-                                                NULL);
-               if (!ok) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_unix(t, v, pipe_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, pipe_name);
 }
 
 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
                             struct messaging_context *msg_ctx)
 {
        const struct ndr_interface_table *t = &ndr_table_ntsvcs;
-       struct dcerpc_binding_vector *v;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
 
        status = rpc_ntsvcs_init(NULL);
@@ -771,25 +413,7 @@ static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               status = dcerpc_binding_vector_new(talloc_tos(), &v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
+       return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
 
        return true;
 }
@@ -813,8 +437,6 @@ static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
 {
        const struct ndr_interface_table *t = &ndr_table_eventlog;
        struct rpc_srv_callbacks eventlog_cb;
-       struct dcerpc_binding_vector *v;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
 
        eventlog_cb.init         = eventlog_init_cb;
@@ -826,35 +448,13 @@ static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               status = dcerpc_binding_vector_new(talloc_tos(), &v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
 }
 
 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
                                   struct messaging_context *msg_ctx)
 {
        const struct ndr_interface_table *t = &ndr_table_initshutdown;
-       struct dcerpc_binding_vector *v;
-       enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
        NTSTATUS status;
 
        status = rpc_initshutdown_init(NULL);
@@ -862,27 +462,7 @@ static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
                return false;
        }
 
-       if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
-               status = dcerpc_binding_vector_new(talloc_tos(), &v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = dcerpc_binding_vector_add_np_default(t, v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-
-               status = rpc_ep_register(ev_ctx,
-                                        msg_ctx,
-                                        t,
-                                        v);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-       }
-
-       return true;
+       return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
 }
 
 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,