From efe39c999f05f3c0a166501655cda4aae57db78b Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 16 Sep 2000 04:33:52 +0000 Subject: [PATCH] modify ldap_dn2ufn() to return completely typeless UFNs hide rest of UFN code behind #ifdef LDAP_UFN in preparation for eventual removal. --- clients/ud/find.c | 2 + include/ldap.h | 4 +- libraries/libldap/getdn.c | 85 ++++++--------------------------------- libraries/libldap/test.c | 8 +++- libraries/libldap/ufn.c | 4 ++ 5 files changed, 27 insertions(+), 76 deletions(-) diff --git a/clients/ud/find.c b/clients/ud/find.c index 9525c86b97..75166b85f2 100644 --- a/clients/ud/find.c +++ b/clients/ud/find.c @@ -199,6 +199,7 @@ find( char *who, int quiet ) search_attrs[k] = NULL; } +#if LDAP_UFN /* * If the user-supplied name has any commas in it, we * assume that it is a UFN, and do everything right @@ -240,6 +241,7 @@ find( char *who, int quiet ) } ldap_set_option(ld, LDAP_OPT_DEREF, &savederef); } +#endif /* * Old users of the MTS *USERDIRECTORY will likely wrap the name diff --git a/include/ldap.h b/include/ldap.h index 5b4d611ac8..4aa439fc75 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -1312,7 +1312,7 @@ ldap_search_st LDAP_P(( /* deprecated */ struct timeval *timeout, LDAPMessage **res )); - +#ifdef LDAP_UFN /* * in ufn.c * (deprecated) @@ -1361,7 +1361,7 @@ ldap_ufn_setprefix LDAP_P(( /* deprecated */ LDAP_F( int ) ldap_ufn_timeout LDAP_P(( /* deprecated */ void *tvparam )); - +#endif /* * in unbind.c diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 3ed841ab5e..3fe68f5466 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -54,88 +54,26 @@ ldap_get_dn( LDAP *ld, LDAPMessage *entry ) char * ldap_dn2ufn( LDAP_CONST char *dn ) { - char *p, *ufn, *r; - int state; + char *ufn; + char **vals; Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 ); + /* produces completely untyped UFNs */ + if( dn == NULL ) { return NULL; } - if ( ( p = ldap_utf8_strpbrk( dn, "=" ) ) == NULL ) { - return( LDAP_STRDUP( dn ) ); + vals = ldap_explode_dn( dn , 1 ); + if( vals == NULL ) { + return NULL; } - ufn = LDAP_STRDUP( ++p ); - - if( ufn == NULL ) return NULL; - -#define INQUOTE 1 -#define OUTQUOTE 2 - state = OUTQUOTE; - for ( p = ufn, r = ufn; *p; LDAP_UTF8_INCR(p) ) { - switch ( *p ) { - case '\\': - if ( p[1] != '\0' ) { - *r++ = '\\'; - LDAP_UTF8_COPY(r,++p); - LDAP_UTF8_INCR(r); - } - break; - case '"': - if ( state == INQUOTE ) - state = OUTQUOTE; - else - state = INQUOTE; - *r++ = *p; - break; + ufn = ldap_charray2str( vals, ", " ); - case ';': - case ',': - if ( state == OUTQUOTE ) - *r++ = ','; - else - *r++ = *p; - break; - - case '=': - if ( state == INQUOTE ) { - *r++ = *p; - } else { - char *rsave = r; - - *r = '\0'; - LDAP_UTF8_DECR( r ); - - while ( !ldap_utf8_isspace( r ) - && *r != ';' && *r != ',' && r > ufn ) - { - LDAP_UTF8_DECR( r ); - } - LDAP_UTF8_INCR( r ); - - if ( strcasecmp( r, "c" ) - && strcasecmp( r, "o" ) - && strcasecmp( r, "ou" ) - && strcasecmp( r, "st" ) - && strcasecmp( r, "l" ) - && strcasecmp( r, "cn" ) ) { - r = rsave; - *r++ = '='; - } - } - break; - - default: - LDAP_UTF8_COPY(r, p); - LDAP_UTF8_INCR(r); - break; - } - } - *r = '\0'; - - return( ufn ); + ldap_memvfree( vals ); + return ufn; } char ** @@ -237,6 +175,9 @@ ldap_dcedn2dn( LDAP_CONST char *dce ) return dn; } +#define INQUOTE 1 +#define OUTQUOTE 2 + static char ** explode_name( const char *name, int notypes, int is_type ) { diff --git a/libraries/libldap/test.c b/libraries/libldap/test.c index a64dfc6b45..c4f0ba5dfe 100644 --- a/libraries/libldap/test.c +++ b/libraries/libldap/test.c @@ -599,6 +599,7 @@ main( int argc, char **argv ) timeout.tv_sec = atoi( line ); break; +#ifdef LDAP_UFN case 'U': /* set ufn search prefix */ getline( line, sizeof(line), stdin, "ufn prefix? " ); ldap_ufn_setprefix( ld, line ); @@ -629,6 +630,7 @@ main( int argc, char **argv ) } free_list( types ); break; +#endif case 'l': /* URL search */ getline( line, sizeof(line), stdin, @@ -765,12 +767,14 @@ main( int argc, char **argv ) printf( " [B]ind async [c]ompare [l]URL search\n" ); printf( " [modi]fy [modr]dn [rem]ove\n" ); printf( " [res]ult [s]earch [q]uit/unbind\n\n" ); - printf( " [u]fn search [ut]fn search with timeout\n" ); +#ifdef LDAP_UFN + printf( " [u]fn search [ut]fn search with timeout [U]fn prefix\n" ); +#endif printf( " [d]ebug [e]nable cache set ms[g]id\n" ); printf( " d[n]suffix [t]imeout [v]ersion\n" ); - printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" ); printf( " [?]help [o]ptions [O]cache options\n" ); printf( " [E]xplode dn [p]arse LDAP URL\n" ); + printf( " [x]uncache entry [X]uncache request\n" ); break; default: diff --git a/libraries/libldap/ufn.c b/libraries/libldap/ufn.c index ec79348fec..343c3ba184 100644 --- a/libraries/libldap/ufn.c +++ b/libraries/libldap/ufn.c @@ -12,6 +12,8 @@ #include "portable.h" +#ifdef LDAP_UFN + #include #include @@ -496,3 +498,5 @@ ldap_ufn_timeout( void *tvparam ) return( tv->tv_usec <= 0 ? 1 : 0 ); } + +#endif \ No newline at end of file -- 2.39.5