This commit was manufactured by cvs2svn to create tag
[Samba.git] / source / passdb / passgrp.c
blob9a5c1f8a7d98031032a5ee0f0f190c13b9f5173d
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
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.
23 #include "includes.h"
24 #include "nterr.h"
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)
45 if (pwgrp_ops)
47 return True;
50 #ifdef WITH_NISPLUS
51 pwgrp_ops = nisplus_initialise_password_grp();
52 #elif defined(WITH_NT5LDAP)
53 pwgrp_ops = nt5ldap_initialise_password_grp();
54 #elif defined(WITH_LDAP)
55 pwgrp_ops = ldap_initialise_password_grp();
56 #elif defined(USE_SMBUNIX_DB)
57 pwgrp_ops = unix_initialise_password_grp();
58 #elif defined(USE_SMBPASS_DB)
59 pwgrp_ops = file_initialise_password_grp();
60 #endif
62 return (pwgrp_ops != NULL);
66 * Functions that return/manipulate a struct smb_passwd.
69 /************************************************************************
70 Utility function to search smb passwd by rid.
71 *************************************************************************/
73 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
74 uint32 **grps, int *num_grps,
75 uint32 **alss, int *num_alss)
77 struct smb_passwd *pwd = NULL;
78 void *fp = NULL;
80 DEBUG(10, ("search by user_rid: 0x%x\n", user_rid));
82 /* Open the smb password database - not for update. */
83 fp = startsmbgrpent(False);
85 if (fp == NULL)
87 DEBUG(0, ("unable to open smb passgrp database.\n"));
88 return NULL;
91 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->user_rid != user_rid)
94 if (pwd != NULL)
96 DEBUG(10, ("found by user_rid: 0x%x\n", user_rid));
99 endsmbgrpent(fp);
100 return pwd;
103 /************************************************************************
104 Utility function to search smb passwd by uid. use this if your database
105 does not have search facilities.
106 *************************************************************************/
108 struct smb_passwd *iterate_getsmbgrpuid(uid_t unix_uid,
109 uint32 **grps, int *num_grps,
110 uint32 **alss, int *num_alss)
112 struct smb_passwd *pwd = NULL;
113 void *fp = NULL;
115 DEBUG(10, ("search by unix_uid: %x\n", (int)unix_uid));
117 /* Open the smb password database - not for update. */
118 fp = startsmbgrpent(False);
120 if (fp == NULL)
122 DEBUG(0, ("unable to open smb passgrp database.\n"));
123 return NULL;
126 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->unix_uid != unix_uid)
129 if (pwd != NULL)
131 DEBUG(10, ("found by unix_uid: %x\n", (int)unix_uid));
134 endsmbgrpent(fp);
135 return pwd;
138 /************************************************************************
139 Utility function to search smb passwd by name. use this if your database
140 does not have search facilities.
141 *************************************************************************/
143 struct smb_passwd *iterate_getsmbgrpntnam(const char *nt_name,
144 uint32 **grps, int *num_grps,
145 uint32 **alss, int *num_alss)
147 struct smb_passwd *pwd = NULL;
148 fstring name;
149 void *fp = NULL;
150 fstrcpy(name, nt_name);
152 DEBUG(10, ("search by name: %s\n", name));
154 /* Open the passgrp file - not for update. */
155 fp = startsmbgrpent(False);
157 if (fp == NULL)
159 DEBUG(0, ("unable to open smb passgrp database.\n"));
160 return NULL;
163 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->nt_name, name))
166 if (pwd != NULL)
168 DEBUG(10, ("found by name: %s\n", name));
171 endsmbgrpent(fp);
172 return pwd;
175 /***************************************************************
176 Start to enumerate the smb or sam passwd list. Returns a void pointer
177 to ensure no modification outside this module.
179 Note that currently it is being assumed that a pointer returned
180 from this function may be used to enumerate struct sam_passwd
181 entries as well as struct smb_passwd entries. This may need
182 to change. JRA.
184 ****************************************************************/
186 void *startsmbgrpent(BOOL update)
188 return pwgrp_ops->startsmbgrpent(update);
191 /***************************************************************
192 End enumeration of the smb or sam passwd list.
194 Note that currently it is being assumed that a pointer returned
195 from this function may be used to enumerate struct sam_passwd
196 entries as well as struct smb_passwd entries. This may need
197 to change. JRA.
199 ****************************************************************/
201 void endsmbgrpent(void *vp)
203 pwgrp_ops->endsmbgrpent(vp);
206 /*************************************************************************
207 Routine to return the next entry in the smb passwd list.
208 *************************************************************************/
210 struct smb_passwd *getsmbgrpent(void *vp,
211 uint32 **grps, int *num_grps,
212 uint32 **alss, int *num_alss)
214 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
217 /************************************************************************
218 Routine to search smb passwd by name.
219 *************************************************************************/
221 struct smb_passwd *getsmbgrpntnam(char *name,
222 uint32 **grps, int *num_grps,
223 uint32 **alss, int *num_alss)
225 return pwgrp_ops->getsmbgrpntnam(name, grps, num_grps, alss, num_alss);
228 /************************************************************************
229 Routine to search smb passwd by user rid.
230 *************************************************************************/
232 struct smb_passwd *getsmbgrprid(uint32 user_rid,
233 uint32 **grps, int *num_grps,
234 uint32 **alss, int *num_alss)
236 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
239 /************************************************************************
240 Routine to search smb passwd by uid.
241 *************************************************************************/
243 struct smb_passwd *getsmbgrpuid(uid_t unix_uid,
244 uint32 **grps, int *num_grps,
245 uint32 **alss, int *num_alss)
247 return pwgrp_ops->getsmbgrpuid(unix_uid, grps, num_grps, alss, num_alss);