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
;
56 enum SID_NAME_USE type
;
65 TALLOC_CTX
*mem_ctx
= talloc_init("add_expanded_sid");
67 if (mem_ctx
== NULL
) {
68 DEBUG(1, ("talloc_init failed\n"));
72 sid_copy(&dom_sid
, sid
);
73 sid_split_rid(&dom_sid
, &rid
);
75 domain
= find_domain_from_sid(&dom_sid
);
78 DEBUG(3, ("Could not find domain for sid %s\n",
79 sid_string_static(sid
)));
83 result
= domain
->methods
->sid_to_name(domain
, mem_ctx
, sid
,
86 if (!NT_STATUS_IS_OK(result
)) {
87 DEBUG(3, ("sid_to_name failed for sid %s\n",
88 sid_string_static(sid
)));
92 DEBUG(10, ("Found name %s, type %d\n", name
, type
));
94 if (type
== SID_NAME_USER
) {
95 add_member(domain
->name
, name
, members
, num_members
);
99 if (type
!= SID_NAME_DOM_GRP
) {
100 DEBUG(10, ("Alias member %s neither user nor group, ignore\n",
105 /* Expand the domain group */
107 result
= domain
->methods
->lookup_groupmem(domain
, mem_ctx
,
112 if (!NT_STATUS_IS_OK(result
)) {
113 DEBUG(10, ("Could not lookup group members for %s: %s\n",
114 name
, nt_errstr(result
)));
118 for (i
=0; i
<num_names
; i
++) {
119 DEBUG(10, ("Adding group member SID %s\n",
120 sid_string_static(sid_mem
[i
])));
122 if (types
[i
] != SID_NAME_USER
) {
123 DEBUG(1, ("Hmmm. Member %s of group %s is no user. "
124 "Ignoring.\n", names
[i
], name
));
128 add_member(domain
->name
, names
[i
], members
, num_members
);
132 talloc_destroy(mem_ctx
);
136 BOOL
fill_passdb_alias_grmem(struct winbindd_domain
*domain
,
138 int *num_gr_mem
, char **gr_mem
, int *gr_mem_len
)
147 if (!pdb_enum_aliasmem(group_sid
, &members
, &num_members
))
150 for (i
=0; i
<num_members
; i
++) {
151 add_expanded_sid(&members
[i
], gr_mem
, num_gr_mem
);
156 if (*gr_mem
!= NULL
) {
159 /* We have at least one member, strip off the last "," */
160 len
= strlen(*gr_mem
);
161 (*gr_mem
)[len
-1] = '\0';
168 /* Query display info for a domain. This returns enough information plus a
169 bit extra to give an overview of domain users for the User Manager
171 static NTSTATUS
query_user_list(struct winbindd_domain
*domain
,
174 WINBIND_USERINFO
**info
)
176 /* We don't have users */
182 /* list all domain groups */
183 static NTSTATUS
enum_dom_groups(struct winbindd_domain
*domain
,
186 struct acct_info
**info
)
188 /* We don't have domain groups */
194 /* List all domain groups */
196 static NTSTATUS
enum_local_groups(struct winbindd_domain
*domain
,
199 struct acct_info
**info
)
201 struct acct_info
*talloced_info
;
203 /* Hmm. One billion aliases should be enough for a start */
205 if (!pdb_enum_aliases(&domain
->sid
, 0, 1000000000,
206 num_entries
, info
)) {
207 /* Nothing to report, just exit. */
211 talloced_info
= (struct acct_info
*)
212 talloc_memdup(mem_ctx
, *info
,
213 *num_entries
* sizeof(struct acct_info
));
216 *info
= talloced_info
;
221 /* convert a single name to a sid in a domain */
222 static NTSTATUS
name_to_sid(struct winbindd_domain
*domain
,
226 enum SID_NAME_USE
*type
)
228 DEBUG(10, ("Finding name %s\n", name
));
230 if (!pdb_find_alias(name
, sid
))
231 return NT_STATUS_NONE_MAPPED
;
233 *type
= SID_NAME_ALIAS
;
238 convert a domain SID to a user or group name
240 static NTSTATUS
sid_to_name(struct winbindd_domain
*domain
,
244 enum SID_NAME_USE
*type
)
246 struct acct_info info
;
248 DEBUG(10, ("Converting SID %s\n", sid_string_static(sid
)));
250 if (!pdb_get_aliasinfo(sid
, &info
))
251 return NT_STATUS_NONE_MAPPED
;
253 *name
= talloc_strdup(mem_ctx
, info
.acct_name
);
254 *type
= SID_NAME_ALIAS
;
259 /* Lookup user information from a rid or username. */
260 static NTSTATUS
query_user(struct winbindd_domain
*domain
,
262 const DOM_SID
*user_sid
,
263 WINBIND_USERINFO
*user_info
)
265 return NT_STATUS_NO_SUCH_USER
;
268 /* Lookup groups a user is a member of. I wish Unix had a call like this! */
269 static NTSTATUS
lookup_usergroups(struct winbindd_domain
*domain
,
271 const DOM_SID
*user_sid
,
272 uint32
*num_groups
, DOM_SID
***user_gids
)
274 return NT_STATUS_NO_SUCH_USER
;
278 /* Lookup group membership given a rid. */
279 static NTSTATUS
lookup_groupmem(struct winbindd_domain
*domain
,
281 const DOM_SID
*group_sid
, uint32
*num_names
,
282 DOM_SID
***sid_mem
, char ***names
,
288 /* find the sequence number for a domain */
289 static NTSTATUS
sequence_number(struct winbindd_domain
*domain
, uint32
*seq
)
295 /* get a list of trusted domains */
296 static NTSTATUS
trusted_domains(struct winbindd_domain
*domain
,
306 /* find the domain sid for a domain */
307 static NTSTATUS
domain_sid(struct winbindd_domain
*domain
, DOM_SID
*sid
)
309 sid_copy(sid
, &domain
->sid
);
313 /* find alternate names list for the domain
314 * should we look for netbios aliases??
316 static NTSTATUS
alternate_name(struct winbindd_domain
*domain
)
318 DEBUG(3,("pdb: alternate_name\n"));
324 /* the rpc backend methods are exposed via this structure */
325 struct winbindd_methods passdb_methods
= {