]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Fix breakage
[openldap] / servers / slapd / slapi / slapi_utils.c
index d9ceeb43db86a6b71f12748b22f4e515d6bef7c1..9abff7520107a036a041b61dd7434bdc1b398497 100644 (file)
@@ -109,7 +109,7 @@ bvptr2obj(
 Slapi_Entry *
 slapi_str2entry(
        char            *s, 
-       int             check_dup )
+       int             flags )
 {
 #ifdef LDAP_SLAPI
        Slapi_Entry     *e = NULL;
@@ -529,6 +529,64 @@ slapi_is_rootdse( const char *dn )
 #endif
 }
 
+int
+slapi_entry_has_children(const Slapi_Entry *e)
+{
+#ifdef LDAP_SLAPI
+       Connection *pConn;
+       Operation *op;
+       int hasSubordinates = 0;
+
+       pConn = slapi_int_init_connection( NULL, LDAP_REQ_SEARCH );
+       if ( pConn == NULL ) {
+               return 0;
+       }
+
+       op = (Operation *)pConn->c_pending_ops.stqh_first;
+       op->o_bd = select_backend( (struct berval *)&e->e_nname, 0, 0 );
+       if ( op->o_bd == NULL ) {
+               return 0;
+       }
+
+       op->o_bd->be_has_subordinates( op, (Entry *)e, &hasSubordinates );
+
+       slapi_int_connection_destroy( &pConn );
+
+       return ( hasSubordinates == LDAP_COMPARE_TRUE );
+#else
+       return 0;
+#endif
+}
+
+/*
+ * Return approximate size of the entry rounded to the nearest
+ * 1K. Only the size of the attribute values are counted in the
+ * Sun implementation.
+ *
+ * http://docs.sun.com/source/816-6701-10/funcref.html#1017388
+ */
+size_t slapi_entry_size(Slapi_Entry *e)
+{
+#ifdef LDAP_SLAPI
+       size_t size;
+       Attribute *a;
+       int i;
+
+       for ( size = 0, a = e->e_attrs; a != NULL; a->a_next ) {
+               for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
+                       size += a->a_vals[i].bv_len + 1;
+               }
+       }
+
+       size += 1023;
+       size -= (size % 1024);
+
+       return size;
+#else
+       return 0;
+#endif /* LDAP_SLAPI */
+}
+
 /*
  * Add values to entry.
  *
@@ -3954,3 +4012,157 @@ int slapi_int_access_allowed( Operation *op,
 #endif /* LDAP_SLAPI */
 }
 
+/*
+ * There is no documentation for this.
+ */
+int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
+{
+#ifdef LDAP_SLAPI
+       LDAPRDN lrdn;
+       LDAPAVA *ava;
+       int rc;
+       char *p;
+
+       *type = NULL;
+
+       bv->bv_len = 0;
+       bv->bv_val = NULL;
+
+       rc = ldap_str2rdn( rdn, &lrdn, &p, LDAP_DN_FORMAT_LDAPV3 );
+       if ( rc != LDAP_SUCCESS ) {
+               return -1;
+       }
+
+       if ( lrdn[1] != NULL ) {
+               return -1; /* not single valued */
+       }
+
+       ava = lrdn[0];
+
+       *type = slapi_ch_strdup( ava->la_attr.bv_val );
+       ber_dupbv( bv, &ava->la_value );
+
+       ldap_rdnfree(lrdn);
+
+       return 0;
+#else
+       return -1;
+#endif /* LDAP_SLAPI */
+}
+
+char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
+{
+#ifdef LDAP_SLAPI
+       struct berval new_dn, parent_dn, newrdn;
+
+       new_dn.bv_val = NULL;
+
+       parent_dn.bv_val = (char *)dn;
+       parent_dn.bv_len = strlen( dn );
+
+       newrdn.bv_val = (char *)rdn;
+       newrdn.bv_len = strlen( rdn );
+
+       build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
+
+       return new_dn.bv_val;
+#else
+       return NULL;
+#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_entry_attr_find( (Slapi_Entry *)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_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 */
+}
+