mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-30 13:30:57 +08:00
Use ldap_str2rdn
This commit is contained in:
parent
6fa6ac6676
commit
fdc4dec350
@ -399,38 +399,22 @@ monitor_subsys_conn_create(
|
|||||||
*ep = e;
|
*ep = e;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char **values = NULL;
|
LDAPRDN *values = NULL;
|
||||||
|
const char *text = NULL;
|
||||||
unsigned long connid;
|
unsigned long connid;
|
||||||
|
|
||||||
/* create exactly the required entry */
|
/* create exactly the required entry */
|
||||||
|
|
||||||
#if 0
|
if ( ldap_str2rdn( ndn->bv_val, &values, &text, LDAP_DN_FORMAT_LDAP ) ) {
|
||||||
struct berval rdn;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: we can pass the entire DN
|
|
||||||
* only if rdn_attrs does not complain.
|
|
||||||
*/
|
|
||||||
if ( dnExtractRdn( ndn, &rdn ) != LDAP_SUCCESS ) {
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
if ( rdn_attrs( rdn.bv_val, NULL, &values ) != LDAP_SUCCESS ) {
|
|
||||||
free( rdn.bv_val );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
free( rdn.bv_val );
|
|
||||||
#else
|
|
||||||
if ( rdn_attrs( ndn->bv_val, NULL, &values ) != LDAP_SUCCESS ) {
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
assert( values );
|
assert( values );
|
||||||
assert( values[ 0 ] );
|
assert( values[ 0 ][ 0 ] );
|
||||||
|
|
||||||
connid = atol( values[ 0 ] );
|
connid = atol( values[ 0 ][ 0 ]->la_value.bv_val );
|
||||||
|
|
||||||
ldap_value_free( values );
|
ldap_rdnfree( values );
|
||||||
|
|
||||||
for ( c = connection_first( &connindex );
|
for ( c = connection_first( &connindex );
|
||||||
c != NULL;
|
c != NULL;
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
static Entry *pw2entry(
|
static Entry *pw2entry(
|
||||||
Backend *be,
|
Backend *be,
|
||||||
struct passwd *pw,
|
struct passwd *pw);
|
||||||
char *rdn);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
passwd_back_search(
|
passwd_back_search(
|
||||||
@ -46,7 +45,7 @@ passwd_back_search(
|
|||||||
int sent = 0;
|
int sent = 0;
|
||||||
int err = LDAP_SUCCESS;
|
int err = LDAP_SUCCESS;
|
||||||
|
|
||||||
char *rdn = NULL;
|
LDAPRDN *rdn = NULL;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
char *matched = NULL;
|
char *matched = NULL;
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
@ -77,7 +76,7 @@ passwd_back_search(
|
|||||||
matched = (char *) base;
|
matched = (char *) base;
|
||||||
|
|
||||||
if( scope != LDAP_SCOPE_ONELEVEL ) {
|
if( scope != LDAP_SCOPE_ONELEVEL ) {
|
||||||
char *type;
|
const char *text;
|
||||||
AttributeDescription *desc = NULL;
|
AttributeDescription *desc = NULL;
|
||||||
|
|
||||||
/* Create an entry corresponding to the base DN */
|
/* Create an entry corresponding to the base DN */
|
||||||
@ -92,34 +91,22 @@ passwd_back_search(
|
|||||||
/* Use the first attribute of the DN
|
/* Use the first attribute of the DN
|
||||||
* as an attribute within the entry itself.
|
* as an attribute within the entry itself.
|
||||||
*/
|
*/
|
||||||
rdn = dn_rdn(NULL, base);
|
if( ldap_str2rdn( base->bv_val, &rdn, &text,
|
||||||
|
LDAP_DN_FORMAT_LDAP ) ) {
|
||||||
if( rdn == NULL || (s = strchr(rdn, '=')) == NULL ) {
|
|
||||||
err = LDAP_INVALID_DN_SYNTAX;
|
err = LDAP_INVALID_DN_SYNTAX;
|
||||||
free(rdn);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
val.bv_val = rdn_attr_value(rdn);
|
if( slap_bv2ad( &rdn[0][0]->la_attr, &desc, &text )) {
|
||||||
val.bv_len = strlen( val.bv_val );
|
err = LDAP_NO_SUCH_OBJECT;
|
||||||
|
ldap_rdnfree(rdn);
|
||||||
type = rdn_attr_type(rdn);
|
goto done;
|
||||||
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
const char *text;
|
|
||||||
rc = slap_str2ad( type, &desc, &text );
|
|
||||||
|
|
||||||
if( rc != LDAP_SUCCESS ) {
|
|
||||||
err = LDAP_NO_SUCH_OBJECT;
|
|
||||||
free(rdn);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val = rdn[0][0]->la_value;
|
||||||
attr_merge( e, desc, vals );
|
attr_merge( e, desc, vals );
|
||||||
|
|
||||||
free(rdn);
|
ldap_rdnfree(rdn);
|
||||||
rdn = NULL;
|
rdn = NULL;
|
||||||
|
|
||||||
/* Every entry needs an objectclass. We don't really
|
/* Every entry needs an objectclass. We don't really
|
||||||
@ -161,7 +148,7 @@ passwd_back_search(
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
e = pw2entry( be, pw, NULL );
|
e = pw2entry( be, pw );
|
||||||
|
|
||||||
if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
|
if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
|
||||||
/* check size limit */
|
/* check size limit */
|
||||||
@ -183,6 +170,8 @@ passwd_back_search(
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
const char *text = NULL;
|
||||||
|
|
||||||
parent = dn_parent( be, nbase->bv_val );
|
parent = dn_parent( be, nbase->bv_val );
|
||||||
|
|
||||||
/* This backend is only one layer deep. Don't answer requests for
|
/* This backend is only one layer deep. Don't answer requests for
|
||||||
@ -204,20 +193,18 @@ passwd_back_search(
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdn = dn_rdn( NULL, base );
|
if ( ldap_str2rdn( base->bv_val, &rdn, &text, LDAP_DN_FORMAT_LDAP )) {
|
||||||
|
|
||||||
if ( (user = rdn_attr_value(rdn)) == NULL) {
|
|
||||||
err = LDAP_OPERATIONS_ERROR;
|
err = LDAP_OPERATIONS_ERROR;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (pw = getpwnam( user )) == NULL ) {
|
if ( (pw = getpwnam( rdn[0][0]->la_value.bv_val )) == NULL ) {
|
||||||
matched = parent;
|
matched = parent;
|
||||||
err = LDAP_NO_SUCH_OBJECT;
|
err = LDAP_NO_SUCH_OBJECT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = pw2entry( be, pw, rdn );
|
e = pw2entry( be, pw );
|
||||||
|
|
||||||
if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
|
if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
|
||||||
send_search_entry( be, conn, op,
|
send_search_entry( be, conn, op,
|
||||||
@ -233,14 +220,13 @@ done:
|
|||||||
err, err == LDAP_NO_SUCH_OBJECT ? matched : NULL, NULL,
|
err, err == LDAP_NO_SUCH_OBJECT ? matched : NULL, NULL,
|
||||||
NULL, NULL );
|
NULL, NULL );
|
||||||
|
|
||||||
if( rdn != NULL ) free( rdn );
|
if( rdn != NULL ) ldap_rdnfree( rdn );
|
||||||
if( user != NULL ) free( user );
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Entry *
|
static Entry *
|
||||||
pw2entry( Backend *be, struct passwd *pw, char *rdn )
|
pw2entry( Backend *be, struct passwd *pw )
|
||||||
{
|
{
|
||||||
size_t pwlen;
|
size_t pwlen;
|
||||||
Entry *e;
|
Entry *e;
|
||||||
|
Loading…
Reference in New Issue
Block a user