summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
Unidiff
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index b998e95..a5e20b2 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -28,116 +28,116 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <time.h> 29#include <time.h>
30 30
31#ifndef Q_OS_MACX 31#ifndef Q_OS_MACX
32#include <shadow.h> 32#include <shadow.h>
33#include <crypt.h> 33#include <crypt.h>
34#endif /* Q_OS_MACX */ 34#endif /* Q_OS_MACX */
35 35
36#else 36#else
37#include <stdlib.h> 37#include <stdlib.h>
38#include <time.h> 38#include <time.h>
39#endif 39#endif
40 40
41 41
42#if defined(_OS_LINUX_) 42#if defined(_OS_LINUX_)
43#include <shadow.h> 43#include <shadow.h>
44#endif 44#endif
45 45
46#include <qtextstream.h> 46#include <qtextstream.h>
47#include <qmessagebox.h> 47#include <qmessagebox.h>
48//#include <qtopia/qcopchannel_qws.h> 48//#include <qtopia/qcopchannel_qws.h>
49#include <qtopia/process.h> 49#include <qtopia/process.h>
50#include <qtopia/private/contact.h> 50#include <qtopia/private/contact.h>
51#include <qtopia/version.h> 51#include <qtopia/version.h>
52#ifdef Q_WS_QWS 52#ifdef Q_WS_QWS
53#include <qtopia/qcopenvelope_qws.h> 53#include <qtopia/qcopenvelope_qws.h>
54#endif 54#endif
55 55
56 56
57#include "transferserver.h" 57#include "transferserver.h"
58#include <qtopia/qprocess.h> 58#include <qtopia/qprocess.h>
59 59
60const int block_size = 51200; 60const int block_size = 51200;
61 61
62TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 62TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
63 const char* name) 63 const char* name)
64 : QServerSocket( port, 1, parent, name ) 64 : QServerSocket( port, 1, parent, name )
65{ 65{
66 connections.setAutoDelete( TRUE ); 66 connections.setAutoDelete( TRUE );
67 if ( !ok() ) 67 if ( !ok() )
68 qWarning( "Failed to bind to port %d", port ); 68 qWarning( "Failed to bind to port %d", port );
69} 69}
70 70
71void TransferServer::authorizeConnections() 71void TransferServer::authorizeConnections()
72{ 72{
73 QListIterator<ServerPI> it(connections); 73 QListIterator<ServerPI> it(connections);
74 while ( it.current() ) { 74 while ( it.current() ) {
75 if ( !it.current()->verifyAuthorised() ) { 75 if ( !it.current()->verifyAuthorised() ) {
76 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 76 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
77 connections.removeRef( it.current() ); 77 connections.removeRef( it.current() );
78 } else 78 } else
79 ++it; 79 ++it;
80 } 80 }
81} 81}
82 82
83void TransferServer::closed(ServerPI *item) 83void TransferServer::closed(ServerPI *item)
84{ 84{
85 connections.removeRef(item); 85 connections.removeRef(item);
86} 86}
87 87
88TransferServer::~TransferServer() 88TransferServer::~TransferServer()
89{ 89{
90} 90}
91 91
92void TransferServer::newConnection( int socket ) 92void TransferServer::newConnection( int socket )
93{ 93{
94 ServerPI *ptr = new ServerPI( socket, this ); 94 ServerPI *ptr = new ServerPI( socket, this );
95 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 95 connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) );
96 connections.append( ptr ); 96 connections.append( ptr );
97} 97}
98 98
99QString SyncAuthentication::serverId() 99QString SyncAuthentication::serverId()
100{ 100{
101 Config cfg("Security"); 101 Config cfg("Security");
102 cfg.setGroup("Sync"); 102 cfg.setGroup("Sync");
103 QString r = cfg.readEntry("serverid"); 103 QString r = cfg.readEntry("serverid");
104 104
105 if ( r.isEmpty() ) { 105 if ( r.isEmpty() ) {
106 r = OGlobal::generateUuid(); 106 r = OGlobal::generateUuid();
107 cfg.writeEntry("serverid", r ); 107 cfg.writeEntry("serverid", r );
108 } 108 }
109 return r; 109 return r;
110} 110}
111 111
112QString SyncAuthentication::ownerName() 112QString SyncAuthentication::ownerName()
113{ 113{
114 QString vfilename = Global::applicationFileName("addressbook", 114 QString vfilename = Global::applicationFileName("addressbook",
115 "businesscard.vcf"); 115 "businesscard.vcf");
116 if (QFile::exists(vfilename)) { 116 if (QFile::exists(vfilename)) {
117 Contact c; 117 Contact c;
118 c = Contact::readVCard( vfilename )[0]; 118 c = Contact::readVCard( vfilename )[0];
119 return c.fullName(); 119 return c.fullName();
120 } 120 }
121 121
122 return QString::null; 122 return QString::null;
123} 123}
124 124
125QString SyncAuthentication::loginName() 125QString SyncAuthentication::loginName()
126{ 126{
127 struct passwd *pw = 0L; 127 struct passwd *pw = 0L;
128#ifndef Q_OS_WIN32 128#ifndef Q_OS_WIN32
129 pw = getpwuid( geteuid() ); 129 pw = getpwuid( geteuid() );
130 return QString::fromLocal8Bit( pw->pw_name ); 130 return QString::fromLocal8Bit( pw->pw_name );
131#else 131#else
132 //### revise 132 //### revise
133 return QString(); 133 return QString();
134#endif 134#endif
135} 135}
136 136
137int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 137int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
138{ 138{
139 Config cfg("Security"); 139 Config cfg("Security");
140 cfg.setGroup("Sync"); 140 cfg.setGroup("Sync");
141 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 141 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
142 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 142 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
143 143
@@ -288,109 +288,109 @@ bool SyncAuthentication::checkPassword( const QString& password )
288#else 288#else
289 //### revise 289 //### revise
290 QString cpassword(""); 290 QString cpassword("");
291#endif 291#endif
292 denials=0; 292 denials=0;
293 pwds.prepend(cpassword); 293 pwds.prepend(cpassword);
294 cfg.writeEntry("Passwords",pwds,' '); 294 cfg.writeEntry("Passwords",pwds,' ');
295 lock--; 295 lock--;
296 return TRUE; 296 return TRUE;
297 } 297 }
298 } 298 }
299 lock--; 299 lock--;
300 300
301 return FALSE; 301 return FALSE;
302} 302}
303 303
304 304
305ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 305ServerPI::ServerPI( int socket, QObject *parent, const char* name )
306 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 306 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
307 storFileSize(-1) 307 storFileSize(-1)
308{ 308{
309 state = Connected; 309 state = Connected;
310 310
311 setSocket( socket ); 311 setSocket( socket );
312 312
313 peerport = peerPort(); 313 peerport = peerPort();
314 peeraddress = peerAddress(); 314 peeraddress = peerAddress();
315 315
316#ifndef INSECURE 316#ifndef INSECURE
317 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 317 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
318 state = Forbidden; 318 state = Forbidden;
319 startTimer( 0 ); 319 startTimer( 0 );
320 } else 320 } else
321#endif 321#endif
322 { 322 {
323 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 323 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
324 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 324 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
325 325
326 passiv = FALSE; 326 passiv = FALSE;
327 for( int i = 0; i < 4; i++ ) 327 for( int i = 0; i < 4; i++ )
328 wait[i] = FALSE; 328 wait[i] = FALSE;
329 329
330 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 330 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
331 state = Wait_USER; 331 state = Wait_USER;
332 332
333 dtp = new ServerDTP( this ); 333 dtp = new ServerDTP( this );
334 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 334 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
335 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 335 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
336 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 336 connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) );
337 337
338 338
339 directory = QDir::currentDirPath(); 339 directory = QDir::currentDirPath();
340 340
341 static int p = 1024; 341 static int p = 1024;
342 342
343 while ( !serversocket || !serversocket->ok() ) { 343 while ( !serversocket || !serversocket->ok() ) {
344 delete serversocket; 344 delete serversocket;
345 serversocket = new ServerSocket( ++p, this ); 345 serversocket = new ServerSocket( ++p, this );
346 } 346 }
347 connect( serversocket, SIGNAL( newIncomming( int ) ), 347 connect( serversocket, SIGNAL( newIncomming(int) ),
348 SLOT( newConnection( int ) ) ); 348 SLOT( newConnection(int) ) );
349 } 349 }
350} 350}
351 351
352ServerPI::~ServerPI() 352ServerPI::~ServerPI()
353{ 353{
354 close(); 354 close();
355 355
356 if ( dtp ) 356 if ( dtp )
357 dtp->close(); 357 dtp->close();
358 delete dtp; 358 delete dtp;
359 delete serversocket; 359 delete serversocket;
360} 360}
361 361
362bool ServerPI::verifyAuthorised() 362bool ServerPI::verifyAuthorised()
363{ 363{
364 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 364 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
365 state = Forbidden; 365 state = Forbidden;
366 return FALSE; 366 return FALSE;
367 } 367 }
368 return TRUE; 368 return TRUE;
369} 369}
370 370
371void ServerPI::connectionClosed() 371void ServerPI::connectionClosed()
372{ 372{
373 // qDebug( "Debug: Connection closed" ); 373 // qDebug( "Debug: Connection closed" );
374 emit connectionClosed(this); 374 emit connectionClosed(this);
375} 375}
376 376
377void ServerPI::send( const QString& msg ) 377void ServerPI::send( const QString& msg )
378{ 378{
379 QTextStream os( this ); 379 QTextStream os( this );
380 os << msg << endl; 380 os << msg << endl;
381 //qDebug( "Reply: %s", msg.latin1() ); 381 //qDebug( "Reply: %s", msg.latin1() );
382} 382}
383 383
384void ServerPI::read() 384void ServerPI::read()
385{ 385{
386 while ( canReadLine() ) 386 while ( canReadLine() )
387 process( readLine().stripWhiteSpace() ); 387 process( readLine().stripWhiteSpace() );
388} 388}
389 389
390bool ServerPI::checkReadFile( const QString& file ) 390bool ServerPI::checkReadFile( const QString& file )
391{ 391{
392 QString filename; 392 QString filename;
393 393
394 if ( file[0] != "/" ) 394 if ( file[0] != "/" )
395 filename = directory.path() + "/" + file; 395 filename = directory.path() + "/" + file;
396 else 396 else
@@ -1041,97 +1041,97 @@ void ServerPI::newConnection( int socket )
1041 qDebug("check retrieve file"); 1041 qDebug("check retrieve file");
1042 if ( backupRestoreGzip( waitfile ) ) 1042 if ( backupRestoreGzip( waitfile ) )
1043 dtp->retrieveGzipFile( waitfile ); 1043 dtp->retrieveGzipFile( waitfile );
1044 else 1044 else
1045 dtp->retrieveFile( waitfile, storFileSize ); 1045 dtp->retrieveFile( waitfile, storFileSize );
1046 dtp->setSocket( socket ); 1046 dtp->setSocket( socket );
1047 } 1047 }
1048 else if ( wait[SendByteArray] ) { 1048 else if ( wait[SendByteArray] ) {
1049 dtp->sendByteArray( waitarray ); 1049 dtp->sendByteArray( waitarray );
1050 dtp->setSocket( socket ); 1050 dtp->setSocket( socket );
1051 } 1051 }
1052 else if ( wait[RetrieveByteArray] ) { 1052 else if ( wait[RetrieveByteArray] ) {
1053 qDebug("retrieve byte array"); 1053 qDebug("retrieve byte array");
1054 dtp->retrieveByteArray(); 1054 dtp->retrieveByteArray();
1055 dtp->setSocket( socket ); 1055 dtp->setSocket( socket );
1056 } 1056 }
1057 else 1057 else
1058 waitsocket = socket; 1058 waitsocket = socket;
1059 1059
1060 for( int i = 0; i < 4; i++ ) 1060 for( int i = 0; i < 4; i++ )
1061 wait[i] = FALSE; 1061 wait[i] = FALSE;
1062} 1062}
1063 1063
1064QString ServerPI::absFilePath( const QString& file ) 1064QString ServerPI::absFilePath( const QString& file )
1065{ 1065{
1066 if ( file.isEmpty() ) return file; 1066 if ( file.isEmpty() ) return file;
1067 1067
1068 QString filepath( file ); 1068 QString filepath( file );
1069 if ( file[0] != "/" ) 1069 if ( file[0] != "/" )
1070 filepath = directory.path() + "/" + file; 1070 filepath = directory.path() + "/" + file;
1071 1071
1072 return filepath; 1072 return filepath;
1073} 1073}
1074 1074
1075 1075
1076void ServerPI::timerEvent( QTimerEvent * ) 1076void ServerPI::timerEvent( QTimerEvent * )
1077{ 1077{
1078 connectionClosed(); 1078 connectionClosed();
1079} 1079}
1080 1080
1081 1081
1082ServerDTP::ServerDTP( QObject *parent, const char* name) 1082ServerDTP::ServerDTP( QObject *parent, const char* name)
1083 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1083 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1084 retrieveTargzProc( 0 ) 1084 retrieveTargzProc( 0 )
1085{ 1085{
1086 1086
1087 connect( this, SIGNAL( connected() ), SLOT( connected() ) ); 1087 connect( this, SIGNAL( connected() ), SLOT( connected() ) );
1088 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 1088 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
1089 connect( this, SIGNAL( bytesWritten( int ) ), SLOT( bytesWritten( int ) ) ); 1089 connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) );
1090 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1090 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1091 1091
1092 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr 1092 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
1093 createTargzProc->setCommunication( QProcess::Stdout ); 1093 createTargzProc->setCommunication( QProcess::Stdout );
1094 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1094 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1095 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1095 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1096 1096
1097 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); 1097 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1098 retrieveTargzProc->setCommunication( QProcess::Stdin ); 1098 retrieveTargzProc->setCommunication( QProcess::Stdin );
1099 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1099 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1100 connect( retrieveTargzProc, SIGNAL( processExited() ), 1100 connect( retrieveTargzProc, SIGNAL( processExited() ),
1101 SIGNAL( completed() ) ); 1101 SIGNAL( completed() ) );
1102 connect( retrieveTargzProc, SIGNAL( processExited() ), 1102 connect( retrieveTargzProc, SIGNAL( processExited() ),
1103 SLOT( extractTarDone() ) ); 1103 SLOT( extractTarDone() ) );
1104} 1104}
1105 1105
1106ServerDTP::~ServerDTP() 1106ServerDTP::~ServerDTP()
1107{ 1107{
1108 buf.close(); 1108 buf.close();
1109 if ( RetrieveFile == mode && file.isOpen() ) { 1109 if ( RetrieveFile == mode && file.isOpen() ) {
1110 // We're being shutdown before the client closed. 1110 // We're being shutdown before the client closed.
1111 file.close(); 1111 file.close();
1112 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { 1112 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1113 qDebug( "STOR incomplete" ); 1113 qDebug( "STOR incomplete" );
1114 file.remove(); 1114 file.remove();
1115 } 1115 }
1116 } else { 1116 } else {
1117 file.close(); 1117 file.close();
1118 } 1118 }
1119 createTargzProc->kill(); 1119 createTargzProc->kill();
1120} 1120}
1121 1121
1122void ServerDTP::extractTarDone() 1122void ServerDTP::extractTarDone()
1123{ 1123{
1124 qDebug("extract done"); 1124 qDebug("extract done");
1125#ifndef QT_NO_COP 1125#ifndef QT_NO_COP
1126 QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); 1126 QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
1127 e << file.name(); 1127 e << file.name();
1128#endif 1128#endif
1129} 1129}
1130 1130
1131void ServerDTP::connected() 1131void ServerDTP::connected()
1132{ 1132{
1133 // send file mode 1133 // send file mode
1134 switch ( mode ) { 1134 switch ( mode ) {
1135 case SendFile : 1135 case SendFile :
1136 if ( !file.exists() || !file.open( IO_ReadOnly) ) { 1136 if ( !file.exists() || !file.open( IO_ReadOnly) ) {
1137 emit failed(); 1137 emit failed();