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 bool reconnect_need_retry(NTSTATUS status, struct winbindd_domain *domain)
32 if (NT_STATUS_IS_OK(status)) {
36 if (!NT_STATUS_IS_ERR(status)) {
40 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
44 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
48 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_GROUP)) {
52 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_ALIAS)) {
56 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_MEMBER)) {
60 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_DOMAIN)) {
64 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_PRIVILEGE)) {
68 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) {
72 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_DEVICE_ERROR)) {
74 * RPC call sent on expired session, needs
77 invalidate_cm_connection(domain);
84 static NTSTATUS query_user_list(struct winbindd_domain *domain,
90 result = msrpc_methods.query_user_list(domain, mem_ctx, rids);
92 if (reconnect_need_retry(result, domain))
93 result = msrpc_methods.query_user_list(domain, mem_ctx, rids);
98 /* list all domain groups */
99 static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
101 uint32_t *num_entries,
102 struct wb_acct_info **info)
106 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
109 if (reconnect_need_retry(result, domain))
110 result = msrpc_methods.enum_dom_groups(domain, mem_ctx,
115 /* List all domain groups */
117 static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
119 uint32_t *num_entries,
120 struct wb_acct_info **info)
124 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
127 if (reconnect_need_retry(result, domain))
128 result = msrpc_methods.enum_local_groups(domain, mem_ctx,
134 /* convert a single name to a sid in a domain */
135 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
137 const char *domain_name,
141 enum lsa_SidType *type)
145 result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
148 if (reconnect_need_retry(result, domain))
149 result = msrpc_methods.name_to_sid(domain, mem_ctx,
150 domain_name, name, flags,
157 convert a domain SID to a user or group name
159 static NTSTATUS sid_to_name(struct winbindd_domain *domain,
161 const struct dom_sid *sid,
164 enum lsa_SidType *type)
168 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
169 domain_name, name, type);
171 if (reconnect_need_retry(result, domain))
172 result = msrpc_methods.sid_to_name(domain, mem_ctx, sid,
173 domain_name, name, type);
178 static NTSTATUS rids_to_names(struct winbindd_domain *domain,
180 const struct dom_sid *sid,
185 enum lsa_SidType **types)
189 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
191 domain_name, names, types);
192 if (reconnect_need_retry(result, domain)) {
193 result = msrpc_methods.rids_to_names(domain, mem_ctx, sid,
202 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
203 static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
205 const struct dom_sid *user_sid,
206 uint32_t *num_groups, struct dom_sid **user_gids)
210 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
211 user_sid, num_groups,
214 if (reconnect_need_retry(result, domain))
215 result = msrpc_methods.lookup_usergroups(domain, mem_ctx,
216 user_sid, num_groups,
222 static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
224 uint32_t num_sids, const struct dom_sid *sids,
225 uint32_t *num_aliases, uint32_t **alias_rids)
229 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
234 if (reconnect_need_retry(result, domain))
235 result = msrpc_methods.lookup_useraliases(domain, mem_ctx,
243 /* Lookup group membership given a rid. */
244 static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
246 const struct dom_sid *group_sid,
247 enum lsa_SidType type,
249 struct dom_sid **sid_mem, char ***names,
250 uint32_t **name_types)
254 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
255 group_sid, type, num_names,
259 if (reconnect_need_retry(result, domain))
260 result = msrpc_methods.lookup_groupmem(domain, mem_ctx,
269 /* find the sequence number for a domain */
270 static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32_t *seq)
274 result = msrpc_methods.sequence_number(domain, seq);
276 if (reconnect_need_retry(result, domain))
277 result = msrpc_methods.sequence_number(domain, seq);
282 /* find the lockout policy of a domain */
283 static NTSTATUS lockout_policy(struct winbindd_domain *domain,
285 struct samr_DomInfo12 *policy)
289 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
291 if (reconnect_need_retry(result, domain))
292 result = msrpc_methods.lockout_policy(domain, mem_ctx, policy);
297 /* find the password policy of a domain */
298 static NTSTATUS password_policy(struct winbindd_domain *domain,
300 struct samr_DomInfo1 *policy)
304 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
306 if (reconnect_need_retry(result, domain))
307 result = msrpc_methods.password_policy(domain, mem_ctx, policy);
312 /* get a list of trusted domains */
313 static NTSTATUS trusted_domains(struct winbindd_domain *domain,
315 struct netr_DomainTrustList *trusts)
319 result = msrpc_methods.trusted_domains(domain, mem_ctx, trusts);
321 if (reconnect_need_retry(result, domain))
322 result = msrpc_methods.trusted_domains(domain, mem_ctx,
328 /* the rpc backend methods are exposed via this structure */
329 struct winbindd_methods reconnect_methods = {