3 Unix SMB/Netbios implementation.
5 LDAP builtin group database for SAMBA
6 Copyright (C) Matthew Chapman 1998
7 Copyright (C) Luke Howard 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 extern int DEBUGLEVEL
;
36 /* Static structure filled for requests */
37 static LOCAL_GRP localgrp
;
40 /***************************************************************
41 Begin/end smbgrp enumeration.
42 ****************************************************************/
45 nt5ldapbuiltin_enumfirst (BOOL update
)
47 LDAPDB_DECLARE_HANDLE (hds
);
50 if (!ldapdb_open (&hds
))
55 slprintf (filter
, sizeof (filter
) - 1, "(&(objectClass=Group)(groupType=%d))",
56 NTDS_GROUP_TYPE_BUILTIN_GROUP
| NTDS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
| NTDS_GROUP_TYPE_SECURITY_ENABLED
);
57 if (!ldapdb_search (hds
, NULL
, filter
, NULL
, LDAP_NO_LIMIT
))
67 nt5ldapbuiltin_enumclose (void *vp
)
69 LDAPDB
*hds
= (LDAPDB
*) vp
;
76 /*************************************************************************
77 Save/restore the current position in a query
78 *************************************************************************/
81 nt5ldapbuiltin_getdbpos (void *vp
)
87 nt5ldapbuiltin_setdbpos (void *vp
, SMB_BIG_UINT tok
)
93 /*************************************************************************
94 Return limited smb_passwd information, and group membership.
95 *************************************************************************/
98 nt5ldapbuiltin_getgrpbynam (const char *name
,
99 LOCAL_GRP_MEMBER
** members
, int *num_membs
)
103 LDAPDB_DECLARE_HANDLE (hds
);
105 if (!ldapdb_open (&hds
))
110 slprintf (filter
, sizeof (filter
) - 1,
111 "(&(objectClass=Group)(sAMAccountName=%s)(groupType=%d))", name
,
112 NTDS_GROUP_TYPE_BUILTIN_GROUP
| NTDS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
| NTDS_GROUP_TYPE_SECURITY_ENABLED
);
113 if (!ldapdb_search (hds
, NULL
, filter
, NULL
, 1))
119 ret
= nt5ldap_make_local_grp (hds
, &localgrp
, members
, num_membs
, NTDS_GROUP_TYPE_BUILTIN_GROUP
);
123 return ret
? &localgrp
: NULL
;
127 nt5ldapbuiltin_getgrpbygid (gid_t grp_id
,
128 LOCAL_GRP_MEMBER
** members
, int *num_membs
)
132 LDAPDB_DECLARE_HANDLE (hds
);
134 if (!ldapdb_open (&hds
))
139 slprintf (filter
, sizeof (filter
) - 1,
140 "(&(objectClass=Group)(gidNumber=%d)(groupType=%d))", grp_id
,
141 NTDS_GROUP_TYPE_BUILTIN_GROUP
| NTDS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
| NTDS_GROUP_TYPE_SECURITY_ENABLED
);
142 if (!ldapdb_search (hds
, NULL
, filter
, NULL
, 1))
148 ret
= nt5ldap_make_local_grp (hds
, &localgrp
, members
, num_membs
, NTDS_GROUP_TYPE_BUILTIN_GROUP
);
152 return ret
? &localgrp
: NULL
;
156 nt5ldapbuiltin_getgrpbyrid (uint32 grp_rid
,
157 LOCAL_GRP_MEMBER
** members
, int *num_membs
)
162 LDAPDB_DECLARE_HANDLE (hds
);
164 if (!ldapdb_make_rid_filter ("objectSid", grp_rid
, sidfilter
))
169 if (!ldapdb_open (&hds
))
174 slprintf (filter
, sizeof (filter
) - 1,
175 "(&(objectClass=Group)(%s)(groupType=%d))", sidfilter
,
176 NTDS_GROUP_TYPE_BUILTIN_GROUP
| NTDS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
| NTDS_GROUP_TYPE_SECURITY_ENABLED
);
177 if (!ldapdb_search (hds
, NULL
, filter
, NULL
, 1))
183 ret
= nt5ldap_make_local_grp (hds
, &localgrp
, members
, num_membs
, NTDS_GROUP_TYPE_BUILTIN_GROUP
);
187 return ret
? &localgrp
: NULL
;
191 nt5ldapbuiltin_getcurrentgrp (void *vp
,
192 LOCAL_GRP_MEMBER
** members
, int *num_membs
)
198 if ((ret
= nt5ldap_make_local_grp ((LDAPDB
*)vp
, &localgrp
, members
, num_membs
, NTDS_GROUP_TYPE_BUILTIN_GROUP
)))
201 while (ldapdb_seq((LDAPDB
*)vp
) == True
);
203 return ret
? &localgrp
: NULL
;
207 /*************************************************************************
208 Add/modify/delete builtin aliases.
209 *************************************************************************/
212 nt5ldapbuiltin_addgrp (LOCAL_GRP
* group
)
214 LDAPMod
**mods
= NULL
;
215 LDAPDB_DECLARE_HANDLE (hds
);
218 if (!ldapdb_open (&hds
))
223 if (!ldapdb_allocate_rid (hds
, &group
->rid
))
225 DEBUG (0, ("RID generation failed\n"));
229 if (!nt5ldap_local_grp_mods (group
, &mods
, LDAP_MOD_ADD
, NTDS_GROUP_TYPE_BUILTIN_GROUP
))
235 ret
= ldapdb_update (hds
, lp_ldap_builtin_subcontext (), "cn", group
->name
, mods
, True
);
244 nt5ldapbuiltin_modgrp (LOCAL_GRP
* group
)
246 LDAPMod
**mods
= NULL
;
247 LDAPDB_DECLARE_HANDLE (hds
);
250 if (!ldapdb_open (&hds
))
255 if (!nt5ldap_local_grp_mods (group
, &mods
, LDAP_MOD_REPLACE
, NTDS_GROUP_TYPE_BUILTIN_GROUP
))
261 ret
= ldapdb_update (hds
, lp_ldap_builtin_subcontext (), "cn", group
->name
, mods
, False
);
270 nt5ldapbuiltin_delgrp (uint32 grp_rid
)
273 LDAPDB_DECLARE_HANDLE (hds
);
276 if (!ldapdb_open (&hds
))
281 if (!ldapdb_rid_to_dn (hds
, grp_rid
, dn
))
287 ret
= ldapdb_delete (hds
, dn
);
295 /*************************************************************************
296 Add users to/remove users from aliases.
297 *************************************************************************/
300 nt5ldapbuiltin_addmem (uint32 grp_rid
, const DOM_SID
* user_sid
)
302 LDAPMod
**mods
= NULL
;
303 LDAPDB_DECLARE_HANDLE (hds
);
305 pstring userdn
, groupdn
;
307 if (!ldapdb_open (&hds
))
312 if (!ldapdb_rid_to_dn (hds
, grp_rid
, groupdn
))
318 if (!nt5ldap_local_grp_member_mods (user_sid
, &mods
, LDAP_MOD_ADD
, userdn
))
324 ret
= ldapdb_commit (hds
, groupdn
, mods
, False
);
330 ret
= ldapdb_queue_mod (&mods
, LDAP_MOD_ADD
, "memberOf", groupdn
) &&
331 ldapdb_commit (hds
, userdn
, mods
, False
);
340 nt5ldapbuiltin_delmem (uint32 grp_rid
, const DOM_SID
* user_sid
)
342 LDAPMod
**mods
= NULL
;
343 LDAPDB_DECLARE_HANDLE (hds
);
345 pstring userdn
, groupdn
;
347 if (!ldapdb_open (&hds
))
352 if (!ldapdb_rid_to_dn (hds
, grp_rid
, groupdn
))
358 if (!nt5ldap_local_grp_member_mods (user_sid
, &mods
, LDAP_MOD_DELETE
, userdn
))
364 ret
= ldapdb_commit (hds
, groupdn
, mods
, False
);
370 ret
= ldapdb_queue_mod (&mods
, LDAP_MOD_DELETE
, "memberOf", groupdn
) &&
371 ldapdb_commit (hds
, userdn
, mods
, False
);
380 /*************************************************************************
381 Return builtin aliases that a user is in.
382 *************************************************************************/
385 nt5ldapbuiltin_getusergroups (const char *name
, LOCAL_GRP
** groups
,
388 LOCAL_GRP
*grouplist
;
392 LDAPDB_DECLARE_HANDLE (hds
);
394 if (!ldapdb_open (&hds
))
399 if (!ldapdb_ntname_to_dn (hds
, name
, dn
))
405 slprintf (filter
, sizeof (pstring
) - 1, "(&(objectclass=Group)(member=%s)(groupType=%d))", dn
,
406 NTDS_GROUP_TYPE_BUILTIN_GROUP
| NTDS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
| NTDS_GROUP_TYPE_SECURITY_ENABLED
);
408 (void) ldapdb_set_synchronous (hds
, True
);
409 if (!ldapdb_search (hds
, NULL
, filter
, NULL
, LDAP_NO_LIMIT
))
415 if (!ldapdb_count_entries (hds
, &ngroups
))
421 grouplist
= calloc (ngroups
, sizeof (LOCAL_GRP
));
422 if (grouplist
== NULL
)
430 for (i
= 0; i
< ngroups
; i
++)
432 if (nt5ldap_make_local_grp (hds
, &grouplist
[*num_grps
], NULL
, NULL
, NTDS_GROUP_TYPE_BUILTIN_GROUP
))
436 if (!ldapdb_seq (hds
))
450 static struct aliasdb_ops nt5ldapbuiltin_ops
=
452 nt5ldapbuiltin_enumfirst
,
453 nt5ldapbuiltin_enumclose
,
454 nt5ldapbuiltin_getdbpos
,
455 nt5ldapbuiltin_setdbpos
,
457 nt5ldapbuiltin_getgrpbynam
,
458 nt5ldapbuiltin_getgrpbygid
,
459 nt5ldapbuiltin_getgrpbyrid
,
460 nt5ldapbuiltin_getcurrentgrp
,
462 nt5ldapbuiltin_addgrp
,
463 nt5ldapbuiltin_modgrp
,
464 nt5ldapbuiltin_delgrp
,
466 nt5ldapbuiltin_addmem
,
467 nt5ldapbuiltin_delmem
,
469 nt5ldapbuiltin_getusergroups
473 nt5ldap_initialise_builtin_db (void)
475 return &nt5ldapbuiltin_ops
;
479 void builtinnt5ldap_dummy_function (void);
481 builtinnt5ldap_dummy_function (void)
483 } /* stop some compilers complaining */