2 * Copyright (c) 1994 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
18 #include <ac/socket.h>
19 #include <ac/string.h>
25 ldap_get_dn( LDAP *ld, LDAPMessage *entry )
30 Debug( LDAP_DEBUG_TRACE, "ldap_get_dn\n", 0, 0, 0 );
32 if ( entry == NULL ) {
33 ld->ld_errno = LDAP_PARAM_ERROR;
37 tmp = *entry->lm_ber; /* struct copy */
38 if ( ber_scanf( &tmp, "{a", &dn ) == LBER_ERROR ) {
39 ld->ld_errno = LDAP_DECODING_ERROR;
47 ldap_dn2ufn( char *dn )
52 Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 );
54 if ( ldap_is_dns_dn( dn ) || ( p = strchr( dn, '=' )) == NULL )
55 return( strdup( dn ));
62 for ( p = ufn, r = ufn; *p; p++ ) {
73 if ( state == INQUOTE )
81 if ( state == OUTQUOTE )
87 if ( state == INQUOTE )
93 while ( !isspace( *r ) && *r != ';'
94 && *r != ',' && r > ufn )
98 if ( strcasecmp( r, "c" )
99 && strcasecmp( r, "o" )
100 && strcasecmp( r, "ou" )
101 && strcasecmp( r, "st" )
102 && strcasecmp( r, "l" )
103 && strcasecmp( r, "cn" ) ) {
120 ldap_explode_dns( char *dn )
122 int ncomps, maxcomps;
126 if ( (rdns = (char **) malloc( 8 * sizeof(char *) )) == NULL ) {
132 for ( s = strtok( dn, "@." ); s != NULL; s = strtok( NULL, "@." ) ) {
133 if ( ncomps == maxcomps ) {
135 if ( (rdns = (char **) realloc( rdns, maxcomps *
136 sizeof(char *) )) == NULL ) {
140 rdns[ncomps++] = strdup( s );
148 ldap_explode_dn( char *dn, int notypes )
150 char *p, *q, *rdnstart, **rdns = NULL;
151 int state, count = 0, endquote, len;
153 Debug( LDAP_DEBUG_TRACE, "ldap_explode_dn\n", 0, 0, 0 );
155 if ( ldap_is_dns_dn( dn ) ) {
156 return( ldap_explode_dns( dn ) );
172 if ( state == INQUOTE )
180 if ( state == OUTQUOTE ) {
182 if ( rdns == NULL ) {
183 if (( rdns = (char **)malloc( 8
184 * sizeof( char *))) == NULL )
186 } else if ( count >= 8 ) {
187 if (( rdns = (char **)realloc( rdns,
188 (count+1) * sizeof( char *)))
192 rdns[ count ] = NULL;
196 q < p && *q != '='; ++q ) {
202 if ( *rdnstart == '"' ) {
206 if ( *(p-1) == '"' ) {
213 if (( rdns[ count-1 ] = (char *)calloc( 1,
214 len + 1 )) != NULL ) {
215 SAFEMEMCPY( rdns[ count-1 ], rdnstart,
217 rdns[ count-1 ][ len ] = '\0';
221 * Don't forget to increment 'p' back to where
222 * it should be. If we don't, then we will
223 * never get past an "end quote."
228 rdnstart = *p ? p + 1 : p;
229 while ( isspace( *rdnstart ))
241 ldap_is_dns_dn( char *dn )
243 return( dn[ 0 ] != '\0' && strchr( dn, '=' ) == NULL &&
244 strchr( dn, ',' ) == NULL );