]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Add manage obsolete attributes capability.
[openldap] / servers / slapd / slapi / slapi_utils.c
index 9abff7520107a036a041b61dd7434bdc1b398497..1adeb85086284b2b9aa2744a2915492fc8f91375 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2002-2004 The OpenLDAP Foundation.
+ * Copyright 2002-2005 The OpenLDAP Foundation.
  * Portions Copyright 1997,2002-2003 IBM Corporation.
  * All rights reserved.
  *
@@ -26,7 +26,6 @@
 #include <ac/stdarg.h>
 #include <ac/ctype.h>
 #include <ac/unistd.h>
-#include <ldap_pvt.h>
 
 #include <slap.h>
 #include <slapi.h>
@@ -348,7 +347,7 @@ slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
 #endif
 }
 
-int
+long
 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
 {
 #ifdef LDAP_SLAPI
@@ -373,7 +372,7 @@ slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
 #endif
 }
 
-int
+unsigned int
 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
 {
 #ifdef LDAP_SLAPI
@@ -398,7 +397,7 @@ slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
 #endif
 }
 
-int
+unsigned long
 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
 {
 #ifdef LDAP_SLAPI
@@ -572,7 +571,7 @@ size_t slapi_entry_size(Slapi_Entry *e)
        Attribute *a;
        int i;
 
-       for ( size = 0, a = e->e_attrs; a != NULL; a->a_next ) {
+       for ( size = 0, a = e->e_attrs; a != NULL; a = a->a_next ) {
                for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
                        size += a->a_vals[i].bv_len + 1;
                }
@@ -1398,7 +1397,7 @@ slapiControlOp2SlapControlMask(unsigned long slapi_mask,
        if ( slapi_mask & SLAPI_OPERATION_ABANDON )
                *slap_mask |= SLAP_CTRL_ABANDON;
 
-       *slap_mask |= SLAP_CTRL_FRONTEND;
+       *slap_mask |= SLAP_CTRL_GLOBAL;
 }
 
 static int
@@ -1423,7 +1422,7 @@ slapi_register_supported_control(
 
        slapiControlOp2SlapControlMask( controlops, &controlmask );
 
-       register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control );
+       register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control, NULL );
 #endif /* LDAP_SLAPI */
 }
 
@@ -1629,6 +1628,7 @@ slapi_send_ldap_search_entry(
        rs.sr_ref = NULL;
        rs.sr_ctrls = ectrls;
        rs.sr_attrs = an;
+       rs.sr_operational_attrs = NULL;
        rs.sr_entry = e;
        rs.sr_v2ref = NULL;
        rs.sr_flags = 0;
@@ -1668,6 +1668,7 @@ slapi_send_ldap_search_reference(
 
        rs.sr_ctrls = ectrls;
        rs.sr_attrs = NULL;
+       rs.sr_operational_attrs = NULL;
        rs.sr_entry = e;
 
        if ( v2refs != NULL ) {
@@ -2696,10 +2697,38 @@ Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
 {
 #ifdef LDAP_SLAPI
-       /*
-        * FIXME: here we may lose alignment between a_vals/a_nvals
-        */
-       return value_add_one( &a->a_vals, (Slapi_Value *)v );
+       struct berval nval;
+       struct berval *nvalp;
+       int rc;
+       AttributeDescription *desc = a->a_desc;
+
+       if ( desc->ad_type->sat_equality &&
+            desc->ad_type->sat_equality->smr_normalize ) {
+               rc = (*desc->ad_type->sat_equality->smr_normalize)(
+                       SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                       desc->ad_type->sat_syntax,
+                       desc->ad_type->sat_equality,
+                       (Slapi_Value *)v, &nval, NULL );
+               if ( rc != LDAP_SUCCESS ) {
+                       return rc;
+               }
+               nvalp = &nval;
+       } else {
+               nvalp = NULL;
+       }
+
+       rc = value_add_one( &a->a_vals, (Slapi_Value *)v );
+       if ( rc == 0 && nvalp != NULL ) {
+               rc = value_add_one( &a->a_nvals, nvalp );
+       } else {
+               a->a_nvals = a->a_vals;
+       }
+
+       if ( nvalp != NULL ) {
+               slapi_ch_free_string( &nval.bv_val );
+       }
+
+       return rc;
 #else
        return -1;
 #endif
@@ -3335,6 +3364,7 @@ int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
        case SLAPI_ACL_DELETE:
        case SLAPI_ACL_ADD:
        case SLAPI_ACL_SELF:
+               /* FIXME: handle ACL_WADD/ACL_WDEL */
                slap_access = ACL_WRITE;
                break;
        default:
@@ -3480,6 +3510,10 @@ Modifications *slapi_int_ldapmods2modifications (LDAPMod **mods)
        Modifications *modlist = NULL, **modtail;
        LDAPMod **modp;
 
+       if ( mods == NULL ) {
+               return NULL;
+       }
+
        modtail = &modlist;
 
        for( modp = mods; *modp != NULL; modp++ ) {
@@ -3642,7 +3676,7 @@ int slapi_int_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_
                return 1;
        }
 
-       if ( !c->cac_attrsonly ) {
+       if ( !c->cac_attrsonly && a->a_vals != NULL ) {
                for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
                        if ( !access_allowed( op, e,
                                desc, &a->a_vals[i], ACL_READ, &c->cac_acl_state)) {
@@ -3967,6 +4001,7 @@ int slapi_int_access_allowed( Operation *op,
 
        switch ( access ) {
        case ACL_WRITE:
+               /* FIXME: handle ACL_WADD/ACL_WDEL */
                slap_access |= SLAPI_ACL_ADD | SLAPI_ACL_DELETE | SLAPI_ACL_WRITE;
                break;
        case ACL_READ:
@@ -4083,7 +4118,8 @@ int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
        if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 )
                return -1;
 
-       rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
+       rc = entry_schema_check( be, e, NULL, 0,
+               &text, textbuf, textlen );
 
        return ( rc == LDAP_SUCCESS ) ? 0 : 1;
 #else
@@ -4097,10 +4133,8 @@ int slapi_entry_rdn_values_present( const Slapi_Entry *e )
        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 );
+       rc = ldap_bv2dn( &((Entry *)e)->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
        if ( rc != LDAP_SUCCESS ) {
                return 0;
        }
@@ -4131,10 +4165,8 @@ 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 );
+       rc = ldap_bv2dn( &e->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
        if ( rc != LDAP_SUCCESS ) {
                return rc;
        }
@@ -4166,3 +4198,89 @@ int slapi_entry_add_rdn_values( Slapi_Entry *e )
 #endif /* LDAP_SLAPI */
 }
 
+const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
+{
+#ifdef LDAP_SLAPI
+       Attribute *attr;
+       const char *uniqueid;
+
+       attr = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
+       if ( attr == NULL ) {
+               return NULL;
+       }
+
+       if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
+               return slapi_value_get_string( &attr->a_vals[0] );
+       }
+#endif /* LDAP_SLAPI */
+
+       return NULL;
+}
+
+void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
+{
+#ifdef LDAP_SLAPI
+       struct berval bv;
+
+       attr_delete ( &e->e_attrs, slap_schema.si_ad_entryUUID );
+
+       bv.bv_val = uniqueid;
+       bv.bv_len = strlen( uniqueid );
+       attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, &bv, NULL );
+#endif /* LDAP_SLAPI */
+}
+
+LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared )
+{
+#ifdef LDAP_SLAPI
+       LDAP *ld;
+       char *url;
+       size_t size;
+       int rc;
+
+       size = sizeof("ldap:///");
+       if ( secure )
+               size++;
+       size += strlen( ldaphost );
+       if ( ldapport != 0 )
+               size += 32;
+
+       url = slapi_ch_malloc( size );
+
+       if ( ldapport != 0 ) {
+               sprintf( url, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
+       } else {
+               sprintf( url, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
+       }
+
+       rc = ldap_initialize( &ld, url );
+
+       slapi_ch_free_string( &url );
+
+       return ( rc == LDAP_SUCCESS ) ? ld : NULL;
+#else
+       return NULL;
+#endif /* LDAP_SLAPI */
+}
+
+void slapi_ldap_unbind( LDAP *ld )
+{
+#ifdef LDAP_SLAPI
+       ldap_unbind( ld );
+#endif /* LDAP_SLAPI */
+}
+
+int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags )
+{
+#ifdef LDAP_SLAPI
+       if ( be == NULL )
+               return LDAP_PARAM_ERROR;
+
+       *flags = SLAP_DBFLAGS(be);
+
+       return LDAP_SUCCESS;
+#else
+       return -1;
+#endif /* LDAP_SLAPI */
+}
+