X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Ffetch.c;h=039d0866761155963a3d17a1e80a366221a0c15b;hb=198879bd5f1baa09e5dc7a951db980a932cd5db5;hp=a182b3591a6324ef1ccfe308b5e4e84e9922dc74;hpb=570126dc25ef430f5e0abe4081f50fe517186557;p=openldap diff --git a/libraries/liblutil/fetch.c b/libraries/liblutil/fetch.c index a182b3591a..039d086676 100644 --- a/libraries/liblutil/fetch.c +++ b/libraries/liblutil/fetch.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2005 The OpenLDAP Foundation. + * Copyright 1999-2009 The OpenLDAP Foundation. * Portions Copyright 1999-2003 Kurt D. Zeilenga. * All rights reserved. * @@ -43,31 +43,40 @@ ldif_open_url( LDAP_CONST char *urlstr ) { FILE *url; - char *p = NULL; -#ifdef HAVE_FETCH - url = fetchGetURL( (char*) urlstr, "" ); -#else - if( strncasecmp( "file://", urlstr, sizeof("file://")-1 ) == 0 ) { - p = strchr( &urlstr[sizeof("file://")-1], '/' ); - if( p == NULL ) { - return NULL; - } + if( strncasecmp( "file:", urlstr, sizeof("file:")-1 ) == 0 ) { + char *p; + urlstr += sizeof("file:")-1; /* we don't check for LDAP_DIRSEP since URLs should contain '/' */ - /* skip over false root */ - p++; + if ( urlstr[0] == '/' && urlstr[1] == '/' ) { + urlstr += 2; + /* path must be absolute if authority is present */ + if ( urlstr[0] != '/' ) + return NULL; + } + + p = ber_strdup( urlstr ); + + /* But we should convert to LDAP_DIRSEP before use */ + if ( LDAP_DIRSEP[0] != '/' ) { + char *s = p; + while (( s = strchr( s, '/' ))) + *s++ = LDAP_DIRSEP[0]; + } - p = ber_strdup( p ); ldap_pvt_hex_unescape( p ); url = fopen( p, "rb" ); ber_memfree( p ); } else { - return NULL; - } +#ifdef HAVE_FETCH + url = fetchGetURL( (char*) urlstr, "" ); +#else + url = NULL; #endif + } return url; }