modify ldap_dn2ufn() to return completely typeless UFNs

hide rest of UFN code behind #ifdef LDAP_UFN in preparation
for eventual removal.
This commit is contained in:
Kurt Zeilenga 2000-09-16 04:33:52 +00:00
parent 55ad2c9319
commit efe39c999f
5 changed files with 27 additions and 76 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
ufn = ldap_charray2str( vals, ", " );
#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;
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 )
{

View file

@ -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:

View file

@ -12,6 +12,8 @@
#include "portable.h"
#ifdef LDAP_UFN
#include <stdio.h>
#include <ac/stdlib.h>
@ -496,3 +498,5 @@ ldap_ufn_timeout( void *tvparam )
return( tv->tv_usec <= 0 ? 1 : 0 );
}
#endif