~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to core/smb4kwalletmanager.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
    smb4kwalletmanager  -  This is the wallet manager of Smb4K.
3
3
                             -------------------
4
4
    begin                : Sa Dez 27 2008
5
 
    copyright            : (C) 2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
 
5
    copyright            : (C) 2008-2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.net
7
7
 ***************************************************************************/
8
8
 
9
9
/***************************************************************************
19
19
 *                                                                         *
20
20
 *   You should have received a copy of the GNU General Public License     *
21
21
 *   along with this program; if not, write to the                         *
22
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
23
 
 *   MA  02111-1307 USA                                                    *
 
22
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
23
 *   MA 02110-1335, USA                                                    *
24
24
 ***************************************************************************/
25
25
 
26
26
// Qt includes
27
27
#include <QDesktopWidget>
28
 
#ifdef __FreeBSD__
 
28
#ifdef Q_OS_FREEBSD
29
29
#include <QFile>
30
30
#include <QDir>
31
31
#include <QTextCodec>
38
38
#include <kapplication.h>
39
39
#include <kpassworddialog.h>
40
40
#include <klocale.h>
41
 
#ifdef __FreeBSD__
 
41
#ifdef Q_OS_FREEBSD
42
42
#include <kprocess.h>
 
43
#include <kstandarddirs.h>
43
44
#endif
44
45
 
45
46
// application specific includes
47
48
#include <smb4ksettings.h>
48
49
#include <smb4kauthinfo.h>
49
50
#include <smb4khomesshareshandler.h>
50
 
#ifdef __FreeBSD__
51
 
#include <smb4kcoremessage.h>
52
 
#include <smb4ksambaoptionshandler.h>
53
 
#endif
54
51
#include <smb4kglobal.h>
 
52
#include <smb4knotification.h>
 
53
#include <smb4khost.h>
 
54
#include <smb4kshare.h>
55
55
 
56
56
using namespace Smb4KGlobal;
57
57
 
75
75
 
76
76
Smb4KWalletManager::~Smb4KWalletManager()
77
77
{
78
 
  // FIXME: Do we have to delete the wallet here?
79
78
}
80
79
 
81
80
 
85
84
}
86
85
 
87
86
 
88
 
void Smb4KWalletManager::init( QWidget *parent, bool async )
 
87
void Smb4KWalletManager::init()
89
88
{
90
89
  if ( KWallet::Wallet::isEnabled() && Smb4KSettings::useWallet() )
91
90
  {
93
92
    // so try to get the wallet.
94
93
    if ( !m_wallet )
95
94
    {
96
 
      int window_id = (parent ? parent->winId() : (kapp->activeWindow() ?
97
 
                      kapp->activeWindow()->winId() : kapp->desktop()->winId()));
98
 
 
99
 
      if ( async )
100
 
      {
101
 
        m_wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(),
102
 
                                                window_id,
103
 
                                                KWallet::Wallet::Asynchronous );
104
 
 
105
 
        connect( m_wallet, SIGNAL( walletOpened( bool ) ),
106
 
                 this,     SIGNAL( walletOpened( bool ) ) );
107
 
 
108
 
        connect( m_wallet, SIGNAL( walletOpened( bool ) ),
109
 
                 this,     SLOT( slotWalletOpened( bool ) ) );
 
95
      // Get the main window as parent of the wallet.
 
96
      QWidget *parent = 0;
 
97
      QWidgetList top_level = kapp->topLevelWidgets();
 
98
 
 
99
      for ( int i = 0; i < top_level.size(); ++i )
 
100
      {
 
101
        if ( QString::compare( top_level.at( i )->metaObject()->className(), "Smb4KMainWindow" ) == 0 )
 
102
        {
 
103
          parent = top_level[i];
 
104
          break;
 
105
        }
 
106
        else
 
107
        {
 
108
          continue;
 
109
        }
 
110
      }
 
111
 
 
112
      m_wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(),
 
113
                                              parent ? parent->winId() : 0,
 
114
                                              KWallet::Wallet::Synchronous );
 
115
 
 
116
      if ( m_wallet )
 
117
      {
 
118
        setupFolder();
 
119
        m_state = UseWallet;
110
120
      }
111
121
      else
112
122
      {
113
 
        m_wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(),
114
 
                                                window_id,
115
 
                                                KWallet::Wallet::Synchronous );
116
 
 
117
 
        if ( m_wallet )
118
 
        {
119
 
          setupFolder();
120
 
          m_state = UseWallet;
121
 
        }
122
 
        else
123
 
        {
124
 
          kDebug() << "Opening the wallet failed ..." << endl;
125
 
          m_state = Unknown;
126
 
        }
127
 
 
128
 
        emit initialized();
 
123
        Smb4KNotification *notification = new Smb4KNotification( this );
 
124
        notification->openingWalletFailed( KWallet::Wallet::NetworkWallet() );
 
125
 
 
126
        m_state = Unknown;
129
127
      }
 
128
 
 
129
      emit initialized();
130
130
    }
131
131
    else
132
132
    {
170
170
  }
171
171
  else
172
172
  {
173
 
    kDebug() << "No wallet or wallet not open ..." << endl;
 
173
    Smb4KNotification *notification = new Smb4KNotification( this );
 
174
    notification->loginsNotAccessible();
174
175
  }
175
176
}
176
177
 
177
178
 
178
 
void Smb4KWalletManager::readAuthInfo( Smb4KAuthInfo *authInfo )
 
179
void Smb4KWalletManager::readAuthInfo( Smb4KBasicNetworkItem *networkItem )
179
180
{
180
 
  Q_ASSERT( authInfo );
 
181
  Q_ASSERT( networkItem );
181
182
 
182
183
  // Initialize the wallet manager. In case the wallet is already
183
 
  // set up, init() will just do nothing.
184
 
  init( 0 );
 
184
  // set up, init() will do nothing.
 
185
  init();
185
186
 
186
 
  if ( m_wallet )
 
187
  if ( useWalletSystem() && m_wallet )
187
188
  {
188
 
    bool set_auth_info = false;
 
189
    bool auth_info_set = false;
189
190
 
190
 
    // Read the authentication information.
191
 
    switch ( authInfo->type() )
 
191
    switch ( networkItem->type() )
192
192
    {
193
 
      case Smb4KAuthInfo::Host:
194
 
      {
195
 
        QMap<QString,QString> map;
196
 
 
197
 
        if ( m_wallet->hasEntry( authInfo->unc().toUpper() ) )
198
 
        {
199
 
          m_wallet->readMap( authInfo->unc().toUpper(), map );
200
 
        }
201
 
        else if ( m_wallet->hasEntry( authInfo->hostName().toUpper() ) )
202
 
        {
203
 
          m_wallet->readMap( authInfo->hostName().toUpper(), map );
204
 
          m_wallet->removeEntry( authInfo->hostName().toUpper() );
205
 
        }
206
 
        else
207
 
        {
208
 
          // Do nothing
209
 
        }
210
 
 
211
 
        // Only set the authentication information the map is not empty and if
212
 
        // either the login was not set in authInfo or it is equal to map["Login"].
213
 
        if ( !map.isEmpty() &&
214
 
             (authInfo->login().isEmpty() || QString::compare( QString::fromLocal8Bit( authInfo->login() ), map["Login"] ) == 0) )
215
 
        {
216
 
          // Do not set the authentication, if the workgroup does not match.
217
 
          if ( map["Workgroup"].isEmpty() || authInfo->workgroupName().isEmpty() ||
218
 
              QString::compare( map["Workgroup"], authInfo->workgroupName().toUpper() ) == 0 )
219
 
          {
220
 
            authInfo->setLogin( map["Login"] );
221
 
            authInfo->setPassword( map["Password"] );
222
 
 
223
 
            if ( !map["Workgroup"].isEmpty() && authInfo->workgroupName().isEmpty() )
224
 
            {
225
 
              authInfo->setWorkgroupName( map["Workgroup"] );
226
 
            }
227
 
            else
228
 
            {
229
 
              // Do nothing
230
 
            }
231
 
 
232
 
            set_auth_info = true;
233
 
          }
234
 
          else
235
 
          {
236
 
            // Do nothing
237
 
          }
238
 
        }
239
 
        else
240
 
        {
241
 
          // Do nothing
242
 
        }
243
 
 
244
 
        break;
245
 
      }
246
 
      case Smb4KAuthInfo::Share:
247
 
      {
248
 
        // Read the authentication information. Prefer the exact match,
249
 
        // but also look for an entry that was provided for the host.
250
 
        QMap<QString,QString> map;
251
 
        m_wallet->readMap( authInfo->unc().toUpper(), map );
252
 
 
253
 
        if ( map.isEmpty() )
254
 
        {
255
 
          m_wallet->readMap( authInfo->hostUNC().toUpper(), map );
256
 
        }
257
 
        else
258
 
        {
259
 
          // Do nothing
260
 
        }
261
 
 
262
 
        // Only set the authentication information the map is not empty and if
263
 
        // either the login was not set in authInfo or it is equal to map["Login"].
264
 
        if ( !map.isEmpty() &&
265
 
             (authInfo->login().isEmpty() || QString::compare( QString::fromLocal8Bit( authInfo->login() ), map["Login"] ) == 0) )
266
 
        {
267
 
          if ( map["Workgroup"].isEmpty() || authInfo->workgroupName().isEmpty() ||
268
 
              QString::compare( map["Workgroup"], authInfo->workgroupName().toUpper() ) == 0 )
269
 
          {
270
 
            authInfo->setLogin( map["Login"] );
271
 
            authInfo->setPassword( map["Password"] );
272
 
 
273
 
            if ( !map["Workgroup"].isEmpty() && authInfo->workgroupName().isEmpty() )
274
 
            {
275
 
              authInfo->setWorkgroupName( map["Workgroup"] );
276
 
            }
277
 
            else
278
 
            {
279
 
              // Do nothing
280
 
            }
281
 
 
282
 
            set_auth_info = true;
283
 
          }
284
 
          else
285
 
          {
286
 
            // Do nothing
287
 
          }
288
 
        }
289
 
        else
290
 
        {
291
 
          // Do nothing
292
 
        }
293
 
 
294
 
        break;
295
 
      }
296
 
      case Smb4KAuthInfo::Default:
297
 
      {
298
 
        QMap<QString,QString> map;
299
 
        m_wallet->readMap( "DEFAULT_LOGIN", map );
300
 
 
301
 
        if ( !map.isEmpty() )
302
 
        {
303
 
          authInfo->setLogin( map["Login"] );
304
 
          authInfo->setPassword( map["Password"] );
305
 
        }
306
 
        else
307
 
        {
308
 
          // Do nothing
309
 
        }
310
 
 
 
193
      case Smb4KBasicNetworkItem::Host:
 
194
      {
 
195
        Smb4KHost *host = static_cast<Smb4KHost *>( networkItem );
 
196
 
 
197
        if ( host )
 
198
        {
 
199
          QMap<QString,QString> map;
 
200
 
 
201
          if ( m_wallet->hasEntry( host->unc().toUpper() ) )
 
202
          {
 
203
            m_wallet->readMap( host->unc().toUpper(), map );
 
204
          }
 
205
          else
 
206
          {
 
207
            // Do nothing
 
208
          }
 
209
 
 
210
          // Set the authentication information.
 
211
          if ( !map.isEmpty() && (host->workgroupName().isEmpty() || map["Workgroup"].isEmpty() ||
 
212
               QString::compare( host->workgroupName(), map.value( "Workgroup" ), Qt::CaseInsensitive ) == 0) )
 
213
          {
 
214
            if ( !host->login().isEmpty() )
 
215
            {
 
216
              if ( QString::compare( host->login(), map.value( "Login" ) ) == 0 )
 
217
              {
 
218
                host->setLogin( map.value( "Login" ) );
 
219
                host->setPassword( map.value( "Password" ) );
 
220
                auth_info_set = true;
 
221
              }
 
222
              else
 
223
              {
 
224
                // Do nothing
 
225
              }
 
226
            }
 
227
            else
 
228
            {
 
229
              host->setLogin( map.value( "Login" ) );
 
230
              host->setPassword( map.value( "Password" ) );
 
231
              auth_info_set = true;
 
232
            }
 
233
 
 
234
            // In difference to the readAuthInfo() function that takes an Smb4KAuthInfo
 
235
            // object, do not set the workgroup or IP address here.
 
236
          }
 
237
          else
 
238
          {
 
239
            // Do nothing
 
240
          }
 
241
 
 
242
          // If no authentication information was set until now, check if
 
243
          // we have to set the default login then.
 
244
          if ( !auth_info_set && Smb4KSettings::useDefaultLogin() )
 
245
          {
 
246
            QMap<QString,QString> map;
 
247
            m_wallet->readMap( "DEFAULT_LOGIN", map );
 
248
 
 
249
            if ( !map.isEmpty() )
 
250
            {
 
251
              host->setLogin( map["Login"] );
 
252
              host->setPassword( map["Password"] );
 
253
            }
 
254
            else
 
255
            {
 
256
              // Do nothing
 
257
            }
 
258
          }
 
259
          else
 
260
          {
 
261
            // Do nothing
 
262
          }
 
263
#ifdef Q_OS_FREEBSD
 
264
          Smb4KAuthInfo authInfo( host );
 
265
          writeToConfigFile( &authInfo );
 
266
#endif
 
267
        }
 
268
        else
 
269
        {
 
270
          // Do nothing
 
271
        }
 
272
        break;
 
273
      }
 
274
      case Smb4KBasicNetworkItem::Share:
 
275
      {
 
276
        Smb4KShare *share = static_cast<Smb4KShare *>( networkItem );
 
277
 
 
278
        if ( share )
 
279
        {
 
280
          QMap<QString,QString> map;
 
281
 
 
282
          if ( !share->isHomesShare() )
 
283
          {
 
284
            if ( m_wallet->hasEntry( share->unc().toUpper() ) )
 
285
            {
 
286
              m_wallet->readMap( share->unc().toUpper(), map );
 
287
            }
 
288
            else
 
289
            {
 
290
              m_wallet->readMap( share->hostUNC().toUpper(), map );
 
291
            }
 
292
          }
 
293
          else
 
294
          {
 
295
            // Specify a user name if necessary. The overwrite argument
 
296
            // is set to FALSE here, so that no dialog is shown if a user
 
297
            // name has already been provided.
 
298
            Smb4KHomesSharesHandler::self()->specifyUser( share, false );
 
299
 
 
300
            if ( m_wallet->hasEntry( share->homeUNC().toUpper() ) )
 
301
            {
 
302
              m_wallet->readMap( share->homeUNC().toUpper(), map );
 
303
            }
 
304
            else
 
305
            {
 
306
              m_wallet->readMap( share->hostUNC().toUpper(), map );
 
307
            }
 
308
          }
 
309
 
 
310
          // Set the authentication information.
 
311
          if ( !map.isEmpty() && (share->workgroupName().isEmpty() || map["Workgroup"].isEmpty() ||
 
312
               QString::compare( share->workgroupName(), map.value( "Workgroup" ), Qt::CaseInsensitive ) == 0) )
 
313
          {
 
314
            if ( !share->login().isEmpty() )
 
315
            {
 
316
              if ( QString::compare( share->login(), map.value( "Login" ) ) == 0 )
 
317
              {
 
318
                share->setLogin( map.value( "Login" ) );
 
319
                share->setPassword( map.value( "Password" ) );
 
320
                auth_info_set = true;
 
321
              }
 
322
              else
 
323
              {
 
324
                // Do nothing
 
325
              }
 
326
            }
 
327
            else
 
328
            {
 
329
              share->setLogin( map.value( "Login" ) );
 
330
              share->setPassword( map.value( "Password" ) );
 
331
              auth_info_set = true;
 
332
            }
 
333
 
 
334
            // In difference to the readAuthInfo() function that takes an Smb4KAuthInfo
 
335
            // object, do not set the workgroup or IP address here.
 
336
          }
 
337
          else
 
338
          {
 
339
            // Do nothing
 
340
          }
 
341
 
 
342
          // If no authentication information was set until now, check if
 
343
          // we have to set the default login then.
 
344
          if ( !auth_info_set && Smb4KSettings::useDefaultLogin() )
 
345
          {
 
346
            QMap<QString,QString> map;
 
347
            m_wallet->readMap( "DEFAULT_LOGIN", map );
 
348
 
 
349
            if ( !map.isEmpty() )
 
350
            {
 
351
              share->setLogin( map["Login"] );
 
352
              share->setPassword( map["Password"] );
 
353
            }
 
354
            else
 
355
            {
 
356
              // Do nothing
 
357
            }
 
358
          }
 
359
          else
 
360
          {
 
361
            // Do nothing
 
362
          }
 
363
#ifdef Q_OS_FREEBSD
 
364
          Smb4KAuthInfo authInfo( share );
 
365
          writeToConfigFile( &authInfo );
 
366
#endif
 
367
        }
 
368
        else
 
369
        {
 
370
          // Do nothing
 
371
        }
311
372
        break;
312
373
      }
313
374
      default:
315
376
        break;
316
377
      }
317
378
    }
318
 
 
319
 
    // If there was no matching authentication information, use the
320
 
    // default one, if it exists.
321
 
    if ( !set_auth_info && Smb4KSettings::useDefaultLogin() &&
322
 
         authInfo->type() != Smb4KAuthInfo::Default )
323
 
    {
324
 
      QMap<QString,QString> map;
325
 
      m_wallet->readMap( "DEFAULT_LOGIN", map );
326
 
 
327
 
      if ( !map.isEmpty() )
328
 
      {
329
 
        authInfo->setLogin( map["Login"] );
330
 
        authInfo->setPassword( map["Password"] );
331
 
      }
332
 
      else
333
 
      {
334
 
        // Do nothing
335
 
      }
336
 
    }
337
 
    else
338
 
    {
339
 
      // Do nothing
340
 
    }
341
379
  }
342
380
  else
343
381
  {
344
 
    for ( int i = 0; i < m_list.size(); ++i )
 
382
    switch ( networkItem->type() )
345
383
    {
346
 
      if ( QString::compare( authInfo->unc().toUpper(), m_list.at( i )->unc().toUpper() ) == 0 )
347
 
      {
348
 
        // Exact match
349
 
        authInfo->setLogin( m_list.at( i )->login() );
350
 
        authInfo->setPassword( m_list.at( i )->password() );
351
 
 
352
 
        if ( authInfo->workgroupName().isEmpty() )
353
 
        {
354
 
          authInfo->setWorkgroupName( m_list.at( i )->workgroupName() );
355
 
        }
356
 
        else
357
 
        {
358
 
          // Do nothing
359
 
        }
360
 
 
361
 
        break;
362
 
      }
363
 
      else if ( QString::compare( authInfo->hostUNC().toUpper(),
364
 
                m_list.at( i )->hostUNC().toUpper() ) == 0 )
365
 
      {
366
 
        // The host is the same
367
 
        authInfo->setLogin( m_list.at( i )->login() );
368
 
        authInfo->setPassword( m_list.at( i )->password() );
369
 
 
370
 
        if ( authInfo->workgroupName().isEmpty() )
371
 
        {
372
 
          authInfo->setWorkgroupName( m_list.at( i )->workgroupName() );
373
 
        }
374
 
        else
375
 
        {
376
 
          // Do nothing
377
 
        }
378
 
 
379
 
        continue;
380
 
      }
381
 
      else
382
 
      {
383
 
        continue;
 
384
      case Smb4KBasicNetworkItem::Host:
 
385
      {
 
386
        Smb4KHost *host = static_cast<Smb4KHost *>( networkItem );
 
387
 
 
388
        if ( host )
 
389
        {
 
390
          for ( int i = 0; i < m_list.size(); ++i )
 
391
          {
 
392
            if ( QString::compare( host->unc(), m_list.at( i )->unc(), Qt::CaseInsensitive ) == 0 &&
 
393
                 (host->workgroupName().isEmpty() || m_list.at( i )->workgroupName().isEmpty() ||
 
394
                 QString::compare( host->workgroupName(), m_list.at( i )->workgroupName(), Qt::CaseInsensitive ) == 0) )
 
395
            {
 
396
              if ( !host->login().isEmpty() )
 
397
              {
 
398
                if ( QString::compare( host->login(), m_list.at( i )->login() ) == 0 )
 
399
                {
 
400
                  host->setLogin( m_list.at( i )->login() );
 
401
                  host->setPassword( m_list.at( i )->password() );
 
402
                }
 
403
                else
 
404
                {
 
405
                  // Do nothing
 
406
                }
 
407
              }
 
408
              else
 
409
              {
 
410
                host->setLogin( m_list.at( i )->login() );
 
411
                host->setPassword( m_list.at( i )->password() );
 
412
              }
 
413
              break;
 
414
            }
 
415
            else
 
416
            {
 
417
              continue;
 
418
            }
 
419
          }
 
420
#ifdef Q_OS_FREEBSD
 
421
          Smb4KAuthInfo authInfo( host );
 
422
          writeToConfigFile( &authInfo );
 
423
#endif
 
424
        }
 
425
        else
 
426
        {
 
427
          // Do nothing
 
428
        }
 
429
        break;
 
430
      }
 
431
      case Smb4KBasicNetworkItem::Share:
 
432
      {
 
433
        Smb4KShare *share = static_cast<Smb4KShare *>( networkItem );
 
434
 
 
435
        if ( share )
 
436
        {
 
437
          QString unc;
 
438
 
 
439
          if ( !share->isHomesShare() )
 
440
          {
 
441
            unc = share->unc();
 
442
          }
 
443
          else
 
444
          {
 
445
            // Specify a user name if necessary. The overwrite argument
 
446
            // is set to FALSE here, so that no dialog is shown if a user
 
447
            // name has already been provided.
 
448
            Smb4KHomesSharesHandler::self()->specifyUser( share, false );
 
449
 
 
450
            unc = share->homeUNC();
 
451
          }
 
452
 
 
453
          for ( int i = 0; i < m_list.size(); ++i )
 
454
          {
 
455
            if ( QString::compare( unc, m_list.at( i )->unc(), Qt::CaseInsensitive ) == 0 &&
 
456
                 (share->workgroupName().isEmpty() || m_list.at( i )->workgroupName().isEmpty() ||
 
457
                 QString::compare( share->workgroupName(), m_list.at( i )->workgroupName(), Qt::CaseInsensitive ) == 0) )
 
458
            {
 
459
              // Exact match
 
460
              if ( !share->login().isEmpty() )
 
461
              {
 
462
                if ( QString::compare( share->login(), m_list.at( i )->login() ) == 0 )
 
463
                {
 
464
                  share->setLogin( m_list.at( i )->login() );
 
465
                  share->setPassword( m_list.at( i )->password() );
 
466
                }
 
467
                else
 
468
                {
 
469
                  // Do nothing
 
470
                }
 
471
              }
 
472
              else
 
473
              {
 
474
                share->setLogin( m_list.at( i )->login() );
 
475
                share->setPassword( m_list.at( i )->password() );
 
476
              }
 
477
              break;
 
478
            }
 
479
            else if ( QString::compare( share->hostUNC(), m_list.at( i )->hostUNC(), Qt::CaseInsensitive ) == 0 &&
 
480
                      (share->workgroupName().isEmpty() || m_list.at( i )->workgroupName().isEmpty() ||
 
481
                      QString::compare( share->workgroupName(), m_list.at( i )->workgroupName(), Qt::CaseInsensitive ) == 0) )
 
482
            {
 
483
              // The host is the same
 
484
              if ( !share->login().isEmpty() )
 
485
              {
 
486
                if ( QString::compare( share->login(), m_list.at( i )->login() ) == 0 )
 
487
                {
 
488
                  share->setLogin( m_list.at( i )->login() );
 
489
                  share->setPassword( m_list.at( i )->password() );
 
490
                }
 
491
                else
 
492
                {
 
493
                  // Do nothing
 
494
                }
 
495
              }
 
496
              else
 
497
              {
 
498
                share->setLogin( m_list.at( i )->login() );
 
499
                share->setPassword( m_list.at( i )->password() );
 
500
              }
 
501
              continue;
 
502
            }
 
503
            else
 
504
            {
 
505
              continue;
 
506
            }
 
507
          }
 
508
#ifdef Q_OS_FREEBSD
 
509
          Smb4KAuthInfo authInfo( share );
 
510
          writeToConfigFile( &authInfo );
 
511
#endif
 
512
        }
 
513
        else
 
514
        {
 
515
          // Do nothing
 
516
        }
 
517
        break;
 
518
      }
 
519
      default:
 
520
      {
 
521
        break;
384
522
      }
385
523
    }
386
524
 
398
536
      // Do nothing
399
537
    }
400
538
  }
401
 
#ifdef __FreeBSD__
402
 
  writeToConfigFile( authInfo );
403
 
#endif
404
539
}
405
540
 
406
541
 
407
 
void Smb4KWalletManager::writeAuthInfo( Smb4KAuthInfo *authInfo )
 
542
void Smb4KWalletManager::readDefaultAuthInfo( Smb4KAuthInfo *authInfo )
408
543
{
409
544
  Q_ASSERT( authInfo );
410
545
 
411
546
  // Initialize the wallet manager. In case the wallet is already
412
547
  // set up, init() will just do nothing.
413
 
  init( 0 );
 
548
  init();
414
549
 
415
 
  if ( m_wallet )
 
550
  // Since we do not store default authentication information
 
551
  // when no wallet is used, we only need to read from the wallet.
 
552
  if ( useWalletSystem() && m_wallet )
416
553
  {
417
 
    // Write the authentication information to the wallet, if it
418
 
    // is not empty.
419
554
    QMap<QString,QString> map;
420
 
 
421
 
    if ( !authInfo->login().isEmpty() /* allow empty passwords */ )
422
 
    {
 
555
    m_wallet->readMap( "DEFAULT_LOGIN", map );
 
556
 
 
557
    if ( !map.isEmpty() )
 
558
    {
 
559
      authInfo->setLogin( map["Login"] );
 
560
      authInfo->setPassword( map["Password"] );
 
561
    }
 
562
    else
 
563
    {
 
564
      // Do nothing
 
565
    }
 
566
 
 
567
    authInfo->useDefaultAuthInfo();
 
568
  }
 
569
  else
 
570
  {
 
571
    // Do nothing
 
572
  }
 
573
}
 
574
 
 
575
 
 
576
void Smb4KWalletManager::writeAuthInfo( Smb4KBasicNetworkItem *networkItem )
 
577
{
 
578
  Q_ASSERT( networkItem );
 
579
 
 
580
  // Initialize the wallet manager. In case the wallet is already
 
581
  // set up, init() will just do nothing.
 
582
  init();
 
583
 
 
584
  if ( useWalletSystem() && m_wallet )
 
585
  {
 
586
    switch ( networkItem->type() )
 
587
    {
 
588
      case Smb4KBasicNetworkItem::Host:
 
589
      {
 
590
        Smb4KHost *host = static_cast<Smb4KHost *>( networkItem );
 
591
 
 
592
        if ( host )
 
593
        {
 
594
          // Write the authentication information to the wallet, if it
 
595
          // is not empty.
 
596
          if ( !host->login().isEmpty() /* allow empty passwords */ && !host->hostName().isEmpty() )
 
597
          {
 
598
            QMap<QString,QString> map;
 
599
            map["Login"]    = host->login();
 
600
            map["Password"] = host->password();
 
601
 
 
602
            if ( !host->workgroupName().isEmpty() )
 
603
            {
 
604
              map["Workgroup"] = host->workgroupName().toUpper();
 
605
            }
 
606
            else
 
607
            {
 
608
              // Do nothing
 
609
            }
 
610
 
 
611
            if ( !host->ip().isEmpty() )
 
612
            {
 
613
              map["IP Address"] = host->ip();
 
614
            }
 
615
            else
 
616
            {
 
617
              // Do nothing
 
618
            }
 
619
 
 
620
            m_wallet->writeMap( host->unc().toUpper(), map );
 
621
            m_wallet->sync();
 
622
          }
 
623
          else
 
624
          {
 
625
            // Do nothing
 
626
          }
 
627
 
 
628
#ifdef Q_OS_FREEBSD
 
629
          Smb4KAuthInfo authInfo( host );
 
630
          writeToConfigFile( &authInfo );
 
631
#endif
 
632
        }
 
633
        else
 
634
        {
 
635
          // Do nothing
 
636
        }
 
637
        break;
 
638
      }
 
639
      case Smb4KBasicNetworkItem::Share:
 
640
      {
 
641
        Smb4KShare *share = static_cast<Smb4KShare *>( networkItem );
 
642
 
 
643
        if ( share )
 
644
        {
 
645
          // Write the authentication information to the wallet, if it
 
646
          // is not empty.
 
647
          if ( !share->login().isEmpty() /* allow empty passwords */ && !share->hostName().isEmpty() )
 
648
          {
 
649
            QMap<QString,QString> map;
 
650
            map["Login"]    = share->login();
 
651
            map["Password"] = share->password();
 
652
 
 
653
            if ( !share->workgroupName().isEmpty() )
 
654
            {
 
655
              map["Workgroup"] = share->workgroupName().toUpper();
 
656
            }
 
657
            else
 
658
            {
 
659
              // Do nothing
 
660
            }
 
661
 
 
662
            if ( !share->hostIP().isEmpty() )
 
663
            {
 
664
              map["IP Address"] = share->hostIP();
 
665
            }
 
666
            else
 
667
            {
 
668
              // Do nothing
 
669
            }
 
670
 
 
671
            if ( !share->isHomesShare() )
 
672
            {
 
673
              m_wallet->writeMap( share->unc().toUpper(), map );
 
674
            }
 
675
            else
 
676
            {
 
677
              m_wallet->writeMap( share->homeUNC().toUpper(), map );
 
678
            }
 
679
            m_wallet->sync();
 
680
          }
 
681
          else
 
682
          {
 
683
            // Do nothing
 
684
          }
 
685
 
 
686
#ifdef Q_OS_FREEBSD
 
687
          Smb4KAuthInfo authInfo( share );
 
688
          writeToConfigFile( &authInfo );
 
689
#endif
 
690
        }
 
691
        else
 
692
        {
 
693
          // Do nothing
 
694
        }
 
695
        break;
 
696
      }
 
697
      default:
 
698
      {
 
699
        break;
 
700
      }
 
701
    }
 
702
  }
 
703
  else
 
704
  {
 
705
    // Clear the list if necessary, i.e. if the wallet manager
 
706
    // should forget the previously used login(s).
 
707
    if ( !Smb4KSettings::rememberLogins() )
 
708
    {
 
709
      while ( !m_list.isEmpty() )
 
710
      {
 
711
        delete m_list.takeFirst();
 
712
      }
 
713
    }
 
714
    else
 
715
    {
 
716
      // Do nothing
 
717
    }
 
718
 
 
719
    // Now insert the new authentication information. Before we
 
720
    // do this, remove the old one, if one is present.
 
721
    switch ( networkItem->type() )
 
722
    {
 
723
      case Smb4KBasicNetworkItem::Host:
 
724
      {
 
725
        Smb4KHost *host = static_cast<Smb4KHost *>( networkItem );
 
726
 
 
727
        if ( host )
 
728
        {
 
729
          Smb4KAuthInfo authInfo( host );
 
730
 
 
731
          QMutableListIterator<Smb4KAuthInfo *> it( m_list );
 
732
 
 
733
          while ( it.hasNext() )
 
734
          {
 
735
            Smb4KAuthInfo *auth_info = it.next();
 
736
 
 
737
            if ( QString::compare( auth_info->unc(), authInfo.unc(), Qt::CaseInsensitive ) == 0 &&
 
738
                 (auth_info->workgroupName().isEmpty() || authInfo.workgroupName().isEmpty() ||
 
739
                 QString::compare( auth_info->workgroupName(), authInfo.workgroupName(), Qt::CaseInsensitive ) == 0) )
 
740
            {
 
741
              it.remove();
 
742
              break;
 
743
            }
 
744
            else
 
745
            {
 
746
              // Do nothing
 
747
            }
 
748
          }
 
749
 
 
750
          m_list << new Smb4KAuthInfo( authInfo );
 
751
 
 
752
#ifdef Q_OS_FREEBSD
 
753
          writeToConfigFile( &authInfo );
 
754
#endif
 
755
        }
 
756
        else
 
757
        {
 
758
          // Do nothing
 
759
        }
 
760
        break;
 
761
      }
 
762
      case Smb4KBasicNetworkItem::Share:
 
763
      {
 
764
        Smb4KShare *share = static_cast<Smb4KShare *>( networkItem );
 
765
 
 
766
        if ( share )
 
767
        {
 
768
          Smb4KAuthInfo authInfo( share );
 
769
 
 
770
          QMutableListIterator<Smb4KAuthInfo *> it( m_list );
 
771
 
 
772
          while ( it.hasNext() )
 
773
          {
 
774
            Smb4KAuthInfo *auth_info = it.next();
 
775
 
 
776
            if ( QString::compare( auth_info->unc(), authInfo.unc(), Qt::CaseInsensitive ) == 0 &&
 
777
                 (auth_info->workgroupName().isEmpty() || authInfo.workgroupName().isEmpty() ||
 
778
                 QString::compare( auth_info->workgroupName(), authInfo.workgroupName(), Qt::CaseInsensitive ) == 0) )
 
779
            {
 
780
              it.remove();
 
781
              break;
 
782
            }
 
783
            else
 
784
            {
 
785
              // Do nothing
 
786
            }
 
787
          }
 
788
 
 
789
          m_list << new Smb4KAuthInfo( authInfo );
 
790
 
 
791
#ifdef Q_OS_FREEBSD
 
792
          writeToConfigFile( &authInfo );
 
793
#endif
 
794
        }
 
795
        else
 
796
        {
 
797
          // Do nothing
 
798
        }
 
799
        break;
 
800
      }
 
801
      default:
 
802
      {
 
803
        break;
 
804
      }
 
805
    }
 
806
  }
 
807
}
 
808
 
 
809
 
 
810
void Smb4KWalletManager::writeDefaultAuthInfo( Smb4KAuthInfo *authInfo )
 
811
{
 
812
  Q_ASSERT( authInfo );
 
813
 
 
814
  if ( useWalletSystem() && m_wallet )
 
815
  {
 
816
    // Write the default authentication information to the wallet
 
817
    if ( authInfo->type() == Smb4KAuthInfo::Default && !authInfo->login().isEmpty() /* allow empty passwords */ )
 
818
    {
 
819
      QMap<QString,QString> map;
423
820
      map["Login"]    = authInfo->login();
424
821
      map["Password"] = authInfo->password();
 
822
      m_wallet->writeMap( "DEFAULT_LOGIN", map );
 
823
      m_wallet->sync();
425
824
    }
426
825
    else
427
826
    {
428
 
      return;
429
 
    }
430
 
 
431
 
    switch ( authInfo->type() )
432
 
    {
433
 
      case Smb4KAuthInfo::Default:
434
 
      {
435
 
        m_wallet->writeMap( "DEFAULT_LOGIN", map );
436
 
        break;
437
 
      }
438
 
      default:
439
 
      {
440
 
        if ( !authInfo->workgroupName().isEmpty() )
441
 
        {
442
 
          map["Workgroup"] = authInfo->workgroupName().toUpper();
443
 
        }
444
 
        else
445
 
        {
446
 
          // Do nothing
447
 
        }
448
 
 
449
 
        m_wallet->writeMap( authInfo->unc().toUpper(), map );
450
 
        break;
451
 
      }
452
 
    }
453
 
 
454
 
    m_wallet->sync();
 
827
      // Do nothing
 
828
    }
455
829
  }
456
830
  else
457
831
  {
458
 
    // Clear the list if necessary, i.e. if the wallet manager
459
 
    // should forget the previously used login(s).
460
 
    if ( !Smb4KSettings::rememberLogins() )
461
 
    {
462
 
      while ( !m_list.isEmpty() )
463
 
      {
464
 
        delete m_list.takeFirst();
465
 
      }
466
 
    }
467
 
    else
468
 
    {
469
 
      // Do nothing
470
 
    }
471
 
 
472
 
    // We do not store a default login if no wallet is used.
473
 
    if ( authInfo->type() != Smb4KAuthInfo::Default )
474
 
    {
475
 
      m_list.append( new Smb4KAuthInfo( *authInfo ) );
476
 
    }
477
 
    else
478
 
    {
479
 
      // Do nothing
480
 
    }
 
832
    // Do nothing
481
833
  }
482
 
 
483
 
#ifdef __FreeBSD__
484
 
  writeToConfigFile( authInfo );
485
 
#endif
486
834
}
487
835
 
488
836
 
489
 
bool Smb4KWalletManager::showPasswordDialog( Smb4KAuthInfo *authInfo, QWidget *parent )
 
837
bool Smb4KWalletManager::showPasswordDialog( Smb4KBasicNetworkItem *networkItem, QWidget *parent )
490
838
{
491
 
  Q_ASSERT( authInfo );
492
 
 
 
839
  Q_ASSERT( networkItem );
 
840
 
 
841
  // Initialize the wallet manager. In case the wallet is already
 
842
  // set up, init() will do nothing.
 
843
  init();
 
844
 
 
845
  // Return value
493
846
  bool success = false;
494
847
 
495
 
  // Read the authentication information.
496
 
  readAuthInfo( authInfo );
497
 
 
498
 
  // Get known logins in case we have a 'homes' share and the share
499
 
  // name has not yet been changed.
500
 
  QMap<QString, QString> logins;
501
 
 
502
 
  if ( authInfo->isHomesShare() && QString::compare( authInfo->shareName(), "homes" ) == 0 )
503
 
  {
504
 
    if ( authInfo->homesUsers().isEmpty() )
505
 
    {
506
 
      // Normally, authInfo should already carry the homes users,
507
 
      // but we will check once more.
508
 
      Smb4KHomesSharesHandler::self()->setHomesUsers( authInfo );
509
 
    }
510
 
    else
511
 
    {
512
 
      // Do nothing
513
 
    }
514
 
 
515
 
    for ( int i = 0; i < authInfo->homesUsers().size(); ++i )
516
 
    {
517
 
      Smb4KAuthInfo user_auth_info( *authInfo );
518
 
      user_auth_info.setHomesUser( authInfo->homesUsers().at( i ) );
519
 
 
520
 
      // Read the authentication data for the share. If it does not
521
 
      // exist yet, user() and password() will be empty.
522
 
      readAuthInfo( &user_auth_info );
523
 
 
524
 
      if ( user_auth_info.login().isEmpty() )
525
 
      {
526
 
        logins.insert( authInfo->homesUsers().at( i ), QString() );
527
 
      }
528
 
      else
529
 
      {
530
 
        logins.insert( QString::fromLocal8Bit( user_auth_info.login() ),
531
 
                       QString::fromLocal8Bit( user_auth_info.password() ) );
532
 
      }
533
 
    }
534
 
  }
535
 
  else
536
 
  {
537
 
    // Do nothing
538
 
  }
 
848
  // Read authentication information
 
849
  readAuthInfo( networkItem );
539
850
 
540
851
  // Set up the password dialog.
541
852
  KPasswordDialog dlg( parent, KPasswordDialog::ShowUsernameLine );
542
853
 
543
 
  if ( !logins.isEmpty() )
544
 
  {
545
 
    dlg.setKnownLogins( logins );
546
 
  }
547
 
  else
548
 
  {
549
 
 
550
 
    dlg.setUsername( authInfo->login() );
551
 
    dlg.setPassword( authInfo->password() );
552
 
  }
553
 
 
554
 
  QString prompt;
555
 
 
556
 
  switch ( authInfo->type() )
557
 
  {
558
 
    case Smb4KAuthInfo::Host:
 
854
  switch ( networkItem->type() )
 
855
  {
 
856
    case Smb4KBasicNetworkItem::Host:
559
857
    {
560
 
      prompt = i18n( "<qt>Please enter a user name and a password for the host %1.</qt>" ).arg( authInfo->hostName() );
 
858
      Smb4KHost *host = static_cast<Smb4KHost *>( networkItem );
 
859
 
 
860
      if ( host )
 
861
      {
 
862
        dlg.setUsername( host->login() );
 
863
        dlg.setPassword( host->password() );
 
864
        dlg.setPrompt( i18n( "<qt>Please enter a username and a password for the host <b>%1</b>.</qt>", host->hostName() ) );
 
865
 
 
866
        // Execute the password dialog, retrieve the new authentication
 
867
        // information and save it.
 
868
        if ( (success = dlg.exec()) )
 
869
        {
 
870
          host->setLogin( dlg.username() );
 
871
          host->setPassword( dlg.password() );
 
872
          writeAuthInfo( host );
 
873
        }
 
874
        else
 
875
        {
 
876
          // Do nothing
 
877
        }
 
878
      }
 
879
      else
 
880
      {
 
881
        // Do nothing
 
882
      }
561
883
      break;
562
884
    }
563
 
    case Smb4KAuthInfo::Share:
 
885
    case Smb4KBasicNetworkItem::Share:
564
886
    {
565
 
      prompt = i18n( "<qt>Please enter a user name and a password for the share %1.</qt>" ).arg( authInfo->unc() );
 
887
      Smb4KShare *share = static_cast<Smb4KShare *>( networkItem );
 
888
 
 
889
      if ( share )
 
890
      {
 
891
        // Get known logins in case we have a 'homes' share and the share
 
892
        // name has not yet been changed.
 
893
        QMap<QString,QString> logins;
 
894
        QStringList users = Smb4KHomesSharesHandler::self()->homesUsers( share );
 
895
 
 
896
        for ( int i = 0; i < users.size(); ++i )
 
897
        {
 
898
          Smb4KShare tmp_share( *share );
 
899
          tmp_share.setLogin( users.at( i ) );
 
900
 
 
901
          // Read the authentication data for the share. If it does not
 
902
          // exist yet, login() and password() will be empty.
 
903
          readAuthInfo( &tmp_share );
 
904
          logins.insert( tmp_share.login(), tmp_share.password() );
 
905
        }
 
906
 
 
907
        // Enter authentication information into the dialog
 
908
        if ( !logins.isEmpty() )
 
909
        {
 
910
          dlg.setKnownLogins( logins );
 
911
        }
 
912
        else
 
913
        {
 
914
          dlg.setUsername( share->login() );
 
915
          dlg.setPassword( share->password() );
 
916
        }
 
917
 
 
918
        dlg.setPrompt( i18n( "<qt>Please enter a username and a password for the share <b>%1</b>.</qt>", share->unc() ) );
 
919
 
 
920
        // Execute the password dialog, retrieve the new authentication
 
921
        // information and save it.
 
922
        if ( (success = dlg.exec()) )
 
923
        {
 
924
          share->setLogin( dlg.username() );
 
925
          share->setPassword( dlg.password() );
 
926
          writeAuthInfo( share );
 
927
        }
 
928
        else
 
929
        {
 
930
          // Do nothing
 
931
        }
 
932
      }
 
933
      else
 
934
      {
 
935
        // Do nothing
 
936
      }
566
937
      break;
567
938
    }
568
939
    default:
569
940
    {
570
 
      prompt = i18n( "<qt>Please enter a user name and a password below.</qt>" );
571
941
      break;
572
942
    }
573
943
  }
574
944
 
575
 
  dlg.setPrompt( prompt );
576
 
 
577
 
  // Execute the password dialog, retrieve the new authentication
578
 
  // information and save it.
579
 
  if ( (success = dlg.exec()) )
580
 
  {
581
 
    authInfo->setLogin( dlg.username() );
582
 
    authInfo->setPassword( dlg.password() );
583
 
 
584
 
    writeAuthInfo( authInfo );
585
 
  }
586
 
  else
587
 
  {
588
 
    // Do nothing
589
 
  }
590
 
 
591
945
  return success;
592
946
}
593
947
 
598
952
}
599
953
 
600
954
 
601
 
#ifdef __FreeBSD__
 
955
QList<Smb4KAuthInfo *> Smb4KWalletManager::walletEntries()
 
956
{
 
957
  // Initialize the wallet manager. In case the wallet is already
 
958
  // set up, init() will just do nothing.
 
959
  init();
 
960
 
 
961
  QList<Smb4KAuthInfo *> list;
 
962
 
 
963
  if ( useWalletSystem() && m_wallet )
 
964
  {
 
965
    QStringList entries = m_wallet->entryList();
 
966
 
 
967
    if ( !entries.isEmpty() )
 
968
    {
 
969
      for ( int i = 0; i < entries.size(); ++i )
 
970
      {
 
971
        Smb4KAuthInfo *authInfo = new Smb4KAuthInfo();
 
972
 
 
973
        QMap<QString,QString> map;
 
974
        m_wallet->readMap( entries.at( i ), map );
 
975
 
 
976
        if ( QString::compare( entries.at( i ), "DEFAULT_LOGIN" ) == 0 )
 
977
        {
 
978
          // Default login
 
979
          authInfo->useDefaultAuthInfo();
 
980
          authInfo->setLogin( map["Login"] );
 
981
          authInfo->setPassword( map["Password"] );
 
982
        }
 
983
        else
 
984
        {
 
985
          authInfo->setURL( QUrl( entries.at( i ) ) );
 
986
          authInfo->setIP( map["IP Address"] );
 
987
          authInfo->setWorkgroupName( map["Workgroup"] );
 
988
          authInfo->setLogin( map["Login"] );
 
989
          authInfo->setPassword( map["Password"] );
 
990
        }
 
991
 
 
992
        list << authInfo;
 
993
      }
 
994
    }
 
995
    else
 
996
    {
 
997
      // Do nothing
 
998
    }
 
999
  }
 
1000
  else
 
1001
  {
 
1002
    // Do nothing
 
1003
  }
 
1004
 
 
1005
  return list;
 
1006
}
 
1007
 
 
1008
 
 
1009
void Smb4KWalletManager::writeWalletEntries( const QList<Smb4KAuthInfo *> &entries )
 
1010
{
 
1011
  // Initialize the wallet manager. In case the wallet is already
 
1012
  // set up, init() will just do nothing.
 
1013
  init();
 
1014
 
 
1015
  if ( useWalletSystem() && m_wallet )
 
1016
  {
 
1017
    // Clear the wallet.
 
1018
    QStringList entry_list = m_wallet->entryList();
 
1019
 
 
1020
    for ( int i = 0; i < entry_list.size(); ++i )
 
1021
    {
 
1022
      m_wallet->removeEntry( entry_list.at( i ) );
 
1023
    }
 
1024
 
 
1025
    // Write the new entries to the wallet.
 
1026
    for ( int i = 0; i < entries.size(); ++i )
 
1027
    {
 
1028
      QMap<QString,QString> map;
 
1029
 
 
1030
      if ( entries.at( i )->type() == Smb4KAuthInfo::Default )
 
1031
      {
 
1032
        // Default login
 
1033
        map["Login"] = entries.at( i )->login();
 
1034
        map["Password"] = entries.at( i )->password();
 
1035
        m_wallet->writeMap( "DEFAULT_LOGIN", map );
 
1036
      }
 
1037
      else
 
1038
      {
 
1039
        map["IP Address"] = entries.at( i )->ip();
 
1040
        map["Workgroup"] = entries.at( i )->workgroupName();
 
1041
        map["Login"] = entries.at( i )->login();
 
1042
        map["Password"] = entries.at( i )->password();
 
1043
        m_wallet->writeMap( entries.at( i )->unc(), map );
 
1044
      }
 
1045
    }
 
1046
 
 
1047
    m_wallet->sync();
 
1048
  }
 
1049
  else
 
1050
  {
 
1051
    // Do nothing
 
1052
  }
 
1053
}
 
1054
 
 
1055
 
 
1056
#ifdef Q_OS_FREEBSD
602
1057
 
603
1058
void Smb4KWalletManager::writeToConfigFile( Smb4KAuthInfo *authInfo )
604
1059
{
614
1069
    // Do nothing
615
1070
  }
616
1071
 
 
1072
  // Find smbutil program
 
1073
  QString smbutil = KStandardDirs::findExe( "smbutil" );
 
1074
 
 
1075
  if ( smbutil.isEmpty() )
 
1076
  {
 
1077
    Smb4KNotification *notification = new Smb4KNotification();
 
1078
    notification->commandNotFound( "smbutil" );
 
1079
    return;
 
1080
  }
 
1081
  else
 
1082
  {
 
1083
    // Go ahead
 
1084
  }
 
1085
 
617
1086
  QStringList contents;
618
1087
 
619
1088
  // Open the config file.
637
1106
    }
638
1107
    else
639
1108
    {
640
 
      Smb4KCoreMessage::error( ERROR_OPENING_FILE, file.fileName(), file.errorString() );
 
1109
      Smb4KNotification *notification = new Smb4KNotification();
 
1110
      notification->openingFileFailed( file );
641
1111
      return;
642
1112
    }
643
1113
  }
653
1123
  if ( !contents.contains( "[default]", Qt::CaseInsensitive ) )
654
1124
  {
655
1125
    // Get the global Samba options.
656
 
    QMap<QString,QString> global_options = Smb4KSambaOptionsHandler::self()->globalSambaOptions();
 
1126
    QMap<QString,QString> global_options = globalSambaOptions();
657
1127
 
658
1128
    // Set up the default section.
659
1129
    QStringList default_section;
702
1172
    }
703
1173
 
704
1174
    // WINS server
705
 
    QString wins_server = Smb4KSambaOptionsHandler::self()->winsServer();
 
1175
    QString wins_server = winsServer();
706
1176
 
707
1177
    if ( !wins_server.isEmpty() )
708
1178
    {
752
1222
  QString password;
753
1223
 
754
1224
  KProcess proc;
755
 
  proc.setShellCommand( Smb4KSettings::smbutil()+" crypt "+authInfo->password() );
 
1225
  proc.setShellCommand( smbutil+" crypt "+authInfo->password() );
756
1226
  proc.setOutputChannelMode( KProcess::SeparateChannels );
757
1227
 
758
1228
  switch ( proc.execute() )
760
1230
    case -2:
761
1231
    case -1:
762
1232
    {
763
 
      Smb4KCoreMessage::processError( ERROR_PROCESS_ERROR, proc.error() );
764
 
      break;
 
1233
      Smb4KNotification *notification = new Smb4KNotification();
 
1234
      notification->processError( proc.error() );
 
1235
      return;
765
1236
    }
766
1237
    default:
767
1238
    {
768
 
      password = QString::fromLocal8Bit( proc.readAllStandardOutput(), -1 ).trimmed();
 
1239
      password = QString::fromUtf8( proc.readAllStandardOutput(), -1 ).trimmed();
769
1240
      break;
770
1241
    }
771
1242
  }
1031
1502
    }
1032
1503
    else
1033
1504
    {
1034
 
      Smb4KCoreMessage::error( ERROR_OPENING_FILE, file.fileName(), file.errorString() );
 
1505
      Smb4KNotification *notification = new Smb4KNotification();
 
1506
      notification->openingFileFailed( file );
1035
1507
      return;
1036
1508
    }
1037
1509
  }
1044
1516
#endif
1045
1517
 
1046
1518
 
1047
 
/////////////////////////////////////////////////////////////////////////////
1048
 
//  SLOT IMPLEMENTATIONS
1049
 
/////////////////////////////////////////////////////////////////////////////
1050
 
 
1051
 
void Smb4KWalletManager::slotWalletOpened( bool success )
1052
 
{
1053
 
  if ( success )
1054
 
  {
1055
 
    setupFolder();
1056
 
    m_state = UseWallet;
1057
 
  }
1058
 
  else
1059
 
  {
1060
 
    kDebug() << "Opening the wallet failed ..." << endl;
1061
 
    m_state = Unknown;
1062
 
  }
1063
 
 
1064
 
  emit initialized();
1065
 
}
1066
 
 
1067
 
 
1068
1519
#include "smb4kwalletmanager.moc"