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.
14 #include "slapi_common.h"
24 struct berval *ns_get_supported_extop( int );
27 #include <sys/systeminfo.h>
33 * server start time (should we use a struct timeval also in slapd?
35 static struct timeval base_time;
36 ldap_pvt_thread_mutex_t slapi_hn_mutex;
37 ldap_pvt_thread_mutex_t slapi_time_mutex;
40 * This function converts an array of pointers to berval objects to
41 * an array of berval objects.
46 struct berval **bvptr,
49 int rc = LDAP_SUCCESS;
53 if ( bvptr == NULL || *bvptr == NULL ) {
57 for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
61 tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
62 if ( tmpberval == NULL ) {
63 return LDAP_NO_MEMORY;
66 for ( i = 0; bvptr[i] != NULL; i++ ) {
67 tmpberval[i].bv_val = bvptr[i]->bv_val;
68 tmpberval[i].bv_len = bvptr[i]->bv_len;
71 if ( rc == LDAP_SUCCESS ) {
83 #if defined(LDAP_SLAPI)
84 Slapi_Entry *e = NULL;
87 pTmpS = slapi_ch_strdup( s );
88 if ( pTmpS != NULL ) {
89 e = str2entry( pTmpS );
90 slapi_ch_free( (void **)&pTmpS );
94 #else /* !defined(LDAP_SLAPI) */
96 #endif /* !defined(LDAP_SLAPI) */
104 #if defined(LDAP_SLAPI)
107 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
108 ret = entry2str( e, len );
109 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
112 #else /* !defined(LDAP_SLAPI) */
114 #endif /* !defined(LDAP_SLAPI) */
118 slapi_entry_get_dn( Slapi_Entry *e )
120 #if defined(LDAP_SLAPI)
121 return e->e_name.bv_val;
122 #else /* !defined(LDAP_SLAPI) */
124 #endif /* !defined(LDAP_SLAPI) */
132 #if defined(LDAP_SLAPI)
133 struct berval dn = { 0, NULL };
136 dn.bv_len = strlen( ldn );
138 dnPrettyNormal( NULL, &dn, &e->e_name, &e->e_nname );
139 #endif /* defined(LDAP_SLAPI) */
143 slapi_entry_dup( Slapi_Entry *e )
145 #if defined(LDAP_SLAPI)
150 tmp = slapi_entry2str( e, &len );
152 return (Slapi_Entry *)NULL;
155 tmpEnt = (Slapi_Entry *)str2entry( tmp );
156 if ( tmpEnt == NULL ) {
157 slapi_ch_free( (void **)&tmp );
158 return (Slapi_Entry *)NULL;
162 slapi_ch_free( (void **)&tmp );
166 #else /* !defined(LDAP_SLAPI) */
168 #endif /* !defined(LDAP_SLAPI) */
172 slapi_entry_attr_delete(
176 #if defined(LDAP_SLAPI)
177 AttributeDescription *ad;
180 if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) {
181 return 1; /* LDAP_NO_SUCH_ATTRIBUTE */
184 if ( attr_delete( &e->e_attrs, ad ) == LDAP_SUCCESS ) {
185 return 0; /* attribute is deleted */
187 return -1; /* something went wrong */
189 #else /* !defined(LDAP_SLAPI) */
191 #endif /* !defined(LDAP_SLAPI) */
195 slapi_entry_alloc( void )
197 #if defined(LDAP_SLAPI)
198 return (Slapi_Entry *)slapi_ch_calloc( 1, sizeof(Slapi_Entry) );
199 #else /* !defined(LDAP_SLAPI) */
201 #endif /* !defined(LDAP_SLAPI) */
205 slapi_entry_free( Slapi_Entry *e )
207 #if defined(LDAP_SLAPI)
209 #endif /* defined(LDAP_SLAPI) */
213 slapi_entry_attr_merge(
216 struct berval **vals )
218 #if defined(LDAP_SLAPI)
219 AttributeDescription *ad;
224 rc = bvptr2obj( vals, &bv );
225 if ( rc != LDAP_SUCCESS ) {
229 rc = slap_str2ad( type, &ad, &text );
230 if ( rc != LDAP_SUCCESS ) {
234 rc = attr_merge( e, ad, bv );
238 #else /* !defined(LDAP_SLAPI) */
240 #endif /* !defined(LDAP_SLAPI) */
244 slapi_entry_attr_find(
249 #if defined(LDAP_SLAPI)
250 AttributeDescription *ad;
254 rc = slap_str2ad( type, &ad, &text );
255 if ( rc != LDAP_SUCCESS ) {
259 *attr = attr_find( e->e_attrs, ad );
260 if ( *attr == NULL ) {
265 #else /* !defined(LDAP_SLAPI) */
267 #endif /* !defined(LDAP_SLAPI) */
271 * FIXME -- The caller must free the allocated memory.
272 * In Netscape they do not have to.
275 slapi_attr_get_values(
277 struct berval ***vals )
279 #if defined(LDAP_SLAPI)
283 if ( attr == NULL ) {
287 for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
291 bv = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
292 for ( j = 0; j < i; j++ ) {
293 bv[j] = (struct berval *)ch_malloc( sizeof(struct berval) );
294 bv[j]->bv_val = ch_strdup( attr->a_vals[j].bv_val );
295 bv[j]->bv_len = attr->a_vals[j].bv_len;
299 *vals = (struct berval **)bv;
302 #else /* !defined(LDAP_SLAPI) */
304 #endif /* !defined(LDAP_SLAPI) */
308 slapi_dn_normalize( char *dn )
310 #if defined(LDAP_SLAPI)
314 assert( dn != NULL );
317 bdn.bv_len = strlen( dn );
319 dnNormalize2( NULL, &bdn, &ndn );
322 * FIXME: ain't it safe to set dn = ndn.bv_val ?
324 dn = ch_strdup( ndn.bv_val );
325 ch_free( ndn.bv_val );
328 #else /* !defined(LDAP_SLAPI) */
330 #endif /* !defined(LDAP_SLAPI) */
334 * FIXME: this function is dangerous and should be deprecated;
335 * DN normalization is a lot more than lower-casing, and BTW
336 * OpenLDAP's DN normalization for case insensitive attributes
337 * is already lower case
340 slapi_dn_normalize_case( char *dn )
342 #if defined(LDAP_SLAPI)
343 slapi_dn_normalize( dn );
344 ldap_pvt_str2lower( dn );
347 #else /* defined(LDAP_SLAPI) */
349 #endif /* defined(LDAP_SLAPI) */
357 #if defined(LDAP_SLAPI)
358 struct berval bdn, ndn;
359 struct berval bsuffix, nsuffix;
361 assert( dn != NULL );
362 assert( suffix != NULL );
365 bdn.bv_len = strlen( dn );
367 bsuffix.bv_val = suffix;
368 bsuffix.bv_len = strlen( suffix );
370 dnNormalize2( NULL, &bdn, &ndn );
371 dnNormalize2( NULL, &bsuffix, &nsuffix );
373 return dnIsSuffix( &ndn, &nsuffix );
374 #else /* !defined(LDAP_SLAPI) */
376 #endif /* !defined(LDAP_SLAPI) */
380 slapi_dn_ignore_case( char *dn )
382 #if defined(LDAP_SLAPI)
383 return slapi_dn_normalize_case( dn );
384 #else /* !defined(LDAP_SLAPI) */
386 #endif /* !defined(LDAP_SLAPI) */
390 slapi_ch_malloc( unsigned long size )
392 #if defined(LDAP_SLAPI)
393 return ch_malloc( size );
394 #else /* !defined(LDAP_SLAPI) */
396 #endif /* !defined(LDAP_SLAPI) */
400 slapi_ch_free( void **ptr )
402 #if defined(LDAP_SLAPI)
405 #endif /* defined(LDAP_SLAPI) */
413 #if defined(LDAP_SLAPI)
414 return ch_calloc( nelem, size );
415 #else /* !defined(LDAP_SLAPI) */
417 #endif /* !defined(LDAP_SLAPI) */
425 #if defined(LDAP_SLAPI)
426 return ch_realloc( block, size );
427 #else /* !defined(LDAP_SLAPI) */
429 #endif /* !defined(LDAP_SLAPI) */
433 slapi_ch_strdup( char *s )
435 #if defined(LDAP_SLAPI)
436 return ch_strdup( (const char *)s );
437 #else /* !defined(LDAP_SLAPI) */
439 #endif /* !defined(LDAP_SLAPI) */
443 slapi_ch_stlen( char *s )
445 #if defined(LDAP_SLAPI)
446 return strlen( (const char *)s );
447 #else /* !defined(LDAP_SLAPI) */
449 #endif /* !defined(LDAP_SLAPI) */
453 slapi_control_present(
454 LDAPControl **controls,
459 #if defined(LDAP_SLAPI)
471 for ( i = 0; controls != NULL && controls[i] != NULL; i++ ) {
472 if ( strcmp( controls[i]->ldctl_oid, oid ) != 0 ) {
477 if ( controls[i]->ldctl_value.bv_len != 0 ) {
479 * FIXME: according to 6.1 specification,
480 * "The val output parameter is set
481 * to point into the controls array.
482 * A copy of the control value is
486 struct berval *pTmpBval;
488 pTmpBval = (struct berval *)slapi_ch_malloc( sizeof(struct berval));
489 if ( pTmpBval == NULL ) {
492 pTmpBval->bv_len = controls[i]->ldctl_value.bv_len;
493 pTmpBval->bv_val = controls[i]->ldctl_value.bv_val;
497 slapi_ch_free( (void **)&pTmpBval );
503 *val = &controls[i]->ldctl_value;
508 *iscritical = controls[i]->ldctl_iscritical;
515 #else /* !defined(LDAP_SLAPI) */
517 #endif /* !defined(LDAP_SLAPI) */
521 slapi_register_supported_control(
523 unsigned long controlops )
525 #if defined(LDAP_SLAPI)
526 /* FIXME -- can not add controls to openLDAP dynamically */
527 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_CONTROLS",
528 "can not add controls to openLDAP dynamically\n" );
529 #endif /* defined(LDAP_SLAPI) */
533 slapi_get_supported_controls(
535 unsigned long **ctrlopsp )
537 #if defined(LDAP_SLAPI)
541 unsigned long *masks = NULL;
543 for (n = 0; get_supported_ctrl( n ) != NULL; n++) {
555 oids = (char **)slapi_ch_malloc( (n + 1) * sizeof(char *) );
556 if ( oids == NULL ) {
561 masks = (unsigned long *)slapi_ch_malloc( n * sizeof(int) );
562 if ( masks == NULL ) {
567 for ( i = 0; i < n; i++ ) {
569 * FIXME: Netscape's specification says nothing about
570 * memory; should we copy the OIDs or return pointers
571 * to internal values? In OpenLDAP the latter is safe
572 * since we do not allow to register coltrols runtime
574 oids[ i ] = ch_strdup( get_supported_ctrl( i ) );
575 if ( oids[ i ] == NULL ) {
579 masks[ i ] = (unsigned long)get_supported_ctrl_mask( i );
587 if ( rc != LDAP_SUCCESS ) {
588 for ( i = 0; oids != NULL && oids[ i ] != NULL; i++ ) {
589 ch_free( oids[ i ] );
596 #else /* !defined(LDAP_SLAPI) */
598 #endif /* !defined(LDAP_SLAPI) */
602 slapi_register_supported_saslmechanism( char *mechanism )
604 #if defined(LDAP_SLAPI)
605 /* FIXME -- can not add saslmechanism to openLDAP dynamically */
606 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL",
607 "can not add saslmechanism to openLDAP dynamically\n" );
608 #endif /* defined(LDAP_SLAPI) */
612 slapi_get_supported_saslmechanisms( void )
614 #if defined(LDAP_SLAPI)
615 /* FIXME -- can not get the saslmechanism wihtout a connection. */
616 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL",
617 "can not get the saslmechanism "
618 "wihtout a connection\n" );
620 #else /* defined(LDAP_SLAPI) */
622 #endif /* defined(LDAP_SLAPI) */
626 slapi_get_supported_extended_ops( void )
628 #if defined(LDAP_SLAPI)
630 char **ppExtOpOID = NULL;
633 for ( i = 0; get_supported_extop( i ) != NULL; i++ ) {
637 for ( j = 0; ns_get_supported_extop( j ) != NULL; j++ ) {
642 if ( numExtOps == 0 ) {
646 ppExtOpOID = (char **)slapi_ch_malloc( (numExtOps + 1) * sizeof(char *) );
647 for ( k = 0; k < i; k++ ) {
650 bv = get_supported_extop( k );
651 assert( bv != NULL );
653 ppExtOpOID[ k ] = bv->bv_val;
656 for ( ; k < j; k++ ) {
659 bv = ns_get_supported_extop( k );
660 assert( bv != NULL );
662 ppExtOpOID[ i + k ] = bv->bv_val;
664 ppExtOpOID[ i + k ] = NULL;
667 #else /* !defined(LDAP_SLAPI) */
669 #endif /* !defined(LDAP_SLAPI) */
673 slapi_send_ldap_result(
679 struct berval **urls )
681 #if defined(LDAP_SLAPI)
686 struct berval *extValue = NULL;
689 slapi_pblock_get( pb, SLAPI_CONNECTION, &conn );
690 slapi_pblock_get( pb, SLAPI_OPERATION, &op );
691 if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
692 slapi_pblock_get( pb, SLAPI_BIND_RET_SASLCREDS, &s );
693 rc = LDAP_SASL_BIND_IN_PROGRESS;
694 send_ldap_sasl( conn, op, rc, NULL, NULL, NULL, NULL, s );
698 slapi_pblock_get( pb, SLAPI_EXT_OP_RET_OID, &extOID );
699 if ( extOID != NULL ) {
700 slapi_pblock_get( pb, SLAPI_EXT_OP_RET_VALUE, &extValue );
701 slapi_send_ldap_extended_response( conn, op, err, extOID,
706 slapi_pblock_set( pb, SLAPI_RESULT_CODE, (void *)err);
707 slapi_pblock_set( pb, SLAPI_RESULT_MATCHED, ( matched != NULL ) ? (void *)ch_strdup( matched ) : NULL );
708 slapi_pblock_set( pb, SLAPI_RESULT_TEXT, ( text != NULL ) ? (void *)ch_strdup( text ) : NULL );
710 send_ldap_result( conn, op, err, matched, text, NULL, NULL );
711 #endif /* defined(LDAP_SLAPI) */
715 slapi_send_ldap_search_entry(
718 LDAPControl **ectrls,
722 #if defined(LDAP_SLAPI)
729 AttributeName *an = NULL;
732 for ( i = 0; attrs[ i ] != NULL; i++ ) {
737 an = (AttributeName *) ch_malloc( i * sizeof(AttributeName) );
738 for ( i = 0; attrs[i] != NULL; i++ ) {
739 an[i].an_name.bv_val = ch_strdup( attrs[i] );
740 an[i].an_name.bv_len = strlen( attrs[i] );
741 an[i].an_desc = NULL;
742 if( slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text ) != LDAP_SUCCESS)
747 if ( ( rc = slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be ) != 0 ) ||
748 ( rc = slapi_pblock_get( pb, SLAPI_CONNECTION, (void *)&pConn) != 0 ) ||
749 ( rc = slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp) != 0 ) ) {
752 rc = send_search_entry( be, pConn, pOp, e, an, attrsonly, NULL );
757 #else /* !defined(LDAP_SLAPI) */
759 #endif /* !defined(LDAP_SLAPI) */
764 slapi_str2filter( char *str )
766 #if defined(LDAP_SLAPI)
767 return str2filter( str );
768 #else /* !defined(LDAP_SLAPI) */
770 #endif /* !defined(LDAP_SLAPI) */
778 #if defined(LDAP_SLAPI)
780 #endif /* defined(LDAP_SLAPI) */
784 slapi_filter_get_choice( Slapi_Filter *f )
786 #if defined(LDAP_SLAPI)
796 #else /* !defined(LDAP_SLAPI) */
797 return -1; /* invalid filter type */
798 #endif /* !defined(LDAP_SLAPI) */
802 slapi_filter_get_ava(
805 struct berval **bval )
807 #if defined(LDAP_SLAPI)
809 int rc = LDAP_SUCCESS;
811 assert( type != NULL );
812 assert( bval != NULL );
818 if ( ftype == LDAP_FILTER_EQUALITY
819 || ftype == LDAP_FILTER_GE
820 || ftype == LDAP_FILTER_LE
821 || ftype == LDAP_FILTER_APPROX ) {
822 *type = slapi_ch_strdup( f->f_un.f_un_ava->aa_desc->ad_cname.bv_val );
823 if ( *type == NULL ) {
828 *bval = (struct berval *)slapi_ch_malloc( sizeof(struct berval) );
829 if ( *bval == NULL ) {
834 (*bval)->bv_len = f->f_un.f_un_ava->aa_value.bv_len;
835 (*bval)->bv_val = slapi_ch_strdup( f->f_un.f_un_ava->aa_value.bv_val );
836 if ( (*bval)->bv_val == NULL ) {
840 } else { /* filter type not supported */
845 if ( rc != LDAP_SUCCESS ) {
858 #else /* !defined(LDAP_SLAPI) */
860 #endif /* !defined(LDAP_SLAPI) */
864 slapi_filter_list_first( Slapi_Filter *f )
866 #if defined(LDAP_SLAPI)
874 if ( ftype == LDAP_FILTER_AND
875 || ftype == LDAP_FILTER_OR
876 || ftype == LDAP_FILTER_NOT ) {
877 return (Slapi_Filter *)f->f_and;
881 #else /* !defined(LDAP_SLAPI) */
883 #endif /* !defined(LDAP_SLAPI) */
887 slapi_filter_list_next(
889 Slapi_Filter *fprev )
891 #if defined(LDAP_SLAPI)
899 if ( ftype == LDAP_FILTER_AND
900 || ftype == LDAP_FILTER_OR
901 || ftype == LDAP_FILTER_NOT ) {
902 if ( f->f_and == fprev ) {
903 return f->f_and->f_next;
908 #else /* !defined(LDAP_SLAPI) */
910 #endif /* !defined(LDAP_SLAPI) */
914 slapi_send_ldap_extended_response(
919 struct berval *response )
921 #if defined(LDAP_SLAPI)
922 send_ldap_extended( conn,op, errornum, NULL, NULL, NULL,
923 respName,response, NULL );
925 #else /* !defined(LDAP_SLAPI) */
927 #endif /* !defined(LDAP_SLAPI) */
932 struct berval **vals,
935 #if defined(LDAP_SLAPI)
937 * FIXME: what's the point?
940 #else /* !defined(LDAP_SLAPI) */
942 #endif /* !defined(LDAP_SLAPI) */
946 slapi_get_hostname( void )
948 #if defined(LDAP_SLAPI)
952 * FIXME: I'd prefer a different check ...
955 hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
957 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
958 "can't malloc memory for hostname\n" );
961 } else if ( sysinfo( SI_HOSTNAME, hn, MAX_HOSTNAME ) < 0 ) {
962 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
963 "can't get hostname\n" );
964 slapi_ch_free( (void **)&hn );
968 static int been_here = 0;
969 static char *static_hn = NULL;
971 ldap_pvt_thread_mutex_lock( &slapi_hn_mutex );
973 static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME );
974 if ( static_hn == NULL) {
975 slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO",
976 "can't malloc memory for hostname\n" );
978 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
983 if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) {
984 slapi_log_error( SLAPI_LOG_FATAL,
986 "can't get hostname\n" );
987 slapi_ch_free( (void **)&static_hn );
989 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
998 ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex );
1000 hn = ch_strdup( static_hn );
1001 #endif /* !_SPARC */
1004 #else /* !defined(LDAP_SLAPI) */
1006 #endif /* !defined(LDAP_SLAPI) */
1010 * FIXME: this should go in an appropriate header ...
1012 extern int vLogError( int level, char *subsystem, char *fmt, va_list arglist );
1021 #if defined(LDAP_SLAPI)
1022 int rc = LDAP_SUCCESS;
1025 va_start( arglist, fmt );
1026 rc = vLogError( severity, subsystem, fmt, arglist );
1030 #else /* !defined(LDAP_SLAPI) */
1032 #endif /* !defined(LDAP_SLAPI) */
1037 slapi_timer_current_time( void )
1039 #if defined(LDAP_SLAPI)
1040 static int first_time = 1;
1041 #if !defined (_WIN32)
1045 ldap_pvt_thread_mutex_lock( &slapi_time_mutex );
1048 gettimeofday( &base_time, NULL );
1050 gettimeofday( &now, NULL );
1051 ret = ( now.tv_sec - base_time.tv_sec ) * 1000000 +
1052 (now.tv_usec - base_time.tv_usec);
1053 ldap_pvt_thread_mutex_unlock( &slapi_time_mutex );
1059 return (slap_get_time() - starttime) * 1000000;
1066 performance_counter_present = QueryPerformanceCounter( &base_time );
1067 QueryPerformanceFrequency( &performance_freq );
1070 if ( !performance_counter_present )
1073 QueryPerformanceCounter( &now );
1074 return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
1076 #else /* !defined(LDAP_SLAPI) */
1078 #endif /* !defined(LDAP_SLAPI) */
1085 slapi_timer_get_time( char *label )
1087 #if defined(LDAP_SLAPI)
1088 unsigned long start = slapi_timer_current_time();
1089 printf("%10ld %10ld usec %s\n", start, 0, label);
1091 #else /* !defined(LDAP_SLAPI) */
1093 #endif /* !defined(LDAP_SLAPI) */
1100 slapi_timer_elapsed_time(
1102 unsigned long start )
1104 #if defined(LDAP_SLAPI)
1105 unsigned long stop = slapi_timer_current_time();
1106 printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
1107 #endif /* defined(LDAP_SLAPI) */
1111 slapi_free_search_results_internal( Slapi_PBlock *pb )
1113 #if defined(LDAP_SLAPI)
1114 Slapi_Entry **entries;
1115 int k = 0, nEnt = 0;
1117 slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
1118 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
1123 if ( entries == NULL ) {
1127 for ( k = 0; k < nEnt; k++ ) {
1128 slapi_entry_free( entries[k] );
1131 slapi_ch_free( (void **)&entries );
1132 #endif /* defined(LDAP_SLAPI) */
1136 * Internal API to prime a Slapi_PBlock with a Backend.
1138 int slapi_backend_set_pb( Slapi_PBlock *pb, Backend *be )
1140 #if defined(LDAP_SLAPI)
1143 rc = slapi_pblock_set(pb, SLAPI_BACKEND, (void *)be);
1144 if (rc != LDAP_SUCCESS)
1147 rc = slapi_pblock_set(pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type);
1148 if (rc != LDAP_SUCCESS)
1151 return LDAP_SUCCESS;
1154 #endif /* defined(LDAP_SLAPI) */
1158 * Internal API to prime a Slapi_PBlock with a Connection.
1160 int slapi_connection_set_pb( Slapi_PBlock *pb, Connection *conn )
1162 #if defined(LDAP_SLAPI)
1167 rc = slapi_pblock_set(pb, SLAPI_CONNECTION, (void *)conn);
1168 if (rc != LDAP_SUCCESS)
1171 rc = slapi_pblock_set(pb, SLAPI_CONN_ID, (void *)conn->c_connid);
1172 if (rc != LDAP_SUCCESS)
1175 switch (conn->c_authz.sai_method) {
1176 case LDAP_AUTH_SASL:
1177 len = sizeof(SLAPD_AUTH_SASL) + conn->c_authz.sai_mech.bv_len;
1178 connAuthType = slapi_ch_malloc(len);
1179 snprintf(connAuthType, len, "%s%s", SLAPD_AUTH_SASL, conn->c_authz.sai_mech.bv_val);
1181 case LDAP_AUTH_SIMPLE:
1182 connAuthType = slapi_ch_strdup(SLAPD_AUTH_SIMPLE);
1184 case LDAP_AUTH_NONE:
1185 connAuthType = slapi_ch_strdup(SLAPD_AUTH_NONE);
1188 connAuthType = NULL;
1191 if (conn->c_is_tls && connAuthType == NULL) {
1192 connAuthType = slapi_ch_strdup(SLAPD_AUTH_SSL);
1194 if (connAuthType != NULL) {
1195 rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHTYPE, (void *)connAuthType);
1196 if (rc != LDAP_SUCCESS)
1199 if (conn->c_authz.sai_dn.bv_val != NULL) {
1200 char *connDn = slapi_ch_strdup(conn->c_authz.sai_dn.bv_val);
1201 rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)connDn);
1202 if (rc != LDAP_SUCCESS)
1205 return LDAP_SUCCESS;
1208 #endif /* defined(LDAP_SLAPI) */
1212 * Internal API to prime a Slapi_PBlock with an Operation.
1214 int slapi_operation_set_pb( Slapi_PBlock *pb, Operation *op )
1216 #if defined(LDAP_SLAPI)
1222 if (slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&be) != 0) {
1226 isRoot = be_isroot(be, &op->o_ndn);
1227 isUpdateDn = be_isupdate(be, &op->o_ndn);
1230 rc = slapi_pblock_set(pb, SLAPI_OPERATION, (void *)op);
1231 if (rc != LDAP_SUCCESS)
1234 rc = slapi_pblock_set(pb, SLAPI_OPINITIATED_TIME, (void *)op->o_time);
1235 if (rc != LDAP_SUCCESS)
1238 rc = slapi_pblock_set(pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot);
1239 if (rc != LDAP_SUCCESS)
1242 rc = slapi_pblock_set(pb, SLAPI_REQUESTOR_ISUPDATEDN, (void *)isUpdateDn);
1243 if (rc != LDAP_SUCCESS)
1246 rc = slapi_pblock_set(pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls);
1247 if (rc != LDAP_SUCCESS)
1250 rc = slapi_pblock_set(pb, SLAPI_REQUESTOR_DN, (void *)op->o_ndn.bv_val);
1251 if (rc != LDAP_SUCCESS)
1254 return LDAP_SUCCESS;
1260 int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
1262 #if defined( LDAP_SLAPI )
1265 slapi_pblock_get( pb, SLAPI_CONNECTION, &conn );
1266 *isSSL = conn->c_is_tls;
1268 return LDAP_SUCCESS;
1271 #endif /* defined(LDAP_SLAPI) */