2 Unix SMB/CIFS implementation.
4 Password and authentication handling by wbclient
6 Copyright (C) Andrew Bartlett 2002
7 Copyright (C) Jelmer Vernooij 2002
8 Copyright (C) Simo Sorce 2003
9 Copyright (C) Volker Lendecke 2006
10 Copyright (C) Dan Sledz 2009
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /* This passdb module retrieves full passdb information for local users and
27 * groups from a wbclient compatible daemon.
29 * The purpose of this module is to defer all SAM authorization information
30 * storage and retrieval to a wbc compatible daemon.
32 * This passdb backend is most useful when used in conjunction with auth_wbc.
34 * A few current limitations of this module are:
35 * - read only interface
41 #include "lib/winbind_util.h"
42 #include "passdb/pdb_wbc_sam.h"
44 /***************************************************************************
45 Default implementations of some functions.
46 ****************************************************************************/
47 static NTSTATUS _pdb_wbc_sam_getsampw(struct pdb_methods *methods,
49 const struct passwd *pwd)
51 NTSTATUS result = NT_STATUS_OK;
54 return NT_STATUS_NO_SUCH_USER;
58 /* Can we really get away with this little of information */
59 user->methods = methods;
60 result = samu_set_unix(user, pwd);
65 static NTSTATUS pdb_wbc_sam_getsampwnam(struct pdb_methods *methods, struct samu *user, const char *sname)
67 return _pdb_wbc_sam_getsampw(methods, user, winbind_getpwnam(sname));
70 static NTSTATUS pdb_wbc_sam_getsampwsid(struct pdb_methods *methods, struct samu *user, const struct dom_sid *sid)
72 return _pdb_wbc_sam_getsampw(methods, user, winbind_getpwsid(sid));
75 static bool pdb_wbc_sam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
78 return winbind_uid_to_sid(sid, uid);
81 static bool pdb_wbc_sam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
84 return winbind_gid_to_sid(sid, gid);
87 static NTSTATUS pdb_wbc_sam_enum_group_members(struct pdb_methods *methods,
89 const struct dom_sid *group,
90 uint32 **pp_member_rids,
91 size_t *p_num_members)
93 return NT_STATUS_NOT_IMPLEMENTED;
96 static NTSTATUS pdb_wbc_sam_enum_group_memberships(struct pdb_methods *methods,
99 struct dom_sid **pp_sids,
101 uint32_t *p_num_groups)
104 const char *username = pdb_get_username(user);
107 if (!winbind_get_groups(mem_ctx, username, &num_groups, pp_gids)) {
108 return NT_STATUS_NO_SUCH_USER;
110 *p_num_groups = num_groups;
112 if (*p_num_groups == 0) {
113 smb_panic("primary group missing");
116 *pp_sids = talloc_array(mem_ctx, struct dom_sid, *p_num_groups);
118 if (*pp_sids == NULL) {
119 TALLOC_FREE(*pp_gids);
120 return NT_STATUS_NO_MEMORY;
123 for (i=0; i < *p_num_groups; i++) {
124 gid_to_sid(&(*pp_sids)[i], (*pp_gids)[i]);
130 static NTSTATUS pdb_wbc_sam_lookup_rids(struct pdb_methods *methods,
131 const struct dom_sid *domain_sid,
135 enum lsa_SidType *attrs)
137 NTSTATUS result = NT_STATUS_OK;
139 char **account_names = NULL;
140 enum lsa_SidType *attr_list = NULL;
143 if (!winbind_lookup_rids(talloc_tos(), domain_sid, num_rids, rids,
144 (const char **)&domain,
145 (const char ***)&account_names, &attr_list))
147 result = NT_STATUS_NONE_MAPPED;
151 memcpy(attrs, attr_list, num_rids * sizeof(enum lsa_SidType));
153 for (i=0; i<num_rids; i++) {
154 if (attrs[i] == SID_NAME_UNKNOWN) {
157 names[i] = talloc_strdup(names, account_names[i]);
158 if (names[i] == NULL) {
159 result = NT_STATUS_NO_MEMORY;
167 TALLOC_FREE(account_names);
169 TALLOC_FREE(attr_list);
173 static NTSTATUS pdb_wbc_sam_get_account_policy(struct pdb_methods *methods, enum pdb_policy_type type, uint32_t *value)
175 return NT_STATUS_UNSUCCESSFUL;
178 static NTSTATUS pdb_wbc_sam_set_account_policy(struct pdb_methods *methods, enum pdb_policy_type type, uint32_t value)
180 return NT_STATUS_UNSUCCESSFUL;
183 static bool pdb_wbc_sam_search_groups(struct pdb_methods *methods,
184 struct pdb_search *search)
189 static bool pdb_wbc_sam_search_aliases(struct pdb_methods *methods,
190 struct pdb_search *search,
191 const struct dom_sid *sid)
197 static bool pdb_wbc_sam_get_trusteddom_pw(struct pdb_methods *methods,
201 time_t *pass_last_set_time)
207 static bool pdb_wbc_sam_set_trusteddom_pw(struct pdb_methods *methods,
210 const struct dom_sid *sid)
215 static bool pdb_wbc_sam_del_trusteddom_pw(struct pdb_methods *methods,
221 static NTSTATUS pdb_wbc_sam_enum_trusteddoms(struct pdb_methods *methods,
224 struct trustdom_info ***domains)
226 return NT_STATUS_NOT_IMPLEMENTED;
229 static bool _make_group_map(struct pdb_methods *methods, const char *domain, const char *name, enum lsa_SidType name_type, gid_t gid, struct dom_sid *sid, GROUP_MAP *map)
231 map->nt_name = talloc_asprintf(map, "%s%c%s",
232 domain, *lp_winbind_separator(), name);
236 map->sid_name_use = name_type;
242 static NTSTATUS pdb_wbc_sam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
245 NTSTATUS result = NT_STATUS_OK;
248 enum lsa_SidType name_type;
251 if (!winbind_lookup_sid(talloc_tos(), &sid, (const char **)&domain,
252 (const char **) &name, &name_type)) {
253 result = NT_STATUS_NO_SUCH_GROUP;
257 if ((name_type != SID_NAME_DOM_GRP) &&
258 (name_type != SID_NAME_DOMAIN) &&
259 (name_type != SID_NAME_ALIAS) &&
260 (name_type != SID_NAME_WKN_GRP)) {
261 result = NT_STATUS_NO_SUCH_GROUP;
265 if (!winbind_sid_to_gid(&gid, &sid)) {
266 result = NT_STATUS_NO_SUCH_GROUP;
270 if (!_make_group_map(methods, domain, name, name_type, gid, &sid, map)) {
271 result = NT_STATUS_NO_SUCH_GROUP;
281 static NTSTATUS pdb_wbc_sam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
284 NTSTATUS result = NT_STATUS_OK;
288 enum lsa_SidType name_type;
290 if (!winbind_gid_to_sid(&sid, gid)) {
291 result = NT_STATUS_NO_SUCH_GROUP;
295 if (!winbind_lookup_sid(talloc_tos(), &sid, (const char **)&domain,
296 (const char **)&name, &name_type)) {
297 result = NT_STATUS_NO_SUCH_GROUP;
301 if ((name_type != SID_NAME_DOM_GRP) &&
302 (name_type != SID_NAME_DOMAIN) &&
303 (name_type != SID_NAME_ALIAS) &&
304 (name_type != SID_NAME_WKN_GRP)) {
305 result = NT_STATUS_NO_SUCH_GROUP;
309 if (!_make_group_map(methods, domain, name, name_type, gid, &sid, map)) {
310 result = NT_STATUS_NO_SUCH_GROUP;
321 static NTSTATUS pdb_wbc_sam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
324 NTSTATUS result = NT_STATUS_OK;
325 const char *domain = "";
328 enum lsa_SidType name_type;
330 if (!winbind_lookup_name(domain, name, &sid, &name_type)) {
331 result = NT_STATUS_NO_SUCH_GROUP;
335 if ((name_type != SID_NAME_DOM_GRP) &&
336 (name_type != SID_NAME_DOMAIN) &&
337 (name_type != SID_NAME_ALIAS) &&
338 (name_type != SID_NAME_WKN_GRP)) {
339 result = NT_STATUS_NO_SUCH_GROUP;
343 if (!winbind_sid_to_gid(&gid, &sid)) {
344 result = NT_STATUS_NO_SUCH_GROUP;
348 if (!_make_group_map(methods, domain, name, name_type, gid, &sid, map)) {
349 result = NT_STATUS_NO_SUCH_GROUP;
358 static NTSTATUS pdb_wbc_sam_enum_group_mapping(struct pdb_methods *methods,
359 const struct dom_sid *sid, enum lsa_SidType sid_name_use,
360 GROUP_MAP ***pp_rmap, size_t *p_num_entries,
363 return NT_STATUS_NOT_IMPLEMENTED;
366 static NTSTATUS pdb_wbc_sam_get_aliasinfo(struct pdb_methods *methods,
367 const struct dom_sid *sid,
368 struct acct_info *info)
370 return NT_STATUS_NOT_IMPLEMENTED;
373 static NTSTATUS pdb_wbc_sam_enum_aliasmem(struct pdb_methods *methods,
374 const struct dom_sid *alias,
376 struct dom_sid **pp_members,
377 size_t *p_num_members)
379 return NT_STATUS_NOT_IMPLEMENTED;
382 static NTSTATUS pdb_wbc_sam_alias_memberships(struct pdb_methods *methods,
384 const struct dom_sid *domain_sid,
385 const struct dom_sid *members,
387 uint32 **pp_alias_rids,
388 size_t *p_num_alias_rids)
390 if (!winbind_get_sid_aliases(mem_ctx, domain_sid,
391 members, num_members, pp_alias_rids, p_num_alias_rids))
392 return NT_STATUS_UNSUCCESSFUL;
397 static NTSTATUS pdb_init_wbc_sam(struct pdb_methods **pdb_method, const char *location)
401 if (!NT_STATUS_IS_OK(result = make_pdb_method( pdb_method))) {
405 (*pdb_method)->name = "wbc_sam";
407 (*pdb_method)->getsampwnam = pdb_wbc_sam_getsampwnam;
408 (*pdb_method)->getsampwsid = pdb_wbc_sam_getsampwsid;
410 (*pdb_method)->getgrsid = pdb_wbc_sam_getgrsid;
411 (*pdb_method)->getgrgid = pdb_wbc_sam_getgrgid;
412 (*pdb_method)->getgrnam = pdb_wbc_sam_getgrnam;
413 (*pdb_method)->enum_group_mapping = pdb_wbc_sam_enum_group_mapping;
414 (*pdb_method)->enum_group_members = pdb_wbc_sam_enum_group_members;
415 (*pdb_method)->enum_group_memberships = pdb_wbc_sam_enum_group_memberships;
416 (*pdb_method)->get_aliasinfo = pdb_wbc_sam_get_aliasinfo;
417 (*pdb_method)->enum_aliasmem = pdb_wbc_sam_enum_aliasmem;
418 (*pdb_method)->enum_alias_memberships = pdb_wbc_sam_alias_memberships;
419 (*pdb_method)->lookup_rids = pdb_wbc_sam_lookup_rids;
420 (*pdb_method)->get_account_policy = pdb_wbc_sam_get_account_policy;
421 (*pdb_method)->set_account_policy = pdb_wbc_sam_set_account_policy;
422 (*pdb_method)->uid_to_sid = pdb_wbc_sam_uid_to_sid;
423 (*pdb_method)->gid_to_sid = pdb_wbc_sam_gid_to_sid;
425 (*pdb_method)->search_groups = pdb_wbc_sam_search_groups;
426 (*pdb_method)->search_aliases = pdb_wbc_sam_search_aliases;
428 (*pdb_method)->get_trusteddom_pw = pdb_wbc_sam_get_trusteddom_pw;
429 (*pdb_method)->set_trusteddom_pw = pdb_wbc_sam_set_trusteddom_pw;
430 (*pdb_method)->del_trusteddom_pw = pdb_wbc_sam_del_trusteddom_pw;
431 (*pdb_method)->enum_trusteddoms = pdb_wbc_sam_enum_trusteddoms;
433 (*pdb_method)->private_data = NULL;
434 (*pdb_method)->free_private_data = NULL;
439 NTSTATUS pdb_wbc_sam_init(void)
441 return smb_register_passdb(PASSDB_INTERFACE_VERSION, "wbc_sam", pdb_init_wbc_sam);