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 maps a unix alias to a rid, domain sid and an nt alias name.
70 *************************************************************************/
71 static void map_unix_als_to_nt_als(struct group *unix_als, char *nt_name, DOM_SID *sid, uint32 *rid)
73 if (map_alias_gid(unix_als->gr_gid, sid, nt_name, NULL))
76 * find the NT name represented by this UNIX gid.
77 * then, only accept NT aliass that are in our domain
80 sid_split_rid(sid, rid);
85 * assume that the UNIX alias is an NT alias with
86 * the same name. convert gid to a alias rid.
89 fstrcpy(nt_name, unix_als->gr_name);
90 sid_copy(sid, &global_sam_sid);
91 (*rid) = pwdb_gid_to_alias_rid(unix_als->gr_gid);
95 /*************************************************************************
96 Routine to return the next entry in the smbdomainalias list.
97 *************************************************************************/
98 BOOL get_unixalias_members(struct group *als,
99 int *num_mem, LOCAL_GRP_MEMBER **members)
105 if (num_mem == NULL || members == NULL)
113 for (i = 0; (unix_name = als->gr_mem[i]) != NULL; i++)
117 struct group unix_als;
119 if (isdigit(unix_name[0]))
121 unix_als.gr_gid = get_number(unix_name);
122 unix_als.gr_name = unix_name;
126 unix_als.gr_name = unix_name;
127 found = map_unix_alias_name(unix_name, &sid, nt_name, NULL);
130 found = found ? sid_equal(&sid, &global_sam_sid) : False;
134 DEBUG(0,("alias database: could not resolve name %s in domain %s\n",
135 unix_name, global_sam_name));
139 (*members) = Realloc((*members), ((*num_mem)+1) * sizeof(LOCAL_GRP_MEMBER));
140 if ((*members) == NULL)
145 fstrcpy((*members)[(*num_mem)].name, nt_name);
151 /*************************************************************************
152 Routine to return the next entry in the domain alias list.
153 *************************************************************************/
154 static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
156 /* Static buffers we will return. */
157 static LOCAL_GRP gp_buf;
158 struct group *unix_grp;
160 if (lp_server_role() == ROLE_DOMAIN_NONE ||
161 lp_server_role() == ROLE_DOMAIN_MEMBER)
164 * only PDC and BDC have domain aliass in the SAM.
165 * (however as member of domain you can have LOCAL aliass,
166 * but that's dealt with in the aliasdb...)
172 aldb_init_als(&gp_buf);
174 fstrcpy(gp_buf.comment, "");
176 /* cycle through unix aliass */
177 while ((unix_grp = getgrent()) != NULL)
180 if (map_alias_gid(unix_grp->gr_gid, &sid, gp_buf.name, NULL))
183 * find the NT name represented by this UNIX gid.
184 * then, only accept NT aliass that are in our domain
187 sid_split_rid(&sid, &gp_buf.rid);
188 if (sid_equal(&sid, &global_sam_sid))
196 * assume that the UNIX alias is an NT alias with
197 * the same name. convert gid to a alias rid.
200 fstrcpy(gp_buf.name, unix_grp->gr_name);
201 gp_buf.rid = pwdb_gid_to_alias_rid(unix_grp->gr_gid);
205 if (unix_grp == NULL)
210 /* get the user's domain aliass. there are a maximum of 32 */
212 if (mem != NULL && num_mem != NULL)
217 get_unixalias_members(unix_grp, num_mem, mem);
223 make_alias_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
224 DEBUG(10,("line: '%s'\n", linebuf));
231 /************************************************************************
232 Routine to add an entry to the alspasswd file.
233 *************************************************************************/
235 static BOOL add_alsunixals_entry(LOCAL_GRP *newals)
237 DEBUG(0, ("add_alsunixals_entry: NOT IMPLEMENTED\n"));
241 /************************************************************************
242 Routine to search the alspasswd file for an entry matching the aliasname.
243 and then modify its alias entry. We can't use the startalspwent()/
244 getalspwent()/endalspwent() interfaces here as we depend on looking
245 in the actual file to decide how much room we have to write data.
246 override = False, normal
247 override = True, override XXXXXXXX'd out alias or NO PASS
248 ************************************************************************/
250 static BOOL mod_alsunixals_entry(LOCAL_GRP* als)
252 DEBUG(0, ("mod_alsunixals_entry: NOT IMPLEMENTED\n"));
257 static struct aliasdb_ops unix_ops =
264 iterate_getaliasnam, /* In aliasdb.c */
265 iterate_getaliasgid, /* In aliasdb.c */
266 iterate_getaliasrid, /* In aliasdb.c */
269 add_alsunixals_entry,
270 mod_alsunixals_entry,
272 iterate_getuseraliasnam /* in aliasdb.c */
275 struct aliasdb_ops *unix_initialise_alias_db(void)
281 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
282 void unix_alspass_dummy_function(void) { } /* stop some compilers complaining */
283 #endif /* USE_SMBPASS_DB */