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/>.
30 #define DBGC_CLASS DBGC_WINBIND
32 extern struct winbindd_methods ads_methods
;
34 static bool ldap_reconnect_need_retry(NTSTATUS status
,
35 struct winbindd_domain
*domain
)
37 if (NT_STATUS_IS_OK(status
)) {
41 if (!NT_STATUS_IS_ERR(status
)) {
45 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
49 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
53 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_GROUP
)) {
57 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_ALIAS
)) {
61 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_MEMBER
)) {
65 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_DOMAIN
)) {
69 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_PRIVILEGE
)) {
73 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MEMORY
)) {
81 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
87 result
= ads_methods
.query_user_list(domain
, mem_ctx
, rids
);
89 if (ldap_reconnect_need_retry(result
, domain
)) {
90 result
= ads_methods
.query_user_list(domain
, mem_ctx
, rids
);
96 /* list all domain groups */
97 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
99 uint32_t *num_entries
,
100 struct wb_acct_info
**info
)
104 result
= ads_methods
.enum_dom_groups(domain
, mem_ctx
,
107 if (ldap_reconnect_need_retry(result
, domain
)) {
108 result
= ads_methods
.enum_dom_groups(domain
, mem_ctx
,
115 /* List all domain groups */
116 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
118 uint32_t *num_entries
,
119 struct wb_acct_info
**info
)
123 result
= ads_methods
.enum_local_groups(domain
, mem_ctx
,
126 if (ldap_reconnect_need_retry(result
, domain
)) {
127 result
= ads_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
,
140 const char **pdom_name
,
142 enum lsa_SidType
*type
)
146 result
= ads_methods
.name_to_sid(domain
, mem_ctx
, domain_name
, name
,
147 flags
, pdom_name
, sid
, type
);
149 if (reconnect_need_retry(result
, domain
)) {
150 result
= ads_methods
.name_to_sid(domain
, mem_ctx
,
151 domain_name
, name
, flags
,
152 pdom_name
, sid
, type
);
159 convert a domain SID to a user or group name
161 static NTSTATUS
sid_to_name(struct winbindd_domain
*domain
,
163 const struct dom_sid
*sid
,
166 enum lsa_SidType
*type
)
170 result
= ads_methods
.sid_to_name(domain
, mem_ctx
, sid
,
171 domain_name
, name
, type
);
173 if (reconnect_need_retry(result
, domain
))
174 result
= ads_methods
.sid_to_name(domain
, mem_ctx
, sid
,
175 domain_name
, name
, type
);
180 static NTSTATUS
rids_to_names(struct winbindd_domain
*domain
,
182 const struct dom_sid
*sid
,
187 enum lsa_SidType
**types
)
191 result
= ads_methods
.rids_to_names(domain
, mem_ctx
, sid
,
193 domain_name
, names
, types
);
194 if (reconnect_need_retry(result
, domain
)) {
195 result
= ads_methods
.rids_to_names(domain
, mem_ctx
, sid
,
196 rids
, num_rids
, domain_name
,
203 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
204 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
206 const struct dom_sid
*user_sid
,
207 uint32_t *num_groups
,
208 struct dom_sid
**user_gids
)
212 result
= ads_methods
.lookup_usergroups(domain
, mem_ctx
, user_sid
,
213 num_groups
, user_gids
);
215 if (ldap_reconnect_need_retry(result
, domain
)) {
216 result
= ads_methods
.lookup_usergroups(domain
, mem_ctx
,
217 user_sid
, num_groups
,
224 static NTSTATUS
lookup_useraliases(struct winbindd_domain
*domain
,
227 const struct dom_sid
*sids
,
228 uint32_t *num_aliases
, uint32_t **alias_rids
)
232 result
= ads_methods
.lookup_useraliases(domain
, mem_ctx
, num_sids
, sids
,
233 num_aliases
, alias_rids
);
235 if (reconnect_need_retry(result
, domain
)) {
236 result
= ads_methods
.lookup_useraliases(domain
, mem_ctx
,
245 /* Lookup group membership given a rid. */
246 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
248 const struct dom_sid
*group_sid
,
249 enum lsa_SidType type
,
251 struct dom_sid
**sid_mem
, char ***names
,
252 uint32_t **name_types
)
256 result
= ads_methods
.lookup_groupmem(domain
, mem_ctx
, group_sid
, type
,
257 num_names
, sid_mem
, names
,
260 if (ldap_reconnect_need_retry(result
, domain
)) {
261 result
= ads_methods
.lookup_groupmem(domain
, mem_ctx
, group_sid
,
262 type
, num_names
, sid_mem
,
269 /* find the sequence number for a domain */
270 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32_t *seq
)
274 result
= ads_methods
.sequence_number(domain
, seq
);
276 if (ldap_reconnect_need_retry(result
, domain
)) {
277 result
= ads_methods
.sequence_number(domain
, seq
);
283 /* find the lockout policy of a domain */
284 static NTSTATUS
lockout_policy(struct winbindd_domain
*domain
,
286 struct samr_DomInfo12
*policy
)
290 result
= ads_methods
.lockout_policy(domain
, mem_ctx
, policy
);
292 if (reconnect_need_retry(result
, domain
)) {
293 result
= ads_methods
.lockout_policy(domain
, mem_ctx
, policy
);
299 /* find the password policy of a domain */
300 static NTSTATUS
password_policy(struct winbindd_domain
*domain
,
302 struct samr_DomInfo1
*policy
)
306 result
= ads_methods
.password_policy(domain
, mem_ctx
, policy
);
308 if (reconnect_need_retry(result
, domain
)) {
309 result
= ads_methods
.password_policy(domain
, mem_ctx
, policy
);
315 /* get a list of trusted domains */
316 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
318 struct netr_DomainTrustList
*trusts
)
322 result
= ads_methods
.trusted_domains(domain
, mem_ctx
, trusts
);
324 if (reconnect_need_retry(result
, domain
)) {
325 result
= ads_methods
.trusted_domains(domain
, mem_ctx
, trusts
);
331 /* the rpc backend methods are exposed via this structure */
332 struct winbindd_methods reconnect_ads_methods
= {