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++ ) {
141 *s = TOUPPER( (unsigned char) *s );
148 * dn_parent - return a copy of the dn of dn's parent
164 while(*dn && SPACE(*dn)) {
172 if ( be_issuffix( be, dn ) ) {
177 * no =, assume it is a dns name, like blah@some.domain.name
178 * if the blah@ part is there, return some.domain.name. if
179 * it's just some.domain.name, return domain.name.
181 if ( strchr( dn, '=' ) == NULL ) {
182 if ( (s = strchr( dn, '@' )) == NULL ) {
183 if ( (s = strchr( dn, '.' )) == NULL ) {
187 if ( *(s + 1) == '\0' ) {
190 return( ch_strdup( &s[1] ) );
195 * else assume it is an X.500-style name, which looks like
196 * foo=bar,sha=baz,...
200 for ( s = dn; *s; s++ ) {
214 } else if ( DNSEPARATOR( *s ) ) {
215 return( ch_strdup( &s[1] ) );
220 return( ch_strdup( "" ) );
234 while(*dn && SPACE(*dn)) {
242 if ( be_issuffix( be, dn ) ) {
246 dn = ch_strdup( dn );
249 * no =, assume it is a dns name, like blah@some.domain.name
250 * if the blah@ part is there, return some.domain.name. if
251 * it's just some.domain.name, return domain.name.
253 if ( strchr( dn, '=' ) == NULL ) {
254 if ( (s = strchr( dn, '@' )) == NULL ) {
255 if ( (s = strchr( dn, '.' )) == NULL ) {
264 * else assume it is an X.500-style name, which looks like
265 * foo=bar,sha=baz,...
270 for ( s = dn; *s; s++ ) {
284 } else if ( DNSEPARATOR( *s ) ) {
295 * dn_issuffix - tells whether suffix is a suffix of dn. both dn
296 * and suffix must be normalized.
305 int dnlen, suffixlen;
311 suffixlen = strlen( suffix );
312 dnlen = strlen( dn );
314 if ( suffixlen > dnlen ) {
318 return( strcmp( dn + dnlen - suffixlen, suffix ) == 0 );
322 * dn_type - tells whether the given dn is an X.500 thing or DNS thing
323 * returns (defined in slap.h): DN_DNS dns-style thing
324 * DN_X500 x500-style thing
330 return( strchr( dn, '=' ) == NULL ? DN_DNS : DN_X500 );
334 dn_upcase( char *dn )
339 for ( s = dn; *s; s++ ) {
340 *s = TOUPPER( (unsigned char) *s );