1 /* LIBLDAP url.c -- LDAP URL (RFC 2255) related routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
17 * All rights reserved.
22 * LDAP URLs look like this:
23 * ldap[is]://host:port[/[dn[?[attributes][?[scope][?[filter][?exts]]]]]]
26 * attributes is a comma separated list
27 * scope is one of these three strings: base one sub (default=base)
28 * filter is an string-represented filter as in RFC 2254
30 * e.g., ldap://host:port/dc=com?o,cn?base?(o=openldap)?extension
32 * We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
39 #include <ac/stdlib.h>
41 #include <ac/socket.h>
42 #include <ac/string.h>
48 static const char* skip_url_prefix LDAP_P((
51 const char **scheme ));
53 int ldap_pvt_url_scheme2proto( const char *scheme )
57 if( scheme == NULL ) {
61 if( strcmp("ldap", scheme) == 0 ) {
62 return LDAP_PROTO_TCP;
65 if( strcmp("ldapi", scheme) == 0 ) {
66 return LDAP_PROTO_IPC;
69 if( strcmp("ldaps", scheme) == 0 ) {
70 return LDAP_PROTO_TCP;
72 #ifdef LDAP_CONNECTIONLESS
73 if( strcmp("cldap", scheme) == 0 ) {
74 return LDAP_PROTO_UDP;
82 ldap_pvt_url_scheme2tls( const char *scheme )
86 if( scheme == NULL ) {
90 return strcmp("ldaps", scheme) == 0;
94 ldap_is_ldap_url( LDAP_CONST char *url )
103 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
111 ldap_is_ldaps_url( LDAP_CONST char *url )
120 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
124 return strcmp(scheme, "ldaps") == 0;
128 ldap_is_ldapi_url( LDAP_CONST char *url )
137 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
141 return strcmp(scheme, "ldapi") == 0;
144 #ifdef LDAP_CONNECTIONLESS
146 ldap_is_ldapc_url( LDAP_CONST char *url )
155 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
159 return strcmp(scheme, "cldap") == 0;
167 const char **scheme )
170 * return non-zero if this looks like a LDAP URL; zero if not
171 * if non-zero returned, *urlp will be moved past "ldap://" part of URL
181 /* skip leading '<' (if any) */
189 /* skip leading "URL:" (if any) */
190 if ( strncasecmp( p, LDAP_URL_URLCOLON, LDAP_URL_URLCOLON_LEN ) == 0 ) {
191 p += LDAP_URL_URLCOLON_LEN;
194 /* check for "ldap://" prefix */
195 if ( strncasecmp( p, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) == 0 ) {
196 /* skip over "ldap://" prefix and return success */
197 p += LDAP_URL_PREFIX_LEN;
202 /* check for "ldaps://" prefix */
203 if ( strncasecmp( p, LDAPS_URL_PREFIX, LDAPS_URL_PREFIX_LEN ) == 0 ) {
204 /* skip over "ldaps://" prefix and return success */
205 p += LDAPS_URL_PREFIX_LEN;
210 /* check for "ldapi://" prefix */
211 if ( strncasecmp( p, LDAPI_URL_PREFIX, LDAPI_URL_PREFIX_LEN ) == 0 ) {
212 /* skip over "ldapi://" prefix and return success */
213 p += LDAPI_URL_PREFIX_LEN;
218 #ifdef LDAP_CONNECTIONLESS
219 /* check for "cldap://" prefix */
220 if ( strncasecmp( p, LDAPC_URL_PREFIX, LDAPC_URL_PREFIX_LEN ) == 0 ) {
221 /* skip over "cldap://" prefix and return success */
222 p += LDAPC_URL_PREFIX_LEN;
232 static int str2scope( const char *p )
234 if ( strcasecmp( p, "one" ) == 0 ) {
235 return LDAP_SCOPE_ONELEVEL;
237 } else if ( strcasecmp( p, "onelevel" ) == 0 ) {
238 return LDAP_SCOPE_ONELEVEL;
240 } else if ( strcasecmp( p, "base" ) == 0 ) {
241 return LDAP_SCOPE_BASE;
243 } else if ( strcasecmp( p, "sub" ) == 0 ) {
244 return LDAP_SCOPE_SUBTREE;
246 } else if ( strcasecmp( p, "subtree" ) == 0 ) {
247 return LDAP_SCOPE_SUBTREE;
249 #ifdef LDAP_SCOPE_SUBORDINATE
250 } else if ( strcasecmp( p, "subordinate" ) == 0 ) {
251 return LDAP_SCOPE_SUBORDINATE;
253 } else if ( strcasecmp( p, "children" ) == 0 ) {
254 return LDAP_SCOPE_SUBORDINATE;
261 static int hex_escape( char *buf, const char *s, int list )
265 static const char hex[] = "0123456789ABCDEF";
267 if( s == NULL ) return 0;
269 for( pos=0,i=0; s[i]; i++ ) {
295 escape = s[i] < 0x20 || 0x1f >= s[i];
300 buf[pos++] = hex[ (s[i] >> 4) & 0x0f ];
301 buf[pos++] = hex[ s[i] & 0x0f ];
311 static int hex_escape_args( char *buf, char **s )
316 if( s == NULL ) return 0;
319 for( i=0; s[i] != NULL; i++ ) {
323 pos += hex_escape( &buf[pos], s[i], 1 );
329 char * ldap_url_desc2str( LDAPURLDesc *u )
336 if( u == NULL ) return NULL;
339 for( i=0; u->lud_exts[i]; i++ ) {
340 len += strlen( u->lud_exts[i] ) + 1;
345 if( u->lud_filter ) {
346 len += strlen( u->lud_filter );
349 if ( len ) len++; /* ? */
351 switch( u->lud_scope ) {
352 case LDAP_SCOPE_BASE:
353 case LDAP_SCOPE_ONELEVEL:
354 case LDAP_SCOPE_SUBTREE:
355 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
356 case LDAP_SCOPE_SUBORDINATE:
358 len += sizeof("subordinate");
363 if ( len ) len++; /* ? */
367 for( i=0; u->lud_attrs[i]; i++ ) {
368 len += strlen( u->lud_attrs[i] ) + 1;
371 } else if ( len ) len++; /* ? */
374 len += strlen( u->lud_dn ) + 1;
379 len += sizeof(":65535") - 1;
383 len+=strlen( u->lud_host );
386 len += strlen( u->lud_scheme ) + sizeof("://");
388 /* allocate enough to hex escape everything -- overkill */
389 s = LDAP_MALLOC( 3*len );
391 if( s == NULL ) return NULL;
394 sprintf( s, "%s://%s:%d%n", u->lud_scheme,
395 u->lud_host, u->lud_port, &sofar );
397 sprintf( s, "%s://%s%n", u->lud_scheme,
398 u->lud_host, &sofar );
401 if( sep < 1 ) goto done;
404 sofar += hex_escape( &s[sofar], u->lud_dn, 0 );
406 if( sep < 2 ) goto done;
409 sofar += hex_escape_args( &s[sofar], u->lud_attrs );
411 if( sep < 3 ) goto done;
414 switch( u->lud_scope ) {
415 case LDAP_SCOPE_BASE:
416 strcpy( &s[sofar], "base" );
417 sofar += sizeof("base") - 1;
419 case LDAP_SCOPE_ONELEVEL:
420 strcpy( &s[sofar], "one" );
421 sofar += sizeof("one") - 1;
423 case LDAP_SCOPE_SUBTREE:
424 strcpy( &s[sofar], "sub" );
425 sofar += sizeof("sub") - 1;
427 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
428 case LDAP_SCOPE_SUBORDINATE:
429 strcpy( &s[sofar], "children" );
430 sofar += sizeof("children") - 1;
435 if( sep < 4 ) goto done;
438 sofar += hex_escape( &s[sofar], u->lud_filter, 0 );
440 if( sep < 5 ) goto done;
443 sofar += hex_escape_args( &s[sofar], u->lud_exts );
451 ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
454 * Pick apart the pieces of an LDAP URL.
460 const char *scheme = NULL;
464 if( url_in == NULL || ludpp == NULL ) {
465 return LDAP_URL_ERR_PARAM;
468 #ifndef LDAP_INT_IN_KERNEL
469 /* Global options may not be created yet
470 * We can't test if the global options are initialized
471 * because a call to LDAP_INT_GLOBAL_OPT() will try to allocate
472 * the options and cause infinite recursion
475 LDAP_LOG ( OPERATION, ENTRY, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
477 Debug( LDAP_DEBUG_TRACE, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
481 *ludpp = NULL; /* pessimistic */
483 url_tmp = skip_url_prefix( url_in, &enclosed, &scheme );
485 if ( url_tmp == NULL ) {
486 return LDAP_URL_ERR_BADSCHEME;
491 /* make working copy of the remainder of the URL */
492 url = LDAP_STRDUP( url_tmp );
494 return LDAP_URL_ERR_MEM;
498 p = &url[strlen(url)-1];
502 return LDAP_URL_ERR_BADENCLOSURE;
508 /* allocate return struct */
509 ludp = (LDAPURLDesc *)LDAP_CALLOC( 1, sizeof( LDAPURLDesc ));
511 if ( ludp == NULL ) {
513 return LDAP_URL_ERR_MEM;
516 ludp->lud_next = NULL;
517 ludp->lud_host = NULL;
520 ludp->lud_attrs = NULL;
521 ludp->lud_filter = NULL;
522 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
523 ludp->lud_filter = NULL;
524 ludp->lud_exts = NULL;
526 ludp->lud_scheme = LDAP_STRDUP( scheme );
528 if ( ludp->lud_scheme == NULL ) {
530 ldap_free_urldesc( ludp );
531 return LDAP_URL_ERR_MEM;
534 /* scan forward for '/' that marks end of hostport and begin. of dn */
535 p = strchr( url, '/' );
538 /* terminate hostport; point to start of dn */
542 /* IPv6 syntax with [ip address]:port */
544 r = strchr( url, ']' );
547 ldap_free_urldesc( ludp );
548 return LDAP_URL_ERR_BADURL;
551 q = strchr( r, ':' );
553 q = strchr( url, ':' );
560 ldap_pvt_hex_unescape( q );
564 ldap_free_urldesc( ludp );
565 return LDAP_URL_ERR_BADURL;
568 ludp->lud_port = strtol( q, &next, 10 );
569 if ( next == NULL || next[0] != '\0' ) {
571 ldap_free_urldesc( ludp );
572 return LDAP_URL_ERR_BADURL;
576 ldap_pvt_hex_unescape( url );
578 /* If [ip address]:port syntax, url is [ip and we skip the [ */
579 ludp->lud_host = LDAP_STRDUP( url + ( *url == '[' ) );
581 if( ludp->lud_host == NULL ) {
583 ldap_free_urldesc( ludp );
584 return LDAP_URL_ERR_MEM;
588 * Kludge. ldap://111.222.333.444:389??cn=abc,o=company
590 * On early Novell releases, search references/referrals were returned
591 * in this format, i.e., the dn was kind of in the scope position,
592 * but the required slash is missing. The whole thing is illegal syntax,
593 * but we need to account for it. Fortunately it can't be confused with
596 if( (p == NULL) && (q != NULL) && ((q = strchr( q, '?')) != NULL)) {
598 /* ? immediately followed by question */
603 ldap_pvt_hex_unescape( q );
604 ludp->lud_dn = LDAP_STRDUP( q );
606 ludp->lud_dn = LDAP_STRDUP( "" );
609 if( ludp->lud_dn == NULL ) {
611 ldap_free_urldesc( ludp );
612 return LDAP_URL_ERR_MEM;
620 return LDAP_URL_SUCCESS;
623 /* scan forward for '?' that may marks end of dn */
624 q = strchr( p, '?' );
627 /* terminate dn part */
633 ldap_pvt_hex_unescape( p );
634 ludp->lud_dn = LDAP_STRDUP( p );
636 ludp->lud_dn = LDAP_STRDUP( "" );
639 if( ludp->lud_dn == NULL ) {
641 ldap_free_urldesc( ludp );
642 return LDAP_URL_ERR_MEM;
649 return LDAP_URL_SUCCESS;
652 /* scan forward for '?' that may marks end of attributes */
654 q = strchr( p, '?' );
657 /* terminate attributes part */
662 /* parse attributes */
663 ldap_pvt_hex_unescape( p );
664 ludp->lud_attrs = ldap_str2charray( p, "," );
666 if( ludp->lud_attrs == NULL ) {
668 ldap_free_urldesc( ludp );
669 return LDAP_URL_ERR_BADATTRS;
677 return LDAP_URL_SUCCESS;
680 /* scan forward for '?' that may marks end of scope */
682 q = strchr( p, '?' );
685 /* terminate the scope part */
690 /* parse the scope */
691 ldap_pvt_hex_unescape( p );
692 ludp->lud_scope = str2scope( p );
694 if( ludp->lud_scope == -1 ) {
696 ldap_free_urldesc( ludp );
697 return LDAP_URL_ERR_BADSCOPE;
705 return LDAP_URL_SUCCESS;
708 /* scan forward for '?' that may marks end of filter */
710 q = strchr( p, '?' );
713 /* terminate the filter part */
718 /* parse the filter */
719 ldap_pvt_hex_unescape( p );
724 ldap_free_urldesc( ludp );
725 return LDAP_URL_ERR_BADFILTER;
728 LDAP_FREE( ludp->lud_filter );
729 ludp->lud_filter = LDAP_STRDUP( p );
731 if( ludp->lud_filter == NULL ) {
733 ldap_free_urldesc( ludp );
734 return LDAP_URL_ERR_MEM;
742 return LDAP_URL_SUCCESS;
745 /* scan forward for '?' that may marks end of extensions */
747 q = strchr( p, '?' );
752 ldap_free_urldesc( ludp );
753 return LDAP_URL_ERR_BADURL;
756 /* parse the extensions */
757 ludp->lud_exts = ldap_str2charray( p, "," );
759 if( ludp->lud_exts == NULL ) {
761 ldap_free_urldesc( ludp );
762 return LDAP_URL_ERR_BADEXTS;
765 for( i=0; ludp->lud_exts[i] != NULL; i++ ) {
766 ldap_pvt_hex_unescape( ludp->lud_exts[i] );
768 if( *ludp->lud_exts[i] == '!' ) {
769 /* count the number of critical extensions */
770 ludp->lud_crit_exts++;
775 /* must have 1 or more */
777 ldap_free_urldesc( ludp );
778 return LDAP_URL_ERR_BADEXTS;
784 return LDAP_URL_SUCCESS;
788 ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
790 int rc = ldap_url_parse_ext( url_in, ludpp );
792 if( rc != LDAP_URL_SUCCESS ) {
796 if ((*ludpp)->lud_scope == LDAP_SCOPE_DEFAULT) {
797 (*ludpp)->lud_scope = LDAP_SCOPE_BASE;
800 if ((*ludpp)->lud_host != NULL && *(*ludpp)->lud_host == '\0') {
801 LDAP_FREE( (*ludpp)->lud_host );
802 (*ludpp)->lud_host = NULL;
805 if ((*ludpp)->lud_port == 0) {
806 if( strcmp((*ludpp)->lud_scheme, "ldap") == 0 ) {
807 (*ludpp)->lud_port = LDAP_PORT;
808 #ifdef LDAP_CONNECTIONLESS
809 } else if( strcmp((*ludpp)->lud_scheme, "cldap") == 0 ) {
810 (*ludpp)->lud_port = LDAP_PORT;
812 } else if( strcmp((*ludpp)->lud_scheme, "ldaps") == 0 ) {
813 (*ludpp)->lud_port = LDAPS_PORT;
821 ldap_url_dup ( LDAPURLDesc *ludp )
825 if ( ludp == NULL ) {
829 dest = LDAP_MALLOC( sizeof(LDAPURLDesc) );
834 dest->lud_scheme = NULL;
835 dest->lud_host = NULL;
837 dest->lud_filter = NULL;
838 dest->lud_attrs = NULL;
839 dest->lud_exts = NULL;
840 dest->lud_next = NULL;
842 if ( ludp->lud_scheme != NULL ) {
843 dest->lud_scheme = LDAP_STRDUP( ludp->lud_scheme );
844 if (dest->lud_scheme == NULL) {
845 ldap_free_urldesc(dest);
850 if ( ludp->lud_host != NULL ) {
851 dest->lud_host = LDAP_STRDUP( ludp->lud_host );
852 if (dest->lud_host == NULL) {
853 ldap_free_urldesc(dest);
858 if ( ludp->lud_dn != NULL ) {
859 dest->lud_dn = LDAP_STRDUP( ludp->lud_dn );
860 if (dest->lud_dn == NULL) {
861 ldap_free_urldesc(dest);
866 if ( ludp->lud_filter != NULL ) {
867 dest->lud_filter = LDAP_STRDUP( ludp->lud_filter );
868 if (dest->lud_filter == NULL) {
869 ldap_free_urldesc(dest);
874 if ( ludp->lud_attrs != NULL ) {
875 dest->lud_attrs = ldap_charray_dup( ludp->lud_attrs );
876 if (dest->lud_attrs == NULL) {
877 ldap_free_urldesc(dest);
882 if ( ludp->lud_exts != NULL ) {
883 dest->lud_exts = ldap_charray_dup( ludp->lud_exts );
884 if (dest->lud_exts == NULL) {
885 ldap_free_urldesc(dest);
894 ldap_url_duplist (LDAPURLDesc *ludlist)
896 LDAPURLDesc *dest, *tail, *ludp, *newludp;
900 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
901 newludp = ldap_url_dup(ludp);
902 if (newludp == NULL) {
903 ldap_free_urllist(dest);
909 tail->lud_next = newludp;
916 ldap_url_parselist (LDAPURLDesc **ludlist, const char *url )
918 return ldap_url_parselist_ext( ludlist, url, ", " );
922 ldap_url_parselist_ext (LDAPURLDesc **ludlist, const char *url, const char *sep )
928 assert( ludlist != NULL );
929 assert( url != NULL );
933 urls = ldap_str2charray(url, sep);
935 return LDAP_NO_MEMORY;
937 /* count the URLs... */
938 for (i = 0; urls[i] != NULL; i++) ;
939 /* ...and put them in the "stack" backward */
941 rc = ldap_url_parse( urls[i], &ludp );
943 ldap_charray_free(urls);
944 ldap_free_urllist(*ludlist);
948 ludp->lud_next = *ludlist;
951 ldap_charray_free(urls);
957 LDAPURLDesc **ludlist,
965 assert( ludlist != NULL );
966 assert( hosts != NULL );
970 specs = ldap_str2charray(hosts, ", ");
972 return LDAP_NO_MEMORY;
974 /* count the URLs... */
975 for (i = 0; specs[i] != NULL; i++) /* EMPTY */;
977 /* ...and put them in the "stack" backward */
979 ludp = LDAP_CALLOC( 1, sizeof(LDAPURLDesc) );
981 ldap_charray_free(specs);
982 ldap_free_urllist(*ludlist);
984 return LDAP_NO_MEMORY;
986 ludp->lud_port = port;
987 ludp->lud_host = specs[i];
989 p = strchr(ludp->lud_host, ':');
991 /* more than one :, IPv6 address */
992 if ( strchr(p+1, ':') != NULL ) {
993 /* allow [address] and [address]:port */
994 if ( *ludp->lud_host == '[' ) {
995 p = LDAP_STRDUP(ludp->lud_host+1);
996 /* copied, make sure we free source later */
997 specs[i] = ludp->lud_host;
999 p = strchr( ludp->lud_host, ']' );
1001 return LDAP_PARAM_ERROR;
1005 return LDAP_PARAM_ERROR;
1016 ldap_pvt_hex_unescape(p);
1017 ludp->lud_port = strtol( p, &next, 10 );
1018 if ( next == NULL || next[0] != '\0' ) {
1019 return LDAP_PARAM_ERROR;
1023 ldap_pvt_hex_unescape(ludp->lud_host);
1024 ludp->lud_scheme = LDAP_STRDUP("ldap");
1025 ludp->lud_next = *ludlist;
1029 /* this should be an array of NULLs now */
1030 /* except entries starting with [ */
1031 ldap_charray_free(specs);
1032 return LDAP_SUCCESS;
1036 ldap_url_list2hosts (LDAPURLDesc *ludlist)
1040 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1042 if (ludlist == NULL)
1045 /* figure out how big the string is */
1046 size = 1; /* nul-term */
1047 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1048 size += strlen(ludp->lud_host) + 1; /* host and space */
1049 if (strchr(ludp->lud_host, ':')) /* will add [ ] below */
1051 if (ludp->lud_port != 0)
1052 size += sprintf(buf, ":%d", ludp->lud_port);
1054 s = LDAP_MALLOC(size);
1059 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1060 if (strchr(ludp->lud_host, ':')) {
1061 p += sprintf(p, "[%s]", ludp->lud_host);
1063 strcpy(p, ludp->lud_host);
1064 p += strlen(ludp->lud_host);
1066 if (ludp->lud_port != 0)
1067 p += sprintf(p, ":%d", ludp->lud_port);
1071 p--; /* nuke that extra space */
1078 LDAPURLDesc *ludlist )
1082 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1084 if (ludlist == NULL)
1087 /* figure out how big the string is */
1088 size = 1; /* nul-term */
1089 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1090 size += strlen(ludp->lud_scheme);
1091 if ( ludp->lud_host ) {
1092 size += strlen(ludp->lud_host);
1093 /* will add [ ] below */
1094 if (strchr(ludp->lud_host, ':'))
1097 size += sizeof(":/// ");
1099 if (ludp->lud_port != 0) {
1100 size += sprintf(buf, ":%d", ludp->lud_port);
1104 s = LDAP_MALLOC(size);
1110 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1111 p += sprintf(p, "%s://", ludp->lud_scheme);
1112 if ( ludp->lud_host ) {
1113 p += sprintf(p, strchr(ludp->lud_host, ':')
1114 ? "[%s]" : "%s", ludp->lud_host);
1116 if (ludp->lud_port != 0)
1117 p += sprintf(p, ":%d", ludp->lud_port);
1122 p--; /* nuke that extra space */
1128 ldap_free_urllist( LDAPURLDesc *ludlist )
1130 LDAPURLDesc *ludp, *next;
1132 for (ludp = ludlist; ludp != NULL; ludp = next) {
1133 next = ludp->lud_next;
1134 ldap_free_urldesc(ludp);
1139 ldap_free_urldesc( LDAPURLDesc *ludp )
1141 if ( ludp == NULL ) {
1145 if ( ludp->lud_scheme != NULL ) {
1146 LDAP_FREE( ludp->lud_scheme );
1149 if ( ludp->lud_host != NULL ) {
1150 LDAP_FREE( ludp->lud_host );
1153 if ( ludp->lud_dn != NULL ) {
1154 LDAP_FREE( ludp->lud_dn );
1157 if ( ludp->lud_filter != NULL ) {
1158 LDAP_FREE( ludp->lud_filter);
1161 if ( ludp->lud_attrs != NULL ) {
1162 LDAP_VFREE( ludp->lud_attrs );
1165 if ( ludp->lud_exts != NULL ) {
1166 LDAP_VFREE( ludp->lud_exts );
1173 ldap_int_unhex( int c )
1175 return( c >= '0' && c <= '9' ? c - '0'
1176 : c >= 'A' && c <= 'F' ? c - 'A' + 10
1181 ldap_pvt_hex_unescape( char *s )
1184 * Remove URL hex escapes from s... done in place. The basic concept for
1185 * this routine is borrowed from the WWW library HTUnEscape() routine.
1189 for ( p = s; *s != '\0'; ++s ) {
1191 if ( *++s == '\0' ) {
1194 *p = ldap_int_unhex( *s ) << 4;
1195 if ( *++s == '\0' ) {
1198 *p++ += ldap_int_unhex( *s );