]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/group.c
Added conn and op arguments to group backend callback.
[openldap] / servers / slapd / back-ldap / group.c
1 /* group.c - ldap backend acl group routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldap.h"
17
18
19 /* return 0 IFF op_dn is a value in member attribute
20  * of entry with gr_dn AND that entry has an objectClass
21  * value of groupOfNames
22  */
23 int
24 ldap_back_group(
25         Backend *be,
26         Connection *conn,
27         Operation *op,
28         Entry   *target,
29         const char      *gr_ndn,
30         const char      *op_ndn,
31         ObjectClass* group_oc,
32         AttributeDescription* group_at
33 )
34 {
35         struct ldapinfo *li = (struct ldapinfo *) be->be_private;    
36         int rc = 1;
37         Attribute   *attr;
38         Entry *e;
39         struct berval bv;
40         LDAPMessage     *result;
41         char *gattr[2];
42         char *filter;
43         LDAP *ld;
44
45         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
46         const char *group_oc_name = NULL;
47         const char *group_at_name = group_at->ad_cname->bv_val;
48
49         if( group_oc->soc_names && group_oc->soc_names[0] ) {
50                 group_oc_name = group_oc->soc_names[0];
51         } else {
52                 group_oc_name = group_oc->soc_oid;
53         }
54
55         if (target != NULL && strcmp(target->e_ndn, gr_ndn) == 0) {
56                 /* we already have a copy of the entry */
57                 e = target;
58
59                 if( is_entry_objectclass( e, group_oc ) ) {
60                         return(1);
61                 }
62
63                 if ((attr = attr_find(e->e_attrs, group_at)) == NULL)
64                         return(1);
65
66                 bv.bv_val = (char *) op_ndn;
67                 bv.bv_len = strlen( op_ndn );         
68                 if( value_find( group_at, attr->a_vals, &bv ) == 0  )
69                         return(1);
70
71         } else {
72                 filter = ch_malloc(sizeof("(&(objectclass=)(=))")
73                                                         + strlen(group_oc_name)
74                                                         + strlen(group_at_name)
75                                                         + strlen(op_ndn) + 1);
76                 if (filter == NULL)
77                         return(1);
78
79                 if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
80                         ch_free(filter);
81                         return(1);
82                 }
83
84                 if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) == LDAP_SUCCESS) {
85                         strcpy(filter, "(&(objectclass=");
86                         strcat(filter, group_oc_name);
87                         strcat(filter, ")(");
88                         strcat(filter, group_at_name);
89                         strcat(filter, "=");
90                         strcat(filter, op_ndn);
91                         strcat(filter, "))");
92
93                         gattr[0] = "objectclass";
94                         gattr[1] = NULL;
95                         if (ldap_search_ext_s(ld, gr_ndn, LDAP_SCOPE_BASE, filter,
96                                                                         gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
97                                                                         LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
98                         {
99                                 if (ldap_first_entry(ld, result) != NULL)
100                                         rc = 0;
101                                 ldap_msgfree(result);
102                         }
103                 }
104                 ldap_unbind(ld);
105                 ch_free(filter);
106                 return(rc);
107     }
108
109         return(0);
110 }
111