forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLDAPExample.C
More file actions
64 lines (49 loc) · 1.43 KB
/
LDAPExample.C
File metadata and controls
64 lines (49 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// \file
/// \ingroup tutorial_net
///
/// \macro_code
///
/// \author
void LDAPExample()
{
gSystem->Load("libRLDAP.so");
TLDAPServer *server = new TLDAPServer("ldap.cern.ch");
if (!server->IsConnected()) {
printf("Could not connect to ldap.cern.ch\n");
delete server;
return;
}
TLDAPResult *result = server.Search();
if (result == 0) {
printf("Search failed\n");
return;
}
result->Print();
delete result;
const char *namingcontexts = server.GetNamingContexts();
result = server.Search(namingcontexts, LDAP_SCOPE_ONELEVEL, 0, 0, 1);
TLDAPEntry *entry = result.GetNext();
entry->Print();
TString dn = entry->GetDn();
delete result;
delete entry;
cout << "The DN of the entry is " << dn << endl;
result = server.Search(dn, LDAP_SCOPE_SUBTREE, 0, 0, 0);
if (result == 0) {
printf("Search failed\n");
return;
}
result->Print();
Int_t counter = result.GetCount();
cout << "The result contains " << counter << " entries !!!" << endl;
entry = result.GetNext();
TLDAPAttribute *attribute = entry.GetAttribute("member");
Int_t counter2 = attribute.GetCount();
cout << "The attribute " << attribute.GetName() << " contains "
<< counter2 << " values !!!" << endl;
const char *value = attribute.GetValue();
cout << "The first value of the attribute is " << endl;
cout << value << endl;
delete result;
delete entry;
}