+static int
+send_ldap_controls( BerElement *ber, LDAPControl **c )
+{
+ int rc;
+ if( c == NULL ) return 0;
+
+ rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
+ if( rc == -1 ) return rc;
+
+ for( ; *c != NULL; c++) {
+ rc = ber_printf( ber, "{s" /*}*/, (*c)->ldctl_oid );
+
+ if( (*c)->ldctl_iscritical ) {
+ rc = ber_printf( ber, "b",
+ (ber_int_t) (*c)->ldctl_iscritical ) ;
+ if( rc == -1 ) return rc;
+ }
+
+ if( (*c)->ldctl_value.bv_val != NULL ) {
+ rc = ber_printf( ber, "O", &((*c)->ldctl_value));
+ if( rc == -1 ) return rc;
+ }
+
+ rc = ber_printf( ber, /*{*/"N}" );
+ if( rc == -1 ) return rc;
+ }
+
+ rc = ber_printf( ber, /*{*/"N}" );
+
+ return rc;
+}
+