2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2004
5 Copyright (C) Rafal Szczesniak 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "libnet/libnet.h"
24 #include "libcli/libcli.h"
25 #include "libcli/composite/composite.h"
26 #include "librpc/rpc/dcerpc.h"
27 #include "librpc/gen_ndr/ndr_lsa_c.h"
28 #include "librpc/gen_ndr/ndr_samr.h"
31 struct rpc_connect_srv_state {
32 struct libnet_context *ctx;
33 struct libnet_RpcConnect r;
38 static void continue_pipe_connect(struct composite_context *ctx);
42 * Initiates connection to rpc pipe on remote server
44 * @param ctx initialised libnet context
45 * @param mem_ctx memory context of this call
46 * @param r data structure containing necessary parameters and return values
47 * @return composite context of this call
50 static struct composite_context* libnet_RpcConnectSrv_send(struct libnet_context *ctx,
52 struct libnet_RpcConnect *r)
54 struct composite_context *c;
55 struct rpc_connect_srv_state *s;
56 struct composite_context *pipe_connect_req;
58 /* composite context allocation and setup */
59 c = talloc_zero(mem_ctx, struct composite_context);
60 if (c == NULL) return NULL;
62 s = talloc_zero(c, struct rpc_connect_srv_state);
63 if (composite_nomem(s, c)) return c;
65 c->state = COMPOSITE_STATE_IN_PROGRESS;
67 c->event_ctx = ctx->event_ctx;
71 ZERO_STRUCT(s->r.out);
73 /* prepare binding string */
75 case LIBNET_RPC_CONNECT_DC:
76 case LIBNET_RPC_CONNECT_PDC:
77 case LIBNET_RPC_CONNECT_SERVER:
78 s->binding = talloc_asprintf(s, "ncacn_np:%s", r->in.name);
81 case LIBNET_RPC_CONNECT_BINDING:
82 s->binding = talloc_strdup(s, r->in.binding);
85 case LIBNET_RPC_CONNECT_DC_INFO:
86 /* this should never happen - DC_INFO level has a separate
88 composite_error(c, NT_STATUS_INVALID_LEVEL);
92 /* connect to remote dcerpc pipe */
93 pipe_connect_req = dcerpc_pipe_connect_send(c, &s->r.out.dcerpc_pipe,
94 s->binding, r->in.dcerpc_iface,
95 ctx->cred, c->event_ctx);
96 if (composite_nomem(pipe_connect_req, c)) return c;
98 composite_continue(c, pipe_connect_req, continue_pipe_connect, c);
104 Step 2 of RpcConnectSrv - get rpc connection
106 static void continue_pipe_connect(struct composite_context *ctx)
108 struct composite_context *c;
109 struct rpc_connect_srv_state *s;
111 c = talloc_get_type(ctx->async.private_data, struct composite_context);
112 s = talloc_get_type(c->private_data, struct rpc_connect_srv_state);
114 /* receive result of rpc pipe connection */
115 c->status = dcerpc_pipe_connect_recv(ctx, c, &s->r.out.dcerpc_pipe);
117 s->r.out.error_string = NULL;
123 * Receives result of connection to rpc pipe on remote server
125 * @param c composite context
126 * @param ctx initialised libnet context
127 * @param mem_ctx memory context of this call
128 * @param r data structure containing necessary parameters and return values
129 * @return nt status of rpc connection
132 static NTSTATUS libnet_RpcConnectSrv_recv(struct composite_context *c,
133 struct libnet_context *ctx,
135 struct libnet_RpcConnect *r)
138 struct rpc_connect_srv_state *s = talloc_get_type(c->private_data,
139 struct rpc_connect_srv_state);
141 status = composite_wait(c);
142 if (NT_STATUS_IS_OK(status)) {
143 /* move the returned rpc pipe between memory contexts */
144 s = talloc_get_type(c->private_data, struct rpc_connect_srv_state);
145 r->out.dcerpc_pipe = talloc_steal(mem_ctx, s->r.out.dcerpc_pipe);
147 /* reference created pipe structure to long-term libnet_context
148 so that it can be used by other api functions even after short-term
150 if (r->in.dcerpc_iface == &dcerpc_table_samr) {
151 ctx->samr_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
153 } else if (r->in.dcerpc_iface == &dcerpc_table_lsarpc) {
154 ctx->lsa_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
157 r->out.error_string = talloc_steal(mem_ctx, s->r.out.error_string);
165 struct rpc_connect_dc_state {
166 struct libnet_context *ctx;
167 struct libnet_RpcConnect r;
168 struct libnet_RpcConnect r2;
169 struct libnet_LookupDCs f;
170 const char *connect_name;
172 /* information about the progress */
173 void (*monitor_fn)(struct monitor_msg *);
177 static void continue_lookup_dc(struct composite_context *ctx);
178 static void continue_rpc_connect(struct composite_context *ctx);
182 * Initiates connection to rpc pipe on domain pdc
184 * @param ctx initialised libnet context
185 * @param mem_ctx memory context of this call
186 * @param r data structure containing necessary parameters and return values
187 * @return composite context of this call
190 static struct composite_context* libnet_RpcConnectDC_send(struct libnet_context *ctx,
192 struct libnet_RpcConnect *r)
194 struct composite_context *c;
195 struct rpc_connect_dc_state *s;
196 struct composite_context *lookup_dc_req;
198 /* composite context allocation and setup */
199 c = talloc_zero(mem_ctx, struct composite_context);
200 if (c == NULL) return NULL;
202 s = talloc_zero(c, struct rpc_connect_dc_state);
203 if (composite_nomem(s, c)) return c;
205 c->state = COMPOSITE_STATE_IN_PROGRESS;
207 c->event_ctx = ctx->event_ctx;
211 ZERO_STRUCT(s->r.out);
214 case LIBNET_RPC_CONNECT_PDC:
215 s->f.in.name_type = NBT_NAME_PDC;
218 case LIBNET_RPC_CONNECT_DC:
219 s->f.in.name_type = NBT_NAME_LOGON;
226 s->f.in.domain_name = r->in.name;
227 s->f.out.num_dcs = 0;
230 /* find the domain pdc first */
231 lookup_dc_req = libnet_LookupDCs_send(ctx, c, &s->f);
232 if (composite_nomem(lookup_dc_req, c)) return c;
234 composite_continue(c, lookup_dc_req, continue_lookup_dc, c);
240 Step 2 of RpcConnectDC: get domain controller name/address and
241 initiate RpcConnect to it
243 static void continue_lookup_dc(struct composite_context *ctx)
245 struct composite_context *c;
246 struct rpc_connect_dc_state *s;
247 struct composite_context *rpc_connect_req;
248 struct monitor_msg msg;
249 struct msg_net_lookup_dc data;
251 c = talloc_get_type(ctx->async.private_data, struct composite_context);
252 s = talloc_get_type(c->private_data, struct rpc_connect_dc_state);
254 /* receive result of domain controller lookup */
255 c->status = libnet_LookupDCs_recv(ctx, c, &s->f);
256 if (!composite_is_ok(c)) return;
258 /* decide on preferred address type depending on DC type */
259 switch (s->r.level) {
260 case LIBNET_RPC_CONNECT_PDC:
261 s->connect_name = s->f.out.dcs[0].name;
264 case LIBNET_RPC_CONNECT_DC:
265 s->connect_name = s->f.out.dcs[0].address;
269 /* we shouldn't absolutely get here */
270 composite_error(c, NT_STATUS_INVALID_LEVEL);
273 /* prepare a monitor message and post it */
274 msg.type = net_lookup_dc;
276 msg.data_size = sizeof(data);
278 data.domain_name = s->f.in.domain_name;
279 data.hostname = s->f.out.dcs[0].name;
280 data.address = s->f.out.dcs[0].address;
282 if (s->monitor_fn) s->monitor_fn(&msg);
284 /* ok, pdc has been found so do attempt to rpc connect */
285 s->r2.level = s->r.level;
287 /* this will cause yet another name resolution, but at least
288 * we pass the right name down the stack now */
289 s->r2.in.name = talloc_strdup(c, s->connect_name);
290 s->r2.in.dcerpc_iface = s->r.in.dcerpc_iface;
292 /* send rpc connect request to the server */
293 rpc_connect_req = libnet_RpcConnectSrv_send(s->ctx, c, &s->r2);
294 if (composite_nomem(rpc_connect_req, c)) return;
296 composite_continue(c, rpc_connect_req, continue_rpc_connect, c);
301 Step 3 of RpcConnectDC: get rpc connection to the server
303 static void continue_rpc_connect(struct composite_context *ctx)
305 struct composite_context *c;
306 struct rpc_connect_dc_state *s;
307 struct monitor_msg msg;
308 struct msg_net_pipe_connected data;
310 c = talloc_get_type(ctx->async.private_data, struct composite_context);
311 s = talloc_get_type(c->private_data, struct rpc_connect_dc_state);
313 c->status = libnet_RpcConnectSrv_recv(ctx, s->ctx, c, &s->r2);
315 /* error string is to be passed anyway */
316 s->r.out.error_string = s->r2.out.error_string;
317 if (!composite_is_ok(c)) return;
319 s->r.out.dcerpc_pipe = s->r2.out.dcerpc_pipe;
321 /* prepare a monitor message and post it */
322 msg.type = net_pipe_connected;
326 data.host = s->r.out.dcerpc_pipe->binding->host;
327 data.endpoint = s->r.out.dcerpc_pipe->binding->endpoint;
328 data.transport = s->r.out.dcerpc_pipe->binding->transport;
330 if (s->monitor_fn) s->monitor_fn(&msg);
337 * Receives result of connection to rpc pipe on domain pdc
339 * @param c composite context
340 * @param ctx initialised libnet context
341 * @param mem_ctx memory context of this call
342 * @param r data structure containing necessary parameters and return values
343 * @return nt status of rpc connection
346 static NTSTATUS libnet_RpcConnectDC_recv(struct composite_context *c,
347 struct libnet_context *ctx,
349 struct libnet_RpcConnect *r)
352 struct rpc_connect_dc_state *s = talloc_get_type(c->private_data,
353 struct rpc_connect_dc_state);
355 status = composite_wait(c);
356 if (NT_STATUS_IS_OK(status)) {
357 /* move connected rpc pipe between memory contexts */
358 r->out.dcerpc_pipe = talloc_steal(mem_ctx, s->r.out.dcerpc_pipe);
360 /* reference created pipe structure to long-term libnet_context
361 so that it can be used by other api functions even after short-term
363 if (r->in.dcerpc_iface == &dcerpc_table_samr) {
364 ctx->samr_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
366 } else if (r->in.dcerpc_iface == &dcerpc_table_lsarpc) {
367 ctx->lsa_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
371 r->out.error_string = talloc_steal(mem_ctx, s->r.out.error_string);
380 struct rpc_connect_dci_state {
381 struct libnet_context *ctx;
382 struct libnet_RpcConnect r;
383 struct libnet_RpcConnect rpc_conn;
384 struct policy_handle lsa_handle;
385 struct lsa_QosInfo qos;
386 struct lsa_ObjectAttribute attr;
387 struct lsa_OpenPolicy2 lsa_open_policy;
388 struct dcerpc_pipe *lsa_pipe;
389 struct lsa_QueryInfoPolicy2 lsa_query_info2;
390 struct lsa_QueryInfoPolicy lsa_query_info;
391 struct dcerpc_binding *final_binding;
392 struct dcerpc_pipe *final_pipe;
396 static void continue_dci_rpc_connect(struct composite_context *ctx);
397 static void continue_lsa_policy(struct rpc_request *req);
398 static void continue_lsa_query_info(struct rpc_request *req);
399 static void continue_lsa_query_info2(struct rpc_request *req);
400 static void continue_epm_map_binding(struct composite_context *ctx);
401 static void continue_secondary_conn(struct composite_context *ctx);
405 * Initiates connection to rpc pipe on remote server or pdc. Received result
406 * contains info on the domain name, domain sid and realm.
408 * @param ctx initialised libnet context
409 * @param mem_ctx memory context of this call
410 * @param r data structure containing necessary parameters and return values. Must be a talloc context
411 * @return composite context of this call
414 static struct composite_context* libnet_RpcConnectDCInfo_send(struct libnet_context *ctx,
416 struct libnet_RpcConnect *r)
418 struct composite_context *c, *conn_req;
419 struct rpc_connect_dci_state *s;
421 /* composite context allocation and setup */
422 c = talloc_zero(mem_ctx, struct composite_context);
423 if (c == NULL) return NULL;
425 s = talloc_zero(c, struct rpc_connect_dci_state);
426 if (composite_nomem(s, c)) return c;
428 c->state = COMPOSITE_STATE_IN_PROGRESS;
430 c->event_ctx = ctx->event_ctx;
434 ZERO_STRUCT(s->r.out);
436 /* proceed to pure rpc connection if the binding string is provided,
437 otherwise try to connect domain controller */
438 if (r->in.binding == NULL) {
439 s->rpc_conn.in.name = r->in.name;
440 s->rpc_conn.level = LIBNET_RPC_CONNECT_DC;
442 s->rpc_conn.in.binding = r->in.binding;
443 s->rpc_conn.level = LIBNET_RPC_CONNECT_BINDING;
446 /* we need to query information on lsarpc interface first */
447 s->rpc_conn.in.dcerpc_iface = &dcerpc_table_lsarpc;
449 /* request connection to the lsa pipe on the pdc */
450 conn_req = libnet_RpcConnect_send(ctx, c, &s->rpc_conn);
451 if (composite_nomem(c, conn_req)) return c;
453 composite_continue(c, conn_req, continue_dci_rpc_connect, c);
459 Step 2 of RpcConnectDCInfo: receive opened rpc pipe and open
462 static void continue_dci_rpc_connect(struct composite_context *ctx)
464 struct composite_context *c;
465 struct rpc_connect_dci_state *s;
466 struct rpc_request *open_pol_req;
468 c = talloc_get_type(ctx->async.private_data, struct composite_context);
469 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
471 c->status = libnet_RpcConnect_recv(ctx, s->ctx, c, &s->rpc_conn);
472 if (!NT_STATUS_IS_OK(c->status)) {
473 composite_error(c, c->status);
477 /* prepare to open a policy handle on lsa pipe */
478 s->lsa_pipe = s->ctx->lsa_pipe;
481 s->qos.impersonation_level = 2;
482 s->qos.context_mode = 1;
483 s->qos.effective_only = 0;
485 s->attr.sec_qos = &s->qos;
487 s->lsa_open_policy.in.attr = &s->attr;
488 s->lsa_open_policy.in.system_name = talloc_asprintf(c, "\\");
489 if (composite_nomem(s->lsa_open_policy.in.system_name, c)) return;
491 s->lsa_open_policy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
492 s->lsa_open_policy.out.handle = &s->lsa_handle;
494 open_pol_req = dcerpc_lsa_OpenPolicy2_send(s->lsa_pipe, c, &s->lsa_open_policy);
495 if (composite_nomem(open_pol_req, c)) return;
497 composite_continue_rpc(c, open_pol_req, continue_lsa_policy, c);
502 Step 3 of RpcConnectDCInfo: Get policy handle and query lsa info
503 for kerberos realm (dns name) and guid. The query may fail.
505 static void continue_lsa_policy(struct rpc_request *req)
507 struct composite_context *c;
508 struct rpc_connect_dci_state *s;
509 struct rpc_request *query_info_req;
511 c = talloc_get_type(req->async.private, struct composite_context);
512 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
514 c->status = dcerpc_ndr_request_recv(req);
515 if (!NT_STATUS_IS_OK(c->status)) {
516 composite_error(c, c->status);
520 if (!NT_STATUS_IS_OK(s->lsa_query_info2.out.result)) {
521 composite_error(c, s->lsa_query_info2.out.result);
525 /* query lsa info for dns domain name and guid */
526 s->lsa_query_info2.in.handle = &s->lsa_handle;
527 s->lsa_query_info2.in.level = LSA_POLICY_INFO_DNS;
529 query_info_req = dcerpc_lsa_QueryInfoPolicy2_send(s->lsa_pipe, c, &s->lsa_query_info2);
530 if (composite_nomem(query_info_req, c)) return;
532 composite_continue_rpc(c, query_info_req, continue_lsa_query_info2, c);
537 Step 4 of RpcConnectDCInfo: Get realm and guid if provided (rpc call
538 may result in failure) and query lsa info for domain name and sid.
540 static void continue_lsa_query_info2(struct rpc_request *req)
542 struct composite_context *c;
543 struct rpc_connect_dci_state *s;
544 struct rpc_request *query_info_req;
546 c = talloc_get_type(req->async.private, struct composite_context);
547 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
549 c->status = dcerpc_ndr_request_recv(req);
551 /* In case of error just null the realm and guid and proceed
552 to the next step. After all, it doesn't have to be AD domain
553 controller we talking to - NT-style PDC also counts */
555 if (NT_STATUS_EQUAL(c->status, NT_STATUS_NET_WRITE_FAULT)) {
556 s->r.out.realm = NULL;
557 s->r.out.guid = NULL;
560 if (!NT_STATUS_IS_OK(c->status)) {
561 s->r.out.error_string = talloc_asprintf(c,
562 "lsa_QueryInfoPolicy2 failed: %s",
563 nt_errstr(c->status));
564 composite_error(c, c->status);
568 if (!NT_STATUS_IS_OK(s->lsa_query_info2.out.result)) {
569 s->r.out.error_string = talloc_asprintf(c,
570 "lsa_QueryInfoPolicy2 failed: %s",
571 nt_errstr(s->lsa_query_info2.out.result));
572 composite_error(c, s->lsa_query_info2.out.result);
576 /* Copy the dns domain name and guid from the query result */
578 /* this should actually be a conversion from lsa_StringLarge */
579 s->r.out.realm = s->lsa_query_info2.out.info->dns.dns_domain.string;
580 s->r.out.guid = talloc(c, struct GUID);
581 if (composite_nomem(s->r.out.guid, c)) {
582 s->r.out.error_string = NULL;
585 *s->r.out.guid = s->lsa_query_info2.out.info->dns.domain_guid;
588 /* query lsa info for domain name and sid */
589 s->lsa_query_info.in.handle = &s->lsa_handle;
590 s->lsa_query_info.in.level = LSA_POLICY_INFO_DOMAIN;
592 query_info_req = dcerpc_lsa_QueryInfoPolicy_send(s->lsa_pipe, c, &s->lsa_query_info);
593 if (composite_nomem(query_info_req, c)) return;
595 composite_continue_rpc(c, query_info_req, continue_lsa_query_info, c);
600 Step 5 of RpcConnectDCInfo: Get domain name and sid and request endpoint
603 static void continue_lsa_query_info(struct rpc_request *req)
605 struct composite_context *c, *epm_map_req;
606 struct rpc_connect_dci_state *s;
608 c = talloc_get_type(req->async.private, struct composite_context);
609 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
611 c->status = dcerpc_ndr_request_recv(req);
612 if (!NT_STATUS_IS_OK(c->status)) {
613 s->r.out.error_string = talloc_asprintf(c,
614 "lsa_QueryInfoPolicy failed: %s",
615 nt_errstr(c->status));
616 composite_error(c, c->status);
620 /* Copy the domain name and sid from the query result */
621 s->r.out.domain_sid = s->lsa_query_info.out.info->domain.sid;
622 s->r.out.domain_name = s->lsa_query_info.out.info->domain.name.string;
625 /* prepare to get endpoint mapping for the requested interface */
626 s->final_binding = talloc(s, struct dcerpc_binding);
627 if (composite_nomem(s->final_binding, c)) return;
629 *s->final_binding = *s->lsa_pipe->binding;
630 /* Ensure we keep hold of the member elements */
631 talloc_reference(s->final_binding, s->lsa_pipe->binding);
633 epm_map_req = dcerpc_epm_map_binding_send(c, s->final_binding, s->r.in.dcerpc_iface,
634 s->lsa_pipe->conn->event_ctx);
635 if (composite_nomem(epm_map_req, c)) return;
637 composite_continue(c, epm_map_req, continue_epm_map_binding, c);
642 Step 6 of RpcConnectDCInfo: Receive endpoint mapping and create secondary
643 rpc connection derived from already used pipe but connected to the requested
644 one (as specified in libnet_RpcConnect structure)
646 static void continue_epm_map_binding(struct composite_context *ctx)
648 struct composite_context *c, *sec_conn_req;
649 struct rpc_connect_dci_state *s;
651 c = talloc_get_type(ctx->async.private_data, struct composite_context);
652 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
654 c->status = dcerpc_epm_map_binding_recv(ctx);
655 if (!NT_STATUS_IS_OK(c->status)) {
656 s->r.out.error_string = talloc_asprintf(c,
657 "failed to map pipe with endpoint mapper - %s",
658 nt_errstr(c->status));
659 composite_error(c, c->status);
663 /* create secondary connection derived from lsa pipe */
664 sec_conn_req = dcerpc_secondary_connection_send(s->lsa_pipe, s->final_binding);
665 if (composite_nomem(sec_conn_req, c)) return;
667 composite_continue(c, sec_conn_req, continue_secondary_conn, c);
672 Step 7 of RpcConnectDCInfo: Get actual lsa pipe to be returned
673 and complete this composite call
675 static void continue_secondary_conn(struct composite_context *ctx)
677 struct composite_context *c;
678 struct rpc_connect_dci_state *s;
680 c = talloc_get_type(ctx->async.private_data, struct composite_context);
681 s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
683 c->status = dcerpc_secondary_connection_recv(ctx, &s->final_pipe);
684 if (!NT_STATUS_IS_OK(c->status)) {
685 s->r.out.error_string = talloc_asprintf(c,
686 "secondary connection failed: %s",
687 nt_errstr(c->status));
689 composite_error(c, c->status);
693 s->r.out.dcerpc_pipe = s->final_pipe;
699 * Receives result of connection to rpc pipe and gets basic
700 * domain info (name, sid, realm, guid)
702 * @param c composite context
703 * @param ctx initialised libnet context
704 * @param mem_ctx memory context of this call
705 * @param r data structure containing return values
706 * @return nt status of rpc connection
709 static NTSTATUS libnet_RpcConnectDCInfo_recv(struct composite_context *c, struct libnet_context *ctx,
710 TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
713 struct rpc_connect_dci_state *s = talloc_get_type(c->private_data,
714 struct rpc_connect_dci_state);
716 status = composite_wait(c);
717 if (NT_STATUS_IS_OK(status)) {
718 r->out.realm = talloc_steal(mem_ctx, s->r.out.realm);
719 r->out.guid = talloc_steal(mem_ctx, s->r.out.guid);
720 r->out.domain_name = talloc_steal(mem_ctx, s->r.out.domain_name);
721 r->out.domain_sid = talloc_steal(mem_ctx, s->r.out.domain_sid);
723 r->out.dcerpc_pipe = talloc_steal(mem_ctx, s->r.out.dcerpc_pipe);
725 /* reference created pipe structure to long-term libnet_context
726 so that it can be used by other api functions even after short-term
728 if (r->in.dcerpc_iface == &dcerpc_table_samr) {
729 ctx->samr_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
731 } else if (r->in.dcerpc_iface == &dcerpc_table_lsarpc) {
732 ctx->lsa_pipe = talloc_reference(ctx, r->out.dcerpc_pipe);
736 r->out.error_string = talloc_steal(mem_ctx, s->r.out.error_string);
745 * Initiates connection to rpc pipe on remote server or pdc, optionally
746 * providing domain info
748 * @param ctx initialised libnet context
749 * @param mem_ctx memory context of this call
750 * @param r data structure containing necessary parameters and return values
751 * @return composite context of this call
754 struct composite_context* libnet_RpcConnect_send(struct libnet_context *ctx,
756 struct libnet_RpcConnect *r)
758 struct composite_context *c;
761 case LIBNET_RPC_CONNECT_SERVER:
762 case LIBNET_RPC_CONNECT_BINDING:
763 c = libnet_RpcConnectSrv_send(ctx, mem_ctx, r);
766 case LIBNET_RPC_CONNECT_PDC:
767 case LIBNET_RPC_CONNECT_DC:
768 c = libnet_RpcConnectDC_send(ctx, mem_ctx, r);
771 case LIBNET_RPC_CONNECT_DC_INFO:
772 c = libnet_RpcConnectDCInfo_send(ctx, mem_ctx, r);
776 c = talloc_zero(mem_ctx, struct composite_context);
777 composite_error(c, NT_STATUS_INVALID_LEVEL);
785 * Receives result of connection to rpc pipe on remote server or pdc
787 * @param c composite context
788 * @param ctx initialised libnet context
789 * @param mem_ctx memory context of this call
790 * @param r data structure containing necessary parameters and return values
791 * @return nt status of rpc connection
794 NTSTATUS libnet_RpcConnect_recv(struct composite_context *c, struct libnet_context *ctx,
795 TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
798 case LIBNET_RPC_CONNECT_SERVER:
799 case LIBNET_RPC_CONNECT_BINDING:
800 return libnet_RpcConnectSrv_recv(c, ctx, mem_ctx, r);
802 case LIBNET_RPC_CONNECT_PDC:
803 case LIBNET_RPC_CONNECT_DC:
804 return libnet_RpcConnectDC_recv(c, ctx, mem_ctx, r);
806 case LIBNET_RPC_CONNECT_DC_INFO:
807 return libnet_RpcConnectDCInfo_recv(c, ctx, mem_ctx, r);
811 return NT_STATUS_INVALID_LEVEL;
817 * Connect to a rpc pipe on a remote server - sync version
819 * @param ctx initialised libnet context
820 * @param mem_ctx memory context of this call
821 * @param r data structure containing necessary parameters and return values
822 * @return nt status of rpc connection
825 NTSTATUS libnet_RpcConnect(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
826 struct libnet_RpcConnect *r)
828 struct composite_context *c;
830 c = libnet_RpcConnect_send(ctx, mem_ctx, r);
831 return libnet_RpcConnect_recv(c, ctx, mem_ctx, r);