summaryrefslogtreecommitdiff
path: root/core
authorzecke <zecke>2003-08-28 14:50:19 (UTC)
committer zecke <zecke>2003-08-28 14:50:19 (UTC)
commit225fa91f6d57f211d53ec686518ca15fc5278d21 (patch) (unidiff)
tree3b7f3bc38693383b45027115efac1176ed5cd1b0 /core
parent704de5567caccd769c693676a55a4af45c85e044 (diff)
downloadopie-225fa91f6d57f211d53ec686518ca15fc5278d21.zip
opie-225fa91f6d57f211d53ec686518ca15fc5278d21.tar.gz
opie-225fa91f6d57f211d53ec686518ca15fc5278d21.tar.bz2
Use old Opie changes
Diffstat (limited to 'core') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp595
1 files changed, 293 insertions, 302 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 0337a94..371400e 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -19,3 +19,8 @@
19**********************************************************************/ 19**********************************************************************/
20#define _XOPEN_SOURCE 20//#define _XOPEN_SOURCE
21
22#include <qtopia/global.h>
23#include <qtopia/qpeapplication.h>
24
25#ifndef Q_OS_WIN32
21#include <pwd.h> 26#include <pwd.h>
@@ -26,15 +31,9 @@
26#include <shadow.h> 31#include <shadow.h>
32#include <crypt.h>
27 33
28/* we need the _OS_LINUX stuff first ! */ 34#else
29#include <qglobal.h> 35#include <stdlib.h>
30 36#include <time.h>
31#ifndef _OS_LINUX_ 37#endif
32
33extern "C"
34{
35#include <uuid/uuid.h>
36#define UUID_H_INCLUDED
37}
38 38
39#endif // not defined linux
40 39
@@ -52,13 +51,17 @@ extern "C"
52#include <qregexp.h> 51#include <qregexp.h>
53//#include <qpe/qcopchannel_qws.h> 52//#include <qtopia/qcopchannel_qws.h>
54#include <qpe/process.h> 53#include <qtopia/process.h>
55#include <qpe/global.h> 54#include <qtopia/global.h>
56#include <qpe/config.h> 55#include <qtopia/config.h>
57#include <qpe/contact.h> 56#include <qtopia/private/contact.h>
58#include <qpe/quuid.h> 57#include <qtopia/quuid.h>
59#include <qpe/version.h> 58#include <qtopia/version.h>
60#include <qpe/qcopenvelope_qws.h> 59#ifdef Q_WS_QWS
60#include <qtopia/qcopenvelope_qws.h>
61#endif
62
63#include "launcherglobal.h"
61 64
62#include "transferserver.h" 65#include "transferserver.h"
63#include <opie/oprocess.h> 66#include <qtopia/qprocess.h>
64 67
@@ -70,2 +73,3 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
70{ 73{
74 connections.setAutoDelete( TRUE );
71 if ( !ok() ) 75 if ( !ok() )
@@ -74,45 +78,28 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
74 78
75TransferServer::~TransferServer() 79void TransferServer::authorizeConnections()
76{ 80{
81 QListIterator<ServerPI> it(connections);
82 while ( it.current() ) {
83 if ( !it.current()->verifyAuthorised() ) {
84 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
85 connections.removeRef( it.current() );
86 } else
87 ++it;
77} 88}
78
79void TransferServer::newConnection( int socket )
80{
81 (void) new ServerPI( socket, this );
82} 89}
83 90
84/* 91void TransferServer::closed(ServerPI *item)
85 * small class in anonymous namespace
86 * to generate a QUUid for us
87 */
88namespace
89{
90struct UidGen
91{ 92{
92 QString uuid(); 93 connections.removeRef(item);
93}; 94}
94#if !defined(_OS_LINUX_)
95 95
96QString UidGen::uuid() 96TransferServer::~TransferServer()
97{ 97{
98 uuid_t uuid;
99 uuid_generate( uuid );
100 return QUUid( uuid ).toString();
101} 98}
102#else
103/*
104* linux got a /proc/sys/kernel/random/uuid file
105* it'll generate the uuids for us
106*/
107QString UidGen::uuid()
108{
109 QFile file( "/proc/sys/kernel/random/uuid" );
110 if (!file.open(IO_ReadOnly ) )
111 return QString::null;
112
113 QTextStream stream(&file);
114 99
115 return "{" + stream.read().stripWhiteSpace() + "}"; 100void TransferServer::newConnection( int socket )
116} 101{
117#endif 102 ServerPI *ptr = new ServerPI( socket, this );
103 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
104 connections.append( ptr );
118} 105}
@@ -124,5 +111,5 @@ QString SyncAuthentication::serverId()
124 QString r = cfg.readEntry("serverid"); 111 QString r = cfg.readEntry("serverid");
112
125 if ( r.isEmpty() ) { 113 if ( r.isEmpty() ) {
126 UidGen gen; 114 r = Opie::Global::uuid();
127 r = gen.uuid();
128 cfg.writeEntry("serverid", r ); 115 cfg.writeEntry("serverid", r );
@@ -142,3 +129,3 @@ QString SyncAuthentication::ownerName()
142 129
143 return ""; 130 return QString::null;
144} 131}
@@ -147,5 +134,10 @@ QString SyncAuthentication::loginName()
147{ 134{
148 struct passwd *pw; 135 struct passwd *pw = 0L;
136#ifndef Q_OS_WIN32
149 pw = getpwuid( geteuid() ); 137 pw = getpwuid( geteuid() );
150 return QString::fromLocal8Bit( pw->pw_name ); 138 return QString::fromLocal8Bit( pw->pw_name );
139#else
140 //### revise
141 return QString();
142#endif
151} 143}
@@ -165,2 +157,3 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
165 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 157 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
158
166 return (peeraddress.ip4Addr() & mask) == auth_peer; 159 return (peeraddress.ip4Addr() & mask) == auth_peer;
@@ -170,4 +163,3 @@ bool SyncAuthentication::checkUser( const QString& user )
170{ 163{
171 if ( user.isEmpty() ) 164 if ( user.isEmpty() ) return FALSE;
172 return FALSE;
173 QString euser = loginName(); 165 QString euser = loginName();
@@ -204,3 +196,4 @@ bool SyncAuthentication::checkPassword( const QString& password )
204 if ( denials < 1 || now > lastdenial + 600 ) { 196 if ( denials < 1 || now > lastdenial + 600 ) {
205 QMessageBox::warning( 0, tr("Sync Connection"), 197 QMessageBox unauth(
198 tr("Sync Connection"),
206 tr("<p>An unauthorized system is requesting access to this device." 199 tr("<p>An unauthorized system is requesting access to this device."
@@ -208,3 +201,8 @@ bool SyncAuthentication::checkPassword( const QString& password )
208 "please upgrade."), 201 "please upgrade."),
209 tr("Deny") ); 202 QMessageBox::Warning,
203 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
204 0, QString::null, TRUE, WStyle_StaysOnTop);
205 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
206 unauth.exec();
207
210 denials++; 208 denials++;
@@ -216,32 +214,59 @@ bool SyncAuthentication::checkPassword( const QString& password )
216 // Second, check sync password... 214 // Second, check sync password...
217 QString pass = password.left(6); 215
218 /* old QtopiaDesktops are sending 216 static int lock=0;
219 * rootme newer versions got a Qtopia 217 if ( lock ) return FALSE;
220 * prefixed. Qtopia prefix will suceed 218
221 * until the sync software syncs up 219 ++lock;
222 * FIXME 220 if ( password.left(6) == "Qtopia" ) {
223 */ 221 Config cfg( QPEApplication::qpeDir()+"/etc/Security.conf", Config::File );
224 if ( pass == "rootme" || pass == "Qtopia") {
225
226 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
227 Config cfg("Security");
228 cfg.setGroup("Sync"); 222 cfg.setGroup("Sync");
229 QString pwds = cfg.readEntry("Passwords"); 223 QStringList pwds = cfg.readListEntry("Passwords",' ');
230 if ( QStringList::split(QChar(' '), pwds).contains(cpassword) ) 224 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
225#ifndef Q_OS_WIN32
226 QString cpassword = QString::fromLocal8Bit(
227 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
228#else
229 // ### revise
230 QString cpassword("");
231#endif
232 if ( *it == cpassword ) {
233 lock--;
231 return TRUE; 234 return TRUE;
235 }
236 }
232 237
233 // Unrecognized system. Be careful... 238 // Unrecognized system. Be careful...
234 239 QMessageBox unrecbox(
235 if ( (denials > 2 && now < lastdenial + 600) 240 tr("Sync Connection"),
236 || QMessageBox::warning(0, tr("Sync Connection"),
237 tr("<p>An unrecognized system is requesting access to this device." 241 tr("<p>An unrecognized system is requesting access to this device."
238 "<p>If you have just initiated a Sync for the first time, this is normal."), 242 "<p>If you have just initiated a Sync for the first time, this is normal."),
239 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) { 243 QMessageBox::Warning,
244 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
245 0, QString::null, TRUE, WStyle_StaysOnTop);
246 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
247 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
248
249 if ( (denials > 2 && now < lastdenial+600)
250 || unrecbox.exec() != QMessageBox::Yes)
251 {
240 denials++; 252 denials++;
241 lastdenial = now; 253 lastdenial = now;
254 lock--;
242 return FALSE; 255 return FALSE;
243 } 256 } else {
244 else { 257 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
258 char salt[2];
259 salt[0]= salty[rand() % (sizeof(salty)-1)];
260 salt[1]= salty[rand() % (sizeof(salty)-1)];
261#ifndef Q_OS_WIN32
262 QString cpassword = QString::fromLocal8Bit(
263 crypt( password.mid(8).local8Bit(), salt ) );
264#else
265 //### revise
266 QString cpassword("");
267#endif
245 denials = 0; 268 denials = 0;
246 cfg.writeEntry("Passwords", pwds + " " + cpassword); 269 pwds.prepend(cpassword);
270 cfg.writeEntry("Passwords",pwds,' ');
271 lock--;
247 return TRUE; 272 return TRUE;
@@ -249,2 +274,3 @@ bool SyncAuthentication::checkPassword( const QString& password )
249 } 274 }
275 lock--;
250 276
@@ -253,4 +279,6 @@ bool SyncAuthentication::checkPassword( const QString& password )
253 279
280
254ServerPI::ServerPI( int socket, QObject *parent , const char* name ) 281ServerPI::ServerPI( int socket, QObject *parent , const char* name )
255 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) 282 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
283 storFileSize(-1)
256{ 284{
@@ -264,3 +292,2 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
264#ifndef INSECURE 292#ifndef INSECURE
265
266 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 293 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
@@ -268,4 +295,3 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
268 startTimer( 0 ); 295 startTimer( 0 );
269 } 296 } else
270 else
271#endif 297#endif
@@ -279,3 +305,3 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
279 305
280 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 306 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
281 state = Wait_USER; 307 state = Wait_USER;
@@ -303,2 +329,15 @@ ServerPI::~ServerPI()
303{ 329{
330 close();
331 dtp->close();
332 delete dtp;
333 delete serversocket;
334}
335
336bool ServerPI::verifyAuthorised()
337{
338 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
339 state = Forbidden;
340 return FALSE;
341 }
342 return TRUE;
304} 343}
@@ -308,3 +347,3 @@ void ServerPI::connectionClosed()
308 // qDebug( "Debug: Connection closed" ); 347 // qDebug( "Debug: Connection closed" );
309 delete this; 348 emit connectionClosed(this);
310} 349}
@@ -360,4 +399,3 @@ void ServerPI::process( const QString& message )
360 QStringList msg = QStringList::split( " ", message ); 399 QStringList msg = QStringList::split( " ", message );
361 if ( msg.isEmpty() ) 400 if ( msg.isEmpty() ) return;
362 return ;
363 401
@@ -385,4 +423,4 @@ void ServerPI::process( const QString& message )
385 if ( cmd == "QUIT" ) { 423 if ( cmd == "QUIT" ) {
386 send( "211 Good bye!" ); 424 send( "211 Good bye!" ); // No tr
387 delete this; 425 close();
388 return ; 426 return ;
@@ -398,6 +436,6 @@ void ServerPI::process( const QString& message )
398 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 436 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
399 send( "530 Please login with USER and PASS" ); 437 send( "530 Please login with USER and PASS" ); // No tr
400 return ; 438 return ;
401 } 439 }
402 send( "331 User name ok, need password" ); 440 send( "331 User name ok, need password" ); // No tr
403 state = Wait_PASS; 441 state = Wait_PASS;
@@ -410,6 +448,6 @@ void ServerPI::process( const QString& message )
410 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 448 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
411 send( "530 Please login with USER and PASS" ); 449 send( "530 Please login with USER and PASS" ); // No tr
412 return ; 450 return ;
413 } 451 }
414 send( "230 User logged in, proceed" ); 452 send( "230 User logged in, proceed" ); // No tr
415 state = Ready; 453 state = Ready;
@@ -420,2 +458,5 @@ void ServerPI::process( const QString& message )
420 458
459 // Only an ALLO sent immediately before STOR is valid.
460 if ( cmd != "STOR" )
461 storFileSize = -1;
421 462
@@ -424,3 +465,3 @@ void ServerPI::process( const QString& message )
424 // even wu-ftp does not support it 465 // even wu-ftp does not support it
425 send( "502 Command not implemented" ); 466 send( "502 Command not implemented" ); // No tr
426 } 467 }
@@ -432,8 +473,8 @@ void ServerPI::process( const QString& message )
432 if ( directory.cd( args, TRUE ) ) 473 if ( directory.cd( args, TRUE ) )
433 send( "250 Requested file action okay, completed" ); 474 send( "250 Requested file action okay, completed" ); // No tr
434 else 475 else
435 send( "550 Requested action not taken" ); 476 send( "550 Requested action not taken" ); // No tr
436 } 477 }
437 else 478 else
438 send( "500 Syntax error, command unrecognized" ); 479 send( "500 Syntax error, command unrecognized" ); // No tr
439 } 480 }
@@ -443,5 +484,5 @@ void ServerPI::process( const QString& message )
443 if ( directory.cdUp() ) 484 if ( directory.cdUp() )
444 send( "250 Requested file action okay, completed" ); 485 send( "250 Requested file action okay, completed" ); // No tr
445 else 486 else
446 send( "550 Requested action not taken" ); 487 send( "550 Requested action not taken" ); // No tr
447 } 488 }
@@ -451,3 +492,3 @@ void ServerPI::process( const QString& message )
451 // even wu-ftp does not support it 492 // even wu-ftp does not support it
452 send( "502 Command not implemented" ); 493 send( "502 Command not implemented" ); // No tr
453 } 494 }
@@ -457,3 +498,3 @@ void ServerPI::process( const QString& message )
457 // even wu-ftp does not support it 498 // even wu-ftp does not support it
458 send( "502 Command not implemented" ); 499 send( "502 Command not implemented" ); // No tr
459 } 500 }
@@ -467,5 +508,5 @@ void ServerPI::process( const QString& message )
467 if ( parsePort( arg ) ) 508 if ( parsePort( arg ) )
468 send( "200 Command okay" ); 509 send( "200 Command okay" ); // No tr
469 else 510 else
470 send( "500 Syntax error, command unrecognized" ); 511 send( "500 Syntax error, command unrecognized" ); // No tr
471 } 512 }
@@ -475,3 +516,3 @@ void ServerPI::process( const QString& message )
475 passiv = TRUE; 516 passiv = TRUE;
476 send( "227 Entering Passive Mode (" 517 send( "227 Entering Passive Mode (" // No tr
477 + address().toString().replace( QRegExp( "\\." ), "," ) + "," 518 + address().toString().replace( QRegExp( "\\." ), "," ) + ","
@@ -484,5 +525,5 @@ void ServerPI::process( const QString& message )
484 if ( arg.upper() == "A" || arg.upper() == "I" ) 525 if ( arg.upper() == "A" || arg.upper() == "I" )
485 send( "200 Command okay" ); 526 send( "200 Command okay" ); // No tr
486 else 527 else
487 send( "504 Command not implemented for that parameter" ); 528 send( "504 Command not implemented for that parameter" ); // No tr
488 } 529 }
@@ -492,5 +533,5 @@ void ServerPI::process( const QString& message )
492 if ( arg.upper() == "F" ) 533 if ( arg.upper() == "F" )
493 send( "200 Command okay" ); 534 send( "200 Command okay" ); // No tr
494 else 535 else
495 send( "504 Command not implemented for that parameter" ); 536 send( "504 Command not implemented for that parameter" ); // No tr
496 } 537 }
@@ -500,5 +541,5 @@ void ServerPI::process( const QString& message )
500 if ( arg.upper() == "S" ) 541 if ( arg.upper() == "S" )
501 send( "200 Command okay" ); 542 send( "200 Command okay" ); // No tr
502 else 543 else
503 send( "504 Command not implemented for that parameter" ); 544 send( "504 Command not implemented for that parameter" ); // No tr
504 } 545 }
@@ -513,3 +554,3 @@ void ServerPI::process( const QString& message )
513 || backupRestoreGzip( absFilePath( args ) ) ) { 554 || backupRestoreGzip( absFilePath( args ) ) ) {
514 send( "150 File status okay" ); 555 send( "150 File status okay" ); // No tr
515 sendFile( absFilePath( args ) ); 556 sendFile( absFilePath( args ) );
@@ -518,3 +559,3 @@ void ServerPI::process( const QString& message )
518 qDebug("550 Requested action not taken"); 559 qDebug("550 Requested action not taken");
519 send( "550 Requested action not taken" ); 560 send( "550 Requested action not taken" ); // No tr
520 } 561 }
@@ -524,3 +565,3 @@ void ServerPI::process( const QString& message )
524 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { 565 if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) {
525 send( "150 File status okay" ); 566 send( "150 File status okay" ); // No tr
526 retrieveFile( absFilePath( args ) ); 567 retrieveFile( absFilePath( args ) );
@@ -528,3 +569,3 @@ void ServerPI::process( const QString& message )
528 else 569 else
529 send( "550 Requested action not taken" ); 570 send( "550 Requested action not taken" ); // No tr
530 571
@@ -532,3 +573,3 @@ void ServerPI::process( const QString& message )
532 else if ( cmd == "STOU" ) { 573 else if ( cmd == "STOU" ) {
533 send( "502 Command not implemented" ); 574 send( "502 Command not implemented" ); // No tr
534 } 575 }
@@ -537,3 +578,3 @@ void ServerPI::process( const QString& message )
537 else if ( cmd == "APPE" ) { 578 else if ( cmd == "APPE" ) {
538 send( "502 Command not implemented" ); 579 send( "502 Command not implemented" ); // No tr
539 } 580 }
@@ -542,3 +583,4 @@ void ServerPI::process( const QString& message )
542 else if ( cmd == "ALLO" ) { 583 else if ( cmd == "ALLO" ) {
543 send( "200 Command okay" ); 584 storFileSize = args.toInt();
585 send( "200 Command okay" ); // No tr
544 } 586 }
@@ -547,3 +589,3 @@ void ServerPI::process( const QString& message )
547 else if ( cmd == "REST" ) { 589 else if ( cmd == "REST" ) {
548 send( "502 Command not implemented" ); 590 send( "502 Command not implemented" ); // No tr
549 } 591 }
@@ -554,3 +596,3 @@ void ServerPI::process( const QString& message )
554 if ( args.isEmpty() ) 596 if ( args.isEmpty() )
555 send( "500 Syntax error, command unrecognized" ); 597 send( "500 Syntax error, command unrecognized" ); // No tr
556 else { 598 else {
@@ -558,3 +600,3 @@ void ServerPI::process( const QString& message )
558 if ( file.exists() ) { 600 if ( file.exists() ) {
559 send( "350 File exists, ready for destination name" ); 601 send( "350 File exists, ready for destination name" ); // No tr
560 renameFrom = absFilePath( args ); 602 renameFrom = absFilePath( args );
@@ -562,3 +604,3 @@ void ServerPI::process( const QString& message )
562 else 604 else
563 send( "550 Requested action not taken" ); 605 send( "550 Requested action not taken" ); // No tr
564 } 606 }
@@ -569,5 +611,5 @@ void ServerPI::process( const QString& message )
569 if ( lastCommand != "RNFR" ) 611 if ( lastCommand != "RNFR" )
570 send( "503 Bad sequence of commands" ); 612 send( "503 Bad sequence of commands" ); // No tr
571 else if ( args.isEmpty() ) 613 else if ( args.isEmpty() )
572 send( "500 Syntax error, command unrecognized" ); 614 send( "500 Syntax error, command unrecognized" ); // No tr
573 else { 615 else {
@@ -575,5 +617,5 @@ void ServerPI::process( const QString& message )
575 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) 617 if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) )
576 send( "250 Requested file action okay, completed." ); 618 send( "250 Requested file action okay, completed." ); // No tr
577 else 619 else
578 send( "550 Requested action not taken" ); 620 send( "550 Requested action not taken" ); // No tr
579 } 621 }
@@ -585,5 +627,5 @@ void ServerPI::process( const QString& message )
585 if ( dtp->dtpMode() != ServerDTP::Idle ) 627 if ( dtp->dtpMode() != ServerDTP::Idle )
586 send( "426 Connection closed; transfer aborted" ); 628 send( "426 Connection closed; transfer aborted" ); // No tr
587 else 629 else
588 send( "226 Closing data connection" ); 630 send( "226 Closing data connection" ); // No tr
589 } 631 }
@@ -593,3 +635,3 @@ void ServerPI::process( const QString& message )
593 if ( args.isEmpty() ) 635 if ( args.isEmpty() )
594 send( "500 Syntax error, command unrecognized" ); 636 send( "500 Syntax error, command unrecognized" ); // No tr
595 else { 637 else {
@@ -597,8 +639,7 @@ void ServerPI::process( const QString& message )
597 if ( file.remove() ) { 639 if ( file.remove() ) {
598 send( "250 Requested file action okay, completed" ); 640 send( "250 Requested file action okay, completed" ); // No tr
599 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 641 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
600 e << file.name(); 642 e << file.name();
601 } 643 } else {
602 else { 644 send( "550 Requested action not taken" ); // No tr
603 send( "550 Requested action not taken" );
604 } 645 }
@@ -610,3 +651,3 @@ void ServerPI::process( const QString& message )
610 if ( args.isEmpty() ) 651 if ( args.isEmpty() )
611 send( "500 Syntax error, command unrecognized" ); 652 send( "500 Syntax error, command unrecognized" ); // No tr
612 else { 653 else {
@@ -614,5 +655,5 @@ void ServerPI::process( const QString& message )
614 if ( dir.rmdir( absFilePath( args ), TRUE ) ) 655 if ( dir.rmdir( absFilePath( args ), TRUE ) )
615 send( "250 Requested file action okay, completed" ); 656 send( "250 Requested file action okay, completed" ); // No tr
616 else 657 else
617 send( "550 Requested action not taken" ); 658 send( "550 Requested action not taken" ); // No tr
618 } 659 }
@@ -624,3 +665,3 @@ void ServerPI::process( const QString& message )
624 qDebug(" Error: no arg"); 665 qDebug(" Error: no arg");
625 send( "500 Syntax error, command unrecognized" ); 666 send( "500 Syntax error, command unrecognized" ); // No tr
626 } 667 }
@@ -629,5 +670,5 @@ void ServerPI::process( const QString& message )
629 if ( dir.mkdir( absFilePath( args ), TRUE ) ) 670 if ( dir.mkdir( absFilePath( args ), TRUE ) )
630 send( "250 Requested file action okay, completed." ); 671 send( "250 Requested file action okay, completed." ); // No tr
631 else 672 else
632 send( "550 Requested action not taken" ); 673 send( "550 Requested action not taken" ); // No tr
633 } 674 }
@@ -643,5 +684,5 @@ void ServerPI::process( const QString& message )
643 if ( sendList( absFilePath( args ) ) ) 684 if ( sendList( absFilePath( args ) ) )
644 send( "150 File status okay" ); 685 send( "150 File status okay" ); // No tr
645 else 686 else
646 send( "500 Syntax error, command unrecognized" ); 687 send( "500 Syntax error, command unrecognized" ); // No tr
647 } 688 }
@@ -654,3 +695,3 @@ void ServerPI::process( const QString& message )
654 if ( !fi.exists() && !gzipfile ) 695 if ( !fi.exists() && !gzipfile )
655 send( "500 Syntax error, command unrecognized" ); 696 send( "500 Syntax error, command unrecognized" ); // No tr
656 else { 697 else {
@@ -669,3 +710,3 @@ void ServerPI::process( const QString& message )
669 int guess = size.toInt() / 5; 710 int guess = size.toInt() / 5;
670 if ( filePath.contains("doc") ) 711 if ( filePath.contains("doc") ) // No tr
671 guess *= 1000; 712 guess *= 1000;
@@ -679,3 +720,3 @@ void ServerPI::process( const QString& message )
679 else if ( cmd == "NLST" ) { 720 else if ( cmd == "NLST" ) {
680 send( "502 Command not implemented" ); 721 send( "502 Command not implemented" ); // No tr
681 } 722 }
@@ -684,3 +725,3 @@ void ServerPI::process( const QString& message )
684 else if ( cmd == "SITE" ) { 725 else if ( cmd == "SITE" ) {
685 send( "502 Command not implemented" ); 726 send( "502 Command not implemented" ); // No tr
686 } 727 }
@@ -689,3 +730,3 @@ void ServerPI::process( const QString& message )
689 else if ( cmd == "SYST" ) { 730 else if ( cmd == "SYST" ) {
690 send( "215 UNIX Type: L8" ); 731 send( "215 UNIX Type: L8" ); // No tr
691 } 732 }
@@ -694,3 +735,3 @@ void ServerPI::process( const QString& message )
694 else if ( cmd == "STAT" ) { 735 else if ( cmd == "STAT" ) {
695 send( "502 Command not implemented" ); 736 send( "502 Command not implemented" ); // No tr
696 } 737 }
@@ -699,3 +740,3 @@ void ServerPI::process( const QString& message )
699 else if ( cmd == "HELP" ) { 740 else if ( cmd == "HELP" ) {
700 send( "502 Command not implemented" ); 741 send( "502 Command not implemented" ); // No tr
701 } 742 }
@@ -704,3 +745,3 @@ void ServerPI::process( const QString& message )
704 else if ( cmd == "NOOP" ) { 745 else if ( cmd == "NOOP" ) {
705 send( "200 Command okay" ); 746 send( "200 Command okay" ); // No tr
706 } 747 }
@@ -709,3 +750,3 @@ void ServerPI::process( const QString& message )
709 else 750 else
710 send( "502 Command not implemented" ); 751 send( "502 Command not implemented" ); // No tr
711 752
@@ -716,3 +757,3 @@ bool ServerPI::backupRestoreGzip( const QString &file )
716{ 757{
717 return (file.find( "backup" ) != -1 && 758 return (file.find( "backup" ) != -1 && // No tr
718 file.findRev( ".tgz" ) == (int)file.length() - 4 ); 759 file.findRev( ".tgz" ) == (int)file.length() - 4 );
@@ -722,3 +763,3 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets )
722{ 763{
723 if ( file.find( "backup" ) != -1 && 764 if ( file.find( "backup" ) != -1 && // No tr
724 file.findRev( ".tgz" ) == (int)file.length() - 4 ) { 765 file.findRev( ".tgz" ) == (int)file.length() - 4 ) {
@@ -745,4 +786,3 @@ void ServerPI::sendFile( const QString& file )
745 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 786 dtp->sendGzipFile( file, targets, peeraddress, peerport );
746 else 787 else dtp->sendFile( file, peeraddress, peerport );
747 dtp->sendFile( file, peeraddress, peerport );
748 } 788 }
@@ -763,3 +803,3 @@ void ServerPI::retrieveFile( const QString& file )
763 else 803 else
764 dtp->retrieveFile( file, peeraddress, peerport ); 804 dtp->retrieveFile( file, peeraddress, peerport, storFileSize );
765 } 805 }
@@ -770,4 +810,3 @@ bool ServerPI::parsePort( const QString& pp )
770 QStringList p = QStringList::split( ",", pp ); 810 QStringList p = QStringList::split( ",", pp );
771 if ( p.count() != 6 ) 811 if ( p.count() != 6 ) return FALSE;
772 return FALSE;
773 812
@@ -782,3 +821,3 @@ void ServerPI::dtpCompleted()
782{ 821{
783 send( "226 Closing data connection, file transfer successful" ); 822 send( "226 Closing data connection, file transfer successful" ); // No tr
784 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { 823 if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
@@ -792,2 +831,3 @@ void ServerPI::dtpCompleted()
792 dtp->close(); 831 dtp->close();
832 storFileSize = -1;
793} 833}
@@ -798,3 +838,4 @@ void ServerPI::dtpFailed()
798 waitsocket = 0; 838 waitsocket = 0;
799 send( "451 Requested action aborted: local error in processing" ); 839 send( "451 Requested action aborted: local error in processing" ); // No tr
840 storFileSize = -1;
800} 841}
@@ -805,3 +846,4 @@ void ServerPI::dtpError( int )
805 waitsocket = 0; 846 waitsocket = 0;
806 send( "451 Requested action aborted: local error in processing" ); 847 send( "451 Requested action aborted: local error in processing" ); // No tr
848 storFileSize = -1;
807} 849}
@@ -823,4 +865,3 @@ bool ServerPI::sendList( const QString& arg )
823 QFileInfo fi( fn ); 865 QFileInfo fi( fn );
824 if ( !fi.exists() ) 866 if ( !fi.exists() ) return FALSE;
825 return FALSE;
826 867
@@ -846,3 +887,3 @@ bool ServerPI::sendList( const QString& arg )
846 887
847 ts << "total " << QString::number( total / 1024 ) << endl; 888 ts << "total " << QString::number( total / 1024 ) << endl; // No tr
848 889
@@ -872,4 +913,3 @@ QString ServerPI::fileListing( QFileInfo *info )
872{ 913{
873 if ( !info ) 914 if ( !info ) return QString::null;
874 return QString::null;
875 QString s; 915 QString s;
@@ -899,6 +939,12 @@ QString ServerPI::fileListing( QFileInfo *info )
899 // owner 939 // owner
900 s += info->owner().leftJustify( 8, ' ', TRUE ) + " "; 940 QString o = info->owner();
941 if ( o.isEmpty() )
942 o = QString::number(info->ownerId());
943 s += o.leftJustify( 8, ' ', TRUE ) + " ";
901 944
902 // group 945 // group
903 s += info->group().leftJustify( 8, ' ', TRUE ) + " "; 946 QString g = info->group();
947 if ( g.isEmpty() )
948 g = QString::number(info->groupId());
949 s += g.leftJustify( 8, ' ', TRUE ) + " ";
904 950
@@ -923,4 +969,3 @@ QString ServerPI::permissionString( QFileInfo *info )
923{ 969{
924 if ( !info ) 970 if ( !info ) return QString( "---------" );
925 return QString( "---------" );
926 QString s; 971 QString s;
@@ -928,42 +973,24 @@ QString ServerPI::permissionString( QFileInfo *info )
928 // user 973 // user
929 if ( info->permission( QFileInfo::ReadUser ) ) 974 if ( info->permission( QFileInfo::ReadUser ) ) s += "r";
930 s += "r"; 975 else s += "-";
931 else 976 if ( info->permission( QFileInfo::WriteUser ) ) s += "w";
932 s += "-"; 977 else s += "-";
933 if ( info->permission( QFileInfo::WriteUser ) ) 978 if ( info->permission( QFileInfo::ExeUser ) ) s += "x";
934 s += "w"; 979 else s += "-";
935 else
936 s += "-";
937 if ( info->permission( QFileInfo::ExeUser ) )
938 s += "x";
939 else
940 s += "-";
941 980
942 // group 981 // group
943 if ( info->permission( QFileInfo::ReadGroup ) ) 982 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r";
944 s += "r"; 983 else s += "-";
945 else 984 if ( info->permission( QFileInfo::WriteGroup ) )s += "w";
946 s += "-"; 985 else s += "-";
947 if ( info->permission( QFileInfo::WriteGroup ) ) 986 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x";
948 s += "w"; 987 else s += "-";
949 else
950 s += "-";
951 if ( info->permission( QFileInfo::ExeGroup ) )
952 s += "x";
953 else
954 s += "-";
955 988
956 // exec 989 // exec
957 if ( info->permission( QFileInfo::ReadOther ) ) 990 if ( info->permission( QFileInfo::ReadOther ) ) s += "r";
958 s += "r"; 991 else s += "-";
959 else 992 if ( info->permission( QFileInfo::WriteOther ) ) s += "w";
960 s += "-"; 993 else s += "-";
961 if ( info->permission( QFileInfo::WriteOther ) ) 994 if ( info->permission( QFileInfo::ExeOther ) ) s += "x";
962 s += "w"; 995 else s += "-";
963 else
964 s += "-";
965 if ( info->permission( QFileInfo::ExeOther ) )
966 s += "x";
967 else
968 s += "-";
969 996
@@ -976,4 +1003,3 @@ void ServerPI::newConnection( int socket )
976 1003
977 if ( !passiv ) 1004 if ( !passiv ) return;
978 return ;
979 1005
@@ -992,3 +1018,3 @@ void ServerPI::newConnection( int socket )
992 else 1018 else
993 dtp->retrieveFile( waitfile ); 1019 dtp->retrieveFile( waitfile, storFileSize );
994 dtp->setSocket( socket ); 1020 dtp->setSocket( socket );
@@ -1013,4 +1039,3 @@ QString ServerPI::absFilePath( const QString& file )
1013{ 1039{
1014 if ( file.isEmpty() ) 1040 if ( file.isEmpty() ) return file;
1015 return file;
1016 1041
@@ -1032,3 +1057,3 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
1032 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), 1057 : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
1033 retrieveTargzProc( 0 ), gzipProc( 0 ) 1058 retrieveTargzProc( 0 )
1034{ 1059{
@@ -1040,15 +1065,13 @@ ServerDTP::ServerDTP( QObject *parent, const char* name)
1040 1065
1041 gzipProc = new OProcess( this, "gzipProc" ); 1066 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr
1042 1067 createTargzProc->setCommunication( QProcess::Stdout );
1043 createTargzProc = new OProcess( QString("tar"), this, "createTargzProc");
1044 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1068 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1045 connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) ); 1069 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) );
1046 1070
1047 QStringList args = "tar"; 1071 retrieveTargzProc = new QProcess( this, "retrieveTargzProc" );
1048 args += "-xv"; 1072 retrieveTargzProc->setCommunication( QProcess::Stdin );
1049 retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" );
1050 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1073 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1051 connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), 1074 connect( retrieveTargzProc, SIGNAL( processExited() ),
1052 SIGNAL( completed() ) ); 1075 SIGNAL( completed() ) );
1053 connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ), 1076 connect( retrieveTargzProc, SIGNAL( processExited() ),
1054 SLOT( extractTarDone() ) ); 1077 SLOT( extractTarDone() ) );
@@ -1059,3 +1082,12 @@ ServerDTP::~ServerDTP()
1059 buf.close(); 1082 buf.close();
1083 if ( RetrieveFile == mode && file.isOpen() ) {
1084 // We're being shutdown before the client closed.
1085 file.close();
1086 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1087 qDebug( "STOR incomplete" );
1088 file.remove();
1089 }
1090 } else {
1060 file.close(); 1091 file.close();
1092 }
1061 createTargzProc->kill(); 1093 createTargzProc->kill();
@@ -1067,4 +1099,3 @@ void ServerDTP::extractTarDone()
1067#ifndef QT_NO_COP 1099#ifndef QT_NO_COP
1068 1100 QCopEnvelope e( "QPE/System", "restoreDone(QString)" );
1069 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
1070 e << file.name(); 1101 e << file.name();
@@ -1092,6 +1123,5 @@ void ServerDTP::connected()
1092 mode = Idle; 1123 mode = Idle;
1093 } 1124 } else {
1094 else { 1125 // Don't write more if there is plenty buffered already.
1095 1126 if ( bytesToWrite() <= block_size && !file.atEnd() ) {
1096 if ( !file.atEnd() ) {
1097 QCString s; 1127 QCString s;
@@ -1112,6 +1142,5 @@ void ServerDTP::connected()
1112 qDebug("==>start send tar process"); 1142 qDebug("==>start send tar process");
1113 if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) ) 1143 if ( !createTargzProc->start() )
1114 qWarning("Error starting %s or %s", 1144 qWarning("Error starting %s",
1115 createTargzProc->args()[0].data(), 1145 createTargzProc->arguments().join(" ").latin1());
1116 gzipProc->args()[0].data());
1117 break; 1146 break;
@@ -1186,4 +1215,10 @@ void ServerDTP::connectionClosed()
1186 file.close(); 1215 file.close();
1216 if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) {
1217 qDebug( "STOR incomplete" );
1218 file.remove();
1219 emit failed();
1220 } else {
1187 emit completed(); 1221 emit completed();
1188 } 1222 }
1223 }
1189 1224
@@ -1191,4 +1226,4 @@ void ServerDTP::connectionClosed()
1191 qDebug("Done writing ungzip file; closing input"); 1226 qDebug("Done writing ungzip file; closing input");
1192 gzipProc->flushStdin(); 1227 retrieveTargzProc->flushStdin();
1193 gzipProc->closeStdin(); 1228 retrieveTargzProc->closeStdin();
1194 } 1229 }
@@ -1246,4 +1281,4 @@ void ServerDTP::readyRead()
1246 else if ( RetrieveGzipFile == mode ) { 1281 else if ( RetrieveGzipFile == mode ) {
1247 if ( !gzipProc->isRunning() ) 1282 if ( !retrieveTargzProc->isRunning() )
1248 gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout )); 1283 retrieveTargzProc->start();
1249 1284
@@ -1252,3 +1287,3 @@ void ServerDTP::readyRead()
1252 readBlock( s.data(), bytesAvailable() ); 1287 readBlock( s.data(), bytesAvailable() );
1253 gzipProc->writeStdin( s.data(), s.size() ); 1288 retrieveTargzProc->writeToStdin( s );
1254 qDebug("wrote %d bytes to ungzip ", s.size() ); 1289 qDebug("wrote %d bytes to ungzip ", s.size() );
@@ -1264,13 +1299,7 @@ void ServerDTP::readyRead()
1264 1299
1265void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen) 1300void ServerDTP::writeTargzBlock()
1266{ 1301{
1267 writeBlock( buffer, buflen ); 1302 QByteArray block = createTargzProc->readStdout();
1268 qDebug("writeTargzBlock %d", buflen); 1303 writeBlock( block.data(), block.size() );
1269 if ( !createTargzProc->isRunning() ) { 1304 qDebug("writeTargzBlock %d", block.size());
1270 qDebug("tar and gzip done");
1271 emit completed();
1272 mode = Idle;
1273 disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ),
1274 this, SLOT( writeTargzBlock(OProcess *, char *, int) ) );
1275 }
1276} 1305}
@@ -1279,16 +1308,7 @@ void ServerDTP::targzDone()
1279{ 1308{
1280 //qDebug("targz done"); 1309 qDebug("tar and gzip done");
1281 disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ), 1310 emit completed();
1282 this, SLOT( gzipTarBlock(OProcess *, char *, int) ) ); 1311 mode = Idle;
1283 gzipProc->closeStdin(); 1312 disconnect( createTargzProc, SIGNAL( readyReadStdout() ),
1284} 1313 this, SLOT( writeTargzBlock() ) );
1285
1286void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen)
1287{
1288 //qDebug("gzipTarBlock");
1289 if ( !gzipProc->isRunning() ) {
1290 //qDebug("auto start gzip proc");
1291 gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout ));
1292 }
1293 gzipProc->writeStdin( buffer, buflen );
1294} 1314}
@@ -1322,41 +1342,14 @@ void ServerDTP::sendGzipFile( const QString &fn,
1322 1342
1323 QStringList args = "tar"; 1343 QStringList args = "targzip";
1324 args += "-cv"; 1344 //args += "-cv";
1325 args += archiveTargets; 1345 args += archiveTargets;
1326 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1346 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1327 createTargzProc->clearArguments( ); 1347 createTargzProc->setArguments( args );
1328 *createTargzProc << args;
1329 connect( createTargzProc, 1348 connect( createTargzProc,
1330 SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) ); 1349 SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) );
1331
1332 gzipProc->clearArguments( );
1333 *gzipProc << "gzip";
1334 connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
1335 SLOT( writeTargzBlock(OProcess *, char *, int) ) );
1336} 1350}
1337 1351
1338void ServerDTP::gunzipDone() 1352void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize )
1339{
1340 qDebug("gunzipDone");
1341 disconnect( gzipProc, SIGNAL( processExited() ),
1342 this, SLOT( gunzipDone() ) );
1343 retrieveTargzProc->closeStdin();
1344 disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
1345 this, SLOT( tarExtractBlock(OProcess *, char *, int) ) );
1346}
1347
1348void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen)
1349{
1350 qDebug("tarExtractBlock");
1351 if ( !retrieveTargzProc->isRunning() ) {
1352 qDebug("auto start ungzip proc");
1353 if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) )
1354 qWarning(" failed to start tar -x process");
1355 }
1356 retrieveTargzProc->writeStdin( buffer, buflen );
1357}
1358
1359
1360void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port )
1361{ 1353{
1354 recvFileSize = fileSize;
1362 file.setName( fn ); 1355 file.setName( fn );
@@ -1366,4 +1359,5 @@ void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT
1366 1359
1367void ServerDTP::retrieveFile( const QString fn ) 1360void ServerDTP::retrieveFile( const QString fn, int fileSize )
1368{ 1361{
1362 recvFileSize = fileSize;
1369 file.setName( fn ); 1363 file.setName( fn );
@@ -1378,8 +1372,5 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
1378 1372
1379 gzipProc->clearArguments(); 1373 retrieveTargzProc->setArguments( "targunzip" );
1380 *gzipProc << "gunzip"; 1374 connect( retrieveTargzProc, SIGNAL( processExited() ),
1381 connect( gzipProc, SIGNAL( readyReadStdout() ), 1375 SLOT( extractTarDone() ) );
1382 SLOT( tarExtractBlock() ) );
1383 connect( gzipProc, SIGNAL( processExited() ),
1384 SLOT( gunzipDone() ) );
1385} 1376}