]> git.sur5r.net Git - openldap/blob - servers/slapd/extended.c
Merge in all devel changes since 2.0-alpha2.
[openldap] / servers / slapd / extended.c
1 /* $OpenLDAP$ */
2 /* 
3  * Copyright 1999 The OpenLDAP Foundation.
4  * All rights reserved.
5  *
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.
10  */
11
12 /*
13  * LDAPv3 Extended Operation Request
14  *      ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
15  *              requestName      [0] LDAPOID,
16  *              requestValue     [1] OCTET STRING OPTIONAL
17  *      }
18  *
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
24  *      }
25  *
26  */
27
28 #include "portable.h"
29
30 #include <stdio.h>
31 #include <ac/socket.h>
32
33 #include "slap.h"
34
35 char *supportedExtensions[] = {
36         NULL
37 };
38
39
40 int
41 do_extended(
42     Connection  *conn,
43     Operation   *op
44 )
45 {
46         int rc = LDAP_SUCCESS;
47         char* reqoid ;
48         struct berval reqdata;
49         ber_tag_t tag;
50         ber_len_t len;
51
52         Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
53
54         reqoid = NULL;
55         reqdata.bv_val = NULL;
56
57         if( op->o_protocol < LDAP_VERSION3 ) {
58                 Debug( LDAP_DEBUG_ANY, "do_extended: protocol version (%d) too low\n",
59                         op->o_protocol, 0 ,0 );
60                 send_ldap_disconnect( conn, op,
61                         LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
62                 rc = -1;
63                 goto done;
64         }
65
66         if ( ber_scanf( op->o_ber, "a", &reqoid ) == LBER_ERROR ) {
67                 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
68                 send_ldap_disconnect( conn, op,
69                         LDAP_PROTOCOL_ERROR, "decoding error" );
70                 rc = -1;
71                 goto done;
72         }
73
74         if( !charray_inlist( supportedExtensions, reqoid ) ) {
75                 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
76                         reqoid, 0 ,0 );
77                 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
78                         NULL, "unsuppored extended operation", NULL, NULL );
79                 goto done;
80         }
81
82         tag = ber_peek_tag( op->o_ber, &len );
83         
84         if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
85                 if( ber_scanf( op->o_ber, "o", &reqdata ) != LBER_ERROR ) {
86                         Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
87                         send_ldap_disconnect( conn, op,
88                                 LDAP_PROTOCOL_ERROR, "decoding error" );
89                         rc = -1;
90                         goto done;
91                 }
92         }
93
94         if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
95                 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
96                 return rc;
97         } 
98
99         Debug( LDAP_DEBUG_ARGS, "do_extended: oid \"%s\"\n", reqoid, 0 ,0 );
100
101         send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
102                 NULL, "unsupported extended operation", NULL, NULL );
103
104 done:
105         if ( reqoid != NULL ) {
106                 free( reqoid );
107         }
108         if ( reqdata.bv_val != NULL ) {
109                 free( reqdata.bv_val );
110         }
111
112         return rc;
113 }