3 * Copyright 1999-2002 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
13 * LDAPv3 Extended Operation Request
14 * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
15 * requestName [0] LDAPOID,
16 * requestValue [1] OCTET STRING OPTIONAL
19 * LDAPv3 Extended Operation Response
20 * ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
21 * COMPONENTS OF LDAPResult,
22 * responseName [10] LDAPOID OPTIONAL,
23 * response [11] OCTET STRING OPTIONAL
31 #include <ac/socket.h>
35 static struct extop_list {
36 struct extop_list *next;
38 SLAP_EXTOP_MAIN_FN *ext_main;
39 } *supp_ext_list = NULL;
41 /* this list of built-in extops is for extops that are not part
42 * of backends or in external modules. essentially, this is
43 * just a way to get built-in extops onto the extop list without
44 * having a separate init routine for each built-in extop.
48 SLAP_EXTOP_MAIN_FN *ext_main;
49 } builtin_extops[] = {
51 { LDAP_EXOP_START_TLS, starttls_extop },
53 { LDAP_EXOP_X_MODIFY_PASSWD, passwd_extop },
58 static struct extop_list *find_extop(
59 struct extop_list *list, char *oid );
62 get_supported_extop (int index)
64 struct extop_list *ext;
66 /* linear scan is slow, but this way doesn't force a
67 * big change on root_dse.c, where this routine is used.
69 for (ext = supp_ext_list; ext != NULL && --index >= 0; ext = ext->next) {
73 if (ext == NULL) return NULL;
84 int rc = LDAP_SUCCESS;
86 struct berval *reqdata;
89 struct extop_list *ext;
93 struct berval *rspdata;
94 LDAPControl **rspctrls;
97 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
98 "do_extended: conn %d\n", conn->c_connid ));
100 Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
105 if( op->o_protocol < LDAP_VERSION3 ) {
107 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
108 "do_extended: protocol version (%d) too low.\n",
111 Debug( LDAP_DEBUG_ANY,
112 "do_extended: protocol version (%d) too low\n",
113 op->o_protocol, 0 ,0 );
115 send_ldap_disconnect( conn, op,
116 LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
121 if ( ber_scanf( op->o_ber, "{a" /*}*/, &reqoid ) == LBER_ERROR ) {
123 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
124 "do_extended: conn %d ber_scanf failed\n", conn->c_connid ));
126 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
128 send_ldap_disconnect( conn, op,
129 LDAP_PROTOCOL_ERROR, "decoding error" );
134 if( !(ext = find_extop(supp_ext_list, reqoid)) ) {
136 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
137 "do_extended: conn %d unsupported operation \"%s\"\n",
138 conn->c_connid, reqoid ));
140 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
143 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
144 NULL, "unsupported extended operation", NULL, NULL );
148 tag = ber_peek_tag( op->o_ber, &len );
150 if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
151 if( ber_scanf( op->o_ber, "O", &reqdata ) == LBER_ERROR ) {
153 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
154 "do_extended: conn %d ber_scanf failed\n", conn->c_connid ));
156 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
158 send_ldap_disconnect( conn, op,
159 LDAP_PROTOCOL_ERROR, "decoding error" );
165 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
167 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
168 "do_extended: conn %d get_ctrls failed\n", conn->c_connid ));
170 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
175 /* check for controls inappropriate for all extended operations */
176 if( get_manageDSAit( op ) == SLAP_CRITICAL_CONTROL ) {
177 send_ldap_result( conn, op,
178 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION,
179 NULL, "manageDSAit control inappropriate",
185 LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
186 "do_extended: conn %d oid=%d\n.", conn->c_connid, reqoid ));
188 Debug( LDAP_DEBUG_ARGS, "do_extended: oid=%s\n", reqoid, 0 ,0 );
197 rc = (ext->ext_main)( conn, op,
199 &rspoid, &rspdata, &rspctrls, &text, &refs );
201 if( rc != SLAPD_ABANDON ) {
202 if ( rc == LDAP_REFERRAL && refs == NULL ) {
203 refs = referral_rewrite( default_referral,
204 NULL, NULL, LDAP_SCOPE_DEFAULT );
207 send_ldap_extended( conn, op, rc, NULL, text, refs,
208 rspoid, rspdata, rspctrls );
210 bvarray_free( refs );
213 if ( rspoid != NULL ) {
217 if ( rspdata != NULL )
218 ber_bvfree( rspdata );
221 if ( reqdata != NULL ) {
222 ber_bvfree( reqdata );
224 if ( reqoid != NULL ) {
234 SLAP_EXTOP_MAIN_FN *ext_main )
236 struct extop_list *ext;
238 if( ext_oid == NULL || *ext_oid == '\0' ) return -1;
239 if(!ext_main) return -1;
241 ext = ch_calloc(1, sizeof(struct extop_list));
245 ext->oid = ch_strdup( ext_oid );
246 if (ext->oid == NULL) {
251 ext->ext_main = ext_main;
252 ext->next = supp_ext_list;
264 for (i = 0; builtin_extops[i].oid != NULL; i++) {
265 load_extop(builtin_extops[i].oid, builtin_extops[i].ext_main);
273 struct extop_list *ext;
275 /* we allocated the memory, so we have to free it, too. */
276 while ((ext = supp_ext_list) != NULL) {
277 supp_ext_list = ext->next;
278 if (ext->oid != NULL)
285 static struct extop_list *
286 find_extop( struct extop_list *list, char *oid )
288 struct extop_list *ext;
290 for (ext = list; ext; ext = ext->next) {
291 if (strcmp(ext->oid, oid) == 0)