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 #define DBGC_CLASS DBGC_PASSDB
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)
50 pwgrp_ops
= nisplus_initialise_password_grp();
51 #elif defined(WITH_LDAP)
52 pwgrp_ops
= ldap_initialize_password_grp();
54 pwgrp_ops
= file_initialise_password_grp();
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
;
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
);
95 DEBUG(0, ("unable to open smb passgrp database.\n"));
99 while ((pwd
= getsmbgrpent(fp
, grps
, num_grps
, alss
, num_alss
)) != NULL
&& pwd
->smb_userid
!= smb_userid
)
104 DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid
));
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
;
123 DEBUG(10, ("search by name: %s\n", name
));
125 /* Open the passgrp file - not for update. */
126 fp
= startsmbgrpent(False
);
130 DEBUG(0, ("unable to open smb passgrp database.\n"));
134 while ((pwd
= getsmbgrpent(fp
, grps
, num_grps
, alss
, num_alss
)) != NULL
&& !strequal(pwd
->smb_name
, name
))
139 DEBUG(10, ("found by name: %s\n", name
));
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
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
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
);