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

KLDAP Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
25 using namespace KLDAP;
26 
27 class 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 
45 LdapServer::LdapServer()
46  : d( new LdapServerPrivate )
47 {
48  clear();
49 }
50 
51 LdapServer::LdapServer( const LdapUrl &url )
52  : d( new LdapServerPrivate )
53 {
54  clear();
55 
56  setUrl( url );
57 }
58 
59 LdapServer::LdapServer( const LdapServer &that )
60  : d( new LdapServerPrivate )
61 {
62  *d = *that.d;
63 }
64 
65 LdapServer &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 
76 LdapServer::~LdapServer()
77 {
78  delete d;
79 }
80 
81 void 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 
96 QString LdapServer::host() const
97 {
98  return d->mHost;
99 }
100 
101 int LdapServer::port() const
102 {
103  return d->mPort;
104 }
105 
106 LdapDN LdapServer::baseDn() const
107 {
108  return d->mBaseDn;
109 }
110 
111 QString LdapServer::user() const
112 {
113  return d->mUser;
114 }
115 
116 QString LdapServer::bindDn() const
117 {
118  return d->mBindDn;
119 }
120 
121 QString LdapServer::realm() const
122 {
123  return d->mRealm;
124 }
125 
126 QString LdapServer::password() const
127 {
128  return d->mPassword;
129 }
130 
131 QString LdapServer::filter() const
132 {
133  return d->mFilter;
134 }
135 
136 LdapUrl::Scope LdapServer::scope() const
137 {
138  return d->mScope;
139 }
140 
141 int LdapServer::timeLimit() const
142 {
143  return d->mTimeLimit;
144 }
145 
146 int LdapServer::sizeLimit() const
147 {
148  return d->mSizeLimit;
149 }
150 
151 int LdapServer::pageSize() const
152 {
153  return d->mPageSize;
154 }
155 
156 int LdapServer::version() const
157 {
158  return d->mVersion;
159 }
160 
161 LdapServer::Security LdapServer::security() const
162 {
163  return d->mSecurity;
164 }
165 
166 LdapServer::Auth LdapServer::auth() const
167 {
168  return d->mAuth;
169 }
170 
171 QString LdapServer::mech() const
172 {
173  return d->mMech;
174 }
175 
176 int LdapServer::timeout() const
177 {
178  return d->mTimeout;
179 }
180 
181 void LdapServer::setHost( const QString &host )
182 {
183  d->mHost = host;
184 }
185 
186 void LdapServer::setPort( int port )
187 {
188  d->mPort = port;
189 }
190 
191 void LdapServer::setBaseDn( const LdapDN &baseDn )
192 {
193  d->mBaseDn = baseDn;
194 }
195 
196 void LdapServer::setUser( const QString &user )
197 {
198  d->mUser = user;
199 }
200 
201 void LdapServer::setBindDn( const QString &bindDn )
202 {
203  d->mBindDn = bindDn;
204 }
205 
206 void LdapServer::setRealm( const QString &realm )
207 {
208  d->mRealm = realm;
209 }
210 
211 void LdapServer::setPassword( const QString &password )
212 {
213  d->mPassword = password;
214 }
215 
216 void LdapServer::setTimeLimit( int timelimit )
217 {
218  d->mTimeLimit = timelimit;
219 }
220 
221 void LdapServer::setSizeLimit( int sizelimit )
222 {
223  d->mSizeLimit = sizelimit;
224 }
225 
226 void LdapServer::setPageSize( int pagesize )
227 {
228  d->mPageSize = pagesize;
229 }
230 
231 void LdapServer::setFilter( const QString &filter )
232 {
233  d->mFilter = filter;
234 }
235 
236 void LdapServer::setScope( LdapUrl::Scope scope )
237 {
238  d->mScope = scope;
239 }
240 
241 void LdapServer::setVersion( int version )
242 {
243  d->mVersion = version;
244 }
245 
246 void LdapServer::setSecurity( Security security )
247 {
248  d->mSecurity = security;
249 }
250 
251 void LdapServer::setAuth( Auth auth )
252 {
253  d->mAuth = auth;
254 }
255 
256 void LdapServer::setMech( const QString &mech )
257 {
258  d->mMech = mech;
259 }
260 
261 void LdapServer::setTimeout( int timeout )
262 {
263  d->mTimeout = timeout;
264 }
265 
266 void 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 
349 LdapUrl 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::baseDn
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
Definition: ldapserver.cpp:106
KLDAP::LdapUrl::hasExtension
bool hasExtension(const QString &extension) const
Returns whether the specified extension exists in the LDAP url.
Definition: ldapurl.cpp:134
KLDAP::LdapServer::Simple
Authenticate via login and password.
Definition: ldapserver.h:85
KLDAP::LdapServer::mech
QString mech() const
Returns the mech of the LDAP connection.
Definition: ldapserver.cpp:171
KLDAP::LdapServer::SASL
Azthenticate with the SASL framework.
Definition: ldapserver.h:86
KLDAP::LdapServer::setBindDn
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
Definition: ldapserver.cpp:201
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::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::setRealm
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
Definition: ldapserver.cpp:206
KLDAP::LdapUrl::filter
QString filter() const
Returns the filter part of the LDAP url.
Definition: ldapurl.cpp:123
KLDAP::LdapUrl::setScope
void setScope(Scope scope)
Sets the scope part of the LDAP url.
Definition: ldapurl.cpp:117
KLDAP::LdapServer::Security
Security
Describes the encryption settings that can be used for the LDAP connection.
Definition: ldapserver.h:73
KLDAP::LdapServer::security
Security security() const
Returns the security mode of the LDAP connection.
Definition: ldapserver.cpp:161
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:42
KLDAP::LdapServer::setBaseDn
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
Definition: ldapserver.cpp:191
KLDAP::LdapServer::Anonymous
Do no authentication.
Definition: ldapserver.h:84
KLDAP::LdapUrl::setDn
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
Definition: ldapurl.cpp:82
KLDAP::LdapServer::setPassword
void setPassword(const QString &password)
Sets the password of the LDAP connection.
Definition: ldapserver.cpp:211
KLDAP::LdapServer::setTimeLimit
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
Definition: ldapserver.cpp:216
KLDAP::LdapServer::setHost
void setHost(const QString &host)
Sets the host of the LDAP connection.
Definition: ldapserver.cpp:181
KLDAP::LdapUrl::Scope
Scope
Describes the scope of the LDAP url.
Definition: ldapurl.h:58
KLDAP::LdapServer::setUrl
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
Definition: ldapserver.cpp:266
KLDAP::LdapServer::pageSize
int pageSize() const
Returns the page size of the LDAP connection.
Definition: ldapserver.cpp:151
KLDAP::LdapUrl::setFilter
void setFilter(const QString &filter)
Sets the filter part of the LDAP url.
Definition: ldapurl.cpp:128
KLDAP::LdapUrl::scope
Scope scope() const
Returns the scope part of the LDAP url.
Definition: ldapurl.cpp:112
KLDAP::LdapServer::scope
LdapUrl::Scope scope() const
Returns the search scope of the LDAP connection.
Definition: ldapserver.cpp:136
KLDAP::LdapServer::timeout
int timeout() const
Returns the timeout of the LDAP connection.
Definition: ldapserver.cpp:176
KLDAP::LdapServer::None
Do not use any encryption.
Definition: ldapserver.h:74
KLDAP::LdapServer::setScope
void setScope(LdapUrl::Scope scope)
Sets the search scope of the LDAP connection.
Definition: ldapserver.cpp:236
KLDAP::LdapServer::sizeLimit
int sizeLimit() const
Returns the size limit of the LDAP connection.
Definition: ldapserver.cpp:146
KLDAP::LdapServer::TLS
Use TLS encryption.
Definition: ldapserver.h:75
KLDAP::LdapServer::setUser
void setUser(const QString &user)
Sets the user of the LDAP connection.
Definition: ldapserver.cpp:196
KLDAP::LdapServer::url
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
Definition: ldapserver.cpp:349
KLDAP::LdapServer::setSecurity
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
Definition: ldapserver.cpp:246
KLDAP::LdapServer
A class that contains LDAP server connection settings.
Definition: ldapserver.h:38
KLDAP::LdapServer::~LdapServer
virtual ~LdapServer()
Destroys the LDAP server object.
Definition: ldapserver.cpp:76
QString::isEmpty
bool isEmpty() const
KLDAP::LdapServer::setPort
void setPort(int port)
Sets the port of the LDAP connection.
Definition: ldapserver.cpp:186
KLDAP::LdapServer::host
QString host() const
Returns the host of the LDAP connection.
Definition: ldapserver.cpp:96
QString
KLDAP::LdapServer::setVersion
void setVersion(int version)
Sets the protocol version of the LDAP connection.
Definition: ldapserver.cpp:241
KLDAP::LdapServer::clear
void clear()
Clears all server settings.
Definition: ldapserver.cpp:81
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::LdapServer::setPageSize
void setPageSize(int size)
Sets the page size of the LDAP connection.
Definition: ldapserver.cpp:226
KLDAP::LdapServer::Auth
Auth
Describes the authentication method that can be used for the LDAP connection.
Definition: ldapserver.h:83
KLDAP::LdapServer::password
QString password() const
Returns the password of the LDAP connection.
Definition: ldapserver.cpp:126
KLDAP::LdapServer::timeLimit
int timeLimit() const
Returns the time limit of the LDAP connection.
Definition: ldapserver.cpp:141
KLDAP::LdapUrl::dn
LdapDN dn() const
Returns the dn part of the LDAP url.
Definition: ldapurl.cpp:91
QLatin1String
KLDAP::LdapServer::setMech
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
Definition: ldapserver.cpp:256
KLDAP::LdapServer::setSizeLimit
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
Definition: ldapserver.cpp:221
KLDAP::LdapServer::bindDn
QString bindDn() const
Returns the bindDn of the LDAP connection.
Definition: ldapserver.cpp:116
KLDAP::LdapServer::SSL
Use SSL encryption.
Definition: ldapserver.h:76
KLDAP::LdapServer::setTimeout
void setTimeout(int timeout)
Sets the timeout of the LDAP connection.
Definition: ldapserver.cpp:261
KLDAP::LdapUrl::extension
Extension extension(const QString &extension) const
Returns the specified extension.
Definition: ldapurl.cpp:139
KLDAP::LdapServer::LdapServer
LdapServer()
Creates an empty LDAP server object.
Definition: ldapserver.cpp:45
KLDAP::LdapServer::realm
QString realm() const
Returns the realm of the LDAP connection.
Definition: ldapserver.cpp:121
KLDAP::LdapServer::filter
QString filter() const
Returns the filter string of the LDAP connection.
Definition: ldapserver.cpp:131
KLDAP::LdapServer::version
int version() const
Returns the protocol version of the LDAP connection.
Definition: ldapserver.cpp:156
KLDAP::LdapServer::auth
Auth auth() const
Returns the authentication method of the LDAP connection.
Definition: ldapserver.cpp:166
KLDAP::LdapServer::user
QString user() const
Returns the user of the LDAP connection.
Definition: ldapserver.cpp:111
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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