turn.c revision 1.1.1.2
1/* $NetBSD: turn.c,v 1.1.1.2 2010/03/08 02:14:20 lukem Exp $ */ 2 3/* OpenLDAP: pkg/ldap/libraries/libldap/turn.c,v 1.3.2.4 2009/01/22 00:00:56 kurt Exp */ 4/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 2005-2009 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 orignally developed by Kurt D. Zeilenga for inclusion in 19 * OpenLDAP Software. 20 */ 21 22/* 23 * LDAPv3 Turn Operation Request 24 */ 25 26#include "portable.h" 27 28#include <stdio.h> 29#include <ac/stdlib.h> 30 31#include <ac/socket.h> 32#include <ac/string.h> 33#include <ac/time.h> 34 35#include "ldap-int.h" 36#include "ldap_log.h" 37 38int 39ldap_turn( 40 LDAP *ld, 41 int mutual, 42 LDAP_CONST char* identifier, 43 LDAPControl **sctrls, 44 LDAPControl **cctrls, 45 int *msgidp ) 46{ 47#ifdef LDAP_EXOP_X_TURN 48 BerElement *turnvalber = NULL; 49 struct berval *turnvalp = NULL; 50 int rc; 51 52 turnvalber = ber_alloc_t( LBER_USE_DER ); 53 if( mutual ) { 54 ber_printf( turnvalber, "{bs}", mutual, identifier ); 55 } else { 56 ber_printf( turnvalber, "{s}", identifier ); 57 } 58 ber_flatten( turnvalber, &turnvalp ); 59 60 rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN, 61 turnvalp, sctrls, cctrls, msgidp ); 62 ber_free( turnvalber, 1 ); 63 return rc; 64#else 65 return LDAP_CONTROL_NOT_FOUND; 66#endif 67} 68 69int 70ldap_turn_s( 71 LDAP *ld, 72 int mutual, 73 LDAP_CONST char* identifier, 74 LDAPControl **sctrls, 75 LDAPControl **cctrls ) 76{ 77#ifdef LDAP_EXOP_X_TURN 78 BerElement *turnvalber = NULL; 79 struct berval *turnvalp = NULL; 80 int rc; 81 82 turnvalber = ber_alloc_t( LBER_USE_DER ); 83 if( mutual ) { 84 ber_printf( turnvalber, "{bs}", 0xFF, identifier ); 85 } else { 86 ber_printf( turnvalber, "{s}", identifier ); 87 } 88 ber_flatten( turnvalber, &turnvalp ); 89 90 rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN, 91 turnvalp, sctrls, cctrls, NULL, NULL ); 92 ber_free( turnvalber, 1 ); 93 return rc; 94#else 95 return LDAP_CONTROL_NOT_FOUND; 96#endif 97} 98 99