FILE * ldif_open_url( LDAP_CONST char *urlstr ) { FILE *url; 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 '/' */ if ( urlstr[0] == '/' && urlstr[1] == '/' ) { urlstr += 2; /* path must be absolute if authority is present * technically, file://hostname/path is also legal but we don't * accept a non-empty hostname */ if ( urlstr[0] != '/' ) { #ifdef _WIN32 /* An absolute path in improper file://C:/foo/bar format */ if ( urlstr[1] != ':' ) #endif return NULL; } #ifdef _WIN32 /* An absolute path in proper file:///C:/foo/bar format */ if ( urlstr[2] == ':' ) urlstr++; #endif } 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]; } ldap_pvt_hex_unescape( p ); url = fopen( p, "rb" ); ber_memfree( p ); } else { #ifdef HAVE_FETCH url = fetchGetURL( (char*) urlstr, "" ); #else url = NULL; #endif } return url; }
FILE * ldif_open_url( LDAP_CONST char *urlstr ) { FILE *url; 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 '/' */ 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]; } ldap_pvt_hex_unescape( p ); url = fopen( p, "rb" ); ber_memfree( p ); } else { #ifdef HAVE_FETCH url = fetchGetURL( (char*) urlstr, "" ); #else url = NULL; #endif } return url; }