2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2007 The OpenLDAP Foundation.
5 * Portions Copyright 1997,2002-2003 IBM Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by IBM Corporation for use in
18 * IBM products and subsequently ported to OpenLDAP Software by
19 * Steve Omrani. Additional significant contributors include:
25 #include <ac/string.h>
26 #include <ac/stdarg.h>
28 #include <ac/unistd.h>
38 * server start time (should we use a struct timeval also in slapd?
40 static struct timeval base_time;
41 ldap_pvt_thread_mutex_t slapi_hn_mutex;
42 ldap_pvt_thread_mutex_t slapi_time_mutex;
45 ldap_pvt_thread_mutex_t mutex;
48 struct slapi_condvar {
49 ldap_pvt_thread_cond_t cond;
50 ldap_pvt_thread_mutex_t mutex;
53 static int checkBVString(const struct berval *bv)
57 for ( i = 0; i < bv->bv_len; i++ ) {
58 if ( bv->bv_val[i] == '\0' )
61 if ( bv->bv_val[i] != '\0' )
68 * This function converts an array of pointers to berval objects to
69 * an array of berval objects.
74 struct berval **bvptr,
78 int rc = LDAP_SUCCESS;
82 if ( bvptr == NULL || *bvptr == NULL ) {
86 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
92 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
93 if ( tmpberval == NULL ) {
94 return LDAP_NO_MEMORY;
97 for ( i = 0; bvptr[i] != NULL; i++ ) {
98 tmpberval[i].bv_val = bvptr[i]->bv_val;
99 tmpberval[i].bv_len = bvptr[i]->bv_len;
101 tmpberval[i].bv_val = NULL;
102 tmpberval[i].bv_len = 0;
104 if ( rc == LDAP_SUCCESS ) {
116 return str2entry( s );
127 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
128 s = entry2str( e, len );
130 ret = slapi_ch_strdup( s );
131 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
137 slapi_entry_get_dn( Slapi_Entry *e )
139 return e->e_name.bv_val;
143 slapi_x_entry_get_id( Slapi_Entry *e )
149 slapi_int_dn_pretty( struct berval *in, struct berval *out )
151 Syntax *syntax = slap_schema.si_syn_distinguishedName;
153 assert( syntax != NULL );
155 return (syntax->ssyn_pretty)( syntax, in, out, NULL );
159 slapi_int_dn_normalize( struct berval *in, struct berval *out )
161 MatchingRule *mr = slap_schema.si_mr_distinguishedNameMatch;
162 Syntax *syntax = slap_schema.si_syn_distinguishedName;
164 assert( mr != NULL );
166 return (mr->smr_normalize)( 0, syntax, mr, in, out, NULL );
174 struct berval dn = BER_BVNULL;
177 dn.bv_len = strlen( ldn );
179 slapi_int_dn_pretty( &dn, &e->e_name );
180 slapi_int_dn_normalize( &dn, &e->e_nname );
184 slapi_entry_dup( Slapi_Entry *e )
186 return entry_dup( e );
190 slapi_entry_attr_delete(
194 AttributeDescription *ad = NULL;
197 if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
198 return 1; /* LDAP_NO_SUCH_ATTRIBUTE */
201 if ( attr_delete( &e->e_attrs, ad ) == LDAP_SUCCESS ) {
202 return 0; /* attribute is deleted */
204 return -1; /* something went wrong */
209 slapi_entry_alloc( void )
211 return (Slapi_Entry *)entry_alloc();
215 slapi_entry_free( Slapi_Entry *e )
222 slapi_entry_attr_merge(
225 struct berval **vals )
227 AttributeDescription *ad = NULL;
232 rc = slap_str2ad( type, &ad, &text );
233 if ( rc != LDAP_SUCCESS ) {
237 rc = bvptr2obj( vals, &bv, NULL );
238 if ( rc != LDAP_SUCCESS ) {
242 rc = attr_merge_normalize( e, ad, bv, NULL );
249 slapi_entry_attr_find(
254 AttributeDescription *ad = NULL;
258 rc = slap_str2ad( type, &ad, &text );
259 if ( rc != LDAP_SUCCESS ) {
263 *attr = attr_find( e->e_attrs, ad );
264 if ( *attr == NULL ) {
272 slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
274 AttributeDescription *ad = NULL;
279 rc = slap_str2ad( type, &ad, &text );
280 if ( rc != LDAP_SUCCESS ) {
284 attr = attr_find( e->e_attrs, ad );
285 if ( attr == NULL ) {
289 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
292 p = slapi_value_get_string( &attr->a_vals[0] );
294 return slapi_ch_strdup( p );
302 slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
304 AttributeDescription *ad = NULL;
309 rc = slap_str2ad( type, &ad, &text );
310 if ( rc != LDAP_SUCCESS ) {
314 attr = attr_find( e->e_attrs, ad );
315 if ( attr == NULL ) {
319 return slapi_value_get_int( attr->a_vals );
323 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
325 AttributeDescription *ad = NULL;
330 rc = slap_str2ad( type, &ad, &text );
331 if ( rc != LDAP_SUCCESS ) {
335 attr = attr_find( e->e_attrs, ad );
336 if ( attr == NULL ) {
340 return slapi_value_get_long( attr->a_vals );
344 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
346 AttributeDescription *ad = NULL;
351 rc = slap_str2ad( type, &ad, &text );
352 if ( rc != LDAP_SUCCESS ) {
356 attr = attr_find( e->e_attrs, ad );
357 if ( attr == NULL ) {
361 return slapi_value_get_uint( attr->a_vals );
365 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
367 AttributeDescription *ad = NULL;
372 rc = slap_str2ad( type, &ad, &text );
373 if ( rc != LDAP_SUCCESS ) {
377 attr = attr_find( e->e_attrs, ad );
378 if ( attr == NULL ) {
382 return slapi_value_get_ulong( attr->a_vals );
386 slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
389 AttributeDescription *ad = NULL;
394 rc = slap_str2ad( type, &ad, &text );
395 if ( rc != LDAP_SUCCESS ) {
399 attr = attr_find( e->e_attrs, ad );
400 if ( attr == NULL ) {
404 bv.bv_val = (char *)value;
405 bv.bv_len = strlen( value );
407 return ( slapi_attr_value_find( attr, &bv ) != -1 );
411 slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value)
413 AttributeDescription *ad = NULL;
418 rc = slap_str2ad( type, &ad, &text );
419 if ( rc != LDAP_SUCCESS ) {
423 attr_delete ( &e->e_attrs, ad );
424 if ( value != NULL ) {
425 bv.bv_val = (char *)value;
426 bv.bv_len = strlen(value);
427 attr_merge_normalize_one( e, ad, &bv, NULL );
432 slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l)
436 snprintf( buf, sizeof( buf ), "%d", l );
437 slapi_entry_attr_set_charptr( e, type, buf );
441 slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l)
445 snprintf( buf, sizeof( buf ), "%u", l );
446 slapi_entry_attr_set_charptr( e, type, buf );
450 slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l)
454 snprintf( buf, sizeof( buf ), "%ld", l );
455 slapi_entry_attr_set_charptr( e, type, buf );
459 slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l)
463 snprintf( buf, sizeof( buf ), "%lu", l );
464 slapi_entry_attr_set_charptr( e, type, buf );
468 slapi_is_rootdse( const char *dn )
470 return ( dn == NULL || dn[0] == '\0' );
474 slapi_entry_has_children( const Slapi_Entry *e )
477 int hasSubordinates = 0;
479 pb = slapi_pblock_new();
480 slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
482 slapi_pblock_set( pb, SLAPI_TARGET_DN, slapi_entry_get_dn( (Entry *)e ) );
484 pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0 );
485 if ( pb->pb_op->o_bd != NULL ) {
486 pb->pb_op->o_bd->be_has_subordinates( pb->pb_op, (Entry *)e, &hasSubordinates );
489 slapi_pblock_destroy( pb );
491 return ( hasSubordinates == LDAP_COMPARE_TRUE );
495 * Return approximate size of the entry rounded to the nearest
496 * 1K. Only the size of the attribute values are counted in the
497 * Sun implementation.
499 * http://docs.sun.com/source/816-6701-10/funcref.html#1017388
501 size_t slapi_entry_size(Slapi_Entry *e)
507 for ( size = 0, a = e->e_attrs; a != NULL; a = a->a_next ) {
508 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
509 size += a->a_vals[i].bv_len + 1;
514 size -= (size % 1024);
520 * Add values to entry.
523 * LDAP_SUCCESS Values added to entry
524 * LDAP_TYPE_OR_VALUE_EXISTS One or more values exist in entry already
525 * LDAP_CONSTRAINT_VIOLATION Any other error (odd, but it's the spec)
528 slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
533 char textbuf[SLAP_TEXT_BUFLEN];
535 mod.sm_op = LDAP_MOD_ADD;
538 mod.sm_type.bv_val = (char *)type;
539 mod.sm_type.bv_len = strlen( type );
541 rc = slap_str2ad( type, &mod.sm_desc, &text );
542 if ( rc != LDAP_SUCCESS ) {
546 if ( vals == NULL ) {
547 /* Apparently vals can be NULL
548 * FIXME: sm_values = NULL ? */
549 mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) );
550 mod.sm_values->bv_val = NULL;
554 rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
555 if ( rc != LDAP_SUCCESS ) {
556 return LDAP_CONSTRAINT_VIOLATION;
559 mod.sm_nvalues = NULL;
561 rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
563 slapi_ch_free( (void **)&mod.sm_values );
565 return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
569 slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
571 return slapi_entry_add_values( e, type, vals );
575 slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
577 AttributeDescription *ad = NULL;
581 rc = slap_str2ad( type, &ad, &text );
582 if ( rc != LDAP_SUCCESS ) {
586 return attr_merge_normalize( e, ad, *vs, NULL );
590 slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **vals )
595 char textbuf[SLAP_TEXT_BUFLEN];
597 mod.sm_op = LDAP_MOD_DELETE;
600 mod.sm_type.bv_val = (char *)type;
601 mod.sm_type.bv_len = strlen( type );
603 if ( vals == NULL ) {
604 /* If vals is NULL, this is a NOOP. */
608 rc = slap_str2ad( type, &mod.sm_desc, &text );
609 if ( rc != LDAP_SUCCESS ) {
613 if ( vals[0] == NULL ) {
614 /* SLAPI doco says LDApb_opERATIONS_ERROR but LDAP_OTHER is better */
615 return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
618 rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
619 if ( rc != LDAP_SUCCESS ) {
620 return LDAP_CONSTRAINT_VIOLATION;
622 mod.sm_nvalues = NULL;
624 rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
626 slapi_ch_free( (void **)&mod.sm_values );
632 slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
634 return slapi_entry_delete_values( e, type, vals );
638 slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
640 return slapi_entry_attr_merge( e, (char *)type, vals );
644 slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value)
646 AttributeDescription *ad = NULL;
650 rc = slap_str2ad( type, &ad, &text );
651 if ( rc != LDAP_SUCCESS ) {
655 rc = attr_merge_normalize_one( e, ad, (Slapi_Value *)value, NULL );
656 if ( rc != LDAP_SUCCESS ) {
664 slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
668 val.bv_val = (char *)value;
669 val.bv_len = strlen( value );
671 return slapi_entry_add_value( e, type, &val );
675 slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
677 Slapi_Value *vals[2];
680 val.bv_val = (char *)value;
681 val.bv_len = strlen( value );
685 return slapi_entry_delete_values_sv( e, type, vals );
689 slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
691 return slapi_entry_attr_merge( e, (char *)type, vals );
695 slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
703 return ( *attr != NULL ) ? 0 : -1;
707 slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr )
713 if ( prevattr == NULL ) {
717 *attr = prevattr->a_next;
719 return ( *attr != NULL ) ? 0 : -1;
723 slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
725 AttributeDescription *ad = NULL;
730 rc = slap_str2ad( type, &ad, &text );
731 if ( rc != LDAP_SUCCESS ) {
735 attr_delete( &e->e_attrs, ad );
737 rc = bvptr2obj( vals, &bv, NULL );
738 if ( rc != LDAP_SUCCESS ) {
742 rc = attr_merge_normalize( e, ad, bv, NULL );
743 slapi_ch_free( (void **)&bv );
744 if ( rc != LDAP_SUCCESS ) {
752 * FIXME -- The caller must free the allocated memory.
753 * In Netscape they do not have to.
756 slapi_attr_get_values(
758 struct berval ***vals )
763 if ( attr == NULL ) {
767 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
771 bv = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
772 for ( j = 0; j < i; j++ ) {
773 bv[j] = ber_dupbv( NULL, &attr->a_vals[j] );
777 *vals = (struct berval **)bv;
783 slapi_dn_normalize( char *dn )
788 assert( dn != NULL );
791 bdn.bv_len = strlen( dn );
793 if ( slapi_int_dn_pretty( &bdn, &pdn ) != LDAP_SUCCESS ) {
801 slapi_dn_normalize_case( char *dn )
806 assert( dn != NULL );
809 bdn.bv_len = strlen( dn );
811 if ( slapi_int_dn_normalize( &bdn, &ndn ) != LDAP_SUCCESS ) {
823 struct berval bdn, ndn;
824 struct berval bsuffix, nsuffix;
827 assert( dn != NULL );
828 assert( suffix != NULL );
831 bdn.bv_len = strlen( dn );
833 bsuffix.bv_val = suffix;
834 bsuffix.bv_len = strlen( suffix );
836 if ( dnNormalize( 0, NULL, NULL, &bdn, &ndn, NULL ) != LDAP_SUCCESS ) {
840 if ( dnNormalize( 0, NULL, NULL, &bsuffix, &nsuffix, NULL )
843 slapi_ch_free( (void **)&ndn.bv_val );
847 rc = dnIsSuffix( &ndn, &nsuffix );
849 slapi_ch_free( (void **)&ndn.bv_val );
850 slapi_ch_free( (void **)&nsuffix.bv_val );
857 const char *parentdn,
858 const char *childdn )
860 struct berval assertedParentDN, normalizedAssertedParentDN;
861 struct berval childDN, normalizedChildDN;
862 struct berval normalizedParentDN;
865 assert( parentdn != NULL );
866 assert( childdn != NULL );
868 assertedParentDN.bv_val = (char *)parentdn;
869 assertedParentDN.bv_len = strlen( parentdn );
871 if ( dnNormalize( 0, NULL, NULL, &assertedParentDN,
872 &normalizedAssertedParentDN, NULL ) != LDAP_SUCCESS )
877 childDN.bv_val = (char *)childdn;
878 childDN.bv_len = strlen( childdn );
880 if ( dnNormalize( 0, NULL, NULL, &childDN,
881 &normalizedChildDN, NULL ) != LDAP_SUCCESS )
883 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
887 dnParent( &normalizedChildDN, &normalizedParentDN );
889 if ( dnMatch( &match, 0, slap_schema.si_syn_distinguishedName, NULL,
890 &normalizedParentDN, (void *)&normalizedAssertedParentDN ) != LDAP_SUCCESS )
895 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
896 slapi_ch_free( (void **)&normalizedChildDN.bv_val );
898 return ( match == 0 );
902 * Returns DN of the parent entry, or NULL if the DN is
903 * an empty string or NULL, or has no parent.
906 slapi_dn_parent( const char *_dn )
908 struct berval dn, prettyDN;
909 struct berval parentDN;
916 dn.bv_val = (char *)_dn;
917 dn.bv_len = strlen( _dn );
919 if ( dn.bv_len == 0 ) {
923 if ( dnPretty( NULL, &dn, &prettyDN, NULL ) != LDAP_SUCCESS ) {
927 dnParent( &prettyDN, &parentDN ); /* in-place */
929 if ( parentDN.bv_len == 0 ) {
930 slapi_ch_free_string( &prettyDN.bv_val );
934 ret = slapi_ch_strdup( parentDN.bv_val );
935 slapi_ch_free_string( &prettyDN.bv_val );
940 int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *ldn )
945 if ( slapi_is_rootdse( ldn ) ) {
949 /* according to spec should already be normalized */
950 ndn.bv_len = strlen( ldn );
953 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
958 return be_issuffix( be, &ndn );
962 * Returns DN of the parent entry; or NULL if the DN is
963 * an empty string, if the DN has no parent, or if the
964 * DN is the suffix of the backend database
966 char *slapi_dn_beparent( Slapi_PBlock *pb, const char *ldn )
969 struct berval dn, prettyDN;
970 struct berval normalizedDN, parentDN;
977 PBLOCK_ASSERT_OP( pb, 0 );
979 if ( slapi_is_rootdse( ldn ) ) {
983 dn.bv_val = (char *)ldn;
984 dn.bv_len = strlen( ldn );
986 if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) {
990 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
992 if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) {
993 dnParent( &prettyDN, &parentDN );
995 if ( parentDN.bv_len != 0 )
996 parent = slapi_ch_strdup( parentDN.bv_val );
999 slapi_ch_free_string( &prettyDN.bv_val );
1000 slapi_ch_free_string( &normalizedDN.bv_val );
1006 slapi_dn_ignore_case( char *dn )
1008 return slapi_dn_normalize_case( dn );
1012 slapi_ch_malloc( unsigned long size )
1014 return ch_malloc( size );
1018 slapi_ch_free( void **ptr )
1020 if ( ptr == NULL || *ptr == NULL )
1027 slapi_ch_free_string( char **ptr )
1029 slapi_ch_free( (void **)ptr );
1033 slapi_ch_array_free( char **arrayp )
1037 if ( arrayp != NULL ) {
1038 for ( p = arrayp; *p != NULL; p++ ) {
1039 slapi_ch_free( (void **)p );
1041 slapi_ch_free( (void **)&arrayp );
1046 slapi_ch_bvdup(const struct berval *v)
1048 return ber_dupbv(NULL, (struct berval *)v);
1052 slapi_ch_bvecdup(const struct berval **v)
1061 for ( i = 0; v[i] != NULL; i++ )
1064 rv = (struct berval **) slapi_ch_malloc( (i + 1) * sizeof(struct berval *) );
1066 for ( i = 0; v[i] != NULL; i++ ) {
1067 rv[i] = slapi_ch_bvdup( v[i] );
1076 unsigned long nelem,
1077 unsigned long size )
1079 return ch_calloc( nelem, size );
1085 unsigned long size )
1087 return ch_realloc( block, size );
1091 slapi_ch_strdup( const char *s )
1093 return ch_strdup( s );
1097 slapi_ch_stlen( const char *s )
1103 slapi_control_present(
1104 LDAPControl **controls,
1106 struct berval **val,
1120 for ( i = 0; controls != NULL && controls[i] != NULL; i++ ) {
1121 if ( strcmp( controls[i]->ldctl_oid, oid ) != 0 ) {
1126 if ( controls[i]->ldctl_value.bv_len != 0 ) {
1128 *val = &controls[i]->ldctl_value;
1133 *iscritical = controls[i]->ldctl_iscritical;
1143 slapControlMask2SlapiControlOp(slap_mask_t slap_mask,
1144 unsigned long *slapi_mask)
1146 *slapi_mask = SLAPI_OPERATION_NONE;
1148 if ( slap_mask & SLAP_CTRL_ABANDON )
1149 *slapi_mask |= SLAPI_OPERATION_ABANDON;
1151 if ( slap_mask & SLAP_CTRL_ADD )
1152 *slapi_mask |= SLAPI_OPERATION_ADD;
1154 if ( slap_mask & SLAP_CTRL_BIND )
1155 *slapi_mask |= SLAPI_OPERATION_BIND;
1157 if ( slap_mask & SLAP_CTRL_COMPARE )
1158 *slapi_mask |= SLAPI_OPERATION_COMPARE;
1160 if ( slap_mask & SLAP_CTRL_DELETE )
1161 *slapi_mask |= SLAPI_OPERATION_DELETE;
1163 if ( slap_mask & SLAP_CTRL_MODIFY )
1164 *slapi_mask |= SLAPI_OPERATION_MODIFY;
1166 if ( slap_mask & SLAP_CTRL_RENAME )
1167 *slapi_mask |= SLAPI_OPERATION_MODDN;
1169 if ( slap_mask & SLAP_CTRL_SEARCH )
1170 *slapi_mask |= SLAPI_OPERATION_SEARCH;
1172 if ( slap_mask & SLAP_CTRL_UNBIND )
1173 *slapi_mask |= SLAPI_OPERATION_UNBIND;
1177 slapiControlOp2SlapControlMask(unsigned long slapi_mask,
1178 slap_mask_t *slap_mask)
1182 if ( slapi_mask & SLAPI_OPERATION_BIND )
1183 *slap_mask |= SLAP_CTRL_BIND;
1185 if ( slapi_mask & SLAPI_OPERATION_UNBIND )
1186 *slap_mask |= SLAP_CTRL_UNBIND;
1188 if ( slapi_mask & SLAPI_OPERATION_SEARCH )
1189 *slap_mask |= SLAP_CTRL_SEARCH;
1191 if ( slapi_mask & SLAPI_OPERATION_MODIFY )
1192 *slap_mask |= SLAP_CTRL_MODIFY;
1194 if ( slapi_mask & SLAPI_OPERATION_ADD )
1195 *slap_mask |= SLAP_CTRL_ADD;
1197 if ( slapi_mask & SLAPI_OPERATION_DELETE )
1198 *slap_mask |= SLAP_CTRL_DELETE;
1200 if ( slapi_mask & SLAPI_OPERATION_MODDN )
1201 *slap_mask |= SLAP_CTRL_RENAME;
1203 if ( slapi_mask & SLAPI_OPERATION_COMPARE )
1204 *slap_mask |= SLAP_CTRL_COMPARE;
1206 if ( slapi_mask & SLAPI_OPERATION_ABANDON )
1207 *slap_mask |= SLAP_CTRL_ABANDON;
1209 *slap_mask |= SLAP_CTRL_GLOBAL;
1213 slapi_int_parse_control(
1218 /* Plugins must deal with controls themselves. */
1220 return LDAP_SUCCESS;
1224 slapi_register_supported_control(
1226 unsigned long controlops )
1228 slap_mask_t controlmask;
1230 slapiControlOp2SlapControlMask( controlops, &controlmask );
1232 register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control, NULL );
1236 slapi_get_supported_controls(
1238 unsigned long **ctrlopsp )
1242 rc = get_supported_controls( ctrloidsp, (slap_mask_t **)ctrlopsp );
1243 if ( rc != LDAP_SUCCESS ) {
1247 for ( i = 0; (*ctrloidsp)[i] != NULL; i++ ) {
1248 /* In place, naughty. */
1249 slapControlMask2SlapiControlOp( (*ctrlopsp)[i], &((*ctrlopsp)[i]) );
1252 return LDAP_SUCCESS;
1256 slapi_dup_control( LDAPControl *ctrl )
1260 ret = (LDAPControl *)slapi_ch_malloc( sizeof(*ret) );
1261 ret->ldctl_oid = slapi_ch_strdup( ctrl->ldctl_oid );
1262 ber_dupbv( &ret->ldctl_value, &ctrl->ldctl_value );
1263 ret->ldctl_iscritical = ctrl->ldctl_iscritical;
1269 slapi_register_supported_saslmechanism( char *mechanism )
1271 /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */
1272 slapi_log_error( SLAPI_LOG_FATAL, "slapi_register_supported_saslmechanism",
1273 "OpenLDAP does not support dynamic registration of SASL mechanisms\n" );
1277 slapi_get_supported_saslmechanisms( void )
1279 /* FIXME -- can not get the saslmechanism without a connection. */
1280 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_supported_saslmechanisms",
1281 "can not get the SASL mechanism list "
1282 "without a connection\n" );
1287 slapi_get_supported_extended_ops( void )
1290 char **ppExtOpOID = NULL;
1293 for ( i = 0; get_supported_extop( i ) != NULL; i++ ) {
1297 for ( j = 0; slapi_int_get_supported_extop( j ) != NULL; j++ ) {
1302 if ( numExtOps == 0 ) {
1306 ppExtOpOID = (char **)slapi_ch_malloc( (numExtOps + 1) * sizeof(char *) );
1307 for ( k = 0; k < i; k++ ) {
1310 bv = get_supported_extop( k );
1311 assert( bv != NULL );
1313 ppExtOpOID[ k ] = bv->bv_val;
1316 for ( ; k < j; k++ ) {
1319 bv = slapi_int_get_supported_extop( k );
1320 assert( bv != NULL );
1322 ppExtOpOID[ i + k ] = bv->bv_val;
1324 ppExtOpOID[ i + k ] = NULL;
1330 slapi_send_ldap_result(
1336 struct berval **urls )
1340 PBLOCK_ASSERT_OP( pb, 0 );
1345 rs->sr_matched = matched;
1349 if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
1350 send_ldap_sasl( pb->pb_op, rs );
1351 } else if ( rs->sr_rspoid != NULL ) {
1352 send_ldap_extended( pb->pb_op, rs );
1354 if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
1355 rs->sr_nentries = nentries;
1357 bvptr2obj( urls, &rs->sr_ref, NULL );
1359 send_ldap_result( pb->pb_op, rs );
1362 slapi_ch_free( (void **)&rs->sr_ref );
1367 slapi_send_ldap_search_entry(
1370 LDAPControl **ectrls,
1374 SlapReply rs = { REP_SEARCH };
1376 AttributeName *an = NULL;
1380 assert( pb->pb_op != NULL );
1382 if ( attrs != NULL ) {
1383 for ( i = 0; attrs[ i ] != NULL; i++ ) {
1389 an = (AttributeName *) slapi_ch_calloc( i + 1, sizeof(AttributeName) );
1390 for ( i = 0; attrs[i] != NULL; i++ ) {
1391 an[j].an_name.bv_val = attrs[i];
1392 an[j].an_name.bv_len = strlen( attrs[i] );
1393 an[j].an_desc = NULL;
1394 if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &text ) == LDAP_SUCCESS) {
1398 an[j].an_name.bv_len = 0;
1399 an[j].an_name.bv_val = NULL;
1402 rs.sr_err = LDAP_SUCCESS;
1403 rs.sr_matched = NULL;
1406 rs.sr_ctrls = ectrls;
1408 rs.sr_operational_attrs = NULL;
1413 rc = send_search_entry( pb->pb_op, &rs );
1415 slapi_ch_free( (void **)&an );
1421 slapi_send_ldap_search_reference(
1424 struct berval **references,
1425 LDAPControl **ectrls,
1426 struct berval **v2refs
1429 SlapReply rs = { REP_SEARCHREF };
1432 rs.sr_err = LDAP_SUCCESS;
1433 rs.sr_matched = NULL;
1436 rc = bvptr2obj( references, &rs.sr_ref, NULL );
1437 if ( rc != LDAP_SUCCESS ) {
1441 rs.sr_ctrls = ectrls;
1443 rs.sr_operational_attrs = NULL;
1446 if ( v2refs != NULL ) {
1447 rc = bvptr2obj( v2refs, &rs.sr_v2ref, NULL );
1448 if ( rc != LDAP_SUCCESS ) {
1449 slapi_ch_free( (void **)&rs.sr_ref );
1456 rc = send_search_reference( pb->pb_op, &rs );
1458 slapi_ch_free( (void **)&rs.sr_ref );
1459 slapi_ch_free( (void **)&rs.sr_v2ref );
1465 slapi_str2filter( char *str )
1467 return str2filter( str );
1479 slapi_filter_dup( Slapi_Filter *filter )
1481 return filter_dup( filter, NULL );
1485 slapi_filter_get_choice( Slapi_Filter *f )
1499 slapi_filter_get_ava(
1502 struct berval **bval )
1505 int rc = LDAP_SUCCESS;
1507 assert( type != NULL );
1508 assert( bval != NULL );
1513 ftype = f->f_choice;
1514 if ( ftype == LDAP_FILTER_EQUALITY
1515 || ftype == LDAP_FILTER_GE
1516 || ftype == LDAP_FILTER_LE
1517 || ftype == LDAP_FILTER_APPROX ) {
1519 * According to the SLAPI Reference Manual these are
1522 *type = f->f_un.f_un_ava->aa_desc->ad_cname.bv_val;
1523 *bval = &f->f_un.f_un_ava->aa_value;
1524 } else { /* filter type not supported */
1532 slapi_filter_list_first( Slapi_Filter *f )
1540 ftype = f->f_choice;
1541 if ( ftype == LDAP_FILTER_AND
1542 || ftype == LDAP_FILTER_OR
1543 || ftype == LDAP_FILTER_NOT ) {
1544 return (Slapi_Filter *)f->f_list;
1551 slapi_filter_list_next(
1553 Slapi_Filter *fprev )
1561 ftype = f->f_choice;
1562 if ( ftype == LDAP_FILTER_AND
1563 || ftype == LDAP_FILTER_OR
1564 || ftype == LDAP_FILTER_NOT )
1566 return fprev->f_next;
1573 slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
1579 switch ( f->f_choice ) {
1580 case LDAP_FILTER_GE:
1581 case LDAP_FILTER_LE:
1582 case LDAP_FILTER_EQUALITY:
1583 case LDAP_FILTER_APPROX:
1584 *type = f->f_av_desc->ad_cname.bv_val;
1586 case LDAP_FILTER_SUBSTRINGS:
1587 *type = f->f_sub_desc->ad_cname.bv_val;
1589 case LDAP_FILTER_PRESENT:
1590 *type = f->f_desc->ad_cname.bv_val;
1592 case LDAP_FILTER_EXT:
1593 *type = f->f_mr_desc->ad_cname.bv_val;
1596 /* Complex filters need not apply. */
1605 slapi_x_filter_set_attribute_type( Slapi_Filter *f, const char *type )
1607 AttributeDescription **adp, *ad = NULL;
1615 switch ( f->f_choice ) {
1616 case LDAP_FILTER_GE:
1617 case LDAP_FILTER_LE:
1618 case LDAP_FILTER_EQUALITY:
1619 case LDAP_FILTER_APPROX:
1620 adp = &f->f_av_desc;
1622 case LDAP_FILTER_SUBSTRINGS:
1623 adp = &f->f_sub_desc;
1625 case LDAP_FILTER_PRESENT:
1628 case LDAP_FILTER_EXT:
1629 adp = &f->f_mr_desc;
1632 /* Complex filters need not apply. */
1636 rc = slap_str2ad( type, &ad, &text );
1637 if ( rc == LDAP_SUCCESS )
1640 return ( rc == LDAP_SUCCESS ) ? 0 : -1;
1644 slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
1645 char ***any, char **final )
1649 if ( f->f_choice != LDAP_FILTER_SUBSTRINGS ) {
1654 * The caller shouldn't free but we can't return an
1655 * array of char *s from an array of bervals without
1656 * allocating memory, so we may as well be consistent.
1659 *type = f->f_sub_desc->ad_cname.bv_val;
1660 *initial = f->f_sub_initial.bv_val ? slapi_ch_strdup(f->f_sub_initial.bv_val) : NULL;
1661 if ( f->f_sub_any != NULL ) {
1662 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ )
1664 *any = (char **)slapi_ch_malloc( (i + 1) * sizeof(char *) );
1665 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
1666 (*any)[i] = slapi_ch_strdup(f->f_sub_any[i].bv_val);
1672 *final = f->f_sub_final.bv_val ? slapi_ch_strdup(f->f_sub_final.bv_val) : NULL;
1678 slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 )
1680 Slapi_Filter *f = NULL;
1682 if ( ftype == LDAP_FILTER_AND ||
1683 ftype == LDAP_FILTER_OR ||
1684 ftype == LDAP_FILTER_NOT )
1686 f = (Slapi_Filter *)slapi_ch_malloc( sizeof(*f) );
1687 f->f_choice = ftype;
1689 f->f_list->f_next = f2;
1697 slapi_x_filter_append( int ftype,
1698 Slapi_Filter **pContainingFilter, /* NULL on first call */
1699 Slapi_Filter **pNextFilter,
1700 Slapi_Filter *filterToAppend )
1702 if ( ftype == LDAP_FILTER_AND ||
1703 ftype == LDAP_FILTER_OR ||
1704 ftype == LDAP_FILTER_NOT )
1706 if ( *pContainingFilter == NULL ) {
1707 *pContainingFilter = (Slapi_Filter *)slapi_ch_malloc( sizeof(Slapi_Filter) );
1708 (*pContainingFilter)->f_choice = ftype;
1709 (*pContainingFilter)->f_list = filterToAppend;
1710 (*pContainingFilter)->f_next = NULL;
1712 if ( (*pContainingFilter)->f_choice != ftype ) {
1716 (*pNextFilter)->f_next = filterToAppend;
1718 *pNextFilter = filterToAppend;
1726 slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
1733 /* spec says return zero if no filter. */
1737 if ( verify_access ) {
1740 return LDAP_PARAM_ERROR;
1746 * According to acl.c it is safe to call test_filter() with
1749 rc = test_filter( op, e, f );
1751 case LDAP_COMPARE_TRUE:
1754 case LDAP_COMPARE_FALSE:
1756 case SLAPD_COMPARE_UNDEFINED:
1759 case LDAP_PROTOCOL_ERROR:
1760 /* filter type unknown: spec says return -1 */
1769 slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f)
1771 return slapi_filter_test( NULL, e, f, 0 );
1775 slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code )
1777 switch ( f->f_choice ) {
1778 case LDAP_FILTER_AND:
1779 case LDAP_FILTER_NOT:
1780 case LDAP_FILTER_OR: {
1784 * FIXME: altering f; should we use a temporary?
1786 for ( f = f->f_list; f != NULL; f = f->f_next ) {
1787 rc = slapi_filter_apply( f, fn, arg, error_code );
1791 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ) {
1797 case LDAP_FILTER_EQUALITY:
1798 case LDAP_FILTER_SUBSTRINGS:
1799 case LDAP_FILTER_GE:
1800 case LDAP_FILTER_LE:
1801 case LDAP_FILTER_PRESENT:
1802 case LDAP_FILTER_APPROX:
1803 case LDAP_FILTER_EXT:
1804 *error_code = fn( f, arg );
1807 *error_code = SLAPI_FILTER_UNKNOWN_FILTER_TYPE;
1810 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ||
1811 *error_code == SLAPI_FILTER_SCAN_CONTINUE ) {
1820 struct berval **vals,
1824 * FIXME: what's the point?
1829 #define MAX_HOSTNAME 512
1832 slapi_get_hostname( void )
1835 static int been_here = 0;
1836 static char *static_hn = NULL;
1838 ldap_pvt_thread_mutex_lock( &slapi_hn_mutex );
1840 static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
1841 if ( static_hn == NULL) {
1842 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_hostname",
1843 "Cannot allocate memory for hostname\n" );
1845 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1850 if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) {
1851 slapi_log_error( SLAPI_LOG_FATAL,
1853 "can't get hostname\n" );
1854 slapi_ch_free( (void **)&static_hn );
1856 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1865 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1867 hn = ch_strdup( static_hn );
1873 * FIXME: this should go in an appropriate header ...
1875 extern int slapi_int_log_error( int level, char *subsystem, char *fmt, va_list arglist );
1884 int rc = LDAP_SUCCESS;
1887 va_start( arglist, fmt );
1888 rc = slapi_int_log_error( severity, subsystem, fmt, arglist );
1896 slapi_timer_current_time( void )
1898 static int first_time = 1;
1899 #if !defined (_WIN32)
1903 ldap_pvt_thread_mutex_lock( &slapi_time_mutex );
1906 gettimeofday( &base_time, NULL );
1908 gettimeofday( &now, NULL );
1909 ret = ( now.tv_sec - base_time.tv_sec ) * 1000000 +
1910 (now.tv_usec - base_time.tv_usec);
1911 ldap_pvt_thread_mutex_unlock( &slapi_time_mutex );
1917 return (slap_get_time() - starttime) * 1000000;
1924 performance_counter_present = QueryPerformanceCounter( &base_time );
1925 QueryPerformanceFrequency( &performance_freq );
1928 if ( !performance_counter_present )
1931 QueryPerformanceCounter( &now );
1932 return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
1940 slapi_timer_get_time( char *label )
1942 unsigned long start = slapi_timer_current_time();
1943 printf("%10ld %10d usec %s\n", start, 0, label);
1951 slapi_timer_elapsed_time(
1953 unsigned long start )
1955 unsigned long stop = slapi_timer_current_time();
1956 printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
1960 slapi_free_search_results_internal( Slapi_PBlock *pb )
1962 Slapi_Entry **entries;
1963 int k = 0, nEnt = 0;
1965 slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
1966 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
1967 if ( nEnt == 0 || entries == NULL ) {
1971 for ( k = 0; k < nEnt; k++ ) {
1972 slapi_entry_free( entries[k] );
1976 slapi_ch_free( (void **)&entries );
1979 int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
1982 return LDAP_PARAM_ERROR;
1984 if ( pb->pb_conn == NULL )
1985 return LDAP_PARAM_ERROR;
1988 *isSSL = pb->pb_conn->c_is_tls;
1993 return LDAP_SUCCESS;
1997 * DS 5.x compatability API follow
2000 int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
2005 return LDAP_PARAM_ERROR;
2007 at = attr->a_desc->ad_type;
2009 *flags = SLAPI_ATTR_FLAG_STD_ATTR;
2011 if ( is_at_single_value( at ) )
2012 *flags |= SLAPI_ATTR_FLAG_SINGLE;
2013 if ( is_at_operational( at ) )
2014 *flags |= SLAPI_ATTR_FLAG_OPATTR;
2015 if ( is_at_obsolete( at ) )
2016 *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
2017 if ( is_at_collective( at ) )
2018 *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
2019 if ( is_at_no_user_mod( at ) )
2020 *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
2022 return LDAP_SUCCESS;
2025 int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
2027 unsigned long flags;
2029 if ( slapi_attr_get_flags( attr, &flags ) != 0 )
2031 return (flags & flag) ? 1 : 0;
2034 Slapi_Attr *slapi_attr_new( void )
2038 ad = (Attribute *)slapi_ch_calloc( 1, sizeof(*ad) );
2043 Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
2046 AttributeDescription *ad = NULL;
2048 if( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
2061 void slapi_attr_free( Slapi_Attr **a )
2067 Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
2069 return attr_dup( (Slapi_Attr *)attr );
2072 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
2075 struct berval *nvalp;
2077 AttributeDescription *desc = a->a_desc;
2079 if ( desc->ad_type->sat_equality &&
2080 desc->ad_type->sat_equality->smr_normalize ) {
2081 rc = (*desc->ad_type->sat_equality->smr_normalize)(
2082 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
2083 desc->ad_type->sat_syntax,
2084 desc->ad_type->sat_equality,
2085 (Slapi_Value *)v, &nval, NULL );
2086 if ( rc != LDAP_SUCCESS ) {
2094 rc = value_add_one( &a->a_vals, (Slapi_Value *)v );
2095 if ( rc == 0 && nvalp != NULL ) {
2096 rc = value_add_one( &a->a_nvals, nvalp );
2098 a->a_nvals = a->a_vals;
2101 if ( nvalp != NULL ) {
2102 slapi_ch_free_string( &nval.bv_val );
2108 int slapi_attr_type2plugin( const char *type, void **pi )
2115 int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
2117 if ( attr == NULL ) {
2118 return LDAP_PARAM_ERROR;
2121 *type = attr->a_desc->ad_cname.bv_val;
2123 return LDAP_SUCCESS;
2126 int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp )
2128 if ( attr == NULL ) {
2129 return LDAP_PARAM_ERROR;
2131 *oidp = attr->a_desc->ad_type->sat_oid;
2133 return LDAP_SUCCESS;
2136 int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
2143 mr = a->a_desc->ad_type->sat_equality;
2144 rc = value_match( &ret, a->a_desc, mr,
2145 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
2146 (struct berval *)v1, (void *)v2, &text );
2147 if ( rc != LDAP_SUCCESS )
2150 return ( ret == 0 ) ? 0 : -1;
2153 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
2157 if ( a ->a_vals == NULL ) {
2160 rc = attr_valfind( (Attribute *)a, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, v,
2162 return rc == 0 ? 0 : -1;
2165 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
2167 AttributeDescription *a1 = NULL;
2168 AttributeDescription *a2 = NULL;
2172 if ( slap_str2ad( t1, &a1, &text ) != LDAP_SUCCESS ) {
2176 if ( slap_str2ad( t2, &a2, &text ) != LDAP_SUCCESS ) {
2180 #define ad_base_cmp(l,r) (((l)->ad_type->sat_cname.bv_len < (r)->ad_type->sat_cname.bv_len) \
2181 ? -1 : (((l)->ad_type->sat_cname.bv_len > (r)->ad_type->sat_cname.bv_len) \
2182 ? 1 : strcasecmp((l)->ad_type->sat_cname.bv_val, (r)->ad_type->sat_cname.bv_val )))
2185 case SLAPI_TYPE_CMP_EXACT:
2186 ret = ad_cmp( a1, a2 );
2188 case SLAPI_TYPE_CMP_BASE:
2189 ret = ad_base_cmp( a1, a2 );
2191 case SLAPI_TYPE_CMP_SUBTYPE:
2192 ret = is_ad_subtype( a2, a2 );
2202 int slapi_attr_types_equivalent( const char *t1, const char *t2 )
2204 return ( slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT ) == 0 );
2207 int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v )
2209 return slapi_valueset_first_value( &a->a_vals, v );
2212 int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v )
2214 return slapi_valueset_next_value( &a->a_vals, hint, v );
2217 int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues )
2219 *numValues = slapi_valueset_count( &a->a_vals );
2224 int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs )
2226 *vs = &((Slapi_Attr *)a)->a_vals;
2231 int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals )
2233 return slapi_attr_get_values( a, vals );
2236 char *slapi_attr_syntax_normalize( const char *s )
2238 AttributeDescription *ad = NULL;
2241 if ( slap_str2ad( s, &ad, &text ) != LDAP_SUCCESS ) {
2245 return ad->ad_cname.bv_val;
2248 Slapi_Value *slapi_value_new( void )
2252 bv = (struct berval *)slapi_ch_malloc( sizeof(*bv) );
2257 Slapi_Value *slapi_value_new_berval(const struct berval *bval)
2259 return ber_dupbv( NULL, (struct berval *)bval );
2262 Slapi_Value *slapi_value_new_value(const Slapi_Value *v)
2264 return slapi_value_new_berval( v );
2267 Slapi_Value *slapi_value_new_string(const char *s)
2271 bv.bv_val = (char *)s;
2272 bv.bv_len = strlen( s );
2274 return slapi_value_new_berval( &bv );
2277 Slapi_Value *slapi_value_init(Slapi_Value *val)
2285 Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval)
2287 return ber_dupbv( v, bval );
2290 Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
2292 v->bv_val = slapi_ch_strdup( s );
2293 v->bv_len = strlen( s );
2298 Slapi_Value *slapi_value_dup(const Slapi_Value *v)
2300 return slapi_value_new_value( v );
2303 void slapi_value_free(Slapi_Value **value)
2305 if ( value == NULL ) {
2309 if ( (*value) != NULL ) {
2310 slapi_ch_free( (void **)&(*value)->bv_val );
2311 slapi_ch_free( (void **)value );
2315 const struct berval *slapi_value_get_berval( const Slapi_Value *value )
2320 Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval )
2322 if ( value == NULL ) {
2325 if ( value->bv_val != NULL ) {
2326 slapi_ch_free( (void **)&value->bv_val );
2328 slapi_value_init_berval( value, (struct berval *)bval );
2333 Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom)
2335 if ( value == NULL ) {
2338 return slapi_value_set_berval( value, vfrom );
2341 Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
2343 if ( value == NULL ) {
2346 if ( value->bv_val != NULL ) {
2347 slapi_ch_free( (void **)&value->bv_val );
2349 value->bv_val = slapi_ch_malloc( len );
2350 value->bv_len = len;
2351 AC_MEMCPY( value->bv_val, val, len );
2356 int slapi_value_set_string(Slapi_Value *value, const char *strVal)
2358 if ( value == NULL ) {
2361 slapi_value_set( value, (void *)strVal, strlen( strVal ) );
2365 int slapi_value_set_int(Slapi_Value *value, int intVal)
2369 snprintf( buf, sizeof( buf ), "%d", intVal );
2371 return slapi_value_set_string( value, buf );
2374 const char *slapi_value_get_string(const Slapi_Value *value)
2376 if ( value == NULL ) return NULL;
2377 if ( value->bv_val == NULL ) return NULL;
2378 if ( !checkBVString( value ) ) return NULL;
2380 return value->bv_val;
2383 int slapi_value_get_int(const Slapi_Value *value)
2385 if ( value == NULL ) return 0;
2386 if ( value->bv_val == NULL ) return 0;
2387 if ( !checkBVString( value ) ) return 0;
2389 return (int)strtol( value->bv_val, NULL, 10 );
2392 unsigned int slapi_value_get_uint(const Slapi_Value *value)
2394 if ( value == NULL ) return 0;
2395 if ( value->bv_val == NULL ) return 0;
2396 if ( !checkBVString( value ) ) return 0;
2398 return (unsigned int)strtoul( value->bv_val, NULL, 10 );
2401 long slapi_value_get_long(const Slapi_Value *value)
2403 if ( value == NULL ) return 0;
2404 if ( value->bv_val == NULL ) return 0;
2405 if ( !checkBVString( value ) ) return 0;
2407 return strtol( value->bv_val, NULL, 10 );
2410 unsigned long slapi_value_get_ulong(const Slapi_Value *value)
2412 if ( value == NULL ) return 0;
2413 if ( value->bv_val == NULL ) return 0;
2414 if ( !checkBVString( value ) ) return 0;
2416 return strtoul( value->bv_val, NULL, 10 );
2419 size_t slapi_value_get_length(const Slapi_Value *value)
2421 if ( value == NULL )
2424 return (size_t) value->bv_len;
2427 int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2)
2429 return slapi_attr_value_cmp( a, v1, v2 );
2432 /* A ValueSet is a container for a BerVarray. */
2433 Slapi_ValueSet *slapi_valueset_new( void )
2437 vs = (Slapi_ValueSet *)slapi_ch_malloc( sizeof( *vs ) );
2443 void slapi_valueset_free(Slapi_ValueSet *vs)
2448 ber_bvarray_free( vp );
2451 slapi_ch_free( (void **)&vp );
2455 void slapi_valueset_init(Slapi_ValueSet *vs)
2457 if ( vs != NULL && *vs == NULL ) {
2458 *vs = (Slapi_ValueSet)slapi_ch_calloc( 1, sizeof(struct berval) );
2459 (*vs)->bv_val = NULL;
2464 void slapi_valueset_done(Slapi_ValueSet *vs)
2471 for ( vp = *vs; vp->bv_val != NULL; vp++ ) {
2473 slapi_ch_free( (void **)&vp->bv_val );
2475 /* but don't free *vs or vs */
2478 void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
2482 ber_dupbv( &bv, (Slapi_Value *)addval );
2483 ber_bvarray_add( vs, &bv );
2486 int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
2488 return slapi_valueset_next_value( vs, 0, v );
2491 int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
2501 for ( i = 0; vp[i].bv_val != NULL; i++ ) {
2511 int slapi_valueset_count( const Slapi_ValueSet *vs )
2524 for ( i = 0; vp[i].bv_val != NULL; i++ )
2531 void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
2535 for ( vp = *vs2; vp->bv_val != NULL; vp++ ) {
2536 slapi_valueset_add_value( vs1, vp );
2540 int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
2541 struct berval *val, int access )
2544 slap_access_t slap_access;
2545 AttributeDescription *ad = NULL;
2548 rc = slap_str2ad( attr, &ad, &text );
2549 if ( rc != LDAP_SUCCESS ) {
2554 * Whilst the SLAPI access types are arranged as a bitmask, the
2555 * documentation indicates that they are to be used separately.
2557 switch ( access & SLAPI_ACL_ALL ) {
2558 case SLAPI_ACL_COMPARE:
2559 slap_access = ACL_COMPARE;
2561 case SLAPI_ACL_SEARCH:
2562 slap_access = ACL_SEARCH;
2564 case SLAPI_ACL_READ:
2565 slap_access = ACL_READ;
2567 case SLAPI_ACL_WRITE:
2568 slap_access = ACL_WRITE;
2570 case SLAPI_ACL_DELETE:
2571 slap_access = ACL_WDEL;
2574 slap_access = ACL_WADD;
2576 case SLAPI_ACL_SELF: /* not documented */
2577 case SLAPI_ACL_PROXY: /* not documented */
2579 return LDAP_INSUFFICIENT_ACCESS;
2583 assert( pb->pb_op != NULL );
2585 if ( access_allowed( pb->pb_op, e, ad, val, slap_access, NULL ) ) {
2586 return LDAP_SUCCESS;
2589 return LDAP_INSUFFICIENT_ACCESS;
2592 int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf)
2594 int rc = LDAP_SUCCESS;
2597 if ( pb == NULL || pb->pb_op == NULL )
2598 return LDAP_PARAM_ERROR;
2600 ml = slapi_int_ldapmods2modifications( pb->pb_op, mods );
2605 if ( rc == LDAP_SUCCESS ) {
2606 rc = acl_check_modlist( pb->pb_op, e, ml ) ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
2609 slap_mods_free( ml, 1 );
2615 * Synthesise an LDAPMod array from a Modifications list to pass
2618 LDAPMod **slapi_int_modifications2ldapmods( Modifications *modlist )
2621 LDAPMod **mods, *modp;
2624 for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
2627 mods = (LDAPMod **)slapi_ch_malloc( (i + 1) * sizeof(LDAPMod *) );
2629 for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
2630 mods[i] = (LDAPMod *)slapi_ch_malloc( sizeof(LDAPMod) );
2632 modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
2633 if ( BER_BVISNULL( &ml->sml_type ) ) {
2634 /* may happen for internally generated mods */
2635 assert( ml->sml_desc != NULL );
2636 modp->mod_type = slapi_ch_strdup( ml->sml_desc->ad_cname.bv_val );
2638 modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
2641 if ( ml->sml_values != NULL ) {
2642 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
2644 modp->mod_bvalues = (struct berval **)slapi_ch_malloc( (j + 1) *
2645 sizeof(struct berval *) );
2646 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
2647 modp->mod_bvalues[j] = (struct berval *)slapi_ch_malloc(
2648 sizeof(struct berval) );
2649 ber_dupbv( modp->mod_bvalues[j], &ml->sml_values[j] );
2651 modp->mod_bvalues[j] = NULL;
2653 modp->mod_bvalues = NULL;
2664 * Convert a potentially modified array of LDAPMods back to a
2665 * Modification list. Unfortunately the values need to be
2666 * duplicated because slap_mods_check() will try to free them
2667 * before prettying (and we can't easily get out of calling
2668 * slap_mods_check() because we need normalized values).
2670 Modifications *slapi_int_ldapmods2modifications ( Operation *op, LDAPMod **mods )
2672 Modifications *modlist = NULL, **modtail;
2674 char textbuf[SLAP_TEXT_BUFLEN];
2677 if ( mods == NULL ) {
2683 for ( modp = mods; *modp != NULL; modp++ ) {
2685 LDAPMod *lmod = *modp;
2688 AttributeDescription *ad = NULL;
2690 if ( slap_str2ad( lmod->mod_type, &ad, &text ) != LDAP_SUCCESS ) {
2694 mod = (Modifications *) slapi_ch_malloc( sizeof(Modifications) );
2695 mod->sml_op = lmod->mod_op & ~(LDAP_MOD_BVALUES);
2697 mod->sml_type = ad->ad_cname;
2699 mod->sml_next = NULL;
2702 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2703 if ( lmod->mod_bvalues != NULL ) {
2704 while ( lmod->mod_bvalues[i] != NULL )
2708 if ( lmod->mod_values != NULL ) {
2709 while ( lmod->mod_values[i] != NULL )
2713 mod->sml_numvals = i;
2716 mod->sml_values = NULL;
2718 mod->sml_values = (BerVarray) slapi_ch_malloc( (i + 1) * sizeof(struct berval) );
2720 /* NB: This implicitly trusts a plugin to return valid modifications. */
2721 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2722 for ( i = 0; lmod->mod_bvalues[i] != NULL; i++ ) {
2723 ber_dupbv( &mod->sml_values[i], lmod->mod_bvalues[i] );
2726 for ( i = 0; lmod->mod_values[i] != NULL; i++ ) {
2727 mod->sml_values[i].bv_val = slapi_ch_strdup( lmod->mod_values[i] );
2728 mod->sml_values[i].bv_len = strlen( lmod->mod_values[i] );
2731 mod->sml_values[i].bv_val = NULL;
2732 mod->sml_values[i].bv_len = 0;
2734 mod->sml_nvalues = NULL;
2737 modtail = &mod->sml_next;
2740 if ( slap_mods_check( op, modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
2741 slap_mods_free( modlist, 1 );
2749 * Sun ONE DS 5.x computed attribute support. Computed attributes
2750 * allow for dynamically generated operational attributes, a very
2751 * useful thing indeed.
2755 * For some reason Sun don't use the normal plugin mechanism
2756 * registration path to register an "evaluator" function (an
2757 * "evaluator" is responsible for adding computed attributes;
2758 * the nomenclature is somewhat confusing).
2760 * As such slapi_compute_add_evaluator() registers the
2761 * function directly.
2763 int slapi_compute_add_evaluator(slapi_compute_callback_t function)
2765 Slapi_PBlock *pPlugin = NULL;
2767 int type = SLAPI_PLUGIN_OBJECT;
2769 pPlugin = slapi_pblock_new();
2770 if ( pPlugin == NULL ) {
2771 rc = LDAP_NO_MEMORY;
2775 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2776 if ( rc != LDAP_SUCCESS ) {
2780 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (void *)function );
2781 if ( rc != LDAP_SUCCESS ) {
2785 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2792 if ( rc != LDAP_SUCCESS ) {
2793 if ( pPlugin != NULL ) {
2794 slapi_pblock_destroy( pPlugin );
2803 * See notes above regarding slapi_compute_add_evaluator().
2805 int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
2807 Slapi_PBlock *pPlugin = NULL;
2809 int type = SLAPI_PLUGIN_OBJECT;
2811 pPlugin = slapi_pblock_new();
2812 if ( pPlugin == NULL ) {
2813 rc = LDAP_NO_MEMORY;
2817 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2818 if ( rc != LDAP_SUCCESS ) {
2822 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, (void *)function );
2823 if ( rc != LDAP_SUCCESS ) {
2827 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2834 if ( rc != LDAP_SUCCESS ) {
2835 if ( pPlugin != NULL ) {
2836 slapi_pblock_destroy( pPlugin );
2845 * Call compute evaluators
2847 int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn)
2850 slapi_compute_callback_t *pGetPlugin, *tmpPlugin;
2852 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
2853 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
2854 /* Nothing to do; front-end should ignore. */
2858 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
2860 * -1: no attribute matched requested type
2861 * 0: one attribute matched
2862 * >0: error happened
2864 rc = (*pGetPlugin)( c, type, e, outputfn );
2870 slapi_ch_free( (void **)&tmpPlugin );
2876 compute_rewrite_search_filter( Slapi_PBlock *pb )
2878 if ( pb == NULL || pb->pb_op == NULL )
2879 return LDAP_PARAM_ERROR;
2881 return slapi_int_call_plugins( pb->pb_op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
2885 * New API to provide the plugin with access to the search
2886 * pblock. Have informed Sun DS team.
2889 slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
2894 if ( c->cac_pb == NULL )
2902 Slapi_Mutex *slapi_new_mutex( void )
2906 m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) );
2907 if ( ldap_pvt_thread_mutex_init( &m->mutex ) != 0 ) {
2908 slapi_ch_free( (void **)&m );
2915 void slapi_destroy_mutex( Slapi_Mutex *mutex )
2917 if ( mutex != NULL ) {
2918 ldap_pvt_thread_mutex_destroy( &mutex->mutex );
2919 slapi_ch_free( (void **)&mutex);
2923 void slapi_lock_mutex( Slapi_Mutex *mutex )
2925 ldap_pvt_thread_mutex_lock( &mutex->mutex );
2928 int slapi_unlock_mutex( Slapi_Mutex *mutex )
2930 return ldap_pvt_thread_mutex_unlock( &mutex->mutex );
2933 Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
2937 if ( mutex == NULL ) {
2941 cv = (Slapi_CondVar *)slapi_ch_malloc( sizeof(*cv) );
2942 if ( ldap_pvt_thread_cond_init( &cv->cond ) != 0 ) {
2943 slapi_ch_free( (void **)&cv );
2947 cv->mutex = mutex->mutex;
2952 void slapi_destroy_condvar( Slapi_CondVar *cvar )
2954 if ( cvar != NULL ) {
2955 ldap_pvt_thread_cond_destroy( &cvar->cond );
2956 slapi_ch_free( (void **)&cvar );
2960 int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout )
2962 if ( cvar == NULL ) {
2966 return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex );
2969 int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
2971 if ( cvar == NULL ) {
2976 return ldap_pvt_thread_cond_broadcast( &cvar->cond );
2979 return ldap_pvt_thread_cond_signal( &cvar->cond );
2982 int slapi_int_access_allowed( Operation *op,
2984 AttributeDescription *desc,
2986 slap_access_t access,
2987 AccessControlState *state )
2989 int rc, slap_access = 0;
2990 slapi_acl_callback_t *pGetPlugin, *tmpPlugin;
2993 pb = SLAPI_OPERATION_PBLOCK( op );
2995 /* internal operation */
3001 slap_access |= SLAPI_ACL_COMPARE;
3004 slap_access |= SLAPI_ACL_SEARCH;
3007 slap_access |= SLAPI_ACL_READ;
3010 slap_access |= SLAPI_ACL_WRITE;
3013 slap_access |= SLAPI_ACL_DELETE;
3016 slap_access |= SLAPI_ACL_ADD;
3022 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_ACL_ALLOW_ACCESS, (SLAPI_FUNC **)&tmpPlugin );
3023 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
3024 /* nothing to do; allowed access */
3028 rc = 1; /* default allow policy */
3030 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
3035 rc = (*pGetPlugin)( pb, entry, desc->ad_cname.bv_val,
3036 val, slap_access, (void *)state );
3042 slapi_ch_free( (void **)&tmpPlugin );
3048 * There is no documentation for this.
3050 int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
3062 rc = ldap_str2rdn( rdn, &lrdn, &p, LDAP_DN_FORMAT_LDAPV3 );
3063 if ( rc != LDAP_SUCCESS ) {
3067 if ( lrdn[1] != NULL ) {
3068 return -1; /* not single valued */
3073 *type = slapi_ch_strdup( ava->la_attr.bv_val );
3074 ber_dupbv( bv, &ava->la_value );
3081 char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
3083 struct berval new_dn, parent_dn, newrdn;
3085 new_dn.bv_val = NULL;
3087 parent_dn.bv_val = (char *)dn;
3088 parent_dn.bv_len = strlen( dn );
3090 newrdn.bv_val = (char *)rdn;
3091 newrdn.bv_len = strlen( rdn );
3093 build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
3095 return new_dn.bv_val;
3098 int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
3102 char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
3103 size_t textlen = sizeof textbuf;
3104 int rc = LDAP_SUCCESS;
3106 PBLOCK_ASSERT_OP( pb, 0 );
3108 be_orig = pb->pb_op->o_bd;
3110 pb->pb_op->o_bd = select_backend( &e->e_nname, 0 );
3111 if ( pb->pb_op->o_bd != NULL ) {
3112 rc = entry_schema_check( pb->pb_op, e, NULL, 0, 0,
3113 &text, textbuf, textlen );
3115 pb->pb_op->o_bd = be_orig;
3117 return ( rc == LDAP_SUCCESS ) ? 0 : 1;
3120 int slapi_entry_rdn_values_present( const Slapi_Entry *e )
3124 int i = 0, match = 0;
3126 rc = ldap_bv2dn( &((Entry *)e)->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3127 if ( rc != LDAP_SUCCESS ) {
3131 if ( dn[0] != NULL ) {
3132 LDAPRDN rdn = dn[0];
3134 for ( i = 0; rdn[i] != NULL; i++ ) {
3135 LDAPAVA *ava = &rdn[0][i];
3136 Slapi_Attr *a = NULL;
3138 if ( slapi_entry_attr_find( (Slapi_Entry *)e, ava->la_attr.bv_val, &a ) == 0 &&
3139 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3146 return ( i == match );
3149 int slapi_entry_add_rdn_values( Slapi_Entry *e )
3154 rc = ldap_bv2dn( &e->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3155 if ( rc != LDAP_SUCCESS ) {
3159 if ( dn[0] != NULL ) {
3160 LDAPRDN rdn = dn[0];
3161 struct berval *vals[2];
3163 for ( i = 0; rdn[i] != NULL; i++ ) {
3164 LDAPAVA *ava = &rdn[0][i];
3165 Slapi_Attr *a = NULL;
3167 if ( slapi_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 &&
3168 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3171 vals[0] = &ava->la_value;
3174 slapi_entry_attr_merge( e, ava->la_attr.bv_val, vals );
3180 return LDAP_SUCCESS;
3183 const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
3187 attr = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
3188 if ( attr == NULL ) {
3192 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
3193 return slapi_value_get_string( &attr->a_vals[0] );
3199 void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
3203 attr_delete ( &e->e_attrs, slap_schema.si_ad_entryUUID );
3205 bv.bv_val = uniqueid;
3206 bv.bv_len = strlen( uniqueid );
3207 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, &bv, NULL );
3210 LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared )
3217 size = sizeof("ldap:///");
3221 size += strlen( ldaphost );
3222 if ( ldapport != 0 ) {
3226 url = slapi_ch_malloc( size );
3228 if ( ldapport != 0 ) {
3229 rc = snprintf( url, size, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
3231 rc = snprintf( url, size, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
3234 if ( rc > 0 && rc < size ) {
3235 rc = ldap_initialize( &ld, url );
3240 slapi_ch_free_string( &url );
3242 return ( rc == LDAP_SUCCESS ) ? ld : NULL;
3245 void slapi_ldap_unbind( LDAP *ld )
3247 ldap_unbind_ext_s( ld, NULL, NULL );
3250 int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags )
3253 return LDAP_PARAM_ERROR;
3255 *flags = SLAP_DBFLAGS(be);
3257 return LDAP_SUCCESS;
3261 slapi_int_count_controls( LDAPControl **ctrls )
3265 if ( ctrls == NULL )
3268 for ( i = 0; ctrls[i] != NULL; i++ )
3275 slapi_op_abandoned( Slapi_PBlock *pb )
3277 if ( pb->pb_op == NULL )
3280 return ( pb->pb_op->o_abandon );
3284 slapi_op_type_to_string(unsigned long type)
3289 case SLAPI_OPERATION_BIND:
3292 case SLAPI_OPERATION_UNBIND:
3295 case SLAPI_OPERATION_SEARCH:
3298 case SLAPI_OPERATION_MODIFY:
3301 case SLAPI_OPERATION_ADD:
3304 case SLAPI_OPERATION_DELETE:
3307 case SLAPI_OPERATION_MODDN:
3310 case SLAPI_OPERATION_COMPARE:
3313 case SLAPI_OPERATION_ABANDON:
3316 case SLAPI_OPERATION_EXTENDED:
3320 str = "unknown operation type";
3327 slapi_op_get_type(Slapi_Operation * op)
3331 switch ( op->o_tag ) {
3333 type = SLAPI_OPERATION_BIND;
3335 case LDAP_REQ_UNBIND:
3336 type = SLAPI_OPERATION_UNBIND;
3338 case LDAP_REQ_SEARCH:
3339 type = SLAPI_OPERATION_SEARCH;
3341 case LDAP_REQ_MODIFY:
3342 type = SLAPI_OPERATION_MODIFY;
3345 type = SLAPI_OPERATION_ADD;
3347 case LDAP_REQ_DELETE:
3348 type = SLAPI_OPERATION_DELETE;
3350 case LDAP_REQ_MODRDN:
3351 type = SLAPI_OPERATION_MODDN;
3353 case LDAP_REQ_COMPARE:
3354 type = SLAPI_OPERATION_COMPARE;
3356 case LDAP_REQ_ABANDON:
3357 type = SLAPI_OPERATION_ABANDON;
3359 case LDAP_REQ_EXTENDED:
3360 type = SLAPI_OPERATION_EXTENDED;
3363 type = SLAPI_OPERATION_NONE;
3369 void slapi_be_set_readonly( Slapi_Backend *be, int readonly )
3375 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
3377 be->be_restrictops &= ~(SLAP_RESTRICT_OP_WRITES);
3380 int slapi_be_get_readonly( Slapi_Backend *be )
3385 return ( (be->be_restrictops & SLAP_RESTRICT_OP_WRITES) == SLAP_RESTRICT_OP_WRITES );
3388 const char *slapi_x_be_get_updatedn( Slapi_Backend *be )
3393 return be->be_update_ndn.bv_val;
3396 Slapi_Backend *slapi_be_select( const Slapi_DN *sdn )
3400 slapi_sdn_get_ndn( sdn );
3402 be = select_backend( (struct berval *)&sdn->ndn, 0 );
3409 slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag)
3414 slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag)
3419 slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag)
3424 #endif /* LDAP_SLAPI */