2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675
17 * Mass Ave, Cambridge, MA 02139, USA.
24 extern int DEBUGLEVEL;
25 extern DOM_SID global_member_sid;
27 /***************************************************************
28 Start to enumerate the smbpasswd list. Returns a void pointer
29 to ensure no modification outside this module.
30 ****************************************************************/
32 static void *startsmbunixgrpent(BOOL update)
34 return startsmbfilepwent(False);
37 /***************************************************************
38 End enumeration of the smbpasswd list.
39 ****************************************************************/
41 static void endsmbunixgrpent(void *vp)
46 /*************************************************************************
47 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
48 This must be treated as an opaque token.
49 *************************************************************************/
51 static SMB_BIG_UINT getsmbunixgrppos(void *vp)
53 return getsmbfilepwpos(vp);
56 /*************************************************************************
57 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
58 This must be treated as an opaque token.
59 *************************************************************************/
61 static BOOL setsmbunixgrppos(void *vp, SMB_BIG_UINT tok)
63 return setsmbfilepwpos(vp, tok);
66 /*************************************************************************
67 Routine to return the next smbpassgroup entry
68 *************************************************************************/
69 static struct smb_passwd *getsmbunixgrpent(void *vp,
70 uint32 **grp_rids, int *num_grps,
71 uint32 **als_rids, int *num_alss)
73 /* Static buffers we will return. */
74 struct smb_passwd *pw_buf;
82 DEBUG(0,("getsmbunixgrpent: Bad password file pointer.\n"));
86 pw_buf = getsmbfilepwent(vp);
100 if (als_rids == NULL && grp_rids == NULL)
106 * find all unix groups
109 pw = Get_Pwnam(pw_buf->smb_name, False);
116 if (get_unixgroups(pw_buf->smb_name, pw->pw_uid, pw->pw_gid, &unixgrps, &grps))
122 * check each unix group for a mapping as an nt alias or an nt group
125 for (i = 0; i < unixgrps; i++)
132 * find the unix name for each user's group.
133 * assume the unix group is an nt name (alias? group? user?)
134 * (user or not our own domain will be an error).
137 unix_grpname = gidtoname(grps[i]);
138 if (map_unix_alias_name(unix_grpname, &sid, NULL, NULL))
141 * ok, the unix groupname is mapped to an alias.
142 * check that it is in our domain.
145 sid_split_rid(&sid, &rid);
146 if (!sid_equal(&sid, &global_member_sid))
149 sid_to_string(sid_str, &sid);
150 DEBUG(0,("user %s is in a UNIX group %s that maps to an NT Domain Alias RID (0x%x) in another domain (%s)\n",
151 pw_buf->smb_name, unix_grpname, rid, sid_str));
155 if (add_num_to_list(als_rids, num_alss, rid) == NULL)
160 else if (map_unix_group_name(unix_grpname, &sid, NULL, NULL))
163 * ok, the unix groupname is mapped to a domain group.
164 * check that it is in our domain.
167 sid_split_rid(&sid, &rid);
168 if (!sid_equal(&sid, &global_member_sid))
171 sid_to_string(sid_str, &sid);
172 DEBUG(0,("user %s is in a UNIX group %s that maps to an NT Domain Group RID (0x%x) in another domain (%s)\n",
173 pw_buf->smb_name, unix_grpname, rid, sid_str));
177 if (add_num_to_list(grp_rids, num_grps, rid) == NULL)
182 else if (lp_server_role() == ROLE_DOMAIN_MEMBER)
185 * server is a member of a domain or stand-alone.
186 * name is not explicitly mapped
187 * so we are responsible for it.
191 rid = pwdb_gid_to_alias_rid(grps[i]);
192 if (add_num_to_list(als_rids, num_alss, rid) == NULL)
197 else if (lp_server_role() != ROLE_DOMAIN_NONE)
200 * server is a PDC or BDC.
201 * name is explicitly mapped
202 * so we are responsible for it.
206 rid = pwdb_gid_to_group_rid(grps[i]);
207 if (add_num_to_list(grp_rids, num_grps, rid) == NULL)
217 static struct passgrp_ops file_ops =
223 iterate_getsmbgrpnam, /* In passgrp.c */
224 iterate_getsmbgrpuid, /* In passgrp.c */
225 iterate_getsmbgrprid, /* In passgrp.c */
229 struct passgrp_ops *unix_initialise_password_grp(void)
235 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
236 void smbpass_dummy_function(void) { } /* stop some compilers complaining */
237 #endif /* USE_SMBPASS_DB */