X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Ffetch.c;h=a56806e0c01f79e2140ee2194760bdec8e0a4369;hb=34249c08a5c15ebf15f78570ca61e6acad94dc22;hp=fb9e5ddaf0c3fa270d82f7d1cf2724faa5c0c75b;hpb=3c598e89fb34a892d369a138daa8c3314294493c;p=openldap diff --git a/libraries/liblutil/fetch.c b/libraries/liblutil/fetch.c index fb9e5ddaf0..a56806e0c0 100644 --- a/libraries/liblutil/fetch.c +++ b/libraries/liblutil/fetch.c @@ -1,9 +1,8 @@ /* fetch.c - routines for fetching data at URLs */ /* $OpenLDAP$ */ -/* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2004 The OpenLDAP Foundation. + * Copyright 1999-2010 The OpenLDAP Foundation. * Portions Copyright 1999-2003 Kurt D. Zeilenga. * All rights reserved. * @@ -39,47 +38,64 @@ #include "ldap_config.h" #include "ldif.h" -int -ldif_fetch_url( - LDAP_CONST char *urlstr, - char **valuep, - ber_len_t *vlenp -) +FILE * +ldif_open_url( + LDAP_CONST char *urlstr ) { FILE *url; - char buffer[1024]; - char *p = NULL; - size_t total; - size_t bytes; - - *valuep = NULL; - *vlenp = 0; -#ifdef HAVE_FETCH - url = fetchGetURL( (char*) urlstr, "" ); + if( strncasecmp( "file:", urlstr, sizeof("file:")-1 ) == 0 ) { + char *p; + urlstr += sizeof("file:")-1; -#else - if( strncasecmp( "file://", urlstr, sizeof("file://")-1 ) == 0 ) { - p = strchr( &urlstr[sizeof("file://")-1], '/' ); - if( p == NULL ) { - return -1; + /* we don't check for LDAP_DIRSEP since URLs should contain '/' */ + if ( urlstr[0] == '/' && urlstr[1] == '/' ) { + urlstr += 2; + /* path must be absolute if authority is present */ + if ( urlstr[0] != '/' ) + return NULL; } - /* we don't check for LDAP_DIRSEP since URLs should contain '/' */ - if( *p != '/' ) { - /* skip over false root */ - p++; + 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 -1; - } +#ifdef HAVE_FETCH + url = fetchGetURL( (char*) urlstr, "" ); +#else + url = NULL; #endif + } + return url; +} + +int +ldif_fetch_url( + LDAP_CONST char *urlstr, + char **valuep, + ber_len_t *vlenp ) +{ + FILE *url; + char buffer[1024]; + char *p = NULL; + size_t total; + size_t bytes; + + *valuep = NULL; + *vlenp = 0; + + url = ldif_open_url( urlstr ); if( url == NULL ) { return -1;