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