Converted to call lib/wins_srv.c:wins_srv_ip() instead of lp_wins_server()
[Samba.git] / source3 / passdb / passgrp.c
blob399a45d8a9ab9bcf5aa52b04b531c08b1177be10
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"
25 extern int DEBUGLEVEL;
28 * NOTE. All these functions are abstracted into a structure
29 * that points to the correct function for the selected database. JRA.
31 * the API does NOT fill in the gaps if you set an API function
32 * to NULL: it will deliberately attempt to call the NULL function.
36 static struct passgrp_ops *pwgrp_ops;
38 /***************************************************************
39 Initialise the passgrp operations.
40 ***************************************************************/
42 BOOL initialise_passgrp_db(void)
44 if (pwgrp_ops)
46 return True;
49 #ifdef WITH_NISPLUS
50 pwgrp_ops = nisplus_initialise_password_grp();
51 #elif defined(WITH_LDAP)
52 pwgrp_ops = ldap_initialize_password_grp();
53 #else
54 pwgrp_ops = file_initialise_password_grp();
55 #endif
57 return (pwgrp_ops != NULL);
61 * Functions that return/manipulate a struct smb_passwd.
64 /************************************************************************
65 Utility function to search smb passwd by rid.
66 *************************************************************************/
68 struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
69 uint32 **grps, int *num_grps,
70 uint32 **alss, int *num_alss)
72 return iterate_getsmbgrpuid(pwdb_user_rid_to_uid(user_rid),
73 grps, num_grps, alss, num_alss);
76 /************************************************************************
77 Utility function to search smb passwd by uid. use this if your database
78 does not have search facilities.
79 *************************************************************************/
81 struct smb_passwd *iterate_getsmbgrpuid(uid_t smb_userid,
82 uint32 **grps, int *num_grps,
83 uint32 **alss, int *num_alss)
85 struct smb_passwd *pwd = NULL;
86 void *fp = NULL;
88 DEBUG(10, ("search by smb_userid: %x\n", (int)smb_userid));
90 /* Open the smb password database - not for update. */
91 fp = startsmbgrpent(False);
93 if (fp == NULL)
95 DEBUG(0, ("unable to open smb passgrp database.\n"));
96 return NULL;
99 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->smb_userid != smb_userid)
102 if (pwd != NULL)
104 DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid));
107 endsmbgrpent(fp);
108 return pwd;
111 /************************************************************************
112 Utility function to search smb passwd by name. use this if your database
113 does not have search facilities.
114 *************************************************************************/
116 struct smb_passwd *iterate_getsmbgrpnam(char *name,
117 uint32 **grps, int *num_grps,
118 uint32 **alss, int *num_alss)
120 struct smb_passwd *pwd = NULL;
121 void *fp = NULL;
123 DEBUG(10, ("search by name: %s\n", name));
125 /* Open the passgrp file - not for update. */
126 fp = startsmbgrpent(False);
128 if (fp == NULL)
130 DEBUG(0, ("unable to open smb passgrp database.\n"));
131 return NULL;
134 while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->smb_name, name))
137 if (pwd != NULL)
139 DEBUG(10, ("found by name: %s\n", name));
142 endsmbgrpent(fp);
143 return pwd;
146 /***************************************************************
147 Start to enumerate the smb or sam passwd list. Returns a void pointer
148 to ensure no modification outside this module.
150 Note that currently it is being assumed that a pointer returned
151 from this function may be used to enumerate struct sam_passwd
152 entries as well as struct smb_passwd entries. This may need
153 to change. JRA.
155 ****************************************************************/
157 void *startsmbgrpent(BOOL update)
159 return pwgrp_ops->startsmbgrpent(update);
162 /***************************************************************
163 End enumeration of the smb or sam passwd list.
165 Note that currently it is being assumed that a pointer returned
166 from this function may be used to enumerate struct sam_passwd
167 entries as well as struct smb_passwd entries. This may need
168 to change. JRA.
170 ****************************************************************/
172 void endsmbgrpent(void *vp)
174 pwgrp_ops->endsmbgrpent(vp);
177 /*************************************************************************
178 Routine to return the next entry in the smb passwd list.
179 *************************************************************************/
181 struct smb_passwd *getsmbgrpent(void *vp,
182 uint32 **grps, int *num_grps,
183 uint32 **alss, int *num_alss)
185 return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
188 /************************************************************************
189 Routine to search smb passwd by name.
190 *************************************************************************/
192 struct smb_passwd *getsmbgrpnam(char *name,
193 uint32 **grps, int *num_grps,
194 uint32 **alss, int *num_alss)
196 return pwgrp_ops->getsmbgrpnam(name, grps, num_grps, alss, num_alss);
199 /************************************************************************
200 Routine to search smb passwd by user rid.
201 *************************************************************************/
203 struct smb_passwd *getsmbgrprid(uint32 user_rid,
204 uint32 **grps, int *num_grps,
205 uint32 **alss, int *num_alss)
207 return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
210 /************************************************************************
211 Routine to search smb passwd by uid.
212 *************************************************************************/
214 struct smb_passwd *getsmbgrpuid(uid_t smb_userid,
215 uint32 **grps, int *num_grps,
216 uint32 **alss, int *num_alss)
218 return pwgrp_ops->getsmbgrpuid(smb_userid, grps, num_grps, alss, num_alss);