summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-21 13:09:17 (UTC)
committer zecke <zecke>2004-02-21 13:09:17 (UTC)
commit4024cfd1e32a43d82361d6ba9977fe64db88e3ce (patch) (side-by-side diff)
tree1d2e0592a3df330a17d9a07cd2f29615ce5be595
parentaa11789fc4d735a04fac09063851753d8a57027b (diff)
downloadopie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.zip
opie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.tar.gz
opie-4024cfd1e32a43d82361d6ba9977fe64db88e3ce.tar.bz2
Fix up syncing mode
InetlliSync,Opie1.0,QtopiaNEW
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qcopbridge.cpp2
-rw-r--r--core/launcher/qcopbridge.h3
-rw-r--r--core/launcher/transferserver.cpp36
3 files changed, 30 insertions, 11 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index b45f0cc..9bca360 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -120,97 +120,97 @@ void QCopBridge::newConnection( int socket )
#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
#endif
if ( sendSync ) {
pi ->startSync();
sendSync = FALSE;
}
}
void QCopBridge::closed( QCopBridgePI *pi )
{
emit connectionClosed( pi->peerAddress() );
openConnections.removeRef( pi );
if ( openConnections.count() == 0 ) {
/* ### FIXME libqtopia merge */
#if 0
QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
#endif
#ifndef QT_NO_COP
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
#endif
}
}
void QCopBridge::closeOpenConnections()
{
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
pi->close();
}
void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
{
if ( command == "startSync()" ) {
// we need to buffer it a bit
sendSync = TRUE;
startTimer( 20000 );
}
if ( m_mode & Qtopia1_7 ) {
// send the command to all open connections
QCopBridgePI *pi;
for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
pi->sendDesktopMessage( command, data );
}
}
- if ( m_mode & Sharp )
+ if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
sendDesktopMessageOld( command, data );
}
#ifndef OPIE_NO_OLD_SYNC_CODE
/*
* Old compat mode
*/
void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
command.stripWhiteSpace();
int paren = command.find( "(" );
if ( paren <= 0 ) {
qDebug("DesktopMessage: bad qcop syntax");
return;
}
QString params = command.mid( paren + 1 );
if ( params[params.length()-1] != ')' ) {
qDebug("DesktopMessage: bad qcop syntax");
return;
}
params.truncate( params.length()-1 );
QStringList paramList = QStringList::split( ",", params );
QString data;
if ( paramList.count() ) {
QDataStream stream( args, IO_ReadOnly );
for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
QString str;
if ( *it == "QString" ) {
stream >> str;
} else if ( *it == "QCString" ) {
QCString cstr;
stream >> cstr;
str = QString::fromLocal8Bit( cstr );
} else if ( *it == "int" ) {
int i;
stream >> i;
str = QString::number( i );
} else if ( *it == "bool" ) {
int i;
stream >> i;
str = QString::number( i );
} else {
qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
return;
}
diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h
index 9483d9d..d5988cd 100644
--- a/core/launcher/qcopbridge.h
+++ b/core/launcher/qcopbridge.h
@@ -1,88 +1,89 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __qcopbridge_h__
#define __qcopbridge_h__
#include <qtopia/global.h>
#include <qserversocket.h>
#include <qsocket.h>
#include <qdir.h>
#include <qfile.h>
#include <qbuffer.h>
class QFileInfo;
class QCopBridgePI;
class QCopChannel;
class QTimer;
class QCopBridge : public QServerSocket
{
Q_OBJECT
public:
- enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, Both = Qtopia1_7 | Sharp };
+ /* can not or anymore :) */
+ enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, IntelliSync = 0x04 };
QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
virtual ~QCopBridge();
void newConnection( int socket );
void closeOpenConnections();
void authorizeConnections();
public slots:
void closed( QCopBridgePI *pi );
void desktopMessage( const QCString &call, const QByteArray & );
signals:
void connectionClosed( const QHostAddress & );
protected:
void timerEvent( QTimerEvent * );
void sendDesktopMessageOld( const QCString&, const QByteArray& );
private:
QCopChannel *desktopChannel;
QCopChannel *cardChannel;
QList<QCopBridgePI> openConnections;
bool sendSync;
Mode m_mode;
};
class QCopBridgePI : public QSocket
{
Q_OBJECT
enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
public:
QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 );
virtual ~QCopBridgePI();
void sendDesktopMessage( const QString &msg );
void sendDesktopMessage( const QCString &msg, const QByteArray& );
void startSync() { sendSync = TRUE; }
bool verifyAuthorised();
signals:
void connectionClosed( QCopBridgePI *);
protected slots:
void read();
void send( const QString& msg );
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 9cb9d7a..8367a62 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -149,105 +149,123 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
Config cfg("Security");
cfg.setGroup("Sync");
// QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
// QHostAddress allowed;
// allowed.setAddress(allowedstr);
// uint auth_peer = allowed.ip4Addr();
uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
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);
Config cfg("Security");
- cfg.setGroup("Sync");
- QString syncapp = cfg.readEntry("syncapp","Qtopia");
-
- //No password needed if the user really wants it
- if (syncapp == "IntelliSync") {
- return TRUE;
- }
-
- // Detect old Qtopia Desktop (no password)
+ cfg.setGroup("SyncMode");
+ int mode = cfg.readNumEntry("Mode", 0x02 );
+
+ //No pass word needed if the user really needs it
+ if (mode & 0x04) {
+ QMessageBox unauth(
+ tr("Sync Connection"),
+ tr("<qt><p>An unauthorized system is requesting access to this device."
+ "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
+ QMessageBox::Warning,
+ 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;
}
}