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;
28 extern fstring global_sam_name;
30 /***************************************************************
31 Start to enumerate the alspasswd list. Returns a void pointer
32 to ensure no modification outside this module.
33 ****************************************************************/
35 static void *startalsunixpwent(BOOL update)
41 /***************************************************************
42 End enumeration of the alspasswd list.
43 ****************************************************************/
45 static void endalsunixpwent(void *vp)
50 /*************************************************************************
51 Return the current position in the alspasswd list as an SMB_BIG_UINT.
52 This must be treated as an opaque token.
53 *************************************************************************/
54 static SMB_BIG_UINT getalsunixpwpos(void *vp)
56 return (SMB_BIG_UINT)0;
59 /*************************************************************************
60 Set the current position in the alspasswd list from an SMB_BIG_UINT.
61 This must be treated as an opaque token.
62 *************************************************************************/
63 static BOOL setalsunixpwpos(void *vp, SMB_BIG_UINT tok)
68 /*************************************************************************
69 Routine to return the next entry in the smbdomainalias list.
70 *************************************************************************/
71 BOOL get_unixalias_members(struct group *grp,
72 int *num_mem, LOCAL_GRP_MEMBER **members)
77 if (num_mem == NULL || members == NULL)
85 for (i = 0; (unix_name = grp->gr_mem[i]) != NULL; i++)
89 LOCAL_GRP_MEMBER *mem;
91 fstrcpy(name, unix_name);
93 if (!lookupsmbpwnam (name, &gmep) &&
94 !lookupsmbgrpnam(name, &gmep))
99 if (!sid_front_equal(&global_sam_sid, &gmep.sid))
101 DEBUG(0,("alias database: could not resolve name %s (wrong Domain SID)\n",
107 (*members) = Realloc((*members), (*num_mem) * sizeof(LOCAL_GRP_MEMBER));
108 if ((*members) == NULL)
110 DEBUG(0,("get_unixalias_members: could not realloc LOCAL_GRP_MEMBERs\n"));
114 mem = &(*members)[(*num_mem)-1];
115 slprintf(mem->name, sizeof(mem->name)-1, "%s\\%s",
116 gmep.nt_domain, gmep.nt_name);
117 sid_copy(&mem->sid, &gmep.sid);
118 mem->sid_use = gmep.type;
120 DEBUG(10,("get_unixalias_members: adding alias %s\n",
126 /*************************************************************************
127 Routine to return the next entry in the domain alias list.
129 when we are a PDC or BDC, then unix groups that are explicitly NOT mapped
130 to aliases are treated as DOMAIN groups (see groupunix.c).
132 when we are a member of a domain (not a PDC or BDC) then unix groups
133 that are explicitly NOT mapped to aliases (map_alias_gid) are treated
136 the reasoning behind this is to make it as simple as possible (not an easy
137 task) for people to set up a domain-aware samba server, in each role that
140 *************************************************************************/
141 static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
143 /* Static buffers we will return. */
144 static LOCAL_GRP gp_buf;
145 struct group *unix_grp;
147 if (lp_server_role() == ROLE_DOMAIN_NONE)
150 * no domain role, no domain aliases (or domain groups,
151 * but that's dealt with by groupdb...).
157 aldb_init_als(&gp_buf);
159 /* cycle through unix groups */
160 while ((unix_grp = getgrent()) != NULL)
164 DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
167 if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
172 sid_to_string(sid_str, &gmep.sid);
173 DEBUG(10,("group %s found, sid %s type %d\n",
174 gmep.nt_name, sid_str, gmep.type));
176 if (gmep.type != SID_NAME_ALIAS)
181 sid_split_rid(&gmep.sid, &gp_buf.rid);
182 if (!sid_equal(&global_sam_sid, &gmep.sid))
187 fstrcpy(gp_buf.name, gmep.nt_name);
191 if (unix_grp == NULL)
196 /* get the user's domain aliases. there are a maximum of 32 */
198 if (mem != NULL && num_mem != NULL)
203 get_unixalias_members(unix_grp, num_mem, mem);
208 make_alias_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
209 DEBUG(10,("line: '%s'\n", linebuf));
215 /************************************************************************
216 Routine to add an entry to the alspasswd file.
217 *************************************************************************/
219 static BOOL add_alsunixgrp_entry(LOCAL_GRP *newals)
221 DEBUG(0, ("add_alsunixgrp_entry: NOT IMPLEMENTED\n"));
225 /************************************************************************
226 Routine to search the alspasswd file for an entry matching the aliasname.
227 and then modify its alias entry. We can't use the startalspwent()/
228 getalspwent()/endalspwent() interfaces here as we depend on looking
229 in the actual file to decide how much room we have to write data.
230 override = False, normal
231 override = True, override XXXXXXXX'd out alias or NO PASS
232 ************************************************************************/
234 static BOOL mod_alsunixgrp_entry(LOCAL_GRP* als)
236 DEBUG(0, ("mod_alsunixgrp_entry: NOT IMPLEMENTED\n"));
241 static struct aliasdb_ops unix_ops =
248 iterate_getaliasntnam, /* In aliasdb.c */
249 iterate_getaliasgid, /* In aliasdb.c */
250 iterate_getaliasrid, /* In aliasdb.c */
253 add_alsunixgrp_entry,
254 mod_alsunixgrp_entry,
256 iterate_getuseraliasntnam /* in aliasdb.c */
259 struct aliasdb_ops *unix_initialise_alias_db(void)
265 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
266 void unix_alspass_dummy_function(void) { } /* stop some compilers complaining */
267 #endif /* USE_SMBPASS_DB */