2 Unix SMB/CIFS implementation.
4 Winbind rpc backend functions
6 Copyright (C) Tim Potter 2000-2001,2003
7 Copyright (C) Simo Sorce 2003
8 Copyright (C) Volker Lendecke 2004
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 2 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, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define DBGC_CLASS DBGC_WINBIND
32 add_member(const char *domain
, const char *user
,
33 char **members
, int *num_members
)
37 fill_domain_username(name
, domain
, user
);
38 safe_strcat(name
, ",", sizeof(name
)-1);
39 string_append(members
, name
);
43 /**********************************************************************
44 Add member users resulting from sid. Expand if it is a domain group.
45 **********************************************************************/
48 add_expanded_sid(const DOM_SID
*sid
, char **members
, int *num_members
)
52 struct winbindd_domain
*domain
;
55 char *domain_name
= NULL
;
57 enum SID_NAME_USE type
;
66 TALLOC_CTX
*mem_ctx
= talloc_init("add_expanded_sid");
68 if (mem_ctx
== NULL
) {
69 DEBUG(1, ("talloc_init failed\n"));
73 sid_copy(&dom_sid
, sid
);
74 sid_split_rid(&dom_sid
, &rid
);
76 domain
= find_lookup_domain_from_sid(sid
);
79 DEBUG(3, ("Could not find domain for sid %s\n",
80 sid_string_static(sid
)));
84 result
= domain
->methods
->sid_to_name(domain
, mem_ctx
, sid
,
85 &domain_name
, &name
, &type
);
87 if (!NT_STATUS_IS_OK(result
)) {
88 DEBUG(3, ("sid_to_name failed for sid %s\n",
89 sid_string_static(sid
)));
93 DEBUG(10, ("Found name %s, type %d\n", name
, type
));
95 if (type
== SID_NAME_USER
) {
96 add_member(domain_name
, name
, members
, num_members
);
100 if (type
!= SID_NAME_DOM_GRP
) {
101 DEBUG(10, ("Alias member %s neither user nor group, ignore\n",
106 /* Expand the domain group, this must be done via the target domain */
108 domain
= find_domain_from_sid(sid
);
110 if (domain
== NULL
) {
111 DEBUG(3, ("Could not find domain from SID %s\n",
112 sid_string_static(sid
)));
116 result
= domain
->methods
->lookup_groupmem(domain
, mem_ctx
,
121 if (!NT_STATUS_IS_OK(result
)) {
122 DEBUG(10, ("Could not lookup group members for %s: %s\n",
123 name
, nt_errstr(result
)));
127 for (i
=0; i
<num_names
; i
++) {
128 DEBUG(10, ("Adding group member SID %s\n",
129 sid_string_static(sid_mem
[i
])));
131 if (types
[i
] != SID_NAME_USER
) {
132 DEBUG(1, ("Hmmm. Member %s of group %s is no user. "
133 "Ignoring.\n", names
[i
], name
));
137 add_member(domain
->name
, names
[i
], members
, num_members
);
141 talloc_destroy(mem_ctx
);
145 BOOL
fill_passdb_alias_grmem(struct winbindd_domain
*domain
,
147 int *num_gr_mem
, char **gr_mem
, int *gr_mem_len
)
156 if (!pdb_enum_aliasmem(group_sid
, &members
, &num_members
))
159 for (i
=0; i
<num_members
; i
++) {
160 add_expanded_sid(&members
[i
], gr_mem
, num_gr_mem
);
165 if (*gr_mem
!= NULL
) {
168 /* We have at least one member, strip off the last "," */
169 len
= strlen(*gr_mem
);
170 (*gr_mem
)[len
-1] = '\0';
177 /* Query display info for a domain. This returns enough information plus a
178 bit extra to give an overview of domain users for the User Manager
180 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
183 WINBIND_USERINFO
**info
)
185 /* We don't have users */
191 /* list all domain groups */
192 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
195 struct acct_info
**info
)
197 /* We don't have domain groups */
203 /* List all domain groups */
205 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
208 struct acct_info
**info
)
210 struct acct_info
*talloced_info
;
212 /* Hmm. One billion aliases should be enough for a start */
214 if (!pdb_enum_aliases(&domain
->sid
, 0, 1000000000,
215 num_entries
, info
)) {
216 /* Nothing to report, just exit. */
220 talloced_info
= (struct acct_info
*)
221 talloc_memdup(mem_ctx
, *info
,
222 *num_entries
* sizeof(struct acct_info
));
225 *info
= talloced_info
;
230 /* convert a single name to a sid in a domain */
231 static NTSTATUS
name_to_sid(struct winbindd_domain
*domain
,
233 const char *domain_name
,
236 enum SID_NAME_USE
*type
)
238 DEBUG(10, ("Finding name %s\n", name
));
240 if (!pdb_find_alias(name
, sid
))
241 return NT_STATUS_NONE_MAPPED
;
243 if (sid_check_is_in_builtin(sid
))
244 *type
= SID_NAME_WKN_GRP
;
246 *type
= SID_NAME_ALIAS
;
252 convert a domain SID to a user or group name
254 static NTSTATUS
sid_to_name(struct winbindd_domain
*domain
,
259 enum SID_NAME_USE
*type
)
261 struct acct_info info
;
263 DEBUG(10, ("Converting SID %s\n", sid_string_static(sid
)));
265 if (!pdb_get_aliasinfo(sid
, &info
))
266 return NT_STATUS_NONE_MAPPED
;
268 *domain_name
= talloc_strdup(mem_ctx
, domain
->name
);
269 *name
= talloc_strdup(mem_ctx
, info
.acct_name
);
270 if (sid_check_is_in_builtin(sid
))
271 *type
= SID_NAME_WKN_GRP
;
273 *type
= SID_NAME_ALIAS
;
278 /* Lookup user information from a rid or username. */
279 static NTSTATUS
query_user(struct winbindd_domain
*domain
,
281 const DOM_SID
*user_sid
,
282 WINBIND_USERINFO
*user_info
)
284 return NT_STATUS_NO_SUCH_USER
;
287 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
288 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
290 const DOM_SID
*user_sid
,
291 uint32
*num_groups
, DOM_SID
***user_gids
)
293 return NT_STATUS_NO_SUCH_USER
;
297 /* Lookup group membership given a rid. */
298 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
300 const DOM_SID
*group_sid
, uint32
*num_names
,
301 DOM_SID
***sid_mem
, char ***names
,
307 /* find the sequence number for a domain */
308 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
314 /* get a list of trusted domains */
315 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
332 nt_status
= secrets_get_trusted_domains(mem_ctx
, &enum_ctx
, 1,
335 *names
= talloc_realloc(mem_ctx
, *names
,
337 (num_sec_domains
+ *num_domains
));
338 *alt_names
= talloc_realloc(mem_ctx
, *alt_names
,
340 (num_sec_domains
+ *num_domains
));
341 *dom_sids
= talloc_realloc(mem_ctx
, *dom_sids
,
343 (num_sec_domains
+ *num_domains
));
345 for (i
=0; i
< num_sec_domains
; i
++) {
346 if (pull_ucs2_talloc(mem_ctx
, &(*names
)[*num_domains
],
347 domains
[i
]->name
) == -1) {
348 return NT_STATUS_NO_MEMORY
;
350 (*alt_names
)[*num_domains
] = NULL
;
351 (*dom_sids
)[*num_domains
] = domains
[i
]->sid
;
355 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
357 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
363 /* find the domain sid for a domain */
364 static NTSTATUS
domain_sid(struct winbindd_domain
*domain
, DOM_SID
*sid
)
366 sid_copy(sid
, &domain
->sid
);
370 /* find alternate names list for the domain
371 * should we look for netbios aliases??
373 static NTSTATUS
alternate_name(struct winbindd_domain
*domain
)
375 DEBUG(3,("pdb: alternate_name\n"));
381 /* the rpc backend methods are exposed via this structure */
382 struct winbindd_methods passdb_methods
= {