/* $OpenLDAP$ */
/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
static const char* skip_url_prefix LDAP_P((
const char *url,
int *enclosedp,
- int *ldaps ));
+ unsigned long *properties,
+ int *protocol));
int
ldap_is_ldap_url( LDAP_CONST char *url )
{
- int enclosed;
- int ldaps;
+ int enclosed, protocol;
+ unsigned long properties;
if( url == NULL ) {
return 0;
}
- if( skip_url_prefix( url, &enclosed, &ldaps) == NULL ) {
+ if( skip_url_prefix( url, &enclosed, &properties, &protocol) == NULL ) {
return 0;
}
- return !ldaps;
+ return !(properties & LDAP_URL_USE_SSL);
}
int
ldap_is_ldaps_url( LDAP_CONST char *url )
{
- int enclosed;
- int ldaps;
+ int enclosed, protocol;
+ unsigned long properties;
if( url == NULL ) {
return 0;
}
- if( skip_url_prefix( url, &enclosed, &ldaps) == NULL ) {
+ if( skip_url_prefix( url, &enclosed, &properties, &protocol) == NULL ) {
return 0;
}
- return ldaps;
+ return (properties & LDAP_URL_USE_SSL);
}
static const char*
skip_url_prefix(
const char *url,
int *enclosedp,
- int *ldaps )
+ unsigned long *properties,
+ int *protocol
+ )
{
/*
* return non-zero if this looks like a LDAP URL; zero if not
p += LDAP_URL_URLCOLON_LEN;
}
+ *properties = 0;
+
/* check for "ldap://" prefix */
if ( strncasecmp( p, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) == 0 ) {
/* skip over "ldap://" prefix and return success */
p += LDAP_URL_PREFIX_LEN;
- *ldaps = 0;
+ *protocol = LDAP_PROTO_TCP;
return( p );
}
if ( strncasecmp( p, LDAPS_URL_PREFIX, LDAPS_URL_PREFIX_LEN ) == 0 ) {
/* skip over "ldaps://" prefix and return success */
p += LDAPS_URL_PREFIX_LEN;
- *ldaps = 1;
+ *protocol = LDAP_PROTO_TCP;
+ *properties |= LDAP_URL_USE_SSL;
+ return( p );
+ }
+
+ /* check for "ldapi://" prefix */
+ if ( strncasecmp( p, LDAPI_URL_PREFIX, LDAPI_URL_PREFIX_LEN ) == 0 ) {
+ /* skip over "ldapi://" prefix and return success */
+ p += LDAPI_URL_PREFIX_LEN;
+ *protocol = LDAP_PROTO_LOCAL;
+ return( p );
+ }
+
+ /* check for "ldapis://" prefix: should this be legal? */
+ if ( strncasecmp( p, LDAPIS_URL_PREFIX, LDAPIS_URL_PREFIX_LEN ) == 0 ) {
+ /* skip over "ldapis://" prefix and return success */
+ p += LDAPIS_URL_PREFIX_LEN;
+ *protocol = LDAP_PROTO_LOCAL;
+ *properties |= LDAP_URL_USE_SSL;
return( p );
}
LDAPURLDesc *ludp;
char *p, *q;
- int i, enclosed, ldaps;
+ int i, enclosed, protocol;
+ unsigned long properties;
const char *url_tmp;
char *url;
*ludpp = NULL; /* pessimistic */
- url_tmp = skip_url_prefix( url_in, &enclosed, &ldaps );
+ url_tmp = skip_url_prefix( url_in, &enclosed, &properties, &protocol );
if ( url_tmp == NULL ) {
return LDAP_URL_ERR_NOTLDAP;
ludp->lud_next = NULL;
ludp->lud_host = NULL;
ludp->lud_port = 0;
- ludp->lud_dn = NULL;
- ludp->lud_attrs = NULL;
- ludp->lud_filter = NULL;
- ludp->lud_ldaps = ldaps;
+ ludp->lud_dn = NULL;
+ ludp->lud_attrs = NULL;
+ ludp->lud_filter = NULL;
+ ludp->lud_properties = properties;
+ ludp->lud_protocol = protocol;
ludp->lud_scope = LDAP_SCOPE_BASE;
ludp->lud_filter = LDAP_STRDUP("(objectClass=*)");
return LDAP_URL_ERR_MEM;
}
+ /*
+ * Kluge. ldap://111.222.333.444:389??cn=abc,o=company
+ *
+ * On early Novell releases, search references/referrals were returned
+ * in this format, i.e., the dn was kind of in the scope position,
+ * but the required slash is missing. The whole thing is illegal syntax,
+ * but we need to account for it. Fortunately it can't be confused with
+ * anything real.
+ */
+ if( (p == NULL) && ((q = strchr( q, '?')) != NULL)) {
+ q++;
+ /* ? immediately followed by question */
+ if( *q == '?') {
+ q++;
+ if( *q != '\0' ) {
+ /* parse dn part */
+ ldap_pvt_hex_unescape( q );
+ ludp->lud_dn = LDAP_STRDUP( q );
+ } else {
+ ludp->lud_dn = LDAP_STRDUP( "" );
+ }
+
+ if( ludp->lud_dn == NULL ) {
+ LDAP_FREE( url );
+ ldap_free_urldesc( ludp );
+ return LDAP_URL_ERR_MEM;
+ }
+ }
+ }
+
if( p == NULL ) {
LDAP_FREE( url );
*ludpp = ludp;
return NULL;
}
- dest = LDAP_CALLOC( 1, sizeof(LDAPURLDesc) );
+ dest = LDAP_MALLOC( sizeof(LDAPURLDesc) );
if (dest == NULL)
return NULL;
+ *dest = *ludp;
+ dest->lud_next = NULL;
+
if ( ludp->lud_host != NULL ) {
dest->lud_host = LDAP_STRDUP( ludp->lud_host );
if (dest->lud_host == NULL) {
}
}
- dest->lud_ldaps = ludp->lud_ldaps;
- dest->lud_port = ludp->lud_port;
- dest->lud_scope = ludp->lud_scope;
-
return dest;
}
ludp->lud_port = atoi(p);
}
ldap_pvt_hex_unescape(ludp->lud_host);
- ludp->lud_ldaps = -1; /* unknown (use TLS default) */
+ ludp->lud_protocol = LDAP_PROTO_TCP;
+ ludp->lud_properties = 0;
ludp->lud_next = *ludlist;
*ludlist = ludp;
}
p = s;
for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
- p += sprintf(p, "ldap%s://%s", (ludp->lud_ldaps == 1) ? "s" : "", ludp->lud_host);
+ p += sprintf(p, "ldap%s://%s", (ludp->lud_properties & LDAP_URL_USE_SSL) ? "s" : "", ludp->lud_host);
if (ludp->lud_port != 0)
p += sprintf(p, ":%d", ludp->lud_port);
*p++ = '/';
int err;
LDAPURLDesc *ludp;
BerElement *ber;
+ LDAPreqinfo bind;
if ( ldap_url_parse( url, &ludp ) != 0 ) {
ld->ld_errno = LDAP_PARAM_ERROR;
if ( ber == NULL ) {
err = -1;
} else {
+ bind.ri_request = LDAP_REQ_SEARCH;
+ bind.ri_msgid = ld->ld_msgid;
+ bind.ri_url = (char *)url;
err = ldap_send_server_request(
ld, ber, ld->ld_msgid, NULL,
(ludp->lud_host != NULL || ludp->lud_port != 0)
? ludp : NULL,
- NULL, 1 );
+ NULL, &bind );
}
ldap_free_urldesc( ludp );
ldap_pvt_hex_unescape( char *s )
{
/*
- * Remove URL hex escapes from s... done in place. The basic concept for
- * this routine is borrowed from the WWW library HTUnEscape() routine.
- */
+* Remove URL hex escapes from s... done in place. The basic concept for
+* this routine is borrowed from the WWW library HTUnEscape() routine.
+*/
char *p;
for ( p = s; *s != '\0'; ++s ) {