/* returns the message id of the request or -1 if an error occurs */ int nsldapi_send_initial_request( LDAP *ld, int msgid, unsigned long msgtype, char *dn, BerElement *ber ) { LDAPServer *servers; LDAPDebug( LDAP_DEBUG_TRACE, "nsldapi_send_initial_request\n", 0,0,0 ); #ifdef LDAP_DNS LDAP_MUTEX_LOCK( ld, LDAP_OPTION_LOCK ); if (( ld->ld_options & LDAP_BITOPT_DNS ) != 0 && ldap_is_dns_dn( dn )) { if (( servers = dn2servers( ld, dn )) == NULL ) { ber_free( ber, 1 ); LDAP_MUTEX_UNLOCK( ld, LDAP_OPTION_LOCK ); return( -1 ); } #ifdef LDAP_DEBUG if ( ldap_debug & LDAP_DEBUG_TRACE ) { LDAPServer *srv; char msg[256]; for ( srv = servers; srv != NULL; srv = srv->lsrv_next ) { sprintf( msg, "LDAP server %s: dn %s, port %d\n", srv->lsrv_host, ( srv->lsrv_dn == NULL ) ? "(default)" : srv->lsrv_dn, srv->lsrv_port ); ber_err_print( msg ); } } #endif /* LDAP_DEBUG */ } else { #endif /* LDAP_DNS */ /* * use of DNS is turned off or this is an LDAP DN... * use our default connection */ servers = NULL; #ifdef LDAP_DNS } LDAP_MUTEX_UNLOCK( ld, LDAP_OPTION_LOCK ); #endif /* LDAP_DNS */ return( nsldapi_send_server_request( ld, ber, msgid, NULL, servers, NULL, ( msgtype == LDAP_REQ_BIND ) ? dn : NULL, 0 )); }
LDAP_CALL ldap_dn2ufn( const char *dn ) { char *p, *ufn, *r; size_t plen; int state; LDAPDebug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 ); if ( dn == NULL ) { dn = ""; } if ( ldap_is_dns_dn( dn ) || ( p = strchr( dn, '=' )) == NULL ) return( nsldapi_strdup( (char *)dn )); ufn = nsldapi_strdup( ++p ); #define INQUOTE 1 #define OUTQUOTE 2 state = OUTQUOTE; for ( p = ufn, r = ufn; *p; p += plen ) { plen = 1; switch ( *p ) { case '\\': if ( *++p == '\0' ) plen=0; else { *r++ = '\\'; r += (plen = LDAP_UTF8COPY(r,p)); } break; case '"': if ( state == INQUOTE ) state = OUTQUOTE; else state = INQUOTE; *r++ = *p; break; case ';': case ',': if ( state == OUTQUOTE ) *r++ = ','; else *r++ = *p; break; case '=': if ( state == INQUOTE ) *r++ = *p; else { char *rsave = r; LDAP_UTF8DEC(r); *rsave = '\0'; while ( !ldap_utf8isspace( r ) && *r != ';' && *r != ',' && r > ufn ) LDAP_UTF8DEC(r); LDAP_UTF8INC(r); if ( strcasecmp( r, "c" ) && strcasecmp( r, "o" ) && strcasecmp( r, "ou" ) && strcasecmp( r, "st" ) && strcasecmp( r, "l" ) && strcasecmp( r, "dc" ) && strcasecmp( r, "uid" ) && strcasecmp( r, "cn" ) ) { r = rsave; *r++ = '='; } } break; default: r += (plen = LDAP_UTF8COPY(r,p)); break; } } *r = '\0'; return( ufn ); }