2 Unix SMB/CIFS implementation.
3 Password and authentication handling
4 Copyright (C) Jeremy Allison 1996-1998
5 Copyright (C) Luke Kenneth Caseson Leighton 1996-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mases Ave, Cambridge, MA 02139, USA.
24 extern fstring global_sam_name;
27 * NOTE. All these functions are abstracted into a structure
28 * that points to the correct function for the selected database. JRA.
31 static struct aliasdb_ops *aldb_ops;
33 /***************************************************************
34 Initialise the alias db operations.
35 ***************************************************************/
37 BOOL initialise_alias_db(void)
45 aldb_ops = nisplus_initialise_alias_db();
46 #elif defined(WITH_LDAP)
47 aldb_ops = ldap_initialise_alias_db();
49 aldb_ops = file_initialise_alias_db();
52 return (aldb_ops != NULL);
56 * Functions that return/manipulate a LOCAL_GRP.
59 /************************************************************************
60 Utility function to search alias database by gid: the LOCAL_GRP
61 structure does not have a gid member, so we have to convert here
62 from gid to alias rid.
63 *************************************************************************/
64 LOCAL_GRP *iterate_getaliasgid(gid_t gid, LOCAL_GRP_MEMBER **mem, int *num_mem)
66 return iterate_getaliasrid(pwdb_gid_to_alias_rid(gid), mem, num_mem);
69 /************************************************************************
70 Utility function to search alias database by rid. use this if your database
71 does not have search facilities.
72 *************************************************************************/
73 LOCAL_GRP *iterate_getaliasrid(uint32 rid, LOCAL_GRP_MEMBER **mem, int *num_mem)
75 LOCAL_GRP *als = NULL;
78 DEBUG(10, ("search by rid: 0x%x\n", rid));
80 /* Open the alias database file - not for update. */
81 fp = startaliasent(False);
85 DEBUG(0, ("unable to open alias database.\n"));
89 while ((als = getaliasent(fp, mem, num_mem)) != NULL && als->rid != rid)
95 DEBUG(10, ("found alias %s by rid: 0x%x\n", als->name, rid));
102 /************************************************************************
103 Utility function to search alias database by name. use this if your database
104 does not have search facilities.
105 *************************************************************************/
106 LOCAL_GRP *iterate_getaliasnam(char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
108 LOCAL_GRP *als = NULL;
111 DEBUG(10, ("search by name: %s\n", name));
113 /* Open the alias database file - not for update. */
114 fp = startaliasent(False);
118 DEBUG(0, ("unable to open alias database.\n"));
122 while ((als = getaliasent(fp, mem, num_mem)) != NULL && !strequal(als->name, name))
128 DEBUG(10, ("found by name: %s\n", name));
135 /*************************************************************************
136 Routine to return the next entry in the smbdomainalias list.
137 *************************************************************************/
138 BOOL add_domain_alias(LOCAL_GRP **alss, int *num_alss, LOCAL_GRP *als)
142 if (alss == NULL || num_alss == NULL || als == NULL)
145 talss = Realloc((*alss), ((*num_alss)+1) * sizeof(LOCAL_GRP));
152 DEBUG(10,("adding alias %s(%s)\n", als->name, als->comment));
154 fstrcpy((*alss)[(*num_alss)].name , als->name);
155 fstrcpy((*alss)[(*num_alss)].comment, als->comment);
156 (*alss)[(*num_alss)].rid = als->rid;
163 /*************************************************************************
164 checks to see if a user is a member of a domain alias
165 *************************************************************************/
166 static BOOL user_is_member(char *user_name, LOCAL_GRP_MEMBER *mem, int num_mem)
170 slprintf(name, sizeof(name)-1, "\\%s\\%s", global_sam_name, user_name);
172 for (i = 0; i < num_mem; i++)
174 DEBUG(10,("searching against user %s...\n", mem[i].name));
175 if (strequal(mem[i].name, name))
177 DEBUG(10,("searching for user %s: found\n", name));
181 DEBUG(10,("searching for user %s: not found\n", name));
185 /*************************************************************************
186 gets an array of aliases that a user is in. use this if your database
187 does not have search facilities
188 *************************************************************************/
189 BOOL iterate_getuseraliasnam(char *user_name, LOCAL_GRP **alss, int *num_alss)
192 LOCAL_GRP_MEMBER *mem = NULL;
196 DEBUG(10, ("search for useralias by name: %s\n", user_name));
198 if (user_name == NULL || als == NULL || num_alss == NULL)
206 /* Open the alias database file - not for update. */
207 fp = startaliasent(False);
211 DEBUG(0, ("unable to open alias database.\n"));
215 /* iterate through all aliases. search members for required user */
216 while ((als = getaliasent(fp, &mem, &num_mem)) != NULL)
218 DEBUG(5,("alias name %s members: %d\n", als->name, num_mem));
219 if (num_mem != 0 && mem != NULL)
222 if (user_is_member(user_name, mem, num_mem))
224 ret = add_domain_alias(alss, num_alss, als);
238 if ((*num_alss) != 0)
240 DEBUG(10, ("found %d user aliases:\n", (*num_alss)));
247 /*************************************************************************
248 gets an array of aliases that a user is in. use this if your database
249 does not have search facilities
250 *************************************************************************/
251 BOOL enumdomaliases(LOCAL_GRP **alss, int *num_alss)
256 DEBUG(10, ("enum user aliases\n"));
258 if (als == NULL || num_alss == NULL)
266 /* Open the alias database file - not for update. */
267 fp = startaliasent(False);
271 DEBUG(0, ("unable to open alias database.\n"));
275 /* iterate through all aliases. */
276 while ((als = getaliasent(fp, NULL, NULL)) != NULL)
278 if (!add_domain_alias(alss, num_alss, als))
280 DEBUG(0,("unable to add alias while enumerating\n"));
285 if ((*num_alss) != 0)
287 DEBUG(10, ("found %d user aliases:\n", (*num_alss)));
294 /***************************************************************
295 Start to enumerate the alias database list. Returns a void pointer
296 to ensure no modification outside this module.
297 ****************************************************************/
299 void *startaliasent(BOOL update)
301 return aldb_ops->startaliasent(update);
304 /***************************************************************
305 End enumeration of the alias database list.
306 ****************************************************************/
308 void endaliasent(void *vp)
310 aldb_ops->endaliasent(vp);
313 /*************************************************************************
314 Routine to return the next entry in the alias database list.
315 *************************************************************************/
317 LOCAL_GRP *getaliasent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
319 return aldb_ops->getaliasent(vp, mem, num_mem);
322 /************************************************************************
323 Routine to add an entry to the alias database file.
324 *************************************************************************/
326 BOOL add_alias_entry(LOCAL_GRP *newals)
328 return aldb_ops->add_alias_entry(newals);
331 /************************************************************************
332 Routine to search the alias database file for an entry matching the aliasname.
333 and then replace the entry.
334 ************************************************************************/
336 BOOL mod_alias_entry(LOCAL_GRP* als)
338 return aldb_ops->mod_alias_entry(als);
341 /************************************************************************
342 Routine to search alias database by name.
343 *************************************************************************/
345 LOCAL_GRP *getaliasnam(char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
347 return aldb_ops->getaliasnam(name, mem, num_mem);
350 /************************************************************************
351 Routine to search alias database by alias rid.
352 *************************************************************************/
354 LOCAL_GRP *getaliasrid(uint32 alias_rid, LOCAL_GRP_MEMBER **mem, int *num_mem)
356 return aldb_ops->getaliasrid(alias_rid, mem, num_mem);
359 /************************************************************************
360 Routine to search alias database by gid.
361 *************************************************************************/
363 LOCAL_GRP *getaliasgid(gid_t gid, LOCAL_GRP_MEMBER **mem, int *num_mem)
365 return aldb_ops->getaliasgid(gid, mem, num_mem);
368 /*************************************************************************
369 gets an array of aliases that a user is in.
370 *************************************************************************/
371 BOOL getuseraliasnam(char *user_name, LOCAL_GRP **als, int *num_alss)
373 return aldb_ops->getuseraliasnam(user_name, als, num_alss);
376 /*************************************************************
377 initialises a LOCAL_GRP.
378 **************************************************************/
380 void aldb_init_als(LOCAL_GRP *als)
382 if (als == NULL) return;