author | zecke <zecke> | 2003-11-21 09:37:54 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-11-21 09:37:54 (UTC) |
commit | 10ae99b2cbbf3e24f3568367a85b3b2d6c0fa289 (patch) (unidiff) | |
tree | ac9c821ddeef8d6e05024206e19b7dc780791611 | |
parent | 99ecb210f893437068060194b031cb37b94a0398 (diff) | |
download | opie-10ae99b2cbbf3e24f3568367a85b3b2d6c0fa289.zip opie-10ae99b2cbbf3e24f3568367a85b3b2d6c0fa289.tar.gz opie-10ae99b2cbbf3e24f3568367a85b3b2d6c0fa289.tar.bz2 |
Fix bug 1219.
If not authorized no dtp is created
so 0x000000000->close is likely to fail.
lpotter something I think Qtopia suffers from as well
-rw-r--r-- | core/launcher/transferserver.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index eea9f3a..9519d11 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -252,193 +252,195 @@ bool SyncAuthentication::checkPassword( const QString& password ) | |||
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | // Unrecognized system. Be careful... | 255 | // Unrecognized system. Be careful... |
256 | QMessageBox unrecbox( | 256 | QMessageBox unrecbox( |
257 | tr("Sync Connection"), | 257 | tr("Sync Connection"), |
258 | tr("<p>An unrecognized system is requesting access to this device." | 258 | tr("<p>An unrecognized system is requesting access to this device." |
259 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 259 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
260 | QMessageBox::Warning, | 260 | QMessageBox::Warning, |
261 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, | 261 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, |
262 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 262 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
263 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); | 263 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); |
264 | unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); | 264 | unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); |
265 | 265 | ||
266 | if ( (denials > 2 && now < lastdenial+600) | 266 | if ( (denials > 2 && now < lastdenial+600) |
267 | || unrecbox.exec() != QMessageBox::Yes) | 267 | || unrecbox.exec() != QMessageBox::Yes) |
268 | { | 268 | { |
269 | denials++; | 269 | denials++; |
270 | lastdenial=now; | 270 | lastdenial=now; |
271 | lock--; | 271 | lock--; |
272 | return FALSE; | 272 | return FALSE; |
273 | } else { | 273 | } else { |
274 | const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; | 274 | const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; |
275 | char salt[2]; | 275 | char salt[2]; |
276 | salt[0]= salty[rand() % (sizeof(salty)-1)]; | 276 | salt[0]= salty[rand() % (sizeof(salty)-1)]; |
277 | salt[1]= salty[rand() % (sizeof(salty)-1)]; | 277 | salt[1]= salty[rand() % (sizeof(salty)-1)]; |
278 | #ifndef Q_OS_WIN32 | 278 | #ifndef Q_OS_WIN32 |
279 | QString cpassword = QString::fromLocal8Bit( | 279 | QString cpassword = QString::fromLocal8Bit( |
280 | crypt( password.mid(8).local8Bit(), salt ) ); | 280 | crypt( password.mid(8).local8Bit(), salt ) ); |
281 | #else | 281 | #else |
282 | //### revise | 282 | //### revise |
283 | QString cpassword(""); | 283 | QString cpassword(""); |
284 | #endif | 284 | #endif |
285 | denials=0; | 285 | denials=0; |
286 | pwds.prepend(cpassword); | 286 | pwds.prepend(cpassword); |
287 | cfg.writeEntry("Passwords",pwds,' '); | 287 | cfg.writeEntry("Passwords",pwds,' '); |
288 | lock--; | 288 | lock--; |
289 | return TRUE; | 289 | return TRUE; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | lock--; | 292 | lock--; |
293 | 293 | ||
294 | return FALSE; | 294 | return FALSE; |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | ServerPI::ServerPI( int socket, QObject *parent, const char* name ) | 298 | ServerPI::ServerPI( int socket, QObject *parent, const char* name ) |
299 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), | 299 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), |
300 | storFileSize(-1) | 300 | storFileSize(-1) |
301 | { | 301 | { |
302 | state = Connected; | 302 | state = Connected; |
303 | 303 | ||
304 | setSocket( socket ); | 304 | setSocket( socket ); |
305 | 305 | ||
306 | peerport = peerPort(); | 306 | peerport = peerPort(); |
307 | peeraddress = peerAddress(); | 307 | peeraddress = peerAddress(); |
308 | 308 | ||
309 | #ifndef INSECURE | 309 | #ifndef INSECURE |
310 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 310 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
311 | state = Forbidden; | 311 | state = Forbidden; |
312 | startTimer( 0 ); | 312 | startTimer( 0 ); |
313 | } else | 313 | } else |
314 | #endif | 314 | #endif |
315 | { | 315 | { |
316 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 316 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
317 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 317 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
318 | 318 | ||
319 | passiv = FALSE; | 319 | passiv = FALSE; |
320 | for( int i = 0; i < 4; i++ ) | 320 | for( int i = 0; i < 4; i++ ) |
321 | wait[i] = FALSE; | 321 | wait[i] = FALSE; |
322 | 322 | ||
323 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr | 323 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr |
324 | state = Wait_USER; | 324 | state = Wait_USER; |
325 | 325 | ||
326 | dtp = new ServerDTP( this ); | 326 | dtp = new ServerDTP( this ); |
327 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 327 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
328 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 328 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
329 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 329 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
330 | 330 | ||
331 | 331 | ||
332 | directory = QDir::currentDirPath(); | 332 | directory = QDir::currentDirPath(); |
333 | 333 | ||
334 | static int p = 1024; | 334 | static int p = 1024; |
335 | 335 | ||
336 | while ( !serversocket || !serversocket->ok() ) { | 336 | while ( !serversocket || !serversocket->ok() ) { |
337 | delete serversocket; | 337 | delete serversocket; |
338 | serversocket = new ServerSocket( ++p, this ); | 338 | serversocket = new ServerSocket( ++p, this ); |
339 | } | 339 | } |
340 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 340 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
341 | SLOT( newConnection( int ) ) ); | 341 | SLOT( newConnection( int ) ) ); |
342 | } | 342 | } |
343 | } | 343 | } |
344 | 344 | ||
345 | ServerPI::~ServerPI() | 345 | ServerPI::~ServerPI() |
346 | { | 346 | { |
347 | close(); | 347 | close(); |
348 | dtp->close(); | 348 | |
349 | if ( dtp ) | ||
350 | dtp->close(); | ||
349 | delete dtp; | 351 | delete dtp; |
350 | delete serversocket; | 352 | delete serversocket; |
351 | } | 353 | } |
352 | 354 | ||
353 | bool ServerPI::verifyAuthorised() | 355 | bool ServerPI::verifyAuthorised() |
354 | { | 356 | { |
355 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 357 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
356 | state = Forbidden; | 358 | state = Forbidden; |
357 | return FALSE; | 359 | return FALSE; |
358 | } | 360 | } |
359 | return TRUE; | 361 | return TRUE; |
360 | } | 362 | } |
361 | 363 | ||
362 | void ServerPI::connectionClosed() | 364 | void ServerPI::connectionClosed() |
363 | { | 365 | { |
364 | // qDebug( "Debug: Connection closed" ); | 366 | // qDebug( "Debug: Connection closed" ); |
365 | emit connectionClosed(this); | 367 | emit connectionClosed(this); |
366 | } | 368 | } |
367 | 369 | ||
368 | void ServerPI::send( const QString& msg ) | 370 | void ServerPI::send( const QString& msg ) |
369 | { | 371 | { |
370 | QTextStream os( this ); | 372 | QTextStream os( this ); |
371 | os << msg << endl; | 373 | os << msg << endl; |
372 | //qDebug( "Reply: %s", msg.latin1() ); | 374 | //qDebug( "Reply: %s", msg.latin1() ); |
373 | } | 375 | } |
374 | 376 | ||
375 | void ServerPI::read() | 377 | void ServerPI::read() |
376 | { | 378 | { |
377 | while ( canReadLine() ) | 379 | while ( canReadLine() ) |
378 | process( readLine().stripWhiteSpace() ); | 380 | process( readLine().stripWhiteSpace() ); |
379 | } | 381 | } |
380 | 382 | ||
381 | bool ServerPI::checkReadFile( const QString& file ) | 383 | bool ServerPI::checkReadFile( const QString& file ) |
382 | { | 384 | { |
383 | QString filename; | 385 | QString filename; |
384 | 386 | ||
385 | if ( file[0] != "/" ) | 387 | if ( file[0] != "/" ) |
386 | filename = directory.path() + "/" + file; | 388 | filename = directory.path() + "/" + file; |
387 | else | 389 | else |
388 | filename = file; | 390 | filename = file; |
389 | 391 | ||
390 | QFileInfo fi( filename ); | 392 | QFileInfo fi( filename ); |
391 | return ( fi.exists() && fi.isReadable() ); | 393 | return ( fi.exists() && fi.isReadable() ); |
392 | } | 394 | } |
393 | 395 | ||
394 | bool ServerPI::checkWriteFile( const QString& file ) | 396 | bool ServerPI::checkWriteFile( const QString& file ) |
395 | { | 397 | { |
396 | QString filename; | 398 | QString filename; |
397 | 399 | ||
398 | if ( file[0] != "/" ) | 400 | if ( file[0] != "/" ) |
399 | filename = directory.path() + "/" + file; | 401 | filename = directory.path() + "/" + file; |
400 | else | 402 | else |
401 | filename = file; | 403 | filename = file; |
402 | 404 | ||
403 | QFileInfo fi( filename ); | 405 | QFileInfo fi( filename ); |
404 | 406 | ||
405 | if ( fi.exists() ) | 407 | if ( fi.exists() ) |
406 | if ( !QFile( filename ).remove() ) | 408 | if ( !QFile( filename ).remove() ) |
407 | return FALSE; | 409 | return FALSE; |
408 | return TRUE; | 410 | return TRUE; |
409 | } | 411 | } |
410 | 412 | ||
411 | void ServerPI::process( const QString& message ) | 413 | void ServerPI::process( const QString& message ) |
412 | { | 414 | { |
413 | //qDebug( "Command: %s", message.latin1() ); | 415 | //qDebug( "Command: %s", message.latin1() ); |
414 | 416 | ||
415 | // split message using "," as separator | 417 | // split message using "," as separator |
416 | QStringList msg = QStringList::split( " ", message ); | 418 | QStringList msg = QStringList::split( " ", message ); |
417 | if ( msg.isEmpty() ) return; | 419 | if ( msg.isEmpty() ) return; |
418 | 420 | ||
419 | // command token | 421 | // command token |
420 | QString cmd = msg[0].upper(); | 422 | QString cmd = msg[0].upper(); |
421 | 423 | ||
422 | // argument token | 424 | // argument token |
423 | QString arg; | 425 | QString arg; |
424 | if ( msg.count() >= 2 ) | 426 | if ( msg.count() >= 2 ) |
425 | arg = msg[1]; | 427 | arg = msg[1]; |
426 | 428 | ||
427 | // full argument string | 429 | // full argument string |
428 | QString args; | 430 | QString args; |
429 | if ( msg.count() >= 2 ) { | 431 | if ( msg.count() >= 2 ) { |
430 | QStringList copy( msg ); | 432 | QStringList copy( msg ); |
431 | // FIXME: for Qt3 | 433 | // FIXME: for Qt3 |
432 | // copy.pop_front() | 434 | // copy.pop_front() |
433 | copy.remove( copy.begin() ); | 435 | copy.remove( copy.begin() ); |
434 | args = copy.join( " " ); | 436 | args = copy.join( " " ); |
435 | } | 437 | } |
436 | 438 | ||
437 | //qDebug( "args: %s", args.latin1() ); | 439 | //qDebug( "args: %s", args.latin1() ); |
438 | 440 | ||
439 | // we always respond to QUIT, regardless of state | 441 | // we always respond to QUIT, regardless of state |
440 | if ( cmd == "QUIT" ) { | 442 | if ( cmd == "QUIT" ) { |
441 | send( "211 Good bye!" ); // No tr | 443 | send( "211 Good bye!" ); // No tr |
442 | close(); | 444 | close(); |
443 | return; | 445 | return; |
444 | } | 446 | } |