Debian packaging updates from Eloy
[Samba.git] / source / passdb / passgrp.c
blobfe5b181e33c2bc0f8cfe88826c01d1c89b65a67f
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"
26 * NOTE. All these functions are abstracted into a structure
27 * that points to the correct function for the selected database. JRA.
29 * the API does NOT fill in the gaps if you set an API function
30 * to NULL: it will deliberately attempt to call the NULL function.
34 static struct passgrp_ops *pwgrp_ops;
36 /***************************************************************
37 Initialise the passgrp operations.
38 ***************************************************************/
40 BOOL initialise_passgrp_db(void)
42 if (pwgrp_ops)
44 return True;
47 #ifdef WITH_NISPLUS
48 pwgrp_ops = nisplus_initialise_password_grp();
49 #elif defined(WITH_LDAP)
50 pwgrp_ops = ldap_initialize_password_grp();
51 #else
52 pwgrp_ops = file_initialise_password_grp();
53 #endif
55 return (pwgrp_ops != NULL);
59 * Functions that return/manipulate a struct smb_passwd.
62 /************************************************************************
63 Utility function to search smb passwd by rid.
64 *************************************************************************/
66 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
67 uint32 **grps, int *num_grps,
68 uint32 **alss, int *num_alss)
70 return iterate_getsmbgrpuid(pwdb_user_rid_to_uid(user_rid),
71 grps, num_grps, alss, num_alss);
74 /************************************************************************
75 Utility function to search smb passwd by uid. use this if your database
76 does not have search facilities.
77 *************************************************************************/
79 struct smb_passwd *iterate_getsmbgrpuid(uid_t smb_userid,
80 uint32 **grps, int *num_grps,
81 uint32 **alss, int *num_alss)
83 struct smb_passwd *pwd = NULL;
84 void *fp = NULL;
86 DEBUG(10, ("search by smb_userid: %x\n", (int)smb_userid));
88 /* Open the smb password database - not for update. */
89 fp = startsmbgrpent(False);
91 if (fp == NULL)
93 DEBUG(0, ("unable to open smb passgrp database.\n"));
94 return NULL;
97 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->smb_userid != smb_userid)
100 if (pwd != NULL)
102 DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid));
105 endsmbgrpent(fp);
106 return pwd;
109 /************************************************************************
110 Utility function to search smb passwd by name. use this if your database
111 does not have search facilities.
112 *************************************************************************/
114 struct smb_passwd *iterate_getsmbgrpnam(char *name,
115 uint32 **grps, int *num_grps,
116 uint32 **alss, int *num_alss)
118 struct smb_passwd *pwd = NULL;
119 void *fp = NULL;
121 DEBUG(10, ("search by name: %s\n", name));
123 /* Open the passgrp file - not for update. */
124 fp = startsmbgrpent(False);
126 if (fp == NULL)
128 DEBUG(0, ("unable to open smb passgrp database.\n"));
129 return NULL;
132 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->smb_name, name))
135 if (pwd != NULL)
137 DEBUG(10, ("found by name: %s\n", name));
140 endsmbgrpent(fp);
141 return pwd;
144 /***************************************************************
145 Start to enumerate the smb or sam passwd list. Returns a void pointer
146 to ensure no modification outside this module.
148 Note that currently it is being assumed that a pointer returned
149 from this function may be used to enumerate struct sam_passwd
150 entries as well as struct smb_passwd entries. This may need
151 to change. JRA.
153 ****************************************************************/
155 void *startsmbgrpent(BOOL update)
157 return pwgrp_ops->startsmbgrpent(update);
160 /***************************************************************
161 End enumeration of the smb or sam passwd list.
163 Note that currently it is being assumed that a pointer returned
164 from this function may be used to enumerate struct sam_passwd
165 entries as well as struct smb_passwd entries. This may need
166 to change. JRA.
168 ****************************************************************/
170 void endsmbgrpent(void *vp)
172 pwgrp_ops->endsmbgrpent(vp);
175 /*************************************************************************
176 Routine to return the next entry in the smb passwd list.
177 *************************************************************************/
179 struct smb_passwd *getsmbgrpent(void *vp,
180 uint32 **grps, int *num_grps,
181 uint32 **alss, int *num_alss)
183 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
186 /************************************************************************
187 Routine to search smb passwd by name.
188 *************************************************************************/
190 struct smb_passwd *getsmbgrpnam(char *name,
191 uint32 **grps, int *num_grps,
192 uint32 **alss, int *num_alss)
194 return pwgrp_ops->getsmbgrpnam(name, grps, num_grps, alss, num_alss);
197 /************************************************************************
198 Routine to search smb passwd by user rid.
199 *************************************************************************/
201 struct smb_passwd *getsmbgrprid(uint32 user_rid,
202 uint32 **grps, int *num_grps,
203 uint32 **alss, int *num_alss)
205 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
208 /************************************************************************
209 Routine to search smb passwd by uid.
210 *************************************************************************/
212 struct smb_passwd *getsmbgrpuid(uid_t smb_userid,
213 uint32 **grps, int *num_grps,
214 uint32 **alss, int *num_alss)
216 return pwgrp_ops->getsmbgrpuid(smb_userid, grps, num_grps, alss, num_alss);