1999-07-31 11:23:26 +08:00
|
|
|
/* line64.c - routines for dealing with the slapd line format */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-05 07:57:27 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-05 07:57:27 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-07-31 11:23:26 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_FETCH
|
|
|
|
#include <fetch.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ldap_log.h"
|
|
|
|
#include "lber_pvt.h"
|
1999-08-04 02:14:24 +08:00
|
|
|
#include "ldap_pvt.h"
|
1999-08-04 03:04:02 +08:00
|
|
|
#include "ldap_config.h"
|
1999-07-31 11:23:26 +08:00
|
|
|
#include "ldif.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
ldif_fetch_url(
|
|
|
|
LDAP_CONST char *urlstr,
|
|
|
|
char **valuep,
|
|
|
|
ber_len_t *vlenp
|
|
|
|
)
|
|
|
|
{
|
1999-08-04 02:14:24 +08:00
|
|
|
FILE *url;
|
1999-07-31 11:23:26 +08:00
|
|
|
char buffer[1024];
|
|
|
|
char *p = NULL;
|
|
|
|
size_t total;
|
|
|
|
size_t bytes;
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
*valuep = NULL;
|
|
|
|
*vlenp = 0;
|
|
|
|
|
|
|
|
#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 -1;
|
|
|
|
}
|
|
|
|
|
2001-12-07 09:46:26 +08:00
|
|
|
/* we don't check for LDAP_DIRSEP since URLs should contain '/' */
|
|
|
|
if( *p != '/' ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
/* skip over false root */
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = ber_strdup( p );
|
|
|
|
ldap_pvt_hex_unescape( p );
|
|
|
|
|
2000-06-21 08:40:10 +08:00
|
|
|
url = fopen( p, "rb" );
|
1999-08-04 02:14:24 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-31 11:23:26 +08:00
|
|
|
if( url == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
total = 0;
|
|
|
|
|
1999-09-06 12:42:20 +08:00
|
|
|
while( (bytes = fread( buffer, 1, sizeof(buffer), url )) != 0 ) {
|
2002-12-03 06:08:26 +08:00
|
|
|
char *newp = ber_memrealloc( p, total + bytes + 1 );
|
1999-07-31 11:23:26 +08:00
|
|
|
if( newp == NULL ) {
|
|
|
|
ber_memfree( p );
|
|
|
|
fclose( url );
|
|
|
|
return -1;
|
|
|
|
}
|
2000-06-21 08:40:10 +08:00
|
|
|
p = newp;
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( &p[total], buffer, bytes );
|
1999-07-31 11:23:26 +08:00
|
|
|
total += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( url );
|
|
|
|
|
2002-12-03 05:46:58 +08:00
|
|
|
if( total == 0 ) {
|
|
|
|
char *newp = ber_memrealloc( p, 1 );
|
|
|
|
if( newp == NULL ) {
|
|
|
|
ber_memfree( p );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p = newp;
|
|
|
|
}
|
|
|
|
|
2002-12-03 06:08:26 +08:00
|
|
|
p[total] = '\0';
|
1999-07-31 11:23:26 +08:00
|
|
|
*valuep = p;
|
|
|
|
*vlenp = total;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|