]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
further clarify size limit related issues in sync replication (ITS#5243)
[openldap] / libraries / libldap / options.c
index debbc5b4fe67bbd6af829ed69fa071ae33f7b3a6..69f730211ea00726abc32f2fa0fe6e7d65de40f1 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,6 +28,9 @@
 #define LDAP_OPT_REBIND_PROC 0x4e814d
 #define LDAP_OPT_REBIND_PARAMS 0x4e814e
 
+#define LDAP_OPT_NEXTREF_PROC 0x4e815d
+#define LDAP_OPT_NEXTREF_PARAMS 0x4e815e
+
 static const LDAPAPIFeatureInfo features[] = {
 #ifdef LDAP_API_FEATURE_X_OPENLDAP
        {       /* OpenLDAP Extensions API Feature */
@@ -131,7 +134,6 @@ ldap_get_option(
                                return LDAP_OPT_ERROR;
                        }
 
-                       info->ldapai_api_version = LDAP_API_VERSION;
                        info->ldapai_api_version = LDAP_API_VERSION;
                        info->ldapai_protocol_version = LDAP_VERSION_MAX;
 
@@ -167,7 +169,7 @@ ldap_get_option(
 
        case LDAP_OPT_SOCKBUF:
                if( ld == NULL ) break;
-               outvalue = ld->ld_sb;
+               *(Sockbuf **)outvalue = ld->ld_sb;
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_TIMEOUT:
@@ -259,7 +261,7 @@ ldap_get_option(
                if( ld->ld_matched == NULL ) {
                        * (char **) outvalue = NULL;
                } else {
-                       * (char **) outvalue = LDAP_STRDUP(ld->ld_matched);
+                       * (char **) outvalue = LDAP_STRDUP( ld->ld_matched );
                }
 
                return LDAP_OPT_SUCCESS;
@@ -386,7 +388,8 @@ ldap_set_option(
                        LDAPControl *const *controls =
                                (LDAPControl *const *) invalue;
 
-                       ldap_controls_free( lo->ldo_sctrls );
+                       if( lo->ldo_sctrls )
+                               ldap_controls_free( lo->ldo_sctrls );
 
                        if( controls == NULL || *controls == NULL ) {
                                lo->ldo_sctrls = NULL;
@@ -405,7 +408,8 @@ ldap_set_option(
                        LDAPControl *const *controls =
                                (LDAPControl *const *) invalue;
 
-                       ldap_controls_free( lo->ldo_cctrls );
+                       if( lo->ldo_cctrls )
+                               ldap_controls_free( lo->ldo_cctrls );
 
                        if( controls == NULL || *controls == NULL ) {
                                lo->ldo_cctrls = NULL;
@@ -448,50 +452,6 @@ ldap_set_option(
                        }
                } return LDAP_OPT_SUCCESS;
 
-       /* Only accessed from inside this function by ldap_set_rebind_proc() */
-       case LDAP_OPT_REBIND_PROC: {
-                       lo->ldo_rebind_proc = (LDAP_REBIND_PROC *)invalue;              
-               } return LDAP_OPT_SUCCESS;
-       case LDAP_OPT_REBIND_PARAMS: {
-                       lo->ldo_rebind_params = (void *)invalue;                
-               } return LDAP_OPT_SUCCESS;
-       }
-
-       if(invalue == NULL) {
-               /* no place to set from */
-               return LDAP_OPT_ERROR;
-       }
-
-       /* options which cannot withstand invalue == NULL */
-
-       switch(option) {
-       case LDAP_OPT_API_INFO:
-       case LDAP_OPT_DESC:
-               /* READ ONLY */
-               break;
-
-       case LDAP_OPT_DEREF:
-               lo->ldo_deref = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_SIZELIMIT:
-               lo->ldo_sizelimit = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_TIMELIMIT:
-               lo->ldo_timelimit = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_PROTOCOL_VERSION: {
-                       int vers = * (const int *) invalue;
-                       if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
-                               /* not supported */
-                               break;
-                       }
-                       lo->ldo_version = vers;
-               } return LDAP_OPT_SUCCESS;
-
-
        case LDAP_OPT_HOST_NAME: {
                        const char *host = (const char *) invalue;
                        LDAPURLDesc *ludlist = NULL;
@@ -582,6 +542,57 @@ ldap_set_option(
                        return rc;
                }
 
+       /* Only accessed from inside this function by ldap_set_rebind_proc() */
+       case LDAP_OPT_REBIND_PROC: {
+                       lo->ldo_rebind_proc = (LDAP_REBIND_PROC *)invalue;              
+               } return LDAP_OPT_SUCCESS;
+       case LDAP_OPT_REBIND_PARAMS: {
+                       lo->ldo_rebind_params = (void *)invalue;                
+               } return LDAP_OPT_SUCCESS;
+
+       /* Only accessed from inside this function by ldap_set_nextref_proc() */
+       case LDAP_OPT_NEXTREF_PROC: {
+                       lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue;            
+               } return LDAP_OPT_SUCCESS;
+       case LDAP_OPT_NEXTREF_PARAMS: {
+                       lo->ldo_nextref_params = (void *)invalue;               
+               } return LDAP_OPT_SUCCESS;
+       }
+
+       if(invalue == NULL) {
+               /* no place to set from */
+               return LDAP_OPT_ERROR;
+       }
+
+       /* options which cannot withstand invalue == NULL */
+
+       switch(option) {
+       case LDAP_OPT_API_INFO:
+       case LDAP_OPT_DESC:
+               /* READ ONLY */
+               break;
+
+       case LDAP_OPT_DEREF:
+               lo->ldo_deref = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_SIZELIMIT:
+               lo->ldo_sizelimit = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_TIMELIMIT:
+               lo->ldo_timelimit = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_PROTOCOL_VERSION: {
+                       int vers = * (const int *) invalue;
+                       if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
+                               /* not supported */
+                               break;
+                       }
+                       lo->ldo_version = vers;
+               } return LDAP_OPT_SUCCESS;
+
        case LDAP_OPT_ERROR_NUMBER: {
                        int err = * (const int *) invalue;
 
@@ -603,24 +614,30 @@ ldap_set_option(
 
                        if( ld->ld_error ) {
                                LDAP_FREE(ld->ld_error);
+                               ld->ld_error = NULL;
                        }
 
-                       ld->ld_error = LDAP_STRDUP(err);
+                       if ( err ) {
+                               ld->ld_error = LDAP_STRDUP(err);
+                       }
                } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_MATCHED_DN: {
-                       const char *err = (const char *) invalue;
+                       const char *matched = (const char *) invalue;
 
-                       if(ld == NULL) {
+                       if (ld == NULL) {
                                /* need a struct ldap */
                                break;
                        }
 
                        if( ld->ld_matched ) {
                                LDAP_FREE(ld->ld_matched);
+                               ld->ld_matched = NULL;
                        }
 
-                       ld->ld_matched = LDAP_STRDUP(err);
+                       if ( matched ) {
+                               ld->ld_matched = LDAP_STRDUP( matched );
+                       }
                } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_REFERRAL_URLS: {
@@ -671,3 +688,14 @@ ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_PROC *proc, void *params )
        rc = ldap_set_option( ld, LDAP_OPT_REBIND_PARAMS, (void *)params );
        return rc;
 }
+
+int
+ldap_set_nextref_proc( LDAP *ld, LDAP_NEXTREF_PROC *proc, void *params )
+{
+       int rc;
+       rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PROC, (void *)proc );
+       if( rc != LDAP_OPT_SUCCESS ) return rc;
+
+       rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PARAMS, (void *)params );
+       return rc;
+}