source: trunk/server/source4/winbind/wb_dom_info.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 4.5 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 Get a struct wb_dom_info for a domain using DNS, netbios, possibly cldap
5 etc.
6
7 Copyright (C) Volker Lendecke 2005
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "includes.h"
24#include "libcli/composite/composite.h"
25#include "libcli/resolve/resolve.h"
26#include "libcli/security/security.h"
27#include "winbind/wb_server.h"
28#include "smbd/service_task.h"
29#include "libcli/finddc.h"
30
31struct get_dom_info_state {
32 struct composite_context *ctx;
33 struct wb_dom_info *info;
34};
35
36static void get_dom_info_recv_addrs(struct tevent_req *req);
37
38struct composite_context *wb_get_dom_info_send(TALLOC_CTX *mem_ctx,
39 struct wbsrv_service *service,
40 const char *domain_name,
41 const char *dns_domain_name,
42 const struct dom_sid *sid)
43{
44 struct composite_context *result;
45 struct tevent_req *req;
46 struct get_dom_info_state *state;
47 struct dom_sid *dom_sid;
48 struct finddcs finddcs_io;
49
50 DEBUG(5, ("wb_get_dom_info_send called\n"));
51 result = composite_create(mem_ctx, service->task->event_ctx);
52 if (result == NULL) goto failed;
53
54 state = talloc(result, struct get_dom_info_state);
55 if (state == NULL) goto failed;
56 state->ctx = result;
57 result->private_data = state;
58
59 state->info = talloc_zero(state, struct wb_dom_info);
60 if (state->info == NULL) goto failed;
61
62 state->info->name = talloc_strdup(state->info, domain_name);
63 if (state->info->name == NULL) goto failed;
64
65 state->info->sid = dom_sid_dup(state->info, sid);
66 if (state->info->sid == NULL) goto failed;
67
68 dom_sid = dom_sid_dup(mem_ctx, sid);
69 if (dom_sid == NULL) goto failed;
70
71 ZERO_STRUCT(finddcs_io);
72 finddcs_io.in.domain_name = dns_domain_name;
73 finddcs_io.in.domain_sid = dom_sid;
74 finddcs_io.in.minimum_dc_flags = NBT_SERVER_LDAP | NBT_SERVER_DS;
75 if (service->sec_channel_type == SEC_CHAN_RODC) {
76 finddcs_io.in.minimum_dc_flags |= NBT_SERVER_WRITABLE;
77 }
78
79 req = finddcs_cldap_send(mem_ctx, &finddcs_io,
80 lpcfg_resolve_context(service->task->lp_ctx),
81 service->task->event_ctx);
82 if (req == NULL) goto failed;
83
84 tevent_req_set_callback(req, get_dom_info_recv_addrs, state);
85
86 return result;
87
88 failed:
89 talloc_free(result);
90 return NULL;
91}
92
93static void get_dom_info_recv_addrs(struct tevent_req *req)
94{
95 struct get_dom_info_state *state = tevent_req_callback_data(req, struct get_dom_info_state);
96 struct finddcs finddcs_io;
97
98 state->info->dc = talloc(state->info, struct nbt_dc_name);
99
100 state->ctx->status = finddcs_cldap_recv(req, state->info, &finddcs_io);
101 if (!composite_is_ok(state->ctx)) return;
102
103 if (finddcs_io.out.netlogon.ntver != NETLOGON_NT_VERSION_5EX) {
104 /* the finddcs code should have mapped the response to
105 the type we want */
106 DEBUG(0,(__location__ ": unexpected ntver 0x%08x in finddcs response\n",
107 finddcs_io.out.netlogon.ntver));
108 state->ctx->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
109 if (!composite_is_ok(state->ctx)) return;
110 }
111
112 state->info->dc->address = finddcs_io.out.address;
113 state->info->dc->name = finddcs_io.out.netlogon.data.nt5_ex.pdc_dns_name;
114
115 composite_done(state->ctx);
116}
117
118NTSTATUS wb_get_dom_info_recv(struct composite_context *ctx,
119 TALLOC_CTX *mem_ctx,
120 struct wb_dom_info **result)
121{
122 NTSTATUS status = composite_wait(ctx);
123 if (NT_STATUS_IS_OK(status)) {
124 struct get_dom_info_state *state =
125 talloc_get_type(ctx->private_data,
126 struct get_dom_info_state);
127 *result = talloc_steal(mem_ctx, state->info);
128 }
129 talloc_free(ctx);
130 return status;
131}
132
133NTSTATUS wb_get_dom_info(TALLOC_CTX *mem_ctx,
134 struct wbsrv_service *service,
135 const char *domain_name,
136 const char *dns_domain_name,
137 const struct dom_sid *sid,
138 struct wb_dom_info **result)
139{
140 struct composite_context *ctx =
141 wb_get_dom_info_send(mem_ctx, service, domain_name, dns_domain_name, sid);
142 return wb_get_dom_info_recv(ctx, mem_ctx, result);
143}
Note: See TracBrowser for help on using the repository browser.