Home | History | Annotate | Line # | Download | only in libldap
      1  1.3  christos /*	$NetBSD: turn.c,v 1.4 2025/09/05 21:16:22 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 2005-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 /* ACKNOWLEDGEMENTS:
     18  1.3  christos  * This program was originally developed by Kurt D. Zeilenga for inclusion in
     19  1.1     lukem  * OpenLDAP Software.
     20  1.1     lukem  */
     21  1.1     lukem 
     22  1.1     lukem /*
     23  1.1     lukem  * LDAPv3 Turn Operation Request
     24  1.1     lukem  */
     25  1.1     lukem 
     26  1.2  christos #include <sys/cdefs.h>
     27  1.3  christos __RCSID("$NetBSD: turn.c,v 1.4 2025/09/05 21:16:22 christos Exp $");
     28  1.2  christos 
     29  1.1     lukem #include "portable.h"
     30  1.1     lukem 
     31  1.1     lukem #include <stdio.h>
     32  1.1     lukem #include <ac/stdlib.h>
     33  1.1     lukem 
     34  1.1     lukem #include <ac/socket.h>
     35  1.1     lukem #include <ac/string.h>
     36  1.1     lukem #include <ac/time.h>
     37  1.1     lukem 
     38  1.1     lukem #include "ldap-int.h"
     39  1.1     lukem #include "ldap_log.h"
     40  1.1     lukem 
     41  1.1     lukem int
     42  1.1     lukem ldap_turn(
     43  1.1     lukem 	LDAP *ld,
     44  1.1     lukem 	int mutual,
     45  1.1     lukem 	LDAP_CONST char* identifier,
     46  1.1     lukem 	LDAPControl **sctrls,
     47  1.1     lukem 	LDAPControl **cctrls,
     48  1.1     lukem 	int *msgidp )
     49  1.1     lukem {
     50  1.1     lukem #ifdef LDAP_EXOP_X_TURN
     51  1.1     lukem 	BerElement *turnvalber = NULL;
     52  1.4  christos 	struct berval turnval;
     53  1.1     lukem 	int rc;
     54  1.1     lukem 
     55  1.1     lukem 	turnvalber = ber_alloc_t( LBER_USE_DER );
     56  1.1     lukem 	if( mutual ) {
     57  1.1     lukem 		ber_printf( turnvalber, "{bs}", mutual, identifier );
     58  1.1     lukem 	} else {
     59  1.1     lukem 		ber_printf( turnvalber, "{s}", identifier );
     60  1.1     lukem 	}
     61  1.4  christos 	ber_flatten2( turnvalber, &turnval, 0 );
     62  1.1     lukem 
     63  1.1     lukem 	rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN,
     64  1.4  christos 			&turnval, sctrls, cctrls, msgidp );
     65  1.1     lukem 	ber_free( turnvalber, 1 );
     66  1.1     lukem 	return rc;
     67  1.1     lukem #else
     68  1.1     lukem 	return LDAP_CONTROL_NOT_FOUND;
     69  1.1     lukem #endif
     70  1.1     lukem }
     71  1.1     lukem 
     72  1.1     lukem int
     73  1.1     lukem ldap_turn_s(
     74  1.1     lukem 	LDAP *ld,
     75  1.1     lukem 	int mutual,
     76  1.1     lukem 	LDAP_CONST char* identifier,
     77  1.1     lukem 	LDAPControl **sctrls,
     78  1.1     lukem 	LDAPControl **cctrls )
     79  1.1     lukem {
     80  1.1     lukem #ifdef LDAP_EXOP_X_TURN
     81  1.1     lukem 	BerElement *turnvalber = NULL;
     82  1.4  christos 	struct berval turnval;
     83  1.1     lukem 	int rc;
     84  1.1     lukem 
     85  1.1     lukem 	turnvalber = ber_alloc_t( LBER_USE_DER );
     86  1.1     lukem 	if( mutual ) {
     87  1.1     lukem 		ber_printf( turnvalber, "{bs}", 0xFF, identifier );
     88  1.1     lukem 	} else {
     89  1.1     lukem 		ber_printf( turnvalber, "{s}", identifier );
     90  1.1     lukem 	}
     91  1.4  christos 	ber_flatten2( turnvalber, &turnval, 0 );
     92  1.1     lukem 
     93  1.1     lukem 	rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN,
     94  1.4  christos 			&turnval, sctrls, cctrls, NULL, NULL );
     95  1.1     lukem 	ber_free( turnvalber, 1 );
     96  1.1     lukem 	return rc;
     97  1.1     lukem #else
     98  1.1     lukem 	return LDAP_CONTROL_NOT_FOUND;
     99  1.1     lukem #endif
    100  1.1     lukem }
    101  1.1     lukem 
    102