2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2009 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>
39 * server start time (should we use a struct timeval also in slapd?
41 static struct timeval base_time;
42 ldap_pvt_thread_mutex_t slapi_hn_mutex;
43 ldap_pvt_thread_mutex_t slapi_time_mutex;
46 ldap_pvt_thread_mutex_t mutex;
49 struct slapi_condvar {
50 ldap_pvt_thread_cond_t cond;
51 ldap_pvt_thread_mutex_t mutex;
54 static int checkBVString(const struct berval *bv)
58 for ( i = 0; i < bv->bv_len; i++ ) {
59 if ( bv->bv_val[i] == '\0' )
62 if ( bv->bv_val[i] != '\0' )
69 * This function converts an array of pointers to berval objects to
70 * an array of berval objects.
75 struct berval **bvptr,
79 int rc = LDAP_SUCCESS;
83 if ( bvptr == NULL || *bvptr == NULL ) {
87 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
93 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
94 if ( tmpberval == NULL ) {
95 return LDAP_NO_MEMORY;
98 for ( i = 0; bvptr[i] != NULL; i++ ) {
99 tmpberval[i].bv_val = bvptr[i]->bv_val;
100 tmpberval[i].bv_len = bvptr[i]->bv_len;
102 tmpberval[i].bv_val = NULL;
103 tmpberval[i].bv_len = 0;
105 if ( rc == LDAP_SUCCESS ) {
117 return str2entry( s );
128 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
129 s = entry2str( e, len );
131 ret = slapi_ch_strdup( s );
132 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
138 slapi_entry_get_dn( Slapi_Entry *e )
140 return e->e_name.bv_val;
144 slapi_x_entry_get_id( Slapi_Entry *e )
150 slapi_int_dn_pretty( struct berval *in, struct berval *out )
152 Syntax *syntax = slap_schema.si_syn_distinguishedName;
154 assert( syntax != NULL );
156 return (syntax->ssyn_pretty)( syntax, in, out, NULL );
160 slapi_int_dn_normalize( struct berval *in, struct berval *out )
162 MatchingRule *mr = slap_schema.si_mr_distinguishedNameMatch;
163 Syntax *syntax = slap_schema.si_syn_distinguishedName;
165 assert( mr != NULL );
167 return (mr->smr_normalize)( 0, syntax, mr, in, out, NULL );
175 struct berval dn = BER_BVNULL;
178 dn.bv_len = strlen( ldn );
180 slapi_int_dn_pretty( &dn, &e->e_name );
181 slapi_int_dn_normalize( &dn, &e->e_nname );
185 slapi_entry_dup( Slapi_Entry *e )
187 return entry_dup( e );
191 slapi_entry_attr_delete(
195 AttributeDescription *ad = NULL;
198 if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
199 return 1; /* LDAP_NO_SUCH_ATTRIBUTE */
202 if ( attr_delete( &e->e_attrs, ad ) == LDAP_SUCCESS ) {
203 return 0; /* attribute is deleted */
205 return -1; /* something went wrong */
210 slapi_entry_alloc( void )
212 return (Slapi_Entry *)entry_alloc();
216 slapi_entry_free( Slapi_Entry *e )
223 slapi_entry_attr_merge(
226 struct berval **vals )
228 AttributeDescription *ad = NULL;
233 rc = slap_str2ad( type, &ad, &text );
234 if ( rc != LDAP_SUCCESS ) {
238 rc = bvptr2obj( vals, &bv, NULL );
239 if ( rc != LDAP_SUCCESS ) {
243 rc = attr_merge_normalize( e, ad, bv, NULL );
250 slapi_entry_attr_find(
255 AttributeDescription *ad = NULL;
259 rc = slap_str2ad( type, &ad, &text );
260 if ( rc != LDAP_SUCCESS ) {
264 *attr = attr_find( e->e_attrs, ad );
265 if ( *attr == NULL ) {
273 slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
275 AttributeDescription *ad = NULL;
280 rc = slap_str2ad( type, &ad, &text );
281 if ( rc != LDAP_SUCCESS ) {
285 attr = attr_find( e->e_attrs, ad );
286 if ( attr == NULL ) {
290 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
293 p = slapi_value_get_string( &attr->a_vals[0] );
295 return slapi_ch_strdup( p );
303 slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
305 AttributeDescription *ad = NULL;
310 rc = slap_str2ad( type, &ad, &text );
311 if ( rc != LDAP_SUCCESS ) {
315 attr = attr_find( e->e_attrs, ad );
316 if ( attr == NULL ) {
320 return slapi_value_get_int( attr->a_vals );
324 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
326 AttributeDescription *ad = NULL;
331 rc = slap_str2ad( type, &ad, &text );
332 if ( rc != LDAP_SUCCESS ) {
336 attr = attr_find( e->e_attrs, ad );
337 if ( attr == NULL ) {
341 return slapi_value_get_long( attr->a_vals );
345 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
347 AttributeDescription *ad = NULL;
352 rc = slap_str2ad( type, &ad, &text );
353 if ( rc != LDAP_SUCCESS ) {
357 attr = attr_find( e->e_attrs, ad );
358 if ( attr == NULL ) {
362 return slapi_value_get_uint( attr->a_vals );
366 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
368 AttributeDescription *ad = NULL;
373 rc = slap_str2ad( type, &ad, &text );
374 if ( rc != LDAP_SUCCESS ) {
378 attr = attr_find( e->e_attrs, ad );
379 if ( attr == NULL ) {
383 return slapi_value_get_ulong( attr->a_vals );
387 slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
390 AttributeDescription *ad = NULL;
395 rc = slap_str2ad( type, &ad, &text );
396 if ( rc != LDAP_SUCCESS ) {
400 attr = attr_find( e->e_attrs, ad );
401 if ( attr == NULL ) {
405 bv.bv_val = (char *)value;
406 bv.bv_len = strlen( value );
408 return ( slapi_attr_value_find( attr, &bv ) != -1 );
412 slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value)
414 AttributeDescription *ad = NULL;
419 rc = slap_str2ad( type, &ad, &text );
420 if ( rc != LDAP_SUCCESS ) {
424 attr_delete ( &e->e_attrs, ad );
425 if ( value != NULL ) {
426 bv.bv_val = (char *)value;
427 bv.bv_len = strlen(value);
428 attr_merge_normalize_one( e, ad, &bv, NULL );
433 slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l)
437 snprintf( buf, sizeof( buf ), "%d", l );
438 slapi_entry_attr_set_charptr( e, type, buf );
442 slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l)
446 snprintf( buf, sizeof( buf ), "%u", l );
447 slapi_entry_attr_set_charptr( e, type, buf );
451 slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l)
455 snprintf( buf, sizeof( buf ), "%ld", l );
456 slapi_entry_attr_set_charptr( e, type, buf );
460 slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l)
464 snprintf( buf, sizeof( buf ), "%lu", l );
465 slapi_entry_attr_set_charptr( e, type, buf );
469 slapi_is_rootdse( const char *dn )
471 return ( dn == NULL || dn[0] == '\0' );
475 slapi_entry_has_children( const Slapi_Entry *e )
478 int hasSubordinates = 0;
480 pb = slapi_pblock_new();
481 slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
483 slapi_pblock_set( pb, SLAPI_TARGET_DN, slapi_entry_get_dn( (Entry *)e ) );
485 pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0 );
486 if ( pb->pb_op->o_bd != NULL ) {
487 pb->pb_op->o_bd->be_has_subordinates( pb->pb_op, (Entry *)e, &hasSubordinates );
490 slapi_pblock_destroy( pb );
492 return ( hasSubordinates == LDAP_COMPARE_TRUE );
496 * Return approximate size of the entry rounded to the nearest
497 * 1K. Only the size of the attribute values are counted in the
498 * Sun implementation.
500 * http://docs.sun.com/source/816-6701-10/funcref.html#1017388
502 size_t slapi_entry_size(Slapi_Entry *e)
508 for ( size = 0, a = e->e_attrs; a != NULL; a = a->a_next ) {
509 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
510 size += a->a_vals[i].bv_len + 1;
515 size -= (size % 1024);
521 * Add values to entry.
524 * LDAP_SUCCESS Values added to entry
525 * LDAP_TYPE_OR_VALUE_EXISTS One or more values exist in entry already
526 * LDAP_CONSTRAINT_VIOLATION Any other error (odd, but it's the spec)
529 slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
534 char textbuf[SLAP_TEXT_BUFLEN];
536 mod.sm_op = LDAP_MOD_ADD;
539 mod.sm_type.bv_val = (char *)type;
540 mod.sm_type.bv_len = strlen( type );
542 rc = slap_str2ad( type, &mod.sm_desc, &text );
543 if ( rc != LDAP_SUCCESS ) {
547 if ( vals == NULL ) {
548 /* Apparently vals can be NULL
549 * FIXME: sm_values = NULL ? */
550 mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) );
551 mod.sm_values->bv_val = NULL;
555 rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
556 if ( rc != LDAP_SUCCESS ) {
557 return LDAP_CONSTRAINT_VIOLATION;
560 mod.sm_nvalues = NULL;
562 rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
564 slapi_ch_free( (void **)&mod.sm_values );
566 return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
570 slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
572 return slapi_entry_add_values( e, type, vals );
576 slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
578 AttributeDescription *ad = NULL;
582 rc = slap_str2ad( type, &ad, &text );
583 if ( rc != LDAP_SUCCESS ) {
587 return attr_merge_normalize( e, ad, *vs, NULL );
591 slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **vals )
596 char textbuf[SLAP_TEXT_BUFLEN];
598 mod.sm_op = LDAP_MOD_DELETE;
601 mod.sm_type.bv_val = (char *)type;
602 mod.sm_type.bv_len = strlen( type );
604 if ( vals == NULL ) {
605 /* If vals is NULL, this is a NOOP. */
609 rc = slap_str2ad( type, &mod.sm_desc, &text );
610 if ( rc != LDAP_SUCCESS ) {
614 if ( vals[0] == NULL ) {
615 /* SLAPI doco says LDApb_opERATIONS_ERROR but LDAP_OTHER is better */
616 return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
619 rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
620 if ( rc != LDAP_SUCCESS ) {
621 return LDAP_CONSTRAINT_VIOLATION;
623 mod.sm_nvalues = NULL;
625 rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
627 slapi_ch_free( (void **)&mod.sm_values );
633 slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
635 return slapi_entry_delete_values( e, type, vals );
639 slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
641 return slapi_entry_attr_merge( e, (char *)type, vals );
645 slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value)
647 AttributeDescription *ad = NULL;
651 rc = slap_str2ad( type, &ad, &text );
652 if ( rc != LDAP_SUCCESS ) {
656 rc = attr_merge_normalize_one( e, ad, (Slapi_Value *)value, NULL );
657 if ( rc != LDAP_SUCCESS ) {
665 slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
669 val.bv_val = (char *)value;
670 val.bv_len = strlen( value );
672 return slapi_entry_add_value( e, type, &val );
676 slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
678 Slapi_Value *vals[2];
681 val.bv_val = (char *)value;
682 val.bv_len = strlen( value );
686 return slapi_entry_delete_values_sv( e, type, vals );
690 slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
692 return slapi_entry_attr_merge( e, (char *)type, vals );
696 slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
704 return ( *attr != NULL ) ? 0 : -1;
708 slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr )
714 if ( prevattr == NULL ) {
718 *attr = prevattr->a_next;
720 return ( *attr != NULL ) ? 0 : -1;
724 slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
726 AttributeDescription *ad = NULL;
731 rc = slap_str2ad( type, &ad, &text );
732 if ( rc != LDAP_SUCCESS ) {
736 attr_delete( &e->e_attrs, ad );
738 rc = bvptr2obj( vals, &bv, NULL );
739 if ( rc != LDAP_SUCCESS ) {
743 rc = attr_merge_normalize( e, ad, bv, NULL );
744 slapi_ch_free( (void **)&bv );
745 if ( rc != LDAP_SUCCESS ) {
753 * FIXME -- The caller must free the allocated memory.
754 * In Netscape they do not have to.
757 slapi_attr_get_values(
759 struct berval ***vals )
764 if ( attr == NULL ) {
768 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
772 bv = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
773 for ( j = 0; j < i; j++ ) {
774 bv[j] = ber_dupbv( NULL, &attr->a_vals[j] );
778 *vals = (struct berval **)bv;
784 slapi_dn_normalize( char *dn )
789 assert( dn != NULL );
792 bdn.bv_len = strlen( dn );
794 if ( slapi_int_dn_pretty( &bdn, &pdn ) != LDAP_SUCCESS ) {
802 slapi_dn_normalize_case( char *dn )
807 assert( dn != NULL );
810 bdn.bv_len = strlen( dn );
812 if ( slapi_int_dn_normalize( &bdn, &ndn ) != LDAP_SUCCESS ) {
824 struct berval bdn, ndn;
825 struct berval bsuffix, nsuffix;
828 assert( dn != NULL );
829 assert( suffix != NULL );
832 bdn.bv_len = strlen( dn );
834 bsuffix.bv_val = suffix;
835 bsuffix.bv_len = strlen( suffix );
837 if ( dnNormalize( 0, NULL, NULL, &bdn, &ndn, NULL ) != LDAP_SUCCESS ) {
841 if ( dnNormalize( 0, NULL, NULL, &bsuffix, &nsuffix, NULL )
844 slapi_ch_free( (void **)&ndn.bv_val );
848 rc = dnIsSuffix( &ndn, &nsuffix );
850 slapi_ch_free( (void **)&ndn.bv_val );
851 slapi_ch_free( (void **)&nsuffix.bv_val );
858 const char *parentdn,
859 const char *childdn )
861 struct berval assertedParentDN, normalizedAssertedParentDN;
862 struct berval childDN, normalizedChildDN;
863 struct berval normalizedParentDN;
866 assert( parentdn != NULL );
867 assert( childdn != NULL );
869 assertedParentDN.bv_val = (char *)parentdn;
870 assertedParentDN.bv_len = strlen( parentdn );
872 if ( dnNormalize( 0, NULL, NULL, &assertedParentDN,
873 &normalizedAssertedParentDN, NULL ) != LDAP_SUCCESS )
878 childDN.bv_val = (char *)childdn;
879 childDN.bv_len = strlen( childdn );
881 if ( dnNormalize( 0, NULL, NULL, &childDN,
882 &normalizedChildDN, NULL ) != LDAP_SUCCESS )
884 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
888 dnParent( &normalizedChildDN, &normalizedParentDN );
890 if ( dnMatch( &match, 0, slap_schema.si_syn_distinguishedName, NULL,
891 &normalizedParentDN, (void *)&normalizedAssertedParentDN ) != LDAP_SUCCESS )
896 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
897 slapi_ch_free( (void **)&normalizedChildDN.bv_val );
899 return ( match == 0 );
903 * Returns DN of the parent entry, or NULL if the DN is
904 * an empty string or NULL, or has no parent.
907 slapi_dn_parent( const char *_dn )
909 struct berval dn, prettyDN;
910 struct berval parentDN;
917 dn.bv_val = (char *)_dn;
918 dn.bv_len = strlen( _dn );
920 if ( dn.bv_len == 0 ) {
924 if ( dnPretty( NULL, &dn, &prettyDN, NULL ) != LDAP_SUCCESS ) {
928 dnParent( &prettyDN, &parentDN ); /* in-place */
930 if ( parentDN.bv_len == 0 ) {
931 slapi_ch_free_string( &prettyDN.bv_val );
935 ret = slapi_ch_strdup( parentDN.bv_val );
936 slapi_ch_free_string( &prettyDN.bv_val );
941 int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *ldn )
946 if ( slapi_is_rootdse( ldn ) ) {
950 /* according to spec should already be normalized */
951 ndn.bv_len = strlen( ldn );
954 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
959 return be_issuffix( be, &ndn );
963 * Returns DN of the parent entry; or NULL if the DN is
964 * an empty string, if the DN has no parent, or if the
965 * DN is the suffix of the backend database
967 char *slapi_dn_beparent( Slapi_PBlock *pb, const char *ldn )
970 struct berval dn, prettyDN;
971 struct berval normalizedDN, parentDN;
978 PBLOCK_ASSERT_OP( pb, 0 );
980 if ( slapi_is_rootdse( ldn ) ) {
984 dn.bv_val = (char *)ldn;
985 dn.bv_len = strlen( ldn );
987 if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) {
991 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
993 if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) {
994 dnParent( &prettyDN, &parentDN );
996 if ( parentDN.bv_len != 0 )
997 parent = slapi_ch_strdup( parentDN.bv_val );
1000 slapi_ch_free_string( &prettyDN.bv_val );
1001 slapi_ch_free_string( &normalizedDN.bv_val );
1007 slapi_dn_ignore_case( char *dn )
1009 return slapi_dn_normalize_case( dn );
1013 slapi_ch_malloc( unsigned long size )
1015 return ch_malloc( size );
1019 slapi_ch_free( void **ptr )
1021 if ( ptr == NULL || *ptr == NULL )
1028 slapi_ch_free_string( char **ptr )
1030 slapi_ch_free( (void **)ptr );
1034 slapi_ch_array_free( char **arrayp )
1038 if ( arrayp != NULL ) {
1039 for ( p = arrayp; *p != NULL; p++ ) {
1040 slapi_ch_free( (void **)p );
1042 slapi_ch_free( (void **)&arrayp );
1047 slapi_ch_bvdup(const struct berval *v)
1049 return ber_dupbv(NULL, (struct berval *)v);
1053 slapi_ch_bvecdup(const struct berval **v)
1062 for ( i = 0; v[i] != NULL; i++ )
1065 rv = (struct berval **) slapi_ch_malloc( (i + 1) * sizeof(struct berval *) );
1067 for ( i = 0; v[i] != NULL; i++ ) {
1068 rv[i] = slapi_ch_bvdup( v[i] );
1077 unsigned long nelem,
1078 unsigned long size )
1080 return ch_calloc( nelem, size );
1086 unsigned long size )
1088 return ch_realloc( block, size );
1092 slapi_ch_strdup( const char *s )
1094 return ch_strdup( s );
1098 slapi_ch_stlen( const char *s )
1104 slapi_control_present(
1105 LDAPControl **controls,
1107 struct berval **val,
1121 for ( i = 0; controls != NULL && controls[i] != NULL; i++ ) {
1122 if ( strcmp( controls[i]->ldctl_oid, oid ) != 0 ) {
1127 if ( controls[i]->ldctl_value.bv_len != 0 ) {
1129 *val = &controls[i]->ldctl_value;
1134 *iscritical = controls[i]->ldctl_iscritical;
1144 slapControlMask2SlapiControlOp(slap_mask_t slap_mask,
1145 unsigned long *slapi_mask)
1147 *slapi_mask = SLAPI_OPERATION_NONE;
1149 if ( slap_mask & SLAP_CTRL_ABANDON )
1150 *slapi_mask |= SLAPI_OPERATION_ABANDON;
1152 if ( slap_mask & SLAP_CTRL_ADD )
1153 *slapi_mask |= SLAPI_OPERATION_ADD;
1155 if ( slap_mask & SLAP_CTRL_BIND )
1156 *slapi_mask |= SLAPI_OPERATION_BIND;
1158 if ( slap_mask & SLAP_CTRL_COMPARE )
1159 *slapi_mask |= SLAPI_OPERATION_COMPARE;
1161 if ( slap_mask & SLAP_CTRL_DELETE )
1162 *slapi_mask |= SLAPI_OPERATION_DELETE;
1164 if ( slap_mask & SLAP_CTRL_MODIFY )
1165 *slapi_mask |= SLAPI_OPERATION_MODIFY;
1167 if ( slap_mask & SLAP_CTRL_RENAME )
1168 *slapi_mask |= SLAPI_OPERATION_MODDN;
1170 if ( slap_mask & SLAP_CTRL_SEARCH )
1171 *slapi_mask |= SLAPI_OPERATION_SEARCH;
1173 if ( slap_mask & SLAP_CTRL_UNBIND )
1174 *slapi_mask |= SLAPI_OPERATION_UNBIND;
1178 slapiControlOp2SlapControlMask(unsigned long slapi_mask,
1179 slap_mask_t *slap_mask)
1183 if ( slapi_mask & SLAPI_OPERATION_BIND )
1184 *slap_mask |= SLAP_CTRL_BIND;
1186 if ( slapi_mask & SLAPI_OPERATION_UNBIND )
1187 *slap_mask |= SLAP_CTRL_UNBIND;
1189 if ( slapi_mask & SLAPI_OPERATION_SEARCH )
1190 *slap_mask |= SLAP_CTRL_SEARCH;
1192 if ( slapi_mask & SLAPI_OPERATION_MODIFY )
1193 *slap_mask |= SLAP_CTRL_MODIFY;
1195 if ( slapi_mask & SLAPI_OPERATION_ADD )
1196 *slap_mask |= SLAP_CTRL_ADD;
1198 if ( slapi_mask & SLAPI_OPERATION_DELETE )
1199 *slap_mask |= SLAP_CTRL_DELETE;
1201 if ( slapi_mask & SLAPI_OPERATION_MODDN )
1202 *slap_mask |= SLAP_CTRL_RENAME;
1204 if ( slapi_mask & SLAPI_OPERATION_COMPARE )
1205 *slap_mask |= SLAP_CTRL_COMPARE;
1207 if ( slapi_mask & SLAPI_OPERATION_ABANDON )
1208 *slap_mask |= SLAP_CTRL_ABANDON;
1210 *slap_mask |= SLAP_CTRL_GLOBAL;
1214 slapi_int_parse_control(
1219 /* Plugins must deal with controls themselves. */
1221 return LDAP_SUCCESS;
1225 slapi_register_supported_control(
1227 unsigned long controlops )
1229 slap_mask_t controlmask;
1231 slapiControlOp2SlapControlMask( controlops, &controlmask );
1233 register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control, NULL );
1237 slapi_get_supported_controls(
1239 unsigned long **ctrlopsp )
1243 rc = get_supported_controls( ctrloidsp, (slap_mask_t **)ctrlopsp );
1244 if ( rc != LDAP_SUCCESS ) {
1248 for ( i = 0; (*ctrloidsp)[i] != NULL; i++ ) {
1249 /* In place, naughty. */
1250 slapControlMask2SlapiControlOp( (*ctrlopsp)[i], &((*ctrlopsp)[i]) );
1253 return LDAP_SUCCESS;
1257 slapi_dup_control( LDAPControl *ctrl )
1261 ret = (LDAPControl *)slapi_ch_malloc( sizeof(*ret) );
1262 ret->ldctl_oid = slapi_ch_strdup( ctrl->ldctl_oid );
1263 ber_dupbv( &ret->ldctl_value, &ctrl->ldctl_value );
1264 ret->ldctl_iscritical = ctrl->ldctl_iscritical;
1270 slapi_register_supported_saslmechanism( char *mechanism )
1272 /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */
1273 slapi_log_error( SLAPI_LOG_FATAL, "slapi_register_supported_saslmechanism",
1274 "OpenLDAP does not support dynamic registration of SASL mechanisms\n" );
1278 slapi_get_supported_saslmechanisms( void )
1280 /* FIXME -- can not get the saslmechanism without a connection. */
1281 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_supported_saslmechanisms",
1282 "can not get the SASL mechanism list "
1283 "without a connection\n" );
1288 slapi_get_supported_extended_ops( void )
1291 char **ppExtOpOID = NULL;
1294 for ( i = 0; get_supported_extop( i ) != NULL; i++ ) {
1298 for ( j = 0; slapi_int_get_supported_extop( j ) != NULL; j++ ) {
1303 if ( numExtOps == 0 ) {
1307 ppExtOpOID = (char **)slapi_ch_malloc( (numExtOps + 1) * sizeof(char *) );
1308 for ( k = 0; k < i; k++ ) {
1311 bv = get_supported_extop( k );
1312 assert( bv != NULL );
1314 ppExtOpOID[ k ] = bv->bv_val;
1317 for ( ; k < j; k++ ) {
1320 bv = slapi_int_get_supported_extop( k );
1321 assert( bv != NULL );
1323 ppExtOpOID[ i + k ] = bv->bv_val;
1325 ppExtOpOID[ i + k ] = NULL;
1331 slapi_send_ldap_result(
1337 struct berval **urls )
1341 PBLOCK_ASSERT_OP( pb, 0 );
1346 rs->sr_matched = matched;
1350 if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
1351 send_ldap_sasl( pb->pb_op, rs );
1352 } else if ( rs->sr_rspoid != NULL ) {
1353 send_ldap_extended( pb->pb_op, rs );
1355 if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
1356 rs->sr_nentries = nentries;
1358 bvptr2obj( urls, &rs->sr_ref, NULL );
1360 send_ldap_result( pb->pb_op, rs );
1363 slapi_ch_free( (void **)&rs->sr_ref );
1368 slapi_send_ldap_search_entry(
1371 LDAPControl **ectrls,
1375 SlapReply rs = { REP_SEARCH };
1377 AttributeName *an = NULL;
1381 assert( pb->pb_op != NULL );
1383 if ( attrs != NULL ) {
1384 for ( i = 0; attrs[ i ] != NULL; i++ ) {
1390 an = (AttributeName *) slapi_ch_calloc( i + 1, sizeof(AttributeName) );
1391 for ( i = 0; attrs[i] != NULL; i++ ) {
1392 an[j].an_name.bv_val = attrs[i];
1393 an[j].an_name.bv_len = strlen( attrs[i] );
1394 an[j].an_desc = NULL;
1395 if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &text ) == LDAP_SUCCESS) {
1399 an[j].an_name.bv_len = 0;
1400 an[j].an_name.bv_val = NULL;
1403 rs.sr_err = LDAP_SUCCESS;
1404 rs.sr_matched = NULL;
1407 rs.sr_ctrls = ectrls;
1409 rs.sr_operational_attrs = NULL;
1414 rc = send_search_entry( pb->pb_op, &rs );
1416 slapi_ch_free( (void **)&an );
1422 slapi_send_ldap_search_reference(
1425 struct berval **references,
1426 LDAPControl **ectrls,
1427 struct berval **v2refs
1430 SlapReply rs = { REP_SEARCHREF };
1433 rs.sr_err = LDAP_SUCCESS;
1434 rs.sr_matched = NULL;
1437 rc = bvptr2obj( references, &rs.sr_ref, NULL );
1438 if ( rc != LDAP_SUCCESS ) {
1442 rs.sr_ctrls = ectrls;
1444 rs.sr_operational_attrs = NULL;
1447 if ( v2refs != NULL ) {
1448 rc = bvptr2obj( v2refs, &rs.sr_v2ref, NULL );
1449 if ( rc != LDAP_SUCCESS ) {
1450 slapi_ch_free( (void **)&rs.sr_ref );
1457 rc = send_search_reference( pb->pb_op, &rs );
1459 slapi_ch_free( (void **)&rs.sr_ref );
1460 slapi_ch_free( (void **)&rs.sr_v2ref );
1466 slapi_str2filter( char *str )
1468 return str2filter( str );
1480 slapi_filter_dup( Slapi_Filter *filter )
1482 return filter_dup( filter, NULL );
1486 slapi_filter_get_choice( Slapi_Filter *f )
1500 slapi_filter_get_ava(
1503 struct berval **bval )
1506 int rc = LDAP_SUCCESS;
1508 assert( type != NULL );
1509 assert( bval != NULL );
1514 ftype = f->f_choice;
1515 if ( ftype == LDAP_FILTER_EQUALITY
1516 || ftype == LDAP_FILTER_GE
1517 || ftype == LDAP_FILTER_LE
1518 || ftype == LDAP_FILTER_APPROX ) {
1520 * According to the SLAPI Reference Manual these are
1523 *type = f->f_un.f_un_ava->aa_desc->ad_cname.bv_val;
1524 *bval = &f->f_un.f_un_ava->aa_value;
1525 } else { /* filter type not supported */
1533 slapi_filter_list_first( Slapi_Filter *f )
1541 ftype = f->f_choice;
1542 if ( ftype == LDAP_FILTER_AND
1543 || ftype == LDAP_FILTER_OR
1544 || ftype == LDAP_FILTER_NOT ) {
1545 return (Slapi_Filter *)f->f_list;
1552 slapi_filter_list_next(
1554 Slapi_Filter *fprev )
1562 ftype = f->f_choice;
1563 if ( ftype == LDAP_FILTER_AND
1564 || ftype == LDAP_FILTER_OR
1565 || ftype == LDAP_FILTER_NOT )
1567 return fprev->f_next;
1574 slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
1580 switch ( f->f_choice ) {
1581 case LDAP_FILTER_GE:
1582 case LDAP_FILTER_LE:
1583 case LDAP_FILTER_EQUALITY:
1584 case LDAP_FILTER_APPROX:
1585 *type = f->f_av_desc->ad_cname.bv_val;
1587 case LDAP_FILTER_SUBSTRINGS:
1588 *type = f->f_sub_desc->ad_cname.bv_val;
1590 case LDAP_FILTER_PRESENT:
1591 *type = f->f_desc->ad_cname.bv_val;
1593 case LDAP_FILTER_EXT:
1594 *type = f->f_mr_desc->ad_cname.bv_val;
1597 /* Complex filters need not apply. */
1606 slapi_x_filter_set_attribute_type( Slapi_Filter *f, const char *type )
1608 AttributeDescription **adp, *ad = NULL;
1616 switch ( f->f_choice ) {
1617 case LDAP_FILTER_GE:
1618 case LDAP_FILTER_LE:
1619 case LDAP_FILTER_EQUALITY:
1620 case LDAP_FILTER_APPROX:
1621 adp = &f->f_av_desc;
1623 case LDAP_FILTER_SUBSTRINGS:
1624 adp = &f->f_sub_desc;
1626 case LDAP_FILTER_PRESENT:
1629 case LDAP_FILTER_EXT:
1630 adp = &f->f_mr_desc;
1633 /* Complex filters need not apply. */
1637 rc = slap_str2ad( type, &ad, &text );
1638 if ( rc == LDAP_SUCCESS )
1641 return ( rc == LDAP_SUCCESS ) ? 0 : -1;
1645 slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
1646 char ***any, char **final )
1650 if ( f->f_choice != LDAP_FILTER_SUBSTRINGS ) {
1655 * The caller shouldn't free but we can't return an
1656 * array of char *s from an array of bervals without
1657 * allocating memory, so we may as well be consistent.
1660 *type = f->f_sub_desc->ad_cname.bv_val;
1661 *initial = f->f_sub_initial.bv_val ? slapi_ch_strdup(f->f_sub_initial.bv_val) : NULL;
1662 if ( f->f_sub_any != NULL ) {
1663 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ )
1665 *any = (char **)slapi_ch_malloc( (i + 1) * sizeof(char *) );
1666 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
1667 (*any)[i] = slapi_ch_strdup(f->f_sub_any[i].bv_val);
1673 *final = f->f_sub_final.bv_val ? slapi_ch_strdup(f->f_sub_final.bv_val) : NULL;
1679 slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 )
1681 Slapi_Filter *f = NULL;
1683 if ( ftype == LDAP_FILTER_AND ||
1684 ftype == LDAP_FILTER_OR ||
1685 ftype == LDAP_FILTER_NOT )
1687 f = (Slapi_Filter *)slapi_ch_malloc( sizeof(*f) );
1688 f->f_choice = ftype;
1690 f->f_list->f_next = f2;
1698 slapi_x_filter_append( int ftype,
1699 Slapi_Filter **pContainingFilter, /* NULL on first call */
1700 Slapi_Filter **pNextFilter,
1701 Slapi_Filter *filterToAppend )
1703 if ( ftype == LDAP_FILTER_AND ||
1704 ftype == LDAP_FILTER_OR ||
1705 ftype == LDAP_FILTER_NOT )
1707 if ( *pContainingFilter == NULL ) {
1708 *pContainingFilter = (Slapi_Filter *)slapi_ch_malloc( sizeof(Slapi_Filter) );
1709 (*pContainingFilter)->f_choice = ftype;
1710 (*pContainingFilter)->f_list = filterToAppend;
1711 (*pContainingFilter)->f_next = NULL;
1713 if ( (*pContainingFilter)->f_choice != ftype ) {
1717 (*pNextFilter)->f_next = filterToAppend;
1719 *pNextFilter = filterToAppend;
1727 slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
1734 /* spec says return zero if no filter. */
1738 if ( verify_access ) {
1741 return LDAP_PARAM_ERROR;
1747 * According to acl.c it is safe to call test_filter() with
1750 rc = test_filter( op, e, f );
1752 case LDAP_COMPARE_TRUE:
1755 case LDAP_COMPARE_FALSE:
1757 case SLAPD_COMPARE_UNDEFINED:
1760 case LDAP_PROTOCOL_ERROR:
1761 /* filter type unknown: spec says return -1 */
1770 slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f)
1772 return slapi_filter_test( NULL, e, f, 0 );
1776 slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code )
1778 switch ( f->f_choice ) {
1779 case LDAP_FILTER_AND:
1780 case LDAP_FILTER_NOT:
1781 case LDAP_FILTER_OR: {
1785 * FIXME: altering f; should we use a temporary?
1787 for ( f = f->f_list; f != NULL; f = f->f_next ) {
1788 rc = slapi_filter_apply( f, fn, arg, error_code );
1792 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ) {
1798 case LDAP_FILTER_EQUALITY:
1799 case LDAP_FILTER_SUBSTRINGS:
1800 case LDAP_FILTER_GE:
1801 case LDAP_FILTER_LE:
1802 case LDAP_FILTER_PRESENT:
1803 case LDAP_FILTER_APPROX:
1804 case LDAP_FILTER_EXT:
1805 *error_code = fn( f, arg );
1808 *error_code = SLAPI_FILTER_UNKNOWN_FILTER_TYPE;
1811 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ||
1812 *error_code == SLAPI_FILTER_SCAN_CONTINUE ) {
1821 struct berval **vals,
1826 if( ( vals == NULL ) || ( v == NULL ) )
1829 for ( i = 0; vals[i] != NULL; i++ ) {
1830 if ( !lutil_passwd( vals[i], v, NULL, NULL ) )
1837 #define MAX_HOSTNAME 512
1840 slapi_get_hostname( void )
1843 static int been_here = 0;
1844 static char *static_hn = NULL;
1846 ldap_pvt_thread_mutex_lock( &slapi_hn_mutex );
1848 static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
1849 if ( static_hn == NULL) {
1850 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_hostname",
1851 "Cannot allocate memory for hostname\n" );
1853 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1858 if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) {
1859 slapi_log_error( SLAPI_LOG_FATAL,
1861 "can't get hostname\n" );
1862 slapi_ch_free( (void **)&static_hn );
1864 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1873 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1875 hn = ch_strdup( static_hn );
1881 * FIXME: this should go in an appropriate header ...
1883 extern int slapi_int_log_error( int level, char *subsystem, char *fmt, va_list arglist );
1892 int rc = LDAP_SUCCESS;
1895 va_start( arglist, fmt );
1896 rc = slapi_int_log_error( severity, subsystem, fmt, arglist );
1904 slapi_timer_current_time( void )
1906 static int first_time = 1;
1907 #if !defined (_WIN32)
1911 ldap_pvt_thread_mutex_lock( &slapi_time_mutex );
1914 gettimeofday( &base_time, NULL );
1916 gettimeofday( &now, NULL );
1917 ret = ( now.tv_sec - base_time.tv_sec ) * 1000000 +
1918 (now.tv_usec - base_time.tv_usec);
1919 ldap_pvt_thread_mutex_unlock( &slapi_time_mutex );
1925 return (slap_get_time() - starttime) * 1000000;
1932 performance_counter_present = QueryPerformanceCounter( &base_time );
1933 QueryPerformanceFrequency( &performance_freq );
1936 if ( !performance_counter_present )
1939 QueryPerformanceCounter( &now );
1940 return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
1948 slapi_timer_get_time( char *label )
1950 unsigned long start = slapi_timer_current_time();
1951 printf("%10ld %10d usec %s\n", start, 0, label);
1959 slapi_timer_elapsed_time(
1961 unsigned long start )
1963 unsigned long stop = slapi_timer_current_time();
1964 printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
1968 slapi_free_search_results_internal( Slapi_PBlock *pb )
1970 Slapi_Entry **entries;
1971 int k = 0, nEnt = 0;
1973 slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
1974 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
1975 if ( nEnt == 0 || entries == NULL ) {
1979 for ( k = 0; k < nEnt; k++ ) {
1980 slapi_entry_free( entries[k] );
1984 slapi_ch_free( (void **)&entries );
1987 int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
1990 return LDAP_PARAM_ERROR;
1992 if ( pb->pb_conn == NULL )
1993 return LDAP_PARAM_ERROR;
1996 *isSSL = pb->pb_conn->c_is_tls;
2001 return LDAP_SUCCESS;
2005 * DS 5.x compatability API follow
2008 int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
2013 return LDAP_PARAM_ERROR;
2015 at = attr->a_desc->ad_type;
2017 *flags = SLAPI_ATTR_FLAG_STD_ATTR;
2019 if ( is_at_single_value( at ) )
2020 *flags |= SLAPI_ATTR_FLAG_SINGLE;
2021 if ( is_at_operational( at ) )
2022 *flags |= SLAPI_ATTR_FLAG_OPATTR;
2023 if ( is_at_obsolete( at ) )
2024 *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
2025 if ( is_at_collective( at ) )
2026 *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
2027 if ( is_at_no_user_mod( at ) )
2028 *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
2030 return LDAP_SUCCESS;
2033 int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
2035 unsigned long flags;
2037 if ( slapi_attr_get_flags( attr, &flags ) != 0 )
2039 return (flags & flag) ? 1 : 0;
2042 Slapi_Attr *slapi_attr_new( void )
2046 ad = (Attribute *)slapi_ch_calloc( 1, sizeof(*ad) );
2051 Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
2054 AttributeDescription *ad = NULL;
2056 if( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
2069 void slapi_attr_free( Slapi_Attr **a )
2075 Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
2077 return attr_dup( (Slapi_Attr *)attr );
2080 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
2083 struct berval *nvalp;
2085 AttributeDescription *desc = a->a_desc;
2087 if ( desc->ad_type->sat_equality &&
2088 desc->ad_type->sat_equality->smr_normalize ) {
2089 rc = (*desc->ad_type->sat_equality->smr_normalize)(
2090 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
2091 desc->ad_type->sat_syntax,
2092 desc->ad_type->sat_equality,
2093 (Slapi_Value *)v, &nval, NULL );
2094 if ( rc != LDAP_SUCCESS ) {
2102 rc = value_add_one( &a->a_vals, (Slapi_Value *)v );
2103 if ( rc == 0 && nvalp != NULL ) {
2104 rc = value_add_one( &a->a_nvals, nvalp );
2106 a->a_nvals = a->a_vals;
2109 if ( nvalp != NULL ) {
2110 slapi_ch_free_string( &nval.bv_val );
2116 int slapi_attr_type2plugin( const char *type, void **pi )
2123 int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
2125 if ( attr == NULL ) {
2126 return LDAP_PARAM_ERROR;
2129 *type = attr->a_desc->ad_cname.bv_val;
2131 return LDAP_SUCCESS;
2134 int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp )
2136 if ( attr == NULL ) {
2137 return LDAP_PARAM_ERROR;
2139 *oidp = attr->a_desc->ad_type->sat_oid;
2141 return LDAP_SUCCESS;
2144 int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
2151 mr = a->a_desc->ad_type->sat_equality;
2152 rc = value_match( &ret, a->a_desc, mr,
2153 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
2154 (struct berval *)v1, (void *)v2, &text );
2155 if ( rc != LDAP_SUCCESS )
2158 return ( ret == 0 ) ? 0 : -1;
2161 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
2165 if ( a ->a_vals == NULL ) {
2168 rc = attr_valfind( (Attribute *)a, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, v,
2170 return rc == 0 ? 0 : -1;
2173 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
2175 AttributeDescription *a1 = NULL;
2176 AttributeDescription *a2 = NULL;
2180 if ( slap_str2ad( t1, &a1, &text ) != LDAP_SUCCESS ) {
2184 if ( slap_str2ad( t2, &a2, &text ) != LDAP_SUCCESS ) {
2188 #define ad_base_cmp(l,r) (((l)->ad_type->sat_cname.bv_len < (r)->ad_type->sat_cname.bv_len) \
2189 ? -1 : (((l)->ad_type->sat_cname.bv_len > (r)->ad_type->sat_cname.bv_len) \
2190 ? 1 : strcasecmp((l)->ad_type->sat_cname.bv_val, (r)->ad_type->sat_cname.bv_val )))
2193 case SLAPI_TYPE_CMP_EXACT:
2194 ret = ad_cmp( a1, a2 );
2196 case SLAPI_TYPE_CMP_BASE:
2197 ret = ad_base_cmp( a1, a2 );
2199 case SLAPI_TYPE_CMP_SUBTYPE:
2200 ret = is_ad_subtype( a2, a2 );
2210 int slapi_attr_types_equivalent( const char *t1, const char *t2 )
2212 return ( slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT ) == 0 );
2215 int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v )
2217 return slapi_valueset_first_value( &a->a_vals, v );
2220 int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v )
2222 return slapi_valueset_next_value( &a->a_vals, hint, v );
2225 int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues )
2227 *numValues = slapi_valueset_count( &a->a_vals );
2232 int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs )
2234 *vs = &((Slapi_Attr *)a)->a_vals;
2239 int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals )
2241 return slapi_attr_get_values( a, vals );
2244 char *slapi_attr_syntax_normalize( const char *s )
2246 AttributeDescription *ad = NULL;
2249 if ( slap_str2ad( s, &ad, &text ) != LDAP_SUCCESS ) {
2253 return ad->ad_cname.bv_val;
2256 Slapi_Value *slapi_value_new( void )
2260 bv = (struct berval *)slapi_ch_malloc( sizeof(*bv) );
2265 Slapi_Value *slapi_value_new_berval(const struct berval *bval)
2267 return ber_dupbv( NULL, (struct berval *)bval );
2270 Slapi_Value *slapi_value_new_value(const Slapi_Value *v)
2272 return slapi_value_new_berval( v );
2275 Slapi_Value *slapi_value_new_string(const char *s)
2279 bv.bv_val = (char *)s;
2280 bv.bv_len = strlen( s );
2282 return slapi_value_new_berval( &bv );
2285 Slapi_Value *slapi_value_init(Slapi_Value *val)
2293 Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval)
2295 return ber_dupbv( v, bval );
2298 Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
2300 v->bv_val = slapi_ch_strdup( s );
2301 v->bv_len = strlen( s );
2306 Slapi_Value *slapi_value_dup(const Slapi_Value *v)
2308 return slapi_value_new_value( v );
2311 void slapi_value_free(Slapi_Value **value)
2313 if ( value == NULL ) {
2317 if ( (*value) != NULL ) {
2318 slapi_ch_free( (void **)&(*value)->bv_val );
2319 slapi_ch_free( (void **)value );
2323 const struct berval *slapi_value_get_berval( const Slapi_Value *value )
2328 Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval )
2330 if ( value == NULL ) {
2333 if ( value->bv_val != NULL ) {
2334 slapi_ch_free( (void **)&value->bv_val );
2336 slapi_value_init_berval( value, (struct berval *)bval );
2341 Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom)
2343 if ( value == NULL ) {
2346 return slapi_value_set_berval( value, vfrom );
2349 Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
2351 if ( value == NULL ) {
2354 if ( value->bv_val != NULL ) {
2355 slapi_ch_free( (void **)&value->bv_val );
2357 value->bv_val = slapi_ch_malloc( len );
2358 value->bv_len = len;
2359 AC_MEMCPY( value->bv_val, val, len );
2364 int slapi_value_set_string(Slapi_Value *value, const char *strVal)
2366 if ( value == NULL ) {
2369 slapi_value_set( value, (void *)strVal, strlen( strVal ) );
2373 int slapi_value_set_int(Slapi_Value *value, int intVal)
2377 snprintf( buf, sizeof( buf ), "%d", intVal );
2379 return slapi_value_set_string( value, buf );
2382 const char *slapi_value_get_string(const Slapi_Value *value)
2384 if ( value == NULL ) return NULL;
2385 if ( value->bv_val == NULL ) return NULL;
2386 if ( !checkBVString( value ) ) return NULL;
2388 return value->bv_val;
2391 int slapi_value_get_int(const Slapi_Value *value)
2393 if ( value == NULL ) return 0;
2394 if ( value->bv_val == NULL ) return 0;
2395 if ( !checkBVString( value ) ) return 0;
2397 return (int)strtol( value->bv_val, NULL, 10 );
2400 unsigned int slapi_value_get_uint(const Slapi_Value *value)
2402 if ( value == NULL ) return 0;
2403 if ( value->bv_val == NULL ) return 0;
2404 if ( !checkBVString( value ) ) return 0;
2406 return (unsigned int)strtoul( value->bv_val, NULL, 10 );
2409 long slapi_value_get_long(const Slapi_Value *value)
2411 if ( value == NULL ) return 0;
2412 if ( value->bv_val == NULL ) return 0;
2413 if ( !checkBVString( value ) ) return 0;
2415 return strtol( value->bv_val, NULL, 10 );
2418 unsigned long slapi_value_get_ulong(const Slapi_Value *value)
2420 if ( value == NULL ) return 0;
2421 if ( value->bv_val == NULL ) return 0;
2422 if ( !checkBVString( value ) ) return 0;
2424 return strtoul( value->bv_val, NULL, 10 );
2427 size_t slapi_value_get_length(const Slapi_Value *value)
2429 if ( value == NULL )
2432 return (size_t) value->bv_len;
2435 int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2)
2437 return slapi_attr_value_cmp( a, v1, v2 );
2440 /* A ValueSet is a container for a BerVarray. */
2441 Slapi_ValueSet *slapi_valueset_new( void )
2445 vs = (Slapi_ValueSet *)slapi_ch_malloc( sizeof( *vs ) );
2451 void slapi_valueset_free(Slapi_ValueSet *vs)
2456 ber_bvarray_free( vp );
2459 slapi_ch_free( (void **)&vp );
2463 void slapi_valueset_init(Slapi_ValueSet *vs)
2465 if ( vs != NULL && *vs == NULL ) {
2466 *vs = (Slapi_ValueSet)slapi_ch_calloc( 1, sizeof(struct berval) );
2467 (*vs)->bv_val = NULL;
2472 void slapi_valueset_done(Slapi_ValueSet *vs)
2479 for ( vp = *vs; vp->bv_val != NULL; vp++ ) {
2481 slapi_ch_free( (void **)&vp->bv_val );
2483 /* but don't free *vs or vs */
2486 void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
2490 ber_dupbv( &bv, (Slapi_Value *)addval );
2491 ber_bvarray_add( vs, &bv );
2494 int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
2496 return slapi_valueset_next_value( vs, 0, v );
2499 int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
2509 for ( i = 0; vp[i].bv_val != NULL; i++ ) {
2519 int slapi_valueset_count( const Slapi_ValueSet *vs )
2532 for ( i = 0; vp[i].bv_val != NULL; i++ )
2539 void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
2543 for ( vp = *vs2; vp->bv_val != NULL; vp++ ) {
2544 slapi_valueset_add_value( vs1, vp );
2548 int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
2549 struct berval *val, int access )
2552 slap_access_t slap_access;
2553 AttributeDescription *ad = NULL;
2556 rc = slap_str2ad( attr, &ad, &text );
2557 if ( rc != LDAP_SUCCESS ) {
2562 * Whilst the SLAPI access types are arranged as a bitmask, the
2563 * documentation indicates that they are to be used separately.
2565 switch ( access & SLAPI_ACL_ALL ) {
2566 case SLAPI_ACL_COMPARE:
2567 slap_access = ACL_COMPARE;
2569 case SLAPI_ACL_SEARCH:
2570 slap_access = ACL_SEARCH;
2572 case SLAPI_ACL_READ:
2573 slap_access = ACL_READ;
2575 case SLAPI_ACL_WRITE:
2576 slap_access = ACL_WRITE;
2578 case SLAPI_ACL_DELETE:
2579 slap_access = ACL_WDEL;
2582 slap_access = ACL_WADD;
2584 case SLAPI_ACL_SELF: /* not documented */
2585 case SLAPI_ACL_PROXY: /* not documented */
2587 return LDAP_INSUFFICIENT_ACCESS;
2591 assert( pb->pb_op != NULL );
2593 if ( access_allowed( pb->pb_op, e, ad, val, slap_access, NULL ) ) {
2594 return LDAP_SUCCESS;
2597 return LDAP_INSUFFICIENT_ACCESS;
2600 int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf)
2602 int rc = LDAP_SUCCESS;
2605 if ( pb == NULL || pb->pb_op == NULL )
2606 return LDAP_PARAM_ERROR;
2608 ml = slapi_int_ldapmods2modifications( pb->pb_op, mods );
2613 if ( rc == LDAP_SUCCESS ) {
2614 rc = acl_check_modlist( pb->pb_op, e, ml ) ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
2617 slap_mods_free( ml, 1 );
2623 * Synthesise an LDAPMod array from a Modifications list to pass
2626 LDAPMod **slapi_int_modifications2ldapmods( Modifications *modlist )
2629 LDAPMod **mods, *modp;
2632 for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
2635 mods = (LDAPMod **)slapi_ch_malloc( (i + 1) * sizeof(LDAPMod *) );
2637 for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
2638 mods[i] = (LDAPMod *)slapi_ch_malloc( sizeof(LDAPMod) );
2640 modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
2641 if ( BER_BVISNULL( &ml->sml_type ) ) {
2642 /* may happen for internally generated mods */
2643 assert( ml->sml_desc != NULL );
2644 modp->mod_type = slapi_ch_strdup( ml->sml_desc->ad_cname.bv_val );
2646 modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
2649 if ( ml->sml_values != NULL ) {
2650 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
2652 modp->mod_bvalues = (struct berval **)slapi_ch_malloc( (j + 1) *
2653 sizeof(struct berval *) );
2654 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
2655 modp->mod_bvalues[j] = (struct berval *)slapi_ch_malloc(
2656 sizeof(struct berval) );
2657 ber_dupbv( modp->mod_bvalues[j], &ml->sml_values[j] );
2659 modp->mod_bvalues[j] = NULL;
2661 modp->mod_bvalues = NULL;
2672 * Convert a potentially modified array of LDAPMods back to a
2673 * Modification list. Unfortunately the values need to be
2674 * duplicated because slap_mods_check() will try to free them
2675 * before prettying (and we can't easily get out of calling
2676 * slap_mods_check() because we need normalized values).
2678 Modifications *slapi_int_ldapmods2modifications ( Operation *op, LDAPMod **mods )
2680 Modifications *modlist = NULL, **modtail;
2682 char textbuf[SLAP_TEXT_BUFLEN];
2685 if ( mods == NULL ) {
2691 for ( modp = mods; *modp != NULL; modp++ ) {
2693 LDAPMod *lmod = *modp;
2696 AttributeDescription *ad = NULL;
2698 if ( slap_str2ad( lmod->mod_type, &ad, &text ) != LDAP_SUCCESS ) {
2702 mod = (Modifications *) slapi_ch_malloc( sizeof(Modifications) );
2703 mod->sml_op = lmod->mod_op & ~(LDAP_MOD_BVALUES);
2705 mod->sml_type = ad->ad_cname;
2707 mod->sml_next = NULL;
2710 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2711 if ( lmod->mod_bvalues != NULL ) {
2712 while ( lmod->mod_bvalues[i] != NULL )
2716 if ( lmod->mod_values != NULL ) {
2717 while ( lmod->mod_values[i] != NULL )
2721 mod->sml_numvals = i;
2724 mod->sml_values = NULL;
2726 mod->sml_values = (BerVarray) slapi_ch_malloc( (i + 1) * sizeof(struct berval) );
2728 /* NB: This implicitly trusts a plugin to return valid modifications. */
2729 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2730 for ( i = 0; lmod->mod_bvalues[i] != NULL; i++ ) {
2731 ber_dupbv( &mod->sml_values[i], lmod->mod_bvalues[i] );
2734 for ( i = 0; lmod->mod_values[i] != NULL; i++ ) {
2735 mod->sml_values[i].bv_val = slapi_ch_strdup( lmod->mod_values[i] );
2736 mod->sml_values[i].bv_len = strlen( lmod->mod_values[i] );
2739 mod->sml_values[i].bv_val = NULL;
2740 mod->sml_values[i].bv_len = 0;
2742 mod->sml_nvalues = NULL;
2745 modtail = &mod->sml_next;
2748 if ( slap_mods_check( op, modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
2749 slap_mods_free( modlist, 1 );
2757 * Sun ONE DS 5.x computed attribute support. Computed attributes
2758 * allow for dynamically generated operational attributes, a very
2759 * useful thing indeed.
2763 * For some reason Sun don't use the normal plugin mechanism
2764 * registration path to register an "evaluator" function (an
2765 * "evaluator" is responsible for adding computed attributes;
2766 * the nomenclature is somewhat confusing).
2768 * As such slapi_compute_add_evaluator() registers the
2769 * function directly.
2771 int slapi_compute_add_evaluator(slapi_compute_callback_t function)
2773 Slapi_PBlock *pPlugin = NULL;
2775 int type = SLAPI_PLUGIN_OBJECT;
2777 pPlugin = slapi_pblock_new();
2778 if ( pPlugin == NULL ) {
2779 rc = LDAP_NO_MEMORY;
2783 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2784 if ( rc != LDAP_SUCCESS ) {
2788 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (void *)function );
2789 if ( rc != LDAP_SUCCESS ) {
2793 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2800 if ( rc != LDAP_SUCCESS ) {
2801 if ( pPlugin != NULL ) {
2802 slapi_pblock_destroy( pPlugin );
2811 * See notes above regarding slapi_compute_add_evaluator().
2813 int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
2815 Slapi_PBlock *pPlugin = NULL;
2817 int type = SLAPI_PLUGIN_OBJECT;
2819 pPlugin = slapi_pblock_new();
2820 if ( pPlugin == NULL ) {
2821 rc = LDAP_NO_MEMORY;
2825 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2826 if ( rc != LDAP_SUCCESS ) {
2830 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, (void *)function );
2831 if ( rc != LDAP_SUCCESS ) {
2835 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2842 if ( rc != LDAP_SUCCESS ) {
2843 if ( pPlugin != NULL ) {
2844 slapi_pblock_destroy( pPlugin );
2853 * Call compute evaluators
2855 int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn)
2858 slapi_compute_callback_t *pGetPlugin, *tmpPlugin;
2860 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
2861 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
2862 /* Nothing to do; front-end should ignore. */
2866 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
2868 * -1: no attribute matched requested type
2869 * 0: one attribute matched
2870 * >0: error happened
2872 rc = (*pGetPlugin)( c, type, e, outputfn );
2878 slapi_ch_free( (void **)&tmpPlugin );
2884 compute_rewrite_search_filter( Slapi_PBlock *pb )
2886 if ( pb == NULL || pb->pb_op == NULL )
2887 return LDAP_PARAM_ERROR;
2889 return slapi_int_call_plugins( pb->pb_op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
2893 * New API to provide the plugin with access to the search
2894 * pblock. Have informed Sun DS team.
2897 slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
2902 if ( c->cac_pb == NULL )
2910 Slapi_Mutex *slapi_new_mutex( void )
2914 m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) );
2915 if ( ldap_pvt_thread_mutex_init( &m->mutex ) != 0 ) {
2916 slapi_ch_free( (void **)&m );
2923 void slapi_destroy_mutex( Slapi_Mutex *mutex )
2925 if ( mutex != NULL ) {
2926 ldap_pvt_thread_mutex_destroy( &mutex->mutex );
2927 slapi_ch_free( (void **)&mutex);
2931 void slapi_lock_mutex( Slapi_Mutex *mutex )
2933 ldap_pvt_thread_mutex_lock( &mutex->mutex );
2936 int slapi_unlock_mutex( Slapi_Mutex *mutex )
2938 return ldap_pvt_thread_mutex_unlock( &mutex->mutex );
2941 Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
2945 if ( mutex == NULL ) {
2949 cv = (Slapi_CondVar *)slapi_ch_malloc( sizeof(*cv) );
2950 if ( ldap_pvt_thread_cond_init( &cv->cond ) != 0 ) {
2951 slapi_ch_free( (void **)&cv );
2955 cv->mutex = mutex->mutex;
2960 void slapi_destroy_condvar( Slapi_CondVar *cvar )
2962 if ( cvar != NULL ) {
2963 ldap_pvt_thread_cond_destroy( &cvar->cond );
2964 slapi_ch_free( (void **)&cvar );
2968 int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout )
2970 if ( cvar == NULL ) {
2974 return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex );
2977 int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
2979 if ( cvar == NULL ) {
2984 return ldap_pvt_thread_cond_broadcast( &cvar->cond );
2987 return ldap_pvt_thread_cond_signal( &cvar->cond );
2990 int slapi_int_access_allowed( Operation *op,
2992 AttributeDescription *desc,
2994 slap_access_t access,
2995 AccessControlState *state )
2997 int rc, slap_access = 0;
2998 slapi_acl_callback_t *pGetPlugin, *tmpPlugin;
3001 pb = SLAPI_OPERATION_PBLOCK( op );
3003 /* internal operation */
3009 slap_access |= SLAPI_ACL_COMPARE;
3012 slap_access |= SLAPI_ACL_SEARCH;
3015 slap_access |= SLAPI_ACL_READ;
3018 slap_access |= SLAPI_ACL_WRITE;
3021 slap_access |= SLAPI_ACL_DELETE;
3024 slap_access |= SLAPI_ACL_ADD;
3030 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_ACL_ALLOW_ACCESS, (SLAPI_FUNC **)&tmpPlugin );
3031 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
3032 /* nothing to do; allowed access */
3036 rc = 1; /* default allow policy */
3038 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
3043 rc = (*pGetPlugin)( pb, entry, desc->ad_cname.bv_val,
3044 val, slap_access, (void *)state );
3050 slapi_ch_free( (void **)&tmpPlugin );
3056 * There is no documentation for this.
3058 int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
3070 rc = ldap_str2rdn( rdn, &lrdn, &p, LDAP_DN_FORMAT_LDAPV3 );
3071 if ( rc != LDAP_SUCCESS ) {
3075 if ( lrdn[1] != NULL ) {
3076 return -1; /* not single valued */
3081 *type = slapi_ch_strdup( ava->la_attr.bv_val );
3082 ber_dupbv( bv, &ava->la_value );
3089 char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
3091 struct berval new_dn, parent_dn, newrdn;
3093 new_dn.bv_val = NULL;
3095 parent_dn.bv_val = (char *)dn;
3096 parent_dn.bv_len = strlen( dn );
3098 newrdn.bv_val = (char *)rdn;
3099 newrdn.bv_len = strlen( rdn );
3101 build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
3103 return new_dn.bv_val;
3106 int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
3110 char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
3111 size_t textlen = sizeof textbuf;
3112 int rc = LDAP_SUCCESS;
3114 PBLOCK_ASSERT_OP( pb, 0 );
3116 be_orig = pb->pb_op->o_bd;
3118 pb->pb_op->o_bd = select_backend( &e->e_nname, 0 );
3119 if ( pb->pb_op->o_bd != NULL ) {
3120 rc = entry_schema_check( pb->pb_op, e, NULL, 0, 0, NULL,
3121 &text, textbuf, textlen );
3123 pb->pb_op->o_bd = be_orig;
3125 return ( rc == LDAP_SUCCESS ) ? 0 : 1;
3128 int slapi_entry_rdn_values_present( const Slapi_Entry *e )
3132 int i = 0, match = 0;
3134 rc = ldap_bv2dn( &((Entry *)e)->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3135 if ( rc != LDAP_SUCCESS ) {
3139 if ( dn[0] != NULL ) {
3140 LDAPRDN rdn = dn[0];
3142 for ( i = 0; rdn[i] != NULL; i++ ) {
3143 LDAPAVA *ava = &rdn[0][i];
3144 Slapi_Attr *a = NULL;
3146 if ( slapi_entry_attr_find( (Slapi_Entry *)e, ava->la_attr.bv_val, &a ) == 0 &&
3147 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3154 return ( i == match );
3157 int slapi_entry_add_rdn_values( Slapi_Entry *e )
3162 rc = ldap_bv2dn( &e->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3163 if ( rc != LDAP_SUCCESS ) {
3167 if ( dn[0] != NULL ) {
3168 LDAPRDN rdn = dn[0];
3169 struct berval *vals[2];
3171 for ( i = 0; rdn[i] != NULL; i++ ) {
3172 LDAPAVA *ava = &rdn[0][i];
3173 Slapi_Attr *a = NULL;
3175 if ( slapi_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 &&
3176 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3179 vals[0] = &ava->la_value;
3182 slapi_entry_attr_merge( e, ava->la_attr.bv_val, vals );
3188 return LDAP_SUCCESS;
3191 const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
3195 attr = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
3196 if ( attr == NULL ) {
3200 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
3201 return slapi_value_get_string( &attr->a_vals[0] );
3207 void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
3211 attr_delete ( &e->e_attrs, slap_schema.si_ad_entryUUID );
3213 bv.bv_val = uniqueid;
3214 bv.bv_len = strlen( uniqueid );
3215 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, &bv, NULL );
3218 LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared )
3225 size = sizeof("ldap:///");
3229 size += strlen( ldaphost );
3230 if ( ldapport != 0 ) {
3234 url = slapi_ch_malloc( size );
3236 if ( ldapport != 0 ) {
3237 rc = snprintf( url, size, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
3239 rc = snprintf( url, size, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
3242 if ( rc > 0 && (size_t) rc < size ) {
3243 rc = ldap_initialize( &ld, url );
3248 slapi_ch_free_string( &url );
3250 return ( rc == LDAP_SUCCESS ) ? ld : NULL;
3253 void slapi_ldap_unbind( LDAP *ld )
3255 ldap_unbind_ext_s( ld, NULL, NULL );
3258 int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags )
3261 return LDAP_PARAM_ERROR;
3263 *flags = SLAP_DBFLAGS(be);
3265 return LDAP_SUCCESS;
3269 slapi_int_count_controls( LDAPControl **ctrls )
3273 if ( ctrls == NULL )
3276 for ( i = 0; ctrls[i] != NULL; i++ )
3283 slapi_op_abandoned( Slapi_PBlock *pb )
3285 if ( pb->pb_op == NULL )
3288 return ( pb->pb_op->o_abandon );
3292 slapi_op_type_to_string(unsigned long type)
3297 case SLAPI_OPERATION_BIND:
3300 case SLAPI_OPERATION_UNBIND:
3303 case SLAPI_OPERATION_SEARCH:
3306 case SLAPI_OPERATION_MODIFY:
3309 case SLAPI_OPERATION_ADD:
3312 case SLAPI_OPERATION_DELETE:
3315 case SLAPI_OPERATION_MODDN:
3318 case SLAPI_OPERATION_COMPARE:
3321 case SLAPI_OPERATION_ABANDON:
3324 case SLAPI_OPERATION_EXTENDED:
3328 str = "unknown operation type";
3335 slapi_op_get_type(Slapi_Operation * op)
3339 switch ( op->o_tag ) {
3341 type = SLAPI_OPERATION_BIND;
3343 case LDAP_REQ_UNBIND:
3344 type = SLAPI_OPERATION_UNBIND;
3346 case LDAP_REQ_SEARCH:
3347 type = SLAPI_OPERATION_SEARCH;
3349 case LDAP_REQ_MODIFY:
3350 type = SLAPI_OPERATION_MODIFY;
3353 type = SLAPI_OPERATION_ADD;
3355 case LDAP_REQ_DELETE:
3356 type = SLAPI_OPERATION_DELETE;
3358 case LDAP_REQ_MODRDN:
3359 type = SLAPI_OPERATION_MODDN;
3361 case LDAP_REQ_COMPARE:
3362 type = SLAPI_OPERATION_COMPARE;
3364 case LDAP_REQ_ABANDON:
3365 type = SLAPI_OPERATION_ABANDON;
3367 case LDAP_REQ_EXTENDED:
3368 type = SLAPI_OPERATION_EXTENDED;
3371 type = SLAPI_OPERATION_NONE;
3377 void slapi_be_set_readonly( Slapi_Backend *be, int readonly )
3383 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
3385 be->be_restrictops &= ~(SLAP_RESTRICT_OP_WRITES);
3388 int slapi_be_get_readonly( Slapi_Backend *be )
3393 return ( (be->be_restrictops & SLAP_RESTRICT_OP_WRITES) == SLAP_RESTRICT_OP_WRITES );
3396 const char *slapi_x_be_get_updatedn( Slapi_Backend *be )
3401 return be->be_update_ndn.bv_val;
3404 Slapi_Backend *slapi_be_select( const Slapi_DN *sdn )
3408 slapi_sdn_get_ndn( sdn );
3410 be = select_backend( (struct berval *)&sdn->ndn, 0 );
3417 slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag)
3422 slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag)
3427 slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag)
3432 #endif /* LDAP_SLAPI */