summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
Unidiff
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp191
1 files changed, 113 insertions, 78 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index cbda247..0337a94 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -31,5 +31,6 @@
31#ifndef _OS_LINUX_ 31#ifndef _OS_LINUX_
32 32
33extern "C" { 33extern "C"
34{
34#include <uuid/uuid.h> 35#include <uuid/uuid.h>
35#define UUID_H_INCLUDED 36#define UUID_H_INCLUDED
@@ -60,5 +61,5 @@ extern "C" {
60 61
61#include "transferserver.h" 62#include "transferserver.h"
62#include "qprocess.h" 63#include <opie/oprocess.h>
63 64
64const int block_size = 51200; 65const int block_size = 51200;
@@ -74,5 +75,4 @@ TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
74TransferServer::~TransferServer() 75TransferServer::~TransferServer()
75{ 76{
76
77} 77}
78 78
@@ -86,10 +86,14 @@ void TransferServer::newConnection( int socket )
86 * to generate a QUUid for us 86 * to generate a QUUid for us
87 */ 87 */
88namespace { 88namespace
89 struct UidGen { 89{
90struct UidGen
91{
90 QString uuid(); 92 QString uuid();
91 }; 93 };
92#if !defined(_OS_LINUX_) 94#if !defined(_OS_LINUX_)
93 QString UidGen::uuid() { 95
96QString UidGen::uuid()
97{
94 uuid_t uuid; 98 uuid_t uuid;
95 uuid_generate( uuid ); 99 uuid_generate( uuid );
@@ -101,5 +105,6 @@ namespace {
101 * it'll generate the uuids for us 105 * it'll generate the uuids for us
102 */ 106 */
103 QString UidGen::uuid() { 107QString UidGen::uuid()
108{
104 QFile file( "/proc/sys/kernel/random/uuid" ); 109 QFile file( "/proc/sys/kernel/random/uuid" );
105 if (!file.open(IO_ReadOnly ) ) 110 if (!file.open(IO_ReadOnly ) )
@@ -164,5 +169,6 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
164bool SyncAuthentication::checkUser( const QString& user ) 169bool SyncAuthentication::checkUser( const QString& user )
165{ 170{
166 if ( user.isEmpty() ) return FALSE; 171 if ( user.isEmpty() )
172 return FALSE;
167 QString euser = loginName(); 173 QString euser = loginName();
168 return user == euser; 174 return user == euser;
@@ -231,10 +237,10 @@ bool SyncAuthentication::checkPassword( const QString& password )
231 tr("<p>An unrecognized system is requesting access to this device." 237 tr("<p>An unrecognized system is requesting access to this device."
232 "<p>If you have just initiated a Sync for the first time, this is normal."), 238 "<p>If you have just initiated a Sync for the first time, this is normal."),
233 tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 ) 239 tr("Allow"), tr("Deny"), 0, 1, 1 ) == 1 ) {
234 {
235 denials++; 240 denials++;
236 lastdenial=now; 241 lastdenial=now;
237 return FALSE; 242 return FALSE;
238 } else { 243 }
244 else {
239 denials=0; 245 denials=0;
240 cfg.writeEntry("Passwords",pwds+" "+cpassword); 246 cfg.writeEntry("Passwords",pwds+" "+cpassword);
@@ -257,8 +263,10 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
257 263
258#ifndef INSECURE 264#ifndef INSECURE
265
259 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 266 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
260 state = Forbidden; 267 state = Forbidden;
261 startTimer( 0 ); 268 startTimer( 0 );
262 } else 269 }
270 else
263#endif 271#endif
264 { 272 {
@@ -294,5 +302,4 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
294ServerPI::~ServerPI() 302ServerPI::~ServerPI()
295{ 303{
296
297} 304}
298 305
@@ -352,5 +359,6 @@ void ServerPI::process( const QString& message )
352 // split message using "," as separator 359 // split message using "," as separator
353 QStringList msg = QStringList::split( " ", message ); 360 QStringList msg = QStringList::split( " ", message );
354 if ( msg.isEmpty() ) return; 361 if ( msg.isEmpty() )
362 return ;
355 363
356 // command token 364 // command token
@@ -591,5 +599,6 @@ void ServerPI::process( const QString& message )
591 QCopEnvelope e("QPE/System", "linkChanged(QString)" ); 599 QCopEnvelope e("QPE/System", "linkChanged(QString)" );
592 e << file.name(); 600 e << file.name();
593 } else { 601 }
602 else {
594 send( "550 Requested action not taken" ); 603 send( "550 Requested action not taken" );
595 } 604 }
@@ -735,5 +744,6 @@ void ServerPI::sendFile( const QString& file )
735 if ( backupRestoreGzip( file, targets ) ) 744 if ( backupRestoreGzip( file, targets ) )
736 dtp->sendGzipFile( file, targets, peeraddress, peerport ); 745 dtp->sendGzipFile( file, targets, peeraddress, peerport );
737 else dtp->sendFile( file, peeraddress, peerport ); 746 else
747 dtp->sendFile( file, peeraddress, peerport );
738 } 748 }
739} 749}
@@ -759,5 +769,6 @@ bool ServerPI::parsePort( const QString& pp )
759{ 769{
760 QStringList p = QStringList::split( ",", pp ); 770 QStringList p = QStringList::split( ",", pp );
761 if ( p.count() != 6 ) return FALSE; 771 if ( p.count() != 6 )
772 return FALSE;
762 773
763 // h1,h2,h3,h4,p1,p2 774 // h1,h2,h3,h4,p1,p2
@@ -811,5 +822,6 @@ bool ServerPI::sendList( const QString& arg )
811 822
812 QFileInfo fi( fn ); 823 QFileInfo fi( fn );
813 if ( !fi.exists() ) return FALSE; 824 if ( !fi.exists() )
825 return FALSE;
814 826
815 // return file listing 827 // return file listing
@@ -859,5 +871,6 @@ bool ServerPI::sendList( const QString& arg )
859QString ServerPI::fileListing( QFileInfo *info ) 871QString ServerPI::fileListing( QFileInfo *info )
860{ 872{
861 if ( !info ) return QString::null; 873 if ( !info )
874 return QString::null;
862 QString s; 875 QString s;
863 876
@@ -909,30 +922,49 @@ QString ServerPI::fileListing( QFileInfo *info )
909QString ServerPI::permissionString( QFileInfo *info ) 922QString ServerPI::permissionString( QFileInfo *info )
910{ 923{
911 if ( !info ) return QString( "---------" ); 924 if ( !info )
925 return QString( "---------" );
912 QString s; 926 QString s;
913 927
914 // user 928 // user
915 if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; 929 if ( info->permission( QFileInfo::ReadUser ) )
916 else s += "-"; 930 s += "r";
917 if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; 931 else
918 else s += "-"; 932 s += "-";
919 if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; 933 if ( info->permission( QFileInfo::WriteUser ) )
920 else s += "-"; 934 s += "w";
935 else
936 s += "-";
937 if ( info->permission( QFileInfo::ExeUser ) )
938 s += "x";
939 else
940 s += "-";
921 941
922 // group 942 // group
923 if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; 943 if ( info->permission( QFileInfo::ReadGroup ) )
924 else s += "-"; 944 s += "r";
925 if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; 945 else
926 else s += "-"; 946 s += "-";
927 if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; 947 if ( info->permission( QFileInfo::WriteGroup ) )
928 else s += "-"; 948 s += "w";
949 else
950 s += "-";
951 if ( info->permission( QFileInfo::ExeGroup ) )
952 s += "x";
953 else
954 s += "-";
929 955
930 // exec 956 // exec
931 if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; 957 if ( info->permission( QFileInfo::ReadOther ) )
932 else s += "-"; 958 s += "r";
933 if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; 959 else
934 else s += "-"; 960 s += "-";
935 if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; 961 if ( info->permission( QFileInfo::WriteOther ) )
936 else s += "-"; 962 s += "w";
963 else
964 s += "-";
965 if ( info->permission( QFileInfo::ExeOther ) )
966 s += "x";
967 else
968 s += "-";
937 969
938 return s; 970 return s;
@@ -943,5 +975,6 @@ void ServerPI::newConnection( int socket )
943 //qDebug( "New incomming connection" ); 975 //qDebug( "New incomming connection" );
944 976
945 if ( !passiv ) return; 977 if ( !passiv )
978 return ;
946 979
947 if ( wait[SendFile] ) { 980 if ( wait[SendFile] ) {
@@ -979,5 +1012,6 @@ void ServerPI::newConnection( int socket )
979QString ServerPI::absFilePath( const QString& file ) 1012QString ServerPI::absFilePath( const QString& file )
980{ 1013{
981 if ( file.isEmpty() ) return file; 1014 if ( file.isEmpty() )
1015 return file;
982 1016
983 QString filepath( file ); 1017 QString filepath( file );
@@ -1005,20 +1039,17 @@ retrieveTargzProc( 0 ), gzipProc( 0 )
1005 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); 1039 connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) );
1006 1040
1007 gzipProc = new QProcess( this, "gzipProc" ); 1041 gzipProc = new OProcess( this, "gzipProc" );
1008 gzipProc->setCommunication( QProcess::Stdin | QProcess::Stdout );
1009 1042
1010 createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); 1043 createTargzProc = new OProcess( QString("tar"), this, "createTargzProc");
1011 createTargzProc->setCommunication( QProcess::Stdout );
1012 createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1044 createTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1013 connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); 1045 connect( createTargzProc, SIGNAL( processExited(OProcess *) ), SLOT( targzDone() ) );
1014 1046
1015 QStringList args = "tar"; 1047 QStringList args = "tar";
1016 args += "-xv"; 1048 args += "-xv";
1017 retrieveTargzProc = new QProcess( args, this, "retrieveTargzProc" ); 1049 retrieveTargzProc = new OProcess( args, this, "retrieveTargzProc" );
1018 retrieveTargzProc->setCommunication( QProcess::Stdin );
1019 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); 1050 retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() );
1020 connect( retrieveTargzProc, SIGNAL( processExited() ), 1051 connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ),
1021 SIGNAL( completed() ) ); 1052 SIGNAL( completed() ) );
1022 connect( retrieveTargzProc, SIGNAL( processExited() ), 1053 connect( retrieveTargzProc, SIGNAL( processExited(OProcess *) ),
1023 SLOT( extractTarDone() ) ); 1054 SLOT( extractTarDone() ) );
1024} 1055}
@@ -1035,4 +1066,5 @@ void ServerDTP::extractTarDone()
1035 qDebug("extract done"); 1066 qDebug("extract done");
1036#ifndef QT_NO_COP 1067#ifndef QT_NO_COP
1068
1037 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" ); 1069 QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
1038 e << file.name(); 1070 e << file.name();
@@ -1059,5 +1091,6 @@ void ServerDTP::connected()
1059 emit completed(); 1091 emit completed();
1060 mode = Idle; 1092 mode = Idle;
1061 } else { 1093 }
1094 else {
1062 1095
1063 if( !file.atEnd() ) { 1096 if( !file.atEnd() ) {
@@ -1078,8 +1111,8 @@ void ServerDTP::connected()
1078 bytes_written = 0; 1111 bytes_written = 0;
1079 qDebug("==>start send tar process"); 1112 qDebug("==>start send tar process");
1080 if ( !createTargzProc->start() ) 1113 if ( !createTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdout) )
1081 qWarning("Error starting %s or %s", 1114 qWarning("Error starting %s or %s",
1082 createTargzProc->arguments().join(" ").latin1(), 1115 createTargzProc->args()[0].data(),
1083 gzipProc->arguments().join(" ").latin1() ); 1116 gzipProc->args()[0].data());
1084 break; 1117 break;
1085 case SendBuffer: 1118 case SendBuffer:
@@ -1213,10 +1246,10 @@ void ServerDTP::readyRead()
1213 else if ( RetrieveGzipFile == mode ) { 1246 else if ( RetrieveGzipFile == mode ) {
1214 if ( !gzipProc->isRunning() ) 1247 if ( !gzipProc->isRunning() )
1215 gzipProc->start(); 1248 gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout ));
1216 1249
1217 QByteArray s; 1250 QByteArray s;
1218 s.resize( bytesAvailable() ); 1251 s.resize( bytesAvailable() );
1219 readBlock( s.data(), bytesAvailable() ); 1252 readBlock( s.data(), bytesAvailable() );
1220 gzipProc->writeToStdin( s ); 1253 gzipProc->writeStdin( s.data(), s.size() );
1221 qDebug("wrote %d bytes to ungzip ", s.size() ); 1254 qDebug("wrote %d bytes to ungzip ", s.size() );
1222 } 1255 }
@@ -1230,15 +1263,14 @@ void ServerDTP::readyRead()
1230} 1263}
1231 1264
1232void ServerDTP::writeTargzBlock() 1265void ServerDTP::writeTargzBlock(OProcess *, char *buffer, int buflen)
1233{ 1266{
1234 QByteArray block = gzipProc->readStdout(); 1267 writeBlock( buffer, buflen );
1235 writeBlock( block.data(), block.size() ); 1268 qDebug("writeTargzBlock %d", buflen);
1236 qDebug("writeTargzBlock %d", block.size());
1237 if ( !createTargzProc->isRunning() ) { 1269 if ( !createTargzProc->isRunning() ) {
1238 qDebug("tar and gzip done"); 1270 qDebug("tar and gzip done");
1239 emit completed(); 1271 emit completed();
1240 mode = Idle; 1272 mode = Idle;
1241 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1273 disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int ) ),
1242 this, SLOT( writeTargzBlock() ) ); 1274 this, SLOT( writeTargzBlock(OProcess *, char *, int) ) );
1243 } 1275 }
1244} 1276}
@@ -1247,17 +1279,17 @@ void ServerDTP::targzDone()
1247{ 1279{
1248 //qDebug("targz done"); 1280 //qDebug("targz done");
1249 disconnect( createTargzProc, SIGNAL( readyReadStdout() ), 1281 disconnect( createTargzProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
1250 this, SLOT( gzipTarBlock() ) ); 1282 this, SLOT( gzipTarBlock(OProcess *, char *, int) ) );
1251 gzipProc->closeStdin(); 1283 gzipProc->closeStdin();
1252} 1284}
1253 1285
1254void ServerDTP::gzipTarBlock() 1286void ServerDTP::gzipTarBlock(OProcess *, char *buffer, int buflen)
1255{ 1287{
1256 //qDebug("gzipTarBlock"); 1288 //qDebug("gzipTarBlock");
1257 if ( !gzipProc->isRunning() ) { 1289 if ( !gzipProc->isRunning() ) {
1258 //qDebug("auto start gzip proc"); 1290 //qDebug("auto start gzip proc");
1259 gzipProc->start(); 1291 gzipProc->start(OProcess::NotifyOnExit, (OProcess::Communication) ( OProcess::Stdin | OProcess::Stdout ));
1260 } 1292 }
1261 gzipProc->writeToStdin( createTargzProc->readStdout() ); 1293 gzipProc->writeStdin( buffer, buflen );
1262} 1294}
1263 1295
@@ -1293,11 +1325,13 @@ void ServerDTP::sendGzipFile( const QString &fn,
1293 args += archiveTargets; 1325 args += archiveTargets;
1294 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1326 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1295 createTargzProc->setArguments( args ); 1327 createTargzProc->clearArguments( );
1328 *createTargzProc << args;
1296 connect( createTargzProc, 1329 connect( createTargzProc,
1297 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); 1330 SIGNAL( receivedStdout(OProcess *, char *, int) ), SLOT( gzipTarBlock(OProcess *, char *, int) ) );
1298 1331
1299 gzipProc->setArguments( "gzip" ); 1332 gzipProc->clearArguments( );
1300 connect( gzipProc, SIGNAL( readyReadStdout() ), 1333 *gzipProc << "gzip";
1301 SLOT( writeTargzBlock() ) ); 1334 connect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
1335 SLOT( writeTargzBlock(OProcess *, char *, int) ) );
1302} 1336}
1303 1337
@@ -1308,17 +1342,17 @@ void ServerDTP::gunzipDone()
1308 this, SLOT( gunzipDone() ) ); 1342 this, SLOT( gunzipDone() ) );
1309 retrieveTargzProc->closeStdin(); 1343 retrieveTargzProc->closeStdin();
1310 disconnect( gzipProc, SIGNAL( readyReadStdout() ), 1344 disconnect( gzipProc, SIGNAL( receivedStdout(OProcess *, char *, int) ),
1311 this, SLOT( tarExtractBlock() ) ); 1345 this, SLOT( tarExtractBlock(OProcess *, char *, int) ) );
1312} 1346}
1313 1347
1314void ServerDTP::tarExtractBlock() 1348void ServerDTP::tarExtractBlock(OProcess *, char *buffer, int buflen)
1315{ 1349{
1316 qDebug("ungzipTarBlock"); 1350 qDebug("tarExtractBlock");
1317 if ( !retrieveTargzProc->isRunning() ) { 1351 if ( !retrieveTargzProc->isRunning() ) {
1318 qDebug("auto start ungzip proc"); 1352 qDebug("auto start ungzip proc");
1319 if ( !retrieveTargzProc->start() ) 1353 if ( !retrieveTargzProc->start(OProcess::NotifyOnExit, OProcess::Stdin) )
1320 qWarning(" failed to start tar -x process"); 1354 qWarning(" failed to start tar -x process");
1321 } 1355 }
1322 retrieveTargzProc->writeToStdin( gzipProc->readStdout() ); 1356 retrieveTargzProc->writeStdin( buffer, buflen );
1323} 1357}
1324 1358
@@ -1343,5 +1377,6 @@ void ServerDTP::retrieveGzipFile( const QString &fn )
1343 mode = RetrieveGzipFile; 1377 mode = RetrieveGzipFile;
1344 1378
1345 gzipProc->setArguments( "gunzip" ); 1379 gzipProc->clearArguments();
1380 *gzipProc << "gunzip";
1346 connect( gzipProc, SIGNAL( readyReadStdout() ), 1381 connect( gzipProc, SIGNAL( readyReadStdout() ),
1347 SLOT( tarExtractBlock() ) ); 1382 SLOT( tarExtractBlock() ) );