preparing for release of alpha-2.6
[Samba/gbeck.git] / source / groupdb / aliasunix.c
blob089b33e1fb664d6def7e1076ca88a09e1005bda8
1 /*
2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
4 *
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)
8 * any later version.
9 *
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
13 * more details.
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.
20 #include "includes.h"
21 #include "sids.h"
23 #ifdef USE_SMBUNIX_DB
25 extern int DEBUGLEVEL;
27 struct unix_entries
29 struct group *grps;
30 int num_grps;
31 int grp_idx;
34 /***************************************************************
35 Start to enumerate the alspasswd list. Returns a void pointer
36 to ensure no modification outside this module.
37 ****************************************************************/
39 static void *startalsunixpwent(BOOL update)
41 struct unix_entries *grps;
42 grps = (struct unix_entries*)malloc(sizeof(struct unix_entries));
44 if (grps == NULL)
46 return NULL;
49 if (!get_unix_grps(&grps->num_grps, &grps->grps))
51 free(grps);
52 return NULL;
55 grps->grp_idx = 0;
57 return (void*)grps;
60 /***************************************************************
61 End enumeration of the alspasswd list.
62 ****************************************************************/
64 static void endalsunixpwent(void *vp)
66 struct unix_entries *grps = (struct unix_entries *)vp;
68 if (grps != NULL)
70 free_unix_grps(grps->num_grps, grps->grps);
71 free(vp);
75 /*************************************************************************
76 Return the current position in the alspasswd list as an SMB_BIG_UINT.
77 This must be treated as an opaque token.
78 *************************************************************************/
79 static SMB_BIG_UINT getalsunixpwpos(void *vp)
81 return (SMB_BIG_UINT)0;
84 /*************************************************************************
85 Set the current position in the alspasswd list from an SMB_BIG_UINT.
86 This must be treated as an opaque token.
87 *************************************************************************/
88 static BOOL setalsunixpwpos(void *vp, SMB_BIG_UINT tok)
90 return False;
93 /*************************************************************************
94 Routine to return the next entry in the smbdomainalias list.
95 *************************************************************************/
96 BOOL get_unixalias_members(struct group *grp,
97 int *num_mem, LOCAL_GRP_MEMBER **members)
99 int i;
100 char *unix_name;
102 if (num_mem == NULL || members == NULL)
104 return False;
107 (*num_mem) = 0;
108 (*members) = NULL;
110 for (i = 0; (unix_name = grp->gr_mem[i]) != NULL; i++)
112 fstring name;
113 DOM_NAME_MAP gmep;
114 LOCAL_GRP_MEMBER *mem;
116 fstrcpy(name, unix_name);
118 if (!lookupsmbpwnam (name, &gmep) &&
119 !lookupsmbgrpnam(name, &gmep))
121 continue;
124 if (!sid_front_equal(&global_sam_sid, &gmep.sid))
126 DEBUG(0,("alias database: could not resolve name %s (wrong Domain SID)\n",
127 name));
128 continue;
131 (*num_mem)++;
132 (*members) = Realloc((*members), (*num_mem) * sizeof(LOCAL_GRP_MEMBER));
133 if ((*members) == NULL)
135 DEBUG(0,("get_unixalias_members: could not realloc LOCAL_GRP_MEMBERs\n"));
136 return False;
139 mem = &(*members)[(*num_mem)-1];
140 slprintf(mem->name, sizeof(mem->name)-1, "%s\\%s",
141 gmep.nt_domain, gmep.nt_name);
142 sid_copy(&mem->sid, &gmep.sid);
143 mem->sid_use = gmep.type;
145 DEBUG(10,("get_unixalias_members: adding alias %s\n",
146 mem->name));
148 return True;
151 /*************************************************************************
152 Routine to return the next entry in the domain alias list.
154 when we are a PDC or BDC, then unix groups that are explicitly NOT mapped
155 to aliases are treated as DOMAIN groups (see groupunix.c).
157 when we are a member of a domain (not a PDC or BDC) then unix groups
158 that are explicitly NOT mapped to aliases (map_alias_gid) are treated
159 as LOCAL groups.
161 the reasoning behind this is to make it as simple as possible (not an easy
162 task) for people to set up a domain-aware samba server, in each role that
163 the server can take.
165 *************************************************************************/
166 static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
168 /* Static buffers we will return. */
169 static LOCAL_GRP gp_buf;
170 struct group unix_grp;
171 struct unix_entries *grps = (struct unix_entries *)vp;
173 aldb_init_als(&gp_buf);
175 /* get array of unix names + gids. this function does NOT
176 get a copy of the unix group members
179 /* cycle through unix groups */
180 for (; grps->grp_idx < grps->num_grps; grps->grp_idx++)
182 DOM_NAME_MAP gmep;
183 fstring sid_str;
185 memcpy(&unix_grp, &grps->grps[grps->grp_idx], sizeof(unix_grp));
187 DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
188 unix_grp.gr_name));
190 if (!lookupsmbgrpgid(unix_grp.gr_gid, &gmep))
192 continue;
195 sid_to_string(sid_str, &gmep.sid);
196 DEBUG(10,("group %s found, sid %s type %d\n",
197 gmep.nt_name, sid_str, gmep.type));
199 if (gmep.type != SID_NAME_ALIAS)
201 continue;
204 sid_split_rid(&gmep.sid, &gp_buf.rid);
205 if (!sid_equal(&global_sam_sid, &gmep.sid))
207 continue;
210 fstrcpy(gp_buf.name, gmep.nt_name);
211 break;
214 if (grps->grp_idx >= grps->num_grps)
216 return NULL;
219 /* get the user's domain aliases. there are a maximum of 32 */
221 if (mem != NULL && num_mem != NULL)
223 (*mem) = NULL;
224 (*num_mem) = 0;
226 memcpy(&unix_grp, getgrgid(unix_grp.gr_gid), sizeof(unix_grp));
227 get_unixalias_members(&unix_grp, num_mem, mem);
231 pstring linebuf;
232 make_alias_line(linebuf, sizeof(pstring), &gp_buf, mem, num_mem);
233 DEBUG(10,("line: '%s'\n", linebuf));
236 grps->grp_idx++; /* advance so next enum gets next entry */
237 return &gp_buf;
240 /************************************************************************
241 Routine to add an entry to the alspasswd file.
242 *************************************************************************/
244 static BOOL add_alsunixgrp_entry(LOCAL_GRP *newals)
246 DEBUG(0, ("add_alsunixgrp_entry: NOT IMPLEMENTED\n"));
247 return False;
250 /************************************************************************
251 Routine to search the alspasswd file for an entry matching the aliasname.
252 and then modify its alias entry.
253 ************************************************************************/
255 static BOOL mod_alsunixgrp_entry(LOCAL_GRP* als)
257 DEBUG(0, ("mod_alsunixgrp_entry: NOT IMPLEMENTED\n"));
258 return False;
261 /************************************************************************
262 Routine to search the grppasswd file for an entry matching the rid.
263 and then delete it.
264 ************************************************************************/
266 static BOOL del_alsunixgrp_entry(uint32 rid)
268 DEBUG(0, ("del_alsunixgrp_entry: NOT IMPLEMENTED\n"));
269 return False;
272 /************************************************************************
273 Routine to add a member to an entry to the grppasswd file.
274 *************************************************************************/
275 static BOOL add_alsunixgrp_member(uint32 rid, const DOM_SID *member_sid)
277 DEBUG(0, ("add_alsunixgrp_member: NOT IMPLEMENTED\n"));
278 return False;
281 /************************************************************************
282 Routine to delete a member from an entry to the grppasswd file.
283 *************************************************************************/
284 static BOOL del_alsunixgrp_member(uint32 rid, const DOM_SID *member_sid)
286 DEBUG(0, ("del_alsunixgrp_member: NOT IMPLEMENTED\n"));
287 return False;
291 static struct aliasdb_ops unix_ops =
293 startalsunixpwent,
294 endalsunixpwent,
295 getalsunixpwpos,
296 setalsunixpwpos,
298 iterate_getaliasntnam, /* In aliasdb.c */
299 iterate_getaliasgid, /* In aliasdb.c */
300 iterate_getaliasrid, /* In aliasdb.c */
301 getalsunixpwent,
303 add_alsunixgrp_entry,
304 mod_alsunixgrp_entry,
305 del_alsunixgrp_entry,
307 add_alsunixgrp_member,
308 del_alsunixgrp_member,
310 iterate_getuseraliasntnam /* in aliasdb.c */
313 struct aliasdb_ops *unix_initialise_alias_db(void)
315 return &unix_ops;
318 #else
319 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
320 void unix_alspass_dummy_function(void) { } /* stop some compilers complaining */
321 #endif /* USE_SMBPASS_DB */