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

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • ldap
ldapclientsearchconfig.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Laurent Montel <montel@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "ldapclientsearchconfig.h"
21 #include <kldap/ldapserver.h>
22 
23 
24 #include <KStandardDirs>
25 #include <KConfig>
26 #include <KConfigGroup>
27 #include <KMessageBox>
28 #include <KLocale>
29 
30 #include <kwallet.h>
31 
32 using namespace KLDAP;
33 
34 class LdapClientSearchConfig::Private
35 {
36 public:
37  Private()
38  : useWallet( false ),
39  wallet( 0 )
40  {
41 
42  }
43  ~Private()
44  {
45  if (useWallet) {
46  wallet->deleteLater();
47  wallet = 0;
48  }
49  }
50  bool useWallet;
51  KWallet::Wallet* wallet;
52 };
53 
54 K_GLOBAL_STATIC_WITH_ARGS( KConfig, s_config, ( QLatin1String("kabldaprc"), KConfig::NoGlobals ) )
55 
56 KConfig* LdapClientSearchConfig::config()
57 {
58  return s_config;
59 }
60 
61 LdapClientSearchConfig::LdapClientSearchConfig(QObject *parent)
62  : QObject(parent), d(new LdapClientSearchConfig::Private())
63 {
64 }
65 
66 LdapClientSearchConfig::~LdapClientSearchConfig()
67 {
68  delete d;
69 }
70 
71 void LdapClientSearchConfig::readConfig( KLDAP::LdapServer &server, KConfigGroup &config, int j, bool active )
72 {
73  QString prefix;
74  if ( active ) {
75  prefix = QLatin1String("Selected");
76  }
77 
78  const QString host = config.readEntry( prefix + QString::fromLatin1( "Host%1" ).arg( j ),
79  QString() ).trimmed();
80  if ( !host.isEmpty() ) {
81  server.setHost( host );
82  }
83 
84  const int port = config.readEntry( prefix + QString::fromLatin1( "Port%1" ).arg( j ), 389 );
85  server.setPort( port );
86 
87  const QString base = config.readEntry( prefix + QString::fromLatin1( "Base%1" ).arg( j ),
88  QString() ).trimmed();
89  if ( !base.isEmpty() ) {
90  server.setBaseDn( KLDAP::LdapDN( base ) );
91  }
92 
93  const QString user = config.readEntry( prefix + QString::fromLatin1( "User%1" ).arg( j ),
94  QString() ).trimmed();
95  if ( !user.isEmpty() ) {
96  server.setUser( user );
97  }
98 
99  const QString bindDN = config.readEntry( prefix + QString::fromLatin1( "Bind%1" ).arg( j ), QString() ).trimmed();
100  if ( !bindDN.isEmpty() ) {
101  server.setBindDn( bindDN );
102  }
103 
104  const QString pwdBindBNEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j );
105  QString pwdBindDN = config.readEntry( pwdBindBNEntry, QString() );
106  if ( !pwdBindDN.isEmpty() ) {
107  if ( KMessageBox::Yes == KMessageBox::questionYesNo(0, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"),
108  i18n("Store clear text password in KWallet"),
109  KStandardGuiItem::yes(),
110  KStandardGuiItem::no(),
111  QLatin1String("DoAskToStoreToKwallet"))) {
112  d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 );
113  if ( d->wallet ) {
114  connect(d->wallet, SIGNAL(walletClosed()), SLOT(slotWalletClosed()));
115  d->useWallet = true;
116  if ( !d->wallet->hasFolder( QLatin1String("ldapclient") ) ) {
117  d->wallet->createFolder( QLatin1String("ldapclient") );
118  }
119  d->wallet->setFolder( QLatin1String("ldapclient") );
120  d->wallet->writePassword(pwdBindBNEntry, pwdBindDN );
121  config.deleteEntry(pwdBindBNEntry);
122  config.sync();
123  }
124  }
125  server.setPassword( pwdBindDN );
126  } else { //Look at in Wallet
127  d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 );
128  if ( d->wallet ) {
129  d->useWallet = true;
130  if ( !d->wallet->setFolder( QLatin1String("ldapclient") ) ) {
131  d->wallet->createFolder( QLatin1String("ldapclient") );
132  d->wallet->setFolder( QLatin1String("ldapclient") );
133  }
134  d->wallet->readPassword( pwdBindBNEntry, pwdBindDN );
135  if (!pwdBindDN.isEmpty())
136  server.setPassword( pwdBindDN );
137  } else {
138  d->useWallet = false;
139  }
140  }
141 
142  server.setTimeLimit( config.readEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), 0 ) );
143  server.setSizeLimit( config.readEntry( prefix + QString::fromLatin1( "SizeLimit%1" ).arg( j ), 0 ) );
144  server.setPageSize( config.readEntry( prefix + QString::fromLatin1( "PageSize%1" ).arg( j ), 0 ) );
145  server.setVersion( config.readEntry( prefix + QString::fromLatin1( "Version%1" ).arg( j ), 3 ) );
146 
147  QString tmp;
148  tmp = config.readEntry( prefix + QString::fromLatin1( "Security%1" ).arg( j ),
149  QString::fromLatin1( "None" ) );
150  server.setSecurity( KLDAP::LdapServer::None );
151  if ( tmp == QLatin1String("SSL") ) {
152  server.setSecurity( KLDAP::LdapServer::SSL );
153  } else if ( tmp == QLatin1String("TLS") ) {
154  server.setSecurity( KLDAP::LdapServer::TLS );
155  }
156 
157  tmp = config.readEntry( prefix + QString::fromLatin1( "Auth%1" ).arg( j ),
158  QString::fromLatin1( "Anonymous" ) );
159  server.setAuth( KLDAP::LdapServer::Anonymous );
160  if ( tmp == QLatin1String("Simple") ) {
161  server.setAuth( KLDAP::LdapServer::Simple );
162  } else if ( tmp == QLatin1String("SASL") ) {
163  server.setAuth( KLDAP::LdapServer::SASL );
164  }
165 
166  server.setMech( config.readEntry( prefix + QString::fromLatin1( "Mech%1" ).arg( j ), QString() ) );
167 }
168 
169 void LdapClientSearchConfig::writeConfig( const KLDAP::LdapServer &server, KConfigGroup &config, int j, bool active )
170 {
171  QString prefix;
172  if ( active ) {
173  prefix = QLatin1String("Selected");
174  }
175 
176  config.writeEntry( prefix + QString::fromLatin1( "Host%1" ).arg( j ), server.host() );
177  config.writeEntry( prefix + QString::fromLatin1( "Port%1" ).arg( j ), server.port() );
178  config.writeEntry( prefix + QString::fromLatin1( "Base%1" ).arg( j ), server.baseDn().toString() );
179  config.writeEntry( prefix + QString::fromLatin1( "User%1" ).arg( j ), server.user() );
180  config.writeEntry( prefix + QString::fromLatin1( "Bind%1" ).arg( j ), server.bindDn() );
181 
182  const QString passwordEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j );
183  const QString password = server.password();
184  if (!password.isEmpty()) {
185  if (d->useWallet && !d->wallet) {
186  d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 );
187  }
188  if (d->wallet) {
189  d->wallet->writePassword(passwordEntry, password );
190  } else {
191  config.writeEntry( passwordEntry, password );
192  d->useWallet = false;
193  }
194  }
195 
196  config.writeEntry( prefix + QString::fromLatin1( "TimeLimit%1" ).arg( j ), server.timeLimit() );
197  config.writeEntry( prefix + QString::fromLatin1( "SizeLimit%1" ).arg( j ), server.sizeLimit() );
198  config.writeEntry( prefix + QString::fromLatin1( "PageSize%1" ).arg( j ), server.pageSize() );
199  config.writeEntry( prefix + QString::fromLatin1( "Version%1" ).arg( j ), server.version() );
200  QString tmp;
201  switch ( server.security() ) {
202  case KLDAP::LdapServer::TLS:
203  tmp = QLatin1String("TLS");
204  break;
205  case KLDAP::LdapServer::SSL:
206  tmp = QLatin1String("SSL");
207  break;
208  default:
209  tmp = QLatin1String("None");
210  }
211  config.writeEntry( prefix + QString::fromLatin1( "Security%1" ).arg( j ), tmp );
212  switch ( server.auth() ) {
213  case KLDAP::LdapServer::Simple:
214  tmp = QLatin1String("Simple");
215  break;
216  case KLDAP::LdapServer::SSL:
217  tmp = QLatin1String("SASL");
218  break;
219  default:
220  tmp = QLatin1String("Anonymous");
221  }
222  config.writeEntry( prefix + QString::fromLatin1( "Auth%1" ).arg( j ), tmp );
223  config.writeEntry( prefix + QString::fromLatin1( "Mech%1" ).arg( j ), server.mech() );
224 }
225 
226 void LdapClientSearchConfig::slotWalletClosed()
227 {
228  delete d->wallet;
229  d->wallet = 0;
230 }
231 
232 
233 #include "ldapclientsearchconfig.moc"
QObject
ldapclientsearchconfig.h
K_GLOBAL_STATIC_WITH_ARGS
K_GLOBAL_STATIC_WITH_ARGS(KConfig, s_config,(QLatin1String("kabldaprc"), KConfig::NoGlobals)) KConfig *LdapClientSearchConfig
Definition: ldapclientsearchconfig.cpp:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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