2 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * (C) Copyright IBM Corp. 1997,2002
7 * Redistribution and use in source and binary forms are permitted
8 * provided that this notice is preserved and that due credit is
9 * given to IBM Corporation. This software is provided ``as is''
10 * without express or implied warranty.
13 * Portions (C) Copyright PADL Software Pty Ltd.
14 * Redistribution and use in source and binary forms are permitted
15 * provided that this notice is preserved and that due credit is
16 * given to PADL Software Pty Ltd. This software is provided ``as is''
17 * without express or implied warranty.
21 #include "slapi_common.h"
23 #include <ac/string.h>
27 #include <ac/stdarg.h>
29 #include <ac/unistd.h>
32 struct berval *ns_get_supported_extop( int );
35 #include <sys/systeminfo.h>
41 * server start time (should we use a struct timeval also in slapd?
43 static struct timeval base_time;
44 ldap_pvt_thread_mutex_t slapi_hn_mutex;
45 ldap_pvt_thread_mutex_t slapi_time_mutex;
48 ldap_pvt_thread_mutex_t mutex;
51 struct slapi_condvar {
52 ldap_pvt_thread_cond_t cond;
53 ldap_pvt_thread_mutex_t mutex;
57 * This function converts an array of pointers to berval objects to
58 * an array of berval objects.
63 struct berval **bvptr,
66 int rc = LDAP_SUCCESS;
70 if ( bvptr == NULL || *bvptr == NULL ) {
74 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
78 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
79 if ( tmpberval == NULL ) {
80 return LDAP_NO_MEMORY;
83 for ( i = 0; bvptr[i] != NULL; i++ ) {
84 tmpberval[i].bv_val = bvptr[i]->bv_val;
85 tmpberval[i].bv_len = bvptr[i]->bv_len;
88 if ( rc == LDAP_SUCCESS ) {
100 #if defined(LDAP_SLAPI)
101 Slapi_Entry *e = NULL;
104 pTmpS = slapi_ch_strdup( s );
105 if ( pTmpS != NULL ) {
106 e = str2entry( pTmpS );
107 slapi_ch_free( (void **)&pTmpS );
111 #else /* !defined(LDAP_SLAPI) */
113 #endif /* !defined(LDAP_SLAPI) */
121 #if defined(LDAP_SLAPI)
124 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
125 ret = entry2str( e, len );
126 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
129 #else /* !defined(LDAP_SLAPI) */
131 #endif /* !defined(LDAP_SLAPI) */
135 slapi_entry_get_dn( Slapi_Entry *e )
137 #if defined(LDAP_SLAPI)
138 return e->e_name.bv_val;
139 #else /* !defined(LDAP_SLAPI) */
141 #endif /* !defined(LDAP_SLAPI) */
145 slapi_x_entry_get_id( Slapi_Entry *e )
147 #if defined(LDAP_SLAPI)
151 #endif /* !defined(LDAP_SLAPI) */
159 #if defined(LDAP_SLAPI)
160 struct berval dn = { 0, NULL };
163 dn.bv_len = strlen( ldn );
165 dnPrettyNormal( NULL, &dn, &e->e_name, &e->e_nname );
166 #endif /* defined(LDAP_SLAPI) */
170 slapi_entry_dup( Slapi_Entry *e )
172 #if defined(LDAP_SLAPI)
177 tmp = slapi_entry2str( e, &len );
179 return (Slapi_Entry *)NULL;
182 tmpEnt = (Slapi_Entry *)str2entry( tmp );
183 if ( tmpEnt == NULL ) {
184 slapi_ch_free( (void **)&tmp );
185 return (Slapi_Entry *)NULL;
189 slapi_ch_free( (void **)&tmp );
193 #else /* !defined(LDAP_SLAPI) */
195 #endif /* !defined(LDAP_SLAPI) */
199 slapi_entry_attr_delete(
203 #if defined(LDAP_SLAPI)
204 AttributeDescription *ad = NULL;
207 if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
208 return 1; /* LDAP_NO_SUCH_ATTRIBUTE */
211 if ( attr_delete( &e->e_attrs, ad ) == LDAP_SUCCESS ) {
212 return 0; /* attribute is deleted */
214 return -1; /* something went wrong */
216 #else /* !defined(LDAP_SLAPI) */
218 #endif /* !defined(LDAP_SLAPI) */
222 slapi_entry_alloc( void )
224 #if defined(LDAP_SLAPI)
225 return (Slapi_Entry *)slapi_ch_calloc( 1, sizeof(Slapi_Entry) );
226 #else /* !defined(LDAP_SLAPI) */
228 #endif /* !defined(LDAP_SLAPI) */
232 slapi_entry_free( Slapi_Entry *e )
234 #if defined(LDAP_SLAPI)
236 #endif /* defined(LDAP_SLAPI) */
240 slapi_entry_attr_merge(
243 struct berval **vals )
245 #if defined(LDAP_SLAPI)
246 AttributeDescription *ad = NULL;
251 rc = bvptr2obj( vals, &bv );
252 if ( rc != LDAP_SUCCESS ) {
256 rc = slap_str2ad( type, &ad, &text );
257 if ( rc != LDAP_SUCCESS ) {
261 rc = attr_merge( e, ad, bv );
265 #else /* !defined(LDAP_SLAPI) */
267 #endif /* !defined(LDAP_SLAPI) */
271 slapi_entry_attr_find(
276 #if defined(LDAP_SLAPI)
277 AttributeDescription *ad = NULL;
281 rc = slap_str2ad( type, &ad, &text );
282 if ( rc != LDAP_SUCCESS ) {
286 *attr = attr_find( e->e_attrs, ad );
287 if ( *attr == NULL ) {
292 #else /* !defined(LDAP_SLAPI) */
294 #endif /* !defined(LDAP_SLAPI) */
298 slapi_entry_attr_get_charptr( 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 if ( attr->a_vals != NULL && attr->a_vals[0].bv_val != NULL ) {
317 return slapi_ch_strdup( attr->a_vals[0].bv_val );
327 slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
330 AttributeDescription *ad = NULL;
335 rc = slap_str2ad( type, &ad, &text );
336 if ( rc != LDAP_SUCCESS ) {
340 attr = attr_find( e->e_attrs, ad );
341 if ( attr == NULL ) {
345 return slapi_value_get_int( attr->a_vals );
352 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
355 AttributeDescription *ad = NULL;
360 rc = slap_str2ad( type, &ad, &text );
361 if ( rc != LDAP_SUCCESS ) {
365 attr = attr_find( e->e_attrs, ad );
366 if ( attr == NULL ) {
370 return slapi_value_get_long( attr->a_vals );
377 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
380 AttributeDescription *ad = NULL;
385 rc = slap_str2ad( type, &ad, &text );
386 if ( rc != LDAP_SUCCESS ) {
390 attr = attr_find( e->e_attrs, ad );
391 if ( attr == NULL ) {
395 return slapi_value_get_uint( attr->a_vals );
402 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
405 AttributeDescription *ad = NULL;
410 rc = slap_str2ad( type, &ad, &text );
411 if ( rc != LDAP_SUCCESS ) {
415 attr = attr_find( e->e_attrs, ad );
416 if ( attr == NULL ) {
420 return slapi_value_get_ulong( attr->a_vals );
427 slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
431 AttributeDescription *ad;
436 rc = slap_str2ad( type, &ad, &text );
437 if ( rc != LDAP_SUCCESS ) {
441 attr = attr_find( e->e_attrs, ad );
442 if ( attr == NULL ) {
446 bv.bv_val = (char *)value;
447 bv.bv_len = strlen( value );
449 return slapi_attr_value_find( attr, &bv );
456 slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value)
459 AttributeDescription *ad = NULL;
464 rc = slap_str2ad( type, &ad, &text );
465 if ( rc != LDAP_SUCCESS ) {
469 attr_delete ( &e->e_attrs, ad );
470 if ( value != NULL ) {
471 bv.bv_val = (char *)value;
472 bv.bv_len = strlen(value);
473 attr_merge_one ( e, ad, &bv );
475 #endif /* LDAP_SLAPI */
479 slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l)
484 snprintf( buf, sizeof( buf ), "%d", l );
485 slapi_entry_attr_set_charptr( e, type, buf );
486 #endif /* LDAP_SLAPI */
490 slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l)
495 snprintf( buf, sizeof( buf ), "%u", l );
496 slapi_entry_attr_set_charptr( e, type, buf );
497 #endif /* LDAP_SLAPI */
501 slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l)
506 snprintf( buf, sizeof( buf ), "%ld", l );
507 slapi_entry_attr_set_charptr( e, type, buf );
508 #endif /* LDAP_SLAPI */
512 slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l)
517 snprintf( buf, sizeof( buf ), "%lu", l );
518 slapi_entry_attr_set_charptr( e, type, buf );
519 #endif /* LDAP_SLAPI */
523 slapi_is_rootdse( const char *dn )
526 return ( dn == NULL || dn[0] == '\0' );
533 * Add values to entry.
536 * LDAP_SUCCESS Values added to entry
537 * LDAP_TYPE_OR_VALUE_EXISTS One or more values exist in entry already
538 * LDAP_CONSTRAINT_VIOLATION Any other error (odd, but it's the spec)
541 slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
547 char textbuf[SLAP_TEXT_BUFLEN];
549 mod.sm_op = LDAP_MOD_ADD;
551 mod.sm_type.bv_val = (char *)type;
552 mod.sm_type.bv_len = strlen( type );
554 rc = slap_str2ad( type, &mod.sm_desc, &text );
555 if ( rc != LDAP_SUCCESS ) {
559 if ( vals == NULL ) {
560 /* Apparently vals can be NULL */
561 mod.sm_bvalues = (BerVarray)ch_malloc( sizeof(struct berval) );
562 mod.sm_bvalues->bv_val = NULL;
564 rc = bvptr2obj( vals, &mod.sm_bvalues );
565 if ( rc != LDAP_SUCCESS ) {
566 return LDAP_CONSTRAINT_VIOLATION;
570 rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
572 ch_free( mod.sm_bvalues );
574 return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
577 #endif /* LDAP_SLAPI */
581 slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
584 return slapi_entry_add_values( e, type, vals );
587 #endif /* LDAP_SLAPI */
591 slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
594 AttributeDescription *ad = NULL;
599 rc = slap_str2ad( type, &ad, &text );
600 if ( rc != LDAP_SUCCESS ) {
604 return attr_merge( e, ad, *vs );
607 #endif /* LDAP_SLAPI */
611 slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **vals )
617 char textbuf[SLAP_TEXT_BUFLEN];
619 mod.sm_op = LDAP_MOD_DELETE;
621 mod.sm_type.bv_val = (char *)type;
622 mod.sm_type.bv_len = strlen( type );
624 if ( vals == NULL ) {
625 /* If vals is NULL, this is a NOOP. */
629 rc = slap_str2ad( type, &mod.sm_desc, &text );
630 if ( rc != LDAP_SUCCESS ) {
634 if ( vals[0] == NULL ) {
635 /* SLAPI doco says LDAP_OPERATIONS_ERROR */
636 return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OPERATIONS_ERROR : LDAP_SUCCESS;
639 rc = bvptr2obj( vals, &mod.sm_bvalues );
640 if ( rc != LDAP_SUCCESS ) {
641 return LDAP_CONSTRAINT_VIOLATION;
644 rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
646 ch_free( mod.sm_bvalues );
651 #endif /* LDAP_SLAPI */
655 slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
658 return slapi_entry_delete_values( e, type, vals );
661 #endif /* LDAP_SLAPI */
665 slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
668 return slapi_entry_attr_merge( e, (char *)type, vals );
671 #endif /* LDAP_SLAPI */
675 slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value)
678 AttributeDescription *ad = NULL;
682 rc = slap_str2ad( type, &ad, &text );
683 if ( rc != LDAP_SUCCESS ) {
687 rc = attr_merge_one( e, ad, (Slapi_Value *)value );
688 if ( rc != LDAP_SUCCESS ) {
695 #endif /* LDAP_SLAPI */
699 slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
704 val.bv_val = (char *)value;
705 val.bv_len = strlen( value );
707 return slapi_entry_add_value( e, type, &val );
710 #endif /* LDAP_SLAPI */
714 slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
717 Slapi_Value *vals[2];
720 val.bv_val = (char *)value;
721 val.bv_len = strlen( value );
725 return slapi_entry_delete_values_sv( e, type, vals );
728 #endif /* LDAP_SLAPI */
733 slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
736 return slapi_entry_attr_merge( e, (char *)type, vals );
743 slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
752 return ( *attr != NULL ) ? 0 : -1;
759 slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr )
766 if ( prevattr == NULL ) {
770 *attr = prevattr->a_next;
772 return ( *attr != NULL ) ? 0 : -1;
779 slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
782 AttributeDescription *ad;
787 rc = slap_str2ad( type, &ad, &text );
788 if ( rc != LDAP_SUCCESS ) {
792 attr_delete( &e->e_attrs, ad );
794 rc = bvptr2obj( vals, &bv );
795 if ( rc != LDAP_SUCCESS ) {
799 rc = attr_merge( e, ad, bv );
800 slapi_ch_free( (void **)&bv );
801 if ( rc != LDAP_SUCCESS ) {
808 #endif /* LDAP_SLAPI */
812 * FIXME -- The caller must free the allocated memory.
813 * In Netscape they do not have to.
816 slapi_attr_get_values(
818 struct berval ***vals )
820 #if defined(LDAP_SLAPI)
824 if ( attr == NULL ) {
828 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
832 bv = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
833 for ( j = 0; j < i; j++ ) {
834 bv[j] = ber_dupbv( NULL, &attr->a_vals[j] );
838 *vals = (struct berval **)bv;
841 #else /* !defined(LDAP_SLAPI) */
843 #endif /* !defined(LDAP_SLAPI) */
847 slapi_dn_normalize( char *dn )
849 #if defined(LDAP_SLAPI)
853 assert( dn != NULL );
856 bdn.bv_len = strlen( dn );
858 dnNormalize2( NULL, &bdn, &ndn );
861 * FIXME: ain't it safe to set dn = ndn.bv_val ?
863 dn = ch_strdup( ndn.bv_val );
864 ch_free( ndn.bv_val );
867 #else /* !defined(LDAP_SLAPI) */
869 #endif /* !defined(LDAP_SLAPI) */
873 * FIXME: this function is dangerous and should be deprecated;
874 * DN normalization is a lot more than lower-casing, and BTW
875 * OpenLDAP's DN normalization for case insensitive attributes
876 * is already lower case
879 slapi_dn_normalize_case( char *dn )
881 #if defined(LDAP_SLAPI)
882 slapi_dn_normalize( dn );
883 ldap_pvt_str2lower( dn );
886 #else /* defined(LDAP_SLAPI) */
888 #endif /* defined(LDAP_SLAPI) */
896 #if defined(LDAP_SLAPI)
897 struct berval bdn, ndn;
898 struct berval bsuffix, nsuffix;
900 assert( dn != NULL );
901 assert( suffix != NULL );
904 bdn.bv_len = strlen( dn );
906 bsuffix.bv_val = suffix;
907 bsuffix.bv_len = strlen( suffix );
909 dnNormalize2( NULL, &bdn, &ndn );
910 dnNormalize2( NULL, &bsuffix, &nsuffix );
912 return dnIsSuffix( &ndn, &nsuffix );
913 #else /* !defined(LDAP_SLAPI) */
915 #endif /* !defined(LDAP_SLAPI) */
919 slapi_dn_ignore_case( char *dn )
921 #if defined(LDAP_SLAPI)
922 return slapi_dn_normalize_case( dn );
923 #else /* !defined(LDAP_SLAPI) */
925 #endif /* !defined(LDAP_SLAPI) */
929 slapi_ch_malloc( unsigned long size )
931 #if defined(LDAP_SLAPI)
932 return ch_malloc( size );
933 #else /* !defined(LDAP_SLAPI) */
935 #endif /* !defined(LDAP_SLAPI) */
939 slapi_ch_free( void **ptr )
941 #if defined(LDAP_SLAPI)
944 #endif /* defined(LDAP_SLAPI) */
948 slapi_ch_free_string( char **ptr )
950 #if defined(LDAP_SLAPI)
951 slapi_ch_free( (void **)ptr );
952 #endif /* defined(LDAP_SLAPI) */
956 slapi_ch_array_free( char **arrayp )
961 if ( arrayp != NULL ) {
962 for ( p = arrayp; *p != NULL; p++ ) {
963 slapi_ch_free( (void **)p );
965 slapi_ch_free( (void **)&arrayp );
971 slapi_ch_bvdup(const struct berval *v)
976 bv = (struct berval *) slapi_ch_malloc( sizeof(struct berval) );
977 bv->bv_len = v->bv_len;
978 bv->bv_val = slapi_ch_malloc( bv->bv_len );
979 AC_MEMCPY( bv->bv_val, v->bv_val, bv->bv_len );
988 slapi_ch_bvecdup(const struct berval **v)
998 for ( i = 0; v[i] != NULL; i++ )
1001 rv = (struct berval **) slapi_ch_malloc( (i + 1) * sizeof(struct berval *) );
1003 for ( i = 0; v[i] != NULL; i++ ) {
1004 rv[i] = slapi_ch_bvdup( v[i] );
1016 unsigned long nelem,
1017 unsigned long size )
1019 #if defined(LDAP_SLAPI)
1020 return ch_calloc( nelem, size );
1021 #else /* !defined(LDAP_SLAPI) */
1023 #endif /* !defined(LDAP_SLAPI) */
1029 unsigned long size )
1031 #if defined(LDAP_SLAPI)
1032 return ch_realloc( block, size );
1033 #else /* !defined(LDAP_SLAPI) */
1035 #endif /* !defined(LDAP_SLAPI) */
1039 slapi_ch_strdup( char *s )
1041 #if defined(LDAP_SLAPI)
1042 return ch_strdup( (const char *)s );
1043 #else /* !defined(LDAP_SLAPI) */
1045 #endif /* !defined(LDAP_SLAPI) */
1049 slapi_ch_stlen( char *s )
1051 #if defined(LDAP_SLAPI)
1052 return strlen( (const char *)s );
1053 #else /* !defined(LDAP_SLAPI) */
1055 #endif /* !defined(LDAP_SLAPI) */
1059 slapi_control_present(
1060 LDAPControl **controls,
1062 struct berval **val,
1065 #if defined(LDAP_SLAPI)
1077 for ( i = 0; controls != NULL && controls[i] != NULL; i++ ) {
1078 if ( strcmp( controls[i]->ldctl_oid, oid ) != 0 ) {
1083 if ( controls[i]->ldctl_value.bv_len != 0 ) {
1085 * FIXME: according to 6.1 specification,
1086 * "The val output parameter is set
1087 * to point into the controls array.
1088 * A copy of the control value is
1092 struct berval *pTmpBval;
1094 pTmpBval = (struct berval *)slapi_ch_malloc( sizeof(struct berval));
1095 if ( pTmpBval == NULL ) {
1098 pTmpBval->bv_len = controls[i]->ldctl_value.bv_len;
1099 pTmpBval->bv_val = controls[i]->ldctl_value.bv_val;
1103 slapi_ch_free( (void **)&pTmpBval );
1109 *val = &controls[i]->ldctl_value;
1114 *iscritical = controls[i]->ldctl_iscritical;
1121 #else /* !defined(LDAP_SLAPI) */
1123 #endif /* !defined(LDAP_SLAPI) */
1127 slapi_register_supported_control(
1129 unsigned long controlops )
1131 #if defined(LDAP_SLAPI)
1132 /* FIXME -- can not add controls to OpenLDAP dynamically */
1133 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_CONTROLS",
1134 "OpenLDAP does not support dynamic registration of LDAP controls\n" );
1135 #endif /* defined(LDAP_SLAPI) */
1139 slapi_get_supported_controls(
1141 unsigned long **ctrlopsp )
1143 #if defined(LDAP_SLAPI)
1147 unsigned long *masks = NULL;
1149 for (n = 0; get_supported_ctrl( n ) != NULL; n++) {
1157 return LDAP_SUCCESS;
1161 oids = (char **)slapi_ch_malloc( (n + 1) * sizeof(char *) );
1162 if ( oids == NULL ) {
1163 rc = LDAP_NO_MEMORY;
1167 masks = (unsigned long *)slapi_ch_malloc( n * sizeof(int) );
1168 if ( masks == NULL ) {
1169 rc = LDAP_NO_MEMORY;
1173 for ( i = 0; i < n; i++ ) {
1175 * FIXME: Netscape's specification says nothing about
1176 * memory; should we copy the OIDs or return pointers
1177 * to internal values? In OpenLDAP the latter is safe
1178 * since we do not allow to register coltrols runtime
1180 oids[ i ] = ch_strdup( get_supported_ctrl( i ) );
1181 if ( oids[ i ] == NULL ) {
1182 rc = LDAP_NO_MEMORY;
1185 masks[ i ] = (unsigned long)get_supported_ctrl_mask( i );
1190 return LDAP_SUCCESS;
1193 if ( rc != LDAP_SUCCESS ) {
1194 for ( i = 0; oids != NULL && oids[ i ] != NULL; i++ ) {
1195 ch_free( oids[ i ] );
1202 #else /* !defined(LDAP_SLAPI) */
1204 #endif /* !defined(LDAP_SLAPI) */
1208 slapi_register_supported_saslmechanism( char *mechanism )
1210 #if defined(LDAP_SLAPI)
1211 /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */
1212 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL",
1213 "OpenLDAP does not support dynamic registration of SASL mechanisms\n" );
1214 #endif /* defined(LDAP_SLAPI) */
1218 slapi_get_supported_saslmechanisms( void )
1220 #if defined(LDAP_SLAPI)
1221 /* FIXME -- can not get the saslmechanism wihtout a connection. */
1222 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL",
1223 "can not get the saslmechanism "
1224 "wihtout a connection\n" );
1226 #else /* defined(LDAP_SLAPI) */
1228 #endif /* defined(LDAP_SLAPI) */
1232 slapi_get_supported_extended_ops( void )
1234 #if defined(LDAP_SLAPI)
1236 char **ppExtOpOID = NULL;
1239 for ( i = 0; get_supported_extop( i ) != NULL; i++ ) {
1243 for ( j = 0; ns_get_supported_extop( j ) != NULL; j++ ) {
1248 if ( numExtOps == 0 ) {
1252 ppExtOpOID = (char **)slapi_ch_malloc( (numExtOps + 1) * sizeof(char *) );
1253 for ( k = 0; k < i; k++ ) {
1256 bv = get_supported_extop( k );
1257 assert( bv != NULL );
1259 ppExtOpOID[ k ] = bv->bv_val;
1262 for ( ; k < j; k++ ) {
1265 bv = ns_get_supported_extop( k );
1266 assert( bv != NULL );
1268 ppExtOpOID[ i + k ] = bv->bv_val;
1270 ppExtOpOID[ i + k ] = NULL;
1273 #else /* !defined(LDAP_SLAPI) */
1275 #endif /* !defined(LDAP_SLAPI) */
1279 slapi_send_ldap_result(
1285 struct berval **urls )
1287 #if defined(LDAP_SLAPI)
1291 char *extOID = NULL;
1292 struct berval *extValue = NULL;
1295 slapi_pblock_get( pb, SLAPI_CONNECTION, &conn );
1296 slapi_pblock_get( pb, SLAPI_OPERATION, &op );
1297 if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
1298 slapi_pblock_get( pb, SLAPI_BIND_RET_SASLCREDS, &s );
1299 rc = LDAP_SASL_BIND_IN_PROGRESS;
1300 send_ldap_sasl( conn, op, rc, NULL, NULL, NULL, NULL, s );
1304 slapi_pblock_get( pb, SLAPI_EXT_OP_RET_OID, &extOID );
1305 if ( extOID != NULL ) {
1306 slapi_pblock_get( pb, SLAPI_EXT_OP_RET_VALUE, &extValue );
1307 slapi_send_ldap_extended_response( conn, op, err, extOID,
1312 send_ldap_result( conn, op, err, matched, text, NULL, NULL );
1313 #endif /* defined(LDAP_SLAPI) */
1317 slapi_send_ldap_search_entry(
1320 LDAPControl **ectrls,
1324 #if defined(LDAP_SLAPI)
1331 AttributeName *an = NULL;
1334 for ( i = 0; attrs[ i ] != NULL; i++ ) {
1339 an = (AttributeName *) ch_malloc( i * sizeof(AttributeName) );
1340 for ( i = 0; attrs[i] != NULL; i++ ) {
1341 an[i].an_name.bv_val = ch_strdup( attrs[i] );
1342 an[i].an_name.bv_len = strlen( attrs[i] );
1343 an[i].an_desc = NULL;
1344 if( slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text ) != LDAP_SUCCESS)
1349 if ( ( rc = slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be ) != 0 ) ||
1350 ( rc = slapi_pblock_get( pb, SLAPI_CONNECTION, (void *)&pConn) != 0 ) ||
1351 ( rc = slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp) != 0 ) ) {
1354 rc = send_search_entry( be, pConn, pOp, e, an, attrsonly, NULL );
1359 #else /* !defined(LDAP_SLAPI) */
1361 #endif /* !defined(LDAP_SLAPI) */
1366 slapi_str2filter( char *str )
1368 #if defined(LDAP_SLAPI)
1369 return str2filter( str );
1370 #else /* !defined(LDAP_SLAPI) */
1372 #endif /* !defined(LDAP_SLAPI) */
1380 #if defined(LDAP_SLAPI)
1382 #endif /* defined(LDAP_SLAPI) */
1386 slapi_filter_get_choice( Slapi_Filter *f )
1388 #if defined(LDAP_SLAPI)
1398 #else /* !defined(LDAP_SLAPI) */
1399 return -1; /* invalid filter type */
1400 #endif /* !defined(LDAP_SLAPI) */
1404 slapi_filter_get_ava(
1407 struct berval **bval )
1409 #if defined(LDAP_SLAPI)
1411 int rc = LDAP_SUCCESS;
1413 assert( type != NULL );
1414 assert( bval != NULL );
1419 ftype = f->f_choice;
1420 if ( ftype == LDAP_FILTER_EQUALITY
1421 || ftype == LDAP_FILTER_GE
1422 || ftype == LDAP_FILTER_LE
1423 || ftype == LDAP_FILTER_APPROX ) {
1425 * According to the SLAPI Reference Manual these are
1428 *type = f->f_un.f_un_ava->aa_desc->ad_cname.bv_val;
1429 *bval = &f->f_un.f_un_ava->aa_value;
1430 } else { /* filter type not supported */
1435 #else /* !defined(LDAP_SLAPI) */
1437 #endif /* !defined(LDAP_SLAPI) */
1441 slapi_filter_list_first( Slapi_Filter *f )
1443 #if defined(LDAP_SLAPI)
1450 ftype = f->f_choice;
1451 if ( ftype == LDAP_FILTER_AND
1452 || ftype == LDAP_FILTER_OR
1453 || ftype == LDAP_FILTER_NOT ) {
1454 return (Slapi_Filter *)f->f_and;
1458 #else /* !defined(LDAP_SLAPI) */
1460 #endif /* !defined(LDAP_SLAPI) */
1464 slapi_filter_list_next(
1466 Slapi_Filter *fprev )
1468 #if defined(LDAP_SLAPI)
1475 ftype = f->f_choice;
1476 if ( ftype == LDAP_FILTER_AND
1477 || ftype == LDAP_FILTER_OR
1478 || ftype == LDAP_FILTER_NOT )
1480 return fprev->f_next;
1484 #else /* !defined(LDAP_SLAPI) */
1486 #endif /* !defined(LDAP_SLAPI) */
1490 slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
1497 switch ( f->f_choice ) {
1498 case LDAP_FILTER_GE:
1499 case LDAP_FILTER_LE:
1500 case LDAP_FILTER_EQUALITY:
1501 case LDAP_FILTER_APPROX:
1502 *type = f->f_av_desc->ad_cname.bv_val;
1504 case LDAP_FILTER_SUBSTRINGS:
1505 *type = f->f_sub_desc->ad_cname.bv_val;
1507 case LDAP_FILTER_PRESENT:
1508 *type = f->f_desc->ad_cname.bv_val;
1510 case LDAP_FILTER_EXT:
1511 *type = f->f_mr_desc->ad_cname.bv_val;
1514 /* Complex filters need not apply. */
1522 #endif /* LDAP_SLAPI */
1526 slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
1527 char ***any, char **final )
1532 if ( f->f_choice != LDAP_FILTER_SUBSTRINGS ) {
1537 * The caller shouldn't free but we can't return an
1538 * array of char *s from an array of bervals without
1539 * allocating memory, so we may as well be consistent.
1542 *type = f->f_sub_desc->ad_cname.bv_val;
1543 *initial = f->f_sub_initial.bv_val ? slapi_ch_strdup(f->f_sub_initial.bv_val) : NULL;
1544 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ )
1546 *any = (char **)slapi_ch_malloc( (i + 1) * sizeof(char *) );
1547 for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
1548 (*any)[i] = slapi_ch_strdup(f->f_sub_any[i].bv_val);
1551 *final = f->f_sub_final.bv_val ? slapi_ch_strdup(f->f_sub_final.bv_val) : NULL;
1556 #endif /* LDAP_SLAPI */
1560 slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2)
1563 Slapi_Filter *f = NULL;
1565 if ( ftype == LDAP_FILTER_AND ||
1566 ftype == LDAP_FILTER_OR ||
1567 ftype == LDAP_FILTER_NOT )
1569 f = (Slapi_Filter *)slapi_ch_malloc( sizeof(*f) );
1570 f->f_choice = ftype;
1578 #endif /* LDAP_SLAPI */
1582 slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
1592 /* spec says return zero if no filter. */
1596 if ( verify_access ) {
1597 (void) slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&be);
1598 rc = slapi_pblock_get(pb, SLAPI_CONNECTION, (void *)&conn);
1600 return LDAP_PARAM_ERROR;
1602 rc = slapi_pblock_get(pb, SLAPI_OPERATION, (void *)&op);
1604 return LDAP_PARAM_ERROR;
1611 * According to acl.c it is safe to call test_filter() with
1614 rc = test_filter( be, conn, op, e, f );
1616 case LDAP_COMPARE_TRUE:
1619 case LDAP_COMPARE_FALSE:
1621 case SLAPD_COMPARE_UNDEFINED:
1624 case LDAP_PROTOCOL_ERROR:
1625 /* filter type unknown: spec says return -1 */
1633 #endif /* LDAP_SLAPI */
1637 slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f)
1640 return slapi_filter_test( NULL, e, f, 0 );
1647 slapi_send_ldap_extended_response(
1652 struct berval *response )
1654 #if defined(LDAP_SLAPI)
1655 send_ldap_extended( conn,op, errornum, NULL, NULL, NULL,
1656 respName,response, NULL );
1657 return LDAP_SUCCESS;
1658 #else /* !defined(LDAP_SLAPI) */
1660 #endif /* !defined(LDAP_SLAPI) */
1665 struct berval **vals,
1668 #if defined(LDAP_SLAPI)
1670 * FIXME: what's the point?
1673 #else /* !defined(LDAP_SLAPI) */
1675 #endif /* !defined(LDAP_SLAPI) */
1679 slapi_get_hostname( void )
1681 #if defined(LDAP_SLAPI)
1685 * FIXME: I'd prefer a different check ...
1688 hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
1690 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
1691 "can't malloc memory for hostname\n" );
1694 } else if ( sysinfo( SI_HOSTNAME, hn, MAX_HOSTNAME ) < 0 ) {
1695 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
1696 "can't get hostname\n" );
1697 slapi_ch_free( (void **)&hn );
1701 static int been_here = 0;
1702 static char *static_hn = NULL;
1704 ldap_pvt_thread_mutex_lock( &slapi_hn_mutex );
1706 static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
1707 if ( static_hn == NULL) {
1708 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
1709 "can't malloc memory for hostname\n" );
1711 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1716 if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) {
1717 slapi_log_error( SLAPI_LOG_FATAL,
1719 "can't get hostname\n" );
1720 slapi_ch_free( (void **)&static_hn );
1722 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1731 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1733 hn = ch_strdup( static_hn );
1734 #endif /* !_SPARC */
1737 #else /* !defined(LDAP_SLAPI) */
1739 #endif /* !defined(LDAP_SLAPI) */
1743 * FIXME: this should go in an appropriate header ...
1745 extern int vLogError( int level, char *subsystem, char *fmt, va_list arglist );
1754 #if defined(LDAP_SLAPI)
1755 int rc = LDAP_SUCCESS;
1758 va_start( arglist, fmt );
1759 rc = vLogError( severity, subsystem, fmt, arglist );
1763 #else /* !defined(LDAP_SLAPI) */
1765 #endif /* !defined(LDAP_SLAPI) */
1770 slapi_timer_current_time( void )
1772 #if defined(LDAP_SLAPI)
1773 static int first_time = 1;
1774 #if !defined (_WIN32)
1778 ldap_pvt_thread_mutex_lock( &slapi_time_mutex );
1781 gettimeofday( &base_time, NULL );
1783 gettimeofday( &now, NULL );
1784 ret = ( now.tv_sec - base_time.tv_sec ) * 1000000 +
1785 (now.tv_usec - base_time.tv_usec);
1786 ldap_pvt_thread_mutex_unlock( &slapi_time_mutex );
1792 return (slap_get_time() - starttime) * 1000000;
1799 performance_counter_present = QueryPerformanceCounter( &base_time );
1800 QueryPerformanceFrequency( &performance_freq );
1803 if ( !performance_counter_present )
1806 QueryPerformanceCounter( &now );
1807 return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
1809 #else /* !defined(LDAP_SLAPI) */
1811 #endif /* !defined(LDAP_SLAPI) */
1818 slapi_timer_get_time( char *label )
1820 #if defined(LDAP_SLAPI)
1821 unsigned long start = slapi_timer_current_time();
1822 printf("%10ld %10ld usec %s\n", start, 0, label);
1824 #else /* !defined(LDAP_SLAPI) */
1826 #endif /* !defined(LDAP_SLAPI) */
1833 slapi_timer_elapsed_time(
1835 unsigned long start )
1837 #if defined(LDAP_SLAPI)
1838 unsigned long stop = slapi_timer_current_time();
1839 printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
1840 #endif /* defined(LDAP_SLAPI) */
1844 slapi_free_search_results_internal( Slapi_PBlock *pb )
1846 #if defined(LDAP_SLAPI)
1847 Slapi_Entry **entries;
1848 int k = 0, nEnt = 0;
1850 slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
1851 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
1856 if ( entries == NULL ) {
1860 for ( k = 0; k < nEnt; k++ ) {
1861 slapi_entry_free( entries[k] );
1864 slapi_ch_free( (void **)&entries );
1865 #endif /* defined(LDAP_SLAPI) */
1869 * Internal API to prime a Slapi_PBlock with a Backend.
1871 int slapi_x_backend_set_pb( Slapi_PBlock *pb, Backend *be )
1873 #if defined(LDAP_SLAPI)
1876 rc = slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be );
1877 if ( rc != LDAP_SUCCESS )
1881 rc = slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type );
1882 if ( rc != LDAP_SUCCESS )
1886 return LDAP_SUCCESS;
1889 #endif /* defined(LDAP_SLAPI) */
1892 #if defined(LDAP_SLAPI)
1894 * If oldStyle is TRUE, then a value suitable for setting to
1895 * the deprecated SLAPI_CONN_AUTHTYPE value is returned
1896 * (pointer to static storage).
1898 * If oldStyle is FALSE, then a value suitable for setting to
1899 * the new SLAPI_CONN_AUTHMETHOD will be returned, which is
1900 * a pointer to allocated memory and will include the SASL
1901 * mechanism (if any).
1903 static char *Authorization2AuthType( AuthorizationInformation *authz, int is_tls, int oldStyle )
1908 switch ( authz->sai_method ) {
1909 case LDAP_AUTH_SASL:
1911 authType = SLAPD_AUTH_SASL;
1913 len = sizeof(SLAPD_AUTH_SASL) + authz->sai_mech.bv_len;
1914 authType = slapi_ch_malloc( len );
1915 snprintf( authType, len, "%s%s", SLAPD_AUTH_SASL, authz->sai_mech.bv_val );
1918 case LDAP_AUTH_SIMPLE:
1919 authType = oldStyle ? SLAPD_AUTH_SIMPLE : slapi_ch_strdup( SLAPD_AUTH_SIMPLE );
1921 case LDAP_AUTH_NONE:
1922 authType = oldStyle ? SLAPD_AUTH_NONE : slapi_ch_strdup( SLAPD_AUTH_NONE );
1928 if ( is_tls && authType == NULL ) {
1929 authType = oldStyle ? SLAPD_AUTH_SSL : slapi_ch_strdup( SLAPD_AUTH_SSL );
1937 * Internal API to prime a Slapi_PBlock with a Connection.
1939 int slapi_x_connection_set_pb( Slapi_PBlock *pb, Connection *conn )
1941 #if defined(LDAP_SLAPI)
1945 rc = slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
1946 if ( rc != LDAP_SUCCESS )
1949 if ( strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0 ) {
1950 rc = slapi_pblock_set( pb, SLAPI_CONN_CLIENTIP, (void *)&conn->c_peer_name.bv_val[3] );
1951 if ( rc != LDAP_SUCCESS )
1953 } else if ( strncmp( conn->c_peer_name.bv_val, "PATH=", 5 ) == 0 ) {
1954 rc = slapi_pblock_set( pb, SLAPI_X_CONN_CLIENTPATH, (void *)&conn->c_peer_name.bv_val[5] );
1955 if ( rc != LDAP_SUCCESS )
1959 if ( strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0 ) {
1960 rc = slapi_pblock_set( pb, SLAPI_CONN_SERVERIP, (void *)&conn->c_sock_name.bv_val[3] );
1961 if ( rc != LDAP_SUCCESS )
1963 } else if ( strncmp( conn->c_sock_name.bv_val, "PATH=", 5 ) == 0 ) {
1964 rc = slapi_pblock_set( pb, SLAPI_X_CONN_SERVERPATH, (void *)&conn->c_sock_name.bv_val[5] );
1965 if ( rc != LDAP_SUCCESS )
1969 #ifdef LDAP_CONNECTIONLESS
1970 rc = slapi_pblock_set( pb, SLAPI_X_CONN_IS_UDP, (void *)conn->c_is_udp );
1971 if ( rc != LDAP_SUCCESS )
1975 rc = slapi_pblock_set( pb, SLAPI_CONN_ID, (void *)conn->c_connid );
1976 if ( rc != LDAP_SUCCESS )
1979 /* Returns pointer to static string */
1980 connAuthType = Authorization2AuthType( &conn->c_authz, conn->c_is_tls, 1 );
1981 if ( connAuthType != NULL ) {
1982 rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHTYPE, (void *)connAuthType);
1983 if ( rc != LDAP_SUCCESS )
1987 /* Returns pointer to allocated string */
1988 connAuthType = Authorization2AuthType( &conn->c_authz, conn->c_is_tls, 0 );
1989 if ( connAuthType != NULL ) {
1990 rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHMETHOD, (void *)connAuthType);
1991 if ( rc != LDAP_SUCCESS )
1995 if ( conn->c_authz.sai_dn.bv_val != NULL ) {
1996 char *connDn = slapi_ch_strdup(conn->c_authz.sai_dn.bv_val);
1997 rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)connDn);
1998 if ( rc != LDAP_SUCCESS )
2005 #endif /* defined(LDAP_SLAPI) */
2009 * Internal API to prime a Slapi_PBlock with an Operation.
2011 int slapi_x_operation_set_pb( Slapi_PBlock *pb, Operation *op )
2013 #if defined(LDAP_SLAPI)
2020 if ( slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&be ) != 0 ) {
2024 isRoot = be_isroot( be, &op->o_ndn );
2025 isUpdateDn = be_isupdate( be, &op->o_ndn );
2028 rc = slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op );
2029 if ( rc != LDAP_SUCCESS )
2032 rc = slapi_pblock_set( pb, SLAPI_OPINITIATED_TIME, (void *)op->o_time );
2033 if ( rc != LDAP_SUCCESS )
2036 rc = slapi_pblock_set( pb, SLAPI_OPERATION_ID, (void *)op->o_opid );
2037 if ( rc != LDAP_SUCCESS )
2040 rc = slapi_pblock_set( pb, SLAPI_OPERATION_TYPE, (void *)op->o_tag );
2041 if ( rc != LDAP_SUCCESS )
2044 rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot );
2045 if ( rc != LDAP_SUCCESS )
2048 rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void *)isUpdateDn );
2049 if ( rc != LDAP_SUCCESS )
2052 rc = slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls );
2053 if ( rc != LDAP_SUCCESS)
2056 rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_DN, (void *)op->o_ndn.bv_val );
2057 if ( rc != LDAP_SUCCESS )
2060 rc = slapi_pblock_get( pb, SLAPI_CONN_AUTHMETHOD, (void *)&opAuthType );
2061 if ( rc == LDAP_SUCCESS && opAuthType != NULL ) {
2062 /* Not quite sure what the point of this is. */
2063 rc = slapi_pblock_set( pb, SLAPI_OPERATION_AUTHTYPE, (void *)opAuthType );
2064 if ( rc != LDAP_SUCCESS )
2068 return LDAP_SUCCESS;
2074 int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
2076 #if defined( LDAP_SLAPI )
2079 slapi_pblock_get( pb, SLAPI_CONNECTION, &conn );
2080 *isSSL = conn->c_is_tls;
2082 return LDAP_SUCCESS;
2085 #endif /* defined(LDAP_SLAPI) */
2089 * DS 5.x compatability API follow
2092 int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
2094 #if defined( LDAP_SLAPI )
2098 return LDAP_PARAM_ERROR;
2100 at = attr->a_desc->ad_type;
2102 *flags = SLAPI_ATTR_FLAG_STD_ATTR;
2104 if ( is_at_single_value( at ) )
2105 *flags |= SLAPI_ATTR_FLAG_SINGLE;
2106 if ( is_at_operational( at ) )
2107 *flags |= SLAPI_ATTR_FLAG_OPATTR;
2108 if ( is_at_obsolete( at ) )
2109 *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
2110 if ( is_at_collective( at ) )
2111 *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
2112 if ( is_at_no_user_mod( at ) )
2113 *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
2115 return LDAP_SUCCESS;
2118 #endif /* defined(LDAP_SLAPI) */
2121 int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
2123 #if defined( LDAP_SLAPI )
2124 unsigned long flags;
2126 if ( slapi_attr_get_flags( attr, &flags ) != 0 )
2128 return (flags & flag) ? 1 : 0;
2131 #endif /* defined(LDAP_SLAPI) */
2134 Slapi_Attr *slapi_attr_new( void )
2139 ad = (Attribute *)slapi_ch_calloc( 1, sizeof(*ad) );
2147 Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
2151 AttributeDescription *ad = NULL;
2153 if( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
2168 void slapi_attr_free( Slapi_Attr **a )
2176 Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
2179 return attr_dup( (Slapi_Attr *)attr );
2185 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
2188 return value_add_one( &a->a_vals, (Slapi_Value *)v );
2194 int slapi_attr_type2plugin( const char *type, void **pi )
2201 int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
2204 if ( attr == NULL ) {
2205 return LDAP_PARAM_ERROR;
2208 *type = attr->a_desc->ad_cname.bv_val;
2210 return LDAP_SUCCESS;
2216 int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp )
2219 if ( attr == NULL ) {
2220 return LDAP_PARAM_ERROR;
2222 *oidp = attr->a_desc->ad_type->sat_oid;
2224 return LDAP_SUCCESS;
2230 int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
2238 mr = a->a_desc->ad_type->sat_equality;
2239 rc = value_match( &ret, a->a_desc, mr, SLAP_MR_ASSERTION_SYNTAX_MATCH,
2240 (struct berval *)v1, (void *)v2, &text );
2241 if ( rc != LDAP_SUCCESS )
2244 return ( ret == 0 ) ? 0 : -1;
2250 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
2260 mr = a->a_desc->ad_type->sat_equality;
2261 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
2262 rc = value_match( &ret, a->a_desc, mr,
2263 SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, v, &text );
2264 if ( rc != LDAP_SUCCESS ) {
2275 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
2278 AttributeDescription *a1 = NULL;
2279 AttributeDescription *a2 = NULL;
2283 if ( slap_str2ad( t1, &a1, &text ) != LDAP_SUCCESS ) {
2287 if ( slap_str2ad( t2, &a2, &text ) != LDAP_SUCCESS ) {
2291 #define ad_base_cmp(l,r) (((l)->ad_type->sat_cname.bv_len < (r)->ad_type->sat_cname.bv_len) \
2292 ? -1 : (((l)->ad_type->sat_cname.bv_len > (r)->ad_type->sat_cname.bv_len) \
2293 ? 1 : strcasecmp((l)->ad_type->sat_cname.bv_val, (r)->ad_type->sat_cname.bv_val )))
2296 case SLAPI_TYPE_CMP_EXACT:
2297 ret = ad_cmp( a1, a2 );
2299 case SLAPI_TYPE_CMP_BASE:
2300 ret = ad_base_cmp( a1, a2 );
2302 case SLAPI_TYPE_CMP_SUBTYPE:
2303 ret = is_ad_subtype( a2, a2 );
2316 int slapi_attr_types_equivalent( const char *t1, const char *t2 )
2319 return slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT );
2325 int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v )
2328 return slapi_valueset_first_value( &a->a_vals, v );
2334 int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v )
2337 return slapi_valueset_next_value( &a->a_vals, hint, v );
2343 int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues )
2346 *numValues = slapi_valueset_count( &a->a_vals );
2354 int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs )
2357 *vs = &((Slapi_Attr *)a)->a_vals;
2365 int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals )
2368 return slapi_attr_get_values( a, vals );
2374 char *slapi_attr_syntax_normalize( const char *s )
2377 AttributeDescription *ad = NULL;
2380 if ( slap_str2ad( s, &ad, &text ) != LDAP_SUCCESS ) {
2384 return ad->ad_cname.bv_val;
2390 Slapi_Value *slapi_value_new( void )
2395 bv = (struct berval *)slapi_ch_malloc( sizeof(*bv) );
2403 Slapi_Value *slapi_value_new_berval(const struct berval *bval)
2406 return ber_dupbv( NULL, (struct berval *)bval );
2412 Slapi_Value *slapi_value_new_value(const Slapi_Value *v)
2415 return slapi_value_new_berval( v );
2421 Slapi_Value *slapi_value_new_string(const char *s)
2426 bv.bv_val = (char *)s;
2427 bv.bv_len = strlen( s );
2429 return slapi_value_new_berval( &bv );
2435 Slapi_Value *slapi_value_init(Slapi_Value *val)
2447 Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval)
2450 return ber_dupbv( v, bval );
2456 Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
2459 v->bv_val = slapi_ch_strdup( (char *)s );
2460 v->bv_len = strlen( s );
2468 Slapi_Value *slapi_value_dup(const Slapi_Value *v)
2471 return slapi_value_new_value( v );
2477 void slapi_value_free(Slapi_Value **value)
2480 if ( value == NULL ) {
2484 if ( (*value) != NULL ) {
2485 slapi_ch_free( (void **)&(*value)->bv_val );
2486 slapi_ch_free( (void **)value );
2491 const struct berval *slapi_value_get_berval( const Slapi_Value *value )
2500 Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval )
2503 if ( value == NULL ) {
2506 if ( value->bv_val != NULL ) {
2507 slapi_ch_free( (void **)&value->bv_val );
2509 slapi_value_init_berval( value, (struct berval *)bval );
2517 Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom)
2520 if ( value == NULL ) {
2523 return slapi_value_set_berval( value, vfrom );
2529 Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
2532 if ( value == NULL ) {
2535 if ( value->bv_val != NULL ) {
2536 slapi_ch_free( (void **)&value->bv_val );
2538 value->bv_val = slapi_ch_malloc( len );
2539 value->bv_len = len;
2540 AC_MEMCPY( value->bv_val, val, len );
2548 int slapi_value_set_string(Slapi_Value *value, const char *strVal)
2551 if ( value == NULL ) {
2554 slapi_value_set( value, (void *)strVal, strlen( strVal ) );
2561 int slapi_value_set_int(Slapi_Value *value, int intVal)
2566 snprintf( buf, sizeof( buf ), "%d", intVal );
2568 return slapi_value_set_string( value, buf );
2574 const char *slapi_value_get_string(const Slapi_Value *value)
2577 if ( value == NULL ) {
2580 return value->bv_val;
2587 static int checkBVString(const struct berval *bv)
2591 for ( i = 0; i < bv->bv_len; i++ ) {
2592 if ( bv->bv_val[i] == '\0' )
2595 if ( bv->bv_val[i] != '\0' )
2602 int slapi_value_get_int(const Slapi_Value *value)
2605 if ( value == NULL ) return 0;
2606 if ( value->bv_val == NULL ) return 0;
2607 if ( !checkBVString( value ) ) return 0;
2609 return (int)strtol( value->bv_val, NULL, 10 );
2615 unsigned int slapi_value_get_uint(const Slapi_Value *value)
2618 if ( value == NULL ) return 0;
2619 if ( value->bv_val == NULL ) return 0;
2620 if ( !checkBVString( value ) ) return 0;
2622 return (unsigned int)strtoul( value->bv_val, NULL, 10 );
2628 long slapi_value_get_long(const Slapi_Value *value)
2631 if ( value == NULL ) return 0;
2632 if ( value->bv_val == NULL ) return 0;
2633 if ( !checkBVString( value ) ) return 0;
2635 return strtol( value->bv_val, NULL, 10 );
2641 unsigned long slapi_value_get_ulong(const Slapi_Value *value)
2644 if ( value == NULL ) return 0;
2645 if ( value->bv_val == NULL ) return 0;
2646 if ( !checkBVString( value ) ) return 0;
2648 return strtoul( value->bv_val, NULL, 10 );
2654 size_t slapi_value_get_length(const Slapi_Value *value)
2657 if ( value == NULL )
2660 return (size_t) value->bv_len;
2666 int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2)
2669 return slapi_attr_value_cmp( a, v1, v2 );
2675 /* A ValueSet is a container for a BerVarray. */
2676 Slapi_ValueSet *slapi_valueset_new( void )
2681 vs = (Slapi_ValueSet *)slapi_ch_malloc( sizeof( *vs ) );
2690 void slapi_valueset_free(Slapi_ValueSet *vs)
2696 ber_bvarray_free( vp );
2697 slapi_ch_free( (void **)&vp );
2704 void slapi_valueset_init(Slapi_ValueSet *vs)
2707 if ( vs != NULL && *vs == NULL ) {
2708 *vs = (Slapi_ValueSet)slapi_ch_calloc( 1, sizeof(struct berval) );
2709 (*vs)->bv_val = NULL;
2715 void slapi_valueset_done(Slapi_ValueSet *vs)
2723 for ( vp = *vs; vp->bv_val != NULL; vp++ ) {
2725 slapi_ch_free( (void **)&vp->bv_val );
2727 /* but don't free *vs or vs */
2731 void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
2736 ber_dupbv( &bv, (Slapi_Value *)addval );
2737 ber_bvarray_add( vs, &bv );
2741 int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
2744 return slapi_valueset_next_value( vs, 0, v );
2750 int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
2761 for ( i = 0; vp[i].bv_val != NULL; i++ ) {
2772 int slapi_valueset_count( const Slapi_ValueSet *vs )
2783 for ( i = 0; vp[i].bv_val != NULL; i++ )
2793 void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
2798 for ( vp = *vs2; vp->bv_val != NULL; vp++ ) {
2799 slapi_valueset_add_value( vs1, vp );
2804 int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
2805 struct berval *val, int access )
2812 slap_access_t slap_access;
2813 AttributeDescription *ad = NULL;
2816 ret = slap_str2ad( attr, &ad, &text );
2817 if ( ret != LDAP_SUCCESS ) {
2821 switch ( access & SLAPI_ACL_ALL ) {
2822 case SLAPI_ACL_COMPARE:
2823 slap_access = ACL_COMPARE;
2825 case SLAPI_ACL_SEARCH:
2826 slap_access = ACL_SEARCH;
2828 case SLAPI_ACL_READ:
2829 slap_access = ACL_READ;
2831 case SLAPI_ACL_WRITE:
2832 case SLAPI_ACL_DELETE:
2834 case SLAPI_ACL_SELF:
2835 slap_access = ACL_WRITE;
2838 return LDAP_INSUFFICIENT_ACCESS;
2842 if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be ) != 0 ) {
2843 return LDAP_PARAM_ERROR;
2846 if ( slapi_pblock_get( pb, SLAPI_CONNECTION, (void *)&conn ) != 0 ) {
2847 return LDAP_PARAM_ERROR;
2850 if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&op ) != 0 ) {
2851 return LDAP_PARAM_ERROR;
2854 ret = access_allowed( be, conn, op, e, desc, val, slap_access, NULL );
2856 return ret ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
2858 return LDAP_UNWILLING_TO_PERFORM;
2862 int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf)
2870 Modifications *next;
2872 if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be ) != 0 ) {
2873 return LDAP_PARAM_ERROR;
2876 if ( slapi_pblock_get( pb, SLAPI_CONNECTION, (void *)&conn ) != 0 ) {
2877 return LDAP_PARAM_ERROR;
2880 if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&op ) != 0 ) {
2881 return LDAP_PARAM_ERROR;
2884 ml = slapi_x_ldapmods2modifications( mods );
2889 ret = acl_check_modlist( be, conn, op, e, ml );
2891 /* Careful when freeing the modlist because it has pointers into the mods array. */
2892 for ( ; ml != NULL; ml = next ) {
2893 next = ml->sml_next;
2895 /* just free the containing array */
2896 slapi_ch_free( (void **)&ml->sml_bvalues );
2897 slapi_ch_free( (void **)&ml );
2900 return ret ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
2902 return LDAP_UNWILLING_TO_PERFORM;
2907 * Synthesise an LDAPMod array from a Modifications list to pass
2908 * to SLAPI. This synthesis is destructive and as such the
2909 * Modifications list may not be used after calling this
2912 * This function must also be called before slap_mods_check().
2914 LDAPMod **slapi_x_modifications2ldapmods(Modifications **pmodlist)
2917 Modifications *ml, *modlist;
2918 LDAPMod **mods, *modp;
2921 modlist = *pmodlist;
2923 for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
2926 mods = (LDAPMod **)ch_malloc( (i + 1) * sizeof(LDAPMod *) );
2928 for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
2929 mods[i] = (LDAPMod *)ch_malloc( sizeof(LDAPMod) );
2931 modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
2933 /* Take ownership of original type. */
2934 modp->mod_type = ml->sml_type.bv_val;
2935 ml->sml_type.bv_val = NULL;
2937 if ( ml->sml_bvalues != NULL ) {
2938 for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ )
2940 modp->mod_bvalues = (struct berval **)ch_malloc( (j + 1) *
2941 sizeof(struct berval *) );
2942 for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ ) {
2943 /* Take ownership of original values. */
2944 modp->mod_bvalues[j] = (struct berval *)ch_malloc( sizeof(struct berval) );
2945 modp->mod_bvalues[j]->bv_len = ml->sml_bvalues[j].bv_len;
2946 modp->mod_bvalues[j]->bv_val = ml->sml_bvalues[j].bv_val;
2947 ml->sml_bvalues[j].bv_len = 0;
2948 ml->sml_bvalues[j].bv_val = NULL;
2950 modp->mod_bvalues[j] = NULL;
2952 modp->mod_bvalues = NULL;
2959 slap_mods_free( modlist );
2969 * Convert a potentially modified array of LDAPMods back to a
2970 * Modification list.
2972 * The returned Modification list contains pointers into the
2973 * LDAPMods array; the latter MUST be freed with
2974 * slapi_x_free_ldapmods() (see below).
2976 Modifications *slapi_x_ldapmods2modifications (LDAPMod **mods)
2979 Modifications *modlist, **modtail;
2984 for( modp = mods; *modp != NULL; modp++ ) {
2988 struct berval **bvp;
2990 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
2991 mod->sml_op = (*modp)->mod_op & (~LDAP_MOD_BVALUES);
2992 mod->sml_type.bv_val = (*modp)->mod_type;
2993 mod->sml_type.bv_len = strlen( mod->sml_type.bv_val );
2994 mod->sml_desc = NULL;
2995 mod->sml_next = NULL;
2997 if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) {
2998 for( i = 0, bvp = (*modp)->mod_bvalues; *bvp != NULL; bvp++, i++ )
3001 for( i = 0, p = (*modp)->mod_values; *p != NULL; p++, i++ )
3005 mod->sml_bvalues = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) );
3007 /* NB: This implicitly trusts a plugin to return valid modifications. */
3008 if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) {
3009 for( i = 0, bvp = (*modp)->mod_bvalues; *bvp != NULL; bvp++, i++ ) {
3010 mod->sml_bvalues[i].bv_val = (*bvp)->bv_val;
3011 mod->sml_bvalues[i].bv_len = (*bvp)->bv_len;
3014 for( i = 0, p = (*modp)->mod_values; *p != NULL; p++, i++ ) {
3015 mod->sml_bvalues[i].bv_val = *p;
3016 mod->sml_bvalues[i].bv_len = strlen( *p );
3019 mod->sml_bvalues[i].bv_val = NULL;
3022 modtail = &mod->sml_next;
3032 * This function only frees the parts of the mods array that
3033 * are not shared with the Modification list that was created
3034 * by slapi_x_ldapmods2modifications().
3037 void slapi_x_free_ldapmods (LDAPMod **mods)
3045 for ( i = 0; mods[i] != NULL; i++ ) {
3047 * Don't free values themselves; they're owned by the
3048 * Modification list. Do free the containing array.
3050 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
3051 for ( j = 0; mods[i]->mod_bvalues[j] != NULL; j++ ) {
3052 ch_free( mods[i]->mod_bvalues[j] );
3054 ch_free( mods[i]->mod_bvalues );
3056 ch_free( mods[i]->mod_values );
3058 /* Don't free type, for same reasons. */
3062 #endif /* LDAP_SLAPI */
3066 * Sun ONE DS 5.x computed attribute support. Computed attributes
3067 * allow for dynamically generated operational attributes, a very
3068 * useful thing indeed.
3072 * Write the computed attribute to a BerElement. Complementary
3073 * functions need to be defined for anything that replaces
3074 * op->o_callback->sc_sendentry, if you wish to make computed
3075 * attributes available to it.
3077 int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e)
3081 Connection *conn = NULL;
3082 Operation *op = NULL;
3084 AttributeDescription *desc;
3100 rc = slapi_pblock_get( c->cac_pb, SLAPI_BACKEND, (void *)&be );
3102 be = NULL; /* no backend for root DSE */
3105 rc = slapi_pblock_get( c->cac_pb, SLAPI_CONNECTION, (void *)&conn );
3106 if ( rc != 0 || conn == NULL ) {
3110 rc = slapi_pblock_get( c->cac_pb, SLAPI_OPERATION, (void *)&op );
3111 if ( rc != 0 || op == NULL ) {
3115 ber = (BerElement *)c->cac_private;
3118 if ( c->cac_attrs == NULL ) {
3119 /* All attrs request, skip operational attributes */
3120 if ( is_at_operational( desc->ad_type ) ) {
3124 /* Specific attrs requested */
3125 if ( is_at_operational( desc->ad_type ) ) {
3126 if ( !c->cac_opattrs && !ad_inlist( desc, c->cac_attrs ) ) {
3130 if ( !c->cac_userattrs && !ad_inlist( desc, c->cac_attrs ) ) {
3136 if ( !access_allowed( be, conn, op, e, desc, NULL, ACL_READ, &c->cac_acl_state) ) {
3137 slapi_log_error( SLAPI_LOG_ACL, "SLAPI_COMPUTE",
3138 "acl: access to attribute %s not allowed\n",
3139 desc->ad_cname.bv_val );
3143 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
3145 slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE",
3146 "ber_printf failed\n");
3150 if ( !c->cac_attrsonly ) {
3151 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
3152 if ( !access_allowed( be, conn, op, e,
3153 desc, &a->a_vals[i], ACL_READ, &c->cac_acl_state)) {
3154 slapi_log_error( SLAPI_LOG_ACL, "SLAPI_COMPUTE",
3155 "slapi_x_compute_output_ber: conn %lu "
3156 "acl: access to %s, value %d not allowed\n",
3157 op->o_connid, desc->ad_cname.bv_val, i );
3161 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
3162 slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE",
3163 "ber_printf failed\n");
3169 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
3170 slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE",
3171 "ber_printf failed\n" );
3182 * For some reason Sun don't use the normal plugin mechanism
3183 * registration path to register an "evaluator" function (an
3184 * "evaluator" is responsible for adding computed attributes;
3185 * the nomenclature is somewhat confusing).
3187 * As such slapi_compute_add_evaluator() registers the
3188 * function directly.
3190 int slapi_compute_add_evaluator(slapi_compute_callback_t function)
3193 Slapi_PBlock *pPlugin = NULL;
3196 pPlugin = slapi_pblock_new();
3197 if ( pPlugin == NULL ) {
3198 rc = LDAP_NO_MEMORY;
3202 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)SLAPI_PLUGIN_OBJECT );
3203 if ( rc != LDAP_SUCCESS ) {
3207 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (void *)function );
3208 if ( rc != LDAP_SUCCESS ) {
3212 rc = insertPlugin( NULL, pPlugin );
3219 if ( rc != LDAP_SUCCESS ) {
3220 if ( pPlugin != NULL ) {
3221 slapi_pblock_destroy( pPlugin );
3229 #endif /* LDAP_SLAPI */
3233 * See notes above regarding slapi_compute_add_evaluator().
3235 int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
3238 Slapi_PBlock *pPlugin = NULL;
3241 pPlugin = slapi_pblock_new();
3242 if ( pPlugin == NULL ) {
3243 rc = LDAP_NO_MEMORY;
3247 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)SLAPI_PLUGIN_OBJECT );
3248 if ( rc != LDAP_SUCCESS ) {
3252 rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, (void *)function );
3253 if ( rc != LDAP_SUCCESS ) {
3257 rc = insertPlugin( NULL, pPlugin );
3264 if ( rc != LDAP_SUCCESS ) {
3265 if ( pPlugin != NULL ) {
3266 slapi_pblock_destroy( pPlugin );
3274 #endif /* LDAP_SLAPI */
3278 * Call compute evaluators
3280 int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn)
3284 slapi_compute_callback_t *pGetPlugin, *tmpPlugin;
3286 rc = getAllPluginFuncs( NULL, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
3287 if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
3288 /* Nothing to do; front-end should ignore. */
3292 for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
3294 * -1: no attribute matched requested type
3295 * 0: one attribute matched
3296 * >0: error happened
3298 rc = (*pGetPlugin)( c, type, e, outputfn );
3304 slapi_ch_free( (void **)&tmpPlugin );
3309 #endif /* LDAP_SLAPI */
3312 int compute_rewrite_search_filter(Slapi_PBlock *pb)
3318 rc = slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be );
3323 return doPluginFNs( be, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
3326 #endif /* LDAP_SLAPI */
3330 * New API to provide the plugin with access to the search
3331 * pblock. Have informed Sun DS team.
3333 int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
3339 if ( c->cac_pb == NULL )
3347 #endif /* LDAP_SLAPI */
3350 Slapi_Mutex *slapi_new_mutex( void )
3355 m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) );
3356 if ( ldap_pvt_thread_mutex_init( &m->mutex ) != 0 ) {
3357 slapi_ch_free( (void **)&m );
3367 void slapi_destroy_mutex( Slapi_Mutex *mutex )
3370 if ( mutex != NULL ) {
3371 ldap_pvt_thread_mutex_destroy( &mutex->mutex );
3372 slapi_ch_free( (void **)&mutex);
3377 void slapi_lock_mutex( Slapi_Mutex *mutex )
3380 ldap_pvt_thread_mutex_lock( &mutex->mutex );
3384 int slapi_unlock_mutex( Slapi_Mutex *mutex )
3387 return ldap_pvt_thread_mutex_unlock( &mutex->mutex );
3393 Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
3398 if ( mutex == NULL ) {
3402 cv = (Slapi_CondVar *)slapi_ch_malloc( sizeof(*cv) );
3403 if ( ldap_pvt_thread_cond_init( &cv->cond ) != 0 ) {
3404 slapi_ch_free( (void **)&cv );
3408 /* XXX struct copy */
3409 cv->mutex = mutex->mutex;
3417 void slapi_destroy_condvar( Slapi_CondVar *cvar )
3420 if ( cvar != NULL ) {
3421 ldap_pvt_thread_cond_destroy( &cvar->cond );
3422 slapi_ch_free( (void **)&cvar );
3427 int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout )
3430 if ( cvar == NULL ) {
3434 return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex );
3440 int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
3443 if ( cvar == NULL ) {
3448 return ldap_pvt_thread_cond_broadcast( &cvar->cond );
3451 return ldap_pvt_thread_cond_signal( &cvar->cond );