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

« back to all changes in this revision

Viewing changes to core/smb4ksambaoptionshandler.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:
1
 
/***************************************************************************
2
 
    smb4ksambaoptionshandler  -  This class handles the Samba options.
3
 
                             -------------------
4
 
    begin                : So Mai 14 2006
5
 
    copyright            : (C) 2006-2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *   This program is free software; you can redistribute it and/or modify  *
11
 
 *   it under the terms of the GNU General Public License as published by  *
12
 
 *   the Free Software Foundation; either version 2 of the License, or     *
13
 
 *   (at your option) any later version.                                   *
14
 
 *                                                                         *
15
 
 *   This program is distributed in the hope that it will be useful, but   *
16
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
17
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
18
 
 *   General Public License for more details.                              *
19
 
 *                                                                         *
20
 
 *   You should have received a copy of the GNU General Public License     *
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                                                    *
24
 
 ***************************************************************************/
25
 
 
26
 
// Qt includes
27
 
#include <QFile>
28
 
#include <QTextStream>
29
 
#include <QDir>
30
 
#include <QTextCodec>
31
 
#include <QXmlStreamReader>
32
 
#include <QXmlStreamWriter>
33
 
 
34
 
// KDE includes
35
 
#include <kstandarddirs.h>
36
 
#include <kprocess.h>
37
 
#include <kdebug.h>
38
 
#include <klocale.h>
39
 
#include <kshell.h>
40
 
#include <kglobal.h>
41
 
 
42
 
// system specific includes
43
 
#include <unistd.h>
44
 
#include <sys/types.h>
45
 
#include <errno.h>
46
 
 
47
 
// application specific includes
48
 
#include <smb4ksambaoptionshandler.h>
49
 
#include <smb4kdefs.h>
50
 
#include <smb4kcoremessage.h>
51
 
#include <smb4kglobal.h>
52
 
#include <smb4ksambaoptionsinfo.h>
53
 
#include <smb4kshare.h>
54
 
#include <smb4ksettings.h>
55
 
#include <smb4kworkgroup.h>
56
 
#include <smb4khost.h>
57
 
 
58
 
using namespace Smb4KGlobal;
59
 
 
60
 
class Smb4KSambaOptionsHandlerPrivate
61
 
{
62
 
  public:
63
 
    /**
64
 
     * The Smb4KSambaOptionsHandler instance
65
 
     */
66
 
    Smb4KSambaOptionsHandler instance;
67
 
};
68
 
 
69
 
 
70
 
K_GLOBAL_STATIC( Smb4KSambaOptionsHandlerPrivate, m_priv );
71
 
 
72
 
 
73
 
Smb4KSambaOptionsHandler::Smb4KSambaOptionsHandler()
74
 
: QObject()
75
 
{
76
 
  // We need the directory.
77
 
  QString dir = KGlobal::dirs()->locateLocal( "data", "smb4k", KGlobal::mainComponent() );
78
 
 
79
 
  if ( !KGlobal::dirs()->exists( dir ) )
80
 
  {
81
 
    KGlobal::dirs()->makeDir( dir );
82
 
  }
83
 
 
84
 
  m_wins_server.clear();
85
 
 
86
 
  readCustomOptions();
87
 
}
88
 
 
89
 
 
90
 
Smb4KSambaOptionsHandler::~Smb4KSambaOptionsHandler()
91
 
{
92
 
  while ( !m_list.isEmpty() )
93
 
  {
94
 
    delete m_list.takeFirst();
95
 
  }
96
 
}
97
 
 
98
 
 
99
 
Smb4KSambaOptionsHandler *Smb4KSambaOptionsHandler::self()
100
 
{
101
 
  return &m_priv->instance;
102
 
}
103
 
 
104
 
 
105
 
QList<Smb4KSambaOptionsInfo *> Smb4KSambaOptionsHandler::sharesToRemount()
106
 
{
107
 
  QList<Smb4KSambaOptionsInfo *> remounts;
108
 
 
109
 
  for ( int i = 0; i < m_list.size(); ++i )
110
 
  {
111
 
    if ( m_list.at( i )->remount() == Smb4KSambaOptionsInfo::DoRemount )
112
 
    {
113
 
      remounts.append( m_list.at( i ) );
114
 
 
115
 
      continue;
116
 
    }
117
 
    else
118
 
    {
119
 
      continue;
120
 
    }
121
 
  }
122
 
 
123
 
  return remounts;
124
 
}
125
 
 
126
 
 
127
 
void Smb4KSambaOptionsHandler::readCustomOptions()
128
 
{
129
 
  // Check if an old custom_options file is present and load the options
130
 
  // from there. Remove the file afterwards.
131
 
  QFile file( KGlobal::dirs()->locateLocal( "data", "smb4k/custom_options", KGlobal::mainComponent() ) );
132
 
 
133
 
  if ( file.exists() )
134
 
  {
135
 
    QStringList contents;
136
 
 
137
 
    if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
138
 
    {
139
 
      QTextStream ts( &file );
140
 
      // Note: With Qt 4.3 this seems to be obsolete, we'll keep
141
 
      // it for now.
142
 
      ts.setCodec( QTextCodec::codecForLocale() );
143
 
 
144
 
      while ( !ts.atEnd() )
145
 
      {
146
 
        contents.append( ts.readLine( 0 ) );
147
 
      }
148
 
 
149
 
      file.close();
150
 
    }
151
 
    else
152
 
    {
153
 
      if ( file.exists() )
154
 
      {
155
 
        Smb4KCoreMessage::error( ERROR_OPENING_FILE, file.fileName() );
156
 
      }
157
 
 
158
 
      return;
159
 
    }
160
 
 
161
 
    if ( !contents.isEmpty() )
162
 
    {
163
 
      for ( int i = 0; i < contents.size(); ++i )
164
 
      {
165
 
        if ( contents.at( i ).startsWith( "[" ) )
166
 
        {
167
 
          Smb4KSambaOptionsInfo *info = new Smb4KSambaOptionsInfo();
168
 
          info->setUNC( contents.at( i ).section( "[", 1, -1 ).section( "]", -2, 0 ) );
169
 
 
170
 
          for ( int j = ++i; j < contents.size(); ++j )
171
 
          {
172
 
            if ( contents.at( j ).startsWith( "workgroup=" ) )
173
 
            {
174
 
              info->setWorkgroup( contents.at( j ).section( "=", 1, 1 ).trimmed() );
175
 
 
176
 
              continue;
177
 
            }
178
 
            else if ( contents.at( j ).startsWith( "ip=" ) )
179
 
            {
180
 
              info->setIP( contents.at( j ).section( "=", 1, 1 ).trimmed() );
181
 
 
182
 
              continue;
183
 
            }
184
 
            else if ( contents.at( j ).startsWith( "remount=" ) )
185
 
            {
186
 
              QString remount = contents.at( j ).section( "=", 1, 1 ).trimmed();
187
 
 
188
 
              if ( QString::compare( remount, "true", Qt::CaseInsensitive ) == 0 )
189
 
              {
190
 
                info->setRemount( Smb4KSambaOptionsInfo::DoRemount );
191
 
              }
192
 
              else if ( QString::compare( remount, "true", Qt::CaseInsensitive ) == 0 )
193
 
              {
194
 
                info->setRemount( Smb4KSambaOptionsInfo::NoRemount );
195
 
              }
196
 
              else
197
 
              {
198
 
                info->setRemount( Smb4KSambaOptionsInfo::UndefinedRemount );
199
 
              }
200
 
 
201
 
              continue;
202
 
            }
203
 
            else if ( contents.at( j ).startsWith( "port=" ) )
204
 
            {
205
 
              int port = contents.at( j ).section( "=", 1, 1 ).trimmed().toInt();
206
 
 
207
 
              info->setPort( port );
208
 
 
209
 
              continue;
210
 
            }
211
 
#ifndef __FreeBSD__
212
 
            else if ( contents.at( j ).startsWith( "write access=" ) )
213
 
            {
214
 
              QString write_access = contents.at( j ).section( "=", 1, 1 ).trimmed();
215
 
 
216
 
              if ( QString::compare( write_access, "true", Qt::CaseInsensitive ) == 0 )
217
 
              {
218
 
                info->setWriteAccess( Smb4KSambaOptionsInfo::ReadWrite );
219
 
              }
220
 
              else if ( QString::compare( write_access, "false", Qt::CaseInsensitive ) == 0 )
221
 
              {
222
 
                info->setWriteAccess( Smb4KSambaOptionsInfo::ReadOnly );
223
 
              }
224
 
              else
225
 
              {
226
 
                info->setWriteAccess( Smb4KSambaOptionsInfo::UndefinedWriteAccess );
227
 
              }
228
 
 
229
 
              continue;
230
 
            }
231
 
#endif
232
 
            else if ( contents.at( j ).startsWith( "protocol=" ) )
233
 
            {
234
 
              QString protocol = contents.at( j ).section( "=", 1, 1 ).trimmed();
235
 
 
236
 
              if ( QString::compare( protocol, "auto" ) == 0 )
237
 
              {
238
 
                info->setProtocol( Smb4KSambaOptionsInfo::Automatic );
239
 
              }
240
 
              else if ( QString::compare( protocol, "rpc" ) == 0 )
241
 
              {
242
 
                info->setProtocol( Smb4KSambaOptionsInfo::RPC );
243
 
              }
244
 
              else if ( QString::compare( protocol, "rap" ) == 0 )
245
 
              {
246
 
                info->setProtocol( Smb4KSambaOptionsInfo::RAP );
247
 
              }
248
 
              else if ( QString::compare( protocol, "ads" ) == 0 )
249
 
              {
250
 
                info->setProtocol( Smb4KSambaOptionsInfo::ADS );
251
 
              }
252
 
              else
253
 
              {
254
 
                info->setProtocol( Smb4KSambaOptionsInfo::UndefinedProtocol );
255
 
              }
256
 
 
257
 
              continue;
258
 
            }
259
 
            else if ( contents.at( j ).startsWith( "kerberos=" ) )
260
 
            {
261
 
              QString use_kerberos = contents.at( j ).section( "=", 1, 1 ).trimmed();
262
 
 
263
 
              if ( QString::compare( use_kerberos, "true", Qt::CaseInsensitive ) == 0 )
264
 
              {
265
 
                info->setUseKerberos( Smb4KSambaOptionsInfo::UseKerberos );
266
 
              }
267
 
              else if ( QString::compare( use_kerberos, "false", Qt::CaseInsensitive ) == 0 )
268
 
              {
269
 
                info->setUseKerberos( Smb4KSambaOptionsInfo::NoKerberos );
270
 
              }
271
 
              else
272
 
              {
273
 
                info->setUseKerberos( Smb4KSambaOptionsInfo::UndefinedKerberos );
274
 
              }
275
 
 
276
 
              continue;
277
 
            }
278
 
            else if ( contents.at( j ).startsWith( "uid=" ) )
279
 
            {
280
 
              info->setUID( (uid_t)contents.at( j ).section( "=", 1, 1 ).trimmed().toInt() );
281
 
 
282
 
              continue;
283
 
            }
284
 
            else if ( contents.at( j ).startsWith( "gid=" ) )
285
 
            {
286
 
              info->setGID( (gid_t)contents.at( j ).section( "=", 1, 1 ).trimmed().toInt() );
287
 
 
288
 
              continue;
289
 
            }
290
 
            else if ( contents.at( j ).isEmpty() || contents.at( j ).trimmed().startsWith( "[" ) )
291
 
            {
292
 
              i = j;
293
 
 
294
 
              break;
295
 
            }
296
 
            else
297
 
            {
298
 
              continue;
299
 
            }
300
 
          }
301
 
 
302
 
          has_custom_options( info );
303
 
 
304
 
          m_list.append( info );
305
 
        }
306
 
        else
307
 
        {
308
 
          continue;
309
 
        }
310
 
      }
311
 
    }
312
 
    else
313
 
    {
314
 
      // Do nothing
315
 
    }
316
 
 
317
 
    file.remove();
318
 
 
319
 
    writeCustomOptions();
320
 
 
321
 
    return;
322
 
  }
323
 
  else
324
 
  {
325
 
    // Do nothing
326
 
  }
327
 
 
328
 
  // Locate the XML file.
329
 
  QFile xmlFile( KGlobal::dirs()->locateLocal( "data", "smb4k/custom_options.xml", KGlobal::mainComponent() ) );
330
 
 
331
 
  if ( xmlFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
332
 
  {
333
 
    QXmlStreamReader xmlReader( &xmlFile );
334
 
 
335
 
    while ( !xmlReader.atEnd() )
336
 
    {
337
 
      xmlReader.readNext();
338
 
 
339
 
      if ( xmlReader.isStartElement() )
340
 
      {
341
 
        if ( xmlReader.name() == "custom_options" && xmlReader.attributes().value( "version" ) != "1.0" )
342
 
        {
343
 
          xmlReader.raiseError( i18n( "%1 is not a version 1.0 file." ).arg( xmlFile.fileName() ) );
344
 
 
345
 
          break;
346
 
        }
347
 
        else
348
 
        {
349
 
          if ( xmlReader.name() == "options" )
350
 
          {
351
 
            Smb4KSambaOptionsInfo *info = new Smb4KSambaOptionsInfo();
352
 
 
353
 
            info->setProfile( xmlReader.attributes().value( "profile" ).toString() );
354
 
 
355
 
            // The type attribute is not used at the moment.
356
 
 
357
 
            while ( !(xmlReader.isEndElement() && xmlReader.name() == "options") )
358
 
            {
359
 
              xmlReader.readNext();
360
 
 
361
 
              if ( xmlReader.isStartElement() )
362
 
              {
363
 
                if ( xmlReader.name() == "workgroup" )
364
 
                {
365
 
                  info->setWorkgroup( xmlReader.readElementText() );
366
 
                }
367
 
                else if ( xmlReader.name() == "unc" )
368
 
                {
369
 
                  info->setUNC( xmlReader.readElementText() );
370
 
                }
371
 
                else if ( xmlReader.name() == "ip" )
372
 
                {
373
 
                  info->setIP( xmlReader.readElementText() );
374
 
                }
375
 
                else if ( xmlReader.name() == "custom" )
376
 
                {
377
 
                  while ( !(xmlReader.isEndElement() && xmlReader.name() == "custom") )
378
 
                  {
379
 
                    xmlReader.readNext();
380
 
 
381
 
                    if ( xmlReader.isStartElement() )
382
 
                    {
383
 
                      if ( xmlReader.name() == "remount" )
384
 
                      {
385
 
                        QString remount = xmlReader.readElementText();
386
 
 
387
 
                        if ( QString::compare( remount, "true" ) == 0 )
388
 
                        {
389
 
                          info->setRemount( Smb4KSambaOptionsInfo::DoRemount );
390
 
                        }
391
 
                        else if ( QString::compare( remount, "false" ) == 0 )
392
 
                        {
393
 
                          info->setRemount( Smb4KSambaOptionsInfo::NoRemount );
394
 
                        }
395
 
                        else
396
 
                        {
397
 
                          info->setRemount( Smb4KSambaOptionsInfo::UndefinedRemount );
398
 
                        }
399
 
                      }
400
 
                      else if ( xmlReader.name() == "port" )
401
 
                      {
402
 
                        info->setPort( xmlReader.readElementText().toInt() );
403
 
                      }
404
 
                      else if ( xmlReader.name() == "protocol" )
405
 
                      {
406
 
                        QString protocol = xmlReader.readElementText();
407
 
 
408
 
                        if ( QString::compare( protocol, "auto" ) == 0 )
409
 
                        {
410
 
                          info->setProtocol( Smb4KSambaOptionsInfo::Automatic );
411
 
                        }
412
 
                        else if ( QString::compare( protocol, "rpc" ) == 0 )
413
 
                        {
414
 
                          info->setProtocol( Smb4KSambaOptionsInfo::RPC );
415
 
                        }
416
 
                        else if ( QString::compare( protocol, "rap" ) == 0 )
417
 
                        {
418
 
                          info->setProtocol( Smb4KSambaOptionsInfo::RAP );
419
 
                        }
420
 
                        else if ( QString::compare( protocol, "ads" ) == 0 )
421
 
                        {
422
 
                          info->setProtocol( Smb4KSambaOptionsInfo::ADS );
423
 
                        }
424
 
                        else
425
 
                        {
426
 
                          info->setProtocol( Smb4KSambaOptionsInfo::UndefinedProtocol );
427
 
                        }
428
 
                      }
429
 
#ifndef __FreeBSD__
430
 
                      else if ( xmlReader.name() == "write_access" )
431
 
                      {
432
 
                        QString write_access = xmlReader.readElementText();
433
 
 
434
 
                        if ( QString::compare( write_access, "true" ) == 0 )
435
 
                        {
436
 
                          info->setWriteAccess( Smb4KSambaOptionsInfo::ReadWrite );
437
 
                        }
438
 
                        else if ( QString::compare( write_access, "false" ) == 0 )
439
 
                        {
440
 
                          info->setWriteAccess( Smb4KSambaOptionsInfo::ReadOnly );
441
 
                        }
442
 
                        else
443
 
                        {
444
 
                          info->setWriteAccess( Smb4KSambaOptionsInfo::UndefinedWriteAccess );
445
 
                        }
446
 
                      }
447
 
#endif
448
 
                      else if ( xmlReader.name() == "kerberos" )
449
 
                      {
450
 
                        QString kerberos = xmlReader.readElementText();
451
 
 
452
 
                        if ( QString::compare( kerberos, "true" ) == 0 )
453
 
                        {
454
 
                          info->setUseKerberos( Smb4KSambaOptionsInfo::UseKerberos );
455
 
                        }
456
 
                        else if ( QString::compare( kerberos, "false" ) == 0 )
457
 
                        {
458
 
                          info->setUseKerberos( Smb4KSambaOptionsInfo::NoKerberos );
459
 
                        }
460
 
                        else
461
 
                        {
462
 
                          info->setUseKerberos( Smb4KSambaOptionsInfo::UndefinedKerberos );
463
 
                        }
464
 
                      }
465
 
                      else if ( xmlReader.name() == "uid" )
466
 
                      {
467
 
                        info->setUID( (uid_t)xmlReader.readElementText().toInt() );
468
 
                      }
469
 
                      else if ( xmlReader.name() == "gid" )
470
 
                      {
471
 
                        info->setGID( (gid_t)xmlReader.readElementText().toInt() );
472
 
                      }
473
 
                      else
474
 
                      {
475
 
                        // Do nothing
476
 
                      }
477
 
                    }
478
 
                    else
479
 
                    {
480
 
                      // Do nothing
481
 
                    }
482
 
                  }
483
 
                }
484
 
                else
485
 
                {
486
 
                  // Do nothing
487
 
                }
488
 
 
489
 
                continue;
490
 
              }
491
 
              else
492
 
              {
493
 
                continue;
494
 
              }
495
 
            }
496
 
 
497
 
            m_list.append( info );
498
 
          }
499
 
          else
500
 
          {
501
 
            continue;
502
 
          }
503
 
        }
504
 
      }
505
 
      else
506
 
      {
507
 
        continue;
508
 
      }
509
 
    }
510
 
 
511
 
    xmlFile.close();
512
 
 
513
 
    if ( xmlReader.hasError() )
514
 
    {
515
 
      Smb4KCoreMessage::error( ERROR_XML_ERROR, xmlFile.fileName(), xmlReader.errorString() );
516
 
    }
517
 
    else
518
 
    {
519
 
      // Do nothing
520
 
    }
521
 
  }
522
 
  else
523
 
  {
524
 
    if ( xmlFile.exists() )
525
 
    {
526
 
      Smb4KCoreMessage::error( ERROR_OPENING_FILE, xmlFile.fileName() );
527
 
    }
528
 
    else
529
 
    {
530
 
      // Do nothing
531
 
    }
532
 
 
533
 
    return;
534
 
  }
535
 
}
536
 
 
537
 
 
538
 
void Smb4KSambaOptionsHandler::writeCustomOptions()
539
 
{
540
 
  QFile xmlFile( KGlobal::dirs()->locateLocal( "data", "smb4k/custom_options.xml", KGlobal::mainComponent() ) );
541
 
 
542
 
  if ( !m_list.isEmpty() )
543
 
  {
544
 
    if ( xmlFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
545
 
    {
546
 
      QXmlStreamWriter xmlWriter( &xmlFile );
547
 
#if QT_VERSION >= 0x040400
548
 
      xmlWriter.setAutoFormatting( true );
549
 
#endif
550
 
 
551
 
      xmlWriter.writeStartDocument();
552
 
      xmlWriter.writeStartElement( "custom_options" );
553
 
      xmlWriter.writeAttribute( "version", "1.0" );
554
 
 
555
 
      for ( int i = 0; i < m_list.size(); ++i )
556
 
      {
557
 
        has_custom_options( m_list[i] );
558
 
 
559
 
        if ( m_list.at( i )->hasCustomOptions() ||
560
 
             m_list.at( i )->remount() == Smb4KSambaOptionsInfo::DoRemount )
561
 
        {
562
 
          xmlWriter.writeStartElement( "options" );
563
 
          xmlWriter.writeAttribute( "type", m_list.at( i )->type() == Smb4KSambaOptionsInfo::Host ? "Host" : "Share" );
564
 
          xmlWriter.writeAttribute( "profile", m_list.at( i )->profile() );
565
 
 
566
 
          xmlWriter.writeTextElement( "workgroup", m_list.at( i )->workgroup() );
567
 
          xmlWriter.writeTextElement( "unc", m_list.at( i )->unc() );
568
 
          xmlWriter.writeTextElement( "ip", m_list.at( i )->ip() );
569
 
 
570
 
          xmlWriter.writeStartElement( "custom" );
571
 
 
572
 
          QMap<QString,QString> map = m_list.at( i )->entries();
573
 
          QMapIterator<QString,QString> it( map );
574
 
 
575
 
          while ( it.hasNext() )
576
 
          {
577
 
            it.next();
578
 
 
579
 
            if ( !it.value().isEmpty() )
580
 
            {
581
 
              xmlWriter.writeTextElement( it.key(), it.value() );
582
 
            }
583
 
            else
584
 
            {
585
 
              // Do nothing
586
 
            }
587
 
          }
588
 
 
589
 
          xmlWriter.writeEndElement();
590
 
          xmlWriter.writeEndElement();
591
 
        }
592
 
        else
593
 
        {
594
 
          continue;
595
 
        }
596
 
      }
597
 
 
598
 
      xmlWriter.writeEndDocument();
599
 
 
600
 
      xmlFile.close();
601
 
    }
602
 
    else
603
 
    {
604
 
      Smb4KCoreMessage::error( ERROR_OPENING_FILE, xmlFile.fileName() );
605
 
      return;
606
 
    }
607
 
  }
608
 
  else
609
 
  {
610
 
    xmlFile.remove();
611
 
  }
612
 
}
613
 
 
614
 
 
615
 
void Smb4KSambaOptionsHandler::remount( Smb4KShare *share, bool yes )
616
 
{
617
 
  if ( share )
618
 
  {
619
 
    Smb4KSambaOptionsInfo *info = NULL;
620
 
 
621
 
    if ( (info = find_item( share->unc() )) )
622
 
    {
623
 
      info->setRemount( yes ?
624
 
                        Smb4KSambaOptionsInfo::DoRemount :
625
 
                        Smb4KSambaOptionsInfo::NoRemount );
626
 
    }
627
 
    else if ( !info && yes )
628
 
    {
629
 
      info = new Smb4KSambaOptionsInfo( share );
630
 
      info->setRemount( yes ?
631
 
                        Smb4KSambaOptionsInfo::DoRemount :
632
 
                        Smb4KSambaOptionsInfo::NoRemount );
633
 
 
634
 
      m_list.append( info );
635
 
    }
636
 
  }
637
 
}
638
 
 
639
 
 
640
 
void Smb4KSambaOptionsHandler::sync()
641
 
{
642
 
  writeCustomOptions();
643
 
}
644
 
 
645
 
 
646
 
Smb4KSambaOptionsInfo *Smb4KSambaOptionsHandler::find_item( const QString &item, bool exactMatch )
647
 
{
648
 
  QString host = item.section( "/", 2, 2 ).trimmed();
649
 
 
650
 
  Smb4KSambaOptionsInfo *info = NULL;
651
 
 
652
 
  if ( !item.trimmed().isEmpty() )
653
 
  {
654
 
    for ( int i = 0; i < m_list.size(); ++i )
655
 
    {
656
 
      if ( QString::compare( item.toUpper(), m_list.at( i )->unc().toUpper() ) == 0 )
657
 
      {
658
 
        info = m_list.at( i );
659
 
 
660
 
        break;
661
 
      }
662
 
      else if ( QString::compare( host.toUpper(), m_list.at( i )->unc().toUpper() ) == 0 )
663
 
      {
664
 
        if ( !info && !exactMatch )
665
 
        {
666
 
          info = m_list.at( i );
667
 
        }
668
 
 
669
 
        continue;
670
 
      }
671
 
      else
672
 
      {
673
 
        continue;
674
 
      }
675
 
    }
676
 
  }
677
 
 
678
 
  return info;
679
 
}
680
 
 
681
 
 
682
 
const QString Smb4KSambaOptionsHandler::smbclientOptions( const Smb4KShare &share )
683
 
{
684
 
  // FIXME: Make globalOptions() return a string.
685
 
 
686
 
  // Get the global Samba options
687
 
  (void) globalSambaOptions();
688
 
 
689
 
  Smb4KSambaOptionsInfo *info = NULL;
690
 
 
691
 
  if ( !share.isEmpty() )
692
 
  {
693
 
    info = find_item( share.name() );
694
 
  }
695
 
 
696
 
  QString args;
697
 
 
698
 
  // Get the strings that are needed to put the
699
 
  // argument list together:
700
 
  QString resolve_order =  (!Smb4KSettings::nameResolveOrder().isEmpty() &&
701
 
                           QString::compare( Smb4KSettings::nameResolveOrder(),
702
 
                           m_samba_options["name resolve order"] ) != 0) ?
703
 
                           Smb4KSettings::nameResolveOrder() :
704
 
                           QString();
705
 
 
706
 
  QString netbios_name =   (!Smb4KSettings::netBIOSName().isEmpty() &&
707
 
                           QString::compare( Smb4KSettings::netBIOSName(),
708
 
                           m_samba_options["netbios name"] ) != 0) ?
709
 
                           Smb4KSettings::netBIOSName() :
710
 
                           QString();
711
 
 
712
 
  QString netbios_scope =  (!Smb4KSettings::netBIOSScope().isEmpty() &&
713
 
                           QString::compare( Smb4KSettings::netBIOSScope(),
714
 
                           m_samba_options["netbios scope"] ) != 0) ?
715
 
                           Smb4KSettings::netBIOSScope() :
716
 
                           QString();
717
 
 
718
 
  QString socket_options = (!Smb4KSettings::socketOptions().isEmpty() &&
719
 
                           QString::compare( Smb4KSettings::socketOptions(),
720
 
                           m_samba_options["socket options"] ) != 0) ?
721
 
                           Smb4KSettings::socketOptions() :
722
 
                           QString();
723
 
 
724
 
  bool kerberos = false;
725
 
 
726
 
  if ( info )
727
 
  {
728
 
    switch ( info->useKerberos() )
729
 
    {
730
 
      case Smb4KSambaOptionsInfo::UseKerberos:
731
 
      {
732
 
        kerberos = true;
733
 
 
734
 
        break;
735
 
      }
736
 
      case Smb4KSambaOptionsInfo::NoKerberos:
737
 
      {
738
 
        kerberos = false;
739
 
 
740
 
        break;
741
 
      }
742
 
      case Smb4KSambaOptionsInfo::UndefinedKerberos:
743
 
      {
744
 
        kerberos = Smb4KSettings::useKerberos();
745
 
 
746
 
        break;
747
 
      }
748
 
      default:
749
 
      {
750
 
        break;
751
 
      }
752
 
    }
753
 
  }
754
 
  else
755
 
  {
756
 
    kerberos = Smb4KSettings::useKerberos();
757
 
  }
758
 
 
759
 
  int port =               info && info->port() != -1 ?
760
 
                           info->port() :
761
 
                           Smb4KSettings::remoteSMBPort();
762
 
 
763
 
  // Options that are not customizable:
764
 
  args.append( !resolve_order.isEmpty() ?
765
 
               QString( " -R '%1'" ).arg( resolve_order ) :
766
 
               QString() );
767
 
 
768
 
  args.append( !netbios_name.isEmpty() ?
769
 
               QString( " -n '%1'" ).arg( netbios_name ) :
770
 
               QString() );
771
 
 
772
 
  args.append( !netbios_scope.isEmpty() ?
773
 
               QString( " -i '%1'" ).arg( netbios_scope ) :
774
 
               QString() );
775
 
 
776
 
  args.append( !socket_options.isEmpty() ?
777
 
               QString( " -O '%1'" ).arg( socket_options ) :
778
 
               QString() );
779
 
 
780
 
  args.append( Smb4KSettings::bufferSize() != 65520 ?
781
 
               QString( " -b %1" ).arg( Smb4KSettings::bufferSize() ) :
782
 
               QString() );
783
 
 
784
 
  args.append( (Smb4KSettings::machineAccount() ?
785
 
               " -P" :
786
 
               QString()) );
787
 
 
788
 
  switch ( Smb4KSettings::signingState() )
789
 
  {
790
 
    case Smb4KSettings::EnumSigningState::None:
791
 
    {
792
 
      // The user does not want this setting
793
 
      // to be used.
794
 
      break;
795
 
    }
796
 
    case Smb4KSettings::EnumSigningState::On:
797
 
    {
798
 
      args.append( " -S on" );
799
 
 
800
 
      break;
801
 
    }
802
 
    case Smb4KSettings::EnumSigningState::Off:
803
 
    {
804
 
      args.append( " -S off" );
805
 
 
806
 
      break;
807
 
    }
808
 
    case Smb4KSettings::EnumSigningState::Required:
809
 
    {
810
 
      args.append( " -S required" );
811
 
 
812
 
      break;
813
 
    }
814
 
    default:
815
 
    {
816
 
      break;
817
 
    }
818
 
  }
819
 
 
820
 
  args.append( (kerberos ?
821
 
               " -k" :
822
 
               QString()) );
823
 
 
824
 
  args.append( QString( " -p %1" ).arg( port ) );
825
 
 
826
 
  return args;
827
 
}
828
 
 
829
 
 
830
 
const QString Smb4KSambaOptionsHandler::nmblookupOptions( bool with_broadcast )
831
 
{
832
 
  // Get the global Samba options
833
 
  (void) globalSambaOptions();
834
 
 
835
 
  QString args;
836
 
 
837
 
  QString netbios_name =   (!Smb4KSettings::netBIOSName().isEmpty() &&
838
 
                           QString::compare( Smb4KSettings::netBIOSName(),
839
 
                           m_samba_options["netbios name"] ) != 0) ?
840
 
                           Smb4KSettings::netBIOSName() :
841
 
                           QString();
842
 
 
843
 
  QString netbios_scope =  (!Smb4KSettings::netBIOSScope().isEmpty() &&
844
 
                           QString::compare( Smb4KSettings::netBIOSScope(),
845
 
                           m_samba_options["netbios scope"] ) != 0) ?
846
 
                           Smb4KSettings::netBIOSScope() :
847
 
                           QString();
848
 
 
849
 
  QString socket_options = (!Smb4KSettings::socketOptions().isEmpty() &&
850
 
                           QString::compare( Smb4KSettings::socketOptions(),
851
 
                           m_samba_options["socket options"] ) != 0) ?
852
 
                           Smb4KSettings::socketOptions() :
853
 
                           QString();
854
 
 
855
 
  QString domain =         (!Smb4KSettings::domainName().isEmpty() &&
856
 
                           QString::compare( Smb4KSettings::domainName(),
857
 
                           m_samba_options["workgroup"] ) != 0) ?
858
 
                           Smb4KSettings::domainName() :
859
 
                           QString();
860
 
 
861
 
  args.append( !netbios_name.isEmpty() ?
862
 
               QString( " -n '%1'" ).arg( netbios_name ) :
863
 
               QString() );
864
 
 
865
 
  args.append( !netbios_scope.isEmpty() ?
866
 
               QString( " -i '%1'" ).arg( netbios_scope ) :
867
 
               QString() );
868
 
 
869
 
  args.append( !socket_options.isEmpty() ?
870
 
               QString( " -O '%1'" ).arg( socket_options ) :
871
 
               QString() );
872
 
 
873
 
  args.append( !domain.isEmpty() ?
874
 
               QString( " -W '%1'" ).arg( domain ) :
875
 
               QString() );
876
 
 
877
 
  args.append( (!Smb4KSettings::broadcastAddress().isEmpty() &&
878
 
               with_broadcast) ?
879
 
               QString( " -B %1" ).arg( Smb4KSettings::broadcastAddress() ) :
880
 
               QString() );
881
 
 
882
 
  args.append( Smb4KSettings::usePort137() ?
883
 
               " -r" :
884
 
               QString() );
885
 
 
886
 
  return args;
887
 
}
888
 
 
889
 
 
890
 
const QString Smb4KSambaOptionsHandler::netOptions( NetCommand command, const Smb4KHost &host )
891
 
{
892
 
  // Find the host in the list.
893
 
  Smb4KSambaOptionsInfo *info = find_item( host.name() );
894
 
 
895
 
  // Determine the protocol that should be used.
896
 
  QString protocol_hint;
897
 
 
898
 
  if ( host.protocol() != Smb4KHost::Automatic )
899
 
  {
900
 
    // The protocol entry of the Smb4KHostItem overwrites
901
 
    // the default protocol hint.
902
 
    switch ( host.protocol() )
903
 
    {
904
 
      case Smb4KHost::RPC:
905
 
      {
906
 
        protocol_hint = "rpc";
907
 
 
908
 
        break;
909
 
      }
910
 
      case Smb4KHost::RAP:
911
 
      {
912
 
        protocol_hint = "rap";
913
 
 
914
 
        break;
915
 
      }
916
 
      case Smb4KHost::ADS:
917
 
      {
918
 
        protocol_hint = "ads";
919
 
 
920
 
        break;
921
 
      }
922
 
      default:
923
 
      {
924
 
        break;
925
 
      }
926
 
    }
927
 
  }
928
 
  else
929
 
  {
930
 
    switch ( Smb4KSettings::protocolHint() )
931
 
    {
932
 
      case Smb4KSettings::EnumProtocolHint::RPC:
933
 
      {
934
 
        protocol_hint = "rpc";
935
 
 
936
 
        break;
937
 
      }
938
 
      case Smb4KSettings::EnumProtocolHint::RAP:
939
 
      {
940
 
        protocol_hint = "rap";
941
 
 
942
 
        break;
943
 
      }
944
 
      case Smb4KSettings::EnumProtocolHint::ADS:
945
 
      {
946
 
        protocol_hint = "ads";
947
 
 
948
 
        break;
949
 
      }
950
 
      default:
951
 
      {
952
 
        break;
953
 
      }
954
 
    }
955
 
  }
956
 
 
957
 
  QString default_protocol;
958
 
 
959
 
  if ( info )
960
 
  {
961
 
    switch ( info->protocol() )
962
 
    {
963
 
      case Smb4KSambaOptionsInfo::RPC:
964
 
      {
965
 
        default_protocol = "rpc";
966
 
 
967
 
        break;
968
 
      }
969
 
      case Smb4KSambaOptionsInfo::RAP:
970
 
      {
971
 
        default_protocol = "rap";
972
 
 
973
 
        break;
974
 
      }
975
 
      case Smb4KSambaOptionsInfo::ADS:
976
 
      {
977
 
        default_protocol = "ads";
978
 
 
979
 
        break;
980
 
      }
981
 
      default:
982
 
      {
983
 
        default_protocol = protocol_hint;
984
 
      }
985
 
    }
986
 
  }
987
 
  else
988
 
  {
989
 
    default_protocol = protocol_hint;
990
 
  }
991
 
 
992
 
  QString netbios_name =     (!Smb4KSettings::netBIOSName().isEmpty() &&
993
 
                             QString::compare( Smb4KSettings::netBIOSName(),
994
 
                             m_samba_options["netbios name"] ) != 0) ?
995
 
                             Smb4KSettings::netBIOSName() :
996
 
                             QString();
997
 
 
998
 
  QString domain =           (!Smb4KSettings::domainName().isEmpty() &&
999
 
                             QString::compare( Smb4KSettings::domainName(),
1000
 
                             m_samba_options["workgroup"] ) != 0) ?
1001
 
                             Smb4KSettings::domainName() :
1002
 
                             QString();
1003
 
 
1004
 
  int port =                 (info && info->port() != -1) ?
1005
 
                             info->port() :
1006
 
                             Smb4KSettings::remoteSMBPort();
1007
 
 
1008
 
 
1009
 
  QString args;
1010
 
 
1011
 
  switch ( command )
1012
 
  {
1013
 
    case Share:
1014
 
    {
1015
 
      // We can only use "rpc" and "rap" protocol hints here. The others
1016
 
      // will be ignored.
1017
 
      // Note: The protocol entry of the Smb4KHost object will always
1018
 
      // overwrite the default protocol.
1019
 
      switch ( host.protocol() )
1020
 
      {
1021
 
        case Smb4KHost::RPC:
1022
 
        {
1023
 
          args.append( " "+protocol_hint+" share list -l" );
1024
 
          break;
1025
 
        }
1026
 
        case Smb4KHost::RAP:
1027
 
        {
1028
 
          // protocol_hint carries the correct protocol:
1029
 
          args.append( " "+protocol_hint+" share -l" );
1030
 
          break;
1031
 
        }
1032
 
        default:
1033
 
        {
1034
 
          if ( !default_protocol.isEmpty() )
1035
 
          {
1036
 
            if ( QString::compare( default_protocol, "rpc", Qt::CaseInsensitive ) == 0 )
1037
 
            {
1038
 
              args.append( " "+default_protocol+" share list -l" );
1039
 
            }
1040
 
            else if ( QString::compare( default_protocol, "rap", Qt::CaseInsensitive ) == 0 )
1041
 
            {
1042
 
              args.append( " "+default_protocol+" share -l" );
1043
 
            }
1044
 
            else
1045
 
            {
1046
 
              // Automatic detection
1047
 
              args.append( " share list -l" );
1048
 
            }
1049
 
          }
1050
 
          else
1051
 
          {
1052
 
            // Automatic detection
1053
 
            args.append( " share list -l" );
1054
 
          }
1055
 
          
1056
 
          break;
1057
 
        }
1058
 
      }
1059
 
 
1060
 
      break;
1061
 
    }
1062
 
    case LookupHost:
1063
 
    {
1064
 
      // Check that the server name is present:
1065
 
      if ( host.name().trimmed().isEmpty() )
1066
 
      {
1067
 
        Smb4KCoreMessage::error( ERROR_NET_COMMAND );
1068
 
 
1069
 
        return args; // still empty
1070
 
      }
1071
 
 
1072
 
      // This lookup command takes no protocol:
1073
 
      args.append( QString( " lookup host %1" ).arg( KShell::quoteArg( host.name() ) ) );
1074
 
 
1075
 
      break;
1076
 
    }
1077
 
    case LookupMaster:
1078
 
    {
1079
 
      // Check that the domain name is present:
1080
 
      if ( host.workgroup().trimmed().isEmpty() )
1081
 
      {
1082
 
        Smb4KCoreMessage::error( ERROR_NET_COMMAND );
1083
 
 
1084
 
        return args; // still empty
1085
 
      }
1086
 
 
1087
 
      // This lookup command takes no protocol:
1088
 
      args.append( QString( " lookup master %1" ).arg( KShell::quoteArg( host.workgroup() ) ) );
1089
 
 
1090
 
      break;
1091
 
    }
1092
 
    default:
1093
 
    {
1094
 
      // Bypass the rest and return an empty string.
1095
 
      return args;
1096
 
    }
1097
 
  }
1098
 
 
1099
 
  args.append( !domain.isEmpty() ?
1100
 
               QString( " -W %1" ).arg( KShell::quoteArg( domain  ) ) :
1101
 
               QString() );
1102
 
 
1103
 
  args.append( !netbios_name.isEmpty() ?
1104
 
               QString( " -n %1" ).arg( KShell::quoteArg( netbios_name ) ) :
1105
 
               QString() );
1106
 
 
1107
 
  args.append( Smb4KSettings::machineAccount() ?
1108
 
               " -P" :
1109
 
               QString() );
1110
 
 
1111
 
  args.append( QString( " -p %1" ).arg( port ) );
1112
 
 
1113
 
  return args;
1114
 
}
1115
 
 
1116
 
 
1117
 
const QString Smb4KSambaOptionsHandler::netOptions( NetCommand command, const Smb4KWorkgroup &workgroup )
1118
 
{
1119
 
  // Find the host in the list.
1120
 
  Smb4KSambaOptionsInfo *info = find_item( workgroup.masterBrowserName() );
1121
 
 
1122
 
  QString netbios_name =     (!Smb4KSettings::netBIOSName().isEmpty() &&
1123
 
                             QString::compare( Smb4KSettings::netBIOSName(),
1124
 
                             m_samba_options["netbios name"] ) != 0) ?
1125
 
                             Smb4KSettings::netBIOSName() :
1126
 
                             QString();
1127
 
 
1128
 
  QString domain =           (!Smb4KSettings::domainName().isEmpty() &&
1129
 
                             QString::compare( Smb4KSettings::domainName(),
1130
 
                             m_samba_options["workgroup"] ) != 0) ?
1131
 
                             Smb4KSettings::domainName() :
1132
 
                             QString();
1133
 
 
1134
 
  int port =                 (info && info->port() != -1) ?
1135
 
                             info->port() :
1136
 
                             Smb4KSettings::remoteSMBPort();
1137
 
 
1138
 
  QString args;
1139
 
 
1140
 
  switch ( command )
1141
 
  {
1142
 
    case LookupHost:
1143
 
    {
1144
 
      // Check that the server name is present:
1145
 
      if ( workgroup.masterBrowserName().trimmed().isEmpty() )
1146
 
      {
1147
 
        Smb4KCoreMessage::error( ERROR_NET_COMMAND );
1148
 
 
1149
 
        return args; // still empty
1150
 
      }
1151
 
 
1152
 
      // This lookup command takes no protocol:
1153
 
      args.append( QString( " lookup host %1" )
1154
 
          .arg( KShell::quoteArg( workgroup.masterBrowserName() ) ) );
1155
 
 
1156
 
      break;
1157
 
    }
1158
 
    case LookupMaster:
1159
 
    {
1160
 
      // Check that the domain name is present:
1161
 
      if ( workgroup.name().trimmed().isEmpty() )
1162
 
      {
1163
 
        Smb4KCoreMessage::error( ERROR_NET_COMMAND );
1164
 
 
1165
 
        return args; // still empty
1166
 
      }
1167
 
 
1168
 
      // This lookup command takes no protocol:
1169
 
      args.append( QString( " lookup master %1" ).arg( KShell::quoteArg( workgroup.name() ) ) );
1170
 
 
1171
 
      break;
1172
 
    }
1173
 
    default:
1174
 
    {
1175
 
      // Bypass the rest and return an empty string.
1176
 
      return args;
1177
 
    }
1178
 
  }
1179
 
 
1180
 
  args.append( !domain.isEmpty() ?
1181
 
               QString( " -W %1" ).arg( KShell::quoteArg( domain ) ) :
1182
 
               QString() );
1183
 
 
1184
 
  args.append( !netbios_name.isEmpty() ?
1185
 
               QString( " -n %1" ).arg( KShell::quoteArg( netbios_name ) ) :
1186
 
               QString() );
1187
 
 
1188
 
  args.append( Smb4KSettings::machineAccount() ?
1189
 
               " -P" :
1190
 
               QString() );
1191
 
 
1192
 
  args.append( QString( " -p %1" ).arg( port ) );
1193
 
 
1194
 
  return args;
1195
 
}
1196
 
 
1197
 
 
1198
 
const QString Smb4KSambaOptionsHandler::netOptions( NetCommand command )
1199
 
{
1200
 
  QString netbios_name =     (!Smb4KSettings::netBIOSName().isEmpty() &&
1201
 
                             QString::compare( Smb4KSettings::netBIOSName(),
1202
 
                             m_samba_options["netbios name"] ) != 0) ?
1203
 
                             Smb4KSettings::netBIOSName() :
1204
 
                             QString();
1205
 
 
1206
 
  QString domain =           (!Smb4KSettings::domainName().isEmpty() &&
1207
 
                             QString::compare( Smb4KSettings::domainName(),
1208
 
                             m_samba_options["workgroup"] ) != 0) ?
1209
 
                             Smb4KSettings::domainName() :
1210
 
                             QString();
1211
 
 
1212
 
  QString args;
1213
 
 
1214
 
  switch ( command )
1215
 
  {
1216
 
    case ServerDomain:
1217
 
    {
1218
 
      // This only works with the rap protocol:
1219
 
      args.append( " rap server domain" );
1220
 
 
1221
 
      break;
1222
 
    }
1223
 
    case Domain:
1224
 
    {
1225
 
      // This only works with the rap protocol:
1226
 
      args.append( " rap domain" );
1227
 
 
1228
 
      break;
1229
 
    }
1230
 
    default:
1231
 
    {
1232
 
      // Bypass the rest and return an
1233
 
      // empty string:
1234
 
      return args;
1235
 
    }
1236
 
  }
1237
 
 
1238
 
  args.append( !domain.isEmpty() ?
1239
 
               QString( " -W %1" ).arg( KShell::quoteArg( domain ) ) :
1240
 
               QString() );
1241
 
 
1242
 
  args.append( !netbios_name.isEmpty() ?
1243
 
               QString( " -n %1" ).arg( KShell::quoteArg( netbios_name ) ) :
1244
 
               QString() );
1245
 
 
1246
 
  args.append( Smb4KSettings::machineAccount() ?
1247
 
               " -P" :
1248
 
               QString() );
1249
 
 
1250
 
  args.append( QString( " -p %1" ).arg( Smb4KSettings::remoteSMBPort() ) );
1251
 
 
1252
 
  return args;
1253
 
}
1254
 
 
1255
 
 
1256
 
const QString Smb4KSambaOptionsHandler::mountOptions( const QString &share )
1257
 
{
1258
 
  Smb4KSambaOptionsInfo *info = find_item( share );
1259
 
  QString args;
1260
 
 
1261
 
  // Read the global Samba options from smb.conf:
1262
 
  (void) globalSambaOptions();
1263
 
 
1264
 
  // Get the strings needed to put the argument list together:
1265
 
  uid_t uid = info ? info->uid() : (uid_t)Smb4KSettings::userID().toInt();
1266
 
  gid_t gid = info ? info->gid() : (gid_t)Smb4KSettings::groupID().toInt();
1267
 
 
1268
 
  QString charset, codepage;
1269
 
 
1270
 
  switch ( Smb4KSettings::clientCharset() )
1271
 
  {
1272
 
    case Smb4KSettings::EnumClientCharset::default_charset:
1273
 
    {
1274
 
      charset = m_samba_options["unix charset"].toLower();  // maybe empty
1275
 
 
1276
 
      break;
1277
 
    }
1278
 
    case Smb4KSettings::EnumClientCharset::iso8859_1:
1279
 
    {
1280
 
      charset = "iso8859-1";
1281
 
 
1282
 
      break;
1283
 
    }
1284
 
    case Smb4KSettings::EnumClientCharset::iso8859_2:
1285
 
    {
1286
 
      charset = "iso8859-2";
1287
 
 
1288
 
      break;
1289
 
    }
1290
 
    case Smb4KSettings::EnumClientCharset::iso8859_3:
1291
 
    {
1292
 
      charset = "iso8859-3";
1293
 
 
1294
 
      break;
1295
 
    }
1296
 
    case Smb4KSettings::EnumClientCharset::iso8859_4:
1297
 
    {
1298
 
      charset = "iso8859-4";
1299
 
 
1300
 
      break;
1301
 
    }
1302
 
    case Smb4KSettings::EnumClientCharset::iso8859_5:
1303
 
    {
1304
 
      charset = "iso8859-5";
1305
 
 
1306
 
      break;
1307
 
    }
1308
 
    case Smb4KSettings::EnumClientCharset::iso8859_6:
1309
 
    {
1310
 
      charset = "iso8859-6";
1311
 
 
1312
 
      break;
1313
 
    }
1314
 
    case Smb4KSettings::EnumClientCharset::iso8859_7:
1315
 
    {
1316
 
      charset = "iso8859-7";
1317
 
 
1318
 
      break;
1319
 
    }
1320
 
    case Smb4KSettings::EnumClientCharset::iso8859_8:
1321
 
    {
1322
 
      charset = "iso8859-8";
1323
 
 
1324
 
      break;
1325
 
    }
1326
 
    case Smb4KSettings::EnumClientCharset::iso8859_9:
1327
 
    {
1328
 
      charset = "iso8859-9";
1329
 
 
1330
 
      break;
1331
 
    }
1332
 
    case Smb4KSettings::EnumClientCharset::iso8859_13:
1333
 
    {
1334
 
      charset = "iso8859-13";
1335
 
 
1336
 
      break;
1337
 
    }
1338
 
    case Smb4KSettings::EnumClientCharset::iso8859_14:
1339
 
    {
1340
 
      charset = "iso8859-14";
1341
 
 
1342
 
      break;
1343
 
    }
1344
 
    case Smb4KSettings::EnumClientCharset::iso8859_15:
1345
 
    {
1346
 
      charset = "iso8859-15";
1347
 
 
1348
 
      break;
1349
 
    }
1350
 
    case Smb4KSettings::EnumClientCharset::utf8:
1351
 
    {
1352
 
      charset = "utf8";
1353
 
 
1354
 
      break;
1355
 
    }
1356
 
    case Smb4KSettings::EnumClientCharset::koi8_r:
1357
 
    {
1358
 
      charset = "koi8-r";
1359
 
 
1360
 
      break;
1361
 
    }
1362
 
    case Smb4KSettings::EnumClientCharset::koi8_u:
1363
 
    {
1364
 
      charset = "koi8-u";
1365
 
 
1366
 
      break;
1367
 
    }
1368
 
    case Smb4KSettings::EnumClientCharset::koi8_ru:
1369
 
    {
1370
 
      charset = "koi8-ru";
1371
 
 
1372
 
      break;
1373
 
    }
1374
 
    case Smb4KSettings::EnumClientCharset::cp1251:
1375
 
    {
1376
 
      charset = "cp1251";
1377
 
 
1378
 
      break;
1379
 
    }
1380
 
    case Smb4KSettings::EnumClientCharset::gb2312:
1381
 
    {
1382
 
      charset = "gb2312";
1383
 
 
1384
 
      break;
1385
 
    }
1386
 
    case Smb4KSettings::EnumClientCharset::big5:
1387
 
    {
1388
 
      charset = "big5";
1389
 
 
1390
 
      break;
1391
 
    }
1392
 
    case Smb4KSettings::EnumClientCharset::euc_jp:
1393
 
    {
1394
 
      charset = "euc-jp";
1395
 
 
1396
 
      break;
1397
 
    }
1398
 
    case Smb4KSettings::EnumClientCharset::euc_kr:
1399
 
    {
1400
 
      charset = "euc-kr";
1401
 
 
1402
 
      break;
1403
 
    }
1404
 
    case Smb4KSettings::EnumClientCharset::tis_620:
1405
 
    {
1406
 
      charset = "tis-620";
1407
 
 
1408
 
      break;
1409
 
    }
1410
 
    default:
1411
 
    {
1412
 
      break;
1413
 
    }
1414
 
  }
1415
 
 
1416
 
#ifndef __FreeBSD__
1417
 
 
1418
 
  QString netbios_name =   (!Smb4KSettings::netBIOSName().isEmpty() &&
1419
 
                           QString::compare( Smb4KSettings::netBIOSName(),
1420
 
                           m_samba_options["netbios name"] ) != 0) ?
1421
 
                           Smb4KSettings::netBIOSName() :
1422
 
                           QString();
1423
 
 
1424
 
  QString socket_options = (!Smb4KSettings::socketOptions().isEmpty() &&
1425
 
                           QString::compare( Smb4KSettings::socketOptions(),
1426
 
                           m_samba_options["socket options"] ) != 0) ?
1427
 
                           Smb4KSettings::socketOptions() :
1428
 
                           QString();
1429
 
 
1430
 
  QString netbios_scope =  (!Smb4KSettings::netBIOSScope().isEmpty() &&
1431
 
                           QString::compare( Smb4KSettings::netBIOSScope(),
1432
 
                           m_samba_options["netbios scope"] ) != 0) ?
1433
 
                           Smb4KSettings::netBIOSScope() :
1434
 
                           QString();
1435
 
 
1436
 
  int port =               info && info->port() != -1 ?
1437
 
                           info->port() :
1438
 
                           Smb4KSettings::remoteFileSystemPort();
1439
 
 
1440
 
  bool kerberos = false;
1441
 
 
1442
 
  if ( info )
1443
 
  {
1444
 
    switch ( info->useKerberos() )
1445
 
    {
1446
 
      case Smb4KSambaOptionsInfo::UseKerberos:
1447
 
      {
1448
 
        kerberos = true;
1449
 
 
1450
 
        break;
1451
 
      }
1452
 
      case Smb4KSambaOptionsInfo::NoKerberos:
1453
 
      {
1454
 
        kerberos = false;
1455
 
 
1456
 
        break;
1457
 
      }
1458
 
      case Smb4KSambaOptionsInfo::UndefinedKerberos:
1459
 
      {
1460
 
        kerberos = Smb4KSettings::useKerberos();
1461
 
 
1462
 
        break;
1463
 
      }
1464
 
      default:
1465
 
      {
1466
 
        break;
1467
 
      }
1468
 
    }
1469
 
  }
1470
 
  else
1471
 
  {
1472
 
    kerberos = Smb4KSettings::useKerberos();
1473
 
  }
1474
 
 
1475
 
  bool write_access = true;
1476
 
 
1477
 
  if ( info )
1478
 
  {
1479
 
    switch ( info->writeAccess() )
1480
 
    {
1481
 
      case Smb4KSambaOptionsInfo::ReadWrite:
1482
 
      {
1483
 
        write_access = true;
1484
 
 
1485
 
        break;
1486
 
      }
1487
 
      case Smb4KSambaOptionsInfo::ReadOnly:
1488
 
      {
1489
 
        write_access = false;
1490
 
 
1491
 
        break;
1492
 
      }
1493
 
      case Smb4KSambaOptionsInfo::UndefinedWriteAccess:
1494
 
      {
1495
 
        write_access = (Smb4KSettings::writeAccess() == Smb4KSettings::EnumWriteAccess::ReadWrite);
1496
 
 
1497
 
        break;
1498
 
      }
1499
 
      default:
1500
 
      {
1501
 
        break;
1502
 
      }
1503
 
    }
1504
 
  }
1505
 
  else
1506
 
  {
1507
 
    write_access = (Smb4KSettings::writeAccess() == Smb4KSettings::EnumWriteAccess::ReadWrite);
1508
 
  }
1509
 
 
1510
 
  // Compile the arguments list:
1511
 
  args.append( !netbios_name.isEmpty() ?
1512
 
               QString( "netbiosname='%1'," ).arg( netbios_name ) :
1513
 
               QString() );
1514
 
 
1515
 
  args.append( QString( "uid=%1," ).arg( uid ) );
1516
 
 
1517
 
  args.append( QString( "gid=%1," ).arg( gid ) );
1518
 
 
1519
 
  args.append( QString( "port=%1," ).arg( port ) );
1520
 
 
1521
 
  args.append( !charset.isEmpty() ?
1522
 
               QString( "iocharset=%1," ).arg( charset ) :
1523
 
               QString() );
1524
 
 
1525
 
  args.append( write_access ? "rw," : "ro," );
1526
 
 
1527
 
  args.append( !Smb4KSettings::fileMask().isEmpty() ?
1528
 
               QString( "file_mode=%1," ).arg( Smb4KSettings::fileMask() ) :
1529
 
               QString() );
1530
 
 
1531
 
  args.append( !Smb4KSettings::directoryMask().isEmpty() ?
1532
 
               QString( "dir_mode=%1," ).arg( Smb4KSettings::directoryMask() ) :
1533
 
               QString() );
1534
 
 
1535
 
  args.append( Smb4KSettings::permissionChecks() ?
1536
 
               "perm," :
1537
 
               "noperm," );
1538
 
 
1539
 
  args.append( Smb4KSettings::clientControlsIDs() ?
1540
 
               "setuids," :
1541
 
               "nosetuids," );
1542
 
 
1543
 
  args.append( Smb4KSettings::serverInodeNumbers() ?
1544
 
               "serverino," :
1545
 
               "noserverino," );
1546
 
 
1547
 
  args.append( Smb4KSettings::inodeDataCaching() ?
1548
 
               "directio," :
1549
 
               QString() );
1550
 
 
1551
 
  args.append( Smb4KSettings::translateReservedChars() ?
1552
 
               "mapchars," :
1553
 
               "nomapchars," );
1554
 
 
1555
 
  args.append( Smb4KSettings::noLocking() ?
1556
 
               "nolock," :
1557
 
               QString() );
1558
 
 
1559
 
  args.append( !Smb4KSettings::customCIFSOptions().isEmpty() ?
1560
 
               Smb4KSettings::customCIFSOptions() :
1561
 
               QString() );
1562
 
 
1563
 
  args.append( !args.endsWith( "," ) ? "," : "" );
1564
 
 
1565
 
#else
1566
 
 
1567
 
  // Compile the arguments list:
1568
 
  args.append( QString( " -u %1" ).arg( uid ) );
1569
 
 
1570
 
  args.append( QString( " -g %1" ).arg( gid ) );
1571
 
 
1572
 
  args.append( !charset.isEmpty() && !codepage.isEmpty() ?
1573
 
               QString( " -E %1:%2" ).arg( charset, codepage ) :
1574
 
               QString() );
1575
 
 
1576
 
  args.append( !Smb4KSettings::fileMask().isEmpty() ?
1577
 
               QString( " -f %1" ).arg( Smb4KSettings::fileMask() ) :
1578
 
               QString() );
1579
 
 
1580
 
  args.append( !Smb4KSettings::directoryMask().isEmpty() ?
1581
 
               QString( " -d %1" ).arg( Smb4KSettings::directoryMask() ) :
1582
 
               QString() );
1583
 
 
1584
 
  // NOTE: Under FreeBSD the port must be managed by the mounter.
1585
 
 
1586
 
  // FIXME: If the manual page was of more use, we could probably implement
1587
 
  // more of the arguments that are available for mount_smbfs.
1588
 
 
1589
 
#endif
1590
 
 
1591
 
  return args;
1592
 
}
1593
 
 
1594
 
 
1595
 
void Smb4KSambaOptionsHandler::read_smb_conf()
1596
 
{
1597
 
  // Clear the options list before reading.
1598
 
  m_samba_options.clear();
1599
 
 
1600
 
  QStringList paths;
1601
 
  paths << "/etc";
1602
 
  paths << "/etc/samba";
1603
 
  paths << "/usr/local/etc";
1604
 
  paths << "/usr/local/etc/samba";
1605
 
 
1606
 
  QFile file( "smb.conf" );
1607
 
 
1608
 
  QStringList contents;
1609
 
 
1610
 
  // Locate the file and read its contents:
1611
 
  for ( int i = 0; i < paths.size(); ++i )
1612
 
  {
1613
 
    QDir::setCurrent( paths.at( i ) );
1614
 
 
1615
 
    if ( file.exists() )
1616
 
    {
1617
 
      if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
1618
 
      {
1619
 
        QTextStream ts( &file );
1620
 
        // Note: With Qt 4.3 this seems to be obsolete, we'll keep
1621
 
        // it for now.
1622
 
        ts.setCodec( QTextCodec::codecForLocale() );
1623
 
 
1624
 
        while ( !ts.atEnd() )
1625
 
        {
1626
 
          contents.append( ts.readLine( 0 ) );
1627
 
        }
1628
 
 
1629
 
        file.close();
1630
 
      }
1631
 
      else
1632
 
      {
1633
 
        Smb4KCoreMessage::error( ERROR_OPENING_FILE, paths.at( i )+QDir::separator()+file.fileName() );
1634
 
 
1635
 
        // Stop here
1636
 
        return;
1637
 
      }
1638
 
 
1639
 
      break;
1640
 
    }
1641
 
    else
1642
 
    {
1643
 
      continue;
1644
 
    }
1645
 
  }
1646
 
 
1647
 
  if ( !contents.isEmpty() )
1648
 
  {
1649
 
    // Process the file contents.
1650
 
    for ( int i = contents.indexOf( "[global]", 0 ); i < contents.size(); ++i )
1651
 
    {
1652
 
      if ( contents.at( i ).trimmed().startsWith( "#" ) ||
1653
 
           contents.at( i ).trimmed().startsWith( ";" ) )
1654
 
      {
1655
 
        // This is a comment. We do not need it.
1656
 
        continue;
1657
 
      }
1658
 
      else if ( contents.at( i ).trimmed().startsWith( "include" ) )
1659
 
      {
1660
 
        // Look for the include file and put its contents into the
1661
 
        // m_samba_options map.
1662
 
        file.setFileName( contents.at( i ).section( "=", 1, 1 ).trimmed() );
1663
 
 
1664
 
        if ( file.exists() )
1665
 
        {
1666
 
          if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
1667
 
          {
1668
 
            QTextStream ts( &file );
1669
 
            // Note: With Qt 4.3 this seems to be obsolete, we'll keep
1670
 
            // it for now.
1671
 
            ts.setCodec( QTextCodec::codecForLocale() );
1672
 
 
1673
 
            QString buffer;
1674
 
 
1675
 
            while( !ts.atEnd() )
1676
 
            {
1677
 
              buffer = ts.readLine( 0 ).trimmed();
1678
 
 
1679
 
              if ( buffer.startsWith( "#" ) || buffer.startsWith( ";" ) )
1680
 
              {
1681
 
                continue;
1682
 
              }
1683
 
              else
1684
 
              {
1685
 
                QString key = buffer.section( "=", 0, 0 ).trimmed().toLower();
1686
 
                m_samba_options[key] = buffer.section( "=", 1, 1 ).trimmed().toUpper();
1687
 
 
1688
 
                continue;
1689
 
              }
1690
 
            }
1691
 
          }
1692
 
          else
1693
 
          {
1694
 
            Smb4KCoreMessage::error( ERROR_OPENING_FILE, file.fileName() );
1695
 
 
1696
 
            // Continue reading the smb.conf file.
1697
 
            continue;
1698
 
          }
1699
 
        }
1700
 
      }
1701
 
      else if ( contents.at( i ).startsWith( "[" ) &&
1702
 
                !contents.at( i ).contains( "[global]", Qt::CaseSensitive ) )
1703
 
      {
1704
 
        // We reached the end of the [global] section. Stop here.
1705
 
        break;
1706
 
      }
1707
 
      else
1708
 
      {
1709
 
        // Put the entries of the [global] section into the m_samba_options
1710
 
        // map.
1711
 
        QString key = contents.at( i ).section( "=", 0, 0 ).trimmed().toLower();
1712
 
        m_samba_options[key] = contents.at( i ).section( "=", 1, 1 ).trimmed().toUpper();
1713
 
      }
1714
 
    }
1715
 
  }
1716
 
  else
1717
 
  {
1718
 
    // Nothing to do
1719
 
  }
1720
 
 
1721
 
  // Post-processing. Some values should be entered with their defaults, if they are
1722
 
  // not already present.
1723
 
  if ( !m_samba_options.contains( "netbios name" ) )
1724
 
  {
1725
 
    size_t hostnamelen = 255;
1726
 
    char *hostname = new char[hostnamelen];
1727
 
 
1728
 
    if ( gethostname( hostname, hostnamelen ) == -1 )
1729
 
    {
1730
 
      int error = errno;
1731
 
      Smb4KCoreMessage::error( ERROR_GETTING_HOSTNAME, QString(), strerror( error ) );
1732
 
    }
1733
 
    else
1734
 
    {
1735
 
      m_samba_options["netbios name"] = ( QString( "%1" ).arg( hostname ) ).toUpper();
1736
 
    }
1737
 
 
1738
 
    delete [] hostname;
1739
 
  }
1740
 
}
1741
 
 
1742
 
 
1743
 
const QMap<QString,QString> &Smb4KSambaOptionsHandler::globalSambaOptions()
1744
 
{
1745
 
  if ( m_samba_options.isEmpty() )
1746
 
  {
1747
 
    read_smb_conf();
1748
 
  }
1749
 
 
1750
 
  return m_samba_options;
1751
 
}
1752
 
 
1753
 
 
1754
 
const QString &Smb4KSambaOptionsHandler::winsServer()
1755
 
{
1756
 
  if ( m_wins_server.isEmpty() )
1757
 
  {
1758
 
    (void) globalSambaOptions();
1759
 
 
1760
 
    if ( !m_samba_options["wins server"].isEmpty() )
1761
 
    {
1762
 
      m_wins_server = m_samba_options["wins server"];
1763
 
    }
1764
 
    else if ( !m_samba_options["wins support"].isEmpty() &&
1765
 
              (QString::compare( m_samba_options["wins support"], "yes", Qt::CaseInsensitive ) == 0 ||
1766
 
              QString::compare( m_samba_options["wins support"], "true", Qt::CaseInsensitive ) == 0) )
1767
 
    {
1768
 
      m_wins_server = "127.0.0.1";
1769
 
    }
1770
 
  }
1771
 
 
1772
 
  return m_wins_server;
1773
 
}
1774
 
 
1775
 
 
1776
 
void Smb4KSambaOptionsHandler::addItem( Smb4KSambaOptionsInfo *info, bool s )
1777
 
{
1778
 
  has_custom_options( info );
1779
 
 
1780
 
  if ( info->hasCustomOptions() ||
1781
 
       info->remount() == Smb4KSambaOptionsInfo::DoRemount )
1782
 
  {
1783
 
    Smb4KSambaOptionsInfo *item = find_item( info->unc() );
1784
 
 
1785
 
    if ( item && QString::compare( item->unc(), info->unc(), Qt::CaseInsensitive ) == 0 )
1786
 
    {
1787
 
      item->update( info );
1788
 
    }
1789
 
    else
1790
 
    {
1791
 
      m_list.append( info );
1792
 
    }
1793
 
 
1794
 
    if ( s )
1795
 
    {
1796
 
      sync();
1797
 
    }
1798
 
  }
1799
 
  else
1800
 
  {
1801
 
    removeItem( info->unc(), false );
1802
 
  }
1803
 
}
1804
 
 
1805
 
 
1806
 
void Smb4KSambaOptionsHandler::removeItem( const QString &unc, bool s )
1807
 
{
1808
 
  Smb4KSambaOptionsInfo *item = find_item( unc );
1809
 
 
1810
 
  if ( item && QString::compare( item->unc(), unc, Qt::CaseInsensitive ) == 0 )
1811
 
  {
1812
 
    int index = m_list.indexOf( item, 0 );
1813
 
    delete m_list.takeAt( index );
1814
 
  }
1815
 
 
1816
 
  if ( s )
1817
 
  {
1818
 
    sync();
1819
 
  }
1820
 
}
1821
 
 
1822
 
 
1823
 
const QString Smb4KSambaOptionsHandler::smbtreeOptions( const QString &master )
1824
 
{
1825
 
  Smb4KSambaOptionsInfo *info = NULL;
1826
 
 
1827
 
  if ( !master.isEmpty() )
1828
 
  {
1829
 
    info = find_item( master );
1830
 
  }
1831
 
 
1832
 
  bool kerberos = false;
1833
 
 
1834
 
  if ( info )
1835
 
  {
1836
 
    switch ( info->useKerberos() )
1837
 
    {
1838
 
      case Smb4KSambaOptionsInfo::UseKerberos:
1839
 
      {
1840
 
        kerberos = true;
1841
 
 
1842
 
        break;
1843
 
      }
1844
 
      case Smb4KSambaOptionsInfo::NoKerberos:
1845
 
      {
1846
 
        kerberos = false;
1847
 
 
1848
 
        break;
1849
 
      }
1850
 
      case Smb4KSambaOptionsInfo::UndefinedKerberos:
1851
 
      {
1852
 
        kerberos = Smb4KSettings::useKerberos();
1853
 
 
1854
 
        break;
1855
 
      }
1856
 
      default:
1857
 
      {
1858
 
        break;
1859
 
      }
1860
 
    }
1861
 
  }
1862
 
  else
1863
 
  {
1864
 
    kerberos = Smb4KSettings::useKerberos();
1865
 
  }
1866
 
 
1867
 
  QString args;
1868
 
 
1869
 
  args.append( (Smb4KSettings::machineAccount() ?
1870
 
               " -P" :
1871
 
               QString()) );
1872
 
 
1873
 
  switch ( Smb4KSettings::signingState() )
1874
 
  {
1875
 
    case Smb4KSettings::EnumSigningState::None:
1876
 
    {
1877
 
      // The user does not want this setting
1878
 
      // to be used.
1879
 
      break;
1880
 
    }
1881
 
    case Smb4KSettings::EnumSigningState::On:
1882
 
    {
1883
 
      args.append( " -S on" );
1884
 
 
1885
 
      break;
1886
 
    }
1887
 
    case Smb4KSettings::EnumSigningState::Off:
1888
 
    {
1889
 
      args.append( " -S off" );
1890
 
 
1891
 
      break;
1892
 
    }
1893
 
    case Smb4KSettings::EnumSigningState::Required:
1894
 
    {
1895
 
      args.append( " -S required" );
1896
 
 
1897
 
      break;
1898
 
    }
1899
 
    default:
1900
 
    {
1901
 
      break;
1902
 
    }
1903
 
  }
1904
 
 
1905
 
  args.append( (Smb4KSettings::smbtreeSendBroadcasts() ?
1906
 
               " -b" :
1907
 
               QString()) );
1908
 
 
1909
 
  args.append( (kerberos ?
1910
 
               " -k" :
1911
 
               QString()) );
1912
 
 
1913
 
  return args;
1914
 
}
1915
 
 
1916
 
 
1917
 
void Smb4KSambaOptionsHandler::updateCustomOptions( const QList<Smb4KSambaOptionsInfo *> &list )
1918
 
{
1919
 
  if ( !list.isEmpty() )
1920
 
  {
1921
 
    // Delete obsolete items.
1922
 
    for ( int i = 0; i < m_list.size(); ++i )
1923
 
    {
1924
 
      bool found = false;
1925
 
 
1926
 
      for ( int j = 0; j < list.size(); ++j )
1927
 
      {
1928
 
        if ( QString::compare( m_list.at( i )->unc(), list.at( j )->unc(), Qt::CaseInsensitive ) == 0 )
1929
 
        {
1930
 
          found = true;
1931
 
 
1932
 
          break;
1933
 
        }
1934
 
        else
1935
 
        {
1936
 
          continue;
1937
 
        }
1938
 
      }
1939
 
 
1940
 
      if ( !found )
1941
 
      {
1942
 
        delete m_list.takeAt( i );
1943
 
 
1944
 
        continue;
1945
 
      }
1946
 
      else
1947
 
      {
1948
 
        continue;
1949
 
      }
1950
 
    }
1951
 
 
1952
 
    // Update and add items.
1953
 
    for ( int i = 0; i < list.size(); ++i )
1954
 
    {
1955
 
      Smb4KSambaOptionsInfo *info = find_item( list.at( i )->unc() );
1956
 
 
1957
 
      if ( info )
1958
 
      {
1959
 
        info->update( list.at( i ) );
1960
 
 
1961
 
        continue;
1962
 
      }
1963
 
      else
1964
 
      {
1965
 
        m_list.append( list.at( i ) );
1966
 
 
1967
 
        continue;
1968
 
      }
1969
 
    }
1970
 
  }
1971
 
  else
1972
 
  {
1973
 
    while ( !m_list.isEmpty() )
1974
 
    {
1975
 
      delete m_list.takeFirst();
1976
 
    }
1977
 
  }
1978
 
 
1979
 
  sync();
1980
 
}
1981
 
 
1982
 
 
1983
 
void Smb4KSambaOptionsHandler::has_custom_options( Smb4KSambaOptionsInfo *item )
1984
 
{
1985
 
  if ( item )
1986
 
  {
1987
 
    switch ( item->type() )
1988
 
    {
1989
 
      case Smb4KSambaOptionsInfo::Host:
1990
 
      {
1991
 
        Smb4KSambaOptionsInfo::Protocol protocol_hint;
1992
 
 
1993
 
        switch ( Smb4KSettings::protocolHint() )
1994
 
        {
1995
 
          case Smb4KSettings::EnumProtocolHint::Automatic:
1996
 
          {
1997
 
            protocol_hint = Smb4KSambaOptionsInfo::Automatic;
1998
 
 
1999
 
            break;
2000
 
          }
2001
 
          case Smb4KSettings::EnumProtocolHint::RPC:
2002
 
          {
2003
 
            protocol_hint = Smb4KSambaOptionsInfo::RPC;
2004
 
 
2005
 
            break;
2006
 
          }
2007
 
          case Smb4KSettings::EnumProtocolHint::RAP:
2008
 
          {
2009
 
            protocol_hint = Smb4KSambaOptionsInfo::RAP;
2010
 
 
2011
 
            break;
2012
 
          }
2013
 
          case Smb4KSettings::EnumProtocolHint::ADS:
2014
 
          {
2015
 
            protocol_hint = Smb4KSambaOptionsInfo::ADS;
2016
 
 
2017
 
            break;
2018
 
          }
2019
 
          default:
2020
 
          {
2021
 
            protocol_hint = Smb4KSambaOptionsInfo::UndefinedProtocol;
2022
 
 
2023
 
            break;
2024
 
          }
2025
 
        }
2026
 
 
2027
 
        Smb4KSambaOptionsInfo::Kerberos default_kerberos = Smb4KSambaOptionsInfo::UndefinedKerberos;
2028
 
 
2029
 
        if ( Smb4KSettings::useKerberos() )
2030
 
        {
2031
 
          default_kerberos = Smb4KSambaOptionsInfo::UseKerberos;
2032
 
        }
2033
 
        else
2034
 
        {
2035
 
          default_kerberos = Smb4KSambaOptionsInfo::NoKerberos;
2036
 
        }
2037
 
 
2038
 
        if ( item->protocol() != Smb4KSambaOptionsInfo::UndefinedProtocol &&
2039
 
             item->protocol() != protocol_hint )
2040
 
        {
2041
 
          item->setHasCustomOptions( true );
2042
 
 
2043
 
          break;
2044
 
        }
2045
 
        else if ( item->port() != -1 &&
2046
 
                  item->port() != Smb4KSettings::remoteSMBPort() )
2047
 
        {
2048
 
          item->setHasCustomOptions( true );
2049
 
 
2050
 
          break;
2051
 
        }
2052
 
        else if ( item->useKerberos() != Smb4KSambaOptionsInfo::UndefinedKerberos &&
2053
 
                  item->useKerberos() != default_kerberos )
2054
 
        {
2055
 
          item->setHasCustomOptions( true );
2056
 
 
2057
 
          break;
2058
 
        }
2059
 
        else
2060
 
        {
2061
 
          break;
2062
 
        }
2063
 
 
2064
 
        break;
2065
 
      }
2066
 
      case Smb4KSambaOptionsInfo::Share:
2067
 
      {
2068
 
#ifndef __FreeBSD__
2069
 
        Smb4KSambaOptionsInfo::WriteAccess write_access;
2070
 
 
2071
 
        switch( Smb4KSettings::writeAccess() )
2072
 
        {
2073
 
          case Smb4KSettings::EnumWriteAccess::ReadWrite:
2074
 
          {
2075
 
            write_access = Smb4KSambaOptionsInfo::ReadWrite;
2076
 
 
2077
 
            break;
2078
 
          }
2079
 
          case Smb4KSettings::EnumWriteAccess::ReadOnly:
2080
 
          {
2081
 
            write_access = Smb4KSambaOptionsInfo::ReadOnly;
2082
 
 
2083
 
            break;
2084
 
          }
2085
 
          default:
2086
 
          {
2087
 
            write_access = Smb4KSambaOptionsInfo::UndefinedWriteAccess;
2088
 
 
2089
 
            break;
2090
 
          }
2091
 
        }
2092
 
#endif
2093
 
 
2094
 
        Smb4KSambaOptionsInfo::Kerberos default_kerberos = Smb4KSambaOptionsInfo::UndefinedKerberos;
2095
 
 
2096
 
        if ( Smb4KSettings::useKerberos() )
2097
 
        {
2098
 
          default_kerberos = Smb4KSambaOptionsInfo::UseKerberos;
2099
 
        }
2100
 
        else
2101
 
        {
2102
 
          default_kerberos = Smb4KSambaOptionsInfo::NoKerberos;
2103
 
        }
2104
 
 
2105
 
#ifndef __FreeBSD__
2106
 
        if ( item->port() != -1 &&
2107
 
             item->port() != Smb4KSettings::remoteFileSystemPort() )
2108
 
        {
2109
 
          item->setHasCustomOptions( true );
2110
 
 
2111
 
          break;
2112
 
        }
2113
 
        else if ( item->writeAccess() != Smb4KSambaOptionsInfo::UndefinedWriteAccess &&
2114
 
                  item->writeAccess() != write_access )
2115
 
        {
2116
 
          item->setHasCustomOptions( true );
2117
 
 
2118
 
          break;
2119
 
        }
2120
 
        else if ( item->useKerberos() != Smb4KSambaOptionsInfo::UndefinedKerberos &&
2121
 
                  item->useKerberos() != default_kerberos )
2122
 
        {
2123
 
          item->setHasCustomOptions( true );
2124
 
 
2125
 
          break;
2126
 
        }
2127
 
#else
2128
 
        if ( item->port() != -1 &&
2129
 
             item->port() != Smb4KSettings::remoteSMBPort() )
2130
 
        {
2131
 
          item->setHasCustomOptions( true );
2132
 
 
2133
 
          break;
2134
 
        }
2135
 
#endif
2136
 
        else if ( item->uidIsSet() && (item->uid() != (uid_t)Smb4KSettings::userID().toInt()) )
2137
 
        {
2138
 
          item->setHasCustomOptions( true );
2139
 
 
2140
 
          break;
2141
 
        }
2142
 
        else if ( item->gidIsSet() && (item->gid() != (gid_t)Smb4KSettings::groupID().toInt()) )
2143
 
        {
2144
 
          item->setHasCustomOptions( true );
2145
 
 
2146
 
          break;
2147
 
        }
2148
 
        else
2149
 
        {
2150
 
          break;
2151
 
        }
2152
 
 
2153
 
        break;
2154
 
      }
2155
 
      default:
2156
 
      {
2157
 
        break;
2158
 
      }
2159
 
    }
2160
 
  }
2161
 
  else
2162
 
  {
2163
 
    // Nothing to do
2164
 
  }
2165
 
}
2166
 
 
2167
 
 
2168
 
#include "smb4ksambaoptionshandler.moc"