summaryrefslogtreecommitdiff
authorzecke <zecke>2002-07-12 13:51:37 (UTC)
committer zecke <zecke>2002-07-12 13:51:37 (UTC)
commit716211b5e06bb25145cfbcf62a11a7c52c79dde5 (patch) (side-by-side diff)
tree595c4c15cb0ca31f2579be42ee029c1c30454b9c
parent7c12000481b535ce54951ef8a53b439814f8fcd6 (diff)
downloadopie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.zip
opie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.tar.gz
opie-716211b5e06bb25145cfbcf62a11a7c52c79dde5.tar.bz2
Security fix by trolltech
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/desktop.cpp4
-rw-r--r--core/launcher/launcher.pro2
-rw-r--r--core/launcher/qcopbridge.cpp100
-rw-r--r--core/launcher/qcopbridge.h7
-rw-r--r--core/launcher/transferserver.cpp207
-rw-r--r--core/launcher/transferserver.h23
6 files changed, 227 insertions, 116 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 24dce73..541b4be 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -568,4 +568,4 @@ void Desktop::execAutoStart() {
e << QString(appName);
- } else {
- }
+ } //else {
+ //}
}
diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro
index ccf8231..169edc1 100644
--- a/core/launcher/launcher.pro
+++ b/core/launcher/launcher.pro
@@ -101,3 +101,3 @@ DEPENDPATH += $(OPIEDIR)/rsync
TARGET = qpe
-LIBS += -lqpe -lcrypt -lopie
+LIBS += -lqpe -lcrypt -lopie -luuid
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 2d084fc..85993ee 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,5 +1,5 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
@@ -23,4 +23,7 @@
+#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
+#endif
#include <qpe/qpeapplication.h>
+#include <qpe/version.h>
@@ -33,9 +36,7 @@
#include <qregexp.h>
+#ifdef QWS
#include <qcopchannel_qws.h>
+#endif
-// actually this is wrong, _XOPEN_SOURCE should get defined on the commandline
-// and it should have a proper value assigned. (Simon)
-#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE
-#endif
#include <pwd.h>
@@ -61,2 +62,3 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
else {
+#ifndef QT_NO_COP
desktopChannel = new QCopChannel( "QPE/Desktop", this );
@@ -67,2 +69,3 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
+#endif
}
@@ -73,3 +76,5 @@ QCopBridge::~QCopBridge()
{
+#ifndef QT_NO_COP
delete desktopChannel;
+#endif
}
@@ -81,3 +86,5 @@ void QCopBridge::newConnection( int socket )
connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) );
+#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
+#endif
@@ -93,3 +100,5 @@ void QCopBridge::connectionClosed( QCopBridgePI *pi )
if ( openConnections.count() == 0 ) {
+#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
+#endif
}
@@ -144,10 +153,28 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args
} else {
- qDebug(" cannot route the argument type %s through the qcop bridge", (*it).latin1() );
+ qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
return;
}
- str.replace( QRegExp("&"), "&amp;" );
- str.replace( QRegExp(" "), "&0x20;" );
- str.replace( QRegExp("\n"), "&0x0d;" );
- str.replace( QRegExp("\r"), "&0x0a;" );
- data += " " + str;
+ QString estr;
+ for (int i=0; i<(int)str.length(); i++) {
+ QChar ch = str[i];
+ if ( ch.row() )
+ goto quick;
+ switch (ch.cell()) {
+ case '&':
+ estr.append( "&amp;" );
+ break;
+ case ' ':
+ estr.append( "&0x20;" );
+ break;
+ case '\n':
+ estr.append( "&0x0d;" );
+ break;
+ case '\r':
+ estr.append( "&0x0a;" );
+ break;
+ default: quick:
+ estr.append(ch);
+ }
+ }
+ data += " " + estr;
}
@@ -184,3 +211,3 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
#ifndef INSECURE
- if ( !accessAuthorized(peeraddress) ) {
+ if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
state = Forbidden;
@@ -195,3 +222,8 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
- send( "220 Qtopia QCop bridge ready!" );
+ QString intro="220 Qtopia ";
+ intro += QPE_VERSION; intro += ";";
+ intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";";
+ intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
+ intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
+ send( intro );
state = Wait_USER;
@@ -237,33 +269,2 @@ void QCopBridgePI::read()
-bool QCopBridgePI::checkUser( const QString& user )
-{
- if ( user.isEmpty() ) return FALSE;
-
- struct passwd *pw;
- pw = getpwuid( geteuid() );
- QString euser = QString::fromLocal8Bit( pw->pw_name );
- return user == euser;
-}
-
-bool QCopBridgePI::checkPassword( const QString& password )
-{
- // ### HACK for testing on local host
- return true;
-
- /*
- struct passwd *pw = 0;
- struct spwd *spw = 0;
-
- pw = getpwuid( geteuid() );
- spw = getspnam( pw->pw_name );
-
- QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
- if ( cpwd == "x" && spw )
- cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
-
- QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
- return cpwd == cpassword;
-*/
-}
-
void QCopBridgePI::process( const QString& message )
@@ -298,3 +299,3 @@ void QCopBridgePI::process( const QString& message )
- if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) {
+ if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
send( "530 Please login with USER and PASS" );
@@ -310,4 +311,3 @@ void QCopBridgePI::process( const QString& message )
- if ( cmd != "PASS" || !checkPassword( arg ) ) {
- //if ( cmd != "PASS" || msg.count() < 2 || !checkPassword( arg ) ) {
+ if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
send( "530 Please login with USER and PASS" );
@@ -391,2 +391,3 @@ void QCopBridgePI::process( const QString& message )
+#ifndef QT_NO_COP
if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
@@ -397,3 +398,5 @@ void QCopBridgePI::process( const QString& message )
}
+#endif
+#ifndef QT_NO_COP
if ( paramList.count() )
@@ -404,2 +407,3 @@ void QCopBridgePI::process( const QString& message )
send( "200 Command okay" );
+#endif
}
diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h
index 114b3ee..408d10d 100644
--- a/core/launcher/qcopbridge.h
+++ b/core/launcher/qcopbridge.h
@@ -1,5 +1,5 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
@@ -81,5 +81,2 @@ protected slots:
protected:
- bool checkUser( const QString& user );
- bool checkPassword( const QString& pw );
-
void timerEvent( QTimerEvent *e );
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 7294f9c..a6dab07 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,5 +1,5 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
@@ -24,2 +24,9 @@
#include <stdlib.h>
+#include <time.h>
+#include <shadow.h>
+
+extern "C" {
+#include <uuid/uuid.h>
+#define UUID_H_INCLUDED
+}
@@ -39,4 +46,10 @@
#include <qpe/process.h>
+#include <qpe/global.h>
#include <qpe/config.h>
+#include <qpe/contact.h>
+#include <qpe/quuid.h>
+#include <qpe/version.h>
+#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
+#endif
@@ -65,3 +78,36 @@ void TransferServer::newConnection( int socket )
-bool accessAuthorized(QHostAddress peeraddress)
+QString SyncAuthentication::serverId()
+{
+ Config cfg("Security");
+ cfg.setGroup("Sync");
+ QString r=cfg.readEntry("serverid");
+ if ( r.isEmpty() ) {
+ uuid_t uuid;
+ uuid_generate( uuid );
+ cfg.writeEntry("serverid",(r = QUuid( uuid ).toString()));
+ }
+ return r;
+}
+
+QString SyncAuthentication::ownerName()
+{
+ QString vfilename = Global::applicationFileName("addressbook",
+ "businesscard.vcf");
+ if (QFile::exists(vfilename)) {
+ Contact c;
+ c = Contact::readVCard( vfilename )[0];
+ return c.fullName();
+ }
+
+ return "";
+}
+
+QString SyncAuthentication::loginName()
+{
+ struct passwd *pw;
+ pw = getpwuid( geteuid() );
+ return QString::fromLocal8Bit( pw->pw_name );
+}
+
+int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
{
@@ -69,16 +115,89 @@ bool accessAuthorized(QHostAddress peeraddress)
cfg.setGroup("Sync");
- uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100);
+ QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
+ QHostAddress allowed;
+ allowed.setAddress(allowedstr);
+ uint auth_peer = allowed.ip4Addr();
uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
- bool ok = (peeraddress.ip4Addr() & (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)))
- == auth_peer;
- /* Allows denial-of-service attack.
- if ( !ok ) {
- QMessageBox::warning(0,tr("Security"),
- tr("<p>An attempt to access this device from %1 has been denied.")
- .arg(peeraddress.toString()));
+ uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
+ ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits));
+ return (peeraddress.ip4Addr() & mask) == auth_peer;
+}
+
+bool SyncAuthentication::checkUser( const QString& user )
+{
+ if ( user.isEmpty() ) return FALSE;
+ QString euser = loginName();
+ return user == euser;
+}
+
+bool SyncAuthentication::checkPassword( const QString& password )
+{
+#ifdef ALLOW_UNIX_USER_FTP
+ // First, check system password...
+
+ struct passwd *pw = 0;
+ struct spwd *spw = 0;
+
+ pw = getpwuid( geteuid() );
+ spw = getspnam( pw->pw_name );
+
+ QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
+ if ( cpwd == "x" && spw )
+ cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
+
+ // Note: some systems use more than crypt for passwords.
+ QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
+ if ( cpwd == cpassword )
+ return TRUE;
+#endif
+
+ static int lastdenial=0;
+ static int denials=0;
+ int now = time(0);
+
+ // Detect old Qtopia Desktop (no password)
+ if ( password.isEmpty() ) {
+ if ( denials < 1 || now > lastdenial+600 ) {
+ QMessageBox::warning( 0,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."),
+ tr("Deny") );
+ denials++;
+ lastdenial=now;
}
- */
- return ok;
+ return FALSE;
}
+ // Second, check sync password...
+ if ( password.left(6) == "Qtopia" ) {
+ QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
+ Config cfg("Security");
+ cfg.setGroup("Sync");
+ QString pwds = cfg.readEntry("Passwords");
+ if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
+ return TRUE;
+
+ // Unrecognized system. Be careful...
+
+ if ( (denials > 2 && now < lastdenial+600)
+ || QMessageBox::warning(0,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."),
+ tr("Allow"),tr("Deny"))==1 )
+ {
+ denials++;
+ lastdenial=now;
+ return FALSE;
+ } else {
+ denials=0;
+ cfg.writeEntry("Passwords",pwds+" "+cpassword);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
ServerPI::ServerPI( int socket, QObject *parent, const char* name )
@@ -94,3 +213,3 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name )
#ifndef INSECURE
- if ( !accessAuthorized(peeraddress) ) {
+ if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
state = Forbidden;
@@ -107,3 +226,3 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name )
- send( "220 Qtopia transfer service ready!" );
+ send( "220 Qtopia " QPE_VERSION " FTP Server" );
state = Wait_USER;
@@ -153,33 +272,2 @@ void ServerPI::read()
-bool ServerPI::checkUser( const QString& user )
-{
- if ( user.isEmpty() ) return FALSE;
-
- struct passwd *pw;
- pw = getpwuid( geteuid() );
- QString euser = QString::fromLocal8Bit( pw->pw_name );
- return user == euser;
-}
-
-bool ServerPI::checkPassword( const QString& /* password */ )
-{
- // ### HACK for testing on local host
- return true;
-
- /*
- struct passwd *pw = 0;
- struct spwd *spw = 0;
-
- pw = getpwuid( geteuid() );
- spw = getspnam( pw->pw_name );
-
- QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
- if ( cpwd == "x" && spw )
- cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
-
- QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
- return cpwd == cpassword;
-*/
-}
-
bool ServerPI::checkReadFile( const QString& file )
@@ -256,3 +344,3 @@ void ServerPI::process( const QString& message )
- if ( cmd != "USER" || msg.count() < 2 || !checkUser( arg ) ) {
+ if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
send( "530 Please login with USER and PASS" );
@@ -268,4 +356,3 @@ void ServerPI::process( const QString& message )
- if ( cmd != "PASS" || !checkPassword( arg ) ) {
- //if ( cmd != "PASS" || msg.count() < 2 || !checkPassword( arg ) ) {
+ if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
send( "530 Please login with USER and PASS" );
@@ -456,5 +543,7 @@ void ServerPI::process( const QString& message )
QFile file( absFilePath( args ) ) ;
- if ( file.remove() )
+ if ( file.remove() ) {
send( "250 Requested file action okay, completed" );
- else
+ QCopEnvelope e("QPE/System", "linkChanged(QString)" );
+ e << file.name();
+ } else {
send( "550 Requested action not taken" );
@@ -462,2 +551,3 @@ void ServerPI::process( const QString& message )
}
+ }
@@ -636,5 +726,12 @@ void ServerPI::dtpCompleted()
{
- dtp->close();
- waitsocket = 0;
send( "226 Closing data connection, file transfer successful" );
+ if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) {
+ QString fn = dtp->fileName();
+ if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) {
+ QCopEnvelope e("QPE/System", "linkChanged(QString)" );
+ e << fn;
+ }
+ }
+ waitsocket = 0;
+ dtp->close();
}
@@ -854,3 +951,3 @@ void ServerPI::timerEvent( QTimerEvent * )
-ServerDTP::ServerDTP( QObject *parent, const char* name )
+ServerDTP::ServerDTP( QObject *parent = 0, const char* name = 0)
: QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ),
@@ -893,4 +990,6 @@ void ServerDTP::extractTarDone()
qDebug("extract done");
+#ifndef QT_NO_COP
QCopEnvelope e( "QPE/Desktop", "restoreDone(QString)" );
e << file.name();
+#endif
}
diff --git a/core/launcher/transferserver.h b/core/launcher/transferserver.h
index 076e460..a3bb060 100644
--- a/core/launcher/transferserver.h
+++ b/core/launcher/transferserver.h
@@ -1,5 +1,5 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
@@ -38,2 +38,16 @@ public:
+class SyncAuthentication : QObject
+{
+ Q_OBJECT
+
+public:
+ static int isAuthorized(QHostAddress peeraddress);
+ static bool checkPassword(const QString& pw);
+ static bool checkUser(const QString& user);
+
+ static QString serverId();
+ static QString loginName();
+ static QString ownerName();
+};
+
@@ -67,2 +81,3 @@ public:
QByteArray buffer() { return buf.buffer(); }
+ QString fileName() const { return file.name(); }
@@ -133,4 +148,2 @@ protected slots:
protected:
- bool checkUser( const QString& user );
- bool checkPassword( const QString& pw );
bool checkReadFile( const QString& file );
@@ -166,3 +179 @@ private:
};
-
-bool accessAuthorized(QHostAddress peeraddress);