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};
40
42 : d(new LdapServerPrivate)
43{
44 clear();
45}
46
48 : d(new LdapServerPrivate)
49{
50 clear();
51
52 setUrl(url);
53}
54
56 : d(new LdapServerPrivate)
57{
58 *d = *that.d;
59}
60
62{
63 if (this == &that) {
64 return *this;
65 }
66
67 *d = *that.d;
68
69 return *this;
70}
71
72LdapServer::~LdapServer() = default;
73
75{
76 d->mPort = 389;
77 d->mHost.clear();
78 d->mUser.clear();
79 d->mBindDn.clear();
80 d->mMech.clear();
81 d->mPassword.clear();
82 d->mSecurity = None;
83 d->mAuth = Anonymous;
84 d->mTLSRequireCertificate = TLSReqCertDefault;
85 d->mTLSCACertFile.clear();
86 d->mVersion = 3;
87 d->mTimeout = 0;
88 d->mSizeLimit = d->mTimeLimit = d->mPageSize = 0;
89 d->mCompletionWeight = -1;
90 d->mActivities.clear();
91}
92
94{
95 return d->mHost;
96}
97
99{
100 return d->mPort;
101}
102
103LdapDN LdapServer::baseDn() const
104{
105 return d->mBaseDn;
106}
107
109{
110 return d->mUser;
111}
112
114{
115 return d->mBindDn;
116}
117
119{
120 return d->mRealm;
121}
122
124{
125 return d->mPassword;
126}
127
129{
130 return d->mFilter;
131}
132
134{
135 return d->mScope;
136}
137
139{
140 return d->mTimeLimit;
141}
142
144{
145 return d->mSizeLimit;
146}
147
149{
150 return d->mPageSize;
151}
152
154{
155 return d->mVersion;
156}
157
159{
160 return d->mSecurity;
161}
162
164{
165 return d->mAuth;
166}
167
169{
170 return d->mTLSRequireCertificate;
171}
172
174{
175 return d->mTLSCACertFile;
176}
177
179{
180 return d->mMech;
181}
182
184{
185 return d->mTimeout;
186}
187
189{
190 d->mHost = host;
191}
192
194{
195 d->mPort = port;
196}
197
198void LdapServer::setBaseDn(const LdapDN &baseDn)
199{
200 d->mBaseDn = baseDn;
201}
202
204{
205 d->mUser = user;
206}
207
209{
210 d->mBindDn = bindDn;
211}
212
214{
215 d->mRealm = realm;
216}
217
218void LdapServer::setPassword(const QString &password)
219{
220 d->mPassword = password;
221}
222
223void LdapServer::setTimeLimit(int timelimit)
224{
225 d->mTimeLimit = timelimit;
226}
227
228void LdapServer::setSizeLimit(int sizelimit)
229{
230 d->mSizeLimit = sizelimit;
231}
232
233void LdapServer::setPageSize(int pagesize)
234{
235 d->mPageSize = pagesize;
236}
237
239{
240 d->mFilter = filter;
241}
242
244{
245 d->mScope = scope;
246}
247
248void LdapServer::setVersion(int version)
249{
250 d->mVersion = version;
251}
252
254{
255 d->mSecurity = security;
256}
257
259{
260 d->mAuth = auth;
261}
262
264{
265 d->mTLSRequireCertificate = reqCert;
266}
267
269{
270 d->mTLSCACertFile = caCertFile;
271}
272
274{
275 d->mMech = mech;
276}
277
278void LdapServer::setTimeout(int timeout)
279{
280 d->mTimeout = timeout;
281}
282
284{
285 bool critical = true;
286
287 d->mHost = url.host();
288 const int port = url.port();
289 if (port <= 0) {
290 d->mPort = 389;
291 } else {
292 d->mPort = port;
293 }
294 d->mBaseDn = url.dn();
295 d->mScope = url.scope();
296
297 d->mFilter = url.filter();
298
299 d->mSecurity = None;
300 if (url.scheme() == "ldaps"_L1) {
301 d->mSecurity = SSL;
302 } else if (url.hasExtension(QStringLiteral("x-tls"))) {
303 d->mSecurity = TLS;
304 }
305 qCDebug(LDAP_CORE_LOG) << "security:" << d->mSecurity;
306
307 d->mMech.clear();
308 d->mUser.clear();
309 d->mBindDn.clear();
310 if (url.hasExtension(QStringLiteral("x-sasl"))) {
311 d->mAuth = SASL;
312 if (url.hasExtension(QStringLiteral("x-mech"))) {
313 d->mMech = url.extension(QStringLiteral("x-mech"), critical);
314 }
315 if (url.hasExtension(QStringLiteral("x-realm"))) {
316 d->mRealm = url.extension(QStringLiteral("x-realm"), critical);
317 }
318 if (url.hasExtension(QStringLiteral("bindname"))) {
319 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
320 }
321 d->mUser = url.userName();
322 } else if (url.hasExtension(QStringLiteral("bindname"))) {
323 d->mAuth = Simple;
324 d->mBindDn = url.extension(QStringLiteral("bindname"), critical);
325 } else {
326 const QString user = url.userName();
327 if (user.isEmpty()) {
328 d->mAuth = Anonymous;
329 } else {
330 d->mAuth = Simple;
331 d->mBindDn = user;
332 }
333 }
334 d->mPassword = url.password();
335 if (url.hasExtension(QStringLiteral("x-version"))) {
336 d->mVersion = url.extension(QStringLiteral("x-version"), critical).toInt();
337 } else {
338 d->mVersion = 3;
339 }
340
341 if (url.hasExtension(QStringLiteral("x-timeout"))) {
342 d->mTimeout = url.extension(QStringLiteral("x-timeout"), critical).toInt();
343 } else {
344 d->mTimeout = 0;
345 }
346
347 if (url.hasExtension(QStringLiteral("x-timelimit"))) {
348 d->mTimeLimit = url.extension(QStringLiteral("x-timelimit"), critical).toInt();
349 } else {
350 d->mTimeLimit = 0;
351 }
352
353 if (url.hasExtension(QStringLiteral("x-sizelimit"))) {
354 d->mSizeLimit = url.extension(QStringLiteral("x-sizelimit"), critical).toInt();
355 } else {
356 d->mSizeLimit = 0;
357 }
358
359 if (url.hasExtension(QStringLiteral("x-pagesize"))) {
360 d->mPageSize = url.extension(QStringLiteral("x-pagesize"), critical).toInt();
361 } else {
362 d->mPageSize = 0;
363 }
364}
365
367{
368 LdapUrl url;
369 url.setScheme(d->mSecurity == SSL ? QStringLiteral("ldaps") : QStringLiteral("ldap"));
370 url.setPort(d->mPort);
371 url.setHost(d->mHost);
372 url.setDn(d->mBaseDn);
373 url.setFilter(d->mFilter);
374 url.setScope(d->mScope);
375 if (d->mAuth == SASL) {
376 url.setUserName(d->mUser);
377 url.setPassword(d->mPassword);
378 url.setExtension(QStringLiteral("bindname"), d->mBindDn, true);
379 url.setExtension(QStringLiteral("x-sasl"), QString());
380 if (!d->mMech.isEmpty()) {
381 url.setExtension(QStringLiteral("x-mech"), d->mMech);
382 }
383 if (!d->mRealm.isEmpty()) {
384 url.setExtension(QStringLiteral("x-realm"), d->mRealm);
385 }
386 } else if (d->mAuth == Simple) {
387 url.setUserName(d->mBindDn);
388 url.setPassword(d->mPassword);
389 }
390 if (d->mVersion == 2) {
391 url.setExtension(QStringLiteral("x-version"), d->mVersion);
392 }
393 if (d->mTimeout) {
394 url.setExtension(QStringLiteral("x-timeout"), d->mTimeout);
395 }
396 if (d->mTimeLimit != 0) {
397 url.setExtension(QStringLiteral("x-timelimit"), d->mTimeLimit);
398 }
399 if (d->mSizeLimit != 0) {
400 url.setExtension(QStringLiteral("x-sizelimit"), d->mSizeLimit);
401 }
402 if (d->mPageSize != 0) {
403 url.setExtension(QStringLiteral("x-pagesize"), d->mPageSize);
404 }
405 if (d->mSecurity == TLS) {
406 url.setExtension(QStringLiteral("x-tls"), 1, true);
407 }
408 return url;
409}
410
411void LdapServer::setCompletionWeight(int value)
412{
413 d->mCompletionWeight = value;
414}
415
416int LdapServer::completionWeight() const
417{
418 return d->mCompletionWeight;
419}
420
421void LdapServer::setActivities(const QStringList &lst)
422{
423 d->mActivities = lst;
424}
425
426QStringList LdapServer::activities() const
427{
428 return d->mActivities;
429}
430
432{
433 d << "completionWeight " << t.completionWeight();
434 d << "timeout " << t.timeout();
435 d << "timeLimit " << t.timeLimit();
436 d << "sizeLimit " << t.sizeLimit();
437 // TODO
438 return d;
439}
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
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
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 Fri Oct 11 2024 12:14:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.