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

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
knserverinfo.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2005 the KNode authors.
4  See file AUTHORS for details
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  You should have received a copy of the GNU General Public License
11  along with this program; if not, write to the Free Software Foundation,
12  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
13 */
14 
15 #include "knserverinfo.h"
16 
17 #include "knaccountmanager.h"
18 #include "knglobals.h"
19 #include "utilities.h"
20 
21 #include <kmessagebox.h>
22 #include <kconfig.h>
23 #include <kconfiggroup.h>
24 #include <klocale.h>
25 #include <kwallet.h>
26 using namespace KWallet;
27 #include <kio/ioslave_defaults.h>
28 
29 
30 KNServerInfo::KNServerInfo() :
31  i_d( -1 ), p_ort( DEFAULT_NNTP_PORT ),
32  n_eedsLogon( false ), p_assDirty( false ),
33  mPassLoaded( false ),
34  mEncryption( None )
35 {
36 }
37 
38 
39 
40 KNServerInfo::~KNServerInfo()
41 {
42 }
43 
44 
45 void KNServerInfo::readConf(KConfigGroup& conf)
46 {
47  s_erver=conf.readEntry("server", "localhost");
48  p_ort=conf.readEntry( "port", DEFAULT_NNTP_PORT );
49  i_d=conf.readEntry("id", -1);
50 
51  n_eedsLogon=conf.readEntry("needsLogon",false);
52  u_ser=conf.readEntry("user");
53  p_ass = KNHelper::decryptStr(conf.readEntry("pass"));
54 
55  // migration to KWallet
56  if ( Wallet::isEnabled() ) {
57  if ( !p_ass.isEmpty() ) {
58  conf.deleteEntry( "pass" );
59  p_assDirty = true;
60  }
61  } else
62  mPassLoaded = true;
63 
64  // if the wallet is open, no need to delay the password loading
65  if (Wallet::isOpen( Wallet::NetworkWallet() ))
66  readPassword();
67 
68  QString encStr = conf.readEntry( "encryption", "None" );
69  if ( encStr.contains( "SSL", Qt::CaseInsensitive ) )
70  mEncryption = SSL;
71  else if ( encStr.contains( "TLS", Qt::CaseInsensitive ) )
72  mEncryption = TLS;
73  else
74  mEncryption = None;
75 }
76 
77 
78 void KNServerInfo::saveConf(KConfigGroup &conf)
79 {
80  conf.writeEntry("server", s_erver);
81  if ( p_ort == 0 ) p_ort = DEFAULT_NNTP_PORT;
82  conf.writeEntry("port", p_ort);
83  conf.writeEntry("id", i_d);
84 
85  conf.writeEntry("needsLogon", n_eedsLogon);
86  conf.writeEntry("user", u_ser);
87  // open wallet for storing only if the user actually changed the password
88  if (n_eedsLogon && p_assDirty) {
89  Wallet *wallet = KNAccountManager::wallet();
90  if (!wallet || wallet->writePassword(QString::number(i_d), p_ass)) {
91  if ( KMessageBox::warningYesNo( 0,
92  i18n("KWallet is not available. It is strongly recommended to use "
93  "KWallet for managing your passwords.\n"
94  "However, KNode can store the password in its configuration "
95  "file instead. The password is stored in an obfuscated format, "
96  "but should not be considered secure from decryption efforts "
97  "if access to the configuration file is obtained.\n"
98  "Do you want to store the password for server '%1' in the "
99  "configuration file?", server() ),
100  i18n("KWallet Not Available"),
101  KGuiItem( i18n("Store Password") ),
102  KGuiItem( i18n("Do Not Store Password") ) )
103  == KMessageBox::Yes ) {
104  conf.writeEntry( "pass", KNHelper::encryptStr( p_ass ) );
105  }
106  }
107  p_assDirty = false;
108  }
109 
110  switch ( mEncryption ) {
111  case SSL:
112  conf.writeEntry( "encryption", "SSL" );
113  break;
114  case TLS:
115  conf.writeEntry( "encryption", "TLS" );
116  break;
117  default:
118  conf.writeEntry( "encryption", "None" );
119  }
120 }
121 
122 
123 
124 bool KNServerInfo::operator==(const KNServerInfo &s) const
125 {
126  return ( (s_erver==s.s_erver) &&
127  (p_ort==s.p_ort) &&
128  (n_eedsLogon==s.n_eedsLogon) &&
129  (u_ser==s.u_ser) &&
130  (p_ass==s.p_ass) &&
131  (mEncryption == s.mEncryption)
132  );
133 }
134 
135 
136 const QString &KNServerInfo::pass()
137 {
138  // if we need to load the password, load all of them
139  if (n_eedsLogon && !mPassLoaded && p_ass.isEmpty() )
140  knGlobals.accountManager()->loadPasswords();
141 
142  return p_ass;
143 }
144 
145 void KNServerInfo::setPass(const QString &s)
146 {
147  if (p_ass != s) {
148  p_ass = s;
149  p_assDirty = true;
150  }
151 }
152 
153 
154 void KNServerInfo::readPassword()
155 {
156  // no need to load a password if the account doesn't require auth
157  if (!n_eedsLogon)
158  return;
159  mPassLoaded = true;
160 
161  // check whether there is a chance to find our password at all
162  if (Wallet::folderDoesNotExist(Wallet::NetworkWallet(), "knode") ||
163  Wallet::keyDoesNotExist(Wallet::NetworkWallet(), "knode", QString::number(i_d)))
164  return;
165 
166  // finally try to open the wallet and read the password
167  KWallet::Wallet *wallet = KNAccountManager::wallet();
168  if ( wallet )
169  wallet->readPassword( QString::number(i_d), p_ass );
170 }
KNServerInfo::readConf
void readConf(KConfigGroup &conf)
Definition: knserverinfo.cpp:45
KNServerInfo::SSL
Definition: knserverinfo.h:32
KNServerInfo::p_ort
int p_ort
Definition: knserverinfo.h:75
utilities.h
KNAccountManager::wallet
static KWallet::Wallet * wallet()
Returns a pointer to an open wallet if available, 0 otherwise.
Definition: knaccountmanager.cpp:239
knaccountmanager.h
KNHelper::encryptStr
static const QString encryptStr(const QString &aStr)
Definition: utilities.cpp:228
KNServerInfo::TLS
Definition: knserverinfo.h:32
KNServerInfo::i_d
int i_d
Definition: knserverinfo.h:75
KNServerInfo::s_erver
QString s_erver
Definition: knserverinfo.h:71
KNServerInfo::~KNServerInfo
~KNServerInfo()
Definition: knserverinfo.cpp:40
KNServerInfo::KNServerInfo
KNServerInfo()
Definition: knserverinfo.cpp:30
KNServerInfo::p_assDirty
bool p_assDirty
Definition: knserverinfo.h:77
KNHelper::decryptStr
static const QString decryptStr(const QString &aStr)
Definition: utilities.cpp:245
KNServerInfo::mEncryption
Encryption mEncryption
Encyrption method.
Definition: knserverinfo.h:83
KNServerInfo::None
Definition: knserverinfo.h:32
KNServerInfo::n_eedsLogon
bool n_eedsLogon
Definition: knserverinfo.h:77
KNServerInfo
Represents an account on a news server.
Definition: knserverinfo.h:29
KNServerInfo::setPass
void setPass(const QString &s)
Definition: knserverinfo.cpp:145
KNServerInfo::u_ser
QString u_ser
Definition: knserverinfo.h:71
knglobals.h
KNServerInfo::pass
const QString & pass()
Definition: knserverinfo.cpp:136
KNServerInfo::p_ass
QString p_ass
Definition: knserverinfo.h:71
KNServerInfo::saveConf
void saveConf(KConfigGroup &conf)
Definition: knserverinfo.cpp:78
KNServerInfo::readPassword
void readPassword()
Loads the password from KWallet, used for on-demand password loading.
Definition: knserverinfo.cpp:154
knGlobals
#define knGlobals
Keep compatibility with the old way.
Definition: knglobals.h:28
KNServerInfo::mPassLoaded
bool mPassLoaded
Prevent loading the password multiple times since wallet operations from the I/O thread don't work...
Definition: knserverinfo.h:81
KNServerInfo::server
const QString & server()
Definition: knserverinfo.h:47
KNServerInfo::operator==
bool operator==(const KNServerInfo &s) const
Definition: knserverinfo.cpp:124
knserverinfo.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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