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,
77 int rc = LDAP_SUCCESS;
81 if ( bvptr == NULL || *bvptr == NULL ) {
85 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
89 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
90 if ( tmpberval == NULL ) {
91 return LDAP_NO_MEMORY;
94 for ( i = 0; bvptr[i] != NULL; i++ ) {
95 tmpberval[i].bv_val = bvptr[i]->bv_val;
96 tmpberval[i].bv_len = bvptr[i]->bv_len;
98 tmpberval[i].bv_val = NULL;
99 tmpberval[i].bv_len = 0;
101 if ( rc == LDAP_SUCCESS ) {
113 return str2entry( s );
124 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
125 s = entry2str( e, len );
127 ret = slapi_ch_strdup( s );
128 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
134 slapi_entry_get_dn( Slapi_Entry *e )
136 return e->e_name.bv_val;
140 slapi_x_entry_get_id( Slapi_Entry *e )
146 slapi_int_dn_pretty( struct berval *in, struct berval *out )
148 Syntax *syntax = slap_schema.si_syn_distinguishedName;
150 assert( syntax != NULL );
152 return (syntax->ssyn_pretty)( syntax, in, out, NULL );
156 slapi_int_dn_normalize( struct berval *in, struct berval *out )
158 MatchingRule *mr = slap_schema.si_mr_distinguishedNameMatch;
159 Syntax *syntax = slap_schema.si_syn_distinguishedName;
161 assert( mr != NULL );
163 return (mr->smr_normalize)( 0, syntax, mr, in, out, NULL );
171 struct berval dn = BER_BVNULL;
174 dn.bv_len = strlen( ldn );
176 slapi_int_dn_pretty( &dn, &e->e_name );
177 slapi_int_dn_normalize( &dn, &e->e_nname );
181 slapi_entry_dup( Slapi_Entry *e )
183 return entry_dup( e );
187 slapi_entry_attr_delete(
191 AttributeDescription *ad = NULL;
194 if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
195 return 1; /* LDAP_NO_SUCH_ATTRIBUTE */
198 if ( attr_delete( &e->e_attrs, ad ) == LDAP_SUCCESS ) {
199 return 0; /* attribute is deleted */
201 return -1; /* something went wrong */
206 slapi_entry_alloc( void )
208 return (Slapi_Entry *)entry_alloc();
212 slapi_entry_free( Slapi_Entry *e )
219 slapi_entry_attr_merge(
222 struct berval **vals )
224 AttributeDescription *ad = NULL;
229 rc = slap_str2ad( type, &ad, &text );
230 if ( rc != LDAP_SUCCESS ) {
234 rc = bvptr2obj( vals, &bv );
235 if ( rc != LDAP_SUCCESS ) {
239 rc = attr_merge_normalize_one( e, ad, bv, NULL );
246 slapi_entry_attr_find(
251 AttributeDescription *ad = NULL;
255 rc = slap_str2ad( type, &ad, &text );
256 if ( rc != LDAP_SUCCESS ) {
260 *attr = attr_find( e->e_attrs, ad );
261 if ( *attr == NULL ) {
269 slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
271 AttributeDescription *ad = NULL;
276 rc = slap_str2ad( type, &ad, &text );
277 if ( rc != LDAP_SUCCESS ) {
281 attr = attr_find( e->e_attrs, ad );
282 if ( attr == NULL ) {
286 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
289 p = slapi_value_get_string( &attr->a_vals[0] );
291 return slapi_ch_strdup( p );
299 slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
301 AttributeDescription *ad = NULL;
306 rc = slap_str2ad( type, &ad, &text );
307 if ( rc != LDAP_SUCCESS ) {
311 attr = attr_find( e->e_attrs, ad );
312 if ( attr == NULL ) {
316 return slapi_value_get_int( attr->a_vals );
320 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
322 AttributeDescription *ad = NULL;
327 rc = slap_str2ad( type, &ad, &text );
328 if ( rc != LDAP_SUCCESS ) {
332 attr = attr_find( e->e_attrs, ad );
333 if ( attr == NULL ) {
337 return slapi_value_get_long( attr->a_vals );
341 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
343 AttributeDescription *ad = NULL;
348 rc = slap_str2ad( type, &ad, &text );
349 if ( rc != LDAP_SUCCESS ) {
353 attr = attr_find( e->e_attrs, ad );
354 if ( attr == NULL ) {
358 return slapi_value_get_uint( attr->a_vals );
362 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
364 AttributeDescription *ad = NULL;
369 rc = slap_str2ad( type, &ad, &text );
370 if ( rc != LDAP_SUCCESS ) {
374 attr = attr_find( e->e_attrs, ad );
375 if ( attr == NULL ) {
379 return slapi_value_get_ulong( attr->a_vals );
383 slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
386 AttributeDescription *ad = NULL;
391 rc = slap_str2ad( type, &ad, &text );
392 if ( rc != LDAP_SUCCESS ) {
396 attr = attr_find( e->e_attrs, ad );
397 if ( attr == NULL ) {
401 bv.bv_val = (char *)value;
402 bv.bv_len = strlen( value );
404 return ( slapi_attr_value_find( attr, &bv ) != -1 );
408 slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value)
410 AttributeDescription *ad = NULL;
415 rc = slap_str2ad( type, &ad, &text );
416 if ( rc != LDAP_SUCCESS ) {
420 attr_delete ( &e->e_attrs, ad );
421 if ( value != NULL ) {
422 bv.bv_val = (char *)value;
423 bv.bv_len = strlen(value);
424 attr_merge_normalize_one( e, ad, &bv, NULL );
429 slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l)
433 snprintf( buf, sizeof( buf ), "%d", l );
434 slapi_entry_attr_set_charptr( e, type, buf );
438 slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l)
442 snprintf( buf, sizeof( buf ), "%u", l );
443 slapi_entry_attr_set_charptr( e, type, buf );
447 slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l)
451 snprintf( buf, sizeof( buf ), "%ld", l );
452 slapi_entry_attr_set_charptr( e, type, buf );
456 slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l)
460 snprintf( buf, sizeof( buf ), "%lu", l );
461 slapi_entry_attr_set_charptr( e, type, buf );
465 slapi_is_rootdse( const char *dn )
467 return ( dn == NULL || dn[0] == '\0' );
471 slapi_entry_has_children( const Slapi_Entry *e )
474 int hasSubordinates = 0;
476 pb = slapi_pblock_new();
477 slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
479 slapi_pblock_set( pb, SLAPI_TARGET_DN, slapi_entry_get_dn( (Entry *)e ) );
481 pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0 );
482 if ( pb->pb_op->o_bd != NULL ) {
483 pb->pb_op->o_bd->be_has_subordinates( pb->pb_op, (Entry *)e, &hasSubordinates );
486 slapi_pblock_destroy( pb );
488 return ( hasSubordinates == LDAP_COMPARE_TRUE );
492 * Return approximate size of the entry rounded to the nearest
493 * 1K. Only the size of the attribute values are counted in the
494 * Sun implementation.
496 * http://docs.sun.com/source/816-6701-10/funcref.html#1017388
498 size_t slapi_entry_size(Slapi_Entry *e)
504 for ( size = 0, a = e->e_attrs; a != NULL; a = a->a_next ) {
505 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
506 size += a->a_vals[i].bv_len + 1;
511 size -= (size % 1024);
517 * Add values to entry.
520 * LDAP_SUCCESS Values added to entry
521 * LDAP_TYPE_OR_VALUE_EXISTS One or more values exist in entry already
522 * LDAP_CONSTRAINT_VIOLATION Any other error (odd, but it's the spec)
525 slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
530 char textbuf[SLAP_TEXT_BUFLEN];
532 mod.sm_op = LDAP_MOD_ADD;
535 mod.sm_type.bv_val = (char *)type;
536 mod.sm_type.bv_len = strlen( type );
538 rc = slap_str2ad( type, &mod.sm_desc, &text );
539 if ( rc != LDAP_SUCCESS ) {
543 if ( vals == NULL ) {
544 /* Apparently vals can be NULL
545 * FIXME: sm_values = NULL ? */
546 mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) );
547 mod.sm_values->bv_val = NULL;
550 rc = bvptr2obj( vals, &mod.sm_values );
551 if ( rc != LDAP_SUCCESS ) {
552 return LDAP_CONSTRAINT_VIOLATION;
555 mod.sm_nvalues = NULL;
557 rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
559 slapi_ch_free( (void **)&mod.sm_values );
561 return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
565 slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
567 return slapi_entry_add_values( e, type, vals );
571 slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
573 AttributeDescription *ad = NULL;
577 rc = slap_str2ad( type, &ad, &text );
578 if ( rc != LDAP_SUCCESS ) {
582 return attr_merge_normalize( e, ad, *vs, NULL );
586 slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **vals )
591 char textbuf[SLAP_TEXT_BUFLEN];
593 mod.sm_op = LDAP_MOD_DELETE;
596 mod.sm_type.bv_val = (char *)type;
597 mod.sm_type.bv_len = strlen( type );
599 if ( vals == NULL ) {
600 /* If vals is NULL, this is a NOOP. */
604 rc = slap_str2ad( type, &mod.sm_desc, &text );
605 if ( rc != LDAP_SUCCESS ) {
609 if ( vals[0] == NULL ) {
610 /* SLAPI doco says LDApb_opERATIONS_ERROR but LDAP_OTHER is better */
611 return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
614 rc = bvptr2obj( vals, &mod.sm_values );
615 if ( rc != LDAP_SUCCESS ) {
616 return LDAP_CONSTRAINT_VIOLATION;
618 mod.sm_nvalues = NULL;
620 rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
622 slapi_ch_free( (void **)&mod.sm_values );
628 slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
630 return slapi_entry_delete_values( e, type, vals );
634 slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
636 return slapi_entry_attr_merge( e, (char *)type, vals );
640 slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value)
642 AttributeDescription *ad = NULL;
646 rc = slap_str2ad( type, &ad, &text );
647 if ( rc != LDAP_SUCCESS ) {
651 rc = attr_merge_normalize_one( e, ad, (Slapi_Value *)value, NULL );
652 if ( rc != LDAP_SUCCESS ) {
660 slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
664 val.bv_val = (char *)value;
665 val.bv_len = strlen( value );
667 return slapi_entry_add_value( e, type, &val );
671 slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
673 Slapi_Value *vals[2];
676 val.bv_val = (char *)value;
677 val.bv_len = strlen( value );
681 return slapi_entry_delete_values_sv( e, type, vals );
685 slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
687 return slapi_entry_attr_merge( e, (char *)type, vals );
691 slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
699 return ( *attr != NULL ) ? 0 : -1;
703 slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr )
709 if ( prevattr == NULL ) {
713 *attr = prevattr->a_next;
715 return ( *attr != NULL ) ? 0 : -1;
719 slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
721 AttributeDescription *ad = NULL;
726 rc = slap_str2ad( type, &ad, &text );
727 if ( rc != LDAP_SUCCESS ) {
731 attr_delete( &e->e_attrs, ad );
733 rc = bvptr2obj( vals, &bv );
734 if ( rc != LDAP_SUCCESS ) {
738 rc = attr_merge_normalize( e, ad, bv, NULL );
739 slapi_ch_free( (void **)&bv );
740 if ( rc != LDAP_SUCCESS ) {
748 * FIXME -- The caller must free the allocated memory.
749 * In Netscape they do not have to.
752 slapi_attr_get_values(
754 struct berval ***vals )
759 if ( attr == NULL ) {
763 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
767 bv = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
768 for ( j = 0; j < i; j++ ) {
769 bv[j] = ber_dupbv( NULL, &attr->a_vals[j] );
773 *vals = (struct berval **)bv;
779 slapi_dn_normalize( char *dn )
784 assert( dn != NULL );
787 bdn.bv_len = strlen( dn );
789 if ( slapi_int_dn_pretty( &bdn, &pdn ) != LDAP_SUCCESS ) {
797 slapi_dn_normalize_case( char *dn )
802 assert( dn != NULL );
805 bdn.bv_len = strlen( dn );
807 if ( slapi_int_dn_normalize( &bdn, &ndn ) != LDAP_SUCCESS ) {
819 struct berval bdn, ndn;
820 struct berval bsuffix, nsuffix;
823 assert( dn != NULL );
824 assert( suffix != NULL );
827 bdn.bv_len = strlen( dn );
829 bsuffix.bv_val = suffix;
830 bsuffix.bv_len = strlen( suffix );
832 if ( dnNormalize( 0, NULL, NULL, &bdn, &ndn, NULL ) != LDAP_SUCCESS ) {
836 if ( dnNormalize( 0, NULL, NULL, &bsuffix, &nsuffix, NULL )
839 slapi_ch_free( (void **)&ndn.bv_val );
843 rc = dnIsSuffix( &ndn, &nsuffix );
845 slapi_ch_free( (void **)&ndn.bv_val );
846 slapi_ch_free( (void **)&nsuffix.bv_val );
853 const char *parentdn,
854 const char *childdn )
856 struct berval assertedParentDN, normalizedAssertedParentDN;
857 struct berval childDN, normalizedChildDN;
858 struct berval normalizedParentDN;
861 assert( parentdn != NULL );
862 assert( childdn != NULL );
864 assertedParentDN.bv_val = (char *)parentdn;
865 assertedParentDN.bv_len = strlen( parentdn );
867 if ( dnNormalize( 0, NULL, NULL, &assertedParentDN,
868 &normalizedAssertedParentDN, NULL ) != LDAP_SUCCESS )
873 childDN.bv_val = (char *)childdn;
874 childDN.bv_len = strlen( childdn );
876 if ( dnNormalize( 0, NULL, NULL, &childDN,
877 &normalizedChildDN, NULL ) != LDAP_SUCCESS )
879 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
883 dnParent( &normalizedChildDN, &normalizedParentDN );
885 if ( dnMatch( &match, 0, slap_schema.si_syn_distinguishedName, NULL,
886 &normalizedParentDN, (void *)&normalizedAssertedParentDN ) != LDAP_SUCCESS )
891 slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val );
892 slapi_ch_free( (void **)&normalizedChildDN.bv_val );
894 return ( match == 0 );
898 * Returns DN of the parent entry, or NULL if the DN is
899 * an empty string or NULL, or has no parent.
902 slapi_dn_parent( const char *_dn )
904 struct berval dn, prettyDN;
905 struct berval parentDN;
912 dn.bv_val = (char *)_dn;
913 dn.bv_len = strlen( _dn );
915 if ( dn.bv_len == 0 ) {
919 if ( dnPretty( NULL, &dn, &prettyDN, NULL ) != LDAP_SUCCESS ) {
923 dnParent( &prettyDN, &parentDN ); /* in-place */
925 if ( parentDN.bv_len == 0 ) {
926 slapi_ch_free_string( &prettyDN.bv_val );
930 ret = slapi_ch_strdup( parentDN.bv_val );
931 slapi_ch_free_string( &prettyDN.bv_val );
936 int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *ldn )
941 if ( slapi_is_rootdse( ldn ) ) {
945 /* according to spec should already be normalized */
946 ndn.bv_len = strlen( ldn );
949 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
954 return be_issuffix( be, &ndn );
958 * Returns DN of the parent entry; or NULL if the DN is
959 * an empty string, if the DN has no parent, or if the
960 * DN is the suffix of the backend database
962 char *slapi_dn_beparent( Slapi_PBlock *pb, const char *ldn )
965 struct berval dn, prettyDN;
966 struct berval normalizedDN, parentDN;
973 PBLOCK_ASSERT_OP( pb, 0 );
975 if ( slapi_is_rootdse( ldn ) ) {
979 dn.bv_val = (char *)ldn;
980 dn.bv_len = strlen( ldn );
982 if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) {
986 be = select_backend( &pb->pb_op->o_req_ndn, 0 );
988 if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) {
989 dnParent( &prettyDN, &parentDN );
991 if ( parentDN.bv_len != 0 )
992 parent = slapi_ch_strdup( parentDN.bv_val );
995 slapi_ch_free_string( &prettyDN.bv_val );
996 slapi_ch_free_string( &normalizedDN.bv_val );
1002 slapi_dn_ignore_case( char *dn )
1004 return slapi_dn_normalize_case( dn );
1008 slapi_ch_malloc( unsigned long size )
1010 return ch_malloc( size );
1014 slapi_ch_free( void **ptr )
1016 if ( ptr == NULL || *ptr == NULL )
1023 slapi_ch_free_string( char **ptr )
1025 slapi_ch_free( (void **)ptr );
1029 slapi_ch_array_free( char **arrayp )
1033 if ( arrayp != NULL ) {
1034 for ( p = arrayp; *p != NULL; p++ ) {
1035 slapi_ch_free( (void **)p );
1037 slapi_ch_free( (void **)&arrayp );
1042 slapi_ch_bvdup(const struct berval *v)
1044 return ber_dupbv(NULL, (struct berval *)v);
1048 slapi_ch_bvecdup(const struct berval **v)
1057 for ( i = 0; v[i] != NULL; i++ )
1060 rv = (struct berval **) slapi_ch_malloc( (i + 1) * sizeof(struct berval *) );
1062 for ( i = 0; v[i] != NULL; i++ ) {
1063 rv[i] = slapi_ch_bvdup( v[i] );
1072 unsigned long nelem,
1073 unsigned long size )
1075 return ch_calloc( nelem, size );
1081 unsigned long size )
1083 return ch_realloc( block, size );
1087 slapi_ch_strdup( const char *s )
1089 return ch_strdup( s );
1093 slapi_ch_stlen( const char *s )
1099 slapi_control_present(
1100 LDAPControl **controls,
1102 struct berval **val,
1116 for ( i = 0; controls != NULL && controls[i] != NULL; i++ ) {
1117 if ( strcmp( controls[i]->ldctl_oid, oid ) != 0 ) {
1122 if ( controls[i]->ldctl_value.bv_len != 0 ) {
1124 *val = &controls[i]->ldctl_value;
1129 *iscritical = controls[i]->ldctl_iscritical;
1139 slapControlMask2SlapiControlOp(slap_mask_t slap_mask,
1140 unsigned long *slapi_mask)
1142 *slapi_mask = SLAPI_OPERATION_NONE;
1144 if ( slap_mask & SLAP_CTRL_ABANDON )
1145 *slapi_mask |= SLAPI_OPERATION_ABANDON;
1147 if ( slap_mask & SLAP_CTRL_ADD )
1148 *slapi_mask |= SLAPI_OPERATION_ADD;
1150 if ( slap_mask & SLAP_CTRL_BIND )
1151 *slapi_mask |= SLAPI_OPERATION_BIND;
1153 if ( slap_mask & SLAP_CTRL_COMPARE )
1154 *slapi_mask |= SLAPI_OPERATION_COMPARE;
1156 if ( slap_mask & SLAP_CTRL_DELETE )
1157 *slapi_mask |= SLAPI_OPERATION_DELETE;
1159 if ( slap_mask & SLAP_CTRL_MODIFY )
1160 *slapi_mask |= SLAPI_OPERATION_MODIFY;
1162 if ( slap_mask & SLAP_CTRL_RENAME )
1163 *slapi_mask |= SLAPI_OPERATION_MODDN;
1165 if ( slap_mask & SLAP_CTRL_SEARCH )
1166 *slapi_mask |= SLAPI_OPERATION_SEARCH;
1168 if ( slap_mask & SLAP_CTRL_UNBIND )
1169 *slapi_mask |= SLAPI_OPERATION_UNBIND;
1173 slapiControlOp2SlapControlMask(unsigned long slapi_mask,
1174 slap_mask_t *slap_mask)
1178 if ( slapi_mask & SLAPI_OPERATION_BIND )
1179 *slap_mask |= SLAP_CTRL_BIND;
1181 if ( slapi_mask & SLAPI_OPERATION_UNBIND )
1182 *slap_mask |= SLAP_CTRL_UNBIND;
1184 if ( slapi_mask & SLAPI_OPERATION_SEARCH )
1185 *slap_mask |= SLAP_CTRL_SEARCH;
1187 if ( slapi_mask & SLAPI_OPERATION_MODIFY )
1188 *slap_mask |= SLAP_CTRL_MODIFY;
1190 if ( slapi_mask & SLAPI_OPERATION_ADD )
1191 *slap_mask |= SLAP_CTRL_ADD;
1193 if ( slapi_mask & SLAPI_OPERATION_DELETE )
1194 *slap_mask |= SLAP_CTRL_DELETE;
1196 if ( slapi_mask & SLAPI_OPERATION_MODDN )
1197 *slap_mask |= SLAP_CTRL_RENAME;
1199 if ( slapi_mask & SLAPI_OPERATION_COMPARE )
1200 *slap_mask |= SLAP_CTRL_COMPARE;
1202 if ( slapi_mask & SLAPI_OPERATION_ABANDON )
1203 *slap_mask |= SLAP_CTRL_ABANDON;
1205 *slap_mask |= SLAP_CTRL_GLOBAL;
1209 slapi_int_parse_control(
1214 /* Plugins must deal with controls themselves. */
1216 return LDAP_SUCCESS;
1220 slapi_register_supported_control(
1222 unsigned long controlops )
1224 slap_mask_t controlmask;
1226 slapiControlOp2SlapControlMask( controlops, &controlmask );
1228 register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control, NULL );
1232 slapi_get_supported_controls(
1234 unsigned long **ctrlopsp )
1238 rc = get_supported_controls( ctrloidsp, (slap_mask_t **)ctrlopsp );
1239 if ( rc != LDAP_SUCCESS ) {
1243 for ( i = 0; (*ctrloidsp)[i] != NULL; i++ ) {
1244 /* In place, naughty. */
1245 slapControlMask2SlapiControlOp( (*ctrlopsp)[i], &((*ctrlopsp)[i]) );
1248 return LDAP_SUCCESS;
1252 slapi_dup_control( LDAPControl *ctrl )
1256 ret = (LDAPControl *)slapi_ch_malloc( sizeof(*ret) );
1257 ret->ldctl_oid = slapi_ch_strdup( ctrl->ldctl_oid );
1258 ber_dupbv( &ret->ldctl_value, &ctrl->ldctl_value );
1259 ret->ldctl_iscritical = ctrl->ldctl_iscritical;
1265 slapi_register_supported_saslmechanism( char *mechanism )
1267 /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */
1268 slapi_log_error( SLAPI_LOG_FATAL, "slapi_register_supported_saslmechanism",
1269 "OpenLDAP does not support dynamic registration of SASL mechanisms\n" );
1273 slapi_get_supported_saslmechanisms( void )
1275 /* FIXME -- can not get the saslmechanism without a connection. */
1276 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_supported_saslmechanisms",
1277 "can not get the SASL mechanism list "
1278 "without a connection\n" );
1283 slapi_get_supported_extended_ops( void )
1286 char **ppExtOpOID = NULL;
1289 for ( i = 0; get_supported_extop( i ) != NULL; i++ ) {
1293 for ( j = 0; slapi_int_get_supported_extop( j ) != NULL; j++ ) {
1298 if ( numExtOps == 0 ) {
1302 ppExtOpOID = (char **)slapi_ch_malloc( (numExtOps + 1) * sizeof(char *) );
1303 for ( k = 0; k < i; k++ ) {
1306 bv = get_supported_extop( k );
1307 assert( bv != NULL );
1309 ppExtOpOID[ k ] = bv->bv_val;
1312 for ( ; k < j; k++ ) {
1315 bv = slapi_int_get_supported_extop( k );
1316 assert( bv != NULL );
1318 ppExtOpOID[ i + k ] = bv->bv_val;
1320 ppExtOpOID[ i + k ] = NULL;
1326 slapi_send_ldap_result(
1332 struct berval **urls )
1336 PBLOCK_ASSERT_OP( pb, 0 );
1341 rs->sr_matched = matched;
1345 if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
1346 send_ldap_sasl( pb->pb_op, rs );
1347 } else if ( rs->sr_rspoid != NULL ) {
1348 send_ldap_extended( pb->pb_op, rs );
1350 if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
1351 rs->sr_nentries = nentries;
1353 bvptr2obj( urls, &rs->sr_ref );
1355 send_ldap_result( pb->pb_op, rs );
1358 slapi_ch_free( (void **)&rs->sr_ref );
1363 slapi_send_ldap_search_entry(
1366 LDAPControl **ectrls,
1370 SlapReply rs = { REP_SEARCH };
1372 AttributeName *an = NULL;
1376 assert( pb->pb_op != NULL );
1378 if ( attrs != NULL ) {
1379 for ( i = 0; attrs[ i ] != NULL; i++ ) {
1385 an = (AttributeName *) slapi_ch_calloc( i + 1, sizeof(AttributeName) );
1386 for ( i = 0; attrs[i] != NULL; i++ ) {
1387 an[j].an_name.bv_val = attrs[i];
1388 an[j].an_name.bv_len = strlen( attrs[i] );
1389 an[j].an_desc = NULL;
1390 if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &text ) == LDAP_SUCCESS) {
1394 an[j].an_name.bv_len = 0;
1395 an[j].an_name.bv_val = NULL;
1398 rs.sr_err = LDAP_SUCCESS;
1399 rs.sr_matched = NULL;
1402 rs.sr_ctrls = ectrls;
1404 rs.sr_operational_attrs = NULL;
1409 rc = send_search_entry( pb->pb_op, &rs );
1411 slapi_ch_free( (void **)&an );
1417 slapi_send_ldap_search_reference(
1420 struct berval **references,
1421 LDAPControl **ectrls,
1422 struct berval **v2refs
1425 SlapReply rs = { REP_SEARCHREF };
1428 rs.sr_err = LDAP_SUCCESS;
1429 rs.sr_matched = NULL;
1432 rc = bvptr2obj( references, &rs.sr_ref );
1433 if ( rc != LDAP_SUCCESS ) {
1437 rs.sr_ctrls = ectrls;
1439 rs.sr_operational_attrs = NULL;
1442 if ( v2refs != NULL ) {
1443 rc = bvptr2obj( v2refs, &rs.sr_v2ref );
1444 if ( rc != LDAP_SUCCESS ) {
1445 slapi_ch_free( (void **)&rs.sr_ref );
1452 rc = send_search_reference( pb->pb_op, &rs );
1454 slapi_ch_free( (void **)&rs.sr_ref );
1455 slapi_ch_free( (void **)&rs.sr_v2ref );
1461 slapi_str2filter( char *str )
1463 return str2filter( str );
1475 slapi_filter_dup( Slapi_Filter *filter )
1477 return filter_dup( filter, NULL );
1481 slapi_filter_get_choice( Slapi_Filter *f )
1495 slapi_filter_get_ava(
1498 struct berval **bval )
1501 int rc = LDAP_SUCCESS;
1503 assert( type != NULL );
1504 assert( bval != NULL );
1509 ftype = f->f_choice;
1510 if ( ftype == LDAP_FILTER_EQUALITY
1511 || ftype == LDAP_FILTER_GE
1512 || ftype == LDAP_FILTER_LE
1513 || ftype == LDAP_FILTER_APPROX ) {
1515 * According to the SLAPI Reference Manual these are
1518 *type = f->f_un.f_un_ava->aa_desc->ad_cname.bv_val;
1519 *bval = &f->f_un.f_un_ava->aa_value;
1520 } else { /* filter type not supported */
1528 slapi_filter_list_first( Slapi_Filter *f )
1536 ftype = f->f_choice;
1537 if ( ftype == LDAP_FILTER_AND
1538 || ftype == LDAP_FILTER_OR
1539 || ftype == LDAP_FILTER_NOT ) {
1540 return (Slapi_Filter *)f->f_list;
1547 slapi_filter_list_next(
1549 Slapi_Filter *fprev )
1557 ftype = f->f_choice;
1558 if ( ftype == LDAP_FILTER_AND
1559 || ftype == LDAP_FILTER_OR
1560 || ftype == LDAP_FILTER_NOT )
1562 return fprev->f_next;
1569 slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
1575 switch ( f->f_choice ) {
1576 case LDAP_FILTER_GE:
1577 case LDAP_FILTER_LE:
1578 case LDAP_FILTER_EQUALITY:
1579 case LDAP_FILTER_APPROX:
1580 *type = f->f_av_desc->ad_cname.bv_val;
1582 case LDAP_FILTER_SUBSTRINGS:
1583 *type = f->f_sub_desc->ad_cname.bv_val;
1585 case LDAP_FILTER_PRESENT:
1586 *type = f->f_desc->ad_cname.bv_val;
1588 case LDAP_FILTER_EXT:
1589 *type = f->f_mr_desc->ad_cname.bv_val;
1592 /* Complex filters need not apply. */
1601 slapi_x_filter_set_attribute_type( Slapi_Filter *f, const char *type )
1603 AttributeDescription **adp, *ad = NULL;
1611 switch ( f->f_choice ) {
1612 case LDAP_FILTER_GE:
1613 case LDAP_FILTER_LE:
1614 case LDAP_FILTER_EQUALITY:
1615 case LDAP_FILTER_APPROX:
1616 adp = &f->f_av_desc;
1618 case LDAP_FILTER_SUBSTRINGS:
1619 adp = &f->f_sub_desc;
1621 case LDAP_FILTER_PRESENT:
1624 case LDAP_FILTER_EXT:
1625 adp = &f->f_mr_desc;
1628 /* Complex filters need not apply. */
1632 rc = slap_str2ad( type, &ad, &text );
1633 if ( rc == LDAP_SUCCESS )
1636 return ( rc == LDAP_SUCCESS ) ? 0 : -1;
1640 slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
1641 char ***any, char **final )
1645 if ( f->f_choice != LDAP_FILTER_SUBSTRINGS ) {
1650 * The caller shouldn't free but we can't return an
1651 * array of char *s from an array of bervals without
1652 * allocating memory, so we may as well be consistent.
1655 *type = f->f_sub_desc->ad_cname.bv_val;
1656 *initial = f->f_sub_initial.bv_val ? slapi_ch_strdup(f->f_sub_initial.bv_val) : NULL;
1657 if ( f->f_sub_any != NULL ) {
1658 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ )
1660 *any = (char **)slapi_ch_malloc( (i + 1) * sizeof(char *) );
1661 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
1662 (*any)[i] = slapi_ch_strdup(f->f_sub_any[i].bv_val);
1668 *final = f->f_sub_final.bv_val ? slapi_ch_strdup(f->f_sub_final.bv_val) : NULL;
1674 slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 )
1676 Slapi_Filter *f = NULL;
1678 if ( ftype == LDAP_FILTER_AND ||
1679 ftype == LDAP_FILTER_OR ||
1680 ftype == LDAP_FILTER_NOT )
1682 f = (Slapi_Filter *)slapi_ch_malloc( sizeof(*f) );
1683 f->f_choice = ftype;
1685 f->f_list->f_next = f2;
1693 slapi_x_filter_append( int ftype,
1694 Slapi_Filter **pContainingFilter, /* NULL on first call */
1695 Slapi_Filter **pNextFilter,
1696 Slapi_Filter *filterToAppend )
1698 if ( ftype == LDAP_FILTER_AND ||
1699 ftype == LDAP_FILTER_OR ||
1700 ftype == LDAP_FILTER_NOT )
1702 if ( *pContainingFilter == NULL ) {
1703 *pContainingFilter = (Slapi_Filter *)slapi_ch_malloc( sizeof(Slapi_Filter) );
1704 (*pContainingFilter)->f_choice = ftype;
1705 (*pContainingFilter)->f_list = filterToAppend;
1706 (*pContainingFilter)->f_next = NULL;
1708 if ( (*pContainingFilter)->f_choice != ftype ) {
1712 (*pNextFilter)->f_next = filterToAppend;
1714 *pNextFilter = filterToAppend;
1722 slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
1729 /* spec says return zero if no filter. */
1733 if ( verify_access ) {
1736 return LDAP_PARAM_ERROR;
1742 * According to acl.c it is safe to call test_filter() with
1745 rc = test_filter( op, e, f );
1747 case LDAP_COMPARE_TRUE:
1750 case LDAP_COMPARE_FALSE:
1752 case SLAPD_COMPARE_UNDEFINED:
1755 case LDAP_PROTOCOL_ERROR:
1756 /* filter type unknown: spec says return -1 */
1765 slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f)
1767 return slapi_filter_test( NULL, e, f, 0 );
1771 slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code )
1773 switch ( f->f_choice ) {
1774 case LDAP_FILTER_AND:
1775 case LDAP_FILTER_NOT:
1776 case LDAP_FILTER_OR: {
1780 * FIXME: altering f; should we use a temporary?
1782 for ( f = f->f_list; f != NULL; f = f->f_next ) {
1783 rc = slapi_filter_apply( f, fn, arg, error_code );
1787 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ) {
1793 case LDAP_FILTER_EQUALITY:
1794 case LDAP_FILTER_SUBSTRINGS:
1795 case LDAP_FILTER_GE:
1796 case LDAP_FILTER_LE:
1797 case LDAP_FILTER_PRESENT:
1798 case LDAP_FILTER_APPROX:
1799 case LDAP_FILTER_EXT:
1800 *error_code = fn( f, arg );
1803 *error_code = SLAPI_FILTER_UNKNOWN_FILTER_TYPE;
1806 if ( *error_code == SLAPI_FILTER_SCAN_NOMORE ||
1807 *error_code == SLAPI_FILTER_SCAN_CONTINUE ) {
1816 struct berval **vals,
1820 * FIXME: what's the point?
1825 #define MAX_HOSTNAME 512
1828 slapi_get_hostname( void )
1831 static int been_here = 0;
1832 static char *static_hn = NULL;
1834 ldap_pvt_thread_mutex_lock( &slapi_hn_mutex );
1836 static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
1837 if ( static_hn == NULL) {
1838 slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_hostname",
1839 "Cannot allocate memory for hostname\n" );
1841 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1846 if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) {
1847 slapi_log_error( SLAPI_LOG_FATAL,
1849 "can't get hostname\n" );
1850 slapi_ch_free( (void **)&static_hn );
1852 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1861 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1863 hn = ch_strdup( static_hn );
1869 * FIXME: this should go in an appropriate header ...
1871 extern int slapi_int_log_error( int level, char *subsystem, char *fmt, va_list arglist );
1880 int rc = LDAP_SUCCESS;
1883 va_start( arglist, fmt );
1884 rc = slapi_int_log_error( severity, subsystem, fmt, arglist );
1892 slapi_timer_current_time( void )
1894 static int first_time = 1;
1895 #if !defined (_WIN32)
1899 ldap_pvt_thread_mutex_lock( &slapi_time_mutex );
1902 gettimeofday( &base_time, NULL );
1904 gettimeofday( &now, NULL );
1905 ret = ( now.tv_sec - base_time.tv_sec ) * 1000000 +
1906 (now.tv_usec - base_time.tv_usec);
1907 ldap_pvt_thread_mutex_unlock( &slapi_time_mutex );
1913 return (slap_get_time() - starttime) * 1000000;
1920 performance_counter_present = QueryPerformanceCounter( &base_time );
1921 QueryPerformanceFrequency( &performance_freq );
1924 if ( !performance_counter_present )
1927 QueryPerformanceCounter( &now );
1928 return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
1936 slapi_timer_get_time( char *label )
1938 unsigned long start = slapi_timer_current_time();
1939 printf("%10ld %10d usec %s\n", start, 0, label);
1947 slapi_timer_elapsed_time(
1949 unsigned long start )
1951 unsigned long stop = slapi_timer_current_time();
1952 printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
1956 slapi_free_search_results_internal( Slapi_PBlock *pb )
1958 Slapi_Entry **entries;
1959 int k = 0, nEnt = 0;
1961 slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
1962 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
1963 if ( nEnt == 0 || entries == NULL ) {
1967 for ( k = 0; k < nEnt; k++ ) {
1968 slapi_entry_free( entries[k] );
1972 slapi_ch_free( (void **)&entries );
1975 int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
1978 return LDAP_PARAM_ERROR;
1980 if ( pb->pb_conn == NULL )
1981 return LDAP_PARAM_ERROR;
1984 *isSSL = pb->pb_conn->c_is_tls;
1989 return LDAP_SUCCESS;
1993 * DS 5.x compatability API follow
1996 int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
2001 return LDAP_PARAM_ERROR;
2003 at = attr->a_desc->ad_type;
2005 *flags = SLAPI_ATTR_FLAG_STD_ATTR;
2007 if ( is_at_single_value( at ) )
2008 *flags |= SLAPI_ATTR_FLAG_SINGLE;
2009 if ( is_at_operational( at ) )
2010 *flags |= SLAPI_ATTR_FLAG_OPATTR;
2011 if ( is_at_obsolete( at ) )
2012 *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
2013 if ( is_at_collective( at ) )
2014 *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
2015 if ( is_at_no_user_mod( at ) )
2016 *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
2018 return LDAP_SUCCESS;
2021 int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
2023 unsigned long flags;
2025 if ( slapi_attr_get_flags( attr, &flags ) != 0 )
2027 return (flags & flag) ? 1 : 0;
2030 Slapi_Attr *slapi_attr_new( void )
2034 ad = (Attribute *)slapi_ch_calloc( 1, sizeof(*ad) );
2039 Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
2042 AttributeDescription *ad = NULL;
2044 if( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
2057 void slapi_attr_free( Slapi_Attr **a )
2063 Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
2065 return attr_dup( (Slapi_Attr *)attr );
2068 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
2071 struct berval *nvalp;
2073 AttributeDescription *desc = a->a_desc;
2075 if ( desc->ad_type->sat_equality &&
2076 desc->ad_type->sat_equality->smr_normalize ) {
2077 rc = (*desc->ad_type->sat_equality->smr_normalize)(
2078 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
2079 desc->ad_type->sat_syntax,
2080 desc->ad_type->sat_equality,
2081 (Slapi_Value *)v, &nval, NULL );
2082 if ( rc != LDAP_SUCCESS ) {
2090 rc = value_add_one( &a->a_vals, (Slapi_Value *)v );
2091 if ( rc == 0 && nvalp != NULL ) {
2092 rc = value_add_one( &a->a_nvals, nvalp );
2094 a->a_nvals = a->a_vals;
2097 if ( nvalp != NULL ) {
2098 slapi_ch_free_string( &nval.bv_val );
2104 int slapi_attr_type2plugin( const char *type, void **pi )
2111 int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
2113 if ( attr == NULL ) {
2114 return LDAP_PARAM_ERROR;
2117 *type = attr->a_desc->ad_cname.bv_val;
2119 return LDAP_SUCCESS;
2122 int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp )
2124 if ( attr == NULL ) {
2125 return LDAP_PARAM_ERROR;
2127 *oidp = attr->a_desc->ad_type->sat_oid;
2129 return LDAP_SUCCESS;
2132 int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
2139 mr = a->a_desc->ad_type->sat_equality;
2140 rc = value_match( &ret, a->a_desc, mr,
2141 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
2142 (struct berval *)v1, (void *)v2, &text );
2143 if ( rc != LDAP_SUCCESS )
2146 return ( ret == 0 ) ? 0 : -1;
2149 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
2158 if ( a ->a_vals == NULL ) {
2161 mr = a->a_desc->ad_type->sat_equality;
2162 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
2163 rc = value_match( &ret, a->a_desc, mr,
2164 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, bv, v, &text );
2165 if ( rc != LDAP_SUCCESS ) {
2175 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
2177 AttributeDescription *a1 = NULL;
2178 AttributeDescription *a2 = NULL;
2182 if ( slap_str2ad( t1, &a1, &text ) != LDAP_SUCCESS ) {
2186 if ( slap_str2ad( t2, &a2, &text ) != LDAP_SUCCESS ) {
2190 #define ad_base_cmp(l,r) (((l)->ad_type->sat_cname.bv_len < (r)->ad_type->sat_cname.bv_len) \
2191 ? -1 : (((l)->ad_type->sat_cname.bv_len > (r)->ad_type->sat_cname.bv_len) \
2192 ? 1 : strcasecmp((l)->ad_type->sat_cname.bv_val, (r)->ad_type->sat_cname.bv_val )))
2195 case SLAPI_TYPE_CMP_EXACT:
2196 ret = ad_cmp( a1, a2 );
2198 case SLAPI_TYPE_CMP_BASE:
2199 ret = ad_base_cmp( a1, a2 );
2201 case SLAPI_TYPE_CMP_SUBTYPE:
2202 ret = is_ad_subtype( a2, a2 );
2212 int slapi_attr_types_equivalent( const char *t1, const char *t2 )
2214 return ( slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT ) == 0 );
2217 int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v )
2219 return slapi_valueset_first_value( &a->a_vals, v );
2222 int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v )
2224 return slapi_valueset_next_value( &a->a_vals, hint, v );
2227 int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues )
2229 *numValues = slapi_valueset_count( &a->a_vals );
2234 int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs )
2236 *vs = &((Slapi_Attr *)a)->a_vals;
2241 int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals )
2243 return slapi_attr_get_values( a, vals );
2246 char *slapi_attr_syntax_normalize( const char *s )
2248 AttributeDescription *ad = NULL;
2251 if ( slap_str2ad( s, &ad, &text ) != LDAP_SUCCESS ) {
2255 return ad->ad_cname.bv_val;
2258 Slapi_Value *slapi_value_new( void )
2262 bv = (struct berval *)slapi_ch_malloc( sizeof(*bv) );
2267 Slapi_Value *slapi_value_new_berval(const struct berval *bval)
2269 return ber_dupbv( NULL, (struct berval *)bval );
2272 Slapi_Value *slapi_value_new_value(const Slapi_Value *v)
2274 return slapi_value_new_berval( v );
2277 Slapi_Value *slapi_value_new_string(const char *s)
2281 bv.bv_val = (char *)s;
2282 bv.bv_len = strlen( s );
2284 return slapi_value_new_berval( &bv );
2287 Slapi_Value *slapi_value_init(Slapi_Value *val)
2295 Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval)
2297 return ber_dupbv( v, bval );
2300 Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
2302 v->bv_val = slapi_ch_strdup( s );
2303 v->bv_len = strlen( s );
2308 Slapi_Value *slapi_value_dup(const Slapi_Value *v)
2310 return slapi_value_new_value( v );
2313 void slapi_value_free(Slapi_Value **value)
2315 if ( value == NULL ) {
2319 if ( (*value) != NULL ) {
2320 slapi_ch_free( (void **)&(*value)->bv_val );
2321 slapi_ch_free( (void **)value );
2325 const struct berval *slapi_value_get_berval( const Slapi_Value *value )
2330 Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval )
2332 if ( value == NULL ) {
2335 if ( value->bv_val != NULL ) {
2336 slapi_ch_free( (void **)&value->bv_val );
2338 slapi_value_init_berval( value, (struct berval *)bval );
2343 Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom)
2345 if ( value == NULL ) {
2348 return slapi_value_set_berval( value, vfrom );
2351 Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
2353 if ( value == NULL ) {
2356 if ( value->bv_val != NULL ) {
2357 slapi_ch_free( (void **)&value->bv_val );
2359 value->bv_val = slapi_ch_malloc( len );
2360 value->bv_len = len;
2361 AC_MEMCPY( value->bv_val, val, len );
2366 int slapi_value_set_string(Slapi_Value *value, const char *strVal)
2368 if ( value == NULL ) {
2371 slapi_value_set( value, (void *)strVal, strlen( strVal ) );
2375 int slapi_value_set_int(Slapi_Value *value, int intVal)
2379 snprintf( buf, sizeof( buf ), "%d", intVal );
2381 return slapi_value_set_string( value, buf );
2384 const char *slapi_value_get_string(const Slapi_Value *value)
2386 if ( value == NULL ) return NULL;
2387 if ( value->bv_val == NULL ) return NULL;
2388 if ( !checkBVString( value ) ) return NULL;
2390 return value->bv_val;
2393 int slapi_value_get_int(const Slapi_Value *value)
2395 if ( value == NULL ) return 0;
2396 if ( value->bv_val == NULL ) return 0;
2397 if ( !checkBVString( value ) ) return 0;
2399 return (int)strtol( value->bv_val, NULL, 10 );
2402 unsigned int slapi_value_get_uint(const Slapi_Value *value)
2404 if ( value == NULL ) return 0;
2405 if ( value->bv_val == NULL ) return 0;
2406 if ( !checkBVString( value ) ) return 0;
2408 return (unsigned int)strtoul( value->bv_val, NULL, 10 );
2411 long slapi_value_get_long(const Slapi_Value *value)
2413 if ( value == NULL ) return 0;
2414 if ( value->bv_val == NULL ) return 0;
2415 if ( !checkBVString( value ) ) return 0;
2417 return strtol( value->bv_val, NULL, 10 );
2420 unsigned long slapi_value_get_ulong(const Slapi_Value *value)
2422 if ( value == NULL ) return 0;
2423 if ( value->bv_val == NULL ) return 0;
2424 if ( !checkBVString( value ) ) return 0;
2426 return strtoul( value->bv_val, NULL, 10 );
2429 size_t slapi_value_get_length(const Slapi_Value *value)
2431 if ( value == NULL )
2434 return (size_t) value->bv_len;
2437 int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2)
2439 return slapi_attr_value_cmp( a, v1, v2 );
2442 /* A ValueSet is a container for a BerVarray. */
2443 Slapi_ValueSet *slapi_valueset_new( void )
2447 vs = (Slapi_ValueSet *)slapi_ch_malloc( sizeof( *vs ) );
2453 void slapi_valueset_free(Slapi_ValueSet *vs)
2458 ber_bvarray_free( vp );
2461 slapi_ch_free( (void **)&vp );
2465 void slapi_valueset_init(Slapi_ValueSet *vs)
2467 if ( vs != NULL && *vs == NULL ) {
2468 *vs = (Slapi_ValueSet)slapi_ch_calloc( 1, sizeof(struct berval) );
2469 (*vs)->bv_val = NULL;
2474 void slapi_valueset_done(Slapi_ValueSet *vs)
2481 for ( vp = *vs; vp->bv_val != NULL; vp++ ) {
2483 slapi_ch_free( (void **)&vp->bv_val );
2485 /* but don't free *vs or vs */
2488 void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
2492 ber_dupbv( &bv, (Slapi_Value *)addval );
2493 ber_bvarray_add( vs, &bv );
2496 int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
2498 return slapi_valueset_next_value( vs, 0, v );
2501 int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
2511 for ( i = 0; vp[i].bv_val != NULL; i++ ) {
2521 int slapi_valueset_count( const Slapi_ValueSet *vs )
2534 for ( i = 0; vp[i].bv_val != NULL; i++ )
2541 void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
2545 for ( vp = *vs2; vp->bv_val != NULL; vp++ ) {
2546 slapi_valueset_add_value( vs1, vp );
2550 int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
2551 struct berval *val, int access )
2554 slap_access_t slap_access;
2555 AttributeDescription *ad = NULL;
2558 rc = slap_str2ad( attr, &ad, &text );
2559 if ( rc != LDAP_SUCCESS ) {
2564 * Whilst the SLAPI access types are arranged as a bitmask, the
2565 * documentation indicates that they are to be used separately.
2567 switch ( access & SLAPI_ACL_ALL ) {
2568 case SLAPI_ACL_COMPARE:
2569 slap_access = ACL_COMPARE;
2571 case SLAPI_ACL_SEARCH:
2572 slap_access = ACL_SEARCH;
2574 case SLAPI_ACL_READ:
2575 slap_access = ACL_READ;
2577 case SLAPI_ACL_WRITE:
2578 slap_access = ACL_WRITE;
2580 case SLAPI_ACL_DELETE:
2581 slap_access = ACL_WDEL;
2584 slap_access = ACL_WADD;
2586 case SLAPI_ACL_SELF: /* not documented */
2587 case SLAPI_ACL_PROXY: /* not documented */
2589 return LDAP_INSUFFICIENT_ACCESS;
2593 assert( pb->pb_op != NULL );
2595 if ( access_allowed( pb->pb_op, e, ad, val, slap_access, NULL ) ) {
2596 return LDAP_SUCCESS;
2599 return LDAP_INSUFFICIENT_ACCESS;
2602 int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf)
2604 int rc = LDAP_SUCCESS;
2607 if ( pb == NULL || pb->pb_op == NULL )
2608 return LDAP_PARAM_ERROR;
2610 ml = slapi_int_ldapmods2modifications( pb->pb_op, mods );
2615 if ( rc == LDAP_SUCCESS ) {
2616 rc = acl_check_modlist( pb->pb_op, e, ml ) ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
2619 slap_mods_free( ml, 1 );
2625 * Synthesise an LDAPMod array from a Modifications list to pass
2628 LDAPMod **slapi_int_modifications2ldapmods( Modifications *modlist )
2631 LDAPMod **mods, *modp;
2634 for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
2637 mods = (LDAPMod **)slapi_ch_malloc( (i + 1) * sizeof(LDAPMod *) );
2639 for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
2640 mods[i] = (LDAPMod *)slapi_ch_malloc( sizeof(LDAPMod) );
2642 modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
2643 if ( BER_BVISNULL( &ml->sml_type ) ) {
2644 /* may happen for internally generated mods */
2645 assert( ml->sml_desc != NULL );
2646 modp->mod_type = slapi_ch_strdup( ml->sml_desc->ad_cname.bv_val );
2648 modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
2651 if ( ml->sml_values != NULL ) {
2652 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
2654 modp->mod_bvalues = (struct berval **)slapi_ch_malloc( (j + 1) *
2655 sizeof(struct berval *) );
2656 for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
2657 modp->mod_bvalues[j] = (struct berval *)slapi_ch_malloc(
2658 sizeof(struct berval) );
2659 ber_dupbv( modp->mod_bvalues[j], &ml->sml_values[j] );
2661 modp->mod_bvalues[j] = NULL;
2663 modp->mod_bvalues = NULL;
2674 * Convert a potentially modified array of LDAPMods back to a
2675 * Modification list. Unfortunately the values need to be
2676 * duplicated because slap_mods_check() will try to free them
2677 * before prettying (and we can't easily get out of calling
2678 * slap_mods_check() because we need normalized values).
2680 Modifications *slapi_int_ldapmods2modifications ( Operation *op, LDAPMod **mods )
2682 Modifications *modlist = NULL, **modtail;
2684 char textbuf[SLAP_TEXT_BUFLEN];
2687 if ( mods == NULL ) {
2693 for ( modp = mods; *modp != NULL; modp++ ) {
2695 LDAPMod *lmod = *modp;
2698 AttributeDescription *ad = NULL;
2700 if ( slap_str2ad( lmod->mod_type, &ad, &text ) != LDAP_SUCCESS ) {
2704 mod = (Modifications *) slapi_ch_malloc( sizeof(Modifications) );
2705 mod->sml_op = lmod->mod_op & ~(LDAP_MOD_BVALUES);
2707 mod->sml_type = ad->ad_cname;
2709 mod->sml_next = NULL;
2712 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2713 if ( lmod->mod_bvalues != NULL ) {
2714 while ( lmod->mod_bvalues[i] != NULL )
2718 if ( lmod->mod_values != NULL ) {
2719 while ( lmod->mod_values[i] != NULL )
2723 mod->sml_numvals = i;
2726 mod->sml_values = NULL;
2728 mod->sml_values = (BerVarray) slapi_ch_malloc( (i + 1) * sizeof(struct berval) );
2730 /* NB: This implicitly trusts a plugin to return valid modifications. */
2731 if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
2732 for ( i = 0; lmod->mod_bvalues[i] != NULL; i++ ) {
2733 ber_dupbv( &mod->sml_values[i], lmod->mod_bvalues[i] );
2736 for ( i = 0; lmod->mod_values[i] != NULL; i++ ) {
2737 mod->sml_values[i].bv_val = slapi_ch_strdup( lmod->mod_values[i] );
2738 mod->sml_values[i].bv_len = strlen( lmod->mod_values[i] );
2741 mod->sml_values[i].bv_val = NULL;
2742 mod->sml_values[i].bv_len = 0;
2744 mod->sml_nvalues = NULL;
2747 modtail = &mod->sml_next;
2750 if ( slap_mods_check( op, modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
2751 slap_mods_free( modlist, 1 );
2759 * Sun ONE DS 5.x computed attribute support. Computed attributes
2760 * allow for dynamically generated operational attributes, a very
2761 * useful thing indeed.
2765 * For some reason Sun don't use the normal plugin mechanism
2766 * registration path to register an "evaluator" function (an
2767 * "evaluator" is responsible for adding computed attributes;
2768 * the nomenclature is somewhat confusing).
2770 * As such slapi_compute_add_evaluator() registers the
2771 * function directly.
2773 int slapi_compute_add_evaluator(slapi_compute_callback_t function)
2775 Slapi_PBlock *pPlugin = NULL;
2777 int type = SLAPI_PLUGIN_OBJECT;
2779 pPlugin = slapi_pblock_new();
2780 if ( pPlugin == NULL ) {
2781 rc = LDAP_NO_MEMORY;
2785 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2786 if ( rc != LDAP_SUCCESS ) {
2790 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (void *)function );
2791 if ( rc != LDAP_SUCCESS ) {
2795 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2802 if ( rc != LDAP_SUCCESS ) {
2803 if ( pPlugin != NULL ) {
2804 slapi_pblock_destroy( pPlugin );
2813 * See notes above regarding slapi_compute_add_evaluator().
2815 int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
2817 Slapi_PBlock *pPlugin = NULL;
2819 int type = SLAPI_PLUGIN_OBJECT;
2821 pPlugin = slapi_pblock_new();
2822 if ( pPlugin == NULL ) {
2823 rc = LDAP_NO_MEMORY;
2827 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
2828 if ( rc != LDAP_SUCCESS ) {
2832 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, (void *)function );
2833 if ( rc != LDAP_SUCCESS ) {
2837 rc = slapi_int_register_plugin( frontendDB, pPlugin );
2844 if ( rc != LDAP_SUCCESS ) {
2845 if ( pPlugin != NULL ) {
2846 slapi_pblock_destroy( pPlugin );
2855 * Call compute evaluators
2857 int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn)
2860 slapi_compute_callback_t *pGetPlugin, *tmpPlugin;
2862 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
2863 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
2864 /* Nothing to do; front-end should ignore. */
2868 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
2870 * -1: no attribute matched requested type
2871 * 0: one attribute matched
2872 * >0: error happened
2874 rc = (*pGetPlugin)( c, type, e, outputfn );
2880 slapi_ch_free( (void **)&tmpPlugin );
2886 compute_rewrite_search_filter( Slapi_PBlock *pb )
2888 if ( pb == NULL || pb->pb_op == NULL )
2889 return LDAP_PARAM_ERROR;
2891 return slapi_int_call_plugins( pb->pb_op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
2895 * New API to provide the plugin with access to the search
2896 * pblock. Have informed Sun DS team.
2899 slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
2904 if ( c->cac_pb == NULL )
2912 Slapi_Mutex *slapi_new_mutex( void )
2916 m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) );
2917 if ( ldap_pvt_thread_mutex_init( &m->mutex ) != 0 ) {
2918 slapi_ch_free( (void **)&m );
2925 void slapi_destroy_mutex( Slapi_Mutex *mutex )
2927 if ( mutex != NULL ) {
2928 ldap_pvt_thread_mutex_destroy( &mutex->mutex );
2929 slapi_ch_free( (void **)&mutex);
2933 void slapi_lock_mutex( Slapi_Mutex *mutex )
2935 ldap_pvt_thread_mutex_lock( &mutex->mutex );
2938 int slapi_unlock_mutex( Slapi_Mutex *mutex )
2940 return ldap_pvt_thread_mutex_unlock( &mutex->mutex );
2943 Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
2947 if ( mutex == NULL ) {
2951 cv = (Slapi_CondVar *)slapi_ch_malloc( sizeof(*cv) );
2952 if ( ldap_pvt_thread_cond_init( &cv->cond ) != 0 ) {
2953 slapi_ch_free( (void **)&cv );
2957 cv->mutex = mutex->mutex;
2962 void slapi_destroy_condvar( Slapi_CondVar *cvar )
2964 if ( cvar != NULL ) {
2965 ldap_pvt_thread_cond_destroy( &cvar->cond );
2966 slapi_ch_free( (void **)&cvar );
2970 int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout )
2972 if ( cvar == NULL ) {
2976 return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex );
2979 int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
2981 if ( cvar == NULL ) {
2986 return ldap_pvt_thread_cond_broadcast( &cvar->cond );
2989 return ldap_pvt_thread_cond_signal( &cvar->cond );
2992 int slapi_int_access_allowed( Operation *op,
2994 AttributeDescription *desc,
2996 slap_access_t access,
2997 AccessControlState *state )
2999 int rc, slap_access = 0;
3000 slapi_acl_callback_t *pGetPlugin, *tmpPlugin;
3003 pb = SLAPI_OPERATION_PBLOCK( op );
3005 /* internal operation */
3011 slap_access |= SLAPI_ACL_COMPARE;
3014 slap_access |= SLAPI_ACL_SEARCH;
3017 slap_access |= SLAPI_ACL_READ;
3020 slap_access |= SLAPI_ACL_WRITE;
3023 slap_access |= SLAPI_ACL_DELETE;
3026 slap_access |= SLAPI_ACL_ADD;
3032 rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_ACL_ALLOW_ACCESS, (SLAPI_FUNC **)&tmpPlugin );
3033 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
3034 /* nothing to do; allowed access */
3038 rc = 1; /* default allow policy */
3040 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
3045 rc = (*pGetPlugin)( pb, entry, desc->ad_cname.bv_val,
3046 val, slap_access, (void *)state );
3052 slapi_ch_free( (void **)&tmpPlugin );
3058 * There is no documentation for this.
3060 int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
3072 rc = ldap_str2rdn( rdn, &lrdn, &p, LDAP_DN_FORMAT_LDAPV3 );
3073 if ( rc != LDAP_SUCCESS ) {
3077 if ( lrdn[1] != NULL ) {
3078 return -1; /* not single valued */
3083 *type = slapi_ch_strdup( ava->la_attr.bv_val );
3084 ber_dupbv( bv, &ava->la_value );
3091 char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
3093 struct berval new_dn, parent_dn, newrdn;
3095 new_dn.bv_val = NULL;
3097 parent_dn.bv_val = (char *)dn;
3098 parent_dn.bv_len = strlen( dn );
3100 newrdn.bv_val = (char *)rdn;
3101 newrdn.bv_len = strlen( rdn );
3103 build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
3105 return new_dn.bv_val;
3108 int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
3112 char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
3113 size_t textlen = sizeof textbuf;
3114 int rc = LDAP_SUCCESS;
3116 PBLOCK_ASSERT_OP( pb, 0 );
3118 be_orig = pb->pb_op->o_bd;
3120 pb->pb_op->o_bd = select_backend( &e->e_nname, 0 );
3121 if ( pb->pb_op->o_bd != NULL ) {
3122 rc = entry_schema_check( pb->pb_op, e, NULL, 0, 0,
3123 &text, textbuf, textlen );
3125 pb->pb_op->o_bd = be_orig;
3127 return ( rc == LDAP_SUCCESS ) ? 0 : 1;
3130 int slapi_entry_rdn_values_present( const Slapi_Entry *e )
3134 int i = 0, match = 0;
3136 rc = ldap_bv2dn( &((Entry *)e)->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3137 if ( rc != LDAP_SUCCESS ) {
3141 if ( dn[0] != NULL ) {
3142 LDAPRDN rdn = dn[0];
3144 for ( i = 0; rdn[i] != NULL; i++ ) {
3145 LDAPAVA *ava = &rdn[0][i];
3146 Slapi_Attr *a = NULL;
3148 if ( slapi_entry_attr_find( (Slapi_Entry *)e, ava->la_attr.bv_val, &a ) == 0 &&
3149 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3156 return ( i == match );
3159 int slapi_entry_add_rdn_values( Slapi_Entry *e )
3164 rc = ldap_bv2dn( &e->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
3165 if ( rc != LDAP_SUCCESS ) {
3169 if ( dn[0] != NULL ) {
3170 LDAPRDN rdn = dn[0];
3171 struct berval *vals[2];
3173 for ( i = 0; rdn[i] != NULL; i++ ) {
3174 LDAPAVA *ava = &rdn[0][i];
3175 Slapi_Attr *a = NULL;
3177 if ( slapi_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 &&
3178 slapi_attr_value_find( a, &ava->la_value ) == 0 )
3181 vals[0] = &ava->la_value;
3184 slapi_entry_attr_merge( e, ava->la_attr.bv_val, vals );
3190 return LDAP_SUCCESS;
3193 const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
3197 attr = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
3198 if ( attr == NULL ) {
3202 if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
3203 return slapi_value_get_string( &attr->a_vals[0] );
3209 void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
3213 attr_delete ( &e->e_attrs, slap_schema.si_ad_entryUUID );
3215 bv.bv_val = uniqueid;
3216 bv.bv_len = strlen( uniqueid );
3217 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, &bv, NULL );
3220 LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared )
3227 size = sizeof("ldap:///");
3230 size += strlen( ldaphost );
3231 if ( ldapport != 0 )
3234 url = slapi_ch_malloc( size );
3236 if ( ldapport != 0 ) {
3237 sprintf( url, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
3239 sprintf( url, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
3242 rc = ldap_initialize( &ld, url );
3244 slapi_ch_free_string( &url );
3246 return ( rc == LDAP_SUCCESS ) ? ld : NULL;
3249 void slapi_ldap_unbind( LDAP *ld )
3251 ldap_unbind_ext_s( ld, NULL, NULL );
3254 int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags )
3257 return LDAP_PARAM_ERROR;
3259 *flags = SLAP_DBFLAGS(be);
3261 return LDAP_SUCCESS;
3265 slapi_int_count_controls( LDAPControl **ctrls )
3269 if ( ctrls == NULL )
3272 for ( i = 0; ctrls[i] != NULL; i++ )
3279 slapi_op_abandoned( Slapi_PBlock *pb )
3281 if ( pb->pb_op == NULL )
3284 return ( pb->pb_op->o_abandon );
3288 slapi_op_type_to_string(unsigned long type)
3293 case SLAPI_OPERATION_BIND:
3296 case SLAPI_OPERATION_UNBIND:
3299 case SLAPI_OPERATION_SEARCH:
3302 case SLAPI_OPERATION_MODIFY:
3305 case SLAPI_OPERATION_ADD:
3308 case SLAPI_OPERATION_DELETE:
3311 case SLAPI_OPERATION_MODDN:
3314 case SLAPI_OPERATION_COMPARE:
3317 case SLAPI_OPERATION_ABANDON:
3320 case SLAPI_OPERATION_EXTENDED:
3324 str = "unknown operation type";
3331 slapi_op_get_type(Slapi_Operation * op)
3335 switch ( op->o_tag ) {
3337 type = SLAPI_OPERATION_BIND;
3339 case LDAP_REQ_UNBIND:
3340 type = SLAPI_OPERATION_UNBIND;
3342 case LDAP_REQ_SEARCH:
3343 type = SLAPI_OPERATION_SEARCH;
3345 case LDAP_REQ_MODIFY:
3346 type = SLAPI_OPERATION_MODIFY;
3349 type = SLAPI_OPERATION_ADD;
3351 case LDAP_REQ_DELETE:
3352 type = SLAPI_OPERATION_DELETE;
3354 case LDAP_REQ_MODRDN:
3355 type = SLAPI_OPERATION_MODDN;
3357 case LDAP_REQ_COMPARE:
3358 type = SLAPI_OPERATION_COMPARE;
3360 case LDAP_REQ_ABANDON:
3361 type = SLAPI_OPERATION_ABANDON;
3363 case LDAP_REQ_EXTENDED:
3364 type = SLAPI_OPERATION_EXTENDED;
3367 type = SLAPI_OPERATION_NONE;
3373 void slapi_be_set_readonly( Slapi_Backend *be, int readonly )
3379 be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
3381 be->be_restrictops &= ~(SLAP_RESTRICT_OP_WRITES);
3384 int slapi_be_get_readonly( Slapi_Backend *be )
3389 return ( (be->be_restrictops & SLAP_RESTRICT_OP_WRITES) == SLAP_RESTRICT_OP_WRITES );
3392 const char *slapi_x_be_get_updatedn( Slapi_Backend *be )
3397 return be->be_update_ndn.bv_val;
3400 Slapi_Backend *slapi_be_select( const Slapi_DN *sdn )
3404 slapi_sdn_get_ndn( sdn );
3406 be = select_backend( (struct berval *)&sdn->ndn, 0 );
3413 slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag)
3418 slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag)
3423 slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag)
3428 #endif /* LDAP_SLAPI */