1 /* chain.c - chain LDAP operations */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
30 #include "back-ldap.h"
33 ldap_chain_response( Operation *op, SlapReply *rs )
35 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
36 void *private = op->o_bd->be_private;
37 slap_callback *sc = op->o_callback;
38 LDAPControl **prev = op->o_ctrls;
39 LDAPControl **ctrls = NULL, authz;
41 int cache = op->o_do_not_cache;
44 struct berval ndn = op->o_ndn;
46 if ( rs->sr_err != LDAP_REFERRAL )
47 return SLAP_CB_CONTINUE;
49 /* currently we assume only one referral destination.
50 * we'll have to parse this in the future.
55 op->o_bd->be_private = on->on_bi.bi_private;
56 op->o_callback = NULL;
58 /* Chaining is performed by a privileged user on behalf
59 * of a normal user, using the ProxyAuthz control. However,
60 * Binds are done separately, on an anonymous session.
62 if ( op->o_tag != LDAP_REQ_BIND ) {
63 for (i=0; prev && prev[i]; i++);
66 /* Add an extra NULL slot */
69 ctrls = op->o_tmpalloc((i+1)*sizeof(LDAPControl *),
71 for (i=0; i <nctrls; i++)
73 ctrls[nctrls] = &authz;
74 ctrls[nctrls+1] = NULL;
75 authz.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
76 authz.ldctl_iscritical = 1;
77 authz.ldctl_value = op->o_dn;
78 if ( op->o_dn.bv_len ) {
79 authzid = op->o_tmpalloc( op->o_dn.bv_len+4,
81 strcpy(authzid, "dn: ");
82 strcpy(authzid+4, op->o_dn.bv_val);
83 authz.ldctl_value.bv_len = op->o_dn.bv_len + 4;
84 authz.ldctl_value.bv_val = authzid;
87 op->o_ndn = op->o_bd->be_rootndn;
92 struct berval rndn = op->o_req_ndn;
93 Connection *conn = op->o_conn;
94 op->o_req_ndn = slap_empty_bv;
96 rc = ldap_back_bind( op, rs );
102 rc = ldap_back_add( op, rs );
104 case LDAP_REQ_DELETE:
105 rc = ldap_back_delete( op, rs );
107 case LDAP_REQ_MODRDN:
108 rc = ldap_back_modrdn( op, rs );
110 case LDAP_REQ_MODIFY:
111 rc = ldap_back_modify( op, rs );
113 case LDAP_REQ_COMPARE:
114 rc = ldap_back_compare( op, rs );
116 case LDAP_REQ_SEARCH:
117 rc = ldap_back_search( op, rs );
119 case LDAP_REQ_EXTENDED:
120 rc = ldap_back_extended( op, rs );
123 rc = SLAP_CB_CONTINUE;
126 op->o_do_not_cache = cache;
128 op->o_bd->be_private = private;
131 if ( ctrls ) op->o_tmpfree( ctrls, op->o_tmpmemctx );
132 if ( authzid ) op->o_tmpfree( authzid, op->o_tmpmemctx );
138 static int ldap_chain_config(
146 slap_overinst *on = (slap_overinst *) be->bd_info;
147 void *private = be->be_private;
150 be->be_private = on->on_bi.bi_private;
151 rc = ldap_back_db_config( be, fname, lineno, argc, argv );
152 be->be_private = private;
156 static int ldap_chain_init(
160 slap_overinst *on = (slap_overinst *) be->bd_info;
161 void *private = be->be_private;
164 be->be_private = NULL;
165 rc = ldap_back_db_init( be );
166 on->on_bi.bi_private = be->be_private;
167 be->be_private = private;
171 static int ldap_chain_destroy(
175 slap_overinst *on = (slap_overinst *) be->bd_info;
176 void *private = be->be_private;
179 be->be_private = on->on_bi.bi_private;
180 rc = ldap_back_db_destroy( be );
181 on->on_bi.bi_private = be->be_private;
182 be->be_private = private;
186 static slap_overinst ldapchain;
188 int ldap_chain_setup()
190 ldapchain.on_bi.bi_type = "chain";
191 ldapchain.on_bi.bi_db_init = ldap_chain_init;
192 ldapchain.on_bi.bi_db_config = ldap_chain_config;
193 ldapchain.on_bi.bi_db_destroy = ldap_chain_destroy;
194 ldapchain.on_response = ldap_chain_response;
196 return overlay_register( &ldapchain );