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
)
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
)) {
76 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
79 WINBIND_USERINFO
**info
)
83 result
= msrpc_methods
.query_user_list(domain
, mem_ctx
,
86 if (reconnect_need_retry(result
))
87 result
= msrpc_methods
.query_user_list(domain
, mem_ctx
,
92 /* list all domain groups */
93 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
96 struct acct_info
**info
)
100 result
= msrpc_methods
.enum_dom_groups(domain
, mem_ctx
,
103 if (reconnect_need_retry(result
))
104 result
= msrpc_methods
.enum_dom_groups(domain
, mem_ctx
,
109 /* List all domain groups */
111 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
114 struct acct_info
**info
)
118 result
= msrpc_methods
.enum_local_groups(domain
, mem_ctx
,
121 if (reconnect_need_retry(result
))
122 result
= msrpc_methods
.enum_local_groups(domain
, mem_ctx
,
128 /* convert a single name to a sid in a domain */
129 static NTSTATUS
name_to_sid(struct winbindd_domain
*domain
,
131 enum winbindd_cmd orig_cmd
,
132 const char *domain_name
,
135 enum lsa_SidType
*type
)
139 result
= msrpc_methods
.name_to_sid(domain
, mem_ctx
, orig_cmd
,
143 if (reconnect_need_retry(result
))
144 result
= msrpc_methods
.name_to_sid(domain
, mem_ctx
, orig_cmd
,
152 convert a domain SID to a user or group name
154 static NTSTATUS
sid_to_name(struct winbindd_domain
*domain
,
159 enum lsa_SidType
*type
)
163 result
= msrpc_methods
.sid_to_name(domain
, mem_ctx
, sid
,
164 domain_name
, name
, type
);
166 if (reconnect_need_retry(result
))
167 result
= msrpc_methods
.sid_to_name(domain
, mem_ctx
, sid
,
168 domain_name
, name
, type
);
173 static NTSTATUS
rids_to_names(struct winbindd_domain
*domain
,
180 enum lsa_SidType
**types
)
184 result
= msrpc_methods
.rids_to_names(domain
, mem_ctx
, sid
,
186 domain_name
, names
, types
);
187 if (reconnect_need_retry(result
)) {
188 result
= msrpc_methods
.rids_to_names(domain
, mem_ctx
, sid
,
197 /* Lookup user information from a rid or username. */
198 static NTSTATUS
query_user(struct winbindd_domain
*domain
,
200 const DOM_SID
*user_sid
,
201 WINBIND_USERINFO
*user_info
)
205 result
= msrpc_methods
.query_user(domain
, mem_ctx
, user_sid
,
208 if (reconnect_need_retry(result
))
209 result
= msrpc_methods
.query_user(domain
, mem_ctx
, user_sid
,
215 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
216 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
218 const DOM_SID
*user_sid
,
219 uint32
*num_groups
, DOM_SID
**user_gids
)
223 result
= msrpc_methods
.lookup_usergroups(domain
, mem_ctx
,
224 user_sid
, num_groups
,
227 if (reconnect_need_retry(result
))
228 result
= msrpc_methods
.lookup_usergroups(domain
, mem_ctx
,
229 user_sid
, num_groups
,
235 static NTSTATUS
lookup_useraliases(struct winbindd_domain
*domain
,
237 uint32 num_sids
, const DOM_SID
*sids
,
238 uint32
*num_aliases
, uint32
**alias_rids
)
242 result
= msrpc_methods
.lookup_useraliases(domain
, mem_ctx
,
247 if (reconnect_need_retry(result
))
248 result
= msrpc_methods
.lookup_useraliases(domain
, mem_ctx
,
256 /* Lookup group membership given a rid. */
257 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
259 const DOM_SID
*group_sid
, uint32
*num_names
,
260 DOM_SID
**sid_mem
, char ***names
,
265 result
= msrpc_methods
.lookup_groupmem(domain
, mem_ctx
,
266 group_sid
, num_names
,
270 if (reconnect_need_retry(result
))
271 result
= msrpc_methods
.lookup_groupmem(domain
, mem_ctx
,
272 group_sid
, num_names
,
279 /* find the sequence number for a domain */
280 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
284 result
= msrpc_methods
.sequence_number(domain
, seq
);
286 if (reconnect_need_retry(result
))
287 result
= msrpc_methods
.sequence_number(domain
, seq
);
292 /* find the lockout policy of a domain */
293 static NTSTATUS
lockout_policy(struct winbindd_domain
*domain
,
295 struct samr_DomInfo12
*policy
)
299 result
= msrpc_methods
.lockout_policy(domain
, mem_ctx
, policy
);
301 if (reconnect_need_retry(result
))
302 result
= msrpc_methods
.lockout_policy(domain
, mem_ctx
, policy
);
307 /* find the password policy of a domain */
308 static NTSTATUS
password_policy(struct winbindd_domain
*domain
,
310 struct samr_DomInfo1
*policy
)
314 result
= msrpc_methods
.password_policy(domain
, mem_ctx
, policy
);
316 if (reconnect_need_retry(result
))
317 result
= msrpc_methods
.password_policy(domain
, mem_ctx
, policy
);
322 /* get a list of trusted domains */
323 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
332 result
= msrpc_methods
.trusted_domains(domain
, mem_ctx
,
334 alt_names
, dom_sids
);
336 if (reconnect_need_retry(result
))
337 result
= msrpc_methods
.trusted_domains(domain
, mem_ctx
,
339 alt_names
, dom_sids
);
344 /* the rpc backend methods are exposed via this structure */
345 struct winbindd_methods reconnect_methods
= {