2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* find a domain pdc generic */
24 static NTSTATUS libnet_find_pdc_generic(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_find_pdc *r)
29 ret = get_pdc_ip(mem_ctx, r->generic.in.domain_name, &ip);
31 /* fallback to a workstation name */
32 ret = resolve_name(mem_ctx, r->generic.in.domain_name, &ip, 0x20);
34 return NT_STATUS_NO_LOGON_SERVERS;
38 r->generic.out.pdc_name = talloc_strdup(mem_ctx, inet_ntoa(ip));
43 /* find a domain pdc */
44 NTSTATUS libnet_find_pdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_find_pdc *r)
46 switch (r->generic.level) {
47 case LIBNET_FIND_PDC_GENERIC:
48 return libnet_find_pdc_generic(ctx, mem_ctx, r);
51 return NT_STATUS_INVALID_LEVEL;
54 /* connect to a dcerpc interface of a domains PDC */
55 static NTSTATUS libnet_rpc_connect_pdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_rpc_connect *r)
58 const char *binding = NULL;
59 union libnet_find_pdc f;
61 f.generic.level = LIBNET_FIND_PDC_GENERIC;
62 f.generic.in.domain_name = r->pdc.in.domain_name;
64 status = libnet_find_pdc(ctx, mem_ctx, &f);
65 if (!NT_STATUS_IS_OK(status)) {
69 binding = talloc_asprintf(mem_ctx, "ncacn_np:%s",
70 f.generic.out.pdc_name);
72 status = dcerpc_pipe_connect(&r->pdc.out.dcerpc_pipe,
74 r->pdc.in.dcerpc_iface_uuid,
75 r->pdc.in.dcerpc_iface_version,
76 ctx->user.domain_name,
77 ctx->user.account_name,
83 /* connect to a dcerpc interface */
84 NTSTATUS libnet_rpc_connect(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_rpc_connect *r)
86 switch (r->pdc.level) {
87 case LIBNET_RPC_CONNECT_PDC:
88 return libnet_rpc_connect_pdc(ctx, mem_ctx, r);
91 return NT_STATUS_INVALID_LEVEL;