3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 * LDAPv3 Extended Operation Request
9 * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
10 * requestName [0] LDAPOID,
11 * requestValue [1] OCTET STRING OPTIONAL
14 * LDAPv3 Extended Operation Response
15 * ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
16 * COMPONENTS OF LDAPResult,
17 * responseName [10] LDAPOID OPTIONAL,
18 * response [11] OCTET STRING OPTIONAL
26 #include <ac/stdlib.h>
28 #include <ac/socket.h>
29 #include <ac/string.h>
36 ldap_extended_operation(
38 LDAP_CONST char *reqoid,
39 struct berval *reqdata,
49 LDAP_LOG ( OPERATION, ENTRY, "ldap_extended_operation\n", 0,0,0 );
51 Debug( LDAP_DEBUG_TRACE, "ldap_extended_operation\n", 0, 0, 0 );
55 assert( LDAP_VALID( ld ) );
56 assert( reqoid != NULL || *reqoid == '\0' );
57 assert( msgidp != NULL );
59 /* must be version 3 (or greater) */
60 if ( ld->ld_version < LDAP_VERSION3 ) {
61 ld->ld_errno = LDAP_NOT_SUPPORTED;
62 return( ld->ld_errno );
65 /* create a message to send */
66 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
67 ld->ld_errno = LDAP_NO_MEMORY;
68 return( ld->ld_errno );
71 LDAP_NEXT_MSGID( ld, id );
72 if ( reqdata != NULL ) {
73 rc = ber_printf( ber, "{it{tstON}", /* '}' */
74 id, LDAP_REQ_EXTENDED,
75 LDAP_TAG_EXOP_REQ_OID, reqoid,
76 LDAP_TAG_EXOP_REQ_VALUE, reqdata );
79 rc = ber_printf( ber, "{it{tsN}", /* '}' */
80 id, LDAP_REQ_EXTENDED,
81 LDAP_TAG_EXOP_REQ_OID, reqoid );
85 ld->ld_errno = LDAP_ENCODING_ERROR;
87 return( ld->ld_errno );
90 /* Put Server Controls */
91 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
96 if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
97 ld->ld_errno = LDAP_ENCODING_ERROR;
99 return( ld->ld_errno );
102 /* send the message */
103 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_EXTENDED, NULL, ber, id );
105 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
109 ldap_extended_operation_s(
111 LDAP_CONST char *reqoid,
112 struct berval *reqdata,
113 LDAPControl **sctrls,
114 LDAPControl **cctrls,
116 struct berval **retdatap )
123 LDAP_LOG ( OPERATION, ENTRY, "ldap_extended_operation_s\n", 0,0,0 );
125 Debug( LDAP_DEBUG_TRACE, "ldap_extended_operation_s\n", 0, 0, 0 );
128 assert( ld != NULL );
129 assert( LDAP_VALID( ld ) );
130 assert( reqoid != NULL || *reqoid == '\0' );
131 assert( retoidp != NULL || retdatap != NULL );
133 rc = ldap_extended_operation( ld, reqoid, reqdata,
134 sctrls, cctrls, &msgid );
136 if ( rc != LDAP_SUCCESS ) {
140 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) {
141 return( ld->ld_errno );
144 if ( retoidp != NULL ) *retoidp = NULL;
145 if ( retdatap != NULL ) *retdatap = NULL;
147 rc = ldap_parse_extended_result( ld, res, retoidp, retdatap, 0 );
149 if( rc != LDAP_SUCCESS ) {
154 return( ldap_result2error( ld, res, 1 ) );
157 /* Parse an extended result */
159 ldap_parse_extended_result (
163 struct berval **retdatap,
170 struct berval *resdata;
174 assert( ld != NULL );
175 assert( LDAP_VALID( ld ) );
176 assert( res != NULL );
179 LDAP_LOG ( OPERATION, ENTRY, "ldap_parse_extended_result\n", 0,0,0 );
181 Debug( LDAP_DEBUG_TRACE, "ldap_parse_extended_result\n", 0, 0, 0 );
184 if( ld->ld_version < LDAP_VERSION3 ) {
185 ld->ld_errno = LDAP_NOT_SUPPORTED;
189 if( res->lm_msgtype != LDAP_RES_EXTENDED ) {
190 ld->ld_errno = LDAP_PARAM_ERROR;
194 if( retoidp != NULL ) *retoidp = NULL;
195 if( retdatap != NULL ) *retdatap = NULL;
197 if ( ld->ld_error ) {
198 LDAP_FREE( ld->ld_error );
202 if ( ld->ld_matched ) {
203 LDAP_FREE( ld->ld_matched );
204 ld->ld_matched = NULL;
207 ber = ber_dup( res->lm_ber );
210 ld->ld_errno = LDAP_NO_MEMORY;
214 rc = ber_scanf( ber, "{iaa" /*}*/, &errcode,
215 &ld->ld_matched, &ld->ld_error );
217 if( rc == LBER_ERROR ) {
218 ld->ld_errno = LDAP_DECODING_ERROR;
226 tag = ber_peek_tag( ber, &len );
228 if( tag == LDAP_TAG_REFERRAL ) {
229 /* skip over referral */
230 if( ber_scanf( ber, "x" ) == LBER_ERROR ) {
231 ld->ld_errno = LDAP_DECODING_ERROR;
236 tag = ber_peek_tag( ber, &len );
239 if( tag == LDAP_TAG_EXOP_RES_OID ) {
240 /* we have a resoid */
241 if( ber_scanf( ber, "a", &resoid ) == LBER_ERROR ) {
242 ld->ld_errno = LDAP_DECODING_ERROR;
247 tag = ber_peek_tag( ber, &len );
250 if( tag == LDAP_TAG_EXOP_RES_VALUE ) {
251 /* we have a resdata */
252 if( ber_scanf( ber, "O", &resdata ) == LBER_ERROR ) {
253 ld->ld_errno = LDAP_DECODING_ERROR;
255 if( resoid != NULL ) LDAP_FREE( resoid );
262 if( retoidp != NULL ) {
268 if( retdatap != NULL ) {
271 ber_bvfree( resdata );
274 ld->ld_errno = errcode;
284 /* Parse an extended partial */
286 ldap_parse_extended_partial (
290 struct berval **retdatap,
291 LDAPControl ***serverctrls,
298 struct berval *resdata;
301 assert( ld != NULL );
302 assert( LDAP_VALID( ld ) );
303 assert( res != NULL );
306 LDAP_LOG ( OPERATION, ENTRY, "ldap_parse_extended_partial\n", 0,0,0 );
308 Debug( LDAP_DEBUG_TRACE, "ldap_parse_extended_partial\n", 0, 0, 0 );
311 if( ld->ld_version < LDAP_VERSION3 ) {
312 ld->ld_errno = LDAP_NOT_SUPPORTED;
316 if( res->lm_msgtype != LDAP_RES_EXTENDED_PARTIAL ) {
317 ld->ld_errno = LDAP_PARAM_ERROR;
321 if( retoidp != NULL ) *retoidp = NULL;
322 if( retdatap != NULL ) *retdatap = NULL;
324 ber = ber_dup( res->lm_ber );
327 ld->ld_errno = LDAP_NO_MEMORY;
331 rc = ber_scanf( ber, "{" /*}*/ );
333 if( rc == LBER_ERROR ) {
334 ld->ld_errno = LDAP_DECODING_ERROR;
342 tag = ber_peek_tag( ber, &len );
344 if( tag == LDAP_TAG_EXOP_RES_OID ) {
345 /* we have a resoid */
346 if( ber_scanf( ber, "a", &resoid ) == LBER_ERROR ) {
347 ld->ld_errno = LDAP_DECODING_ERROR;
352 tag = ber_peek_tag( ber, &len );
355 if( tag == LDAP_TAG_EXOP_RES_VALUE ) {
356 /* we have a resdata */
357 if( ber_scanf( ber, "O", &resdata ) == LBER_ERROR ) {
358 ld->ld_errno = LDAP_DECODING_ERROR;
360 if( resoid != NULL ) LDAP_FREE( resoid );
365 if ( serverctrls == NULL ) {
367 goto free_and_return;
370 if ( ber_scanf( ber, /*{*/ "}" ) == LBER_ERROR ) {
371 rc = LDAP_DECODING_ERROR;
372 goto free_and_return;
375 rc = ldap_int_get_controls( ber, serverctrls );
380 if( retoidp != NULL ) {
386 if( retdatap != NULL ) {
389 ber_bvfree( resdata );
399 #ifdef LDAP_RES_INTERMEDIATE_RESP
400 /* Parse an intermediate response result */
402 ldap_parse_intermediate_resp_result (
406 struct berval **retdatap,
413 struct berval *resdata;
417 assert( ld != NULL );
418 assert( LDAP_VALID( ld ) );
419 assert( res != NULL );
422 LDAP_LOG ( OPERATION, ENTRY, "ldap_parse_intermediate_resp_result\n", 0,0,0 );
424 Debug( LDAP_DEBUG_TRACE, "ldap_parse_intermediate_resp_result\n", 0, 0, 0 );
427 if( ld->ld_version < LDAP_VERSION3 ) {
428 ld->ld_errno = LDAP_NOT_SUPPORTED;
432 if( res->lm_msgtype != LDAP_RES_INTERMEDIATE_RESP ) {
433 ld->ld_errno = LDAP_PARAM_ERROR;
437 if( retoidp != NULL ) *retoidp = NULL;
438 if( retdatap != NULL ) *retdatap = NULL;
440 if ( ld->ld_error ) {
441 LDAP_FREE( ld->ld_error );
445 if ( ld->ld_matched ) {
446 LDAP_FREE( ld->ld_matched );
447 ld->ld_matched = NULL;
450 ber = ber_dup( res->lm_ber );
453 ld->ld_errno = LDAP_NO_MEMORY;
457 rc = ber_scanf( ber, "{iaa" /*}*/, &errcode,
458 &ld->ld_matched, &ld->ld_error );
460 if( rc == LBER_ERROR ) {
461 ld->ld_errno = LDAP_DECODING_ERROR;
469 tag = ber_peek_tag( ber, &len );
471 if( tag == LDAP_TAG_EXOP_RES_OID ) {
472 /* we have a resoid */
473 if( ber_scanf( ber, "a", &resoid ) == LBER_ERROR ) {
474 ld->ld_errno = LDAP_DECODING_ERROR;
479 tag = ber_peek_tag( ber, &len );
482 if( tag == LDAP_TAG_EXOP_RES_VALUE ) {
483 /* we have a resdata */
484 if( ber_scanf( ber, "O", &resdata ) == LBER_ERROR ) {
485 ld->ld_errno = LDAP_DECODING_ERROR;
487 if( resoid != NULL ) LDAP_FREE( resoid );
494 if( retoidp != NULL ) {
500 if( retdatap != NULL ) {
503 ber_bvfree( resdata );
506 ld->ld_errno = errcode;