Home | History | Annotate | Line # | Download | only in libldap
      1 /*	$NetBSD: turn.c,v 1.4 2025/09/05 21:16:22 christos Exp $	*/
      2 
      3 /* $OpenLDAP$ */
      4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      5  *
      6  * Copyright 2005-2024 The OpenLDAP Foundation.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted only as authorized by the OpenLDAP
     11  * Public License.
     12  *
     13  * A copy of this license is available in the file LICENSE in the
     14  * top-level directory of the distribution or, alternatively, at
     15  * <http://www.OpenLDAP.org/license.html>.
     16  */
     17 /* ACKNOWLEDGEMENTS:
     18  * This program was originally developed by Kurt D. Zeilenga for inclusion in
     19  * OpenLDAP Software.
     20  */
     21 
     22 /*
     23  * LDAPv3 Turn Operation Request
     24  */
     25 
     26 #include <sys/cdefs.h>
     27 __RCSID("$NetBSD: turn.c,v 1.4 2025/09/05 21:16:22 christos Exp $");
     28 
     29 #include "portable.h"
     30 
     31 #include <stdio.h>
     32 #include <ac/stdlib.h>
     33 
     34 #include <ac/socket.h>
     35 #include <ac/string.h>
     36 #include <ac/time.h>
     37 
     38 #include "ldap-int.h"
     39 #include "ldap_log.h"
     40 
     41 int
     42 ldap_turn(
     43 	LDAP *ld,
     44 	int mutual,
     45 	LDAP_CONST char* identifier,
     46 	LDAPControl **sctrls,
     47 	LDAPControl **cctrls,
     48 	int *msgidp )
     49 {
     50 #ifdef LDAP_EXOP_X_TURN
     51 	BerElement *turnvalber = NULL;
     52 	struct berval turnval;
     53 	int rc;
     54 
     55 	turnvalber = ber_alloc_t( LBER_USE_DER );
     56 	if( mutual ) {
     57 		ber_printf( turnvalber, "{bs}", mutual, identifier );
     58 	} else {
     59 		ber_printf( turnvalber, "{s}", identifier );
     60 	}
     61 	ber_flatten2( turnvalber, &turnval, 0 );
     62 
     63 	rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN,
     64 			&turnval, sctrls, cctrls, msgidp );
     65 	ber_free( turnvalber, 1 );
     66 	return rc;
     67 #else
     68 	return LDAP_CONTROL_NOT_FOUND;
     69 #endif
     70 }
     71 
     72 int
     73 ldap_turn_s(
     74 	LDAP *ld,
     75 	int mutual,
     76 	LDAP_CONST char* identifier,
     77 	LDAPControl **sctrls,
     78 	LDAPControl **cctrls )
     79 {
     80 #ifdef LDAP_EXOP_X_TURN
     81 	BerElement *turnvalber = NULL;
     82 	struct berval turnval;
     83 	int rc;
     84 
     85 	turnvalber = ber_alloc_t( LBER_USE_DER );
     86 	if( mutual ) {
     87 		ber_printf( turnvalber, "{bs}", 0xFF, identifier );
     88 	} else {
     89 		ber_printf( turnvalber, "{s}", identifier );
     90 	}
     91 	ber_flatten2( turnvalber, &turnval, 0 );
     92 
     93 	rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN,
     94 			&turnval, sctrls, cctrls, NULL, NULL );
     95 	ber_free( turnvalber, 1 );
     96 	return rc;
     97 #else
     98 	return LDAP_CONTROL_NOT_FOUND;
     99 #endif
    100 }
    101 
    102