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;
253 static int hex_escape( char *buf, const char *s, int list )
257 static const char hex[] = "0123456789ABCDEF";
259 if( s == NULL ) return 0;
261 for( pos=0,i=0; s[i]; i++ ) {
287 escape = s[i] < 0x20 || 0x1f >= s[i];
292 buf[pos++] = hex[ (s[i] >> 4) & 0x0f ];
293 buf[pos++] = hex[ s[i] & 0x0f ];
303 static int hex_escape_args( char *buf, char **s )
308 if( s == NULL ) return 0;
311 for( i=0; s[i] != NULL; i++ ) {
315 pos += hex_escape( &buf[pos], s[i], 1 );
321 char * ldap_url_desc2str( LDAPURLDesc *u )
328 if( u == NULL ) return NULL;
331 for( i=0; u->lud_exts[i]; i++ ) {
332 len += strlen( u->lud_exts[i] ) + 1;
337 if( u->lud_filter ) {
338 len += strlen( u->lud_filter );
341 if ( len ) len++; /* ? */
343 switch( u->lud_scope ) {
344 case LDAP_SCOPE_ONELEVEL:
345 case LDAP_SCOPE_SUBTREE:
346 case LDAP_SCOPE_BASE:
347 len += sizeof("base");
352 if ( len ) len++; /* ? */
356 for( i=0; u->lud_attrs[i]; i++ ) {
357 len += strlen( u->lud_attrs[i] ) + 1;
360 } else if ( len ) len++; /* ? */
363 len += strlen( u->lud_dn ) + 1;
368 len += sizeof(":65535") - 1;
372 len+=strlen( u->lud_host );
375 len += strlen( u->lud_scheme ) + sizeof("://");
377 /* allocate enough to hex escape everything -- overkill */
378 s = LDAP_MALLOC( 3*len );
380 if( s == NULL ) return NULL;
383 sprintf( s, "%s://%s:%d%n", u->lud_scheme,
384 u->lud_host, u->lud_port, &sofar );
386 sprintf( s, "%s://%s%n", u->lud_scheme,
387 u->lud_host, &sofar );
390 if( sep < 1 ) goto done;
393 sofar += hex_escape( &s[sofar], u->lud_dn, 0 );
395 if( sep < 2 ) goto done;
398 sofar += hex_escape_args( &s[sofar], u->lud_attrs );
400 if( sep < 3 ) goto done;
403 switch( u->lud_scope ) {
404 case LDAP_SCOPE_BASE:
405 strcpy( &s[sofar], "base" );
406 sofar += sizeof("base") - 1;
408 case LDAP_SCOPE_ONELEVEL:
409 strcpy( &s[sofar], "one" );
410 sofar += sizeof("one") - 1;
412 case LDAP_SCOPE_SUBTREE:
413 strcpy( &s[sofar], "sub" );
414 sofar += sizeof("sub") - 1;
418 if( sep < 4 ) goto done;
421 sofar += hex_escape( &s[sofar], u->lud_filter, 0 );
423 if( sep < 5 ) goto done;
426 sofar += hex_escape_args( &s[sofar], u->lud_exts );
434 ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
437 * Pick apart the pieces of an LDAP URL.
443 const char *scheme = NULL;
447 if( url_in == NULL || ludpp == NULL ) {
448 return LDAP_URL_ERR_PARAM;
451 #ifndef LDAP_INT_IN_KERNEL
452 /* Global options may not be created yet
453 * We can't test if the global options are initialized
454 * because a call to LDAP_INT_GLOBAL_OPT() will try to allocate
455 * the options and cause infinite recursion
458 LDAP_LOG ( OPERATION, ENTRY, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
460 Debug( LDAP_DEBUG_TRACE, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
464 *ludpp = NULL; /* pessimistic */
466 url_tmp = skip_url_prefix( url_in, &enclosed, &scheme );
468 if ( url_tmp == NULL ) {
469 return LDAP_URL_ERR_BADSCHEME;
474 /* make working copy of the remainder of the URL */
475 url = LDAP_STRDUP( url_tmp );
477 return LDAP_URL_ERR_MEM;
481 p = &url[strlen(url)-1];
485 return LDAP_URL_ERR_BADENCLOSURE;
491 /* allocate return struct */
492 ludp = (LDAPURLDesc *)LDAP_CALLOC( 1, sizeof( LDAPURLDesc ));
494 if ( ludp == NULL ) {
496 return LDAP_URL_ERR_MEM;
499 ludp->lud_next = NULL;
500 ludp->lud_host = NULL;
503 ludp->lud_attrs = NULL;
504 ludp->lud_filter = NULL;
505 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
506 ludp->lud_filter = NULL;
507 ludp->lud_exts = NULL;
509 ludp->lud_scheme = LDAP_STRDUP( scheme );
511 if ( ludp->lud_scheme == NULL ) {
513 ldap_free_urldesc( ludp );
514 return LDAP_URL_ERR_MEM;
517 /* scan forward for '/' that marks end of hostport and begin. of dn */
518 p = strchr( url, '/' );
521 /* terminate hostport; point to start of dn */
525 /* IPv6 syntax with [ip address]:port */
527 r = strchr( url, ']' );
530 ldap_free_urldesc( ludp );
531 return LDAP_URL_ERR_BADURL;
534 q = strchr( r, ':' );
536 q = strchr( url, ':' );
543 ldap_pvt_hex_unescape( q );
547 ldap_free_urldesc( ludp );
548 return LDAP_URL_ERR_BADURL;
551 ludp->lud_port = strtol( q, &next, 10 );
552 if ( next == NULL || next[0] != '\0' ) {
554 ldap_free_urldesc( ludp );
555 return LDAP_URL_ERR_BADURL;
559 ldap_pvt_hex_unescape( url );
561 /* If [ip address]:port syntax, url is [ip and we skip the [ */
562 ludp->lud_host = LDAP_STRDUP( url + ( *url == '[' ) );
564 if( ludp->lud_host == NULL ) {
566 ldap_free_urldesc( ludp );
567 return LDAP_URL_ERR_MEM;
571 * Kludge. ldap://111.222.333.444:389??cn=abc,o=company
573 * On early Novell releases, search references/referrals were returned
574 * in this format, i.e., the dn was kind of in the scope position,
575 * but the required slash is missing. The whole thing is illegal syntax,
576 * but we need to account for it. Fortunately it can't be confused with
579 if( (p == NULL) && (q != NULL) && ((q = strchr( q, '?')) != NULL)) {
581 /* ? immediately followed by question */
586 ldap_pvt_hex_unescape( q );
587 ludp->lud_dn = LDAP_STRDUP( q );
589 ludp->lud_dn = LDAP_STRDUP( "" );
592 if( ludp->lud_dn == NULL ) {
594 ldap_free_urldesc( ludp );
595 return LDAP_URL_ERR_MEM;
603 return LDAP_URL_SUCCESS;
606 /* scan forward for '?' that may marks end of dn */
607 q = strchr( p, '?' );
610 /* terminate dn part */
616 ldap_pvt_hex_unescape( p );
617 ludp->lud_dn = LDAP_STRDUP( p );
619 ludp->lud_dn = LDAP_STRDUP( "" );
622 if( ludp->lud_dn == NULL ) {
624 ldap_free_urldesc( ludp );
625 return LDAP_URL_ERR_MEM;
632 return LDAP_URL_SUCCESS;
635 /* scan forward for '?' that may marks end of attributes */
637 q = strchr( p, '?' );
640 /* terminate attributes part */
645 /* parse attributes */
646 ldap_pvt_hex_unescape( p );
647 ludp->lud_attrs = ldap_str2charray( p, "," );
649 if( ludp->lud_attrs == NULL ) {
651 ldap_free_urldesc( ludp );
652 return LDAP_URL_ERR_BADATTRS;
660 return LDAP_URL_SUCCESS;
663 /* scan forward for '?' that may marks end of scope */
665 q = strchr( p, '?' );
668 /* terminate the scope part */
673 /* parse the scope */
674 ldap_pvt_hex_unescape( p );
675 ludp->lud_scope = str2scope( p );
677 if( ludp->lud_scope == -1 ) {
679 ldap_free_urldesc( ludp );
680 return LDAP_URL_ERR_BADSCOPE;
688 return LDAP_URL_SUCCESS;
691 /* scan forward for '?' that may marks end of filter */
693 q = strchr( p, '?' );
696 /* terminate the filter part */
701 /* parse the filter */
702 ldap_pvt_hex_unescape( p );
707 ldap_free_urldesc( ludp );
708 return LDAP_URL_ERR_BADFILTER;
711 LDAP_FREE( ludp->lud_filter );
712 ludp->lud_filter = LDAP_STRDUP( p );
714 if( ludp->lud_filter == NULL ) {
716 ldap_free_urldesc( ludp );
717 return LDAP_URL_ERR_MEM;
725 return LDAP_URL_SUCCESS;
728 /* scan forward for '?' that may marks end of extensions */
730 q = strchr( p, '?' );
735 ldap_free_urldesc( ludp );
736 return LDAP_URL_ERR_BADURL;
739 /* parse the extensions */
740 ludp->lud_exts = ldap_str2charray( p, "," );
742 if( ludp->lud_exts == NULL ) {
744 ldap_free_urldesc( ludp );
745 return LDAP_URL_ERR_BADEXTS;
748 for( i=0; ludp->lud_exts[i] != NULL; i++ ) {
749 ldap_pvt_hex_unescape( ludp->lud_exts[i] );
751 if( *ludp->lud_exts[i] == '!' ) {
752 /* count the number of critical extensions */
753 ludp->lud_crit_exts++;
758 /* must have 1 or more */
760 ldap_free_urldesc( ludp );
761 return LDAP_URL_ERR_BADEXTS;
767 return LDAP_URL_SUCCESS;
771 ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
773 int rc = ldap_url_parse_ext( url_in, ludpp );
775 if( rc != LDAP_URL_SUCCESS ) {
779 if ((*ludpp)->lud_scope == LDAP_SCOPE_DEFAULT) {
780 (*ludpp)->lud_scope = LDAP_SCOPE_BASE;
783 if ((*ludpp)->lud_host != NULL && *(*ludpp)->lud_host == '\0') {
784 LDAP_FREE( (*ludpp)->lud_host );
785 (*ludpp)->lud_host = NULL;
788 if ((*ludpp)->lud_port == 0) {
789 if( strcmp((*ludpp)->lud_scheme, "ldap") == 0 ) {
790 (*ludpp)->lud_port = LDAP_PORT;
791 #ifdef LDAP_CONNECTIONLESS
792 } else if( strcmp((*ludpp)->lud_scheme, "cldap") == 0 ) {
793 (*ludpp)->lud_port = LDAP_PORT;
795 } else if( strcmp((*ludpp)->lud_scheme, "ldaps") == 0 ) {
796 (*ludpp)->lud_port = LDAPS_PORT;
804 ldap_url_dup ( LDAPURLDesc *ludp )
808 if ( ludp == NULL ) {
812 dest = LDAP_MALLOC( sizeof(LDAPURLDesc) );
817 dest->lud_scheme = NULL;
818 dest->lud_host = NULL;
820 dest->lud_filter = NULL;
821 dest->lud_attrs = NULL;
822 dest->lud_exts = NULL;
823 dest->lud_next = NULL;
825 if ( ludp->lud_scheme != NULL ) {
826 dest->lud_scheme = LDAP_STRDUP( ludp->lud_scheme );
827 if (dest->lud_scheme == NULL) {
828 ldap_free_urldesc(dest);
833 if ( ludp->lud_host != NULL ) {
834 dest->lud_host = LDAP_STRDUP( ludp->lud_host );
835 if (dest->lud_host == NULL) {
836 ldap_free_urldesc(dest);
841 if ( ludp->lud_dn != NULL ) {
842 dest->lud_dn = LDAP_STRDUP( ludp->lud_dn );
843 if (dest->lud_dn == NULL) {
844 ldap_free_urldesc(dest);
849 if ( ludp->lud_filter != NULL ) {
850 dest->lud_filter = LDAP_STRDUP( ludp->lud_filter );
851 if (dest->lud_filter == NULL) {
852 ldap_free_urldesc(dest);
857 if ( ludp->lud_attrs != NULL ) {
858 dest->lud_attrs = ldap_charray_dup( ludp->lud_attrs );
859 if (dest->lud_attrs == NULL) {
860 ldap_free_urldesc(dest);
865 if ( ludp->lud_exts != NULL ) {
866 dest->lud_exts = ldap_charray_dup( ludp->lud_exts );
867 if (dest->lud_exts == NULL) {
868 ldap_free_urldesc(dest);
877 ldap_url_duplist (LDAPURLDesc *ludlist)
879 LDAPURLDesc *dest, *tail, *ludp, *newludp;
883 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
884 newludp = ldap_url_dup(ludp);
885 if (newludp == NULL) {
886 ldap_free_urllist(dest);
892 tail->lud_next = newludp;
899 ldap_url_parselist (LDAPURLDesc **ludlist, const char *url )
901 return ldap_url_parselist_ext( ludlist, url, ", " );
905 ldap_url_parselist_ext (LDAPURLDesc **ludlist, const char *url, const char *sep )
911 assert( ludlist != NULL );
912 assert( url != NULL );
916 urls = ldap_str2charray(url, sep);
918 return LDAP_URL_ERR_MEM;
920 /* count the URLs... */
921 for (i = 0; urls[i] != NULL; i++) ;
922 /* ...and put them in the "stack" backward */
924 rc = ldap_url_parse( urls[i], &ludp );
926 ldap_charray_free(urls);
927 ldap_free_urllist(*ludlist);
931 ludp->lud_next = *ludlist;
934 ldap_charray_free(urls);
935 return LDAP_URL_SUCCESS;
940 LDAPURLDesc **ludlist,
948 assert( ludlist != NULL );
949 assert( hosts != NULL );
953 specs = ldap_str2charray(hosts, ", ");
955 return LDAP_NO_MEMORY;
957 /* count the URLs... */
958 for (i = 0; specs[i] != NULL; i++) /* EMPTY */;
960 /* ...and put them in the "stack" backward */
962 ludp = LDAP_CALLOC( 1, sizeof(LDAPURLDesc) );
964 ldap_charray_free(specs);
965 ldap_free_urllist(*ludlist);
967 return LDAP_NO_MEMORY;
969 ludp->lud_port = port;
970 ludp->lud_host = specs[i];
972 p = strchr(ludp->lud_host, ':');
974 /* more than one :, IPv6 address */
975 if ( strchr(p+1, ':') != NULL ) {
976 /* allow [address] and [address]:port */
977 if ( *ludp->lud_host == '[' ) {
978 p = LDAP_STRDUP(ludp->lud_host+1);
979 /* copied, make sure we free source later */
980 specs[i] = ludp->lud_host;
982 p = strchr( ludp->lud_host, ']' );
984 return LDAP_PARAM_ERROR;
988 return LDAP_PARAM_ERROR;
999 ldap_pvt_hex_unescape(p);
1000 ludp->lud_port = strtol( p, &next, 10 );
1001 if ( next == NULL || next[0] != '\0' ) {
1002 return LDAP_PARAM_ERROR;
1006 ldap_pvt_hex_unescape(ludp->lud_host);
1007 ludp->lud_scheme = LDAP_STRDUP("ldap");
1008 ludp->lud_next = *ludlist;
1012 /* this should be an array of NULLs now */
1013 /* except entries starting with [ */
1014 ldap_charray_free(specs);
1015 return LDAP_SUCCESS;
1019 ldap_url_list2hosts (LDAPURLDesc *ludlist)
1023 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1025 if (ludlist == NULL)
1028 /* figure out how big the string is */
1029 size = 1; /* nul-term */
1030 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1031 size += strlen(ludp->lud_host) + 1; /* host and space */
1032 if (strchr(ludp->lud_host, ':')) /* will add [ ] below */
1034 if (ludp->lud_port != 0)
1035 size += sprintf(buf, ":%d", ludp->lud_port);
1037 s = LDAP_MALLOC(size);
1042 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1043 if (strchr(ludp->lud_host, ':')) {
1044 p += sprintf(p, "[%s]", ludp->lud_host);
1046 strcpy(p, ludp->lud_host);
1047 p += strlen(ludp->lud_host);
1049 if (ludp->lud_port != 0)
1050 p += sprintf(p, ":%d", ludp->lud_port);
1054 p--; /* nuke that extra space */
1061 LDAPURLDesc *ludlist )
1065 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1067 if (ludlist == NULL)
1070 /* figure out how big the string is */
1071 size = 1; /* nul-term */
1072 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1073 size += strlen(ludp->lud_scheme);
1074 if ( ludp->lud_host ) {
1075 size += strlen(ludp->lud_host);
1076 /* will add [ ] below */
1077 if (strchr(ludp->lud_host, ':'))
1080 size += sizeof(":/// ");
1082 if (ludp->lud_port != 0) {
1083 size += sprintf(buf, ":%d", ludp->lud_port);
1087 s = LDAP_MALLOC(size);
1093 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1094 p += sprintf(p, "%s://", ludp->lud_scheme);
1095 if ( ludp->lud_host ) {
1096 p += sprintf(p, strchr(ludp->lud_host, ':')
1097 ? "[%s]" : "%s", ludp->lud_host);
1099 if (ludp->lud_port != 0)
1100 p += sprintf(p, ":%d", ludp->lud_port);
1105 p--; /* nuke that extra space */
1111 ldap_free_urllist( LDAPURLDesc *ludlist )
1113 LDAPURLDesc *ludp, *next;
1115 for (ludp = ludlist; ludp != NULL; ludp = next) {
1116 next = ludp->lud_next;
1117 ldap_free_urldesc(ludp);
1122 ldap_free_urldesc( LDAPURLDesc *ludp )
1124 if ( ludp == NULL ) {
1128 if ( ludp->lud_scheme != NULL ) {
1129 LDAP_FREE( ludp->lud_scheme );
1132 if ( ludp->lud_host != NULL ) {
1133 LDAP_FREE( ludp->lud_host );
1136 if ( ludp->lud_dn != NULL ) {
1137 LDAP_FREE( ludp->lud_dn );
1140 if ( ludp->lud_filter != NULL ) {
1141 LDAP_FREE( ludp->lud_filter);
1144 if ( ludp->lud_attrs != NULL ) {
1145 LDAP_VFREE( ludp->lud_attrs );
1148 if ( ludp->lud_exts != NULL ) {
1149 LDAP_VFREE( ludp->lud_exts );
1156 ldap_int_unhex( int c )
1158 return( c >= '0' && c <= '9' ? c - '0'
1159 : c >= 'A' && c <= 'F' ? c - 'A' + 10
1164 ldap_pvt_hex_unescape( char *s )
1167 * Remove URL hex escapes from s... done in place. The basic concept for
1168 * this routine is borrowed from the WWW library HTUnEscape() routine.
1172 for ( p = s; *s != '\0'; ++s ) {
1174 if ( *++s == '\0' ) {
1177 *p = ldap_int_unhex( *s ) << 4;
1178 if ( *++s == '\0' ) {
1181 *p++ += ldap_int_unhex( *s );