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
= ldap_initialise_alias_db();
47 aldb_ops
= file_initialise_alias_db();
50 return (aldb_ops
!= NULL
);
54 * Functions that return/manipulate a LOCAL_GRP.
57 /************************************************************************
58 Utility function to search alias database by gid: the LOCAL_GRP
59 structure does not have a gid member, so we have to convert here
60 from gid to alias rid.
61 *************************************************************************/
62 LOCAL_GRP
*iterate_getaliasgid(gid_t gid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
64 return iterate_getaliasrid(pwdb_gid_to_alias_rid(gid
), mem
, num_mem
);
67 /************************************************************************
68 Utility function to search alias database by rid. use this if your database
69 does not have search facilities.
70 *************************************************************************/
71 LOCAL_GRP
*iterate_getaliasrid(uint32 rid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
73 LOCAL_GRP
*als
= NULL
;
76 DEBUG(10, ("search by rid: 0x%x\n", rid
));
78 /* Open the alias database file - not for update. */
79 fp
= startaliasent(False
);
83 DEBUG(0, ("unable to open alias database.\n"));
87 while ((als
= getaliasent(fp
, mem
, num_mem
)) != NULL
&& als
->rid
!= rid
)
93 DEBUG(10, ("found alias %s by rid: 0x%x\n", als
->name
, rid
));
100 /************************************************************************
101 Utility function to search alias database by name. use this if your database
102 does not have search facilities.
103 *************************************************************************/
104 LOCAL_GRP
*iterate_getaliasnam(char *name
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
106 LOCAL_GRP
*als
= NULL
;
109 DEBUG(10, ("search by name: %s\n", name
));
111 /* Open the alias database file - not for update. */
112 fp
= startaliasent(False
);
116 DEBUG(0, ("unable to open alias database.\n"));
120 while ((als
= getaliasent(fp
, mem
, num_mem
)) != NULL
&& !strequal(als
->name
, name
))
126 DEBUG(10, ("found by name: %s\n", name
));
133 /*************************************************************************
134 Routine to return the next entry in the smbdomainalias list.
135 *************************************************************************/
136 BOOL
add_domain_alias(LOCAL_GRP
**alss
, int *num_alss
, LOCAL_GRP
*als
)
140 if (alss
== NULL
|| num_alss
== NULL
|| als
== NULL
)
143 talss
= Realloc((*alss
), ((*num_alss
)+1) * sizeof(LOCAL_GRP
));
150 DEBUG(10,("adding alias %s(%s)\n", als
->name
, als
->comment
));
152 fstrcpy((*alss
)[(*num_alss
)].name
, als
->name
);
153 fstrcpy((*alss
)[(*num_alss
)].comment
, als
->comment
);
154 (*alss
)[(*num_alss
)].rid
= als
->rid
;
161 /*************************************************************************
162 checks to see if a user is a member of a domain alias
163 *************************************************************************/
164 static BOOL
user_is_member(char *user_name
, LOCAL_GRP_MEMBER
*mem
, int num_mem
)
168 slprintf(name
, sizeof(name
)-1, "\\%s\\%s", global_sam_name
, user_name
);
170 for (i
= 0; i
< num_mem
; i
++)
172 DEBUG(10,("searching against user %s...\n", mem
[i
].name
));
173 if (strequal(mem
[i
].name
, name
))
175 DEBUG(10,("searching for user %s: found\n", name
));
179 DEBUG(10,("searching for user %s: not found\n", name
));
183 /*************************************************************************
184 gets an array of aliases that a user is in. use this if your database
185 does not have search facilities
186 *************************************************************************/
187 BOOL
iterate_getuseraliasnam(char *user_name
, LOCAL_GRP
**alss
, int *num_alss
)
190 LOCAL_GRP_MEMBER
*mem
= NULL
;
194 DEBUG(10, ("search for useralias by name: %s\n", user_name
));
196 if (user_name
== NULL
|| als
== NULL
|| num_alss
== NULL
)
204 /* Open the alias database file - not for update. */
205 fp
= startaliasent(False
);
209 DEBUG(0, ("unable to open alias database.\n"));
213 /* iterate through all aliases. search members for required user */
214 while ((als
= getaliasent(fp
, &mem
, &num_mem
)) != NULL
)
216 DEBUG(5,("alias name %s members: %d\n", als
->name
, num_mem
));
217 if (num_mem
!= 0 && mem
!= NULL
)
220 if (user_is_member(user_name
, mem
, num_mem
))
222 ret
= add_domain_alias(alss
, num_alss
, als
);
236 if ((*num_alss
) != 0)
238 DEBUG(10, ("found %d user aliases:\n", (*num_alss
)));
245 /*************************************************************************
246 gets an array of aliases that a user is in. use this if your database
247 does not have search facilities
248 *************************************************************************/
249 BOOL
enumdomaliases(LOCAL_GRP
**alss
, int *num_alss
)
254 DEBUG(10, ("enum user aliases\n"));
256 if (als
== NULL
|| num_alss
== NULL
)
264 /* Open the alias database file - not for update. */
265 fp
= startaliasent(False
);
269 DEBUG(0, ("unable to open alias database.\n"));
273 /* iterate through all aliases. */
274 while ((als
= getaliasent(fp
, NULL
, NULL
)) != NULL
)
276 if (!add_domain_alias(alss
, num_alss
, als
))
278 DEBUG(0,("unable to add alias while enumerating\n"));
283 if ((*num_alss
) != 0)
285 DEBUG(10, ("found %d user aliases:\n", (*num_alss
)));
292 /***************************************************************
293 Start to enumerate the alias database list. Returns a void pointer
294 to ensure no modification outside this module.
295 ****************************************************************/
297 void *startaliasent(BOOL update
)
299 return aldb_ops
->startaliasent(update
);
302 /***************************************************************
303 End enumeration of the alias database list.
304 ****************************************************************/
306 void endaliasent(void *vp
)
308 aldb_ops
->endaliasent(vp
);
311 /*************************************************************************
312 Routine to return the next entry in the alias database list.
313 *************************************************************************/
315 LOCAL_GRP
*getaliasent(void *vp
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
317 return aldb_ops
->getaliasent(vp
, mem
, num_mem
);
320 /************************************************************************
321 Routine to add an entry to the alias database file.
322 *************************************************************************/
324 BOOL
add_alias_entry(LOCAL_GRP
*newals
)
326 return aldb_ops
->add_alias_entry(newals
);
329 /************************************************************************
330 Routine to search the alias database file for an entry matching the aliasname.
331 and then replace the entry.
332 ************************************************************************/
334 BOOL
mod_alias_entry(LOCAL_GRP
* als
)
336 return aldb_ops
->mod_alias_entry(als
);
339 /************************************************************************
340 Routine to search alias database by name.
341 *************************************************************************/
343 LOCAL_GRP
*getaliasnam(char *name
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
345 return aldb_ops
->getaliasnam(name
, mem
, num_mem
);
348 /************************************************************************
349 Routine to search alias database by alias rid.
350 *************************************************************************/
352 LOCAL_GRP
*getaliasrid(uint32 alias_rid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
354 return aldb_ops
->getaliasrid(alias_rid
, mem
, num_mem
);
357 /************************************************************************
358 Routine to search alias database by gid.
359 *************************************************************************/
361 LOCAL_GRP
*getaliasgid(gid_t gid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
363 return aldb_ops
->getaliasgid(gid
, mem
, num_mem
);
366 /*************************************************************************
367 gets an array of aliases that a user is in.
368 *************************************************************************/
369 BOOL
getuseraliasnam(char *user_name
, LOCAL_GRP
**als
, int *num_alss
)
371 return aldb_ops
->getuseraliasnam(user_name
, als
, num_alss
);
374 /*************************************************************
375 initialises a LOCAL_GRP.
376 **************************************************************/
378 void aldb_init_als(LOCAL_GRP
*als
)
380 if (als
== NULL
) return;