1 /* dn.c - routines for dealing with distinguished names */
19 #define INQUOTEDVALUE 5
23 * dn_normalize - put dn into a canonical format. the dn is
24 * normalized in place, as well as returned.
28 dn_normalize( char *dn )
33 /* Debug( LDAP_DEBUG_TRACE, "=> dn_normalize \"%s\"\n", dn, 0, 0 ); */
37 for ( d = s = dn; *s; s++ ) {
40 if ( ! SPACE( *s ) ) {
49 } else if ( SPACE( *s ) ) {
59 } else if ( ! SPACE( *s ) ) {
60 /* not a valid dn - but what can we do here? */
66 state = INQUOTEDVALUE;
68 } else if ( ! SPACE( *s ) ) {
74 if ( !gotesc && SEPARATOR( *s ) ) {
75 while ( SPACE( *(d - 1) ) )
83 } else if ( gotesc && !NEEDSESCAPE( *s ) &&
92 if ( !gotesc && *s == '"' ) {
95 } else if ( gotesc && !NEEDSESCAPE( *s ) ) {
103 if ( SEPARATOR( *s ) ) {
109 Debug( LDAP_DEBUG_ANY,
110 "dn_normalize - unknown state %d\n", state, 0, 0 );
121 /* Debug( LDAP_DEBUG_TRACE, "<= dn_normalize \"%s\"\n", dn, 0, 0 ); */
126 * dn_normalize_case - put dn into a canonical form suitable for storing
127 * in a hash database. this involves normalizing the case as well as
128 * the format. the dn is normalized in place as well as returned.
132 dn_normalize_case( char *dn )
136 /* normalize format */
140 for ( s = dn; *s; s++ ) {
148 * dn_parent - return a copy of the dn of dn's parent
160 if ( dn == NULL || *dn == '\0' || be_issuffix( be, dn ) ) {
165 * no =, assume it is a dns name, like blah@some.domain.name
166 * if the blah@ part is there, return some.domain.name. if
167 * it's just some.domain.name, return domain.name.
169 if ( strchr( dn, '=' ) == NULL ) {
170 if ( (s = strchr( dn, '@' )) == NULL ) {
171 if ( (s = strchr( dn, '.' )) == NULL ) {
175 if ( *(s + 1) == '\0' ) {
178 return( ch_strdup( s + 1 ) );
183 * else assume it is an X.500-style name, which looks like
184 * foo=bar,sha=baz,...
188 for ( s = dn; *s; s++ ) {
200 else if ( DNSEPARATOR( *s ) )
201 return( ch_strdup( s + 1 ) );
205 return( ch_strdup("") );
209 * dn_issuffix - tells whether suffix is a suffix of dn. both dn
210 * and suffix must be normalized.
219 int dnlen, suffixlen;
225 suffixlen = strlen( suffix );
226 dnlen = strlen( dn );
228 if ( suffixlen > dnlen ) {
232 return( strcasecmp( dn + dnlen - suffixlen, suffix ) == 0 );
236 * dn_type - tells whether the given dn is an X.500 thing or DNS thing
237 * returns (defined in slap.h): DN_DNS dns-style thing
238 * DN_X500 x500-style thing
244 return( strchr( dn, '=' ) == NULL ? DN_DNS : DN_X500 );
248 dn_upcase( char *dn )
253 for ( s = dn; *s; s++ ) {