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, *
22
* Free Software Foundation, 51 Franklin Street, Suite 500, Boston, *
23
* MA 02110-1335, USA *
24
24
***************************************************************************/
29
#include <QHostAddress>
30
#include <QAbstractSocket>
33
#include <kstandarddirs.h>
26
36
// application specific includes
27
#include "smb4kscanner_p.h"
37
#include <smb4kscanner_p.h>
38
#include <smb4ksettings.h>
39
#include <smb4knotification.h>
40
#include <smb4kglobal.h>
41
#include <smb4kcustomoptionsmanager.h>
42
#include <smb4kcustomoptions.h>
43
#include <smb4kworkgroup.h>
44
#include <smb4khost.h>
45
#include <smb4kshare.h>
46
#include <smb4kwalletmanager.h>
48
using namespace Smb4KGlobal;
51
Smb4KLookupDomainsJob::Smb4KLookupDomainsJob( QObject *parent ) : KJob( parent ),
52
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
57
Smb4KLookupDomainsJob::~Smb4KLookupDomainsJob()
62
void Smb4KLookupDomainsJob::start()
65
QTimer::singleShot( 0, this, SLOT( slotStartLookup() ) );
69
void Smb4KLookupDomainsJob::setupLookup( QWidget *parent )
71
m_parent_widget = parent;
75
bool Smb4KLookupDomainsJob::doKill()
77
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
86
return KJob::doKill();
90
void Smb4KLookupDomainsJob::processWorkgroups()
92
QStringList stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).split( "\n", QString::SkipEmptyParts );
94
if ( !stdout.isEmpty() )
96
Smb4KWorkgroup workgroup;
98
foreach ( const QString &line, stdout )
100
if ( line.startsWith( "Looking up status of" ) )
102
// Get the IP address of the master browser.
103
workgroup.setMasterBrowserIP( line.section( "of", 1, 1 ).trimmed() );
106
else if ( line.contains( "MAC Address", Qt::CaseSensitive ) )
108
// Add workgroup to the list. Ignore misconfigured master browsers,
109
// that do not belong to a workgroup/domain, i.e. where the workgroup
111
if ( !workgroup.workgroupName().isEmpty() && !workgroup.masterBrowserName().isEmpty() )
113
m_workgroups_list << workgroup;
120
workgroup = Smb4KWorkgroup();
123
else if ( line.contains( " <00> ", Qt::CaseSensitive ) )
125
// Set the name of the workgroup/host.
126
if ( line.contains( " <GROUP> ", Qt::CaseSensitive ) )
128
// Avoid setting the workgroup name twice.
129
if ( workgroup.workgroupName().isEmpty() )
131
workgroup.setWorkgroupName( line.section( "<00>", 0, 0 ).trimmed() );
140
// Avoid setting the name of the master browser twice.
141
if ( workgroup.masterBrowserName().isEmpty() )
143
workgroup.setMasterBrowserName( line.section( "<00>", 0, 0 ).trimmed() );
153
else if ( line.contains( " <1d> ", Qt::CaseSensitive ) )
155
// Get the workgroup name.
156
if ( workgroup.workgroupName().isEmpty() )
158
workgroup.setWorkgroupName( line.section( "<1d>", 0, 0 ).trimmed() );
167
else if ( line.contains( "__MSBROWSE__", Qt::CaseSensitive ) &&
168
line.contains( " <01> ", Qt::CaseSensitive ) )
170
// The host is a master browser.
171
workgroup.setHasPseudoMasterBrowser( false );
185
emit workgroups( m_workgroups_list );
189
void Smb4KLookupDomainsJob::slotStartLookup()
191
// Find nmblookup program.
192
QString nmblookup = KStandardDirs::findExe( "nmblookup" );
194
if ( nmblookup.isEmpty() )
196
Smb4KNotification *notification = new Smb4KNotification();
197
notification->commandNotFound( "nmblookup" );
206
// Find grep program.
207
QString grep = KStandardDirs::findExe( "grep" );
209
if ( grep.isEmpty() )
211
Smb4KNotification *notification = new Smb4KNotification();
212
notification->commandNotFound( "grep" );
222
QString awk = KStandardDirs::findExe( "awk" );
226
Smb4KNotification *notification = new Smb4KNotification();
227
notification->commandNotFound( "awk" );
236
// Find xargs program
237
QString xargs = KStandardDirs::findExe( "xargs" );
239
if ( xargs.isEmpty() )
241
Smb4KNotification *notification = new Smb4KNotification();
242
notification->commandNotFound( "xargs" );
251
// Global Samba options
252
QMap<QString,QString> samba_options = globalSambaOptions();
255
QStringList arguments;
258
arguments << nmblookup;
261
if ( !Smb4KSettings::domainName().isEmpty() &&
262
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
264
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
272
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
273
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
275
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
283
if ( !Smb4KSettings::netBIOSScope().isEmpty() &&
284
QString::compare( Smb4KSettings::netBIOSScope(), samba_options["netbios scope"] ) != 0 )
286
arguments << QString( "-i %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSScope() ) );
294
if ( !Smb4KSettings::socketOptions().isEmpty() &&
295
QString::compare( Smb4KSettings::socketOptions(), samba_options["socket options"] ) != 0 )
297
arguments << QString( "-O %1" ).arg( KShell::quoteArg( Smb4KSettings::socketOptions() ) );
305
if ( Smb4KSettings::usePort137() )
315
QHostAddress address( Smb4KSettings::broadcastAddress() );
317
if ( !Smb4KSettings::broadcastAddress().isEmpty() &&
318
address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol )
320
arguments << QString( "-B %1" ).arg( Smb4KSettings::broadcastAddress() );
332
arguments << "'<01>'";
335
arguments << "'{print $1}'";
338
if ( !winsServer().isEmpty() )
341
arguments << "-Iips";
342
arguments << nmblookup;
344
arguments << QString( "-U %1" ).arg( KShell::quoteArg( winsServer() ) );
345
arguments << "-A ips";
350
arguments << "-Iips";
351
arguments << nmblookup;
352
arguments << "-A ips";
356
if ( !Smb4KSettings::domainName().isEmpty() &&
357
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
359
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
367
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
368
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
370
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
378
if ( !Smb4KSettings::netBIOSScope().isEmpty() &&
379
QString::compare( Smb4KSettings::netBIOSScope(), samba_options["netbios scope"] ) != 0 )
381
arguments << QString( "-i %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSScope() ) );
389
if ( !Smb4KSettings::socketOptions().isEmpty() &&
390
QString::compare( Smb4KSettings::socketOptions(), samba_options["socket options"] ) != 0 )
392
arguments << QString( "-O %1" ).arg( KShell::quoteArg( Smb4KSettings::socketOptions() ) );
400
if ( Smb4KSettings::usePort137() )
409
m_proc = new Smb4KProcess( this );
410
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
411
m_proc->setShellCommand( arguments.join( " " ) );
413
connect( m_proc, SIGNAL( readyReadStandardError() ), this, SLOT( slotReadStandardError() ) );
414
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), this, SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
422
void Smb4KLookupDomainsJob::slotReadStandardError()
424
// Read from stderr and decide what to do.
425
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 ).trimmed();
427
if ( !stderr.isEmpty() )
429
Smb4KNotification *notification = new Smb4KNotification();
430
notification->retrievingDomainsFailed( stderr );
439
void Smb4KLookupDomainsJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
441
switch ( exitStatus )
443
case QProcess::CrashExit:
445
if ( !m_proc->isAborted() )
447
Smb4KNotification *notification = new Smb4KNotification();
448
notification->processError( m_proc->error() );
469
Smb4KQueryMasterJob::Smb4KQueryMasterJob( QObject *parent ) : KJob( parent ),
470
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
475
Smb4KQueryMasterJob::~Smb4KQueryMasterJob()
480
void Smb4KQueryMasterJob::start()
483
QTimer::singleShot( 0, this, SLOT( slotStartLookup() ) );
487
void Smb4KQueryMasterJob::setupLookup( const QString &master, QWidget *parent )
489
m_master_browser = master;
490
m_parent_widget = parent;
494
bool Smb4KQueryMasterJob::doKill()
496
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
505
return KJob::doKill();
509
void Smb4KQueryMasterJob::processWorkgroups()
511
QStringList stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).split( "\n", QString::SkipEmptyParts );
513
if ( !stdout.isEmpty() )
515
Smb4KWorkgroup workgroup;
517
foreach ( const QString &line, stdout )
519
if ( line.trimmed().startsWith( "Enumerating" ) )
523
else if ( line.trimmed().startsWith( "Domain name" ) )
527
else if ( line.trimmed().startsWith( "-------------" ) )
531
else if ( line.trimmed().isEmpty() )
537
// This is the workgroup and master entry. Process it.
538
workgroup.setWorkgroupName( line.section( " ", 0, 0 ).trimmed() );
539
workgroup.setMasterBrowserName( line.section( " ", 1, -1 ).trimmed() );
540
workgroup.setHasPseudoMasterBrowser( false );
542
m_workgroups_list << workgroup;
544
workgroup = Smb4KWorkgroup();
554
emit workgroups( m_workgroups_list );
558
void Smb4KQueryMasterJob::slotStartLookup()
561
QString net = KStandardDirs::findExe( "net" );
565
Smb4KNotification *notification = new Smb4KNotification();
566
notification->commandNotFound( "net" );
575
// Find xargs program
576
QString xargs = KStandardDirs::findExe( "xargs" );
578
if ( xargs.isEmpty() )
580
Smb4KNotification *notification = new Smb4KNotification();
581
notification->commandNotFound( "xargs" );
590
// Global Samba options
591
QMap<QString,QString> samba_options = globalSambaOptions();
594
Smb4KWorkgroup workgroup;
596
if ( !Smb4KSettings::domainName().isEmpty() )
598
workgroup.setWorkgroupName( Smb4KSettings::domainName() );
602
workgroup.setWorkgroupName( samba_options["workgroup"] );
605
Smb4KCustomOptions *options = NULL;
606
QStringList arguments;
609
if ( !m_master_browser.isEmpty() )
611
// We do not need to set the domain here, because neither
612
// Smb4KCustomOptionsMangager nor Smb4KWalletManager need
613
// the domain entry to return correct data.
614
if ( QHostAddress( m_master_browser ).protocol() == QAbstractSocket::UnknownNetworkLayerProtocol )
616
host.setHostName( m_master_browser );
620
host.setIP( m_master_browser );
623
// Acquire the custom options for the master browser
624
options = Smb4KCustomOptionsManager::self()->findOptions( &host );
626
// Get authentication information for the host if needed
627
if ( Smb4KSettings::masterBrowsersRequireAuth() )
629
Smb4KWalletManager::self()->readAuthInfo( &host );
636
// Custom master lookup
638
arguments << "lookup";
640
arguments << KShell::quoteArg( host.hostName() );
644
// Get authentication information for the host if needed
645
if ( Smb4KSettings::masterBrowsersRequireAuth() && Smb4KSettings::useDefaultLogin() )
647
Smb4KWalletManager::self()->readAuthInfo( &host );
656
arguments << "lookup";
657
arguments << "master";
658
arguments << KShell::quoteArg( workgroup.workgroupName() );
661
// The user's workgroup/domain name
662
if ( !Smb4KSettings::domainName().isEmpty() &&
663
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
665
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
672
// The user's NetBIOS name
673
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
674
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
676
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
684
if ( Smb4KSettings::machineAccount() )
694
if ( options && options->smbPort() != Smb4KSettings::remoteSMBPort() )
696
arguments << QString( "-p %1" ).arg( options->smbPort() );
700
arguments << QString( "-p %1" ).arg( Smb4KSettings::remoteSMBPort() );
703
// User name and password if needed
704
if ( Smb4KSettings::masterBrowsersRequireAuth() && !host.login().isEmpty() )
706
arguments << QString( "-U %1%" ).arg( host.login() );
710
// Do *not* change this to "-U guest%". This won't work.
716
// Domain lookup (via xargs)
721
// Protocol & command. Since the domain lookup only works with the RAP
722
// protocol, there is no point in using the 'Automatic' feature.
724
arguments << "domain";
726
// The user's workgroup/domain name
727
if ( !Smb4KSettings::domainName().isEmpty() &&
728
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
730
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
737
// The user's NetBIOS name
738
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
739
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
741
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
749
if ( Smb4KSettings::machineAccount() )
759
if ( options && options->smbPort() != Smb4KSettings::remoteSMBPort() )
761
arguments << QString( "-p %1" ).arg( options->smbPort() );
765
arguments << QString( "-p %1" ).arg( Smb4KSettings::remoteSMBPort() );
768
// User name and password if needed
769
if ( Smb4KSettings::masterBrowsersRequireAuth() && !host.login().isEmpty() )
771
arguments << QString( "-U %1%" ).arg( host.login() );
775
// Do *not* change this to "-U guest%". This won't work.
779
// IP address (discovered by by previous net command)
780
arguments << "-I ip";
782
// Server name if available
783
if ( !m_master_browser.isEmpty() )
785
arguments << QString( "-S %1" ).arg( KShell::quoteArg( m_master_browser ) );
792
// Add debug level to get the IP of the master browser that we
793
// are connecting to.
796
m_proc = new Smb4KProcess( this );
797
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
798
m_proc->setShellCommand( arguments.join( " " ) );
800
if ( Smb4KSettings::masterBrowsersRequireAuth() && !host.password().isEmpty() )
802
m_proc->setEnv( "PASSWD", host.password(), true );
806
m_proc->unsetEnv( "PASSWD" );
809
connect( m_proc, SIGNAL( readyReadStandardError() ), this, SLOT( slotReadStandardError() ) );
810
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), this, SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
818
void Smb4KQueryMasterJob::slotReadStandardError()
820
// Read from stderr and decide what to do.
821
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 ).trimmed();
823
if ( !stderr.isEmpty() )
825
if ( stderr.contains( "The username or password was not correct." ) ||
826
stderr.contains( "NT_STATUS_ACCOUNT_DISABLED" ) /* AD error */ ||
827
stderr.contains( "NT_STATUS_ACCESS_DENIED" ) ||
828
stderr.contains( "NT_STATUS_LOGON_FAILURE" ) )
830
if ( m_master_browser.isEmpty() )
832
// Figure out the current master browser's IP address.
833
QStringList stderr_list = stderr.split( "\n", QString::SkipEmptyParts );
835
foreach ( const QString &line, stderr_list )
837
if ( line.contains( "Connecting to host=" ) )
839
m_master_browser = line.section( "=", 1, 1 ).trimmed();
853
emit authError( this );
857
// Avoid reporting the debug output as error.
858
if ( stderr.contains( "NT_STATUS" ) )
860
Smb4KNotification *notification = new Smb4KNotification();
861
notification->retrievingDomainsFailed( stderr );
865
// Debug output. Do nothing
876
void Smb4KQueryMasterJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
878
switch ( exitStatus )
880
case QProcess::CrashExit:
882
if ( !m_proc->isAborted() )
884
Smb4KNotification *notification = new Smb4KNotification();
885
notification->processError( m_proc->error() );
906
Smb4KScanBAreasJob::Smb4KScanBAreasJob( QObject *parent ) : KJob( parent ),
907
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
912
Smb4KScanBAreasJob::~Smb4KScanBAreasJob()
917
void Smb4KScanBAreasJob::start()
920
QTimer::singleShot( 0, this, SLOT( slotStartScan() ) );
924
void Smb4KScanBAreasJob::setupScan( QWidget *parent )
926
m_parent_widget = parent;
930
bool Smb4KScanBAreasJob::doKill()
932
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
941
return KJob::doKill();
945
void Smb4KScanBAreasJob::processScan()
947
QStringList stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).trimmed().split( "\n", QString::SkipEmptyParts );
949
if ( !stdout.isEmpty() )
951
Smb4KWorkgroup workgroup;
955
foreach ( const QString &line, stdout )
957
// Check if we have to skip this host entry.
958
// A host entry is skipped if the IP address is invalid, i.e.
959
// 0.0.0.0 is returned.
960
if ( line.startsWith( "Looking up status of" ) )
962
QString ip_address = line.section( "of", 1, 1 ).trimmed();
963
skip = (QString::compare( ip_address, "0.0.0.0" ) == 0);
970
// Now process the output if everything is OK. Otherwise
971
// skip lines until there is a valid host entry.
974
if ( line.startsWith( "Looking up status of" ) )
976
// Set the IP address of the host.
977
QString ip_address = line.section( "of", 1, 1 ).trimmed();
979
if ( QString::compare( ip_address, "0.0.0.0" ) != 0 )
981
host.setIP( ip_address );
989
else if ( line.contains( "MAC Address", Qt::CaseSensitive ) )
991
// Check that the workgroup object carries a workgroup
992
// name and a master browser name.
993
if ( !workgroup.workgroupName().isEmpty() && !workgroup.masterBrowserName().isEmpty() )
995
// Check whether the workgroup has already been entered
997
bool workgroup_found = false;
999
for ( int i = 0; i < m_workgroups_list.size(); ++i )
1001
if ( QString::compare( m_workgroups_list.at( i ).workgroupName(), workgroup.workgroupName(), Qt::CaseInsensitive ) == 0 )
1003
workgroup_found = true;
1012
if ( !workgroup_found )
1014
m_workgroups_list << workgroup;
1026
m_hosts_list << host;
1028
workgroup = Smb4KWorkgroup();
1032
else if ( line.contains( " <00> ", Qt::CaseSensitive ) )
1034
// This is the name of the workgroup and/or host. Depending
1035
// on if the <GROUP> label is present, it is either a host name
1036
// or a workgroup name that we process here.
1037
if ( line.contains( " <GROUP> ", Qt::CaseSensitive ) )
1039
workgroup.setWorkgroupName( line.section( "<00>", 0, 0 ).trimmed() );
1040
host.setWorkgroupName( line.section( "<00>", 0, 0 ).trimmed() );
1044
host.setHostName( line.section( "<00>", 0, 0 ).trimmed() );
1048
else if ( line.contains( "__MSBROWSE__", Qt::CaseSensitive ) )
1050
// The __MSBROWSE__ label marks a host that offers a browse list.
1051
// If also the <01> label is present, this is a master browser.
1053
// If the host is not a master browser but offers a browse list,
1054
// we use it temporarily as pseudo master browser for the workgroup
1055
// until the right master browser has been set.
1056
if ( line.contains( " <01> ", Qt::CaseSensitive ) )
1058
workgroup.setMasterBrowserName( host.hostName() );
1059
workgroup.setMasterBrowserIP( host.ip() );
1060
workgroup.setHasPseudoMasterBrowser( false );
1061
host.setIsMasterBrowser( true );
1065
if ( workgroup.masterBrowserName().isEmpty() )
1067
workgroup.setMasterBrowserName( host.hostName() );
1068
workgroup.setMasterBrowserIP( host.ip() );
1069
workgroup.setHasPseudoMasterBrowser( true );
1094
// Emit the list of workgroups and the list of hosts.
1095
emit workgroups( m_workgroups_list );
1096
emit hosts( m_hosts_list );
1100
void Smb4KScanBAreasJob::slotStartScan()
1102
// Find nmblookup program.
1103
QString nmblookup = KStandardDirs::findExe( "nmblookup" );
1105
if ( nmblookup.isEmpty() )
1107
Smb4KNotification *notification = new Smb4KNotification();
1108
notification->commandNotFound( "nmblookup" );
1118
QString awk = KStandardDirs::findExe( "awk" );
1120
if ( awk.isEmpty() )
1122
Smb4KNotification *notification = new Smb4KNotification();
1123
notification->commandNotFound( "awk" );
1133
QString sed = KStandardDirs::findExe( "sed" );
1135
if ( sed.isEmpty() )
1137
Smb4KNotification *notification = new Smb4KNotification();
1138
notification->commandNotFound( "sed" );
1147
// Find xargs program
1148
QString xargs = KStandardDirs::findExe( "xargs" );
1150
if ( xargs.isEmpty() )
1152
Smb4KNotification *notification = new Smb4KNotification();
1153
notification->commandNotFound( "xargs" );
1162
// Global Samba options
1163
QMap<QString,QString> samba_options = globalSambaOptions();
1165
// Broadcast areas/addresses
1167
// FIXME: Emit error message if the list is empty!!!
1168
QStringList addresses = Smb4KSettings::broadcastAreas().split( ",", QString::SkipEmptyParts );
1170
// Assemble the command
1171
QStringList arguments;
1173
for ( int i = 0; i < addresses.size(); ++i )
1175
if ( !arguments.isEmpty() )
1184
arguments << nmblookup;
1187
if ( !Smb4KSettings::domainName().isEmpty() &&
1188
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
1190
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
1198
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
1199
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
1201
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
1209
if ( !Smb4KSettings::netBIOSScope().isEmpty() &&
1210
QString::compare( Smb4KSettings::netBIOSScope(), samba_options["netbios scope"] ) != 0 )
1212
arguments << QString( "-i %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSScope() ) );
1220
if ( !Smb4KSettings::socketOptions().isEmpty() &&
1221
QString::compare( Smb4KSettings::socketOptions(), samba_options["socket options"] ) != 0 )
1223
arguments << QString( "-O %1" ).arg( KShell::quoteArg( Smb4KSettings::socketOptions() ) );
1231
if ( Smb4KSettings::usePort137() )
1240
// We do not want the globally defined broadcast address here, because the
1241
// broadcast address option is needed for the IP scan.
1243
// FIXME: Emit error message if address is not IP4 or IP6!!!
1244
arguments << QString( "-B %1" ).arg( addresses.at( i ) );
1246
arguments << QString( "%1" ).arg( KShell::quoteArg( "*" ) );
1248
arguments << "-e /querying/d";
1251
arguments << QString( "%1" ).arg( KShell::quoteArg( "{print $1}" ) );
1254
arguments << "-Iip";
1255
arguments << nmblookup;
1258
if ( !Smb4KSettings::domainName().isEmpty() &&
1259
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
1261
QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
1269
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
1270
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
1272
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
1280
if ( !Smb4KSettings::netBIOSScope().isEmpty() &&
1281
QString::compare( Smb4KSettings::netBIOSScope(), samba_options["netbios scope"] ) != 0 )
1283
arguments << QString( "-i %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSScope() ) );
1291
if ( !Smb4KSettings::socketOptions().isEmpty() &&
1292
QString::compare( Smb4KSettings::socketOptions(), samba_options["socket options"] ) != 0 )
1294
arguments << QString( "-O %1" ).arg( KShell::quoteArg( Smb4KSettings::socketOptions() ) );
1302
if ( Smb4KSettings::usePort137() )
1311
// Broadcast address
1312
// Note: This time we want to have the global one!
1313
if ( !Smb4KSettings::broadcastAddress().isEmpty() &&
1314
QHostAddress( Smb4KSettings::broadcastAddress() ).protocol() != QAbstractSocket::UnknownNetworkLayerProtocol )
1316
arguments << QString( "-B %1" ).arg( Smb4KSettings::broadcastAddress() );
1323
// Include the WINS server:
1324
if ( !winsServer().isEmpty() )
1327
arguments << QString( "-U %1" ).arg( winsServer() );
1334
arguments << "-A ip";
1337
m_proc = new Smb4KProcess( this );
1338
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
1339
m_proc->setShellCommand( arguments.join( " " ) );
1341
connect( m_proc, SIGNAL( readyReadStandardError() ), SLOT( slotReadStandardError() ) );
1342
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
1344
emit aboutToStart();
1350
void Smb4KScanBAreasJob::slotReadStandardError()
1352
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 ).trimmed();
1354
if ( !stderr.isEmpty() )
1356
Smb4KNotification *notification = new Smb4KNotification();
1357
notification->scanningBroadcastAreaFailed( stderr );
1366
void Smb4KScanBAreasJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
1368
switch ( exitStatus )
1370
case QProcess::CrashExit:
1372
if ( !m_proc->isAborted() )
1374
Smb4KNotification *notification = new Smb4KNotification();
1375
notification->processError( m_proc->error() );
1396
Smb4KLookupDomainMembersJob::Smb4KLookupDomainMembersJob( QObject *parent ) : KJob( parent ),
1397
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
1402
Smb4KLookupDomainMembersJob::~Smb4KLookupDomainMembersJob()
1407
void Smb4KLookupDomainMembersJob::start()
1410
QTimer::singleShot( 0, this, SLOT( slotStartLookup() ) );
1414
void Smb4KLookupDomainMembersJob::setupLookup( Smb4KWorkgroup *workgroup, QWidget *parent )
1416
Q_ASSERT( workgroup );
1417
m_workgroup = *workgroup;
1418
m_parent_widget = parent;
1422
bool Smb4KLookupDomainMembersJob::doKill()
1424
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
1433
return KJob::doKill();
1437
void Smb4KLookupDomainMembersJob::processHosts()
1439
QStringList stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).split( "\n", QString::SkipEmptyParts );
1441
if ( !stdout.isEmpty() )
1445
foreach ( const QString &line, stdout )
1447
if ( line.trimmed().startsWith( "Enumerating" ) )
1451
else if ( line.trimmed().startsWith( "Server name" ) )
1455
else if ( line.trimmed().startsWith( "-------------" ) )
1461
// Omit host names that contain spaces since QUrl cannot handle them.
1462
// And, they are wrong, anyway.
1463
if ( !line.section( " ", 0, 0 ).trimmed().contains( " " ) )
1465
host.setHostName( line.section( " ", 0, 0 ).trimmed() );
1466
host.setWorkgroupName( m_workgroup.workgroupName() );
1467
host.setComment( line.section( " ", 1, -1 ).trimmed() );
1469
if ( QString::compare( host.hostName(), m_workgroup.masterBrowserName() ) == 0 )
1471
host.setLogin( m_master_browser.login() );
1472
host.setPassword( m_master_browser.password() );
1473
host.setIsMasterBrowser( true );
1475
if ( m_workgroup.hasMasterBrowserIP() )
1477
host.setIP( m_workgroup.masterBrowserIP() );
1486
host.setIsMasterBrowser( false );
1489
m_hosts_list << host;
1493
qDebug() << "This host name contains a space. I cannot handle this...";
1506
emit hosts( &m_workgroup, m_hosts_list );
1510
void Smb4KLookupDomainMembersJob::slotStartLookup()
1513
QString net = KStandardDirs::findExe( "net" );
1515
if ( net.isEmpty() )
1517
Smb4KNotification *notification = new Smb4KNotification();
1518
notification->commandNotFound( "net" );
1527
// Get the master browser of the defined workgroup, so that we
1528
// can connect to it.
1529
Smb4KHost *host = findHost( m_workgroup.masterBrowserName(), m_workgroup.workgroupName() );
1533
// Copy host entry to private variable.
1534
m_master_browser = *host;
1536
// If the master browsers need authentication, we read it now.
1537
if ( Smb4KSettings::masterBrowsersRequireAuth() )
1539
Smb4KWalletManager::self()->readAuthInfo( &m_master_browser );
1546
// Global Samba options
1547
QMap<QString,QString> samba_options = globalSambaOptions();
1550
Smb4KCustomOptions *options = Smb4KCustomOptionsManager::self()->findOptions( &m_master_browser );
1552
// Assemble the command.
1553
QStringList arguments;
1558
// Protocol & command. Since the domain member lookup only works with
1559
// the RAP protocol, there is no point in using the 'Automatic' feature.
1561
arguments << "server";
1562
arguments << "domain";
1564
// The user's domain or workgroup
1565
if ( !Smb4KSettings::domainName().isEmpty() &&
1566
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
1568
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
1575
// The NetBIOS name of the user's machine
1576
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
1577
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
1579
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
1587
if ( Smb4KSettings::machineAccount() )
1597
if ( options && options->smbPort() != Smb4KSettings::remoteSMBPort() )
1599
arguments << QString( "-p %1" ).arg( options->smbPort() );
1603
arguments << QString( "-p %1" ).arg( Smb4KSettings::remoteSMBPort() );
1606
// IP address of the master browser
1607
if ( m_workgroup.hasMasterBrowserIP() )
1609
arguments << QString( "-I %1" ).arg( m_workgroup.masterBrowserIP() );
1616
// Workgroup of the remote master browser that is to be
1617
// queried for the workgroup/domain members.
1618
arguments << QString( "-w %1" ).arg( KShell::quoteArg( m_workgroup.workgroupName() ) );
1620
// Name of the remote master browser
1621
arguments << QString( "-S %1" ).arg( KShell::quoteArg( m_workgroup.masterBrowserName() ) );
1623
// Authentication, if needed
1624
if ( Smb4KSettings::masterBrowsersRequireAuth() && !m_master_browser.login().isEmpty() )
1626
arguments << QString( "-U %1" ).arg( m_master_browser.login() );
1630
// Do *not* change this to "-U guest%". This won't work.
1631
arguments << "-U %";
1634
m_proc = new Smb4KProcess( this );
1635
m_proc->setShellCommand( arguments.join( " " ) );
1636
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
1638
if ( Smb4KSettings::self()->masterBrowsersRequireAuth() && !m_master_browser.password().isEmpty() )
1640
m_proc->setEnv( "PASSWD", m_master_browser.password(), true );
1644
m_proc->unsetEnv( "PASSWD" );
1647
connect( m_proc, SIGNAL( readyReadStandardError() ), SLOT( slotReadStandardError() ) );
1648
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
1650
emit aboutToStart( &m_workgroup );
1656
// The master browser could not be determined. End the
1657
// job here and emit an empty hosts list.
1658
emit hosts( &m_workgroup, m_hosts_list );
1664
void Smb4KLookupDomainMembersJob::slotReadStandardError()
1666
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 ).trimmed();
1668
if ( !stderr.isEmpty() )
1670
if ( stderr.contains( "The username or password was not correct." ) ||
1671
stderr.contains( "NT_STATUS_ACCOUNT_DISABLED" ) /* AD error */ ||
1672
stderr.contains( "NT_STATUS_ACCESS_DENIED" ) ||
1673
stderr.contains( "NT_STATUS_LOGON_FAILURE" ) )
1675
emit authError( this );
1677
else if ( stderr.contains( "tdb_transaction_recover:" ) )
1679
// Suppress debug output/information sent to stderr
1684
// Notify the user that an error occurred.
1685
Smb4KNotification *notification = new Smb4KNotification();
1686
notification->retrievingServersFailed( &m_workgroup, stderr );
1696
void Smb4KLookupDomainMembersJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
1698
switch ( exitStatus )
1700
case QProcess::CrashExit:
1702
if ( !m_proc->isAborted() )
1704
Smb4KNotification *notification = new Smb4KNotification();
1705
notification->processError( m_proc->error() );
1721
emit finished( &m_workgroup );
1726
Smb4KLookupSharesJob::Smb4KLookupSharesJob( QObject *parent ) : KJob( parent ),
1727
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
1732
Smb4KLookupSharesJob::~Smb4KLookupSharesJob()
1737
void Smb4KLookupSharesJob::start()
1740
QTimer::singleShot( 0, this, SLOT( slotStartLookup() ) );
1744
void Smb4KLookupSharesJob::setupLookup( Smb4KHost *host, QWidget *parent )
1748
m_parent_widget = parent;
1752
bool Smb4KLookupSharesJob::doKill()
1754
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
1763
return KJob::doKill();
1767
void Smb4KLookupSharesJob::processShares()
1769
// Additional authentication error handling.
1770
if ( m_proc->exitCode() == 104 /* access denied in W2k3 domain */ ||
1771
m_proc->exitCode() == 235 /* wrong password in W2k3 domain */ )
1773
emit authError( this );
1774
// We can just return here, because this function is invoked
1775
// in slotProcessFinished() and emitResult() will be emitted
1784
QStringList stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).split( "\n", QString::SkipEmptyParts );
1786
if ( !stdout.isEmpty() )
1790
foreach ( const QString &line, stdout )
1792
if ( line.trimmed().startsWith( "Enumerating" ) )
1796
else if ( line.trimmed().startsWith( "Share name" ) )
1800
else if ( line.trimmed().startsWith( "----------" ) )
1804
else if ( line.contains( " Disk ", Qt::CaseSensitive ) /* line has comment */ ||
1805
(!line.contains( " Disk ", Qt::CaseSensitive ) &&
1806
line.trimmed().endsWith( " Disk", Qt::CaseSensitive ) /* line has no comment */) )
1808
if ( !line.trimmed().endsWith( " Disk", Qt::CaseSensitive ) )
1810
share.setShareName( line.section( " Disk ", 0, 0 ).trimmed() );
1811
share.setComment( line.section( " Disk ", 1, 1 ).trimmed() );
1815
share.setShareName( line.section( " Disk", 0, 0 ).trimmed() );
1816
share.setComment( "" );
1819
share.setHostName( m_host.hostName() );
1820
share.setWorkgroupName( m_host.workgroupName() );
1821
share.setTypeString( "Disk" );
1822
share.setLogin( m_host.login() );
1823
share.setPassword( m_host.password() );
1825
if ( m_host.hasIP() )
1827
share.setHostIP( m_host.ip() );
1834
m_shares_list << share;
1835
share = Smb4KShare();
1838
else if ( line.contains( " IPC ", Qt::CaseSensitive ) /* line has comment */ ||
1839
(!line.contains( " IPC ", Qt::CaseSensitive ) &&
1840
line.trimmed().endsWith( " IPC", Qt::CaseSensitive ) /* line has no comment */) )
1842
if ( !line.trimmed().endsWith( " IPC", Qt::CaseSensitive ) )
1844
share.setShareName( line.section( " IPC ", 0, 0 ).trimmed() );
1845
share.setComment( line.section( " IPC ", 1, 1 ).trimmed() );
1849
share.setShareName( line.section( " IPC", 0, 0 ).trimmed() );
1850
share.setComment( "" );
1853
share.setHostName( m_host.hostName() );
1854
share.setWorkgroupName( m_host.workgroupName() );
1855
share.setTypeString( "IPC" );
1856
share.setLogin( m_host.login() );
1857
share.setPassword( m_host.password() );
1859
if ( m_host.hasIP() )
1861
share.setHostIP( m_host.ip() );
1868
m_shares_list << share;
1869
share = Smb4KShare();
1872
else if ( line.contains( " Print ", Qt::CaseSensitive ) /* line has comment */ ||
1873
(!line.contains( " Print ", Qt::CaseSensitive ) &&
1874
line.trimmed().endsWith( " Print", Qt::CaseSensitive ) /* line has no comment */) )
1876
if ( !line.trimmed().endsWith( " Print", Qt::CaseSensitive ) )
1878
share.setShareName( line.section( " Print ", 0, 0 ).trimmed() );
1879
share.setComment( line.section( " Print ", 1, 1 ).trimmed() );
1883
share.setShareName( line.section( " Print", 0, 0 ).trimmed() );
1884
share.setComment( "" );
1887
share.setHostName( m_host.hostName() );
1888
share.setWorkgroupName( m_host.workgroupName() );
1889
share.setTypeString( "Printer" );
1890
share.setLogin( m_host.login() );
1891
share.setPassword( m_host.password() );
1893
if ( m_host.hasIP() )
1895
share.setHostIP( m_host.ip() );
1902
m_shares_list << share;
1903
share = Smb4KShare();
1917
emit shares( &m_host, m_shares_list );
1921
void Smb4KLookupSharesJob::slotStartLookup()
1924
QString net = KStandardDirs::findExe( "net" );
1926
if ( net.isEmpty() )
1928
Smb4KNotification *notification = new Smb4KNotification();
1929
notification->commandNotFound( "net" );
1938
// Authentication information.
1939
Smb4KWalletManager::self()->readAuthInfo( &m_host );
1941
// Global Samba and custom options
1942
QMap<QString,QString> samba_options = globalSambaOptions();
1943
Smb4KCustomOptions *options = Smb4KCustomOptionsManager::self()->findOptions( &m_host );
1945
// Assemble the command.
1946
QStringList arguments;
1951
// Protocol hint & command.
1952
if ( options && options->protocolHint() != Smb4KCustomOptions::UndefinedProtocolHint )
1954
switch ( options->protocolHint() )
1956
case Smb4KCustomOptions::RAP:
1959
arguments << "share";
1964
// Since version 1.0.0 we use the RPC protocol as a default
1965
// when querying a server for its shares (ignoring the 'Automatic
1966
// detection' choice of the user. Because this way we can avoid
1967
// the 'Invalid command: net rap share list' error, that occurred
1968
// under certain circumstances in earlier versions.
1970
arguments << "share";
1971
arguments << "list";
1978
switch ( Smb4KSettings::protocolHint() )
1980
case Smb4KSettings::EnumProtocolHint::RAP:
1983
arguments << "share";
1988
// Since version 1.0.0 we use the RPC protocol as a default
1989
// when querying a server for its shares (ignoring the 'Automatic
1990
// detection' choice of the user. Because this way we can avoid
1991
// the 'Invalid command: net rap share list' error, that occurred
1992
// under certain circumstances in earlier versions.
1994
arguments << "share";
1995
arguments << "list";
2001
// Long output. We need this, because we want to know the type and
2002
// the comment, too.
2005
// The user's domain or workgroup
2006
if ( !Smb4KSettings::domainName().isEmpty() &&
2007
QString::compare( Smb4KSettings::domainName(), samba_options["workgroup"] ) != 0 )
2009
arguments << QString( "-W %1" ).arg( KShell::quoteArg( Smb4KSettings::domainName() ) );
2016
// The user's NetBIOS name
2017
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
2018
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
2020
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
2028
if ( Smb4KSettings::machineAccount() )
2038
// If a port was defined for the host via Smb4KHost::port(), it will
2039
// overwrite the other options.
2040
if ( m_host.port() != -1 )
2042
arguments << QString( "-p %1" ).arg( m_host.port() );
2046
if ( options && options->smbPort() != Smb4KSettings::remoteSMBPort() )
2048
arguments << QString( "-p %1" ).arg( options->smbPort() );
2052
arguments << QString( "-p %1" ).arg( Smb4KSettings::remoteSMBPort() );
2056
// Remote domain/workgroup name
2057
arguments << QString( "-w %1" ).arg( KShell::quoteArg( m_host.workgroupName() ) );
2060
arguments << QString( "-S %1" ).arg( KShell::quoteArg( m_host.hostName() ) );
2063
if ( m_host.hasIP() )
2065
arguments << QString( "-I %1" ).arg( m_host.ip() );
2072
// Authentication data
2073
if ( !m_host.login().isEmpty() && !m_host.login().isEmpty() )
2075
arguments << QString( "-U %1" ).arg( m_host.login() );
2079
// Under some circumstances you need under Windows the 'guest'
2080
// account to be able to retrieve the list of shared resources.
2081
arguments << "-U guest%";
2085
m_proc = new Smb4KProcess( this );
2086
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
2087
m_proc->setShellCommand( arguments.join( " " ) );
2089
if ( !m_host.password().isEmpty() )
2091
m_proc->setEnv( "PASSWD", m_host.password(), true );
2095
m_proc->unsetEnv( "PASSWD" );
2098
connect( m_proc, SIGNAL( readyReadStandardError() ), this, SLOT( slotReadStandardError() ) );
2099
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), this, SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
2101
emit aboutToStart( &m_host );
2107
void Smb4KLookupSharesJob::slotReadStandardError()
2109
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 ).trimmed();
2111
if ( !stderr.isEmpty() )
2113
if ( stderr.contains( "The username or password was not correct." ) ||
2114
stderr.contains( "NT_STATUS_ACCOUNT_DISABLED" ) /* AD error */ ||
2115
stderr.contains( "NT_STATUS_ACCESS_DENIED" ) ||
2116
stderr.contains( "NT_STATUS_LOGON_FAILURE" ) )
2118
emit authError( this );
2120
else if ( stderr.contains( "could not obtain sid for domain", Qt::CaseSensitive ) )
2123
qDebug() << "FIXME: Wrong protocol used for host " << m_host.hostName();
2127
if ( !stderr.contains( "creating lame", Qt::CaseSensitive ) )
2129
Smb4KNotification *notification = new Smb4KNotification();
2130
notification->retrievingSharesFailed( &m_host, stderr );
2145
void Smb4KLookupSharesJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
2147
switch ( exitStatus )
2149
case QProcess::CrashExit:
2151
if ( !m_proc->isAborted() )
2153
Smb4KNotification *notification = new Smb4KNotification();
2154
notification->processError( m_proc->error() );
2170
emit finished( &m_host );
2175
Smb4KLookupInfoJob::Smb4KLookupInfoJob( QObject *parent ) : KJob( parent ),
2176
m_started( false ), m_parent_widget( NULL ), m_proc( NULL )
2181
Smb4KLookupInfoJob::~Smb4KLookupInfoJob()
2186
void Smb4KLookupInfoJob::start()
2189
QTimer::singleShot( 0, this, SLOT( slotStartLookup() ) );
2193
void Smb4KLookupInfoJob::setupLookup( Smb4KHost *host, QWidget* parent )
2197
m_parent_widget = parent;
2201
bool Smb4KLookupInfoJob::doKill()
2203
if ( m_proc && (m_proc->state() == KProcess::Running || m_proc->state() == KProcess::Starting) )
2212
return KJob::doKill();
2216
void Smb4KLookupInfoJob::processInfo()
2218
// First evaluate stdout and if we cannot find the appropriate
2219
// information also evaluate stderr.
2220
QString stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 );
2222
if ( stdout.contains( "OS=" ) || stdout.contains( "Server=" ) )
2224
QStringList stdout_list = stdout.split( "\n", QString::SkipEmptyParts );
2226
foreach ( const QString &line, stdout_list )
2228
if ( line.contains( "OS=" ) || line.contains( "Server=" ) )
2230
QString server = line.section( "Server=[", 1, 1 ).section( "]", 0, 0 ).trimmed();
2231
QString os = line.section( "OS=[", 1, 1 ).section( "]", 0, 0 ).trimmed();
2232
m_host.setInfo( server, os );
2233
emit info( &m_host );
2244
QString stderr = QString::fromUtf8( m_proc->readAllStandardError(), -1 );
2246
if ( stderr.contains( "OS=" ) || stderr.contains( "Server=" ) )
2248
QStringList stderr_list = stderr.split( "\n", QString::SkipEmptyParts );
2250
foreach ( const QString &line, stderr_list )
2252
if ( line.contains( "OS=" ) || line.contains( "Server=" ) )
2254
QString server = line.section( "Server=[", 1, 1 ).section( "]", 0, 0 ).trimmed();
2255
QString os = line.section( "OS=[", 1, 1 ).section( "]", 0, 0 ).trimmed();
2256
m_host.setInfo( server, os );
2257
emit info( &m_host );
2270
void Smb4KLookupInfoJob::slotStartLookup()
2272
// Find the smbclient program
2273
QString smbclient = KStandardDirs::findExe( "smbclient" );
2275
if ( smbclient.isEmpty() )
2277
Smb4KNotification *notification = new Smb4KNotification();
2278
notification->commandNotFound( "smbclient" );
2287
// Compile the command.
2288
QStringList arguments;
2289
arguments << smbclient;
2292
arguments << QString( "-W %1" ).arg( KShell::quoteArg( m_host.workgroupName() ) );
2293
arguments << QString( "-L %1" ).arg( KShell::quoteArg( m_host.hostName() ) );
2295
if ( m_host.hasIP() )
2297
arguments << QString( "-I %1" ).arg( m_host.ip() );
2305
if ( Smb4KSettings::machineAccount() )
2315
switch ( Smb4KSettings::signingState() )
2317
case Smb4KSettings::EnumSigningState::None:
2321
case Smb4KSettings::EnumSigningState::On:
2323
arguments << "-S on";
2326
case Smb4KSettings::EnumSigningState::Off:
2328
arguments << "-S off";
2331
case Smb4KSettings::EnumSigningState::Required:
2333
arguments << "-S required";
2343
if ( Smb4KSettings::bufferSize() != 65520 )
2345
arguments << QString( "-b %1" ).arg( Smb4KSettings::bufferSize() );
2352
// Get global Samba and custom options
2353
QMap<QString,QString> samba_options = globalSambaOptions();
2354
Smb4KCustomOptions *options = Smb4KCustomOptionsManager::self()->findOptions( &m_host );
2357
// If a port was defined for the host via Smb4KHost::port(), it will
2358
// overwrite the other options.
2359
if ( m_host.port() != -1 )
2361
arguments << QString( "-p %1" ).arg( m_host.port() );
2365
if ( options && options->smbPort() != Smb4KSettings::remoteSMBPort() )
2367
arguments << QString( "-p %1" ).arg( options->smbPort() );
2371
arguments << QString( "-p %1" ).arg( Smb4KSettings::remoteSMBPort() );
2378
switch ( options->useKerberos() )
2380
case Smb4KCustomOptions::UseKerberos:
2385
case Smb4KCustomOptions::NoKerberos:
2390
case Smb4KCustomOptions::UndefinedKerberos:
2392
if ( Smb4KSettings::useKerberos() )
2410
if ( Smb4KSettings::useKerberos() )
2421
if ( !Smb4KSettings::nameResolveOrder().isEmpty() &&
2422
QString::compare( Smb4KSettings::nameResolveOrder(), samba_options["name resolve order"] ) != 0 )
2424
arguments << QString( "-R %1" ).arg( KShell::quoteArg( Smb4KSettings::nameResolveOrder() ) );
2432
if ( !Smb4KSettings::netBIOSName().isEmpty() &&
2433
QString::compare( Smb4KSettings::netBIOSName(), samba_options["netbios name"] ) != 0 )
2435
arguments << QString( "-n %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
2443
if ( !Smb4KSettings::netBIOSScope().isEmpty() &&
2444
QString::compare( Smb4KSettings::netBIOSScope(), samba_options["netbios scope"] ) != 0 )
2446
arguments << QString( "-i %1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSScope() ) );
2454
if ( !Smb4KSettings::socketOptions().isEmpty() &&
2455
QString::compare( Smb4KSettings::socketOptions(), samba_options["socket options"] ) != 0 )
2457
arguments << QString( "-O %1" ).arg( KShell::quoteArg( Smb4KSettings::socketOptions() ) );
2464
// Use Winbind CCache
2465
if ( Smb4KSettings::useWinbindCCache() )
2475
if ( Smb4KSettings::encryptSMBTransport() )
2484
m_proc = new Smb4KProcess( this );
2485
m_proc->setOutputChannelMode( KProcess::SeparateChannels );
2486
m_proc->setShellCommand( arguments.join( " " ) );
2488
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), this, SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
2490
emit aboutToStart( &m_host );
2496
void Smb4KLookupInfoJob::slotProcessFinished( int /*exitCode*/, QProcess::ExitStatus exitStatus )
2498
switch ( exitStatus )
2500
case QProcess::CrashExit:
2502
if ( !m_proc->isAborted() )
2504
Smb4KNotification *notification = new Smb4KNotification();
2505
notification->processError( m_proc->error() );
2521
emit finished( &m_host );
30
2527
Smb4KScannerPrivate::Smb4KScannerPrivate()