Revert "s3/service: convert lp_force_group() to const"
[Samba.git] / source3 / winbindd / winbindd_reconnect.c
blob1d0e8e6d472aa72377acc7340c3f9752409b2bdf
1 /*
2 Unix SMB/CIFS implementation.
4 Wrapper around winbindd_rpc.c to centralize retry logic.
6 Copyright (C) Volker Lendecke 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "winbindd.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_WINBIND
28 extern struct winbindd_methods msrpc_methods;
30 bool reconnect_need_retry(NTSTATUS status, struct winbindd_domain *domain)
32 if (NT_STATUS_IS_OK(status)) {
33 return false;
36 if (!NT_STATUS_IS_ERR(status)) {
37 return false;
40 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
41 return false;
44 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
45 return false;
48 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_GROUP)) {
49 return false;
52 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_ALIAS)) {
53 return false;
56 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_MEMBER)) {
57 return false;
60 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_DOMAIN)) {
61 return false;
64 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_PRIVILEGE)) {
65 return false;
68 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) {
69 return false;
72 reset_cm_connection_on_error(domain, NULL, status);
74 return true;
77 /* List all users */
78 static NTSTATUS query_user_list(struct winbindd_domain *domain,
79 TALLOC_CTX *mem_ctx,
80 uint32_t **rids)
82 NTSTATUS result;
84 result = msrpc_methods.query_user_list(domain, mem_ctx, rids);
86 if (reconnect_need_retry(result, domain))
87 result = msrpc_methods.query_user_list(domain, mem_ctx, rids);
89 return result;
92 /* list all domain groups */
93 static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
94 TALLOC_CTX *mem_ctx,
95 uint32_t *num_entries,
96 struct wb_acct_info **info)
98 NTSTATUS result;
100 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
101 num_entries, info);
103 if (reconnect_need_retry(result, domain))
104 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
105 num_entries, info);
106 return result;
109 /* List all domain groups */
111 static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
112 TALLOC_CTX *mem_ctx,
113 uint32_t *num_entries,
114 struct wb_acct_info **info)
116 NTSTATUS result;
118 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
119 num_entries, info);
121 if (reconnect_need_retry(result, domain))
122 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
123 num_entries, info);
125 return result;
128 /* convert a single name to a sid in a domain */
129 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
130 TALLOC_CTX *mem_ctx,
131 const char *domain_name,
132 const char *name,
133 uint32_t flags,
134 struct dom_sid *sid,
135 enum lsa_SidType *type)
137 NTSTATUS result;
139 result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
140 flags, sid, type);
142 if (reconnect_need_retry(result, domain))
143 result = msrpc_methods.name_to_sid(domain, mem_ctx,
144 domain_name, name, flags,
145 sid, type);
147 return result;
151 convert a domain SID to a user or group name
153 static NTSTATUS sid_to_name(struct winbindd_domain *domain,
154 TALLOC_CTX *mem_ctx,
155 const struct dom_sid *sid,
156 char **domain_name,
157 char **name,
158 enum lsa_SidType *type)
160 NTSTATUS result;
162 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
163 domain_name, name, type);
165 if (reconnect_need_retry(result, domain))
166 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
167 domain_name, name, type);
169 return result;
172 static NTSTATUS rids_to_names(struct winbindd_domain *domain,
173 TALLOC_CTX *mem_ctx,
174 const struct dom_sid *sid,
175 uint32_t *rids,
176 size_t num_rids,
177 char **domain_name,
178 char ***names,
179 enum lsa_SidType **types)
181 NTSTATUS result;
183 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
184 rids, num_rids,
185 domain_name, names, types);
186 if (reconnect_need_retry(result, domain)) {
187 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
188 rids, num_rids,
189 domain_name, names,
190 types);
193 return result;
196 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
197 static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
198 TALLOC_CTX *mem_ctx,
199 const struct dom_sid *user_sid,
200 uint32_t *num_groups, struct dom_sid **user_gids)
202 NTSTATUS result;
204 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
205 user_sid, num_groups,
206 user_gids);
208 if (reconnect_need_retry(result, domain))
209 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
210 user_sid, num_groups,
211 user_gids);
213 return result;
216 static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
217 TALLOC_CTX *mem_ctx,
218 uint32_t num_sids, const struct dom_sid *sids,
219 uint32_t *num_aliases, uint32_t **alias_rids)
221 NTSTATUS result;
223 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
224 num_sids, sids,
225 num_aliases,
226 alias_rids);
228 if (reconnect_need_retry(result, domain))
229 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
230 num_sids, sids,
231 num_aliases,
232 alias_rids);
234 return result;
237 /* Lookup group membership given a rid. */
238 static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
239 TALLOC_CTX *mem_ctx,
240 const struct dom_sid *group_sid,
241 enum lsa_SidType type,
242 uint32_t *num_names,
243 struct dom_sid **sid_mem, char ***names,
244 uint32_t **name_types)
246 NTSTATUS result;
248 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
249 group_sid, type, num_names,
250 sid_mem, names,
251 name_types);
253 if (reconnect_need_retry(result, domain))
254 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
255 group_sid, type,
256 num_names,
257 sid_mem, names,
258 name_types);
260 return result;
263 /* find the sequence number for a domain */
264 static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32_t *seq)
266 NTSTATUS result;
268 result = msrpc_methods.sequence_number(domain, seq);
270 if (reconnect_need_retry(result, domain))
271 result = msrpc_methods.sequence_number(domain, seq);
273 return result;
276 /* find the lockout policy of a domain */
277 static NTSTATUS lockout_policy(struct winbindd_domain *domain,
278 TALLOC_CTX *mem_ctx,
279 struct samr_DomInfo12 *policy)
281 NTSTATUS result;
283 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
285 if (reconnect_need_retry(result, domain))
286 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
288 return result;
291 /* find the password policy of a domain */
292 static NTSTATUS password_policy(struct winbindd_domain *domain,
293 TALLOC_CTX *mem_ctx,
294 struct samr_DomInfo1 *policy)
296 NTSTATUS result;
298 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
300 if (reconnect_need_retry(result, domain))
301 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
303 return result;
306 /* get a list of trusted domains */
307 static NTSTATUS trusted_domains(struct winbindd_domain *domain,
308 TALLOC_CTX *mem_ctx,
309 struct netr_DomainTrustList *trusts)
311 NTSTATUS result;
313 result = msrpc_methods.trusted_domains(domain, mem_ctx, trusts);
315 if (reconnect_need_retry(result, domain))
316 result = msrpc_methods.trusted_domains(domain, mem_ctx,
317 trusts);
319 return result;
322 /* the rpc backend methods are exposed via this structure */
323 struct winbindd_methods reconnect_methods = {
324 False,
325 query_user_list,
326 enum_dom_groups,
327 enum_local_groups,
328 name_to_sid,
329 sid_to_name,
330 rids_to_names,
331 lookup_usergroups,
332 lookup_useraliases,
333 lookup_groupmem,
334 sequence_number,
335 lockout_policy,
336 password_policy,
337 trusted_domains,