-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldapproto.h
136 lines (109 loc) · 3.05 KB
/
ldapproto.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <vector>
#include <memory>
#include <string>
#include <map>
#include <iterator>
#include "ber.h"
namespace Ldap {
enum class MessageTag : uint8_t {
BindRequest = 0,
BindResponse = 1,
UnbindRequest = 2,
SearchRequest = 3,
SearchResEntry = 4,
SearchResDone = 5,
SearchResRef = 19,
ModifyRequest = 6,
ModifyResponse = 7,
AddRequest = 8,
AddResponse = 9,
DelRequest = 10,
DelResponse = 11,
ModDNRequest = 12,
ModDNResponse = 13,
CompareRequest = 14,
CompareResponse = 15,
AbandonRequest = 16,
ExtendedRequest = 23,
ExtendedResponse = 24,
IntermediateResponse = 25
};
struct Entry {
std::string dn;
std::map<std::string, std::vector<std::string>> attributes;
Entry(std::string _dn):
dn(_dn),
attributes()
{ }
Entry():
dn {},
attributes {}
{ }
void appendValue(std::string name, std::string value);
};
Ber::Packet buildLdapResult(
Ldap::ErrorCode code,
std::string matchedDn,
std::string errMsg,
MessageTag tag);
namespace Search {
struct SubFilter {
enum class Type { Initial, Any, Final } type;
std::string value;
};
struct Filter {
enum class Type { And, Or, Not, Eq, Sub, Gte, Lte, Present, Approx, Extensible } type;
std::vector<Filter> children;
std::vector<SubFilter> subChildren;
std::string value;
std::string attributeName;
};
struct Request {
std::string base;
enum class Scope { Base, One, Sub } scope;
enum class DerefAliases { Never, Searching, Finding, Always } derefAliases;
int sizeLimit;
int timeLimit;
bool typesOnly;
Filter filter;
std::vector<std::string> attributes;
Request(const Ber::Packet p);
};
Ber::Packet generateResult(const Ldap::Entry& e);
} // namespace Search
namespace Modify {
struct Modification {
Modification(const Ber::Packet p);
enum class Type { Add, Delete, Replace } type;
std::vector<std::string> values;
std::string name;
};
struct Request {
std::string dn;
std::vector<Modification> mods;
Request(const Ber::Packet p);
};
} //namespace Modify
namespace Bind {
struct Request {
int version;
std::string dn;
std::string simple;
std::string saslMech;
std::vector<uint8_t> saslCredentials;
enum class Type { Simple = 0, Sasl = 3 } type;
Request(const Ber::Packet& p);
};
struct Response {
Ber::Packet response;
Response(Ber::Packet result);
void appendSaslResponse(std::vector<uint8_t> resp);
};
} // namespace bind
namespace Add {
Ldap::Entry parseRequest(Ber::Packet p);
} // namespace Add
namespace Delete {
std::string parseRequest(Ber::Packet p);
} // namespace Delete
} // namespace Ldap