KLdap

ldapserver.cpp
1/*
2 This file is part of libkldap.
3 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "ldapserver.h"
9
10#include "ldap_core_debug.h"
11
12using namespace KLDAPCore;
13
14class Q_DECL_HIDDEN LdapServer::LdapServerPrivate
15{
16public:
17 QString mHost;
18 int mPort;
19 LdapDN mBaseDn;
20 QString mUser;
21 QString mBindDn;
22 QString mRealm;
23 QString mPassword;
24 QString mMech;
25 QString mFilter;
26 int mTimeLimit;
27 int mSizeLimit;
28 int mVersion;
29 int mPageSize;
30 int mTimeout;
31 Security mSecurity;
32 Auth mAuth;
33 QString mTLSCACertFile;
34 TLSRequireCertificate mTLSRequireCertificate;
35 LdapUrl::Scope mScope;
36 int mCompletionWeight = -1;
37};
38
40 : d(new LdapServerPrivate)
41{
42 clear();
43}
44
46 : d(new LdapServerPrivate)
47{
48 clear();
49
50 setUrl(url);
51}
52
54 : d(new LdapServerPrivate)
55{
56 *d = *that.d;
57}
58
60{
61 if (this == &that) {
62 return *this;
63 }
64
65 *d = *that.d;
66
67 return *this;
68}
69
70LdapServer::~LdapServer() = default;
71
73{
74 d->mPort = 389;
75 d->mHost.clear();
76 d->mUser.clear();
77 d->mBindDn.clear();
78 d->mMech.clear();
79 d->mPassword.clear();
80 d->mSecurity = None;
81 d->mAuth = Anonymous;
82 d->mTLSRequireCertificate = TLSReqCertDefault;
83 d->mTLSCACertFile.clear();
84 d->mVersion = 3;
85 d->mTimeout = 0;
86 d->mSizeLimit = d->mTimeLimit = d->mPageSize = 0;
87 d->mCompletionWeight = -1;
88}
89
91{
92 return d->mHost;
93}
94
96{
97 return d->mPort;
98}
99
100LdapDN LdapServer::baseDn() const
101{
102 return d->mBaseDn;
103}
104
106{
107 return d->mUser;
108}
109
111{
112 return d->mBindDn;
113}
114
116{
117 return d->mRealm;
118}
119
121{
122 return d->mPassword;
123}
124
126{
127 return d->mFilter;
128}
129
131{
132 return d->mScope;
133}
134
136{
137 return d->mTimeLimit;
138}
139
141{
142 return d->mSizeLimit;
143}
144
146{
147 return d->mPageSize;
148}
149
151{
152 return d->mVersion;
153}
154
156{
157 return d->mSecurity;
158}
159
161{
162 return d->mAuth;
163}
164
166{
167 return d->mTLSRequireCertificate;
168}
169
171{
172 return d->mTLSCACertFile;
173}
174
176{
177 return d->mMech;
178}
179
181{
182 return d->mTimeout;
183}
184
186{
187 d->mHost = host;
188}
189
191{
192 d->mPort = port;
193}
194
195void LdapServer::setBaseDn(const LdapDN &baseDn)
196{
197 d->mBaseDn = baseDn;
198}
199
201{
202 d->mUser = user;
203}
204
206{
207 d->mBindDn = bindDn;
208}
209
211{
212 d->mRealm = realm;
213}
214
215void LdapServer::setPassword(const QString &password)
216{
217 d->mPassword = password;
218}
219
220void LdapServer::setTimeLimit(int timelimit)
221{
222 d->mTimeLimit = timelimit;
223}
224
225void LdapServer::setSizeLimit(int sizelimit)
226{
227 d->mSizeLimit = sizelimit;
228}
229
230void LdapServer::setPageSize(int pagesize)
231{
232 d->mPageSize = pagesize;
233}
234
236{
237 d->mFilter = filter;
238}
239
241{
242 d->mScope = scope;
243}
244
245void LdapServer::setVersion(int version)
246{
247 d->mVersion = version;
248}
249
251{
252 d->mSecurity = security;
253}
254
256{
257 d->mAuth = auth;
258}
259
261{
262 d->mTLSRequireCertificate = reqCert;
263}
264
266{
267 d->mTLSCACertFile = caCertFile;
268}
269
271{
272 d->mMech = mech;
273}
274
275void LdapServer::setTimeout(int timeout)
276{
277 d->mTimeout = timeout;
278}
279
281{
282 bool critical = true;
283
284 d->mHost = url.host();
285 const int port = url.port();
286 if (port <= 0) {
287 d->mPort = 389;
288 } else {
289 d->mPort = port;
290 }
291 d->mBaseDn = url.dn();
292 d->mScope = url.scope();
293
294 d->mFilter = url.filter();
295
296 d->mSecurity = None;
297 if (url.scheme() == QLatin1StringView("ldaps")) {
298 d->mSecurity = SSL;
299 } else if (url.hasExtension(QStringLiteral("x-tls"))) {
300 d->mSecurity = TLS;
301 }
302 qCDebug(LDAP_LOG) << "security:" << d->mSecurity;
303
304 d->mMech.clear();
305 d->mUser.clear();
306 d->mBindDn.clear();
307 if (url.hasExtension(QStringLiteral("x-sasl"))) {
308 d->mAuth = SASL;
309 if (url.hasExtension(QStringLiteral("x-mech"))) {
310 d->mMech = url.extension(QStringLiteral("x-mech"), critical);
311 }
312 if (url.hasExtension(QStringLiteral("x-realm"))) {
313 d->mRealm = url.extension(QStringLiteral("x-realm"), critical);
314 }
315 if (url.hasExtension(QStringLiteral("bindname"))) {
316 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
317 }
318 d->mUser = url.userName();
319 } else if (url.hasExtension(QStringLiteral("bindname"))) {
320 d->mAuth = Simple;
321 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
322 } else {
323 const QString user = url.userName();
324 if (user.isEmpty()) {
325 d->mAuth = Anonymous;
326 } else {
327 d->mAuth = Simple;
328 d->mBindDn = user;
329 }
330 }
331 d->mPassword = url.password();
332 if (url.hasExtension(QStringLiteral("x-version"))) {
333 d->mVersion = url.extension(QStringLiteral("x-version"), critical).toInt();
334 } else {
335 d->mVersion = 3;
336 }
337
338 if (url.hasExtension(QStringLiteral("x-timeout"))) {
339 d->mTimeout = url.extension(QStringLiteral("x-timeout"), critical).toInt();
340 } else {
341 d->mTimeout = 0;
342 }
343
344 if (url.hasExtension(QStringLiteral("x-timelimit"))) {
345 d->mTimeLimit = url.extension(QStringLiteral("x-timelimit"), critical).toInt();
346 } else {
347 d->mTimeLimit = 0;
348 }
349
350 if (url.hasExtension(QStringLiteral("x-sizelimit"))) {
351 d->mSizeLimit = url.extension(QStringLiteral("x-sizelimit"), critical).toInt();
352 } else {
353 d->mSizeLimit = 0;
354 }
355
356 if (url.hasExtension(QStringLiteral("x-pagesize"))) {
357 d->mPageSize = url.extension(QStringLiteral("x-pagesize"), critical).toInt();
358 } else {
359 d->mPageSize = 0;
360 }
361}
362
364{
365 LdapUrl url;
366 url.setScheme(d->mSecurity == SSL ? QStringLiteral("ldaps") : QStringLiteral("ldap"));
367 url.setPort(d->mPort);
368 url.setHost(d->mHost);
369 url.setDn(d->mBaseDn);
370 url.setFilter(d->mFilter);
371 url.setScope(d->mScope);
372 if (d->mAuth == SASL) {
373 url.setUserName(d->mUser);
374 url.setPassword(d->mPassword);
375 url.setExtension(QStringLiteral("bindname"), d->mBindDn, true);
376 url.setExtension(QStringLiteral("x-sasl"), QString());
377 if (!d->mMech.isEmpty()) {
378 url.setExtension(QStringLiteral("x-mech"), d->mMech);
379 }
380 if (!d->mRealm.isEmpty()) {
381 url.setExtension(QStringLiteral("x-realm"), d->mRealm);
382 }
383 } else if (d->mAuth == Simple) {
384 url.setUserName(d->mBindDn);
385 url.setPassword(d->mPassword);
386 }
387 if (d->mVersion == 2) {
388 url.setExtension(QStringLiteral("x-version"), d->mVersion);
389 }
390 if (d->mTimeout) {
391 url.setExtension(QStringLiteral("x-timeout"), d->mTimeout);
392 }
393 if (d->mTimeLimit != 0) {
394 url.setExtension(QStringLiteral("x-timelimit"), d->mTimeLimit);
395 }
396 if (d->mSizeLimit != 0) {
397 url.setExtension(QStringLiteral("x-sizelimit"), d->mSizeLimit);
398 }
399 if (d->mPageSize != 0) {
400 url.setExtension(QStringLiteral("x-pagesize"), d->mPageSize);
401 }
402 if (d->mSecurity == TLS) {
403 url.setExtension(QStringLiteral("x-tls"), 1, true);
404 }
405 return url;
406}
407
408void LdapServer::setCompletionWeight(int value)
409{
410 d->mCompletionWeight = value;
411}
412
413int LdapServer::completionWeight() const
414{
415 return d->mCompletionWeight;
416}
417
419{
420 d << "completionWeight " << t.completionWeight();
421 d << "timeout " << t.timeout();
422 d << "timeLimit " << t.timeLimit();
423 d << "sizeLimit " << t.sizeLimit();
424 // TODO
425 return d;
426}
A class that contains LDAP server connection settings.
Definition ldapserver.h:27
QString realm() const
Returns the realm of the LDAP connection.
void setHost(const QString &host)
Sets the host of the LDAP connection.
void setTimeout(int timeout)
Sets the timeout of the LDAP connection.
enum { None, TLS, SSL } Security
Describes the encryption settings that can be used for the LDAP connection.
Definition ldapserver.h:61
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
Security security() const
Returns the security mode of the LDAP connection.
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
LdapServer()
Creates an empty LDAP server object.
void setTLSCACertFile(const QString &caCertFile)
Sets the CA certificate file for TLS/SSL connections.
enum { TLSReqCertDefault, TLSReqCertNever, TLSReqCertDemand, TLSReqCertAllow, TLSReqCertTry, TLSReqCertHard, } TLSRequireCertificate
Describes the certificate request and check behaviour for TLS/SSL connections.
Definition ldapserver.h:81
void setTLSRequireCertificate(TLSRequireCertificate reqCert)
Sets the certificate require mode for TLS/SSL connections.
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
QString filter() const
Returns the filter string of the LDAP connection.
void setVersion(int version)
Sets the protocol version of the LDAP connection.
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
int timeout() const
Returns the timeout of the LDAP connection.
enum { Anonymous, Simple, SASL } Auth
Describes the authentication method that can be used for the LDAP connection.
Definition ldapserver.h:71
void setPassword(const QString &password)
Sets the password of the LDAP connection.
void setScope(LdapUrl::Scope scope)
Sets the search scope of the LDAP connection.
int timeLimit() const
Returns the time limit of the LDAP connection.
void setUser(const QString &user)
Sets the user of the LDAP connection.
QString password() const
Returns the password of the LDAP connection.
QString bindDn() const
Returns the bindDn of the LDAP connection.
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
~LdapServer()
Destroys the LDAP server object.
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
int version() const
Returns the protocol version of the LDAP connection.
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
void setAuth(Auth authentication)
Sets the authentication method of the LDAP connection.
QString tlsCACertFile() const
Returns the CA certificate file used for TLS/SSL connections.
int port() const
Returns the port of the LDAP connection.
int sizeLimit() const
Returns the size limit of the LDAP connection.
void setPageSize(int size)
Sets the page size of the LDAP connection.
QString host() const
Returns the host of the LDAP connection.
int pageSize() const
Returns the page size of the LDAP connection.
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.
LdapServer & operator=(const LdapServer &other)
Overwrites the values of the LDAP server object with the values from an other object.
Auth auth() const
Returns the authentication method of the LDAP connection.
void clear()
Clears all server settings.
void setPort(int port)
Sets the port of the LDAP connection.
QString mech() const
Returns the mech of the LDAP connection.
LdapUrl::Scope scope() const
Returns the search scope of the LDAP connection.
void setFilter(const QString &filter)
Sets the filter string of the LDAP connection.
TLSRequireCertificate tlsRequireCertificate() const
Returns the certificate require mode for TLS/SSL connections.
A special url class for LDAP.
Definition ldapurl.h:30
void setFilter(const QString &filter)
Sets the filter part of the LDAP url.
Definition ldapurl.cpp:108
void setExtension(const QString &key, const Extension &extension)
Sets the specified extension key with the value and criticality in extension.
void setScope(Scope scope)
Sets the scope part of the LDAP url.
Definition ldapurl.cpp:97
Scope scope() const
Returns the scope part of the LDAP url.
Definition ldapurl.cpp:92
LdapDN dn() const
Returns the dn part of the LDAP url.
Definition ldapurl.cpp:71
enum { Base, One, Sub } Scope
Describes the scope of the LDAP url.
Definition ldapurl.h:44
QString filter() const
Returns the filter part of the LDAP url.
Definition ldapurl.cpp:103
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
Definition ldapurl.cpp:61
bool hasExtension(const QString &extension) const
Returns whether the specified extension exists in the LDAP url.
Definition ldapurl.cpp:114
Extension extension(const QString &extension) const
Returns the specified extension.
Definition ldapurl.cpp:119
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
bool isEmpty() const const
QString host(ComponentFormattingOptions options) const const
QString password(ComponentFormattingOptions options) const const
int port(int defaultPort) const const
QString scheme() const const
void setHost(const QString &host, ParsingMode mode)
void setPassword(const QString &password, ParsingMode mode)
void setPort(int port)
void setScheme(const QString &scheme)
void setUserName(const QString &userName, ParsingMode mode)
QString userName(ComponentFormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.