s4:kdc: remove unused sdb_entry_ex_to_hdb_entry_ex()
[Samba.git] / source3 / winbindd / winbindd_reconnect.c
blob508ac756561b749fc4eab658d30be1d5a1079318
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 const char **pdom_name,
135 struct dom_sid *sid,
136 enum lsa_SidType *type)
138 NTSTATUS result;
140 result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
141 flags, pdom_name, sid, type);
143 if (reconnect_need_retry(result, domain))
144 result = msrpc_methods.name_to_sid(domain, mem_ctx,
145 domain_name, name, flags,
146 pdom_name, sid, type);
148 return result;
152 convert a domain SID to a user or group name
154 static NTSTATUS sid_to_name(struct winbindd_domain *domain,
155 TALLOC_CTX *mem_ctx,
156 const struct dom_sid *sid,
157 char **domain_name,
158 char **name,
159 enum lsa_SidType *type)
161 NTSTATUS result;
163 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
164 domain_name, name, type);
166 if (reconnect_need_retry(result, domain))
167 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
168 domain_name, name, type);
170 return result;
173 static NTSTATUS rids_to_names(struct winbindd_domain *domain,
174 TALLOC_CTX *mem_ctx,
175 const struct dom_sid *sid,
176 uint32_t *rids,
177 size_t num_rids,
178 char **domain_name,
179 char ***names,
180 enum lsa_SidType **types)
182 NTSTATUS result;
184 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
185 rids, num_rids,
186 domain_name, names, types);
187 if (reconnect_need_retry(result, domain)) {
188 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
189 rids, num_rids,
190 domain_name, names,
191 types);
194 return result;
197 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
198 static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
199 TALLOC_CTX *mem_ctx,
200 const struct dom_sid *user_sid,
201 uint32_t *num_groups, struct dom_sid **user_gids)
203 NTSTATUS result;
205 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
206 user_sid, num_groups,
207 user_gids);
209 if (reconnect_need_retry(result, domain))
210 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
211 user_sid, num_groups,
212 user_gids);
214 return result;
217 static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
218 TALLOC_CTX *mem_ctx,
219 uint32_t num_sids, const struct dom_sid *sids,
220 uint32_t *num_aliases, uint32_t **alias_rids)
222 NTSTATUS result;
224 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
225 num_sids, sids,
226 num_aliases,
227 alias_rids);
229 if (reconnect_need_retry(result, domain))
230 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
231 num_sids, sids,
232 num_aliases,
233 alias_rids);
235 return result;
238 /* Lookup group membership given a rid. */
239 static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
240 TALLOC_CTX *mem_ctx,
241 const struct dom_sid *group_sid,
242 enum lsa_SidType type,
243 uint32_t *num_names,
244 struct dom_sid **sid_mem, char ***names,
245 uint32_t **name_types)
247 NTSTATUS result;
249 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
250 group_sid, type, num_names,
251 sid_mem, names,
252 name_types);
254 if (reconnect_need_retry(result, domain))
255 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
256 group_sid, type,
257 num_names,
258 sid_mem, names,
259 name_types);
261 return result;
264 /* find the lockout policy of a domain */
265 static NTSTATUS lockout_policy(struct winbindd_domain *domain,
266 TALLOC_CTX *mem_ctx,
267 struct samr_DomInfo12 *policy)
269 NTSTATUS result;
271 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
273 if (reconnect_need_retry(result, domain))
274 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
276 return result;
279 /* find the password policy of a domain */
280 static NTSTATUS password_policy(struct winbindd_domain *domain,
281 TALLOC_CTX *mem_ctx,
282 struct samr_DomInfo1 *policy)
284 NTSTATUS result;
286 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
288 if (reconnect_need_retry(result, domain))
289 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
291 return result;
294 /* get a list of trusted domains */
295 static NTSTATUS trusted_domains(struct winbindd_domain *domain,
296 TALLOC_CTX *mem_ctx,
297 struct netr_DomainTrustList *trusts)
299 NTSTATUS result;
301 result = msrpc_methods.trusted_domains(domain, mem_ctx, trusts);
303 if (reconnect_need_retry(result, domain))
304 result = msrpc_methods.trusted_domains(domain, mem_ctx,
305 trusts);
307 return result;
310 /* the rpc backend methods are exposed via this structure */
311 struct winbindd_methods reconnect_methods = {
312 False,
313 query_user_list,
314 enum_dom_groups,
315 enum_local_groups,
316 name_to_sid,
317 sid_to_name,
318 rids_to_names,
319 lookup_usergroups,
320 lookup_useraliases,
321 lookup_groupmem,
322 lockout_policy,
323 password_policy,
324 trusted_domains,