]> git.sur5r.net Git - openldap/blob - libraries/libldap/turn.c
Build + client side changes from HEAD
[openldap] / libraries / libldap / turn.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2005 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This program was orignally developed by Kurt D. Zeilenga for inclusion in
17  * OpenLDAP Software.
18  */
19
20 /*
21  * LDAPv3 Turn Operation Request
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27 #include <ac/stdlib.h>
28
29 #include <ac/socket.h>
30 #include <ac/string.h>
31 #include <ac/time.h>
32
33 #include "ldap-int.h"
34 #include "ldap_log.h"
35
36 int
37 ldap_turn(
38         LDAP *ld,
39         int mutual,
40         LDAP_CONST char* identifier,
41         LDAPControl **sctrls,
42         LDAPControl **cctrls,
43         int *msgidp )
44 {
45         BerElement *turnvalber = NULL;
46         struct berval *turnvalp = NULL;
47         int rc;
48
49         turnvalber = ber_alloc_t( LBER_USE_DER );
50         if( mutual ) {
51                 ber_printf( turnvalber, "{bs}", mutual, identifier );
52         } else {
53                 ber_printf( turnvalber, "{s}", identifier );
54         }
55         ber_flatten( turnvalber, &turnvalp );
56
57         rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN,
58                         turnvalp, sctrls, cctrls, msgidp );
59         ber_free( turnvalber, 1 );
60         return rc;
61 }
62
63 int
64 ldap_turn_s(
65         LDAP *ld,
66         int mutual,
67         LDAP_CONST char* identifier,
68         LDAPControl **sctrls,
69         LDAPControl **cctrls )
70 {
71         BerElement *turnvalber = NULL;
72         struct berval *turnvalp = NULL;
73         int rc;
74
75         turnvalber = ber_alloc_t( LBER_USE_DER );
76         if( mutual ) {
77                 ber_printf( turnvalber, "{bs}", 0xFF, identifier );
78         } else {
79                 ber_printf( turnvalber, "{s}", identifier );
80         }
81         ber_flatten( turnvalber, &turnvalp );
82
83         rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN,
84                         turnvalp, sctrls, cctrls, NULL, NULL );
85         ber_free( turnvalber, 1 );
86         return rc;
87 }
88