summaryrefslogtreecommitdiff
authorzecke <zecke>2004-12-20 21:58:55 (UTC)
committer zecke <zecke>2004-12-20 21:58:55 (UTC)
commit5f35158ba0e7c2813768aaab6d6ad478dc0271a1 (patch) (side-by-side diff)
treea4d6e8000e14ecd4e48ffee18fba733f78fbd0a7
parent7479e7ac142eb830329fb08f16179bb3aca642e5 (diff)
downloadopie-5f35158ba0e7c2813768aaab6d6ad478dc0271a1.zip
opie-5f35158ba0e7c2813768aaab6d6ad478dc0271a1.tar.gz
opie-5f35158ba0e7c2813768aaab6d6ad478dc0271a1.tar.bz2
Restore lost change
-Kill Config instance in different scope for the same file -Work when a ftp client sends -la in a listdir request
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 1d4ca40..2b2e435 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -187,97 +187,96 @@ bool SyncAuthentication::checkPassword( const QString& password )
QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
switch( unauth.exec() ) {
case QMessageBox::Ok:
return TRUE;
break;
case QMessageBox::Cancel:
default:
denials++;
lastdenial=now;
return FALSE;
}
}
// Detect old Qtopia Desktop (no password) and fail
if ( password.isEmpty() ) {
if ( denials < 3 || now > lastdenial+600 ) {
QMessageBox unauth(
tr("Sync Connection"),
tr("<p>An unauthorized system is requesting access to this device."
"<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
"please upgrade or change the security setting to use IntelliSync." ),
QMessageBox::Warning,
QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
unauth.exec();
denials++;
lastdenial=now;
}
return FALSE;
}
// Second, check sync password...
static int lock=0;
if ( lock ) return FALSE;
++lock;
/*
* we need to support old Sync software and QtopiaDesktop
*/
if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
- Config cfg( "Security" );
cfg.setGroup("Sync");
QStringList pwds = cfg.readListEntry("Passwords",' ');
for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
#ifndef Q_OS_WIN32
QString cpassword = QString::fromLocal8Bit(
crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
#else
// ### revise
QString cpassword("");
#endif
if ( *it == cpassword ) {
lock--;
return TRUE;
}
}
// Unrecognized system. Be careful...
QMessageBox unrecbox(
tr("Sync Connection"),
tr( "<p>An unrecognized system is requesting access to this device."
"<p>If you have just initiated a Sync for the first time, this is normal."),
QMessageBox::Warning,
QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
0, QString::null, TRUE, WStyle_StaysOnTop);
unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
if ( (denials > 2 && now < lastdenial+600)
|| unrecbox.exec() != QMessageBox::Yes)
{
denials++;
lastdenial=now;
lock--;
return FALSE;
} else {
const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
char salt[2];
salt[0]= salty[rand() % (sizeof(salty)-1)];
salt[1]= salty[rand() % (sizeof(salty)-1)];
#ifndef Q_OS_WIN32
QString cpassword = QString::fromLocal8Bit(
crypt( password.mid(8).local8Bit(), salt ) );
#else
//### revise
QString cpassword("");
#endif
denials=0;
pwds.prepend(cpassword);
@@ -335,98 +334,100 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name )
serversocket = new ServerSocket( ++p, this );
}
connect( serversocket, SIGNAL( newIncomming(int) ),
SLOT( newConnection(int) ) );
}
}
ServerPI::~ServerPI()
{
close();
if ( dtp )
dtp->close();
delete dtp;
delete serversocket;
}
bool ServerPI::verifyAuthorised()
{
if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
state = Forbidden;
return FALSE;
}
return TRUE;
}
void ServerPI::connectionClosed()
{
// odebug << "Debug: Connection closed" << oendl;
emit connectionClosed(this);
}
void ServerPI::send( const QString& msg )
{
QTextStream os( this );
os << msg << endl;
//odebug << "Reply: " << msg << "" << oendl;
}
void ServerPI::read()
{
while ( canReadLine() )
process( readLine().stripWhiteSpace() );
}
bool ServerPI::checkReadFile( const QString& file )
{
QString filename;
-
- if ( file[0] != "/" )
+
+ if ( file.length() == 1 && file[0] == "/" )
+ filename = file;
+ else if ( file[0] != "/" )
filename = directory.path() + "/" + file;
else
filename = file;
QFileInfo fi( filename );
return ( fi.exists() && fi.isReadable() );
}
bool ServerPI::checkWriteFile( const QString& file )
{
QString filename;
if ( file[0] != "/" )
filename = directory.path() + "/" + file;
else
filename = file;
QFileInfo fi( filename );
if ( fi.exists() )
if ( !QFile( filename ).remove() )
return FALSE;
return TRUE;
}
void ServerPI::process( const QString& message )
{
//odebug << "Command: " << message << "" << oendl;
// split message using "," as separator
QStringList msg = QStringList::split( " ", message );
if ( msg.isEmpty() ) return;
// command token
QString cmd = msg[0].upper();
// argument token
QString arg;
if ( msg.count() >= 2 )
arg = msg[1];
// full argument string
QString args;
if ( msg.count() >= 2 ) {
QStringList copy( msg );
// FIXME: for Qt3
// copy.pop_front()
copy.remove( copy.begin() );
@@ -652,96 +653,99 @@ void ServerPI::process( const QString& message )
send( "500 Syntax error, command unrecognized" ); // No tr
else {
QFile file( absFilePath( args ) ) ;
if ( file.remove() ) {
send( "250 Requested file action okay, completed" ); // No tr
QCopEnvelope e("QPE/System", "linkChanged(QString)" );
e << file.name();
} else {
send( "550 Requested action not taken" ); // No tr
}
}
}
// remove directory (RMD)
else if ( cmd == "RMD" ) {
if ( args.isEmpty() )
send( "500 Syntax error, command unrecognized" ); // No tr
else {
QDir dir;
if ( dir.rmdir( absFilePath( args ), TRUE ) )
send( "250 Requested file action okay, completed" ); // No tr
else
send( "550 Requested action not taken" ); // No tr
}
}
// make directory (MKD)
else if ( cmd == "MKD" ) {
if ( args.isEmpty() ) {
odebug << " Error: no arg" << oendl;
send( "500 Syntax error, command unrecognized" ); // No tr
}
else {
QDir dir;
if ( dir.mkdir( absFilePath( args ), TRUE ) )
send( "250 Requested file action okay, completed." ); // No tr
else
send( "550 Requested action not taken" ); // No tr
}
}
// print working directory (PWD)
else if ( cmd == "PWD" ) {
send( "257 \"" + directory.path() +"\"" );
}
// list (LIST)
else if ( cmd == "LIST" ) {
+ if ( args == "-la" )
+ args = QString::null;
+
if ( sendList( absFilePath( args ) ) )
send( "150 File status okay" ); // No tr
else
send( "500 Syntax error, command unrecognized" ); // No tr
}
// size (SIZE)
else if ( cmd == "SIZE" ) {
QString filePath = absFilePath( args );
QFileInfo fi( filePath );
bool gzipfile = backupRestoreGzip( filePath );
if ( !fi.exists() && !gzipfile )
send( "500 Syntax error, command unrecognized" ); // No tr
else {
if ( !gzipfile )
send( "213 " + QString::number( fi.size() ) );
else {
Process duproc( QString("du") );
duproc.addArgument("-s");
QString in, out;
if ( !duproc.exec(in, out) ) {
odebug << "du process failed; just sending back 1K" << oendl;
send( "213 1024");
}
else {
QString size = out.left( out.find("\t") );
int guess = size.toInt()/5;
if ( filePath.contains("doc") ) // No tr
guess *= 1000;
odebug << "sending back gzip guess of " << guess << "" << oendl;
send( "213 " + QString::number(guess) );
}
}
}
}
// name list (NLST)
else if ( cmd == "NLST" ) {
send( "502 Command not implemented" ); // No tr
}
// site parameters (SITE)
else if ( cmd == "SITE" ) {
send( "502 Command not implemented" ); // No tr
}
// system (SYST)
else if ( cmd == "SYST" ) {
send( "215 UNIX Type: L8" ); // No tr