Home | History | Annotate | Line # | Download | only in libldap
      1  1.3  christos /*	$NetBSD: assertion.c,v 1.4 2025/09/05 21:16:21 christos Exp $	*/
      2  1.2  christos 
      3  1.2  christos /* $OpenLDAP$ */
      4  1.1     lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      5  1.1     lukem  *
      6  1.4  christos  * Copyright 1998-2024 The OpenLDAP Foundation.
      7  1.1     lukem  * All rights reserved.
      8  1.1     lukem  *
      9  1.1     lukem  * Redistribution and use in source and binary forms, with or without
     10  1.1     lukem  * modification, are permitted only as authorized by the OpenLDAP
     11  1.1     lukem  * Public License.
     12  1.1     lukem  *
     13  1.1     lukem  * A copy of this license is available in the file LICENSE in the
     14  1.1     lukem  * top-level directory of the distribution or, alternatively, at
     15  1.1     lukem  * <http://www.OpenLDAP.org/license.html>.
     16  1.1     lukem  */
     17  1.1     lukem 
     18  1.2  christos #include <sys/cdefs.h>
     19  1.3  christos __RCSID("$NetBSD: assertion.c,v 1.4 2025/09/05 21:16:21 christos Exp $");
     20  1.2  christos 
     21  1.1     lukem #include "portable.h"
     22  1.1     lukem 
     23  1.1     lukem #include <stdio.h>
     24  1.1     lukem #include <ac/stdlib.h>
     25  1.1     lukem #include <ac/string.h>
     26  1.1     lukem #include <ac/time.h>
     27  1.1     lukem 
     28  1.1     lukem #include "ldap-int.h"
     29  1.1     lukem 
     30  1.1     lukem int
     31  1.1     lukem ldap_create_assertion_control_value(
     32  1.1     lukem 	LDAP		*ld,
     33  1.1     lukem 	char		*assertion,
     34  1.1     lukem 	struct berval	*value )
     35  1.1     lukem {
     36  1.1     lukem 	BerElement		*ber = NULL;
     37  1.1     lukem 	int			err;
     38  1.1     lukem 
     39  1.2  christos 	ld->ld_errno = LDAP_SUCCESS;
     40  1.2  christos 
     41  1.1     lukem 	if ( assertion == NULL || assertion[ 0 ] == '\0' ) {
     42  1.1     lukem 		ld->ld_errno = LDAP_PARAM_ERROR;
     43  1.1     lukem 		return ld->ld_errno;
     44  1.1     lukem 	}
     45  1.1     lukem 
     46  1.1     lukem 	if ( value == NULL ) {
     47  1.1     lukem 		ld->ld_errno = LDAP_PARAM_ERROR;
     48  1.1     lukem 		return ld->ld_errno;
     49  1.1     lukem 	}
     50  1.1     lukem 
     51  1.1     lukem 	BER_BVZERO( value );
     52  1.1     lukem 
     53  1.1     lukem 	ber = ldap_alloc_ber_with_options( ld );
     54  1.1     lukem 	if ( ber == NULL ) {
     55  1.1     lukem 		ld->ld_errno = LDAP_NO_MEMORY;
     56  1.1     lukem 		return ld->ld_errno;
     57  1.1     lukem 	}
     58  1.1     lukem 
     59  1.1     lukem 	err = ldap_pvt_put_filter( ber, assertion );
     60  1.1     lukem 	if ( err < 0 ) {
     61  1.1     lukem 		ld->ld_errno = LDAP_ENCODING_ERROR;
     62  1.1     lukem 		goto done;
     63  1.1     lukem 	}
     64  1.1     lukem 
     65  1.1     lukem 	err = ber_flatten2( ber, value, 1 );
     66  1.1     lukem 	if ( err < 0 ) {
     67  1.1     lukem 		ld->ld_errno = LDAP_NO_MEMORY;
     68  1.1     lukem 		goto done;
     69  1.1     lukem 	}
     70  1.1     lukem 
     71  1.1     lukem done:;
     72  1.1     lukem 	if ( ber != NULL ) {
     73  1.1     lukem 		ber_free( ber, 1 );
     74  1.1     lukem 	}
     75  1.1     lukem 
     76  1.1     lukem 	return ld->ld_errno;
     77  1.1     lukem }
     78  1.1     lukem 
     79  1.1     lukem int
     80  1.1     lukem ldap_create_assertion_control(
     81  1.1     lukem 	LDAP		*ld,
     82  1.1     lukem 	char		*assertion,
     83  1.1     lukem 	int		iscritical,
     84  1.1     lukem 	LDAPControl	**ctrlp )
     85  1.1     lukem {
     86  1.1     lukem 	struct berval	value;
     87  1.1     lukem 
     88  1.1     lukem 	if ( ctrlp == NULL ) {
     89  1.1     lukem 		ld->ld_errno = LDAP_PARAM_ERROR;
     90  1.1     lukem 		return ld->ld_errno;
     91  1.1     lukem 	}
     92  1.1     lukem 
     93  1.1     lukem 	ld->ld_errno = ldap_create_assertion_control_value( ld,
     94  1.1     lukem 		assertion, &value );
     95  1.1     lukem 	if ( ld->ld_errno == LDAP_SUCCESS ) {
     96  1.1     lukem 		ld->ld_errno = ldap_control_create( LDAP_CONTROL_ASSERT,
     97  1.1     lukem 			iscritical, &value, 0, ctrlp );
     98  1.1     lukem 		if ( ld->ld_errno != LDAP_SUCCESS ) {
     99  1.1     lukem 			LDAP_FREE( value.bv_val );
    100  1.1     lukem 		}
    101  1.1     lukem 	}
    102  1.1     lukem 
    103  1.1     lukem 	return ld->ld_errno;
    104  1.1     lukem }
    105  1.1     lukem 
    106