-
Notifications
You must be signed in to change notification settings - Fork 5
/
ldapconnection.h
94 lines (87 loc) · 3.35 KB
/
ldapconnection.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef INCLUDED_LDAPCONNECTION_H
#define INCLUDED_LDAPCONNECTION_H
#if USE_WINLDAP
#include <windows.h>
#include <winldap.h>
#include <lmaccess.h>
#else
#include <ldap.h>
#define UF_ACCOUNTDISABLE 2
#define UF_LOCKOUT 16
#define UF_DONT_EXPIRE_PASSWD 65536
#ifndef NO_PAGED_LDAP
#define NO_PAGED_LDAP
#endif
#endif
#ifdef USE_WINLDAP
#define LDAP_SHORT_HELP_ENCRYPTION "[-s] "
//#define LDAP_LONG_HELP_ENCRYPTION " -s \tUse SSL encryption for the LDAP communication\n"
#define LDAP_LONG_HELP_ENCRYPTION " -s \tUse TLS encryption for the LDAP communication\n"
#else
#define LDAP_SHORT_HELP_ENCRYPTION ""
#define LDAP_LONG_HELP_ENCRYPTION ""
#endif
#define LDAP_COMMAND_LINE_PARAMETERS "[-h host[:port]] " LDAP_SHORT_HELP_ENCRYPTION "[-u user -p password] [-b searchbase] [-l user]"
#define LDAP_COMMAND_LINE_HELP \
" -h host[:port] \tLDAP host (and optionally port) to connect to (default\n" \
" \tis the default Active Directory LDAP server)\n" \
LDAP_LONG_HELP_ENCRYPTION \
" -u user \tLDAP authentication user login (default is to\n" \
" \tauthenticate as the currently logged on domain user)\n" \
" -p password \tLDAP authentication password (default is to\n" \
" \tauthenticate as the currently logged on domain user)\n" \
" -b searchbase \tLDAP search base (default is current domain's default\n" \
" \tnaming context)\n"
char* get_current_login ();
class LDAPConnection
{
protected:
friend class LDAPResponse;
char* ldaphost;
unsigned int ldapport;
int ldapsecure;
char* ldapuser;
char* ldappass;
char* ldapsearchbase;
LDAP* ldapconnection;
public:
LDAPConnection ();
~LDAPConnection ();
bool ProcessCommandLineParameter (int argc, char** argv, int& index);
const char* Open ();
void Close();
//std::string GetValue (const char* name, const char* line_join = "\n");
//inline std::string GetValue (std::string name, const char* line_join = "\n") { return GetValue(name.c_str(), line_join); }
//inline std::string GetValue (std::string name, std::string line_join) { return GetValue(name.c_str(), line_join.c_str()); }
class LDAPResponse* Search (const char* searchfilter, const char** attrs = NULL);
void SetSearchBase (const char* searchbase);
const char* GetSearchBase () { return ldapsearchbase; }
};
class LDAPResponse
{
friend class LDAPConnection;
public:
typedef bool (*attribute_callback_fn) (const char* attributename, void* userdata);
protected:
LDAPConnection* parent;
LDAPMessage* ldapresponse;
LDAPMessage* currentldapresponse;
#ifndef NO_PAGED_LDAP
LDAPSearch* pagedldapsearch;
LDAPResponse (LDAPConnection* ldap, LDAPMessage* response, LDAPSearch* pagedsearch);
#else
LDAPResponse (LDAPConnection* ldap, LDAPMessage* response);
#endif
public:
~LDAPResponse ();
bool Rewind ();
bool Next ();
int IterateAttributes (attribute_callback_fn callback, void* userdata = NULL);
char* GetDN ();
char* GetUFNDN ();
//void ShowAttribute (const char* name, const char* separator = "\n");
char* GetAttribute (const char* name, const char* separator = "\n");
long long GetAttributeInt (const char* name);
void* GetAttributeBin (const char* name, size_t* len);
};
#endif //INCLUDED_LDAPCONNECTION_H