]> git.sur5r.net Git - openldap/blob - servers/slapd/extended.c
(re)introduce o_connid such that STATS doesn't need c_mutex (which it
[openldap] / servers / slapd / extended.c
1 /* 
2  * Copyright 1999 The OpenLDAP Foundation.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted only
6  * as authorized by the OpenLDAP Public License.  A copy of this
7  * license is available at http://www.OpenLDAP.org/license.html or
8  * in file LICENSE in the top-level directory of the distribution.
9  */
10
11 /*
12  * LDAPv3 Extended Operation Request
13  *      ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
14  *              requestName      [0] LDAPOID,
15  *              requestValue     [1] OCTET STRING OPTIONAL
16  *      }
17  *
18  * LDAPv3 Extended Operation Response
19  *      ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
20  *              COMPONENTS OF LDAPResult,
21  *              responseName     [10] LDAPOID OPTIONAL,
22  *              response         [11] OCTET STRING OPTIONAL
23  *      }
24  *
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30 #include <ac/socket.h>
31
32 #include "slap.h"
33
34 char *supportedExtensions[] = {
35         NULL
36 };
37
38
39 int
40 do_extended(
41     Connection  *conn,
42     Operation   *op
43 )
44 {
45         int rc = LDAP_SUCCESS;
46         char* reqoid ;
47         struct berval reqdata;
48         ber_tag_t tag;
49         ber_len_t len;
50
51         Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
52
53         reqoid = NULL;
54         reqdata.bv_val = NULL;
55
56         if( op->o_protocol < LDAP_VERSION3 ) {
57                 Debug( LDAP_DEBUG_ANY, "do_extended: protocol version (%d) too low\n",
58                         op->o_protocol, 0 ,0 );
59                 send_ldap_disconnect( conn, op,
60                         LDAP_PROTOCOL_ERROR, "requires LDAPv3" );
61                 rc = -1;
62                 goto done;
63         }
64
65         if ( ber_scanf( op->o_ber, "a", &reqoid ) == LBER_ERROR ) {
66                 Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
67                 send_ldap_disconnect( conn, op,
68                         LDAP_PROTOCOL_ERROR, "decoding error" );
69                 rc = -1;
70                 goto done;
71         }
72
73         if( !charray_inlist( supportedExtensions, reqoid ) ) {
74                 Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
75                         reqoid, 0 ,0 );
76                 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
77                         NULL, "unsuppored extended operation", NULL, NULL );
78                 goto done;
79         }
80
81         tag = ber_peek_tag( op->o_ber, &len );
82         
83         if( ber_peek_tag( op->o_ber, &len ) == LDAP_TAG_EXOP_REQ_VALUE ) {
84                 if( ber_scanf( op->o_ber, "o", &reqdata ) != LBER_ERROR ) {
85                         Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
86                         send_ldap_disconnect( conn, op,
87                                 LDAP_PROTOCOL_ERROR, "decoding error" );
88                         rc = -1;
89                         goto done;
90                 }
91         }
92
93         if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
94                 Debug( LDAP_DEBUG_ANY, "do_extended: get_ctrls failed\n", 0, 0 ,0 );
95                 return rc;
96         } 
97
98         Debug( LDAP_DEBUG_ARGS, "do_extended: oid \"%s\"\n", reqoid, 0 ,0 );
99
100         send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
101                 NULL, "unsupported extended operation", NULL, NULL );
102
103 done:
104         if ( reqoid != NULL ) {
105                 free( reqoid );
106         }
107         if ( reqdata.bv_val != NULL ) {
108                 free( reqdata.bv_val );
109         }
110
111         return rc;
112 }