This commit was manufactured by cvs2svn to create tag
[Samba/gbeck.git] / source / passdb / passgrp.c
blobded9ef33d2afb01d09eb1a7eb5cb3ce40a95905b
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;
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_LDAP)
53 pwgrp_ops = ldap_initialise_password_grp();
54 #else
55 pwgrp_ops = file_initialise_password_grp();
56 #endif
58 return (pwgrp_ops != NULL);
62 * Functions that return/manipulate a struct smb_passwd.
65 /************************************************************************
66 Utility function to search smb passwd by rid.
67 *************************************************************************/
69 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
70 uint32 **grps, int *num_grps,
71 uint32 **alss, int *num_alss)
73 return iterate_getsmbgrpuid(pwdb_user_rid_to_uid(user_rid),
74 grps, num_grps, alss, num_alss);
77 /************************************************************************
78 Utility function to search smb passwd by uid. use this if your database
79 does not have search facilities.
80 *************************************************************************/
82 struct smb_passwd *iterate_getsmbgrpuid(uid_t smb_userid,
83 uint32 **grps, int *num_grps,
84 uint32 **alss, int *num_alss)
86 struct smb_passwd *pwd = NULL;
87 void *fp = NULL;
89 DEBUG(10, ("search by smb_userid: %x\n", (int)smb_userid));
91 /* Open the smb password database - not for update. */
92 fp = startsmbgrpent(False);
94 if (fp == NULL)
96 DEBUG(0, ("unable to open smb passgrp database.\n"));
97 return NULL;
100 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->smb_userid != smb_userid)
103 if (pwd != NULL)
105 DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid));
108 endsmbgrpent(fp);
109 return pwd;
112 /************************************************************************
113 Utility function to search smb passwd by name. use this if your database
114 does not have search facilities.
115 *************************************************************************/
117 struct smb_passwd *iterate_getsmbgrpnam(char *name,
118 uint32 **grps, int *num_grps,
119 uint32 **alss, int *num_alss)
121 struct smb_passwd *pwd = NULL;
122 void *fp = NULL;
124 DEBUG(10, ("search by name: %s\n", name));
126 /* Open the passgrp file - not for update. */
127 fp = startsmbgrpent(False);
129 if (fp == NULL)
131 DEBUG(0, ("unable to open smb passgrp database.\n"));
132 return NULL;
135 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->smb_name, name))
138 if (pwd != NULL)
140 DEBUG(10, ("found by name: %s\n", name));
143 endsmbgrpent(fp);
144 return pwd;
147 /***************************************************************
148 Start to enumerate the smb or sam passwd list. Returns a void pointer
149 to ensure no modification outside this module.
151 Note that currently it is being assumed that a pointer returned
152 from this function may be used to enumerate struct sam_passwd
153 entries as well as struct smb_passwd entries. This may need
154 to change. JRA.
156 ****************************************************************/
158 void *startsmbgrpent(BOOL update)
160 return pwgrp_ops->startsmbgrpent(update);
163 /***************************************************************
164 End enumeration of the smb or sam passwd list.
166 Note that currently it is being assumed that a pointer returned
167 from this function may be used to enumerate struct sam_passwd
168 entries as well as struct smb_passwd entries. This may need
169 to change. JRA.
171 ****************************************************************/
173 void endsmbgrpent(void *vp)
175 pwgrp_ops->endsmbgrpent(vp);
178 /*************************************************************************
179 Routine to return the next entry in the smb passwd list.
180 *************************************************************************/
182 struct smb_passwd *getsmbgrpent(void *vp,
183 uint32 **grps, int *num_grps,
184 uint32 **alss, int *num_alss)
186 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
189 /************************************************************************
190 Routine to search smb passwd by name.
191 *************************************************************************/
193 struct smb_passwd *getsmbgrpnam(char *name,
194 uint32 **grps, int *num_grps,
195 uint32 **alss, int *num_alss)
197 return pwgrp_ops->getsmbgrpnam(name, grps, num_grps, alss, num_alss);
200 /************************************************************************
201 Routine to search smb passwd by user rid.
202 *************************************************************************/
204 struct smb_passwd *getsmbgrprid(uint32 user_rid,
205 uint32 **grps, int *num_grps,
206 uint32 **alss, int *num_alss)
208 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
211 /************************************************************************
212 Routine to search smb passwd by uid.
213 *************************************************************************/
215 struct smb_passwd *getsmbgrpuid(uid_t smb_userid,
216 uint32 **grps, int *num_grps,
217 uint32 **alss, int *num_alss)
219 return pwgrp_ops->getsmbgrpuid(smb_userid, grps, num_grps, alss, num_alss);