]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/extended.c
Fix prev commit
[openldap] / servers / slapd / extended.c
index a9a601476e9ef5df29cd86754955e1e34951a017..0abb6db23d38036b82e1ab48c754c10f7888eee7 100644 (file)
@@ -1,12 +1,16 @@
 /* $OpenLDAP$ */
-/* 
- * Copyright 1999-2003 The OpenLDAP Foundation.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2004 The OpenLDAP Foundation.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted only
- * as authorized by the OpenLDAP Public License.  A copy of this
- * license is available at http://www.OpenLDAP.org/license.html or
- * in file LICENSE in the top-level directory of the distribution.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 /*
 #include "lber_pvt.h"
 
 #ifdef LDAP_SLAPI
-#include "slapi.h"
+#include "slapi/slapi.h"
 #endif
 
-#define UNSUPPORTED_EXTENDEDOP "unsupported extended operation"
+#define UNSUPPORTED_EXOP "unsupported extended operation"
 
 #ifdef LDAP_DEVEL
 #define SLAP_EXOP_HIDE 0x0000
@@ -56,14 +60,12 @@ static struct extop_list {
 
 static SLAP_EXTOP_MAIN_FN whoami_extop;
 
-/* this list of built-in extops is for extops that are not part
- * of backends or in external modules. essentially, this is
+/* This list of built-in extops is for extops that are not part
+ * of backends or in external modules. Essentially, this is
  * just a way to get built-in extops onto the extop list without
  * having a separate init routine for each built-in extop.
  */
-#ifdef LDAP_EXOP_X_CANCEL
 const struct berval slap_EXOP_CANCEL = BER_BVC(LDAP_EXOP_X_CANCEL);
-#endif
 const struct berval slap_EXOP_WHOAMI = BER_BVC(LDAP_EXOP_X_WHO_AM_I);
 const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD);
 const struct berval slap_EXOP_START_TLS = BER_BVC(LDAP_EXOP_START_TLS);
@@ -73,21 +75,37 @@ static struct {
        slap_mask_t flags;
        SLAP_EXTOP_MAIN_FN *ext_main;
 } builtin_extops[] = {
-#ifdef LDAP_EXOP_X_CANCEL
        { &slap_EXOP_CANCEL, SLAP_EXOP_HIDE, cancel_extop },
-#endif
        { &slap_EXOP_WHOAMI, 0, whoami_extop },
        { &slap_EXOP_MODIFY_PASSWD, 0, passwd_extop },
 #ifdef HAVE_TLS
        { &slap_EXOP_START_TLS, 0, starttls_extop },
 #endif
-       { NULL, NULL }
+       { NULL, 0, NULL }
 };
 
 
 static struct extop_list *find_extop(
        struct extop_list *list, struct berval *oid );
 
+struct berval *
+get_supported_extop (int index)
+{
+       struct extop_list *ext;
+
+       /* linear scan is slow, but this way doesn't force a
+        * big change on root_dse.c, where this routine is used.
+        */
+       for (ext = supp_ext_list; ext != NULL && --index >= 0; ext = ext->next) {
+               ; /* empty */
+       }
+
+       if (ext == NULL) return NULL;
+
+       return &ext->oid;
+}
+
+
 int exop_root_dse_info( Entry *e )
 {
        AttributeDescription *ad_supportedExtension
@@ -162,7 +180,7 @@ do_extended(
        }
 
 #ifdef LDAP_SLAPI
-       getPluginFunc( &op->ore_reqoid, &funcAddr ); /* NS-SLAPI extended operation */
+       slapi_int_get_extop_plugin( &op->ore_reqoid, &funcAddr ); /* NS-SLAPI extended operation */
        if( !funcAddr && !(ext = find_extop(supp_ext_list, &op->ore_reqoid )))
 #else
        if( !(ext = find_extop(supp_ext_list, &op->ore_reqoid )))
@@ -224,35 +242,7 @@ do_extended(
 #endif
 
 #if defined(LDAP_SLAPI)
-       if (ext != NULL) { /* OpenLDAP extended operation */
-#endif /* defined(LDAP_SLAPI) */
-
-               if (reqdata.bv_val) op->ore_reqdata = &reqdata;
-               rs->sr_err = (ext->ext_main)( op, rs );
-
-               if( rs->sr_err != SLAPD_ABANDON ) {
-                       if ( rs->sr_err == LDAP_REFERRAL && rs->sr_ref == NULL ) {
-                               rs->sr_ref = referral_rewrite( default_referral,
-                                       NULL, NULL, LDAP_SCOPE_DEFAULT );
-                       }
-
-                       send_ldap_extended( op, rs );
-
-                       ber_bvarray_free( rs->sr_ref );
-               }
-
-               if ( rs->sr_rspoid != NULL ) {
-                       free( (char *)rs->sr_rspoid );
-               }
-
-               if ( rs->sr_rspdata != NULL ) {
-                       ber_bvfree( rs->sr_rspdata );
-               }
-
-#if defined( LDAP_SLAPI )
-               goto done;  /* end of OpenLDAP extended operation */
-
-       } else { /* start of Netscape extended operation */
+       if ( funcAddr != NULL ) {
                rs->sr_err = slapi_pblock_set( pb, SLAPI_EXT_OP_REQ_OID,
                                (void *)op->ore_reqoid.bv_val);
                if ( rs->sr_err != LDAP_SUCCESS ) {
@@ -267,7 +257,7 @@ do_extended(
                        goto done;
                }
 
-               rs->sr_err = slapi_x_pblock_set_operation( pb, op );
+               rs->sr_err = slapi_int_pblock_set_operation( pb, op );
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        rs->sr_err = LDAP_OTHER;
                        goto done;
@@ -279,7 +269,7 @@ do_extended(
 
                } else if ( extop_rc == SLAPI_PLUGIN_EXTENDED_NOT_HANDLED ) {
                        rs->sr_err = LDAP_PROTOCOL_ERROR;
-                       rs->sr_text = UNSUPPORTED_EXTENDEDOP;
+                       rs->sr_text = UNSUPPORTED_EXOP;
 
                } else {
                        rs->sr_err = slapi_pblock_get( pb, SLAPI_EXT_OP_RET_OID,
@@ -311,9 +301,40 @@ done2:;
                if ( rs->sr_rspdata != NULL ) {
                        ber_bvfree( rs->sr_rspdata );
                }
-
-       } /* end of Netscape extended operation */
+       } else { /* start of OpenLDAP extended operation */
 #endif /* defined( LDAP_SLAPI ) */
+               if (reqdata.bv_val) op->ore_reqdata = &reqdata;
+               rs->sr_err = (ext->ext_main)( op, rs );
+
+               if( rs->sr_err != SLAPD_ABANDON ) {
+                       if ( rs->sr_err == LDAP_REFERRAL && rs->sr_ref == NULL ) {
+                               rs->sr_ref = referral_rewrite( default_referral,
+                                       NULL, NULL, LDAP_SCOPE_DEFAULT );
+                               if ( !rs->sr_ref ) rs->sr_ref = default_referral;
+                               if ( !rs->sr_ref ) {
+                                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                                       rs->sr_text = "referral missing";
+                               }
+                       }
+
+                       send_ldap_extended( op, rs );
+
+                       if ( rs->sr_ref != default_referral ) {
+                               ber_bvarray_free( rs->sr_ref );
+                               rs->sr_ref = NULL;
+                       }
+               }
+
+               if ( rs->sr_rspoid != NULL ) {
+                       free( (char *)rs->sr_rspoid );
+               }
+
+               if ( rs->sr_rspdata != NULL ) {
+                       ber_bvfree( rs->sr_rspdata );
+               }
+#ifdef LDAP_SLAPI
+       } /* end of OpenLDAP extended operation */
+#endif /* LDAP_SLAPI */
 
 done:
        return rs->sr_err;