3 * Copyright 1999-2000 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 #define MAX_OID_LENGTH 128
37 typedef struct extop_list_t {
38 struct extop_list_t *next;
40 SLAP_EXTOP_MAIN_FN ext_main;
43 extop_list_t *supp_ext_list = NULL;
45 /* this list of built-in extops is for extops that are not part
46 * of backends or in external modules. essentially, this is
47 * just a way to get built-in extops onto the extop list without
48 * having a separate init routine for each built-in extop.
52 SLAP_EXTOP_MAIN_FN ext_main;
53 } builtin_extops[] = {
55 { LDAP_EXOP_START_TLS, starttls_extop },
57 { LDAP_EXOP_X_MODIFY_PASSWD, passwd_extop },
62 static extop_list_t *find_extop( extop_list_t *list, char *oid );
65 get_supported_extop (int index)
69 /* linear scan is slow, but this way doesn't force a
70 * big change on root_dse.c, where this routine is used.
72 for (ext = supp_ext_list; ext != NULL && --index >= 0; ext = ext->next) ;
84 int rc = LDAP_SUCCESS;
86 struct berval *reqdata;
93 struct berval *rspdata;
94 LDAPControl **rspctrls;
96 Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
101 if( op->o_protocol < LDAP_VERSION3 ) {
102 Debug( LDAP_DEBUG_ANY, "do_extended: protocol version (%d) too low\n",
103 op->o_protocol, 0 ,0 );
104 send_ldap_disconnect( conn, op,
105 LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
110 if ( ber_scanf( op->o_ber, "{a" /*}*/, &reqoid ) == LBER_ERROR ) {
111 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
112 send_ldap_disconnect( conn, op,
113 LDAP_PROTOCOL_ERROR, "decoding error" );
118 if( !(ext = find_extop(supp_ext_list, reqoid)) ) {
119 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
121 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
122 NULL, "unsupported extended operation", NULL, NULL );
126 tag = ber_peek_tag( op->o_ber, &len );
128 if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
129 if( ber_scanf( op->o_ber, "O", &reqdata ) == LBER_ERROR ) {
130 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
131 send_ldap_disconnect( conn, op,
132 LDAP_PROTOCOL_ERROR, "decoding error" );
138 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
139 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
143 Debug( LDAP_DEBUG_ARGS, "do_extended: oid=%s\n", reqoid, 0 ,0 );
151 rc = (ext->ext_main)( conn, op,
153 &rspoid, &rspdata, &rspctrls, &text, &refs );
155 if( rc != SLAPD_ABANDON ) {
156 if (rc == LDAP_REFERRAL) {
157 refs = default_referral;
160 send_ldap_extended( conn, op, rc, NULL, text, refs,
161 rspoid, rspdata, rspctrls );
164 if ( rspoid != NULL ) {
168 if ( rspdata != NULL )
169 ber_bvfree( rspdata );
172 if ( reqdata != NULL ) {
173 ber_bvfree( reqdata );
175 if ( reqoid != NULL ) {
185 SLAP_EXTOP_MAIN_FN ext_main )
189 if( ext_oid == NULL || *ext_oid == '\0' ) return -1;
190 if(!ext_main) return -1;
192 ext = ch_calloc(1, sizeof(extop_list_t));
196 ext->oid = ch_strdup( ext_oid );
197 if (ext->oid == NULL) {
202 ext->ext_main = ext_main;
203 ext->next = supp_ext_list;
215 for (i = 0; builtin_extops[i].oid != NULL; i++) {
216 load_extop(builtin_extops[i].oid, builtin_extops[i].ext_main);
226 /* we allocated the memory, so we have to free it, too. */
227 while ((ext = supp_ext_list) != NULL) {
228 supp_ext_list = ext->next;
229 if (ext->oid != NULL)
236 static extop_list_t *
237 find_extop( extop_list_t *list, char *oid )
241 for (ext = list; ext; ext = ext->next) {
242 if (strcmp(ext->oid, oid) == 0)