]> git.sur5r.net Git - openldap/commitdiff
print the correct search base when taken from ldaprc (ITS#4504)
authorPierangelo Masarati <ando@openldap.org>
Tue, 25 Apr 2006 22:23:00 +0000 (22:23 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 25 Apr 2006 22:23:00 +0000 (22:23 +0000)
clients/tools/ldapsearch.c
include/ldap.h
libraries/libldap/options.c

index 6eca59dbc77b01a5077019d205cbef15efeb6f05..73fdc9087ab353263a9b8e8d1a242c6d4491b113 100644 (file)
@@ -899,10 +899,16 @@ getNextPage:
        }
 
        if (ldif < 2 ) {
+               char    *realbase = base;
+
+               if ( realbase == NULL ) {
+                       ldap_get_option( ld, LDAP_OPT_DEFBASE, (void **)&realbase );
+               }
+               
                printf( "#\n" );
                printf(_("# LDAPv%d\n"), protocol);
                printf(_("# base <%s> with scope %s\n"),
-                       base ? base : "",
+                       realbase ? realbase : "(NULL)",
                        ((scope == LDAP_SCOPE_BASE) ? "baseObject"
                                : ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
                                : ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
@@ -943,6 +949,10 @@ getNextPage:
                }
 
                printf( _("\n#\n\n") );
+
+               if ( realbase && realbase != base ) {
+                       ldap_memfree( realbase );
+               }
        }
 
        if ( infile == NULL ) {
index dc9e9d2d0115d99d9731c9d167347d94d3e6c884..c9d9d574de8248163ecdcebd0a18b44e4a327524 100644 (file)
@@ -120,6 +120,7 @@ LDAP_BEGIN_DECL
 #define LDAP_OPT_URI                           0x5006
 #define LDAP_OPT_REFERRAL_URLS      0x5007  /* Referral URLs */
 #define LDAP_OPT_SOCKBUF            0x5008  /* sockbuf */
+#define LDAP_OPT_DEFBASE               0x5009  /* searchbase */
 
 /* OpenLDAP TLS options */
 #define LDAP_OPT_X_TLS                         0x6000
index 1cfd9487b7dced4c1136e3496cecdd861ada4fa1..cfc4711eb10a51b407efb9be394c54c7e931bf17 100644 (file)
@@ -230,6 +230,15 @@ ldap_get_option(
                * (char **) outvalue = ldap_url_list2urls(lo->ldo_defludp);
                return LDAP_OPT_SUCCESS;
 
+       case LDAP_OPT_DEFBASE:
+               if( lo->ldo_defbase == NULL ) {
+                       * (char **) outvalue = NULL;
+               } else {
+                       * (char **) outvalue = LDAP_STRDUP(lo->ldo_defbase);
+               }
+
+               return LDAP_OPT_SUCCESS;
+
        case LDAP_OPT_ERROR_NUMBER:
                if(ld == NULL) {
                        /* bad param */
@@ -509,7 +518,7 @@ ldap_set_option(
                                ludlist = ldap_url_duplist(
                                        ldap_int_global_options.ldo_defludp);
                                if (ludlist == NULL)
-                                       rc = LDAP_NO_MEMORY;
+                                       rc = LDAP_URL_ERR_MEM;
                        }
 
                        switch (rc) {
@@ -534,7 +543,7 @@ ldap_set_option(
                                break;
                        }
 
-                       if (rc == LDAP_OPT_SUCCESS) {
+                       if (rc == LDAP_SUCCESS) {
                                if (lo->ldo_defludp != NULL)
                                        ldap_free_urllist(lo->ldo_defludp);
                                lo->ldo_defludp = ludlist;
@@ -542,6 +551,24 @@ ldap_set_option(
                        return rc;
                }
 
+       case LDAP_OPT_DEFBASE: {
+                       const char *newbase = (const char *) invalue;
+                       char *defbase = NULL;
+
+                       if ( newbase != NULL ) {
+                               defbase = LDAP_STRDUP( newbase );
+                               if ( defbase == NULL ) return LDAP_NO_MEMORY;
+
+                       } else if ( ld != NULL ) {
+                               defbase = LDAP_STRDUP( ldap_int_global_options.ldo_defbase );
+                               if ( defbase == NULL ) return LDAP_NO_MEMORY;
+                       }
+                       
+                       if ( lo->ldo_defbase != NULL )
+                               LDAP_FREE( lo->ldo_defbase );
+                       lo->ldo_defbase = defbase;
+               } return LDAP_OPT_SUCCESS;
+
        case LDAP_OPT_ERROR_STRING: {
                        const char *err = (const char *) invalue;