X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Furl.c;h=6098bb8910cbaa2b088dc29abb19e317c8628bd2;hb=c23536faa9bebfed42ee17b693f780e160a801ad;hp=551892f00923d58ccaea7b35093789eeb1700a3a;hpb=26c7d69e8c30decc73374fcb41f0d711a1af3500;p=openldap diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 551892f009..6098bb8910 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -1,6 +1,6 @@ /* $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 @@ -40,48 +40,51 @@ 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 @@ -109,11 +112,13 @@ skip_url_prefix( 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 ); } @@ -121,7 +126,25 @@ skip_url_prefix( 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 ); } @@ -160,7 +183,8 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) LDAPURLDesc *ludp; char *p, *q; - int i, enclosed, ldaps; + int i, enclosed, protocol; + unsigned long properties; const char *url_tmp; char *url; @@ -172,7 +196,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) *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; @@ -205,10 +229,11 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) 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=*)"); @@ -249,6 +274,36 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) 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; @@ -424,10 +479,13 @@ ldap_url_dup ( LDAPURLDesc *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) { @@ -468,10 +526,6 @@ ldap_url_dup ( LDAPURLDesc *ludp ) } } - dest->lud_ldaps = ludp->lud_ldaps; - dest->lud_port = ludp->lud_port; - dest->lud_scope = ludp->lud_scope; - return dest; } @@ -563,10 +617,12 @@ ldap_url_parsehosts (LDAPURLDesc **ludlist, const char *hosts ) p = strchr(ludp->lud_host, ':'); if (p != NULL) { *p++ = 0; + ldap_pvt_hex_unescape(p); ludp->lud_port = atoi(p); } - if (ludp->lud_port == LDAPS_PORT) - ludp->lud_ldaps = 1; /* cheat */ + ldap_pvt_hex_unescape(ludp->lud_host); + ludp->lud_protocol = LDAP_PROTO_TCP; + ludp->lud_properties = 0; ludp->lud_next = *ludlist; *ludlist = ludp; } @@ -634,7 +690,7 @@ ldap_url_list2urls (LDAPURLDesc *ludlist) p = s; for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) { - p += sprintf(p, "ldap%s://%s", ludp->lud_ldaps ? "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++ = '/'; @@ -695,6 +751,7 @@ ldap_url_search( LDAP *ld, LDAP_CONST char *url, int attrsonly ) int err; LDAPURLDesc *ludp; BerElement *ber; + LDAPreqinfo bind; if ( ldap_url_parse( url, &ludp ) != 0 ) { ld->ld_errno = LDAP_PARAM_ERROR; @@ -708,11 +765,14 @@ ldap_url_search( LDAP *ld, LDAP_CONST char *url, int attrsonly ) 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 ); @@ -766,9 +826,9 @@ void 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 ) {