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 #ifdef SLAPD_EXTERNAL_EXTENSIONS
37 typedef struct extensions_cookie_t {
40 } extensions_cookie_t;
42 #define MAX_OID_LENGTH 128
44 typedef struct extensions_list_t {
45 struct extensions_list_t *next;
47 int (*ext_main)(int (*)(), void *, char *reqoid, struct berval *reqdata, char **rspoid, struct berval *rspdata, char **text);
50 extensions_list_t *supp_ext_list = NULL;
52 #define MAX_SUPP_EXT_TRACKED 64
53 int supp_ext_count = 0;
54 char *supportedExtensions[MAX_SUPP_EXT_TRACKED] = { NULL };
56 extensions_list_t *find_extension (extensions_list_t *list, char *oid);
57 int extensions_callback (extensions_cookie_t *cookie, int msg, int arg, void *argp);
60 char *supportedExtensions[] = {
72 int rc = LDAP_SUCCESS;
74 struct berval reqdata;
77 #ifdef SLAPD_EXTERNAL_EXTENSIONS
78 extensions_list_t *ext;
80 struct berval rspdata;
81 extensions_cookie_t cookie;
84 Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
87 reqdata.bv_val = NULL;
89 if( op->o_protocol < LDAP_VERSION3 ) {
90 Debug( LDAP_DEBUG_ANY, "do_extended: protocol version (%d) too low\n",
91 op->o_protocol, 0 ,0 );
92 send_ldap_disconnect( conn, op,
93 LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
98 if ( ber_scanf( op->o_ber, "{a" /*}*/, &reqoid ) == LBER_ERROR ) {
99 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
100 send_ldap_disconnect( conn, op,
101 LDAP_PROTOCOL_ERROR, "decoding error" );
106 #ifdef SLAPD_EXTERNAL_EXTENSIONS
107 if( !(ext = find_extension(supp_ext_list, reqoid)) )
109 if( !charray_inlist( supportedExtensions, reqoid ) )
112 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
114 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
115 NULL, "unsuppored extended operation", NULL, NULL );
119 tag = ber_peek_tag( op->o_ber, &len );
121 if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
122 if( ber_scanf( op->o_ber, "o", &reqdata ) == LBER_ERROR ) {
123 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
124 send_ldap_disconnect( conn, op,
125 LDAP_PROTOCOL_ERROR, "decoding error" );
131 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
132 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
136 Debug( LDAP_DEBUG_ARGS, "do_extended: oid \"%s\"\n", reqoid, 0 ,0 );
138 #ifdef SLAPD_EXTERNAL_EXTENSIONS
143 rspdata.bv_val = NULL;
145 rc = (ext->ext_main)(extensions_callback, &cookie, reqoid, &reqdata, &rspoid, &rspdata, &text);
147 send_ldap_extended(conn, op, rc, NULL, text, rspoid, rspdata.bv_val ? &rspdata : NULL);
151 if ( rspdata.bv_val != NULL )
152 free(rspdata.bv_val);
157 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
158 NULL, "unsupported extended operation", NULL, NULL );
163 if ( reqoid != NULL ) {
166 if ( reqdata.bv_val != NULL ) {
167 free( reqdata.bv_val );
173 #ifdef SLAPD_EXTERNAL_EXTENSIONS
178 const char *file_name
181 extensions_list_t *ext;
182 int (*ext_getoid)(int index, char *oid, int blen);
185 ext = ch_calloc(1, sizeof(extensions_list_t));
189 ext->oid = ch_malloc(MAX_OID_LENGTH);
190 if (ext->oid == NULL) {
195 ext->ext_main = module_resolve(module, "ext_main");
196 if (ext->ext_main == NULL) {
202 ext_getoid = module_resolve(module, "ext_getoid");
203 if (ext_getoid == NULL) {
208 rc = (ext_getoid)(0, ext->oid, MAX_OID_LENGTH);
214 if (*ext->oid == 0) {
220 /* supportedExtensions must be maintained for the root DSE.
221 * Unfortunately, this global var is declared extern char *[],
222 * which means it cannot grow dynamically. So, for now it is
223 * a char *[n], and only (n-1) oids are tracked. In the off
224 * chance that this is too few, the extensions will still be
225 * loaded, but not reported in root DSE info. To increase
226 * the maximum, change MAX_SUPP_EXT_TRACKED and recompile or
227 * fix root_dse.c to use something other than a static array.
229 if (supp_ext_count < (MAX_SUPP_EXT_TRACKED - 1)) {
230 supportedExtensions[supp_ext_count++] = ch_strdup(ext->oid);
231 supportedExtensions[supp_ext_count] = NULL;
234 ext->next = supp_ext_list;
240 find_extension (extensions_list_t *list, char *oid)
242 extensions_list_t *ext;
244 for (ext = list; ext; ext = ext->next) {
245 if (strcmp(ext->oid, oid) == 0)
252 extensions_callback (extensions_cookie_t *cookie, int msg, int arg, void *argp)
261 case 0: /* SLAPD_EXT_GETVERSION */
265 case 1: /* SLAPD_EXT_GETPROTO */
266 *(int *)argp = cookie->op->o_protocol;
269 case 2: /* SLAPD_EXT_GETAUTH */
270 *(int *)argp = cookie->op->o_authtype;
273 case 3: /* SLAPD_EXT_GETDN */
274 *(char **)argp = cookie->op->o_dn;
277 case 4: /* SLAPD_EXT_GETCLIENT */
278 if (cookie->conn->c_peer_domain != NULL && *cookie->conn->c_peer_domain != 0) {
279 *(char **)argp = cookie->conn->c_peer_domain;
282 if (cookie->conn->c_peer_name != NULL && *cookie->conn->c_peer_name != 0) {
283 *(char **)argp = cookie->conn->c_peer_name;