Back to index

openldap  2.4.31
turn.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 2005-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 /* ACKNOWLEDGEMENTS:
00016  * This program was orignally developed by Kurt D. Zeilenga for inclusion in
00017  * OpenLDAP Software.
00018  */
00019 
00020 /*
00021  * LDAPv3 Turn Operation Request
00022  */
00023 
00024 #include "portable.h"
00025 
00026 #include <stdio.h>
00027 #include <ac/stdlib.h>
00028 
00029 #include <ac/socket.h>
00030 #include <ac/string.h>
00031 #include <ac/time.h>
00032 
00033 #include "ldap-int.h"
00034 #include "ldap_log.h"
00035 
00036 int
00037 ldap_turn(
00038        LDAP *ld,
00039        int mutual,
00040        LDAP_CONST char* identifier,
00041        LDAPControl **sctrls,
00042        LDAPControl **cctrls,
00043        int *msgidp )
00044 {
00045 #ifdef LDAP_EXOP_X_TURN
00046        BerElement *turnvalber = NULL;
00047        struct berval *turnvalp = NULL;
00048        int rc;
00049 
00050        turnvalber = ber_alloc_t( LBER_USE_DER );
00051        if( mutual ) {
00052               ber_printf( turnvalber, "{bs}", mutual, identifier );
00053        } else {
00054               ber_printf( turnvalber, "{s}", identifier );
00055        }
00056        ber_flatten( turnvalber, &turnvalp );
00057 
00058        rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN,
00059                      turnvalp, sctrls, cctrls, msgidp );
00060        ber_free( turnvalber, 1 );
00061        return rc;
00062 #else
00063        return LDAP_CONTROL_NOT_FOUND;
00064 #endif
00065 }
00066 
00067 int
00068 ldap_turn_s(
00069        LDAP *ld,
00070        int mutual,
00071        LDAP_CONST char* identifier,
00072        LDAPControl **sctrls,
00073        LDAPControl **cctrls )
00074 {
00075 #ifdef LDAP_EXOP_X_TURN
00076        BerElement *turnvalber = NULL;
00077        struct berval *turnvalp = NULL;
00078        int rc;
00079 
00080        turnvalber = ber_alloc_t( LBER_USE_DER );
00081        if( mutual ) {
00082               ber_printf( turnvalber, "{bs}", 0xFF, identifier );
00083        } else {
00084               ber_printf( turnvalber, "{s}", identifier );
00085        }
00086        ber_flatten( turnvalber, &turnvalp );
00087 
00088        rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN,
00089                      turnvalp, sctrls, cctrls, NULL, NULL );
00090        ber_free( turnvalber, 1 );
00091        return rc;
00092 #else
00093        return LDAP_CONTROL_NOT_FOUND;
00094 #endif
00095 }
00096