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 /* prepare binding string */
42 case LIBNET_RPC_CONNECT_PDC:
43 case LIBNET_RPC_CONNECT_SERVER:
44 binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", r->in.domain_name);
47 case LIBNET_RPC_CONNECT_BINDING:
48 binding = r->in.binding;
52 /* connect to remote dcerpc pipe */
53 status = dcerpc_pipe_connect(mem_ctx, &r->out.dcerpc_pipe,
54 binding, r->in.dcerpc_iface_uuid, r->in.dcerpc_iface_version,
55 ctx->cred, ctx->event_ctx);
57 if (!NT_STATUS_IS_OK(status)) {
58 r->out.error_string = talloc_asprintf(mem_ctx,
59 "dcerpc_pipe_connect to pipe %s failed with %s\n",
60 r->in.dcerpc_iface_name, binding);
64 r->out.error_string = NULL;
65 ctx->pipe = r->out.dcerpc_pipe;
72 * Connects rpc pipe on domain pdc
74 * @param ctx initialised libnet context
75 * @param mem_ctx memory context of this call
76 * @param r data structure containing necessary parameters and return values
77 * @return nt status of the call
80 static NTSTATUS libnet_RpcConnectPdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
83 struct libnet_RpcConnect r2;
84 struct libnet_Lookup f;
86 f.in.hostname = r->in.domain_name;
90 /* find the domain pdc first */
91 status = libnet_LookupPdc(ctx, mem_ctx, &f);
92 if (!NT_STATUS_IS_OK(status)) {
93 r->out.error_string = talloc_asprintf(mem_ctx, "libnet_LookupPdc failed: %s",
98 /* ok, pdc has been found so do attempt to rpc connect */
99 r2.level = LIBNET_RPC_CONNECT_SERVER;
100 r2.in.domain_name = talloc_strdup(mem_ctx, f.out.address[0]);
101 r2.in.dcerpc_iface_name = r->in.dcerpc_iface_name;
102 r2.in.dcerpc_iface_uuid = r->in.dcerpc_iface_uuid;
103 r2.in.dcerpc_iface_version = r->in.dcerpc_iface_version;
105 status = libnet_RpcConnect(ctx, mem_ctx, &r2);
107 r->out.dcerpc_pipe = r2.out.dcerpc_pipe;
108 r->out.error_string = r2.out.error_string;
110 ctx->pipe = r->out.dcerpc_pipe;
117 * Connects to rpc pipe on remote server or pdc
119 * @param ctx initialised libnet context
120 * @param mem_ctx memory context of this call
121 * @param r data structure containing necessary parameters and return values
122 * @return nt status of the call
125 NTSTATUS libnet_RpcConnect(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_RpcConnect *r)
128 case LIBNET_RPC_CONNECT_SERVER:
129 return libnet_RpcConnectSrv(ctx, mem_ctx, r);
131 case LIBNET_RPC_CONNECT_BINDING:
132 return libnet_RpcConnectSrv(ctx, mem_ctx, r);
134 case LIBNET_RPC_CONNECT_PDC:
135 return libnet_RpcConnectPdc(ctx, mem_ctx, r);
138 return NT_STATUS_INVALID_LEVEL;