2 Unix SMB/Netbios implementation.
4 Pasesword and authentication handling
5 Copyright (C) Jeremy Allison 1996-1998
6 Copyright (C) Luke Kenneth Caseson Leighton 1996-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mases Ave, Cambridge, MA 02139, USA.
26 extern int DEBUGLEVEL
;
28 extern fstring global_sam_name
;
31 * NOTE. All these functions are abstracted into a structure
32 * that points to the correct function for the selected database. JRA.
35 static struct aliasdb_ops
*aldb_ops
;
37 /***************************************************************
38 Initialise the alias db operations.
39 ***************************************************************/
41 BOOL
initialise_alias_db(void)
49 aldb_ops
= nisplus_initialise_alias_db();
50 #elif defined(WITH_LDAP)
51 aldb_ops
= ldap_initialise_alias_db();
53 aldb_ops
= file_initialise_alias_db();
56 return (aldb_ops
!= NULL
);
60 * Functions that return/manipulate a LOCAL_GRP.
63 /************************************************************************
64 Utility function to search alias database by gid: the LOCAL_GRP
65 structure does not have a gid member, so we have to convert here
66 from gid to alias rid.
67 *************************************************************************/
68 LOCAL_GRP
*iterate_getaliasgid(gid_t gid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
70 return iterate_getaliasrid(pwdb_gid_to_alias_rid(gid
), mem
, num_mem
);
73 /************************************************************************
74 Utility function to search alias database by rid. use this if your database
75 does not have search facilities.
76 *************************************************************************/
77 LOCAL_GRP
*iterate_getaliasrid(uint32 rid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
79 LOCAL_GRP
*als
= NULL
;
82 DEBUG(10, ("search by rid: 0x%x\n", rid
));
84 /* Open the alias database file - not for update. */
85 fp
= startaliasent(False
);
89 DEBUG(0, ("unable to open alias database.\n"));
93 while ((als
= getaliasent(fp
, mem
, num_mem
)) != NULL
&& als
->rid
!= rid
)
99 DEBUG(10, ("found alias %s by rid: 0x%x\n", als
->name
, rid
));
106 /************************************************************************
107 Utility function to search alias database by name. use this if your database
108 does not have search facilities.
109 *************************************************************************/
110 LOCAL_GRP
*iterate_getaliasnam(char *name
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
112 LOCAL_GRP
*als
= NULL
;
115 DEBUG(10, ("search by name: %s\n", name
));
117 /* Open the alias database file - not for update. */
118 fp
= startaliasent(False
);
122 DEBUG(0, ("unable to open alias database.\n"));
126 while ((als
= getaliasent(fp
, mem
, num_mem
)) != NULL
&& !strequal(als
->name
, name
))
132 DEBUG(10, ("found by name: %s\n", name
));
139 /*************************************************************************
140 Routine to return the next entry in the smbdomainalias list.
141 *************************************************************************/
142 BOOL
add_domain_alias(LOCAL_GRP
**alss
, int *num_alss
, LOCAL_GRP
*als
)
144 if (alss
== NULL
|| num_alss
== NULL
|| als
== NULL
)
149 (*alss
) = Realloc((*alss
), ((*num_alss
)+1) * sizeof(LOCAL_GRP
));
155 DEBUG(10,("adding alias %s(%s)\n", als
->name
, als
->comment
));
157 fstrcpy((*alss
)[(*num_alss
)].name
, als
->name
);
158 fstrcpy((*alss
)[(*num_alss
)].comment
, als
->comment
);
159 (*alss
)[(*num_alss
)].rid
= als
->rid
;
166 /*************************************************************************
167 checks to see if a user is a member of a domain alias
168 *************************************************************************/
169 static BOOL
user_is_member(char *user_name
, LOCAL_GRP_MEMBER
*mem
, int num_mem
)
173 slprintf(name
, sizeof(name
)-1, "\\%s\\%s", global_sam_name
, user_name
);
175 for (i
= 0; i
< num_mem
; i
++)
177 DEBUG(10,("searching against user %s...\n", mem
[i
].name
));
178 if (strequal(mem
[i
].name
, name
))
180 DEBUG(10,("searching for user %s: found\n", name
));
184 DEBUG(10,("searching for user %s: not found\n", name
));
188 /*************************************************************************
189 gets an array of aliases that a user is in. use this if your database
190 does not have search facilities
191 *************************************************************************/
192 BOOL
iterate_getuseraliasnam(char *user_name
, LOCAL_GRP
**alss
, int *num_alss
)
195 LOCAL_GRP_MEMBER
*mem
= NULL
;
199 DEBUG(10, ("search for useralias by name: %s\n", user_name
));
201 if (user_name
== NULL
|| als
== NULL
|| num_alss
== NULL
)
209 /* Open the alias database file - not for update. */
210 fp
= startaliasent(False
);
214 DEBUG(0, ("unable to open alias database.\n"));
218 /* iterate through all aliases. search members for required user */
219 while ((als
= getaliasent(fp
, &mem
, &num_mem
)) != NULL
)
221 DEBUG(5,("alias name %s members: %d\n", als
->name
, num_mem
));
222 if (num_mem
!= 0 && mem
!= NULL
)
225 if (user_is_member(user_name
, mem
, num_mem
))
227 ret
= add_domain_alias(alss
, num_alss
, als
);
242 if ((*num_alss
) != 0)
244 DEBUG(10, ("found %d user aliases:\n", (*num_alss
)));
251 /*************************************************************************
252 gets an array of aliases that a user is in. use this if your database
253 does not have search facilities
254 *************************************************************************/
255 BOOL
enumdomaliases(LOCAL_GRP
**alss
, int *num_alss
)
260 DEBUG(10, ("enum user aliases\n"));
262 if (als
== NULL
|| num_alss
== NULL
)
270 /* Open the alias database file - not for update. */
271 fp
= startaliasent(False
);
275 DEBUG(0, ("unable to open alias database.\n"));
279 /* iterate through all aliases. */
280 while ((als
= getaliasent(fp
, NULL
, NULL
)) != NULL
)
282 if (!add_domain_alias(alss
, num_alss
, als
))
284 DEBUG(0,("unable to add alias while enumerating\n"));
289 if ((*num_alss
) != 0)
291 DEBUG(10, ("found %d user aliases:\n", (*num_alss
)));
298 /***************************************************************
299 Start to enumerate the alias database list. Returns a void pointer
300 to ensure no modification outside this module.
301 ****************************************************************/
303 void *startaliasent(BOOL update
)
305 return aldb_ops
->startaliasent(update
);
308 /***************************************************************
309 End enumeration of the alias database list.
310 ****************************************************************/
312 void endaliasent(void *vp
)
314 aldb_ops
->endaliasent(vp
);
317 /*************************************************************************
318 Routine to return the next entry in the alias database list.
319 *************************************************************************/
321 LOCAL_GRP
*getaliasent(void *vp
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
323 return aldb_ops
->getaliasent(vp
, mem
, num_mem
);
326 /************************************************************************
327 Routine to add an entry to the alias database file.
328 *************************************************************************/
330 BOOL
add_alias_entry(LOCAL_GRP
*newals
)
332 return aldb_ops
->add_alias_entry(newals
);
335 /************************************************************************
336 Routine to search the alias database file for an entry matching the aliasname.
337 and then replace the entry.
338 ************************************************************************/
340 BOOL
mod_alias_entry(LOCAL_GRP
* als
)
342 return aldb_ops
->mod_alias_entry(als
);
345 /************************************************************************
346 Routine to search alias database by name.
347 *************************************************************************/
349 LOCAL_GRP
*getaliasnam(char *name
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
351 return aldb_ops
->getaliasnam(name
, mem
, num_mem
);
354 /************************************************************************
355 Routine to search alias database by alias rid.
356 *************************************************************************/
358 LOCAL_GRP
*getaliasrid(uint32 alias_rid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
360 return aldb_ops
->getaliasrid(alias_rid
, mem
, num_mem
);
363 /************************************************************************
364 Routine to search alias database by gid.
365 *************************************************************************/
367 LOCAL_GRP
*getaliasgid(gid_t gid
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
369 return aldb_ops
->getaliasgid(gid
, mem
, num_mem
);
372 /*************************************************************************
373 gets an array of aliases that a user is in.
374 *************************************************************************/
375 BOOL
getuseraliasnam(char *user_name
, LOCAL_GRP
**als
, int *num_alss
)
377 return aldb_ops
->getuseraliasnam(user_name
, als
, num_alss
);
380 /*************************************************************
381 initialises a LOCAL_GRP.
382 **************************************************************/
384 void aldb_init_als(LOCAL_GRP
*als
)
386 if (als
== NULL
) return;