3 * Copyright 2010-2017 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 #include "LDAPAsynConnection.h"
10 #include "TlsOptions.h"
12 int main( int argc, char* argv[]){
14 std::cerr << "usage: " << argv[0] << " <ldap-uri> <cacertfile> <cacertdir>" << std::endl;
17 std::string uri(argv[1]);
18 std::string cacert(argv[2]);
19 std::string cadir(argv[3]);
21 std::cout << "Current global settings:" << std::endl;
22 std::cout << " CaCertfile: " << tls.getStringOption( TlsOptions::CACERTFILE) << std::endl;
23 std::cout << " CaCertDir: " << tls.getStringOption( TlsOptions::CACERTDIR ) << std::endl;
24 std::cout << " Require Cert: " << tls.getIntOption( TlsOptions::REQUIRE_CERT ) << std::endl;
25 std::cout << "Applying new settings:" << std::endl;
26 tls.setOption( TlsOptions::CACERTFILE, cacert );
27 tls.setOption( TlsOptions::REQUIRE_CERT, TlsOptions::DEMAND );
28 std::cout << " CaCertfile: " << tls.getStringOption( TlsOptions::CACERTFILE ) << std::endl;
29 std::cout << " Require Cert: " << tls.getIntOption( TlsOptions::REQUIRE_CERT ) << std::endl;
32 // 1. connect using global options
33 LDAPAsynConnection l(uri);
36 std::cout << "StartTLS successful." << std::endl;
38 } catch ( LDAPException e ) {
39 std::cerr << e << std::endl;
42 // 2. connect using connection specific option
43 LDAPAsynConnection l1(uri);
44 tls=l1.getTlsOptions();
45 std::cout << "Current connection specific settings:" << std::endl;
46 std::cout << " CaCertfile: " << tls.getStringOption( TlsOptions::CACERTFILE) << std::endl;
47 std::cout << " CaCertDir: " << tls.getStringOption( TlsOptions::CACERTDIR ) << std::endl;
48 std::cout << " Require Cert: " << tls.getIntOption( TlsOptions::REQUIRE_CERT ) << std::endl;
49 std::cout << "Applying new settings:" << std::endl;
50 tls.setOption( TlsOptions::CACERTDIR, cadir );
51 tls.setOption( TlsOptions::REQUIRE_CERT, TlsOptions::DEMAND );
52 std::cout << " CaCertDir: " << tls.getStringOption( TlsOptions::CACERTDIR ) << std::endl;
53 std::cout << " Require Cert: " << tls.getIntOption( TlsOptions::REQUIRE_CERT ) << std::endl;
56 std::cout << "StartTLS successful." << std::endl;
58 } catch ( LDAPException e ) {
59 std::cerr << e << std::endl;
62 // 3. and once again using the globals
64 LDAPAsynConnection l2(uri);
66 std::cout << "Current global settings:" << std::endl;
67 std::cout << " CaCertfile: " << tls2.getStringOption( TlsOptions::CACERTFILE) << std::endl;
68 std::cout << " CaCertDir: " << tls2.getStringOption( TlsOptions::CACERTDIR ) << std::endl;
69 std::cout << " Require Cert: " << tls2.getIntOption( TlsOptions::REQUIRE_CERT ) << std::endl;
71 std::cout << "StartTLS successful." << std::endl;
73 } catch ( LDAPException e ) {
74 std::cerr << e << std::endl;
76 } catch ( LDAPException e ) {
77 std::cerr << e << std::endl;