• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KLDAP Library

  • kldap
ldapserver.cpp
1/*
2 This file is part of libkldap.
3 Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "ldapserver.h"
22
23#include <kdebug.h>
24
25using namespace KLDAP;
26
27class LdapServer::LdapServerPrivate
28{
29 public:
30 QString mHost;
31 int mPort;
32 LdapDN mBaseDn;
33 QString mUser;
34 QString mBindDn;
35 QString mRealm;
36 QString mPassword;
37 QString mMech;
38 QString mFilter;
39 int mTimeLimit, mSizeLimit, mVersion, mPageSize, mTimeout;
40 Security mSecurity;
41 Auth mAuth;
42 LdapUrl::Scope mScope;
43};
44
45LdapServer::LdapServer()
46 : d( new LdapServerPrivate )
47{
48 clear();
49}
50
51LdapServer::LdapServer( const LdapUrl &url )
52 : d( new LdapServerPrivate )
53{
54 clear();
55
56 setUrl( url );
57}
58
59LdapServer::LdapServer( const LdapServer &that )
60 : d( new LdapServerPrivate )
61{
62 *d = *that.d;
63}
64
65LdapServer &LdapServer::operator= ( const LdapServer &that )
66{
67 if ( this == &that ) {
68 return *this;
69 }
70
71 *d = *that.d;
72
73 return *this;
74}
75
76LdapServer::~LdapServer()
77{
78 delete d;
79}
80
81void LdapServer::clear()
82{
83 d->mPort = 389;
84 d->mHost.clear();
85 d->mUser.clear();
86 d->mBindDn.clear();
87 d->mMech.clear();
88 d->mPassword.clear();
89 d->mSecurity = None;
90 d->mAuth = Anonymous;
91 d->mVersion = 3;
92 d->mTimeout = 0;
93 d->mSizeLimit = d->mTimeLimit = d->mPageSize = 0;
94}
95
96QString LdapServer::host() const
97{
98 return d->mHost;
99}
100
101int LdapServer::port() const
102{
103 return d->mPort;
104}
105
106LdapDN LdapServer::baseDn() const
107{
108 return d->mBaseDn;
109}
110
111QString LdapServer::user() const
112{
113 return d->mUser;
114}
115
116QString LdapServer::bindDn() const
117{
118 return d->mBindDn;
119}
120
121QString LdapServer::realm() const
122{
123 return d->mRealm;
124}
125
126QString LdapServer::password() const
127{
128 return d->mPassword;
129}
130
131QString LdapServer::filter() const
132{
133 return d->mFilter;
134}
135
136LdapUrl::Scope LdapServer::scope() const
137{
138 return d->mScope;
139}
140
141int LdapServer::timeLimit() const
142{
143 return d->mTimeLimit;
144}
145
146int LdapServer::sizeLimit() const
147{
148 return d->mSizeLimit;
149}
150
151int LdapServer::pageSize() const
152{
153 return d->mPageSize;
154}
155
156int LdapServer::version() const
157{
158 return d->mVersion;
159}
160
161LdapServer::Security LdapServer::security() const
162{
163 return d->mSecurity;
164}
165
166LdapServer::Auth LdapServer::auth() const
167{
168 return d->mAuth;
169}
170
171QString LdapServer::mech() const
172{
173 return d->mMech;
174}
175
176int LdapServer::timeout() const
177{
178 return d->mTimeout;
179}
180
181void LdapServer::setHost( const QString &host )
182{
183 d->mHost = host;
184}
185
186void LdapServer::setPort( int port )
187{
188 d->mPort = port;
189}
190
191void LdapServer::setBaseDn( const LdapDN &baseDn )
192{
193 d->mBaseDn = baseDn;
194}
195
196void LdapServer::setUser( const QString &user )
197{
198 d->mUser = user;
199}
200
201void LdapServer::setBindDn( const QString &bindDn )
202{
203 d->mBindDn = bindDn;
204}
205
206void LdapServer::setRealm( const QString &realm )
207{
208 d->mRealm = realm;
209}
210
211void LdapServer::setPassword( const QString &password )
212{
213 d->mPassword = password;
214}
215
216void LdapServer::setTimeLimit( int timelimit )
217{
218 d->mTimeLimit = timelimit;
219}
220
221void LdapServer::setSizeLimit( int sizelimit )
222{
223 d->mSizeLimit = sizelimit;
224}
225
226void LdapServer::setPageSize( int pagesize )
227{
228 d->mPageSize = pagesize;
229}
230
231void LdapServer::setFilter( const QString &filter )
232{
233 d->mFilter = filter;
234}
235
236void LdapServer::setScope( LdapUrl::Scope scope )
237{
238 d->mScope = scope;
239}
240
241void LdapServer::setVersion( int version )
242{
243 d->mVersion = version;
244}
245
246void LdapServer::setSecurity( Security security )
247{
248 d->mSecurity = security;
249}
250
251void LdapServer::setAuth( Auth auth )
252{
253 d->mAuth = auth;
254}
255
256void LdapServer::setMech( const QString &mech )
257{
258 d->mMech = mech;
259}
260
261void LdapServer::setTimeout( int timeout )
262{
263 d->mTimeout = timeout;
264}
265
266void LdapServer::setUrl( const LdapUrl &url )
267{
268 bool critical = true;
269
270 d->mHost = url.host();
271 int port = url.port();
272 if ( port <= 0 ) {
273 d->mPort = 389;
274 } else {
275 d->mPort = port;
276 }
277 d->mBaseDn = url.dn();
278 d->mScope = url.scope();
279
280 d->mFilter = url.filter();
281
282 d->mSecurity = None;
283 if ( url.protocol() == QLatin1String("ldaps") ) {
284 d->mSecurity = SSL;
285 } else if ( url.hasExtension( QLatin1String("x-tls") ) ) {
286 d->mSecurity = TLS;
287 }
288 kDebug() << "security:" << d->mSecurity;
289
290 d->mMech.clear();
291 d->mUser.clear();
292 d->mBindDn.clear();
293 if ( url.hasExtension(QLatin1String( "x-sasl") ) ) {
294 d->mAuth = SASL;
295 if ( url.hasExtension( QLatin1String("x-mech") ) ) {
296 d->mMech = url.extension( QLatin1String("x-mech"), critical );
297 }
298 if ( url.hasExtension( QLatin1String("x-realm") ) ) {
299 d->mRealm = url.extension( QLatin1String("x-realm"), critical );
300 }
301 if ( url.hasExtension( QLatin1String("bindname") ) ) {
302 d->mBindDn = url.extension( QLatin1String("bindname"), critical );
303 }
304 d->mUser = url.user();
305 } else if ( url.hasExtension( QLatin1String("bindname") ) ) {
306 d->mAuth = Simple;
307 d->mBindDn = url.extension( QLatin1String("bindname"), critical );
308 } else {
309 QString user = url.user();
310 if ( user.isEmpty() ) {
311 d->mAuth = Anonymous;
312 } else {
313 d->mAuth = Simple;
314 d->mBindDn = user;
315 }
316 }
317 d->mPassword = url.password();
318 if ( url.hasExtension( QLatin1String("x-version") ) ) {
319 d->mVersion = url.extension( QLatin1String("x-version"), critical ).toInt();
320 } else {
321 d->mVersion = 3;
322 }
323
324 if ( url.hasExtension( QLatin1String("x-timeout") ) ) {
325 d->mTimeout = url.extension( QLatin1String("x-timeout"), critical ).toInt();
326 } else {
327 d->mTimeout = 0;
328 }
329
330 if ( url.hasExtension( QLatin1String("x-timelimit") ) ) {
331 d->mTimeLimit = url.extension( QLatin1String("x-timelimit"), critical ).toInt();
332 } else {
333 d->mTimeLimit = 0;
334 }
335
336 if ( url.hasExtension( QLatin1String("x-sizelimit") ) ) {
337 d->mSizeLimit = url.extension( QLatin1String("x-sizelimit"), critical ).toInt();
338 } else {
339 d->mSizeLimit = 0;
340 }
341
342 if ( url.hasExtension( QLatin1String("x-pagesize") ) ) {
343 d->mPageSize = url.extension( QLatin1String("x-pagesize"), critical ).toInt();
344 } else {
345 d->mPageSize = 0;
346 }
347}
348
349LdapUrl LdapServer::url() const
350{
351 LdapUrl url;
352 url.setProtocol( d->mSecurity == SSL ? QLatin1String("ldaps") : QLatin1String("ldap") );
353 url.setPort( d->mPort );
354 url.setHost( d->mHost );
355 url.setDn( d->mBaseDn );
356 url.setFilter( d->mFilter );
357 url.setScope( d->mScope );
358 if ( d->mAuth == SASL ) {
359 url.setUser( d->mUser );
360 url.setPassword( d->mPassword );
361 url.setExtension( QLatin1String("bindname"), d->mBindDn, true );
362 url.setExtension( QLatin1String("x-sasl"), QString() );
363 if ( !d->mMech.isEmpty() ) {
364 url.setExtension( QLatin1String("x-mech"), d->mMech );
365 }
366 if ( !d->mRealm.isEmpty() ) {
367 url.setExtension( QLatin1String("x-realm"), d->mRealm );
368 }
369 } else if (d->mAuth == Simple ) {
370 url.setUser( d->mBindDn );
371 url.setPassword( d->mPassword );
372 }
373 if ( d->mVersion == 2 ) {
374 url.setExtension( QLatin1String("x-version"), d->mVersion );
375 }
376 if ( d->mTimeout ) {
377 url.setExtension( QLatin1String("x-timeout"), d->mTimeout );
378 }
379 if ( d->mTimeLimit != 0 ) {
380 url.setExtension( QLatin1String("x-timelimit"), d->mTimeLimit );
381 }
382 if ( d->mSizeLimit != 0 ) {
383 url.setExtension( QLatin1String("x-sizelimit"), d->mSizeLimit );
384 }
385 if ( d->mPageSize != 0 ) {
386 url.setExtension( QLatin1String("x-pagesize"), d->mPageSize );
387 }
388 if ( d->mSecurity == TLS ) {
389 url.setExtension( QLatin1String("x-tls"), 1, true );
390 }
391
392 return url;
393}
KLDAP::LdapServer
A class that contains LDAP server connection settings.
Definition ldapserver.h:39
KLDAP::LdapServer::realm
QString realm() const
Returns the realm of the LDAP connection.
Definition ldapserver.cpp:121
KLDAP::LdapServer::setHost
void setHost(const QString &host)
Sets the host of the LDAP connection.
Definition ldapserver.cpp:181
KLDAP::LdapServer::Auth
Auth
Describes the authentication method that can be used for the LDAP connection.
Definition ldapserver.h:83
KLDAP::LdapServer::Simple
@ Simple
Authenticate via login and password.
Definition ldapserver.h:85
KLDAP::LdapServer::SASL
@ SASL
Azthenticate with the SASL framework.
Definition ldapserver.h:86
KLDAP::LdapServer::Anonymous
@ Anonymous
Do no authentication.
Definition ldapserver.h:84
KLDAP::LdapServer::setTimeout
void setTimeout(int timeout)
Sets the timeout of the LDAP connection.
Definition ldapserver.cpp:261
KLDAP::LdapServer::setMech
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
Definition ldapserver.cpp:256
KLDAP::LdapServer::security
Security security() const
Returns the security mode of the LDAP connection.
Definition ldapserver.cpp:161
KLDAP::LdapServer::setSecurity
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
Definition ldapserver.cpp:246
KLDAP::LdapServer::setSizeLimit
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
Definition ldapserver.cpp:221
KLDAP::LdapServer::LdapServer
LdapServer()
Creates an empty LDAP server object.
Definition ldapserver.cpp:45
KLDAP::LdapServer::url
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
Definition ldapserver.cpp:349
KLDAP::LdapServer::filter
QString filter() const
Returns the filter string of the LDAP connection.
Definition ldapserver.cpp:131
KLDAP::LdapServer::setVersion
void setVersion(int version)
Sets the protocol version of the LDAP connection.
Definition ldapserver.cpp:241
KLDAP::LdapServer::baseDn
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
Definition ldapserver.cpp:106
KLDAP::LdapServer::timeout
int timeout() const
Returns the timeout of the LDAP connection.
Definition ldapserver.cpp:176
KLDAP::LdapServer::setPassword
void setPassword(const QString &password)
Sets the password of the LDAP connection.
Definition ldapserver.cpp:211
KLDAP::LdapServer::setScope
void setScope(LdapUrl::Scope scope)
Sets the search scope of the LDAP connection.
Definition ldapserver.cpp:236
KLDAP::LdapServer::timeLimit
int timeLimit() const
Returns the time limit of the LDAP connection.
Definition ldapserver.cpp:141
KLDAP::LdapServer::setUser
void setUser(const QString &user)
Sets the user of the LDAP connection.
Definition ldapserver.cpp:196
KLDAP::LdapServer::password
QString password() const
Returns the password of the LDAP connection.
Definition ldapserver.cpp:126
KLDAP::LdapServer::bindDn
QString bindDn() const
Returns the bindDn of the LDAP connection.
Definition ldapserver.cpp:116
KLDAP::LdapServer::setTimeLimit
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
Definition ldapserver.cpp:216
KLDAP::LdapServer::~LdapServer
virtual ~LdapServer()
Destroys the LDAP server object.
Definition ldapserver.cpp:76
KLDAP::LdapServer::setRealm
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
Definition ldapserver.cpp:206
KLDAP::LdapServer::version
int version() const
Returns the protocol version of the LDAP connection.
Definition ldapserver.cpp:156
KLDAP::LdapServer::setUrl
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
Definition ldapserver.cpp:266
KLDAP::LdapServer::setAuth
void setAuth(Auth authentication)
Sets the authentication method of the LDAP connection.
Definition ldapserver.cpp:251
KLDAP::LdapServer::port
int port() const
Returns the port of the LDAP connection.
Definition ldapserver.cpp:101
KLDAP::LdapServer::sizeLimit
int sizeLimit() const
Returns the size limit of the LDAP connection.
Definition ldapserver.cpp:146
KLDAP::LdapServer::setPageSize
void setPageSize(int size)
Sets the page size of the LDAP connection.
Definition ldapserver.cpp:226
KLDAP::LdapServer::host
QString host() const
Returns the host of the LDAP connection.
Definition ldapserver.cpp:96
KLDAP::LdapServer::pageSize
int pageSize() const
Returns the page size of the LDAP connection.
Definition ldapserver.cpp:151
KLDAP::LdapServer::setBindDn
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
Definition ldapserver.cpp:201
KLDAP::LdapServer::setBaseDn
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
Definition ldapserver.cpp:191
KLDAP::LdapServer::user
QString user() const
Returns the user of the LDAP connection.
Definition ldapserver.cpp:111
KLDAP::LdapServer::operator=
LdapServer & operator=(const LdapServer &other)
Overwrites the values of the LDAP server object with the values from an other object.
Definition ldapserver.cpp:65
KLDAP::LdapServer::auth
Auth auth() const
Returns the authentication method of the LDAP connection.
Definition ldapserver.cpp:166
KLDAP::LdapServer::clear
void clear()
Clears all server settings.
Definition ldapserver.cpp:81
KLDAP::LdapServer::Security
Security
Describes the encryption settings that can be used for the LDAP connection.
Definition ldapserver.h:73
KLDAP::LdapServer::TLS
@ TLS
Use TLS encryption.
Definition ldapserver.h:75
KLDAP::LdapServer::None
@ None
Do not use any encryption.
Definition ldapserver.h:74
KLDAP::LdapServer::SSL
@ SSL
Use SSL encryption.
Definition ldapserver.h:76
KLDAP::LdapServer::setPort
void setPort(int port)
Sets the port of the LDAP connection.
Definition ldapserver.cpp:186
KLDAP::LdapServer::mech
QString mech() const
Returns the mech of the LDAP connection.
Definition ldapserver.cpp:171
KLDAP::LdapServer::scope
LdapUrl::Scope scope() const
Returns the search scope of the LDAP connection.
Definition ldapserver.cpp:136
KLDAP::LdapServer::setFilter
void setFilter(const QString &filter)
Sets the filter string of the LDAP connection.
Definition ldapserver.cpp:231
KLDAP::LdapUrl
A special url class for LDAP.
Definition ldapurl.h:43
KLDAP::LdapUrl::setExtension
void setExtension(const QString &key, const Extension &extension)
Sets the specified extension key with the value and criticality in extension.
Definition ldapurl.cpp:163
KLDAP::LdapUrl::setFilter
void setFilter(const QString &filter)
Sets the filter part of the LDAP url.
Definition ldapurl.cpp:128
KLDAP::LdapUrl::setScope
void setScope(Scope scope)
Sets the scope part of the LDAP url.
Definition ldapurl.cpp:117
KLDAP::LdapUrl::Scope
Scope
Describes the scope of the LDAP url.
Definition ldapurl.h:58
KLDAP::LdapUrl::scope
Scope scope() const
Returns the scope part of the LDAP url.
Definition ldapurl.cpp:112
KLDAP::LdapUrl::dn
LdapDN dn() const
Returns the dn part of the LDAP url.
Definition ldapurl.cpp:91
KLDAP::LdapUrl::filter
QString filter() const
Returns the filter part of the LDAP url.
Definition ldapurl.cpp:123
KLDAP::LdapUrl::setDn
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
Definition ldapurl.cpp:82
KLDAP::LdapUrl::hasExtension
bool hasExtension(const QString &extension) const
Returns whether the specified extension exists in the LDAP url.
Definition ldapurl.cpp:134
KLDAP::LdapUrl::extension
Extension extension(const QString &extension) const
Returns the specified extension.
Definition ldapurl.cpp:139
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal