2 Unix SMB/CIFS implementation.
3 Password and authentication handling
4 Copyright (C) Jeremy Allison 1996-1998
5 Copyright (C) Luke Kenneth Casson 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 Mass Ave, Cambridge, MA 02139, USA.
25 * NOTE. All these functions are abstracted into a structure
26 * that points to the correct function for the selected database. JRA.
28 * the API does NOT fill in the gaps if you set an API function
29 * to NULL: it will deliberately attempt to call the NULL function.
33 static struct passgrp_ops *pwgrp_ops;
35 /***************************************************************
36 Initialise the passgrp operations.
37 ***************************************************************/
39 BOOL initialise_passgrp_db(void)
47 pwgrp_ops = nisplus_initialise_password_grp();
48 #elif defined(WITH_LDAP)
49 pwgrp_ops = ldap_initialize_password_grp();
51 pwgrp_ops = file_initialise_password_grp();
54 return (pwgrp_ops != NULL);
58 * Functions that return/manipulate a struct smb_passwd.
61 /************************************************************************
62 Utility function to search smb passwd by rid.
63 *************************************************************************/
65 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
66 uint32 **grps, int *num_grps,
67 uint32 **alss, int *num_alss)
69 return iterate_getsmbgrpuid(pwdb_user_rid_to_uid(user_rid),
70 grps, num_grps, alss, num_alss);
73 /************************************************************************
74 Utility function to search smb passwd by uid. use this if your database
75 does not have search facilities.
76 *************************************************************************/
78 struct smb_passwd *iterate_getsmbgrpuid(uid_t smb_userid,
79 uint32 **grps, int *num_grps,
80 uint32 **alss, int *num_alss)
82 struct smb_passwd *pwd = NULL;
85 DEBUG(10, ("search by smb_userid: %x\n", (int)smb_userid));
87 /* Open the smb password database - not for update. */
88 fp = startsmbgrpent(False);
92 DEBUG(0, ("unable to open smb passgrp database.\n"));
96 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->smb_userid != smb_userid)
101 DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid));
108 /************************************************************************
109 Utility function to search smb passwd by name. use this if your database
110 does not have search facilities.
111 *************************************************************************/
113 struct smb_passwd *iterate_getsmbgrpnam(char *name,
114 uint32 **grps, int *num_grps,
115 uint32 **alss, int *num_alss)
117 struct smb_passwd *pwd = NULL;
120 DEBUG(10, ("search by name: %s\n", name));
122 /* Open the passgrp file - not for update. */
123 fp = startsmbgrpent(False);
127 DEBUG(0, ("unable to open smb passgrp database.\n"));
131 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->smb_name, name))
136 DEBUG(10, ("found by name: %s\n", name));
143 /***************************************************************
144 Start to enumerate the smb or sam passwd list. Returns a void pointer
145 to ensure no modification outside this module.
147 Note that currently it is being assumed that a pointer returned
148 from this function may be used to enumerate struct sam_passwd
149 entries as well as struct smb_passwd entries. This may need
152 ****************************************************************/
154 void *startsmbgrpent(BOOL update)
156 return pwgrp_ops->startsmbgrpent(update);
159 /***************************************************************
160 End enumeration of the smb or sam passwd list.
162 Note that currently it is being assumed that a pointer returned
163 from this function may be used to enumerate struct sam_passwd
164 entries as well as struct smb_passwd entries. This may need
167 ****************************************************************/
169 void endsmbgrpent(void *vp)
171 pwgrp_ops->endsmbgrpent(vp);
174 /*************************************************************************
175 Routine to return the next entry in the smb passwd list.
176 *************************************************************************/
178 struct smb_passwd *getsmbgrpent(void *vp,
179 uint32 **grps, int *num_grps,
180 uint32 **alss, int *num_alss)
182 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
185 /************************************************************************
186 Routine to search smb passwd by name.
187 *************************************************************************/
189 struct smb_passwd *getsmbgrpnam(char *name,
190 uint32 **grps, int *num_grps,
191 uint32 **alss, int *num_alss)
193 return pwgrp_ops->getsmbgrpnam(name, grps, num_grps, alss, num_alss);
196 /************************************************************************
197 Routine to search smb passwd by user rid.
198 *************************************************************************/
200 struct smb_passwd *getsmbgrprid(uint32 user_rid,
201 uint32 **grps, int *num_grps,
202 uint32 **alss, int *num_alss)
204 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
207 /************************************************************************
208 Routine to search smb passwd by uid.
209 *************************************************************************/
211 struct smb_passwd *getsmbgrpuid(uid_t smb_userid,
212 uint32 **grps, int *num_grps,
213 uint32 **alss, int *num_alss)
215 return pwgrp_ops->getsmbgrpuid(smb_userid, grps, num_grps, alss, num_alss);