3 * Copyright 1999 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 );
64 static int extop_callback(
65 Connection *conn, Operation *op,
66 int msg, int arg, void *argp);
69 get_supported_extop (int index)
73 /* linear scan is slow, but this way doesn't force a
74 * big change on root_dse.c, where this routine is used.
76 for (ext = supp_ext_list; ext != NULL && --index >= 0; ext = ext->next) ;
88 int rc = LDAP_SUCCESS;
90 struct berval *reqdata;
95 struct berval *rspdata;
97 Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
102 if( op->o_protocol < LDAP_VERSION3 ) {
103 Debug( LDAP_DEBUG_ANY, "do_extended: protocol version (%d) too low\n",
104 op->o_protocol, 0 ,0 );
105 send_ldap_disconnect( conn, op,
106 LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
111 if ( ber_scanf( op->o_ber, "{a" /*}*/, &oid ) == LBER_ERROR ) {
112 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
113 send_ldap_disconnect( conn, op,
114 LDAP_PROTOCOL_ERROR, "decoding error" );
119 if( !(ext = find_extop(supp_ext_list, oid)) ) {
120 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
122 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
123 NULL, "unsupported extended operation", NULL, NULL );
127 tag = ber_peek_tag( op->o_ber, &len );
129 if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
130 if( ber_scanf( op->o_ber, "O", &reqdata ) == LBER_ERROR ) {
131 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
132 send_ldap_disconnect( conn, op,
133 LDAP_PROTOCOL_ERROR, "decoding error" );
139 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
140 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
144 Debug( LDAP_DEBUG_ARGS, "do_extended: oid=%s\n", oid, 0 ,0 );
149 rc = (ext->ext_main)( extop_callback, conn, op,
150 oid, reqdata, &rspdata, &text );
152 if( rc != SLAPD_ABANDON ) {
153 send_ldap_extended( conn, op, rc, NULL, text,
157 if ( rspdata != NULL )
158 ber_bvfree( rspdata );
164 if ( reqdata != NULL ) {
165 ber_bvfree( reqdata );
177 SLAP_EXTOP_MAIN_FN ext_main )
181 if( ext_oid == NULL || *ext_oid == '\0' ) return -1;
182 if(!ext_main) return -1;
184 ext = ch_calloc(1, sizeof(extop_list_t));
188 ext->oid = ch_strdup( ext_oid );
189 if (ext->oid == NULL) {
194 ext->ext_main = ext_main;
195 ext->next = supp_ext_list;
207 for (i = 0; builtin_extops[i].oid != NULL; i++) {
208 load_extop(builtin_extops[i].oid, builtin_extops[i].ext_main);
218 /* we allocated the memory, so we have to free it, too. */
219 while ((ext = supp_ext_list) != NULL) {
220 supp_ext_list = ext->next;
221 if (ext->oid != NULL)
228 static extop_list_t *
229 find_extop( extop_list_t *list, char *oid )
233 for (ext = list; ext; ext = ext->next) {
234 if (strcmp(ext->oid, oid) == 0)
242 Connection *conn, Operation *op,
243 int msg, int arg, void *argp)
249 case SLAPD_EXTOP_GETVERSION:
253 case SLAPD_EXTOP_GETPROTO:
254 *(int *)argp = op->o_protocol;
257 case SLAPD_EXTOP_GETAUTH:
258 *(int *)argp = op->o_authtype;
261 case SLAPD_EXTOP_GETDN:
262 *(char **)argp = op->o_dn;
265 case SLAPD_EXTOP_GETCLIENT:
266 if (conn->c_peer_domain != NULL && *conn->c_peer_domain != 0) {
267 *(char **)argp = conn->c_peer_domain;
270 if (conn->c_peer_name != NULL && *conn->c_peer_name != 0) {
271 *(char **)argp = conn->c_peer_name;