2 Unix SMB/Netbios implementation.
4 Password and authentication handling
5 Copyright (C) Jeremy Allison 1996-1998
6 Copyright (C) Luke Kenneth Casson 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 Mass Ave, Cambridge, MA 02139, USA.
26 extern int DEBUGLEVEL;
29 * NOTE. All these functions are abstracted into a structure
30 * that points to the correct function for the selected database. JRA.
32 * the API does NOT fill in the gaps if you set an API function
33 * to NULL: it will deliberately attempt to call the NULL function.
37 static struct passgrp_ops *pwgrp_ops = NULL;
39 /***************************************************************
40 Initialise the passgrp operations.
41 ***************************************************************/
43 BOOL initialise_passgrp_db(void)
51 pwgrp_ops = nisplus_initialise_password_grp();
52 #elif defined(WITH_LDAP)
53 pwgrp_ops = ldap_initialise_password_grp();
54 #elif defined(USE_SMBUNIX_DB)
55 pwgrp_ops = unix_initialise_password_grp();
56 #elif defined(USE_SMBPASS_DB)
57 pwgrp_ops = file_initialise_password_grp();
60 return (pwgrp_ops != NULL);
64 * Functions that return/manipulate a struct smb_passwd.
67 /************************************************************************
68 Utility function to search smb passwd by rid.
69 *************************************************************************/
71 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
72 uint32 **grps, int *num_grps,
73 uint32 **alss, int *num_alss)
75 struct smb_passwd *pwd = NULL;
78 DEBUG(10, ("search by user_rid: 0x%x\n", user_rid));
80 /* Open the smb password database - not for update. */
81 fp = startsmbgrpent(False);
85 DEBUG(0, ("unable to open smb passgrp database.\n"));
89 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->user_rid != user_rid)
94 DEBUG(10, ("found by user_rid: 0x%x\n", user_rid));
101 /************************************************************************
102 Utility function to search smb passwd by uid. use this if your database
103 does not have search facilities.
104 *************************************************************************/
106 struct smb_passwd *iterate_getsmbgrpuid(uid_t unix_uid,
107 uint32 **grps, int *num_grps,
108 uint32 **alss, int *num_alss)
110 struct smb_passwd *pwd = NULL;
113 DEBUG(10, ("search by unix_uid: %x\n", (int)unix_uid));
115 /* Open the smb password database - not for update. */
116 fp = startsmbgrpent(False);
120 DEBUG(0, ("unable to open smb passgrp database.\n"));
124 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->unix_uid != unix_uid)
129 DEBUG(10, ("found by unix_uid: %x\n", (int)unix_uid));
136 /************************************************************************
137 Utility function to search smb passwd by name. use this if your database
138 does not have search facilities.
139 *************************************************************************/
141 struct smb_passwd *iterate_getsmbgrpntnam(const char *nt_name,
142 uint32 **grps, int *num_grps,
143 uint32 **alss, int *num_alss)
145 struct smb_passwd *pwd = NULL;
148 fstrcpy(name, nt_name);
150 DEBUG(10, ("search by name: %s\n", name));
152 /* Open the passgrp file - not for update. */
153 fp = startsmbgrpent(False);
157 DEBUG(0, ("unable to open smb passgrp database.\n"));
161 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->nt_name, name))
166 DEBUG(10, ("found by name: %s\n", name));
173 /***************************************************************
174 Start to enumerate the smb or sam passwd list. Returns a void pointer
175 to ensure no modification outside this module.
177 Note that currently it is being assumed that a pointer returned
178 from this function may be used to enumerate struct sam_passwd
179 entries as well as struct smb_passwd entries. This may need
182 ****************************************************************/
184 void *startsmbgrpent(BOOL update)
186 return pwgrp_ops->startsmbgrpent(update);
189 /***************************************************************
190 End enumeration of the smb or sam passwd list.
192 Note that currently it is being assumed that a pointer returned
193 from this function may be used to enumerate struct sam_passwd
194 entries as well as struct smb_passwd entries. This may need
197 ****************************************************************/
199 void endsmbgrpent(void *vp)
201 pwgrp_ops->endsmbgrpent(vp);
204 /*************************************************************************
205 Routine to return the next entry in the smb passwd list.
206 *************************************************************************/
208 struct smb_passwd *getsmbgrpent(void *vp,
209 uint32 **grps, int *num_grps,
210 uint32 **alss, int *num_alss)
212 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
215 /************************************************************************
216 Routine to search smb passwd by name.
217 *************************************************************************/
219 struct smb_passwd *getsmbgrpntnam(char *name,
220 uint32 **grps, int *num_grps,
221 uint32 **alss, int *num_alss)
223 return pwgrp_ops->getsmbgrpntnam(name, grps, num_grps, alss, num_alss);
226 /************************************************************************
227 Routine to search smb passwd by user rid.
228 *************************************************************************/
230 struct smb_passwd *getsmbgrprid(uint32 user_rid,
231 uint32 **grps, int *num_grps,
232 uint32 **alss, int *num_alss)
234 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
237 /************************************************************************
238 Routine to search smb passwd by uid.
239 *************************************************************************/
241 struct smb_passwd *getsmbgrpuid(uid_t unix_uid,
242 uint32 **grps, int *num_grps,
243 uint32 **alss, int *num_alss)
245 return pwgrp_ops->getsmbgrpuid(unix_uid, grps, num_grps, alss, num_alss);