werror: replace WERR_NO_SUCH_SHARE with WERR_BAD_NET_NAME in source3/rpc_server/srvsv...
[Samba.git] / source3 / winbindd / winbindd_reconnect_ads.c
blob7ea8298c4a4356ce286c317d463efc4d6b0ad107
1 /*
2 Unix SMB/CIFS implementation.
4 Wrapper around winbindd_ads.c to centralize retry logic.
5 Copyright (C) Christof Schmitt 2016
7 Based on winbindd_reconnect.c
8 Copyright (C) Volker Lendecke 2005
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "winbindd.h"
27 #ifdef HAVE_ADS
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_WINBIND
32 extern struct winbindd_methods ads_methods;
34 /* List all users */
35 static NTSTATUS query_user_list(struct winbindd_domain *domain,
36 TALLOC_CTX *mem_ctx,
37 uint32_t *num_entries,
38 struct wbint_userinfo **info)
40 NTSTATUS result;
42 result = ads_methods.query_user_list(domain, mem_ctx,
43 num_entries, info);
45 if (reconnect_need_retry(result, domain)) {
46 result = ads_methods.query_user_list(domain, mem_ctx,
47 num_entries, info);
50 return result;
53 /* list all domain groups */
54 static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
55 TALLOC_CTX *mem_ctx,
56 uint32_t *num_entries,
57 struct wb_acct_info **info)
59 NTSTATUS result;
61 result = ads_methods.enum_dom_groups(domain, mem_ctx,
62 num_entries, info);
64 if (reconnect_need_retry(result, domain)) {
65 result = ads_methods.enum_dom_groups(domain, mem_ctx,
66 num_entries, info);
69 return result;
72 /* List all domain groups */
73 static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
74 TALLOC_CTX *mem_ctx,
75 uint32_t *num_entries,
76 struct wb_acct_info **info)
78 NTSTATUS result;
80 result = ads_methods.enum_local_groups(domain, mem_ctx,
81 num_entries, info);
83 if (reconnect_need_retry(result, domain)) {
84 result = ads_methods.enum_local_groups(domain, mem_ctx,
85 num_entries, info);
88 return result;
91 /* convert a single name to a sid in a domain */
92 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
93 TALLOC_CTX *mem_ctx,
94 const char *domain_name,
95 const char *name,
96 uint32_t flags,
97 struct dom_sid *sid,
98 enum lsa_SidType *type)
100 NTSTATUS result;
102 result = ads_methods.name_to_sid(domain, mem_ctx, domain_name, name,
103 flags, sid, type);
105 if (reconnect_need_retry(result, domain)) {
106 result = ads_methods.name_to_sid(domain, mem_ctx,
107 domain_name, name, flags,
108 sid, type);
111 return result;
115 convert a domain SID to a user or group name
117 static NTSTATUS sid_to_name(struct winbindd_domain *domain,
118 TALLOC_CTX *mem_ctx,
119 const struct dom_sid *sid,
120 char **domain_name,
121 char **name,
122 enum lsa_SidType *type)
124 NTSTATUS result;
126 result = ads_methods.sid_to_name(domain, mem_ctx, sid,
127 domain_name, name, type);
129 if (reconnect_need_retry(result, domain))
130 result = ads_methods.sid_to_name(domain, mem_ctx, sid,
131 domain_name, name, type);
133 return result;
136 static NTSTATUS rids_to_names(struct winbindd_domain *domain,
137 TALLOC_CTX *mem_ctx,
138 const struct dom_sid *sid,
139 uint32_t *rids,
140 size_t num_rids,
141 char **domain_name,
142 char ***names,
143 enum lsa_SidType **types)
145 NTSTATUS result;
147 result = ads_methods.rids_to_names(domain, mem_ctx, sid,
148 rids, num_rids,
149 domain_name, names, types);
150 if (reconnect_need_retry(result, domain)) {
151 result = ads_methods.rids_to_names(domain, mem_ctx, sid,
152 rids, num_rids, domain_name,
153 names, types);
156 return result;
159 /* Lookup user information from a rid or username. */
160 static NTSTATUS query_user(struct winbindd_domain *domain,
161 TALLOC_CTX *mem_ctx,
162 const struct dom_sid *user_sid,
163 struct wbint_userinfo *user_info)
165 NTSTATUS result;
167 result = ads_methods.query_user(domain, mem_ctx, user_sid, user_info);
169 if (reconnect_need_retry(result, domain)) {
170 result = ads_methods.query_user(domain, mem_ctx, user_sid,
171 user_info);
174 return result;
177 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
178 static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
179 TALLOC_CTX *mem_ctx,
180 const struct dom_sid *user_sid,
181 uint32_t *num_groups,
182 struct dom_sid **user_gids)
184 NTSTATUS result;
186 result = ads_methods.lookup_usergroups(domain, mem_ctx, user_sid,
187 num_groups, user_gids);
189 if (reconnect_need_retry(result, domain)) {
190 result = ads_methods.lookup_usergroups(domain, mem_ctx,
191 user_sid, num_groups,
192 user_gids);
195 return result;
198 static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
199 TALLOC_CTX *mem_ctx,
200 uint32_t num_sids,
201 const struct dom_sid *sids,
202 uint32_t *num_aliases, uint32_t **alias_rids)
204 NTSTATUS result;
206 result = ads_methods.lookup_useraliases(domain, mem_ctx, num_sids, sids,
207 num_aliases, alias_rids);
209 if (reconnect_need_retry(result, domain)) {
210 result = ads_methods.lookup_useraliases(domain, mem_ctx,
211 num_sids, sids,
212 num_aliases,
213 alias_rids);
216 return result;
219 /* Lookup group membership given a rid. */
220 static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
221 TALLOC_CTX *mem_ctx,
222 const struct dom_sid *group_sid,
223 enum lsa_SidType type,
224 uint32_t *num_names,
225 struct dom_sid **sid_mem, char ***names,
226 uint32_t **name_types)
228 NTSTATUS result;
230 result = ads_methods.lookup_groupmem(domain, mem_ctx, group_sid, type,
231 num_names, sid_mem, names,
232 name_types);
234 if (reconnect_need_retry(result, domain)) {
235 result = ads_methods.lookup_groupmem(domain, mem_ctx, group_sid,
236 type, num_names, sid_mem,
237 names, name_types);
240 return result;
243 /* find the sequence number for a domain */
244 static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32_t *seq)
246 NTSTATUS result;
248 result = ads_methods.sequence_number(domain, seq);
250 if (reconnect_need_retry(result, domain)) {
251 result = ads_methods.sequence_number(domain, seq);
254 return result;
257 /* find the lockout policy of a domain */
258 static NTSTATUS lockout_policy(struct winbindd_domain *domain,
259 TALLOC_CTX *mem_ctx,
260 struct samr_DomInfo12 *policy)
262 NTSTATUS result;
264 result = ads_methods.lockout_policy(domain, mem_ctx, policy);
266 if (reconnect_need_retry(result, domain)) {
267 result = ads_methods.lockout_policy(domain, mem_ctx, policy);
270 return result;
273 /* find the password policy of a domain */
274 static NTSTATUS password_policy(struct winbindd_domain *domain,
275 TALLOC_CTX *mem_ctx,
276 struct samr_DomInfo1 *policy)
278 NTSTATUS result;
280 result = ads_methods.password_policy(domain, mem_ctx, policy);
282 if (reconnect_need_retry(result, domain)) {
283 result = ads_methods.password_policy(domain, mem_ctx, policy);
286 return result;
289 /* get a list of trusted domains */
290 static NTSTATUS trusted_domains(struct winbindd_domain *domain,
291 TALLOC_CTX *mem_ctx,
292 struct netr_DomainTrustList *trusts)
294 NTSTATUS result;
296 result = ads_methods.trusted_domains(domain, mem_ctx, trusts);
298 if (reconnect_need_retry(result, domain)) {
299 result = ads_methods.trusted_domains(domain, mem_ctx, trusts);
302 return result;
305 /* the rpc backend methods are exposed via this structure */
306 struct winbindd_methods reconnect_ads_methods = {
307 true,
308 query_user_list,
309 enum_dom_groups,
310 enum_local_groups,
311 name_to_sid,
312 sid_to_name,
313 rids_to_names,
314 query_user,
315 lookup_usergroups,
316 lookup_useraliases,
317 lookup_groupmem,
318 sequence_number,
319 lockout_policy,
320 password_policy,
321 trusted_domains,
324 #endif