summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-21 13:09:17 (UTC)
committer zecke <zecke>2004-02-21 13:09:17 (UTC)
commit4024cfd1e32a43d82361d6ba9977fe64db88e3ce (patch) (unidiff)
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
@@ -72,193 +72,193 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
72 qWarning( "Failed to bind to port %d", port ); 72 qWarning( "Failed to bind to port %d", port );
73 else { 73 else {
74#ifndef QT_NO_COP 74#ifndef QT_NO_COP
75 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 75 desktopChannel = new QCopChannel( "QPE/Desktop", this );
76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
78 cardChannel = new QCopChannel( "QPE/Card", this ); 78 cardChannel = new QCopChannel( "QPE/Card", this );
79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
81#endif 81#endif
82 } 82 }
83 sendSync = FALSE; 83 sendSync = FALSE;
84 openConnections.setAutoDelete( TRUE ); 84 openConnections.setAutoDelete( TRUE );
85 authorizeConnections(); 85 authorizeConnections();
86} 86}
87 87
88QCopBridge::~QCopBridge() 88QCopBridge::~QCopBridge()
89{ 89{
90#ifndef QT_NO_COP 90#ifndef QT_NO_COP
91 delete desktopChannel; 91 delete desktopChannel;
92#endif 92#endif
93} 93}
94 94
95void QCopBridge::authorizeConnections() 95void QCopBridge::authorizeConnections()
96{ 96{
97 Config cfg("Security"); 97 Config cfg("Security");
98 cfg.setGroup("SyncMode"); 98 cfg.setGroup("SyncMode");
99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
100 QListIterator<QCopBridgePI> it(openConnections); 100 QListIterator<QCopBridgePI> it(openConnections);
101 while ( it.current() ) { 101 while ( it.current() ) {
102 if ( !it.current()->verifyAuthorised() ) { 102 if ( !it.current()->verifyAuthorised() ) {
103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
104 openConnections.removeRef( it.current() ); 104 openConnections.removeRef( it.current() );
105 } else 105 } else
106 ++it; 106 ++it;
107 } 107 }
108} 108}
109 109
110void QCopBridge::newConnection( int socket ) 110void QCopBridge::newConnection( int socket )
111{ 111{
112 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 112 QCopBridgePI *pi = new QCopBridgePI( socket, this );
113 openConnections.append( pi ); 113 openConnections.append( pi );
114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
115 115
116 /* ### libqtopia merge FIXME */ 116 /* ### libqtopia merge FIXME */
117#if 0 117#if 0
118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); 118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
119#endif 119#endif
120#ifndef QT_NO_COP 120#ifndef QT_NO_COP
121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
122#endif 122#endif
123 123
124 if ( sendSync ) { 124 if ( sendSync ) {
125 pi ->startSync(); 125 pi ->startSync();
126 sendSync = FALSE; 126 sendSync = FALSE;
127 } 127 }
128} 128}
129 129
130void QCopBridge::closed( QCopBridgePI *pi ) 130void QCopBridge::closed( QCopBridgePI *pi )
131{ 131{
132 emit connectionClosed( pi->peerAddress() ); 132 emit connectionClosed( pi->peerAddress() );
133 openConnections.removeRef( pi ); 133 openConnections.removeRef( pi );
134 if ( openConnections.count() == 0 ) { 134 if ( openConnections.count() == 0 ) {
135 /* ### FIXME libqtopia merge */ 135 /* ### FIXME libqtopia merge */
136#if 0 136#if 0
137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); 137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
138#endif 138#endif
139#ifndef QT_NO_COP 139#ifndef QT_NO_COP
140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
141#endif 141#endif
142 } 142 }
143} 143}
144 144
145void QCopBridge::closeOpenConnections() 145void QCopBridge::closeOpenConnections()
146{ 146{
147 QCopBridgePI *pi; 147 QCopBridgePI *pi;
148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
149 pi->close(); 149 pi->close();
150} 150}
151 151
152 152
153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) 153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
154{ 154{
155 if ( command == "startSync()" ) { 155 if ( command == "startSync()" ) {
156 // we need to buffer it a bit 156 // we need to buffer it a bit
157 sendSync = TRUE; 157 sendSync = TRUE;
158 startTimer( 20000 ); 158 startTimer( 20000 );
159 } 159 }
160 160
161 if ( m_mode & Qtopia1_7 ) { 161 if ( m_mode & Qtopia1_7 ) {
162 // send the command to all open connections 162 // send the command to all open connections
163 QCopBridgePI *pi; 163 QCopBridgePI *pi;
164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
165 pi->sendDesktopMessage( command, data ); 165 pi->sendDesktopMessage( command, data );
166 } 166 }
167 } 167 }
168 if ( m_mode & Sharp ) 168 if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) )
169 sendDesktopMessageOld( command, data ); 169 sendDesktopMessageOld( command, data );
170} 170}
171 171
172#ifndef OPIE_NO_OLD_SYNC_CODE 172#ifndef OPIE_NO_OLD_SYNC_CODE
173/* 173/*
174 * Old compat mode 174 * Old compat mode
175 */ 175 */
176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
177 command.stripWhiteSpace(); 177 command.stripWhiteSpace();
178 178
179 int paren = command.find( "(" ); 179 int paren = command.find( "(" );
180 if ( paren <= 0 ) { 180 if ( paren <= 0 ) {
181 qDebug("DesktopMessage: bad qcop syntax"); 181 qDebug("DesktopMessage: bad qcop syntax");
182 return; 182 return;
183 } 183 }
184 184
185 QString params = command.mid( paren + 1 ); 185 QString params = command.mid( paren + 1 );
186 if ( params[params.length()-1] != ')' ) { 186 if ( params[params.length()-1] != ')' ) {
187 qDebug("DesktopMessage: bad qcop syntax"); 187 qDebug("DesktopMessage: bad qcop syntax");
188 return; 188 return;
189 } 189 }
190 190
191 params.truncate( params.length()-1 ); 191 params.truncate( params.length()-1 );
192 192
193 QStringList paramList = QStringList::split( ",", params ); 193 QStringList paramList = QStringList::split( ",", params );
194 QString data; 194 QString data;
195 if ( paramList.count() ) { 195 if ( paramList.count() ) {
196 QDataStream stream( args, IO_ReadOnly ); 196 QDataStream stream( args, IO_ReadOnly );
197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
198 QString str; 198 QString str;
199 if ( *it == "QString" ) { 199 if ( *it == "QString" ) {
200 stream >> str; 200 stream >> str;
201 } else if ( *it == "QCString" ) { 201 } else if ( *it == "QCString" ) {
202 QCString cstr; 202 QCString cstr;
203 stream >> cstr; 203 stream >> cstr;
204 str = QString::fromLocal8Bit( cstr ); 204 str = QString::fromLocal8Bit( cstr );
205 } else if ( *it == "int" ) { 205 } else if ( *it == "int" ) {
206 int i; 206 int i;
207 stream >> i; 207 stream >> i;
208 str = QString::number( i ); 208 str = QString::number( i );
209 } else if ( *it == "bool" ) { 209 } else if ( *it == "bool" ) {
210 int i; 210 int i;
211 stream >> i; 211 stream >> i;
212 str = QString::number( i ); 212 str = QString::number( i );
213 } else { 213 } else {
214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
215 return; 215 return;
216 } 216 }
217 QString estr; 217 QString estr;
218 for (int i=0; i<(int)str.length(); i++) { 218 for (int i=0; i<(int)str.length(); i++) {
219 QChar ch = str[i]; 219 QChar ch = str[i];
220 if ( ch.row() ) 220 if ( ch.row() )
221 goto quick; 221 goto quick;
222 switch (ch.cell()) { 222 switch (ch.cell()) {
223 case '&': 223 case '&':
224 estr.append( "&amp;" ); 224 estr.append( "&amp;" );
225 break; 225 break;
226 case ' ': 226 case ' ':
227 estr.append( "&0x20;" ); 227 estr.append( "&0x20;" );
228 break; 228 break;
229 case '\n': 229 case '\n':
230 estr.append( "&0x0d;" ); 230 estr.append( "&0x0d;" );
231 break; 231 break;
232 case '\r': 232 case '\r':
233 estr.append( "&0x0a;" ); 233 estr.append( "&0x0a;" );
234 break; 234 break;
235 default: quick: 235 default: quick:
236 estr.append(ch); 236 estr.append(ch);
237 } 237 }
238 } 238 }
239 data += " " + estr; 239 data += " " + estr;
240 } 240 }
241 } 241 }
242 QString sendCommand = QString(command.data()) + data; 242 QString sendCommand = QString(command.data()) + data;
243 243
244 244
245 // send the command to all open connections 245 // send the command to all open connections
246 QCopBridgePI *pi; 246 QCopBridgePI *pi;
247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
248 pi->sendDesktopMessage( sendCommand ); 248 pi->sendDesktopMessage( sendCommand );
249 249
250} 250}
251#endif 251#endif
252 252
253 253
254void QCopBridge::timerEvent( QTimerEvent * ) 254void QCopBridge::timerEvent( QTimerEvent * )
255{ 255{
256 sendSync = FALSE; 256 sendSync = FALSE;
257 killTimers(); 257 killTimers();
258} 258}
259 259
260 260
261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
262 : QSocket( parent, name ) 262 : QSocket( parent, name )
263{ 263{
264 setSocket( socket ); 264 setSocket( socket );
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,100 +1,101 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __qcopbridge_h__ 20#ifndef __qcopbridge_h__
21#define __qcopbridge_h__ 21#define __qcopbridge_h__
22 22
23#include <qtopia/global.h> 23#include <qtopia/global.h>
24#include <qserversocket.h> 24#include <qserversocket.h>
25#include <qsocket.h> 25#include <qsocket.h>
26#include <qdir.h> 26#include <qdir.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qbuffer.h> 28#include <qbuffer.h>
29 29
30class QFileInfo; 30class QFileInfo;
31class QCopBridgePI; 31class QCopBridgePI;
32class QCopChannel; 32class QCopChannel;
33class QTimer; 33class QTimer;
34 34
35class QCopBridge : public QServerSocket 35class QCopBridge : public QServerSocket
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 38
39public: 39public:
40 enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, Both = Qtopia1_7 | Sharp }; 40 /* can not or anymore :) */
41 enum Mode { Qtopia1_7= 0x01, Sharp = 0x02, IntelliSync = 0x04 };
41 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 ); 42 QCopBridge( Q_UINT16 port, QObject *parent = 0, const char* name = 0 );
42 virtual ~QCopBridge(); 43 virtual ~QCopBridge();
43 44
44 void newConnection( int socket ); 45 void newConnection( int socket );
45 void closeOpenConnections(); 46 void closeOpenConnections();
46 void authorizeConnections(); 47 void authorizeConnections();
47 48
48public slots: 49public slots:
49 void closed( QCopBridgePI *pi ); 50 void closed( QCopBridgePI *pi );
50 void desktopMessage( const QCString &call, const QByteArray & ); 51 void desktopMessage( const QCString &call, const QByteArray & );
51 52
52signals: 53signals:
53 void connectionClosed( const QHostAddress & ); 54 void connectionClosed( const QHostAddress & );
54 55
55protected: 56protected:
56 void timerEvent( QTimerEvent * ); 57 void timerEvent( QTimerEvent * );
57 void sendDesktopMessageOld( const QCString&, const QByteArray& ); 58 void sendDesktopMessageOld( const QCString&, const QByteArray& );
58 59
59private: 60private:
60 QCopChannel *desktopChannel; 61 QCopChannel *desktopChannel;
61 QCopChannel *cardChannel; 62 QCopChannel *cardChannel;
62 QList<QCopBridgePI> openConnections; 63 QList<QCopBridgePI> openConnections;
63 bool sendSync; 64 bool sendSync;
64 Mode m_mode; 65 Mode m_mode;
65}; 66};
66 67
67 68
68class QCopBridgePI : public QSocket 69class QCopBridgePI : public QSocket
69{ 70{
70 Q_OBJECT 71 Q_OBJECT
71 72
72 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden }; 73 enum State { Connected, Wait_USER, Wait_PASS, Ready, Forbidden };
73 74
74public: 75public:
75 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 ); 76 QCopBridgePI( int socket, QObject *parent = 0, const char* name = 0 );
76 virtual ~QCopBridgePI(); 77 virtual ~QCopBridgePI();
77 78
78 void sendDesktopMessage( const QString &msg ); 79 void sendDesktopMessage( const QString &msg );
79 void sendDesktopMessage( const QCString &msg, const QByteArray& ); 80 void sendDesktopMessage( const QCString &msg, const QByteArray& );
80 void startSync() { sendSync = TRUE; } 81 void startSync() { sendSync = TRUE; }
81 bool verifyAuthorised(); 82 bool verifyAuthorised();
82 83
83signals: 84signals:
84 void connectionClosed( QCopBridgePI *); 85 void connectionClosed( QCopBridgePI *);
85 86
86protected slots: 87protected slots:
87 void read(); 88 void read();
88 void send( const QString& msg ); 89 void send( const QString& msg );
89 void process( const QString& command ); 90 void process( const QString& command );
90 void myConnectionClosed(); 91 void myConnectionClosed();
91 92
92private: 93private:
93 State state; 94 State state;
94 Q_UINT16 peerport; 95 Q_UINT16 peerport;
95 QHostAddress peeraddress; 96 QHostAddress peeraddress;
96 bool sendSync; 97 bool sendSync;
97 QTimer *timer; 98 QTimer *timer;
98}; 99};
99 100
100#endif 101#endif
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
@@ -101,201 +101,219 @@ TransferServer::~TransferServer()
101 101
102void TransferServer::newConnection( int socket ) 102void TransferServer::newConnection( int socket )
103{ 103{
104 ServerPI *ptr = new ServerPI( socket, this ); 104 ServerPI *ptr = new ServerPI( socket, this );
105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
106 connections.append( ptr ); 106 connections.append( ptr );
107} 107}
108 108
109QString SyncAuthentication::serverId() 109QString SyncAuthentication::serverId()
110{ 110{
111 Config cfg("Security"); 111 Config cfg("Security");
112 cfg.setGroup("Sync"); 112 cfg.setGroup("Sync");
113 QString r = cfg.readEntry("serverid"); 113 QString r = cfg.readEntry("serverid");
114 114
115 if ( r.isEmpty() ) { 115 if ( r.isEmpty() ) {
116 r = OGlobal::generateUuid(); 116 r = OGlobal::generateUuid();
117 cfg.writeEntry("serverid", r ); 117 cfg.writeEntry("serverid", r );
118 } 118 }
119 return r; 119 return r;
120} 120}
121 121
122QString SyncAuthentication::ownerName() 122QString SyncAuthentication::ownerName()
123{ 123{
124 QString vfilename = Global::applicationFileName("addressbook", 124 QString vfilename = Global::applicationFileName("addressbook",
125 "businesscard.vcf"); 125 "businesscard.vcf");
126 if (QFile::exists(vfilename)) { 126 if (QFile::exists(vfilename)) {
127 Contact c; 127 Contact c;
128 c = Contact::readVCard( vfilename )[0]; 128 c = Contact::readVCard( vfilename )[0];
129 return c.fullName(); 129 return c.fullName();
130 } 130 }
131 131
132 return QString::null; 132 return QString::null;
133} 133}
134 134
135QString SyncAuthentication::loginName() 135QString SyncAuthentication::loginName()
136{ 136{
137 struct passwd *pw = 0L; 137 struct passwd *pw = 0L;
138#ifndef Q_OS_WIN32 138#ifndef Q_OS_WIN32
139 pw = getpwuid( geteuid() ); 139 pw = getpwuid( geteuid() );
140 return QString::fromLocal8Bit( pw->pw_name ); 140 return QString::fromLocal8Bit( pw->pw_name );
141#else 141#else
142 //### revise 142 //### revise
143 return QString(); 143 return QString();
144#endif 144#endif
145} 145}
146 146
147int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 147int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
148{ 148{
149 Config cfg("Security"); 149 Config cfg("Security");
150 cfg.setGroup("Sync"); 150 cfg.setGroup("Sync");
151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
153 153
154 // QHostAddress allowed; 154 // QHostAddress allowed;
155 // allowed.setAddress(allowedstr); 155 // allowed.setAddress(allowedstr);
156 // uint auth_peer = allowed.ip4Addr(); 156 // uint auth_peer = allowed.ip4Addr();
157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
158 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
159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
160 160
161 return (peeraddress.ip4Addr() & mask) == auth_peer; 161 return (peeraddress.ip4Addr() & mask) == auth_peer;
162} 162}
163 163
164bool SyncAuthentication::checkUser( const QString& user ) 164bool SyncAuthentication::checkUser( const QString& user )
165{ 165{
166 if ( user.isEmpty() ) return FALSE; 166 if ( user.isEmpty() ) return FALSE;
167 QString euser = loginName(); 167 QString euser = loginName();
168 return user == euser; 168 return user == euser;
169} 169}
170 170
171bool SyncAuthentication::checkPassword( const QString& password ) 171bool SyncAuthentication::checkPassword( const QString& password )
172{ 172{
173#ifdef ALLOW_UNIX_USER_FTP 173#ifdef ALLOW_UNIX_USER_FTP
174 // First, check system password... 174 // First, check system password...
175 175
176 struct passwd *pw = 0; 176 struct passwd *pw = 0;
177 struct spwd *spw = 0; 177 struct spwd *spw = 0;
178 178
179 pw = getpwuid( geteuid() ); 179 pw = getpwuid( geteuid() );
180 spw = getspnam( pw->pw_name ); 180 spw = getspnam( pw->pw_name );
181 181
182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
183 if ( cpwd == "x" && spw ) 183 if ( cpwd == "x" && spw )
184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
185 185
186 // Note: some systems use more than crypt for passwords. 186 // Note: some systems use more than crypt for passwords.
187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
188 if ( cpwd == cpassword ) 188 if ( cpwd == cpassword )
189 return TRUE; 189 return TRUE;
190#endif 190#endif
191 191
192 static int lastdenial=0; 192 static int lastdenial=0;
193 static int denials=0; 193 static int denials=0;
194 int now = time(0); 194 int now = time(0);
195 195
196 Config cfg("Security"); 196 Config cfg("Security");
197 cfg.setGroup("Sync"); 197 cfg.setGroup("SyncMode");
198 QString syncapp = cfg.readEntry("syncapp","Qtopia"); 198 int mode = cfg.readNumEntry("Mode", 0x02 );
199 199
200 //No password needed if the user really wants it 200 //No pass word needed if the user really needs it
201 if (syncapp == "IntelliSync") { 201 if (mode & 0x04) {
202 return TRUE; 202 QMessageBox unauth(
203 } 203 tr("Sync Connection"),
204 204 tr("<qt><p>An unauthorized system is requesting access to this device."
205 // Detect old Qtopia Desktop (no password) 205 "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ),
206 QMessageBox::Warning,
207 QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton,
208 0, QString::null, TRUE, WStyle_StaysOnTop);
209 unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) );
210 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
211 switch( unauth.exec() ) {
212 case QMessageBox::Ok:
213 return TRUE;
214 break;
215 case QMessageBox::Cancel:
216 default:
217 denials++;
218 lastdenial=now;
219 return FALSE;
220 }
221 }
222
223 // Detect old Qtopia Desktop (no password) and fail
206 if ( password.isEmpty() ) { 224 if ( password.isEmpty() ) {
207 if ( denials < 3 || now > lastdenial+600 ) { 225 if ( denials < 3 || now > lastdenial+600 ) {
208 QMessageBox unauth( 226 QMessageBox unauth(
209 tr("Sync Connection"), 227 tr("Sync Connection"),
210 tr("<p>An unauthorized system is requesting access to this device." 228 tr("<p>An unauthorized system is requesting access to this device."
211 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 229 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
212 "please upgrade or change the security setting to use IntelliSync." ), 230 "please upgrade or change the security setting to use IntelliSync." ),
213 QMessageBox::Warning, 231 QMessageBox::Warning,
214 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 232 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
215 0, QString::null, TRUE, WStyle_StaysOnTop); 233 0, QString::null, TRUE, WStyle_StaysOnTop);
216 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 234 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
217 unauth.exec(); 235 unauth.exec();
218 236
219 denials++; 237 denials++;
220 lastdenial=now; 238 lastdenial=now;
221 } 239 }
222 return FALSE; 240 return FALSE;
223 241
224 } 242 }
225 243
226 // Second, check sync password... 244 // Second, check sync password...
227 245
228 static int lock=0; 246 static int lock=0;
229 if ( lock ) return FALSE; 247 if ( lock ) return FALSE;
230 248
231 ++lock; 249 ++lock;
232 250
233 /* 251 /*
234 * we need to support old Sync software and QtopiaDesktop 252 * we need to support old Sync software and QtopiaDesktop
235 */ 253 */
236 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 254 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
237 Config cfg( "Security" ); 255 Config cfg( "Security" );
238 cfg.setGroup("Sync"); 256 cfg.setGroup("Sync");
239 QStringList pwds = cfg.readListEntry("Passwords",' '); 257 QStringList pwds = cfg.readListEntry("Passwords",' ');
240 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 258 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
241#ifndef Q_OS_WIN32 259#ifndef Q_OS_WIN32
242 QString cpassword = QString::fromLocal8Bit( 260 QString cpassword = QString::fromLocal8Bit(
243 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 261 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
244#else 262#else
245 // ### revise 263 // ### revise
246 QString cpassword(""); 264 QString cpassword("");
247#endif 265#endif
248 if ( *it == cpassword ) { 266 if ( *it == cpassword ) {
249 lock--; 267 lock--;
250 return TRUE; 268 return TRUE;
251 } 269 }
252 } 270 }
253 271
254 // Unrecognized system. Be careful... 272 // Unrecognized system. Be careful...
255 QMessageBox unrecbox( 273 QMessageBox unrecbox(
256 tr("Sync Connection"), 274 tr("Sync Connection"),
257 tr("<p>An unrecognized system is requesting access to this device." 275 tr("<p>An unrecognized system is requesting access to this device."
258 "<p>If you have just initiated a Sync for the first time, this is normal."), 276 "<p>If you have just initiated a Sync for the first time, this is normal."),
259 QMessageBox::Warning, 277 QMessageBox::Warning,
260 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 278 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
261 0, QString::null, TRUE, WStyle_StaysOnTop); 279 0, QString::null, TRUE, WStyle_StaysOnTop);
262 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 280 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
263 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 281 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
264 282
265 if ( (denials > 2 && now < lastdenial+600) 283 if ( (denials > 2 && now < lastdenial+600)
266 || unrecbox.exec() != QMessageBox::Yes) 284 || unrecbox.exec() != QMessageBox::Yes)
267 { 285 {
268 denials++; 286 denials++;
269 lastdenial=now; 287 lastdenial=now;
270 lock--; 288 lock--;
271 return FALSE; 289 return FALSE;
272 } else { 290 } else {
273 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 291 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
274 char salt[2]; 292 char salt[2];
275 salt[0]= salty[rand() % (sizeof(salty)-1)]; 293 salt[0]= salty[rand() % (sizeof(salty)-1)];
276 salt[1]= salty[rand() % (sizeof(salty)-1)]; 294 salt[1]= salty[rand() % (sizeof(salty)-1)];
277#ifndef Q_OS_WIN32 295#ifndef Q_OS_WIN32
278 QString cpassword = QString::fromLocal8Bit( 296 QString cpassword = QString::fromLocal8Bit(
279 crypt( password.mid(8).local8Bit(), salt ) ); 297 crypt( password.mid(8).local8Bit(), salt ) );
280#else 298#else
281 //### revise 299 //### revise
282 QString cpassword(""); 300 QString cpassword("");
283#endif 301#endif
284 denials=0; 302 denials=0;
285 pwds.prepend(cpassword); 303 pwds.prepend(cpassword);
286 cfg.writeEntry("Passwords",pwds,' '); 304 cfg.writeEntry("Passwords",pwds,' ');
287 lock--; 305 lock--;
288 return TRUE; 306 return TRUE;
289 } 307 }
290 } 308 }
291 lock--; 309 lock--;
292 310
293 return FALSE; 311 return FALSE;
294} 312}
295 313
296 314
297ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 315ServerPI::ServerPI( int socket, QObject *parent, const char* name )
298 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 316 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
299 storFileSize(-1) 317 storFileSize(-1)
300{ 318{
301 state = Connected; 319 state = Connected;