2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1998,
5 * Largely re-written : 2005
6 * Copyright (C) Jeremy Allison 1998 - 2005
7 * Copyright (C) Simo Sorce 2010
8 * Copyright (C) Andrew Bartlett 2011
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "rpc_client/cli_pipe.h"
26 #include "rpc_server/srv_pipe_internal.h"
28 #include "../libcli/named_pipe_auth/npa_tstream.h"
29 #include "rpc_server/rpc_ncacn_np.h"
30 #include "librpc/gen_ndr/netlogon.h"
31 #include "librpc/gen_ndr/auth.h"
32 #include "../auth/auth_sam_reply.h"
34 #include "rpc_server/rpc_pipes.h"
35 #include "../lib/tsocket/tsocket.h"
36 #include "../lib/util/tevent_ntstatus.h"
37 #include "rpc_contexts.h"
38 #include "rpc_server/rpc_config.h"
39 #include "librpc/ndr/ndr_table.h"
40 #include "rpc_server/rpc_server.h"
43 #define DBGC_CLASS DBGC_RPC_SRV
45 static struct npa_state *npa_state_init(TALLOC_CTX *mem_ctx)
47 struct npa_state *npa;
49 npa = talloc_zero(mem_ctx, struct npa_state);
54 npa->read_queue = tevent_queue_create(npa, "npa_cli_read");
55 if (npa->read_queue == NULL) {
56 DEBUG(0, ("tevent_queue_create failed\n"));
60 npa->write_queue = tevent_queue_create(npa, "npa_cli_write");
61 if (npa->write_queue == NULL) {
62 DEBUG(0, ("tevent_queue_create failed\n"));
72 NTSTATUS make_internal_rpc_pipe_socketpair(TALLOC_CTX *mem_ctx,
73 struct tevent_context *ev_ctx,
74 struct messaging_context *msg_ctx,
75 const char *pipe_name,
76 const struct ndr_syntax_id *syntax,
77 const struct tsocket_address *remote_address,
78 const struct auth_session_info *session_info,
79 struct npa_state **pnpa)
81 TALLOC_CTX *tmp_ctx = talloc_stackframe();
82 struct named_pipe_client *npc;
83 struct tevent_req *subreq;
84 struct npa_state *npa;
89 DEBUG(4, ("Create of internal pipe %s requested\n", pipe_name));
91 npa = npa_state_init(tmp_ctx);
93 status = NT_STATUS_NO_MEMORY;
97 npa->file_type = FILE_TYPE_MESSAGE_MODE_PIPE;
98 npa->device_state = 0xff | 0x0400 | 0x0100;
99 npa->allocation_size = 4096;
101 npc = named_pipe_client_init(npa,
108 npa->allocation_size,
109 NULL); /* private_data */
111 status = NT_STATUS_NO_MEMORY;
114 npa->private_data = (void*) npc;
116 rc = tstream_npa_socketpair(npa->file_type,
122 status = map_nt_error_from_unix(errno);
126 npc->remote_client_addr = tsocket_address_copy(remote_address, npc);
127 if (npc->remote_client_addr == NULL) {
128 status = NT_STATUS_NO_MEMORY;
132 npc->remote_client_name = tsocket_address_inet_addr_string(npc->remote_client_addr,
134 if (npc->remote_client_name == NULL) {
135 status = NT_STATUS_NO_MEMORY;
139 npc->session_info = copy_session_info(npc, session_info);
140 if (npc->session_info == NULL) {
141 status = NT_STATUS_NO_MEMORY;
145 rc = make_server_pipes_struct(npc,
149 npc->local_server_addr,
150 npc->remote_client_addr,
155 status = map_nt_error_from_unix(error);
159 npc->write_queue = tevent_queue_create(npc, "npa_server_write_queue");
160 if (npc->write_queue == NULL) {
161 status = NT_STATUS_NO_MEMORY;
165 subreq = dcerpc_read_ncacn_packet_send(npc, npc->ev, npc->tstream);
166 if (subreq == NULL) {
167 DEBUG(2, ("Failed to start receving packets\n"));
168 status = NT_STATUS_PIPE_BROKEN;
171 tevent_req_set_callback(subreq, named_pipe_packet_process, npc);
173 *pnpa = talloc_steal(mem_ctx, npa);
174 status = NT_STATUS_OK;
176 talloc_free(tmp_ctx);
180 /****************************************************************************
181 Make an internal namedpipes structure
182 ****************************************************************************/
184 struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
185 const struct ndr_syntax_id *syntax,
186 const struct tsocket_address *remote_address,
187 const struct tsocket_address *local_address,
188 const struct auth_session_info *session_info,
189 struct messaging_context *msg_ctx)
191 struct pipes_struct *p;
192 struct pipe_rpc_fns *context_fns;
193 const char *pipe_name;
195 const struct ndr_interface_table *table;
197 table = ndr_table_by_uuid(&syntax->uuid);
199 DEBUG(0,("unknown interface\n"));
203 pipe_name = dcerpc_default_transport_endpoint(mem_ctx, NCACN_NP, table);
205 DEBUG(4,("Create pipe requested %s\n", pipe_name));
207 ret = make_base_pipes_struct(mem_ctx, msg_ctx, pipe_name,
208 NCALRPC, RPC_LITTLE_ENDIAN,
209 remote_address, local_address, &p);
211 DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
215 if (!init_pipe_handles(p, syntax)) {
216 DEBUG(0,("open_rpc_pipe_p: init_pipe_handles failed.\n"));
221 p->session_info = copy_session_info(p, session_info);
222 if (p->session_info == NULL) {
223 DEBUG(0, ("open_rpc_pipe_p: copy_serverinfo failed\n"));
224 close_policy_by_pipe(p);
229 context_fns = talloc_zero(p, struct pipe_rpc_fns);
230 if (context_fns == NULL) {
231 DEBUG(0,("talloc() failed!\n"));
236 context_fns->next = context_fns->prev = NULL;
237 context_fns->n_cmds = rpc_srv_get_pipe_num_cmds(syntax);
238 context_fns->cmds = rpc_srv_get_pipe_cmds(syntax);
239 context_fns->context_id = 0;
240 context_fns->syntax = *syntax;
242 /* add to the list of open contexts */
243 DLIST_ADD(p->contexts, context_fns);
245 DEBUG(4,("Created internal pipe %s\n", pipe_name));
250 static NTSTATUS rpcint_dispatch(struct pipes_struct *p,
253 const DATA_BLOB *in_data,
256 struct pipe_rpc_fns *fns = find_pipe_fns_by_context(p->contexts, 0);
257 uint32_t num_cmds = fns->n_cmds;
258 const struct api_struct *cmds = fns->cmds;
265 for (i = 0; i < num_cmds; i++) {
266 if (cmds[i].opnum == opnum && cmds[i].fn != NULL) {
272 return NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE;
275 p->in_data.data = *in_data;
276 p->out_data.rdata = data_blob_null;
279 p->in_data.data = data_blob_null;
281 data_blob_free(&p->out_data.rdata);
282 talloc_free_children(p->mem_ctx);
283 return NT_STATUS_RPC_CALL_FAILED;
286 if (p->fault_state) {
289 status = NT_STATUS(p->fault_state);
291 data_blob_free(&p->out_data.rdata);
292 talloc_free_children(p->mem_ctx);
296 *out_data = p->out_data.rdata;
297 talloc_steal(mem_ctx, out_data->data);
298 p->out_data.rdata = data_blob_null;
300 talloc_free_children(p->mem_ctx);
304 struct rpcint_bh_state {
305 struct pipes_struct *p;
308 static bool rpcint_bh_is_connected(struct dcerpc_binding_handle *h)
310 struct rpcint_bh_state *hs = dcerpc_binding_handle_data(h,
311 struct rpcint_bh_state);
320 static uint32_t rpcint_bh_set_timeout(struct dcerpc_binding_handle *h,
323 /* TODO: implement timeouts */
327 struct rpcint_bh_raw_call_state {
333 static struct tevent_req *rpcint_bh_raw_call_send(TALLOC_CTX *mem_ctx,
334 struct tevent_context *ev,
335 struct dcerpc_binding_handle *h,
336 const struct GUID *object,
339 const uint8_t *in_data,
342 struct rpcint_bh_state *hs =
343 dcerpc_binding_handle_data(h,
344 struct rpcint_bh_state);
345 struct tevent_req *req;
346 struct rpcint_bh_raw_call_state *state;
350 req = tevent_req_create(mem_ctx, &state,
351 struct rpcint_bh_raw_call_state);
355 state->in_data.data = discard_const_p(uint8_t, in_data);
356 state->in_data.length = in_length;
358 ok = rpcint_bh_is_connected(h);
360 tevent_req_nterror(req, NT_STATUS_CONNECTION_DISCONNECTED);
361 return tevent_req_post(req, ev);
364 /* TODO: allow async */
365 status = rpcint_dispatch(hs->p, state, opnum,
368 if (!NT_STATUS_IS_OK(status)) {
369 tevent_req_nterror(req, status);
370 return tevent_req_post(req, ev);
373 tevent_req_done(req);
374 return tevent_req_post(req, ev);
377 static NTSTATUS rpcint_bh_raw_call_recv(struct tevent_req *req,
383 struct rpcint_bh_raw_call_state *state =
385 struct rpcint_bh_raw_call_state);
388 if (tevent_req_is_nterror(req, &status)) {
389 tevent_req_received(req);
393 *out_data = talloc_move(mem_ctx, &state->out_data.data);
394 *out_length = state->out_data.length;
396 tevent_req_received(req);
400 struct rpcint_bh_disconnect_state {
404 static struct tevent_req *rpcint_bh_disconnect_send(TALLOC_CTX *mem_ctx,
405 struct tevent_context *ev,
406 struct dcerpc_binding_handle *h)
408 struct rpcint_bh_state *hs = dcerpc_binding_handle_data(h,
409 struct rpcint_bh_state);
410 struct tevent_req *req;
411 struct rpcint_bh_disconnect_state *state;
414 req = tevent_req_create(mem_ctx, &state,
415 struct rpcint_bh_disconnect_state);
420 ok = rpcint_bh_is_connected(h);
422 tevent_req_nterror(req, NT_STATUS_CONNECTION_DISCONNECTED);
423 return tevent_req_post(req, ev);
427 * TODO: do a real async disconnect ...
429 * For now the caller needs to free pipes_struct
433 tevent_req_done(req);
434 return tevent_req_post(req, ev);
437 static NTSTATUS rpcint_bh_disconnect_recv(struct tevent_req *req)
441 if (tevent_req_is_nterror(req, &status)) {
442 tevent_req_received(req);
446 tevent_req_received(req);
450 static bool rpcint_bh_ref_alloc(struct dcerpc_binding_handle *h)
455 static void rpcint_bh_do_ndr_print(struct dcerpc_binding_handle *h,
457 const void *_struct_ptr,
458 const struct ndr_interface_call *call)
460 void *struct_ptr = discard_const(_struct_ptr);
462 if (DEBUGLEVEL < 11) {
466 if (ndr_flags & NDR_IN) {
467 ndr_print_function_debug(call->ndr_print,
472 if (ndr_flags & NDR_OUT) {
473 ndr_print_function_debug(call->ndr_print,
480 static const struct dcerpc_binding_handle_ops rpcint_bh_ops = {
482 .is_connected = rpcint_bh_is_connected,
483 .set_timeout = rpcint_bh_set_timeout,
484 .raw_call_send = rpcint_bh_raw_call_send,
485 .raw_call_recv = rpcint_bh_raw_call_recv,
486 .disconnect_send = rpcint_bh_disconnect_send,
487 .disconnect_recv = rpcint_bh_disconnect_recv,
489 .ref_alloc = rpcint_bh_ref_alloc,
490 .do_ndr_print = rpcint_bh_do_ndr_print,
493 static NTSTATUS rpcint_binding_handle_ex(TALLOC_CTX *mem_ctx,
494 const struct ndr_syntax_id *abstract_syntax,
495 const struct ndr_interface_table *ndr_table,
496 const struct tsocket_address *remote_address,
497 const struct tsocket_address *local_address,
498 const struct auth_session_info *session_info,
499 struct messaging_context *msg_ctx,
500 struct dcerpc_binding_handle **binding_handle)
502 struct dcerpc_binding_handle *h;
503 struct rpcint_bh_state *hs;
506 abstract_syntax = &ndr_table->syntax_id;
509 h = dcerpc_binding_handle_create(mem_ctx,
514 struct rpcint_bh_state,
517 return NT_STATUS_NO_MEMORY;
519 hs->p = make_internal_rpc_pipe_p(hs,
527 return NT_STATUS_NO_MEMORY;
534 * @brief Create a new DCERPC Binding Handle which uses a local dispatch function.
536 * @param[in] mem_ctx The memory context to use.
538 * @param[in] ndr_table Normally the ndr_table_<name>.
540 * @param[in] remote_address The info about the connected client.
542 * @param[in] serversupplied_info The server supplied authentication function.
544 * @param[in] msg_ctx The messaging context that can be used by the server
546 * @param[out] binding_handle A pointer to store the connected
547 * dcerpc_binding_handle
549 * @return NT_STATUS_OK on success, a corresponding NT status if an
553 * struct dcerpc_binding_handle *winreg_binding;
556 * status = rpcint_binding_handle(tmp_ctx,
564 NTSTATUS rpcint_binding_handle(TALLOC_CTX *mem_ctx,
565 const struct ndr_interface_table *ndr_table,
566 const struct tsocket_address *remote_address,
567 const struct tsocket_address *local_address,
568 const struct auth_session_info *session_info,
569 struct messaging_context *msg_ctx,
570 struct dcerpc_binding_handle **binding_handle)
572 return rpcint_binding_handle_ex(mem_ctx, NULL, ndr_table, remote_address,
573 local_address, session_info,
574 msg_ctx, binding_handle);
580 * @brief Create a new RPC client context which uses a local transport.
582 * This creates a local transport. It is a shortcut to directly call the server
583 * functions and avoid marshalling.
584 * NOTE: this function should be used only by rpc_pipe_open_interface()
586 * @param[in] mem_ctx The memory context to use.
588 * @param[in] ndr_table the ndr_table_<name> structure.
590 * @param[in] serversupplied_info The server supplied authentication function.
592 * @param[in] remote_address The client address information.
594 * @param[in] msg_ctx The messaging context to use.
596 * @param[out] presult A pointer to store the connected rpc client pipe.
598 * @return NT_STATUS_OK on success, a corresponding NT status if an
601 NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx,
602 const struct ndr_interface_table *ndr_table,
603 const struct auth_session_info *session_info,
604 const struct tsocket_address *remote_address,
605 const struct tsocket_address *local_address,
606 struct messaging_context *msg_ctx,
607 struct rpc_pipe_client **presult)
609 struct rpc_pipe_client *result;
612 result = talloc_zero(mem_ctx, struct rpc_pipe_client);
613 if (result == NULL) {
614 return NT_STATUS_NO_MEMORY;
617 result->abstract_syntax = ndr_table->syntax_id;
618 result->transfer_syntax = ndr_transfer_syntax_ndr;
620 if (remote_address == NULL) {
621 struct tsocket_address *local;
624 rc = tsocket_address_inet_from_strings(mem_ctx,
631 return NT_STATUS_NO_MEMORY;
634 remote_address = local;
637 result->max_xmit_frag = -1;
639 status = rpcint_binding_handle(result,
645 &result->binding_handle);
646 if (!NT_STATUS_IS_OK(status)) {
655 /****************************************************************************
656 * External pipes functions
657 ***************************************************************************/
659 NTSTATUS make_external_rpc_pipe(TALLOC_CTX *mem_ctx,
660 const char *pipe_name,
661 const struct tsocket_address *local_address,
662 const struct tsocket_address *remote_address,
663 const struct auth_session_info *session_info,
664 struct npa_state **pnpa)
666 TALLOC_CTX *tmp_ctx = talloc_stackframe();
667 struct auth_session_info_transport *session_info_t;
668 struct tevent_context *ev_ctx;
669 struct tevent_req *subreq;
670 const char *socket_np_dir;
671 const char *socket_dir;
672 struct npa_state *npa;
678 npa = npa_state_init(tmp_ctx);
680 status = NT_STATUS_NO_MEMORY;
684 socket_dir = lp_parm_const_string(GLOBAL_SECTION_SNUM,
688 if (socket_dir == NULL) {
689 DEBUG(0, ("external_rpc_pipe: socket_dir not set\n"));
690 status = NT_STATUS_PIPE_NOT_AVAILABLE;
694 socket_np_dir = talloc_asprintf(tmp_ctx, "%s/np", socket_dir);
695 if (socket_np_dir == NULL) {
696 DEBUG(0, ("talloc_asprintf failed\n"));
697 status = NT_STATUS_NO_MEMORY;
701 session_info_t = talloc_zero(tmp_ctx,
702 struct auth_session_info_transport);
703 if (session_info_t == NULL) {
704 DEBUG(0, ("talloc failed\n"));
705 status = NT_STATUS_NO_MEMORY;
709 session_info_t->session_info = copy_session_info(session_info_t,
711 if (session_info_t->session_info == NULL) {
712 DEBUG(0, ("copy_session_info failed\n"));
713 status = NT_STATUS_NO_MEMORY;
717 ev_ctx = samba_tevent_context_init(tmp_ctx);
718 if (ev_ctx == NULL) {
719 DEBUG(0, ("samba_tevent_context_init failed\n"));
720 status = NT_STATUS_NO_MEMORY;
725 subreq = tstream_npa_connect_send(tmp_ctx,
729 remote_address, /* client_addr */
730 NULL, /* client_name */
731 local_address, /* server_addr */
732 NULL, /* server_name */
734 if (subreq == NULL) {
736 DEBUG(0, ("tstream_npa_connect_send to %s for pipe %s and "
737 "user %s\\%s failed\n",
738 socket_np_dir, pipe_name, session_info_t->session_info->info->domain_name,
739 session_info_t->session_info->info->account_name));
740 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
743 ok = tevent_req_poll(subreq, ev_ctx);
746 DEBUG(0, ("tevent_req_poll to %s for pipe %s and user %s\\%s "
747 "failed for tstream_npa_connect: %s\n",
750 session_info_t->session_info->info->domain_name,
751 session_info_t->session_info->info->account_name,
753 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
757 rc = tstream_npa_connect_recv(subreq,
763 &npa->allocation_size);
768 if (errno == ENOENT) {
772 DEBUG(l, ("tstream_npa_connect_recv to %s for pipe %s and "
773 "user %s\\%s failed: %s\n",
776 session_info_t->session_info->info->domain_name,
777 session_info_t->session_info->info->account_name,
778 strerror(sys_errno)));
779 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
783 *pnpa = talloc_steal(mem_ctx, npa);
784 status = NT_STATUS_OK;
786 talloc_free(tmp_ctx);
791 struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
792 const char *pipe_name,
793 const struct tsocket_address *local_address,
794 const struct tsocket_address *remote_address,
795 const struct auth_session_info *session_info)
797 struct np_proxy_state *result;
799 const char *socket_dir;
800 struct tevent_context *ev;
801 struct tevent_req *subreq;
802 struct auth_session_info_transport *session_info_t;
807 result = talloc(mem_ctx, struct np_proxy_state);
808 if (result == NULL) {
809 DEBUG(0, ("talloc failed\n"));
813 result->read_queue = tevent_queue_create(result, "np_read");
814 if (result->read_queue == NULL) {
815 DEBUG(0, ("tevent_queue_create failed\n"));
819 result->write_queue = tevent_queue_create(result, "np_write");
820 if (result->write_queue == NULL) {
821 DEBUG(0, ("tevent_queue_create failed\n"));
825 ev = samba_tevent_context_init(talloc_tos());
827 DEBUG(0, ("samba_tevent_context_init failed\n"));
831 socket_dir = lp_parm_const_string(
832 GLOBAL_SECTION_SNUM, "external_rpc_pipe", "socket_dir",
834 if (socket_dir == NULL) {
835 DEBUG(0, ("external_rpc_pipe:socket_dir not set\n"));
838 socket_np_dir = talloc_asprintf(talloc_tos(), "%s/np", socket_dir);
839 if (socket_np_dir == NULL) {
840 DEBUG(0, ("talloc_asprintf failed\n"));
844 session_info_t = talloc_zero(talloc_tos(), struct auth_session_info_transport);
845 if (session_info_t == NULL) {
846 DEBUG(0, ("talloc failed\n"));
850 session_info_t->session_info = copy_session_info(session_info_t,
852 if (session_info_t->session_info == NULL) {
853 DEBUG(0, ("copy_session_info failed\n"));
858 subreq = tstream_npa_connect_send(talloc_tos(), ev,
861 remote_address, /* client_addr */
862 NULL, /* client_name */
863 local_address, /* server_addr */
864 NULL, /* server_name */
866 if (subreq == NULL) {
868 DEBUG(0, ("tstream_npa_connect_send to %s for pipe %s and "
869 "user %s\\%s failed\n",
870 socket_np_dir, pipe_name, session_info_t->session_info->info->domain_name,
871 session_info_t->session_info->info->account_name));
874 ok = tevent_req_poll(subreq, ev);
877 DEBUG(0, ("tevent_req_poll to %s for pipe %s and user %s\\%s "
878 "failed for tstream_npa_connect: %s\n",
879 socket_np_dir, pipe_name, session_info_t->session_info->info->domain_name,
880 session_info_t->session_info->info->account_name,
885 ret = tstream_npa_connect_recv(subreq, &sys_errno,
889 &result->device_state,
890 &result->allocation_size);
894 if (errno == ENOENT) {
897 DEBUG(l, ("tstream_npa_connect_recv to %s for pipe %s and "
898 "user %s\\%s failed: %s\n",
899 socket_np_dir, pipe_name, session_info_t->session_info->info->domain_name,
900 session_info_t->session_info->info->account_name,
901 strerror(sys_errno)));
912 static NTSTATUS rpc_pipe_open_external(TALLOC_CTX *mem_ctx,
913 const char *pipe_name,
914 const struct ndr_interface_table *table,
915 const struct auth_session_info *session_info,
916 struct rpc_pipe_client **_result)
918 struct tsocket_address *local, *remote;
919 struct rpc_pipe_client *result = NULL;
920 struct np_proxy_state *proxy_state = NULL;
921 struct pipe_auth_data *auth;
925 /* this is an internal connection, fake up ip addresses */
926 ret = tsocket_address_inet_from_strings(talloc_tos(), "ip",
929 return NT_STATUS_NO_MEMORY;
931 ret = tsocket_address_inet_from_strings(talloc_tos(), "ip",
934 return NT_STATUS_NO_MEMORY;
937 proxy_state = make_external_rpc_pipe_p(mem_ctx, pipe_name,
938 local, remote, session_info);
940 DEBUG(1, ("Unable to make proxy_state for connection to %s.\n", pipe_name));
941 return NT_STATUS_UNSUCCESSFUL;
944 result = talloc_zero(mem_ctx, struct rpc_pipe_client);
945 if (result == NULL) {
946 status = NT_STATUS_NO_MEMORY;
950 result->abstract_syntax = table->syntax_id;
951 result->transfer_syntax = ndr_transfer_syntax_ndr;
953 result->desthost = get_myname(result);
954 result->srv_name_slash = talloc_asprintf_strupper_m(
955 result, "\\\\%s", result->desthost);
956 if ((result->desthost == NULL) || (result->srv_name_slash == NULL)) {
957 status = NT_STATUS_NO_MEMORY;
961 result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN;
963 status = rpc_transport_tstream_init(result,
966 if (!NT_STATUS_IS_OK(status)) {
970 result->binding_handle = rpccli_bh_create(result, NULL, table);
971 if (result->binding_handle == NULL) {
972 status = NT_STATUS_NO_MEMORY;
973 DEBUG(0, ("Failed to create binding handle.\n"));
977 result->auth = talloc_zero(result, struct pipe_auth_data);
979 status = NT_STATUS_NO_MEMORY;
982 result->auth->auth_type = DCERPC_AUTH_TYPE_NONE;
983 result->auth->auth_level = DCERPC_AUTH_LEVEL_NONE;
984 result->auth->auth_context_id = 0;
986 status = rpccli_anon_bind_data(result, &auth);
987 if (!NT_STATUS_IS_OK(status)) {
988 DEBUG(0, ("Failed to initialize anonymous bind.\n"));
992 status = rpc_pipe_bind(result, auth);
993 if (!NT_STATUS_IS_OK(status)) {
994 DEBUG(0, ("Failed to bind external pipe.\n"));
999 if (!NT_STATUS_IS_OK(status)) {
1000 TALLOC_FREE(result);
1002 TALLOC_FREE(proxy_state);
1008 * @brief Create a new RPC client context which uses a local dispatch function
1009 * or a remote transport, depending on rpc_server configuration for the
1012 * @param[in] mem_ctx The memory context to use.
1014 * @param[in] abstract_syntax Normally the syntax_id of the autogenerated
1017 * @param[in] serversupplied_info The server supplied authentication function.
1019 * @param[in] remote_address The client address information.
1021 * @param[in] msg_ctx The messaging context to use.
1023 * @param[out] presult A pointer to store the connected rpc client pipe.
1025 * @return NT_STATUS_OK on success, a corresponding NT status if an
1029 * struct rpc_pipe_client *winreg_pipe;
1032 * status = rpc_pipe_open_interface(tmp_ctx,
1033 * &ndr_table_winreg.syntax_id,
1040 NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
1041 const struct ndr_interface_table *table,
1042 const struct auth_session_info *session_info,
1043 const struct tsocket_address *remote_address,
1044 const struct tsocket_address *local_address,
1045 struct messaging_context *msg_ctx,
1046 struct rpc_pipe_client **cli_pipe)
1048 struct rpc_pipe_client *cli = NULL;
1049 enum rpc_service_mode_e pipe_mode;
1050 const char *pipe_name;
1052 TALLOC_CTX *tmp_ctx;
1054 if (cli_pipe != NULL) {
1055 if (rpccli_is_connected(*cli_pipe)) {
1056 return NT_STATUS_OK;
1058 TALLOC_FREE(*cli_pipe);
1062 tmp_ctx = talloc_stackframe();
1063 if (tmp_ctx == NULL) {
1064 return NT_STATUS_NO_MEMORY;
1067 pipe_name = dcerpc_default_transport_endpoint(mem_ctx, NCACN_NP, table);
1068 if (pipe_name == NULL) {
1069 DEBUG(1, ("Unable to find pipe name to forward %s to.\n", table->name));
1070 status = NT_STATUS_INVALID_PARAMETER;
1074 while (pipe_name[0] == '\\') {
1078 DEBUG(5, ("Connecting to %s pipe.\n", pipe_name));
1080 pipe_mode = rpc_service_mode(pipe_name);
1082 switch (pipe_mode) {
1083 case RPC_SERVICE_MODE_EMBEDDED:
1084 status = rpc_pipe_open_internal(tmp_ctx,
1085 table, session_info,
1086 remote_address, local_address,
1089 if (!NT_STATUS_IS_OK(status)) {
1093 case RPC_SERVICE_MODE_EXTERNAL:
1094 /* It would be nice to just use rpc_pipe_open_ncalrpc() but
1095 * for now we need to use the special proxy setup to connect
1098 status = rpc_pipe_open_external(tmp_ctx,
1102 if (!NT_STATUS_IS_OK(status)) {
1106 case RPC_SERVICE_MODE_DISABLED:
1107 status = NT_STATUS_NOT_IMPLEMENTED;
1108 DEBUG(0, ("Service pipe %s is disabled in config file: %s",
1109 pipe_name, nt_errstr(status)));
1113 status = NT_STATUS_OK;
1115 if (NT_STATUS_IS_OK(status) && cli_pipe != NULL) {
1116 *cli_pipe = talloc_move(mem_ctx, &cli);
1118 TALLOC_FREE(tmp_ctx);