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;
27 extern DOM_SID global_sam_sid;
29 /***************************************************************
30 Start to enumerate the grppasswd list. Returns a void pointer
31 to ensure no modification outside this module.
32 ****************************************************************/
41 static void *startgrpunixpwent(BOOL update)
43 struct unix_entries *grps;
44 grps = (struct unix_entries*)malloc(sizeof(struct unix_entries));
51 if (!get_unix_grps(&grps->num_grps, &grps->grps))
62 /***************************************************************
63 End enumeration of the grppasswd list.
64 ****************************************************************/
66 static void endgrpunixpwent(void *vp)
68 struct unix_entries *grps = (struct unix_entries *)vp;
72 free_unix_grps(grps->num_grps, grps->grps);
77 /*************************************************************************
78 Return the current position in the grppasswd list as an SMB_BIG_UINT.
79 This must be treated as an opaque token.
80 *************************************************************************/
81 static SMB_BIG_UINT getgrpunixpwpos(void *vp)
83 return (SMB_BIG_UINT)0;
86 /*************************************************************************
87 Set the current position in the grppasswd list from an SMB_BIG_UINT.
88 This must be treated as an opaque token.
89 *************************************************************************/
90 static BOOL setgrpunixpwpos(void *vp, SMB_BIG_UINT tok)
95 /*************************************************************************
96 Routine to return the next entry in the smbdomaingroup list.
97 *************************************************************************/
98 BOOL get_unixgroup_members(struct group *grp,
99 int *num_mem, DOMAIN_GRP_MEMBER **members)
104 if (num_mem == NULL || members == NULL)
112 for (i = 0; (unix_name = grp->gr_mem[i]) != NULL; i++)
115 DOMAIN_GRP_MEMBER *mem;
118 if (!lookupsmbpwnam (unix_name, &gmep) &&
119 !lookupsmbgrpnam(unix_name, &gmep))
124 if (gmep.type != SID_NAME_DOM_GRP &&
125 gmep.type != SID_NAME_USER &&
126 gmep.type != SID_NAME_WKN_GRP)
128 DEBUG(0,("group database: name %s is not in a Domain Group\n",
133 sid_split_rid(&gmep.sid, &rid);
134 if (!sid_equal(&global_sam_sid, &gmep.sid))
136 DEBUG(0,("group database: could not resolve name %s (wrong Domain SID)\n",
141 (*members) = Realloc((*members), ((*num_mem)+1) * sizeof(DOMAIN_GRP_MEMBER));
142 if ((*members) == NULL)
147 mem = &(*members)[(*num_mem)];
150 fstrcpy(mem->name, gmep.nt_name);
152 mem->sid_use = gmep.type;
158 /*************************************************************************
159 Routine to return the next entry in the domain group list.
161 if we are not a PDC or BDC, then we do NOT support Domain groups, only
162 aliases. try running MUSRMGR.EXE or running USRMGR.EXE selected on a
163 workstation, you will find that no Domain groups are listed: only aliases.
165 so, as a PDC or BDC, all unix groups not explicitly mapped using
166 map_group_gid() are treated as Domain groups.
168 *************************************************************************/
169 static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_mem)
171 /* Static buffers we will return. */
172 static DOMAIN_GRP gp_buf;
173 struct group *unix_grp = NULL;
174 struct unix_entries *grps = (struct unix_entries *)vp;
181 if (lp_server_role() == ROLE_DOMAIN_NONE ||
182 lp_server_role() == ROLE_DOMAIN_MEMBER)
185 * only PDC and BDC have domain groups in the SAM.
186 * (however as member of domain you can have LOCAL groups,
187 * but that's dealt with in the aliasdb...)
193 gpdb_init_grp(&gp_buf);
195 fstrcpy(gp_buf.comment, "");
198 /* get array of unix names + gids. this function does NOT
199 get a copy of the unix group members
202 /* cycle through unix groups */
203 for (; grps->grp_idx < grps->num_grps; grps->grp_idx++)
207 unix_grp = &grps->grps[grps->grp_idx];
209 DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
212 if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
217 if (gmep.type != SID_NAME_DOM_GRP &&
218 gmep.type != SID_NAME_WKN_GRP)
223 sid_split_rid(&gmep.sid, &gp_buf.rid);
224 if (!sid_equal(&gmep.sid, &global_sam_sid))
229 fstrcpy(gp_buf.name, gmep.nt_name);
233 if (unix_grp == NULL || grps->grp_idx >= grps->num_grps)
238 /* get the user's domain groups. there are a maximum of 32 */
240 if (mem != NULL && num_mem != NULL)
245 unix_grp = getgrgid(unix_grp->gr_gid);
246 get_unixgroup_members(unix_grp, num_mem, mem);
251 make_group_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
252 DEBUG(10,("line: '%s'\n", linebuf));
255 grps->grp_idx++; /* advance so next enum gets next entry */
259 /************************************************************************
260 Routine to add an entry to the grppasswd file.
261 *************************************************************************/
263 static BOOL add_grpunixgrp_entry(DOMAIN_GRP *newgrp)
265 DEBUG(0, ("add_grpunixgrp_entry: NOT IMPLEMENTED\n"));
269 /************************************************************************
270 Routine to search database for entry matching the groupname and/or rid.
271 and then modify its group entry.
272 ************************************************************************/
274 static BOOL mod_grpunixgrp_entry(DOMAIN_GRP* grp)
276 DEBUG(0, ("mod_grpunixgrp_entry: NOT IMPLEMENTED\n"));
280 /************************************************************************
281 Routine to search the grppasswd file for an entry matching the rid.
283 ************************************************************************/
285 static BOOL del_grpunixgrp_entry(uint32 rid)
287 DEBUG(0, ("del_grpunixgrp_entry: NOT IMPLEMENTED\n"));
291 /************************************************************************
292 Routine to add a member to an entry to the grppasswd file.
293 *************************************************************************/
294 static BOOL add_grpunixgrp_member(uint32 rid, uint32 member_rid)
296 DEBUG(0, ("add_grpunixgrp_member: NOT IMPLEMENTED\n"));
300 /************************************************************************
301 Routine to delete a member from an entry to the grppasswd file.
302 *************************************************************************/
303 static BOOL del_grpunixgrp_member(uint32 rid, uint32 member_rid)
305 DEBUG(0, ("del_grpunixgrp_member: NOT IMPLEMENTED\n"));
309 static struct groupdb_ops unix_ops =
316 iterate_getgroupntnam, /* In groupdb.c */
317 iterate_getgroupgid, /* In groupdb.c */
318 iterate_getgrouprid, /* In groupdb.c */
321 add_grpunixgrp_entry,
322 mod_grpunixgrp_entry,
323 del_grpunixgrp_entry,
325 add_grpunixgrp_member,
326 del_grpunixgrp_member,
328 iterate_getusergroupsnam /* in groupdb.c */
331 struct groupdb_ops *unix_initialise_group_db(void)
337 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
338 void unix_grppass_dummy_function(void) { } /* stop some compilers complaining */
339 #endif /* USE_SMBPASS_DB */