]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/controls.c
ITS#8845 Recognise control-exop compatibility
[openldap] / servers / slapd / controls.c
index 8ed1003af585beae64118411ebd30656ab2c561f..73f3acf9fddc286404ebaee6c45d6b2eba8a83af 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2017 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -330,15 +330,6 @@ register_supported_control2(const char *controloid,
 
        } else {
                if ( sc->sc_extendedopsbv ) {
-                       /* FIXME: in principle, we should rather merge
-                        * existing extops with those supported by the
-                        * new control handling implementation.
-                        * In fact, whether a control is compatible with
-                        * an extop should not be a matter of implementation.
-                        * We likely also need a means for a newly
-                        * registered extop to declare that it is
-                        * comptible with an already registered control.
-                        */
                        ber_bvarray_free( sc->sc_extendedopsbv );
                        sc->sc_extendedopsbv = NULL;
                        sc->sc_extendedops = NULL;
@@ -387,6 +378,60 @@ unregister_supported_control( const char *controloid )
 }
 #endif /* SLAP_CONFIG_DELETE */
 
+int
+register_control_exop( const char *controloid, char *exopoid )
+{
+       struct slap_control *sc = NULL;
+       BerVarray extendedopsbv;
+       char **extendedops;
+       int i;
+
+       if ( controloid == NULL || exopoid == NULL ) {
+               return LDAP_PARAM_ERROR;
+       }
+
+       for ( i = 0; slap_known_controls[ i ]; i++ ) {
+               if ( strcmp( controloid, slap_known_controls[ i ] ) == 0 ) {
+                       sc = find_ctrl( controloid );
+                       assert( sc != NULL );
+                       break;
+               }
+       }
+
+       if ( !sc ) {
+               Debug( LDAP_DEBUG_ANY, "register_control_exop: "
+                       "Control %s not registered.\n",
+                       controloid, 0, 0 );
+               return LDAP_PARAM_ERROR;
+       }
+
+       for ( i = 0; sc->sc_extendedops && sc->sc_extendedops[ i ]; i++ ) {
+               if ( strcmp( exopoid, sc->sc_extendedops[ i ] ) == 0 ) {
+                       return LDAP_SUCCESS;
+               }
+       }
+
+       extendedops = ber_memrealloc( sc->sc_extendedops, (i + 2) * sizeof( char * ) );
+       if ( extendedops == NULL ) {
+               return LDAP_NO_MEMORY;
+       }
+       sc->sc_extendedops = extendedops;
+
+       extendedopsbv = ber_memrealloc( sc->sc_extendedopsbv, (i + 2) * sizeof( struct berval ) );
+       if ( extendedopsbv == NULL ) {
+               return LDAP_NO_MEMORY;
+       }
+       sc->sc_extendedopsbv = extendedopsbv;
+
+       extendedops[ i ] = exopoid;
+       extendedops[ i+1 ] = NULL;
+
+       ber_str2bv( exopoid, 0, 1, &extendedopsbv[ i ] );
+       BER_BVZERO( &extendedopsbv[ i+1 ] );
+
+       return LDAP_SUCCESS;
+}
+
 /*
  * One-time initialization of internal controls.
  */
@@ -843,7 +888,7 @@ get_ctrls2(
 
                } else if( c->ldctl_oid == NULL ) {
                        Debug( LDAP_DEBUG_TRACE,
-                               "get_ctrls: conn %lu got emtpy OID.\n",
+                               "get_ctrls: conn %lu got empty OID.\n",
                                op->o_connid, 0, 0 );
 
                        slap_free_ctrls( op, op->o_ctrls );
@@ -1681,8 +1726,8 @@ static int parseDomainScope (
                return LDAP_PROTOCOL_ERROR;
        }
 
-       if ( BER_BVISNULL( &ctrl->ldctl_value )) {
-               rs->sr_text = "domainScope control value not empty";
+       if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
+               rs->sr_text = "domainScope control value not absent";
                return LDAP_PROTOCOL_ERROR;
        }