No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / assertion.c
blob2e46f7ca6b32508ee455987a74376a55d4db5cd8
1 /* $OpenLDAP: pkg/ldap/libraries/libldap/assertion.c,v 1.1.2.1 2008/07/09 00:29:57 quanah Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 #include "portable.h"
18 #include <stdio.h>
19 #include <ac/stdlib.h>
20 #include <ac/string.h>
21 #include <ac/time.h>
23 #include "ldap-int.h"
25 int
26 ldap_create_assertion_control_value(
27 LDAP *ld,
28 char *assertion,
29 struct berval *value )
31 BerElement *ber = NULL;
32 int err;
34 if ( assertion == NULL || assertion[ 0 ] == '\0' ) {
35 ld->ld_errno = LDAP_PARAM_ERROR;
36 return ld->ld_errno;
39 if ( value == NULL ) {
40 ld->ld_errno = LDAP_PARAM_ERROR;
41 return ld->ld_errno;
44 BER_BVZERO( value );
46 ber = ldap_alloc_ber_with_options( ld );
47 if ( ber == NULL ) {
48 ld->ld_errno = LDAP_NO_MEMORY;
49 return ld->ld_errno;
52 err = ldap_pvt_put_filter( ber, assertion );
53 if ( err < 0 ) {
54 ld->ld_errno = LDAP_ENCODING_ERROR;
55 goto done;
58 err = ber_flatten2( ber, value, 1 );
59 if ( err < 0 ) {
60 ld->ld_errno = LDAP_NO_MEMORY;
61 goto done;
64 done:;
65 if ( ber != NULL ) {
66 ber_free( ber, 1 );
69 return ld->ld_errno;
72 int
73 ldap_create_assertion_control(
74 LDAP *ld,
75 char *assertion,
76 int iscritical,
77 LDAPControl **ctrlp )
79 struct berval value;
81 if ( ctrlp == NULL ) {
82 ld->ld_errno = LDAP_PARAM_ERROR;
83 return ld->ld_errno;
86 ld->ld_errno = ldap_create_assertion_control_value( ld,
87 assertion, &value );
88 if ( ld->ld_errno == LDAP_SUCCESS ) {
89 ld->ld_errno = ldap_control_create( LDAP_CONTROL_ASSERT,
90 iscritical, &value, 0, ctrlp );
91 if ( ld->ld_errno != LDAP_SUCCESS ) {
92 LDAP_FREE( value.bv_val );
96 return ld->ld_errno;