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/>.
26 #define DBGC_CLASS DBGC_WINBIND
28 extern struct winbindd_methods msrpc_methods;
30 static bool reconnect_need_retry(NTSTATUS status,
31 struct winbindd_domain *domain)
33 if (NT_STATUS_IS_OK(status)) {
37 if (!NT_STATUS_IS_ERR(status)) {
41 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
45 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
49 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_GROUP)) {
53 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_ALIAS)) {
57 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_MEMBER)) {
61 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_DOMAIN)) {
65 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_PRIVILEGE)) {
69 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) {
73 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_DEVICE_ERROR)) {
75 * RPC call sent on expired session, needs
78 invalidate_cm_connection(domain);
85 static NTSTATUS query_user_list(struct winbindd_domain *domain,
87 uint32_t *num_entries,
88 struct wbint_userinfo **info)
92 result = msrpc_methods.query_user_list(domain, mem_ctx,
95 if (reconnect_need_retry(result, domain))
96 result = msrpc_methods.query_user_list(domain, mem_ctx,
101 /* list all domain groups */
102 static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
104 uint32_t *num_entries,
105 struct wb_acct_info **info)
109 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
112 if (reconnect_need_retry(result, domain))
113 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
118 /* List all domain groups */
120 static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
122 uint32_t *num_entries,
123 struct wb_acct_info **info)
127 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
130 if (reconnect_need_retry(result, domain))
131 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
137 /* convert a single name to a sid in a domain */
138 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
140 const char *domain_name,
144 enum lsa_SidType *type)
148 result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
151 if (reconnect_need_retry(result, domain))
152 result = msrpc_methods.name_to_sid(domain, mem_ctx,
153 domain_name, name, flags,
160 convert a domain SID to a user or group name
162 static NTSTATUS sid_to_name(struct winbindd_domain *domain,
164 const struct dom_sid *sid,
167 enum lsa_SidType *type)
171 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
172 domain_name, name, type);
174 if (reconnect_need_retry(result, domain))
175 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
176 domain_name, name, type);
181 static NTSTATUS rids_to_names(struct winbindd_domain *domain,
183 const struct dom_sid *sid,
188 enum lsa_SidType **types)
192 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
194 domain_name, names, types);
195 if (reconnect_need_retry(result, domain)) {
196 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
205 /* Lookup user information from a rid or username. */
206 static NTSTATUS query_user(struct winbindd_domain *domain,
208 const struct dom_sid *user_sid,
209 struct wbint_userinfo *user_info)
213 result = msrpc_methods.query_user(domain, mem_ctx, user_sid,
216 if (reconnect_need_retry(result, domain))
217 result = msrpc_methods.query_user(domain, mem_ctx, user_sid,
223 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
224 static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
226 const struct dom_sid *user_sid,
227 uint32_t *num_groups, struct dom_sid **user_gids)
231 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
232 user_sid, num_groups,
235 if (reconnect_need_retry(result, domain))
236 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
237 user_sid, num_groups,
243 static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
245 uint32_t num_sids, const struct dom_sid *sids,
246 uint32_t *num_aliases, uint32_t **alias_rids)
250 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
255 if (reconnect_need_retry(result, domain))
256 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
264 /* Lookup group membership given a rid. */
265 static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
267 const struct dom_sid *group_sid,
268 enum lsa_SidType type,
270 struct dom_sid **sid_mem, char ***names,
271 uint32_t **name_types)
275 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
276 group_sid, type, num_names,
280 if (reconnect_need_retry(result, domain))
281 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
290 /* find the sequence number for a domain */
291 static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32_t *seq)
295 result = msrpc_methods.sequence_number(domain, seq);
297 if (reconnect_need_retry(result, domain))
298 result = msrpc_methods.sequence_number(domain, seq);
303 /* find the lockout policy of a domain */
304 static NTSTATUS lockout_policy(struct winbindd_domain *domain,
306 struct samr_DomInfo12 *policy)
310 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
312 if (reconnect_need_retry(result, domain))
313 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
318 /* find the password policy of a domain */
319 static NTSTATUS password_policy(struct winbindd_domain *domain,
321 struct samr_DomInfo1 *policy)
325 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
327 if (reconnect_need_retry(result, domain))
328 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
333 /* get a list of trusted domains */
334 static NTSTATUS trusted_domains(struct winbindd_domain *domain,
336 struct netr_DomainTrustList *trusts)
340 result = msrpc_methods.trusted_domains(domain, mem_ctx, trusts);
342 if (reconnect_need_retry(result, domain))
343 result = msrpc_methods.trusted_domains(domain, mem_ctx,
349 /* the rpc backend methods are exposed via this structure */
350 struct winbindd_methods reconnect_methods = {