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"
9using namespace Qt::Literals::StringLiterals;
10
11#include "ldap_core_debug.h"
12
13using namespace KLDAPCore;
14
15class Q_DECL_HIDDEN LdapServer::LdapServerPrivate
16{
17public:
18 QString mHost;
19 int mPort;
20 LdapDN mBaseDn;
21 QString mUser;
22 QString mBindDn;
23 QString mRealm;
24 QString mPassword;
25 QString mMech;
26 QString mFilter;
27 int mTimeLimit;
28 int mSizeLimit;
29 int mVersion;
30 int mPageSize;
31 int mTimeout;
32 Security mSecurity;
33 Auth mAuth;
34 QString mTLSCACertFile;
35 TLSRequireCertificate mTLSRequireCertificate;
36 LdapUrl::Scope mScope;
37 int mCompletionWeight = -1;
38 QStringList mActivities;
39 bool mEnablePlasmaActivities = false;
40};
41
43 : d(new LdapServerPrivate)
44{
45 clear();
46}
47
49 : d(new LdapServerPrivate)
50{
51 clear();
52
53 setUrl(url);
54}
55
57 : d(new LdapServerPrivate)
58{
59 *d = *that.d;
60}
61
63{
64 if (this == &that) {
65 return *this;
66 }
67
68 *d = *that.d;
69
70 return *this;
71}
72
73LdapServer::~LdapServer() = default;
74
76{
77 d->mPort = 389;
78 d->mHost.clear();
79 d->mUser.clear();
80 d->mBindDn.clear();
81 d->mMech.clear();
82 d->mPassword.clear();
83 d->mSecurity = None;
84 d->mAuth = Anonymous;
85 d->mTLSRequireCertificate = TLSReqCertDefault;
86 d->mTLSCACertFile.clear();
87 d->mVersion = 3;
88 d->mTimeout = 0;
89 d->mSizeLimit = d->mTimeLimit = d->mPageSize = 0;
90 d->mCompletionWeight = -1;
91 d->mActivities.clear();
92 d->mEnablePlasmaActivities = false;
93}
94
96{
97 return d->mHost;
98}
99
101{
102 return d->mPort;
103}
104
105LdapDN LdapServer::baseDn() const
106{
107 return d->mBaseDn;
108}
109
111{
112 return d->mUser;
113}
114
116{
117 return d->mBindDn;
118}
119
121{
122 return d->mRealm;
123}
124
126{
127 return d->mPassword;
128}
129
131{
132 return d->mFilter;
133}
134
136{
137 return d->mScope;
138}
139
141{
142 return d->mTimeLimit;
143}
144
146{
147 return d->mSizeLimit;
148}
149
151{
152 return d->mPageSize;
153}
154
156{
157 return d->mVersion;
158}
159
161{
162 return d->mSecurity;
163}
164
166{
167 return d->mAuth;
168}
169
171{
172 return d->mTLSRequireCertificate;
173}
174
176{
177 return d->mTLSCACertFile;
178}
179
181{
182 return d->mMech;
183}
184
186{
187 return d->mTimeout;
188}
189
191{
192 d->mHost = host;
193}
194
196{
197 d->mPort = port;
198}
199
200void LdapServer::setBaseDn(const LdapDN &baseDn)
201{
202 d->mBaseDn = baseDn;
203}
204
206{
207 d->mUser = user;
208}
209
211{
212 d->mBindDn = bindDn;
213}
214
216{
217 d->mRealm = realm;
218}
219
220void LdapServer::setPassword(const QString &password)
221{
222 d->mPassword = password;
223}
224
225void LdapServer::setTimeLimit(int timelimit)
226{
227 d->mTimeLimit = timelimit;
228}
229
230void LdapServer::setSizeLimit(int sizelimit)
231{
232 d->mSizeLimit = sizelimit;
233}
234
235void LdapServer::setPageSize(int pagesize)
236{
237 d->mPageSize = pagesize;
238}
239
241{
242 d->mFilter = filter;
243}
244
246{
247 d->mScope = scope;
248}
249
250void LdapServer::setVersion(int version)
251{
252 d->mVersion = version;
253}
254
256{
257 d->mSecurity = security;
258}
259
261{
262 d->mAuth = auth;
263}
264
266{
267 d->mTLSRequireCertificate = reqCert;
268}
269
271{
272 d->mTLSCACertFile = caCertFile;
273}
274
276{
277 d->mMech = mech;
278}
279
280void LdapServer::setTimeout(int timeout)
281{
282 d->mTimeout = timeout;
283}
284
286{
287 bool critical = true;
288
289 d->mHost = url.host();
290 const int port = url.port();
291 if (port <= 0) {
292 d->mPort = 389;
293 } else {
294 d->mPort = port;
295 }
296 d->mBaseDn = url.dn();
297 d->mScope = url.scope();
298
299 d->mFilter = url.filter();
300
301 d->mSecurity = None;
302 if (url.scheme() == "ldaps"_L1) {
303 d->mSecurity = SSL;
304 } else if (url.hasExtension(QStringLiteral("x-tls"))) {
305 d->mSecurity = TLS;
306 }
307 qCDebug(LDAP_CORE_LOG) << "security:" << d->mSecurity;
308
309 d->mMech.clear();
310 d->mUser.clear();
311 d->mBindDn.clear();
312 if (url.hasExtension(QStringLiteral("x-sasl"))) {
313 d->mAuth = SASL;
314 if (url.hasExtension(QStringLiteral("x-mech"))) {
315 d->mMech = url.extension(QStringLiteral("x-mech"), critical);
316 }
317 if (url.hasExtension(QStringLiteral("x-realm"))) {
318 d->mRealm = url.extension(QStringLiteral("x-realm"), critical);
319 }
320 if (url.hasExtension(QStringLiteral("bindname"))) {
321 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
322 }
323 d->mUser = url.userName();
324 } else if (url.hasExtension(QStringLiteral("bindname"))) {
325 d->mAuth = Simple;
326 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
327 } else {
328 const QString user = url.userName();
329 if (user.isEmpty()) {
330 d->mAuth = Anonymous;
331 } else {
332 d->mAuth = Simple;
333 d->mBindDn = user;
334 }
335 }
336 d->mPassword = url.password();
337 if (url.hasExtension(QStringLiteral("x-version"))) {
338 d->mVersion = url.extension(QStringLiteral("x-version"), critical).toInt();
339 } else {
340 d->mVersion = 3;
341 }
342
343 if (url.hasExtension(QStringLiteral("x-timeout"))) {
344 d->mTimeout = url.extension(QStringLiteral("x-timeout"), critical).toInt();
345 } else {
346 d->mTimeout = 0;
347 }
348
349 if (url.hasExtension(QStringLiteral("x-timelimit"))) {
350 d->mTimeLimit = url.extension(QStringLiteral("x-timelimit"), critical).toInt();
351 } else {
352 d->mTimeLimit = 0;
353 }
354
355 if (url.hasExtension(QStringLiteral("x-sizelimit"))) {
356 d->mSizeLimit = url.extension(QStringLiteral("x-sizelimit"), critical).toInt();
357 } else {
358 d->mSizeLimit = 0;
359 }
360
361 if (url.hasExtension(QStringLiteral("x-pagesize"))) {
362 d->mPageSize = url.extension(QStringLiteral("x-pagesize"), critical).toInt();
363 } else {
364 d->mPageSize = 0;
365 }
366}
367
369{
370 LdapUrl url;
371 url.setScheme(d->mSecurity == SSL ? QStringLiteral("ldaps") : QStringLiteral("ldap"));
372 url.setPort(d->mPort);
373 url.setHost(d->mHost);
374 url.setDn(d->mBaseDn);
375 url.setFilter(d->mFilter);
376 url.setScope(d->mScope);
377 if (d->mAuth == SASL) {
378 url.setUserName(d->mUser);
379 url.setPassword(d->mPassword);
380 url.setExtension(QStringLiteral("bindname"), d->mBindDn, true);
381 url.setExtension(QStringLiteral("x-sasl"), QString());
382 if (!d->mMech.isEmpty()) {
383 url.setExtension(QStringLiteral("x-mech"), d->mMech);
384 }
385 if (!d->mRealm.isEmpty()) {
386 url.setExtension(QStringLiteral("x-realm"), d->mRealm);
387 }
388 } else if (d->mAuth == Simple) {
389 url.setUserName(d->mBindDn);
390 url.setPassword(d->mPassword);
391 }
392 if (d->mVersion == 2) {
393 url.setExtension(QStringLiteral("x-version"), d->mVersion);
394 }
395 if (d->mTimeout) {
396 url.setExtension(QStringLiteral("x-timeout"), d->mTimeout);
397 }
398 if (d->mTimeLimit != 0) {
399 url.setExtension(QStringLiteral("x-timelimit"), d->mTimeLimit);
400 }
401 if (d->mSizeLimit != 0) {
402 url.setExtension(QStringLiteral("x-sizelimit"), d->mSizeLimit);
403 }
404 if (d->mPageSize != 0) {
405 url.setExtension(QStringLiteral("x-pagesize"), d->mPageSize);
406 }
407 if (d->mSecurity == TLS) {
408 url.setExtension(QStringLiteral("x-tls"), 1, true);
409 }
410 return url;
411}
412
413void LdapServer::setCompletionWeight(int value)
414{
415 d->mCompletionWeight = value;
416}
417
418int LdapServer::completionWeight() const
419{
420 return d->mCompletionWeight;
421}
422
423void LdapServer::setActivities(const QStringList &lst)
424{
425 d->mActivities = lst;
426}
427
428QStringList LdapServer::activities() const
429{
430 return d->mActivities;
431}
432
433void LdapServer::setEnablePlasmaActivities(bool enabled)
434{
435 d->mEnablePlasmaActivities = enabled;
436}
437
438bool LdapServer::enablePlasmaActivities() const
439{
440 return d->mEnablePlasmaActivities;
441}
442
444{
445 d << "port " << t.port();
446 d << "host " << t.host();
447 d << "user " << t.user();
448 d << "bindDn " << t.bindDn();
449 d << "mech " << t.mech();
450 d << "security " << t.security();
451 d << "auth " << t.auth();
452 d << "tlsRequireCertificate " << t.tlsRequireCertificate();
453 d << "tlsCACertFile " << t.tlsCACertFile();
454 d << "version " << t.version();
455 d << "completionWeight " << t.completionWeight();
456 d << "timeout " << t.timeout();
457 d << "timeLimit " << t.timeLimit();
458 d << "sizeLimit " << t.sizeLimit();
459 d << "activities " << t.activities();
460 d << "enablePlasmaActivities " << t.enablePlasmaActivities();
461 return d;
462}
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:109
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:98
Scope scope() const
Returns the scope part of the LDAP url.
Definition ldapurl.cpp:93
LdapDN dn() const
Returns the dn part of the LDAP url.
Definition ldapurl.cpp:72
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:104
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
Definition ldapurl.cpp:62
bool hasExtension(const QString &extension) const
Returns whether the specified extension exists in the LDAP url.
Definition ldapurl.cpp:115
Extension extension(const QString &extension) const
Returns the specified extension.
Definition ldapurl.cpp:120
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
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 Sat Dec 21 2024 17:03:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.