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"
27 * Connects rpc pipe on remote server
29 * @param ctx initialised libnet context
30 * @param mem_ctx memory context of this call
31 * @param r data structure containing necessary parameters and return values
32 * @return nt status of the call
35 static NTSTATUS libnet_RpcConnectSrv(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
38 const char *binding = NULL;
40 binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", r->in.domain_name);
42 status = dcerpc_pipe_connect(mem_ctx, &r->out.dcerpc_pipe,
43 binding, r->in.dcerpc_iface_uuid,r->in.dcerpc_iface_version,
44 ctx->cred, ctx->event_ctx);
46 if (!NT_STATUS_IS_OK(status)) {
47 r->out.error_string = talloc_asprintf(mem_ctx,
48 "dcerpc_pipe_connect to pipe %s failed with %s\n",
49 r->in.dcerpc_iface_name, binding);
53 r->out.error_string = NULL;
54 ctx->pipe = r->out.dcerpc_pipe;
61 * Connects rpc pipe on domain pdc
63 * @param ctx initialised libnet context
64 * @param mem_ctx memory context of this call
65 * @param r data structure containing necessary parameters and return values
66 * @return nt status of the call
69 static NTSTATUS libnet_RpcConnectPdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
72 struct libnet_RpcConnect r2;
73 struct libnet_Lookup f;
74 const char *address = talloc_array(ctx, const char, 16);
76 f.in.hostname = r->in.domain_name;
78 f.out.address = &address;
80 status = libnet_LookupPdc(ctx, mem_ctx, &f);
81 if (!NT_STATUS_IS_OK(status)) {
82 r->out.error_string = talloc_asprintf(mem_ctx, "libnet_LookupPdc failed: %s",
87 r2.level = LIBNET_RPC_CONNECT_SERVER;
88 r2.in.domain_name = talloc_strdup(mem_ctx, *f.out.address);
89 r2.in.dcerpc_iface_name = r->in.dcerpc_iface_name;
90 r2.in.dcerpc_iface_uuid = r->in.dcerpc_iface_uuid;
91 r2.in.dcerpc_iface_version = r->in.dcerpc_iface_version;
93 status = libnet_RpcConnect(ctx, mem_ctx, &r2);
95 r->out.dcerpc_pipe = r2.out.dcerpc_pipe;
96 r->out.error_string = r2.out.error_string;
98 ctx->pipe = r->out.dcerpc_pipe;
105 * Connects to rpc pipe on remote server or pdc
107 * @param ctx initialised libnet context
108 * @param mem_ctx memory context of this call
109 * @param r data structure containing necessary parameters and return values
110 * @return nt status of the call
113 NTSTATUS libnet_RpcConnect(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
116 case LIBNET_RPC_CONNECT_SERVER:
117 return libnet_RpcConnectSrv(ctx, mem_ctx, r);
118 case LIBNET_RPC_CONNECT_PDC:
119 return libnet_RpcConnectPdc(ctx, mem_ctx, r);
122 return NT_STATUS_INVALID_LEVEL;