2 Unix SMB/Netbios implementation.
4 LDAP passgrp database for SAMBA
5 Copyright (C) Matthew Chapman 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.
30 extern int DEBUGLEVEL;
33 extern LDAP *ldap_struct;
34 extern LDAPMessage *ldap_results;
35 extern LDAPMessage *ldap_entry;
38 /***************************************************************
39 Enumerate RIDs of groups which user is a member of, of type
41 ****************************************************************/
43 static void ldappassgrp_member(char *attribute, uint32 **rids, int *numrids)
49 if((values = ldap_get_values(ldap_struct, ldap_entry, attribute))) {
50 *numrids = i = ldap_count_values(values);
51 *rids = ridlist = malloc(i * sizeof(uint32));
53 ridlist[--i] = atoi(values[i]);
55 ldap_value_free(values);
63 /***************************************************************
64 Begin/end smbgrp enumeration.
65 ****************************************************************/
67 static void *ldappassgrp_enumfirst(BOOL update)
72 ldap_search_for("&(objectclass=sambaAccount)(|(group=*)(alias=*))");
77 static void ldappassgrp_enumclose(void *vp)
83 /*************************************************************************
84 Save/restore the current position in a query
85 *************************************************************************/
87 static SMB_BIG_UINT ldappassgrp_getdbpos(void *vp)
89 return (SMB_BIG_UINT)((ulong)ldap_entry);
92 static BOOL ldappassgrp_setdbpos(void *vp, SMB_BIG_UINT tok)
94 ldap_entry = (LDAPMessage *)((ulong)tok);
99 /*************************************************************************
100 Return limited smb_passwd information, and group membership.
101 *************************************************************************/
103 static struct smb_passwd *ldappassgrp_getpwbynam(const char *name,
104 uint32 **grp_rids, int *num_grps,
105 uint32 **als_rids, int *num_alss)
107 struct smb_passwd *ret;
112 ldap_search_by_ntname(name);
113 ldappassgrp_member("group", grp_rids, num_grps);
114 ldappassgrp_member("alias", als_rids, num_alss);
121 static struct smb_passwd *ldappassgrp_getpwbyuid(uid_t userid,
122 uint32 **grp_rids, int *num_grps,
123 uint32 **als_rids, int *num_alss)
125 struct smb_passwd *ret;
130 ldap_search_by_uid(userid);
131 ldappassgrp_member("group", grp_rids, num_grps);
132 ldappassgrp_member("alias", als_rids, num_alss);
139 static struct smb_passwd *ldappassgrp_getpwbyrid(uint32 user_rid,
140 uint32 **grp_rids, int *num_grps,
141 uint32 **als_rids, int *num_alss)
143 struct smb_passwd *ret;
148 ldap_search_by_rid(user_rid);
149 ldappassgrp_member("group", grp_rids, num_grps);
150 ldappassgrp_member("alias", als_rids, num_alss);
157 static struct smb_passwd *ldappassgrp_getcurrentpw(void *vp,
158 uint32 **grp_rids, int *num_grps,
159 uint32 **als_rids, int *num_alss)
161 ldappassgrp_member("group", grp_rids, num_grps);
162 ldappassgrp_member("alias", als_rids, num_alss);
168 static struct passgrp_ops ldappassgrp_ops =
170 ldappassgrp_enumfirst,
171 ldappassgrp_enumclose,
172 ldappassgrp_getdbpos,
173 ldappassgrp_setdbpos,
175 ldappassgrp_getpwbynam,
176 ldappassgrp_getpwbyuid,
177 ldappassgrp_getpwbyrid,
178 ldappassgrp_getcurrentpw,
181 struct passgrp_ops *ldap_initialise_password_grp(void)
183 return &ldappassgrp_ops;
187 void passgrpldap_dummy_function(void);
188 void passgrpldap_dummy_function(void) { } /* stop some compilers complaining */