From: Luke Howard Date: Sun, 23 May 2004 15:47:23 +0000 (+0000) Subject: Add slapi_entry_add_rdn_values(), slapi_entry_rdn_values_present(), slapi_entry_schem... X-Git-Tag: OPENDLAP_REL_ENG_2_2_MP~336 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4c2e3eeda4e27a6023f0f9f59d782c4d8ae13524;p=openldap Add slapi_entry_add_rdn_values(), slapi_entry_rdn_values_present(), slapi_entry_schema_check() API --- diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index 7e256aab5a..2710ece83c 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -61,6 +61,10 @@ extern int slapi_entry_add_string(Slapi_Entry *e, const char *type, const char * extern int slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value); extern int slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr ); extern int slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr ); +extern int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e ); +extern int slapi_entry_rdn_values_present( const Slapi_Entry *e ); +extern int slapi_entry_add_rdn_values( Slapi_Entry *e ); + extern char *slapi_entry_get_dn( Slapi_Entry *e ); extern int slapi_x_entry_get_id( Slapi_Entry *e ); extern void slapi_entry_set_dn( Slapi_Entry *e, char *dn ); diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 4f8146474b..e0af81be67 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -4071,3 +4071,98 @@ char *slapi_dn_plus_rdn( const char *dn, const char *rdn ) #endif /* LDAP_SLAPI */ } +int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e ) +{ +#ifdef LDAP_SLAPI + Backend *be; + const char *text; + char textbuf[SLAP_TEXT_BUFLEN] = { '\0' }; + size_t textlen = sizeof textbuf; + int rc; + + if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 ) + return -1; + + rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen ); + + return ( rc == LDAP_SUCCESS ) ? 0 : 1; +#else + return -1; +#endif /* LDAP_SLAPI */ +} + +int slapi_entry_rdn_values_present( const Slapi_Entry *e ) +{ +#ifdef LDAP_SLAPI + LDAPDN dn; + int rc; + int i = 0, match = 0; + char *dn_str; + + dn_str = slapi_entry_get_dn( (Slapi_Entry *) e ); + rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + if ( dn[0] != NULL ) { + LDAPRDN rdn = dn[0]; + + for ( i = 0; rdn[i] != NULL; i++ ) { + LDAPAVA *ava = &rdn[0][i]; + Slapi_Attr *a = NULL; + + if ( slapi_attr_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 && + slapi_attr_value_find( a, &ava->la_value ) == 0 ) + match++; + } + } + + ldap_dnfree( dn ); + + return ( i == match ); +#else + return 0; +#endif /* LDAP_SLAPI */ +} + +int slapi_entry_add_rdn_values( Slapi_Entry *e ) +{ +#ifdef LDAP_SLAPI + LDAPDN dn; + int i, rc; + char *dn_str; + + dn_str = slapi_entry_get_dn( e ); + rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 ); + if ( rc != LDAP_SUCCESS ) { + return rc; + } + + if ( dn[0] != NULL ) { + LDAPRDN rdn = dn[0]; + struct berval *vals[2]; + + for ( i = 0; rdn[i] != NULL; i++ ) { + LDAPAVA *ava = &rdn[0][i]; + Slapi_Attr *a = NULL; + + if ( slapi_attr_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 && + slapi_attr_value_find( a, &ava->la_value ) == 0 ) + continue; + + vals[0] = &ava->la_value; + vals[1] = NULL; + + slapi_entry_attr_merge( e, ava->la_attr.bv_val, vals ); + } + } + + ldap_dnfree( dn ); + + return LDAP_SUCCESS; +#else + return LDAP_OTHER; +#endif /* LDAP_SLAPI */ +} +