s3-rpc_server: Add make_internal_rpc_pipe_socketpair().
authorAndreas Schneider <asn@samba.org>
Wed, 25 Sep 2013 09:35:41 +0000 (11:35 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Oct 2013 15:17:03 +0000 (16:17 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/rpc_server/rpc_ncacn_np.c
source3/rpc_server/rpc_ncacn_np.h
source3/rpc_server/wscript_build
source3/wscript_build

index 0a5ab6abb2da6a4824d31cb57a274580c4e3dccc..92a724b982fb77d04446555787722a7ceef42368 100644 (file)
@@ -37,6 +37,7 @@
 #include "rpc_contexts.h"
 #include "rpc_server/rpc_config.h"
 #include "librpc/ndr/ndr_table.h"
+#include "rpc_server/rpc_server.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -68,6 +69,114 @@ fail:
        return NULL;
 }
 
+NTSTATUS make_internal_rpc_pipe_socketpair(TALLOC_CTX *mem_ctx,
+                                          struct tevent_context *ev_ctx,
+                                          struct messaging_context *msg_ctx,
+                                          const char *pipe_name,
+                                          const struct ndr_syntax_id *syntax,
+                                          const struct tsocket_address *remote_address,
+                                          const struct auth_session_info *session_info,
+                                          struct npa_state **pnpa)
+{
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       struct named_pipe_client *npc;
+       struct tevent_req *subreq;
+       struct npa_state *npa;
+       NTSTATUS status;
+       int error;
+       int rc;
+
+       DEBUG(4, ("Create of internal pipe %s requested\n", pipe_name));
+
+       npa = npa_state_init(tmp_ctx);
+       if (npa == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+
+       npa->file_type = FILE_TYPE_MESSAGE_MODE_PIPE;
+       npa->device_state = 0xff | 0x0400 | 0x0100;
+       npa->allocation_size = 4096;
+
+       npc = named_pipe_client_init(npa,
+                                    ev_ctx,
+                                    msg_ctx,
+                                    pipe_name,
+                                    NULL, /* term_fn */
+                                    npa->file_type,
+                                    npa->device_state,
+                                    npa->allocation_size,
+                                    NULL); /* private_data */
+       if (npc == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+       npa->private_data = (void*) npc;
+
+       rc = tstream_npa_socketpair(npa->file_type,
+                                   npa,
+                                   &npa->stream,
+                                   npc,
+                                   &npc->tstream);
+       if (rc == -1) {
+               status = map_nt_error_from_unix(errno);
+               goto out;
+       }
+
+       npc->client = tsocket_address_copy(remote_address, npc);
+       if (npc->client == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+
+       npc->client_name = tsocket_address_inet_addr_string(npc->client, npc);
+       if (npc->client_name == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+
+       npc->session_info = copy_session_info(npc, session_info);
+       if (npc->session_info == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+
+       rc = make_server_pipes_struct(npc,
+                                     npc->msg_ctx,
+                                     npc->pipe_name,
+                                     NCACN_NP,
+                                     false,
+                                     npc->server,
+                                     npc->client,
+                                     npc->session_info,
+                                     &npc->p,
+                                     &error);
+       if (rc == -1) {
+               status = map_nt_error_from_unix(error);
+               goto out;
+       }
+
+       npc->write_queue = tevent_queue_create(npc, "npa_server_write_queue");
+       if (npc->write_queue == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
+
+       subreq = dcerpc_read_ncacn_packet_send(npc, npc->ev, npc->tstream);
+       if (subreq == NULL) {
+               DEBUG(2, ("Failed to start receving packets\n"));
+               status = NT_STATUS_PIPE_BROKEN;
+               goto out;
+       }
+       tevent_req_set_callback(subreq, named_pipe_packet_process, npc);
+
+       *pnpa = talloc_steal(mem_ctx, npa);
+       status = NT_STATUS_OK;
+out:
+       talloc_free(tmp_ctx);
+       return status;
+}
+
 NTSTATUS make_internal_rpc_pipe(TALLOC_CTX *mem_ctx,
                                struct messaging_context *msg_ctx,
                                const char *pipe_name,
index 92e3d6c17b07d84cf27e73e5848028ffb5b1c54c..07a2c15a63eb2918fcf52d443730fe5251a74ff3 100644 (file)
@@ -52,6 +52,15 @@ NTSTATUS make_internal_rpc_pipe(TALLOC_CTX *mem_ctx,
                                const struct auth_session_info *session_info,
                                struct npa_state **pnpa);
 
+NTSTATUS make_internal_rpc_pipe_socketpair(TALLOC_CTX *mem_ctx,
+                                          struct tevent_context *ev_ctx,
+                                          struct messaging_context *msg_ctx,
+                                          const char *pipe_name,
+                                          const struct ndr_syntax_id *syntax,
+                                          const struct tsocket_address *remote_address,
+                                          const struct auth_session_info *session_info,
+                                          struct npa_state **pnpa);
+
 struct np_proxy_state {
        uint16_t file_type;
        uint16_t device_state;
index c30852a75a0b1413c472015927a56ffb5fa87a37..061bdd6b327b878c18343dd9decc23e73d838888 100755 (executable)
@@ -73,8 +73,7 @@ bld.SAMBA3_SUBSYSTEM('RPC_NETDFS',
 
 bld.SAMBA3_SUBSYSTEM('RPC_NETLOGON',
                      source='''netlogon/srv_netlog_nt.c
-                     ../../librpc/gen_ndr/srv_netlogon.c''',
-                     deps='RPC_NCACN_NP')
+                     ../../librpc/gen_ndr/srv_netlogon.c''')
 
 bld.SAMBA3_SUBSYSTEM('RPC_NTSVCS',
                     source='''ntsvcs/srv_ntsvcs_nt.c
@@ -97,7 +96,7 @@ bld.SAMBA3_SUBSYSTEM('RPC_SPOOLSS',
                     source='''spoolss/srv_spoolss_nt.c
                     ../../librpc/gen_ndr/srv_spoolss.c
                     spoolss/srv_spoolss_util.c''',
-                    deps='PRINTING PRINTBACKEND LIBCLI_WINREG_INTERNAL RPC_NCACN_NP')
+                    deps='PRINTING PRINTBACKEND LIBCLI_WINREG_INTERNAL')
 
 bld.SAMBA3_SUBSYSTEM('RPC_SRVSVC',
                     source='''srvsvc/srv_srvsvc_nt.c
index 9f5be8ee36a7f2fa288f2edcf90be6a9e9e852f5..d3eed3c164714961b87d694e1e0a940b3d87cc02 100755 (executable)
@@ -778,7 +778,7 @@ bld.SAMBA3_SUBSYSTEM('LIBCLI_WINREG',
 
 bld.SAMBA3_SUBSYSTEM('LIBCLI_WINREG_INTERNAL',
                     source='rpc_client/cli_winreg_int.c',
-                    deps='LIBCLI_WINREG RPC_NCACN_NP')
+                    deps='LIBCLI_WINREG RPC_SERVER')
 
 bld.SAMBA3_SUBSYSTEM('RPC_CLIENT_SCHANNEL',
                     source='rpc_client/cli_pipe_schannel.c',
@@ -935,8 +935,7 @@ bld.SAMBA3_BINARY('winbindd/winbindd',
                  SRV_NDR_WBINT
                  RPC_SAMR
                  RPC_LSARPC
-                 RPC_NCACN_NP
-                 RPC_PIPE_REGISTER
+                 RPC_SERVER
                  WB_REQTRANS
                  TDB_VALIDATE
                  ''',