+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;
+}
+