From: Pierangelo Masarati Date: Tue, 25 Apr 2006 22:23:00 +0000 (+0000) Subject: print the correct search base when taken from ldaprc (ITS#4504) X-Git-Tag: OPENLDAP_REL_ENG_2_4_1ALPHA~2^2~145 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8242166888046c3f0cc3287b56873f47e40a3691;p=openldap print the correct search base when taken from ldaprc (ITS#4504) --- diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 6eca59dbc7..73fdc9087a 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -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 ) { diff --git a/include/ldap.h b/include/ldap.h index dc9e9d2d01..c9d9d574de 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -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 diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 1cfd9487b7..cfc4711eb1 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -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;