summaryrefslogtreecommitdiff
path: root/core/launcher/transferserver.cpp
authorzecke <zecke>2002-09-06 21:35:13 (UTC)
committer zecke <zecke>2002-09-06 21:35:13 (UTC)
commite95e14f056ce6be658a4fd0d4737168431e92d88 (patch) (unidiff)
tree732f0a69b2063dc6c54444486223fd99879da72c /core/launcher/transferserver.cpp
parent5536f65e60b3c662d2da3636e617faaad02522db (diff)
downloadopie-e95e14f056ce6be658a4fd0d4737168431e92d88.zip
opie-e95e14f056ce6be658a4fd0d4737168431e92d88.tar.gz
opie-e95e14f056ce6be658a4fd0d4737168431e92d88.tar.bz2
Remove the libuuid dependency for Linux targets...
Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp59
1 files changed, 47 insertions, 12 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 9d18b7b..a20df2f 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -22,17 +22,21 @@
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <time.h> 25#include <time.h>
26#include <shadow.h> 26#include <shadow.h>
27 27
28#ifndef _OS_LINUX_
29
28extern "C" { 30extern "C" {
29#include <uuid/uuid.h> 31#include <uuid/uuid.h>
30#define UUID_H_INCLUDED 32#define UUID_H_INCLUDED
31} 33}
32 34
35#endif // not defined linux
36
33#if defined(_OS_LINUX_) 37#if defined(_OS_LINUX_)
34#include <shadow.h> 38#include <shadow.h>
35#endif 39#endif
36 40
37#include <qdir.h> 41#include <qdir.h>
38#include <qfile.h> 42#include <qfile.h>
@@ -73,21 +77,52 @@ TransferServer::~TransferServer()
73 77
74void TransferServer::newConnection( int socket ) 78void TransferServer::newConnection( int socket )
75{ 79{
76 (void) new ServerPI( socket, this ); 80 (void) new ServerPI( socket, this );
77} 81}
78 82
83/*
84 * small class in anonymous namespace
85 * to generate a QUUid for us
86 */
87namespace {
88 struct UidGen {
89 QString uuid();
90 };
91#if defined(_OS_LINUX_)
92 /*
93 * linux got a /proc/sys/kernel/random/uuid file
94 * it'll generate the uuids for us
95 */
96 QString UidGen::uuid() {
97 QFile file( "/proc/sys/kernel/random/uuid" );
98 if (!file.open(IO_ReadOnly ) )
99 return QString::null;
100
101 QTextStream stream(&file);
102
103 return "{" + stream.read().stripWhiteSpace() + "}";
104 }
105#else
106 QString UidGen::uuid() {
107 uuid_t uuid;
108 uuid_generate( uuid );
109 return QUUid( uuid ).toString();
110 }
111#endif
112}
113
79QString SyncAuthentication::serverId() 114QString SyncAuthentication::serverId()
80{ 115{
81 Config cfg("Security"); 116 Config cfg("Security");
82 cfg.setGroup("Sync"); 117 cfg.setGroup("Sync");
83 QString r=cfg.readEntry("serverid"); 118 QString r=cfg.readEntry("serverid");
84 if ( r.isEmpty() ) { 119 if ( r.isEmpty() ) {
85 uuid_t uuid; 120 UidGen gen;
86 uuid_generate( uuid ); 121 r = gen.uuid();
87 cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); 122 cfg.writeEntry("serverid", r );
88 } 123 }
89 return r; 124 return r;
90} 125}
91 126
92QString SyncAuthentication::ownerName() 127QString SyncAuthentication::ownerName()
93{ 128{
@@ -112,13 +147,13 @@ QString SyncAuthentication::loginName()
112int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 147int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
113{ 148{
114 Config cfg("Security"); 149 Config cfg("Security");
115 cfg.setGroup("Sync"); 150 cfg.setGroup("Sync");
116// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 151// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
117 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); 152 uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
118 153
119// QHostAddress allowed; 154// QHostAddress allowed;
120// allowed.setAddress(allowedstr); 155// allowed.setAddress(allowedstr);
121// uint auth_peer = allowed.ip4Addr(); 156// uint auth_peer = allowed.ip4Addr();
122 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
123 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
124 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); 159 ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
@@ -170,20 +205,20 @@ bool SyncAuthentication::checkPassword( const QString& password )
170 } 205 }
171 return FALSE; 206 return FALSE;
172 } 207 }
173 208
174 // Second, check sync password... 209 // Second, check sync password...
175 QString pass = password.left(6); 210 QString pass = password.left(6);
176 /* old QtopiaDesktops are sending 211 /* old QtopiaDesktops are sending
177 * rootme newer versions got a Qtopia 212 * rootme newer versions got a Qtopia
178 * prefixed. Qtopia prefix will suceed 213 * prefixed. Qtopia prefix will suceed
179 * until the sync software syncs up 214 * until the sync software syncs up
180 * FIXME 215 * FIXME
181 */ 216 */
182 if ( pass == "rootme" || pass == "Qtopia") { 217 if ( pass == "rootme" || pass == "Qtopia") {
183 218
184 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 219 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
185 Config cfg("Security"); 220 Config cfg("Security");
186 cfg.setGroup("Sync"); 221 cfg.setGroup("Sync");
187 QString pwds = cfg.readEntry("Passwords"); 222 QString pwds = cfg.readEntry("Passwords");
188 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 223 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
189 return TRUE; 224 return TRUE;
@@ -221,17 +256,17 @@ ServerPI::ServerPI( int socket, QObject *parent , const char* name )
221 256
222#ifndef INSECURE 257#ifndef INSECURE
223 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 258 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
224 state = Forbidden; 259 state = Forbidden;
225 startTimer( 0 ); 260 startTimer( 0 );
226 } else 261 } else
227#endif 262#endif
228 { 263 {
229 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 264 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
230 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 265 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
231 266
232 passiv = FALSE; 267 passiv = FALSE;
233 for( int i = 0; i < 4; i++ ) 268 for( int i = 0; i < 4; i++ )
234 wait[i] = FALSE; 269 wait[i] = FALSE;
235 270
236 send( "220 Qtopia " QPE_VERSION " FTP Server" ); 271 send( "220 Qtopia " QPE_VERSION " FTP Server" );
237 state = Wait_USER; 272 state = Wait_USER;
@@ -624,13 +659,13 @@ void ServerPI::process( const QString& message )
624 int guess = size.toInt()/5; 659 int guess = size.toInt()/5;
625 if ( filePath.contains("doc") ) 660 if ( filePath.contains("doc") )
626 guess *= 1000; 661 guess *= 1000;
627 qDebug("sending back gzip guess of %d", guess); 662 qDebug("sending back gzip guess of %d", guess);
628 send( "213 " + QString::number(guess) ); 663 send( "213 " + QString::number(guess) );
629 } 664 }
630 } 665 }
631 } 666 }
632 } 667 }
633 // name list (NLST) 668 // name list (NLST)
634 else if ( cmd == "NLST" ) { 669 else if ( cmd == "NLST" ) {
635 send( "502 Command not implemented" ); 670 send( "502 Command not implemented" );
636 } 671 }
@@ -1174,13 +1209,13 @@ void ServerDTP::readyRead()
1174 readBlock( s.data(), bytesAvailable() ); 1209 readBlock( s.data(), bytesAvailable() );
1175 file.writeBlock( s.data(), s.size() ); 1210 file.writeBlock( s.data(), s.size() );
1176 } 1211 }
1177 else if ( RetrieveGzipFile == mode ) { 1212 else if ( RetrieveGzipFile == mode ) {
1178 if ( !gzipProc->isRunning() ) 1213 if ( !gzipProc->isRunning() )
1179 gzipProc->start(); 1214 gzipProc->start();
1180 1215
1181 QByteArray s; 1216 QByteArray s;
1182 s.resize( bytesAvailable() ); 1217 s.resize( bytesAvailable() );
1183 readBlock( s.data(), bytesAvailable() ); 1218 readBlock( s.data(), bytesAvailable() );
1184 gzipProc->writeToStdin( s ); 1219 gzipProc->writeToStdin( s );
1185 qDebug("wrote %d bytes to ungzip ", s.size() ); 1220 qDebug("wrote %d bytes to ungzip ", s.size() );
1186 } 1221 }
@@ -1257,13 +1292,13 @@ void ServerDTP::sendGzipFile( const QString &fn,
1257 args += archiveTargets; 1292 args += archiveTargets;
1258 qDebug("sendGzipFile %s", args.join(" ").latin1() ); 1293 qDebug("sendGzipFile %s", args.join(" ").latin1() );
1259 createTargzProc->setArguments( args ); 1294 createTargzProc->setArguments( args );
1260 connect( createTargzProc, 1295 connect( createTargzProc,
1261 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) ); 1296 SIGNAL( readyReadStdout() ), SLOT( gzipTarBlock() ) );
1262 1297
1263 gzipProc->setArguments( "gzip" ); 1298 gzipProc->setArguments( "gzip" );
1264 connect( gzipProc, SIGNAL( readyReadStdout() ), 1299 connect( gzipProc, SIGNAL( readyReadStdout() ),
1265 SLOT( writeTargzBlock() ) ); 1300 SLOT( writeTargzBlock() ) );
1266} 1301}
1267 1302
1268void ServerDTP::gunzipDone() 1303void ServerDTP::gunzipDone()
1269{ 1304{
@@ -1303,13 +1338,13 @@ void ServerDTP::retrieveFile( const QString fn )
1303void ServerDTP::retrieveGzipFile( const QString &fn ) 1338void ServerDTP::retrieveGzipFile( const QString &fn )
1304{ 1339{
1305 qDebug("retrieveGzipFile %s", fn.latin1()); 1340 qDebug("retrieveGzipFile %s", fn.latin1());
1306 file.setName( fn ); 1341 file.setName( fn );
1307 mode = RetrieveGzipFile; 1342 mode = RetrieveGzipFile;
1308 1343
1309 gzipProc->setArguments( "gunzip" ); 1344 gzipProc->setArguments( "gunzip" );
1310 connect( gzipProc, SIGNAL( readyReadStdout() ), 1345 connect( gzipProc, SIGNAL( readyReadStdout() ),
1311 SLOT( tarExtractBlock() ) ); 1346 SLOT( tarExtractBlock() ) );
1312 connect( gzipProc, SIGNAL( processExited() ), 1347 connect( gzipProc, SIGNAL( processExited() ),
1313 SLOT( gunzipDone() ) ); 1348 SLOT( gunzipDone() ) );
1314} 1349}
1315 1350