/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/* Portions
* Copyright (c) 1996 Regents of the University of Michigan.
* All rights reserved.
*
* We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
*/
-#ifndef lint
-static char copyright[] = "@(#) Copyright (c) 1996 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
+#include "portable.h"
#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
#include <stdlib.h>
-#ifdef MACOS
-#include "macos.h"
-#endif /* MACOS */
-
-#if defined( DOS ) || defined( _WIN32 )
-#include <malloc.h>
-#include "msdos.h"
-#endif /* DOS || _WIN32 */
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
-#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 )
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#endif /* !MACOS && !DOS && !_WIN32 */
-
-#include "lber.h"
-#include "ldap.h"
#include "ldap-int.h"
-static int skip_url_prefix LDAP_P(( char **urlp, int *enclosedp ));
+/* local functions */
+static const char* skip_url_prefix LDAP_P(( const char *url, int *enclosedp ));
static void hex_unescape LDAP_P(( char *s ));
-static int unhex LDAP_P(( char c ));
+static int unhex( char c );
int
-ldap_is_ldap_url( char *url )
+ldap_is_ldap_url( LDAP_CONST char *url )
{
int enclosed;
- return( url != NULL && skip_url_prefix( &url, &enclosed ));
+ return( url != NULL && skip_url_prefix( url, &enclosed ) != NULL );
}
-static int
-skip_url_prefix( char **urlp, int *enclosedp )
+static const char*
+skip_url_prefix( const char *url, int *enclosedp )
{
/*
* return non-zero if this looks like a LDAP URL; zero if not
* if non-zero returned, *urlp will be moved past "ldap://" part of URL
*/
- if ( *urlp == NULL ) {
- return( 0 );
+ char* p;
+
+ if ( url == NULL ) {
+ return( NULL );
}
+ p = (char *) url;
+
/* skip leading '<' (if any) */
- if ( **urlp == '<' ) {
+ if ( *p == '<' ) {
*enclosedp = 1;
- ++*urlp;
+ ++p;
} else {
*enclosedp = 0;
}
/* skip leading "URL:" (if any) */
- if ( strlen( *urlp ) >= LDAP_URL_URLCOLON_LEN && strncasecmp(
- *urlp, LDAP_URL_URLCOLON, LDAP_URL_URLCOLON_LEN ) == 0 ) {
- *urlp += LDAP_URL_URLCOLON_LEN;
+ if ( strlen( p ) >= LDAP_URL_URLCOLON_LEN
+ && strncasecmp( p, LDAP_URL_URLCOLON, LDAP_URL_URLCOLON_LEN ) == 0 )
+ {
+ p += LDAP_URL_URLCOLON_LEN;
}
/* check for missing "ldap://" prefix */
- if ( strlen( *urlp ) < LDAP_URL_PREFIX_LEN ||
- strncasecmp( *urlp, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) != 0 ) {
- return( 0 );
+ if ( strlen( p ) < LDAP_URL_PREFIX_LEN ||
+ strncasecmp( p, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) != 0 ) {
+ return( NULL );
}
/* skip over "ldap://" prefix and return success */
- *urlp += LDAP_URL_PREFIX_LEN;
- return( 1 );
+ p += LDAP_URL_PREFIX_LEN;
+ return( p );
}
int
-ldap_url_parse( char *url, LDAPURLDesc **ludpp )
+ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
{
/*
* Pick apart the pieces of an LDAP URL.
LDAPURLDesc *ludp;
char *attrs, *p, *q;
int enclosed, i, nattrs;
+ const char *url_tmp;
+ char *url;
- Debug( LDAP_DEBUG_TRACE, "ldap_url_parse(%s)\n", url, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "ldap_url_parse(%s)\n", url_in, 0, 0 );
*ludpp = NULL; /* pessimistic */
- if ( !skip_url_prefix( &url, &enclosed )) {
+ url_tmp = skip_url_prefix( url_in, &enclosed );
+
+ if ( url_tmp == NULL ) {
return( LDAP_URL_ERR_NOTLDAP );
}
- /* allocate return struct */
- if (( ludp = (LDAPURLDesc *)calloc( 1, sizeof( LDAPURLDesc )))
- == NULLLDAPURLDESC ) {
+ /* make working copy of the remainder of the URL */
+ if (( url = strdup( url_tmp )) == NULL ) {
return( LDAP_URL_ERR_MEM );
}
- /* make working copy of the remainder of the URL */
- if (( url = strdup( url )) == NULL ) {
- ldap_free_urldesc( ludp );
+ /* allocate return struct */
+ if (( ludp = (LDAPURLDesc *)calloc( 1, sizeof( LDAPURLDesc )))
+ == NULLLDAPURLDESC )
+ {
+ free( url );
return( LDAP_URL_ERR_MEM );
}
+
if ( enclosed && *((p = url + strlen( url ) - 1)) == '>' ) {
*p = '\0';
}
int
-ldap_url_search( LDAP *ld, char *url, int attrsonly )
+ldap_url_search( LDAP *ld, LDAP_CONST char *url, int attrsonly )
{
int err;
LDAPURLDesc *ludp;
BerElement *ber;
-#ifdef LDAP_REFERRALS
LDAPServer *srv = NULL;
-#endif /* LDAP_REFERRALS */
if ( ldap_url_parse( url, &ludp ) != 0 ) {
ld->ld_errno = LDAP_PARAM_ERROR;
return( -1 );
}
- if (( ber = ldap_build_search_req( ld, ludp->lud_dn, ludp->lud_scope,
- ludp->lud_filter, ludp->lud_attrs, attrsonly )) == NULLBER ) {
+ ber = ldap_build_search_req( ld, ludp->lud_dn, ludp->lud_scope,
+ ludp->lud_filter, ludp->lud_attrs, attrsonly, NULL, NULL,
+ -1, -1 );
+
+ if ( ber == NULLBER ) {
return( -1 );
}
err = 0;
if ( ludp->lud_host != NULL || ludp->lud_port != 0 ) {
-#ifdef LDAP_REFERRALS
if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer )))
== NULL || ( srv->lsrv_host = strdup( ludp->lud_host ==
NULL ? ld->ld_defhost : ludp->lud_host )) == NULL ) {
err = -1;
} else {
if ( ludp->lud_port == 0 ) {
- srv->lsrv_port = LDAP_PORT;
+ srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
} else {
- srv->lsrv_port = ludp->lud_port;
+ srv->lsrv_port = ludp->lud_port;
}
}
-#else /* LDAP_REFERRALS */
- ld->ld_errno = LDAP_LOCAL_ERROR;
- err = -1;
-#endif /* LDAP_REFERRALS */
}
if ( err != 0 ) {
ber_free( ber, 1 );
} else {
-#ifdef LDAP_REFERRALS
err = ldap_send_server_request( ld, ber, ld->ld_msgid, NULL, srv,
NULL, 1 );
-#else /* LDAP_REFERRALS */
- err = ldap_send_initial_request( ld, LDAP_REQ_SEARCH,
- ludp->lud_dn, ber );
-#endif /* LDAP_REFERRALS */
}
ldap_free_urldesc( ludp );
int
-ldap_url_search_st( LDAP *ld, char *url, int attrsonly,
+ldap_url_search_st( LDAP *ld, LDAP_CONST char *url, int attrsonly,
struct timeval *timeout, LDAPMessage **res )
{
int msgid;
int
-ldap_url_search_s( LDAP *ld, char *url, int attrsonly, LDAPMessage **res )
+ldap_url_search_s(
+ LDAP *ld, LDAP_CONST char *url, int attrsonly, LDAPMessage **res )
{
int msgid;