-rw-r--r-- | core/launcher/transferserver.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index dea140d..aaa4425 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -1,745 +1,745 @@ | |||
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 | #define _XOPEN_SOURCE | 20 | #define _XOPEN_SOURCE |
21 | #include <pwd.h> | 21 | #include <pwd.h> |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <time.h> | 25 | #include <time.h> |
26 | #include <shadow.h> | 26 | #include <shadow.h> |
27 | 27 | ||
28 | /* we need the _OS_LINUX stuff first ! */ | 28 | /* we need the _OS_LINUX stuff first ! */ |
29 | #include <qglobal.h> | 29 | #include <qglobal.h> |
30 | 30 | ||
31 | #ifndef _OS_LINUX_ | 31 | #ifndef _OS_LINUX_ |
32 | 32 | ||
33 | extern "C" { | 33 | extern "C" { |
34 | #include <uuid/uuid.h> | 34 | #include <uuid/uuid.h> |
35 | #define UUID_H_INCLUDED | 35 | #define UUID_H_INCLUDED |
36 | } | 36 | } |
37 | 37 | ||
38 | #endif // not defined linux | 38 | #endif // not defined linux |
39 | 39 | ||
40 | #if defined(_OS_LINUX_) | 40 | #if defined(_OS_LINUX_) |
41 | #include <shadow.h> | 41 | #include <shadow.h> |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | #include <qdir.h> | 44 | #include <qdir.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | #include <qtextstream.h> | 46 | #include <qtextstream.h> |
47 | #include <qdatastream.h> | 47 | #include <qdatastream.h> |
48 | #include <qmessagebox.h> | 48 | #include <qmessagebox.h> |
49 | #include <qstringlist.h> | 49 | #include <qstringlist.h> |
50 | #include <qfileinfo.h> | 50 | #include <qfileinfo.h> |
51 | #include <qregexp.h> | 51 | #include <qregexp.h> |
52 | //#include <qpe/qcopchannel_qws.h> | 52 | //#include <qpe/qcopchannel_qws.h> |
53 | #include <qpe/process.h> | 53 | #include <qpe/process.h> |
54 | #include <qpe/global.h> | 54 | #include <qpe/global.h> |
55 | #include <qpe/config.h> | 55 | #include <qpe/config.h> |
56 | #include <qpe/contact.h> | 56 | #include <qpe/contact.h> |
57 | #include <qpe/quuid.h> | 57 | #include <qpe/quuid.h> |
58 | #include <qpe/version.h> | 58 | #include <qpe/version.h> |
59 | #include <qpe/qcopenvelope_qws.h> | 59 | #include <qpe/qcopenvelope_qws.h> |
60 | 60 | ||
61 | #include "transferserver.h" | 61 | #include "transferserver.h" |
62 | #include "qprocess.h" | 62 | #include "qprocess.h" |
63 | 63 | ||
64 | const int block_size = 51200; | 64 | const int block_size = 51200; |
65 | 65 | ||
66 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 66 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
67 | const char* name ) | 67 | const char* name ) |
68 | : QServerSocket( port, 1, parent, name ) | 68 | : QServerSocket( port, 1, parent, name ) |
69 | { | 69 | { |
70 | if ( !ok() ) | 70 | if ( !ok() ) |
71 | qWarning( "Failed to bind to port %d", port ); | 71 | qWarning( "Failed to bind to port %d", port ); |
72 | } | 72 | } |
73 | 73 | ||
74 | TransferServer::~TransferServer() | 74 | TransferServer::~TransferServer() |
75 | { | 75 | { |
76 | 76 | ||
77 | } | 77 | } |
78 | 78 | ||
79 | void TransferServer::newConnection( int socket ) | 79 | void TransferServer::newConnection( int socket ) |
80 | { | 80 | { |
81 | (void) new ServerPI( socket, this ); | 81 | (void) new ServerPI( socket, this ); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * small class in anonymous namespace | 85 | * small class in anonymous namespace |
86 | * to generate a QUUid for us | 86 | * to generate a QUUid for us |
87 | */ | 87 | */ |
88 | namespace { | 88 | namespace { |
89 | struct UidGen { | 89 | struct UidGen { |
90 | QString uuid(); | 90 | QString uuid(); |
91 | }; | 91 | }; |
92 | #if !defined(_OS_LINUX_) | 92 | #if !defined(_OS_LINUX_) |
93 | QString UidGen::uuid() { | 93 | QString UidGen::uuid() { |
94 | uuid_t uuid; | 94 | uuid_t uuid; |
95 | uuid_generate( uuid ); | 95 | uuid_generate( uuid ); |
96 | return QUUid( uuid ).toString(); | 96 | return QUUid( uuid ).toString(); |
97 | } | 97 | } |
98 | #else | 98 | #else |
99 | /* | 99 | /* |
100 | * linux got a /proc/sys/kernel/random/uuid file | 100 | * linux got a /proc/sys/kernel/random/uuid file |
101 | * it'll generate the uuids for us | 101 | * it'll generate the uuids for us |
102 | */ | 102 | */ |
103 | QString UidGen::uuid() { | 103 | QString UidGen::uuid() { |
104 | QFile file( "/proc/sys/kernel/random/uuid" ); | 104 | QFile file( "/proc/sys/kernel/random/uuid" ); |
105 | if (!file.open(IO_ReadOnly ) ) | 105 | if (!file.open(IO_ReadOnly ) ) |
106 | return QString::null; | 106 | return QString::null; |
107 | 107 | ||
108 | QTextStream stream(&file); | 108 | QTextStream stream(&file); |
109 | 109 | ||
110 | return "{" + stream.read().stripWhiteSpace() + "}"; | 110 | return "{" + stream.read().stripWhiteSpace() + "}"; |
111 | } | 111 | } |
112 | #endif | 112 | #endif |
113 | } | 113 | } |
114 | 114 | ||
115 | QString SyncAuthentication::serverId() | 115 | QString SyncAuthentication::serverId() |
116 | { | 116 | { |
117 | Config cfg("Security"); | 117 | Config cfg("Security"); |
118 | cfg.setGroup("Sync"); | 118 | cfg.setGroup("Sync"); |
119 | QString r=cfg.readEntry("serverid"); | 119 | QString r=cfg.readEntry("serverid"); |
120 | if ( r.isEmpty() ) { | 120 | if ( r.isEmpty() ) { |
121 | UidGen gen; | 121 | UidGen gen; |
122 | r = gen.uuid(); | 122 | r = gen.uuid(); |
123 | cfg.writeEntry("serverid", r ); | 123 | cfg.writeEntry("serverid", r ); |
124 | } | 124 | } |
125 | return r; | 125 | return r; |
126 | } | 126 | } |
127 | 127 | ||
128 | QString SyncAuthentication::ownerName() | 128 | QString SyncAuthentication::ownerName() |
129 | { | 129 | { |
130 | QString vfilename = Global::applicationFileName("addressbook", | 130 | QString vfilename = Global::applicationFileName("addressbook", |
131 | "businesscard.vcf"); | 131 | "businesscard.vcf"); |
132 | if (QFile::exists(vfilename)) { | 132 | if (QFile::exists(vfilename)) { |
133 | Contact c; | 133 | Contact c; |
134 | c = Contact::readVCard( vfilename )[0]; | 134 | c = Contact::readVCard( vfilename )[0]; |
135 | return c.fullName(); | 135 | return c.fullName(); |
136 | } | 136 | } |
137 | 137 | ||
138 | return ""; | 138 | return ""; |
139 | } | 139 | } |
140 | 140 | ||
141 | QString SyncAuthentication::loginName() | 141 | QString SyncAuthentication::loginName() |
142 | { | 142 | { |
143 | struct passwd *pw; | 143 | struct passwd *pw; |
144 | pw = getpwuid( geteuid() ); | 144 | pw = getpwuid( geteuid() ); |
145 | return QString::fromLocal8Bit( pw->pw_name ); | 145 | return QString::fromLocal8Bit( pw->pw_name ); |
146 | } | 146 | } |
147 | 147 | ||
148 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 148 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
149 | { | 149 | { |
150 | Config cfg("Security"); | 150 | Config cfg("Security"); |
151 | cfg.setGroup("Sync"); | 151 | cfg.setGroup("Sync"); |
152 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 152 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
153 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); | 153 | uint auth_peer = cfg.readNumEntry("auth_peer",0xc0a80100); |
154 | 154 | ||
155 | // QHostAddress allowed; | 155 | // QHostAddress allowed; |
156 | // allowed.setAddress(allowedstr); | 156 | // allowed.setAddress(allowedstr); |
157 | // uint auth_peer = allowed.ip4Addr(); | 157 | // uint auth_peer = allowed.ip4Addr(); |
158 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); | 158 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); |
159 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 159 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
160 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); | 160 | ? 0xffffffff : (((1<<auth_peer_bits)-1)<<(32-auth_peer_bits)); |
161 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 161 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
162 | } | 162 | } |
163 | 163 | ||
164 | bool SyncAuthentication::checkUser( const QString& user ) | 164 | bool 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 | ||
171 | bool SyncAuthentication::checkPassword( const QString& password ) | 171 | bool 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 | // Detect old Qtopia Desktop (no password) | 196 | // Detect old Qtopia Desktop (no password) |
197 | if ( password.isEmpty() ) { | 197 | if ( password.isEmpty() ) { |
198 | if ( denials < 1 || now > lastdenial+600 ) { | 198 | if ( denials < 1 || now > lastdenial+600 ) { |
199 | QMessageBox::warning( 0,tr("Sync Connection"), | 199 | QMessageBox::warning( 0,tr("Sync Connection"), |
200 | tr("<p>An unauthorized system is requesting access to this device." | 200 | tr("<p>An unauthorized system is requesting access to this device." |
201 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 201 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
202 | "please upgrade."), | 202 | "please upgrade."), |
203 | tr("Deny") ); | 203 | tr("Deny") ); |
204 | denials++; | 204 | denials++; |
205 | lastdenial=now; | 205 | lastdenial=now; |
206 | } | 206 | } |
207 | return FALSE; | 207 | return FALSE; |
208 | } | 208 | } |
209 | 209 | ||
210 | // Second, check sync password... | 210 | // Second, check sync password... |
211 | QString pass = password.left(6); | 211 | QString pass = password.left(6); |
212 | /* old QtopiaDesktops are sending | 212 | /* old QtopiaDesktops are sending |
213 | * rootme newer versions got a Qtopia | 213 | * rootme newer versions got a Qtopia |
214 | * prefixed. Qtopia prefix will suceed | 214 | * prefixed. Qtopia prefix will suceed |
215 | * until the sync software syncs up | 215 | * until the sync software syncs up |
216 | * FIXME | 216 | * FIXME |
217 | */ | 217 | */ |
218 | if ( pass == "rootme" || pass == "Qtopia") { | 218 | if ( pass == "rootme" || pass == "Qtopia") { |
219 | 219 | ||
220 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); | 220 | QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); |
221 | Config cfg("Security"); | 221 | Config cfg("Security"); |
222 | cfg.setGroup("Sync"); | 222 | cfg.setGroup("Sync"); |
223 | QString pwds = cfg.readEntry("Passwords"); | 223 | QString pwds = cfg.readEntry("Passwords"); |
224 | if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) | 224 | if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) |
225 | return TRUE; | 225 | return TRUE; |
226 | 226 | ||
227 | // Unrecognized system. Be careful... | 227 | // Unrecognized system. Be careful... |
228 | 228 | ||
229 | if ( (denials > 2 && now < lastdenial+600) | 229 | if ( (denials > 2 && now < lastdenial+600) |
230 | || QMessageBox::warning(0,tr("Sync Connection"), | 230 | || QMessageBox::warning(0,tr("Sync Connection"), |
231 | tr("<p>An unrecognized system is requesting access to this device." | 231 | tr("<p>An unrecognized system is requesting access to this device." |
232 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 232 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
233 | tr("Allow"),tr("Deny"))==1 ) | 233 | tr("Allow"),tr("Deny"), 0, 1, 1 ) ==1 ) |
234 | { | 234 | { |
235 | denials++; | 235 | denials++; |
236 | lastdenial=now; | 236 | lastdenial=now; |
237 | return FALSE; | 237 | return FALSE; |
238 | } else { | 238 | } else { |
239 | denials=0; | 239 | denials=0; |
240 | cfg.writeEntry("Passwords",pwds+" "+cpassword); | 240 | cfg.writeEntry("Passwords",pwds+" "+cpassword); |
241 | return TRUE; | 241 | return TRUE; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | return FALSE; | 245 | return FALSE; |
246 | } | 246 | } |
247 | 247 | ||
248 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) | 248 | ServerPI::ServerPI( int socket, QObject *parent , const char* name ) |
249 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) | 249 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ) |
250 | { | 250 | { |
251 | state = Connected; | 251 | state = Connected; |
252 | 252 | ||
253 | setSocket( socket ); | 253 | setSocket( socket ); |
254 | 254 | ||
255 | peerport = peerPort(); | 255 | peerport = peerPort(); |
256 | peeraddress = peerAddress(); | 256 | peeraddress = peerAddress(); |
257 | 257 | ||
258 | #ifndef INSECURE | 258 | #ifndef INSECURE |
259 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 259 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
260 | state = Forbidden; | 260 | state = Forbidden; |
261 | startTimer( 0 ); | 261 | startTimer( 0 ); |
262 | } else | 262 | } else |
263 | #endif | 263 | #endif |
264 | { | 264 | { |
265 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 265 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
266 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 266 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
267 | 267 | ||
268 | passiv = FALSE; | 268 | passiv = FALSE; |
269 | for( int i = 0; i < 4; i++ ) | 269 | for( int i = 0; i < 4; i++ ) |
270 | wait[i] = FALSE; | 270 | wait[i] = FALSE; |
271 | 271 | ||
272 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); | 272 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); |
273 | state = Wait_USER; | 273 | state = Wait_USER; |
274 | 274 | ||
275 | dtp = new ServerDTP( this ); | 275 | dtp = new ServerDTP( this ); |
276 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 276 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
277 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 277 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
278 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); | 278 | connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); |
279 | 279 | ||
280 | 280 | ||
281 | directory = QDir::currentDirPath(); | 281 | directory = QDir::currentDirPath(); |
282 | 282 | ||
283 | static int p = 1024; | 283 | static int p = 1024; |
284 | 284 | ||
285 | while ( !serversocket || !serversocket->ok() ) { | 285 | while ( !serversocket || !serversocket->ok() ) { |
286 | delete serversocket; | 286 | delete serversocket; |
287 | serversocket = new ServerSocket( ++p, this ); | 287 | serversocket = new ServerSocket( ++p, this ); |
288 | } | 288 | } |
289 | connect( serversocket, SIGNAL( newIncomming( int ) ), | 289 | connect( serversocket, SIGNAL( newIncomming( int ) ), |
290 | SLOT( newConnection( int ) ) ); | 290 | SLOT( newConnection( int ) ) ); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | 293 | ||
294 | ServerPI::~ServerPI() | 294 | ServerPI::~ServerPI() |
295 | { | 295 | { |
296 | 296 | ||
297 | } | 297 | } |
298 | 298 | ||
299 | void ServerPI::connectionClosed() | 299 | void ServerPI::connectionClosed() |
300 | { | 300 | { |
301 | // qDebug( "Debug: Connection closed" ); | 301 | // qDebug( "Debug: Connection closed" ); |
302 | delete this; | 302 | delete this; |
303 | } | 303 | } |
304 | 304 | ||
305 | void ServerPI::send( const QString& msg ) | 305 | void ServerPI::send( const QString& msg ) |
306 | { | 306 | { |
307 | QTextStream os( this ); | 307 | QTextStream os( this ); |
308 | os << msg << endl; | 308 | os << msg << endl; |
309 | //qDebug( "Reply: %s", msg.latin1() ); | 309 | //qDebug( "Reply: %s", msg.latin1() ); |
310 | } | 310 | } |
311 | 311 | ||
312 | void ServerPI::read() | 312 | void ServerPI::read() |
313 | { | 313 | { |
314 | while ( canReadLine() ) | 314 | while ( canReadLine() ) |
315 | process( readLine().stripWhiteSpace() ); | 315 | process( readLine().stripWhiteSpace() ); |
316 | } | 316 | } |
317 | 317 | ||
318 | bool ServerPI::checkReadFile( const QString& file ) | 318 | bool ServerPI::checkReadFile( const QString& file ) |
319 | { | 319 | { |
320 | QString filename; | 320 | QString filename; |
321 | 321 | ||
322 | if ( file[0] != "/" ) | 322 | if ( file[0] != "/" ) |
323 | filename = directory.path() + "/" + file; | 323 | filename = directory.path() + "/" + file; |
324 | else | 324 | else |
325 | filename = file; | 325 | filename = file; |
326 | 326 | ||
327 | QFileInfo fi( filename ); | 327 | QFileInfo fi( filename ); |
328 | return ( fi.exists() && fi.isReadable() ); | 328 | return ( fi.exists() && fi.isReadable() ); |
329 | } | 329 | } |
330 | 330 | ||
331 | bool ServerPI::checkWriteFile( const QString& file ) | 331 | bool ServerPI::checkWriteFile( const QString& file ) |
332 | { | 332 | { |
333 | QString filename; | 333 | QString filename; |
334 | 334 | ||
335 | if ( file[0] != "/" ) | 335 | if ( file[0] != "/" ) |
336 | filename = directory.path() + "/" + file; | 336 | filename = directory.path() + "/" + file; |
337 | else | 337 | else |
338 | filename = file; | 338 | filename = file; |
339 | 339 | ||
340 | QFileInfo fi( filename ); | 340 | QFileInfo fi( filename ); |
341 | 341 | ||
342 | if ( fi.exists() ) | 342 | if ( fi.exists() ) |
343 | if ( !QFile( filename ).remove() ) | 343 | if ( !QFile( filename ).remove() ) |
344 | return FALSE; | 344 | return FALSE; |
345 | return TRUE; | 345 | return TRUE; |
346 | } | 346 | } |
347 | 347 | ||
348 | void ServerPI::process( const QString& message ) | 348 | void ServerPI::process( const QString& message ) |
349 | { | 349 | { |
350 | //qDebug( "Command: %s", message.latin1() ); | 350 | //qDebug( "Command: %s", message.latin1() ); |
351 | 351 | ||
352 | // split message using "," as separator | 352 | // split message using "," as separator |
353 | QStringList msg = QStringList::split( " ", message ); | 353 | QStringList msg = QStringList::split( " ", message ); |
354 | if ( msg.isEmpty() ) return; | 354 | if ( msg.isEmpty() ) return; |
355 | 355 | ||
356 | // command token | 356 | // command token |
357 | QString cmd = msg[0].upper(); | 357 | QString cmd = msg[0].upper(); |
358 | 358 | ||
359 | // argument token | 359 | // argument token |
360 | QString arg; | 360 | QString arg; |
361 | if ( msg.count() >= 2 ) | 361 | if ( msg.count() >= 2 ) |
362 | arg = msg[1]; | 362 | arg = msg[1]; |
363 | 363 | ||
364 | // full argument string | 364 | // full argument string |
365 | QString args; | 365 | QString args; |
366 | if ( msg.count() >= 2 ) { | 366 | if ( msg.count() >= 2 ) { |
367 | QStringList copy( msg ); | 367 | QStringList copy( msg ); |
368 | // FIXME: for Qt3 | 368 | // FIXME: for Qt3 |
369 | // copy.pop_front() | 369 | // copy.pop_front() |
370 | copy.remove( copy.begin() ); | 370 | copy.remove( copy.begin() ); |
371 | args = copy.join( " " ); | 371 | args = copy.join( " " ); |
372 | } | 372 | } |
373 | 373 | ||
374 | //qDebug( "args: %s", args.latin1() ); | 374 | //qDebug( "args: %s", args.latin1() ); |
375 | 375 | ||
376 | // we always respond to QUIT, regardless of state | 376 | // we always respond to QUIT, regardless of state |
377 | if ( cmd == "QUIT" ) { | 377 | if ( cmd == "QUIT" ) { |
378 | send( "211 Good bye!" ); | 378 | send( "211 Good bye!" ); |
379 | delete this; | 379 | delete this; |
380 | return; | 380 | return; |
381 | } | 381 | } |
382 | 382 | ||
383 | // connected to client | 383 | // connected to client |
384 | if ( Connected == state ) | 384 | if ( Connected == state ) |
385 | return; | 385 | return; |
386 | 386 | ||
387 | // waiting for user name | 387 | // waiting for user name |
388 | if ( Wait_USER == state ) { | 388 | if ( Wait_USER == state ) { |
389 | 389 | ||
390 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 390 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
391 | send( "530 Please login with USER and PASS" ); | 391 | send( "530 Please login with USER and PASS" ); |
392 | return; | 392 | return; |
393 | } | 393 | } |
394 | send( "331 User name ok, need password" ); | 394 | send( "331 User name ok, need password" ); |
395 | state = Wait_PASS; | 395 | state = Wait_PASS; |
396 | return; | 396 | return; |
397 | } | 397 | } |
398 | 398 | ||
399 | // waiting for password | 399 | // waiting for password |
400 | if ( Wait_PASS == state ) { | 400 | if ( Wait_PASS == state ) { |
401 | 401 | ||
402 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 402 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
403 | send( "530 Please login with USER and PASS" ); | 403 | send( "530 Please login with USER and PASS" ); |
404 | return; | 404 | return; |
405 | } | 405 | } |
406 | send( "230 User logged in, proceed" ); | 406 | send( "230 User logged in, proceed" ); |
407 | state = Ready; | 407 | state = Ready; |
408 | return; | 408 | return; |
409 | } | 409 | } |
410 | 410 | ||
411 | // ACCESS CONTROL COMMANDS | 411 | // ACCESS CONTROL COMMANDS |
412 | 412 | ||
413 | 413 | ||
414 | // account (ACCT) | 414 | // account (ACCT) |
415 | if ( cmd == "ACCT" ) { | 415 | if ( cmd == "ACCT" ) { |
416 | // even wu-ftp does not support it | 416 | // even wu-ftp does not support it |
417 | send( "502 Command not implemented" ); | 417 | send( "502 Command not implemented" ); |
418 | } | 418 | } |
419 | 419 | ||
420 | // change working directory (CWD) | 420 | // change working directory (CWD) |
421 | else if ( cmd == "CWD" ) { | 421 | else if ( cmd == "CWD" ) { |
422 | 422 | ||
423 | if ( !args.isEmpty() ) { | 423 | if ( !args.isEmpty() ) { |
424 | if ( directory.cd( args, TRUE ) ) | 424 | if ( directory.cd( args, TRUE ) ) |
425 | send( "250 Requested file action okay, completed" ); | 425 | send( "250 Requested file action okay, completed" ); |
426 | else | 426 | else |
427 | send( "550 Requested action not taken" ); | 427 | send( "550 Requested action not taken" ); |
428 | } | 428 | } |
429 | else | 429 | else |
430 | send( "500 Syntax error, command unrecognized" ); | 430 | send( "500 Syntax error, command unrecognized" ); |
431 | } | 431 | } |
432 | 432 | ||
433 | // change to parent directory (CDUP) | 433 | // change to parent directory (CDUP) |
434 | else if ( cmd == "CDUP" ) { | 434 | else if ( cmd == "CDUP" ) { |
435 | if ( directory.cdUp() ) | 435 | if ( directory.cdUp() ) |
436 | send( "250 Requested file action okay, completed" ); | 436 | send( "250 Requested file action okay, completed" ); |
437 | else | 437 | else |
438 | send( "550 Requested action not taken" ); | 438 | send( "550 Requested action not taken" ); |
439 | } | 439 | } |
440 | 440 | ||
441 | // structure mount (SMNT) | 441 | // structure mount (SMNT) |
442 | else if ( cmd == "SMNT" ) { | 442 | else if ( cmd == "SMNT" ) { |
443 | // even wu-ftp does not support it | 443 | // even wu-ftp does not support it |
444 | send( "502 Command not implemented" ); | 444 | send( "502 Command not implemented" ); |
445 | } | 445 | } |
446 | 446 | ||
447 | // reinitialize (REIN) | 447 | // reinitialize (REIN) |
448 | else if ( cmd == "REIN" ) { | 448 | else if ( cmd == "REIN" ) { |
449 | // even wu-ftp does not support it | 449 | // even wu-ftp does not support it |
450 | send( "502 Command not implemented" ); | 450 | send( "502 Command not implemented" ); |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
454 | // TRANSFER PARAMETER COMMANDS | 454 | // TRANSFER PARAMETER COMMANDS |
455 | 455 | ||
456 | 456 | ||
457 | // data port (PORT) | 457 | // data port (PORT) |
458 | else if ( cmd == "PORT" ) { | 458 | else if ( cmd == "PORT" ) { |
459 | if ( parsePort( arg ) ) | 459 | if ( parsePort( arg ) ) |
460 | send( "200 Command okay" ); | 460 | send( "200 Command okay" ); |
461 | else | 461 | else |
462 | send( "500 Syntax error, command unrecognized" ); | 462 | send( "500 Syntax error, command unrecognized" ); |
463 | } | 463 | } |
464 | 464 | ||
465 | // passive (PASV) | 465 | // passive (PASV) |
466 | else if ( cmd == "PASV" ) { | 466 | else if ( cmd == "PASV" ) { |
467 | passiv = TRUE; | 467 | passiv = TRUE; |
468 | send( "227 Entering Passive Mode (" | 468 | send( "227 Entering Passive Mode (" |
469 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," | 469 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," |
470 | + QString::number( ( serversocket->port() ) >> 8 ) + "," | 470 | + QString::number( ( serversocket->port() ) >> 8 ) + "," |
471 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); | 471 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); |
472 | } | 472 | } |
473 | 473 | ||
474 | // representation type (TYPE) | 474 | // representation type (TYPE) |
475 | else if ( cmd == "TYPE" ) { | 475 | else if ( cmd == "TYPE" ) { |
476 | if ( arg.upper() == "A" || arg.upper() == "I" ) | 476 | if ( arg.upper() == "A" || arg.upper() == "I" ) |
477 | send( "200 Command okay" ); | 477 | send( "200 Command okay" ); |
478 | else | 478 | else |
479 | send( "504 Command not implemented for that parameter" ); | 479 | send( "504 Command not implemented for that parameter" ); |
480 | } | 480 | } |
481 | 481 | ||
482 | // file structure (STRU) | 482 | // file structure (STRU) |
483 | else if ( cmd == "STRU" ) { | 483 | else if ( cmd == "STRU" ) { |
484 | if ( arg.upper() == "F" ) | 484 | if ( arg.upper() == "F" ) |
485 | send( "200 Command okay" ); | 485 | send( "200 Command okay" ); |
486 | else | 486 | else |
487 | send( "504 Command not implemented for that parameter" ); | 487 | send( "504 Command not implemented for that parameter" ); |
488 | } | 488 | } |
489 | 489 | ||
490 | // transfer mode (MODE) | 490 | // transfer mode (MODE) |
491 | else if ( cmd == "MODE" ) { | 491 | else if ( cmd == "MODE" ) { |
492 | if ( arg.upper() == "S" ) | 492 | if ( arg.upper() == "S" ) |
493 | send( "200 Command okay" ); | 493 | send( "200 Command okay" ); |
494 | else | 494 | else |
495 | send( "504 Command not implemented for that parameter" ); | 495 | send( "504 Command not implemented for that parameter" ); |
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | // FTP SERVICE COMMANDS | 499 | // FTP SERVICE COMMANDS |
500 | 500 | ||
501 | 501 | ||
502 | // retrieve (RETR) | 502 | // retrieve (RETR) |
503 | else if ( cmd == "RETR" ) | 503 | else if ( cmd == "RETR" ) |
504 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 504 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
505 | || backupRestoreGzip( absFilePath( args ) ) ) { | 505 | || backupRestoreGzip( absFilePath( args ) ) ) { |
506 | send( "150 File status okay" ); | 506 | send( "150 File status okay" ); |
507 | sendFile( absFilePath( args ) ); | 507 | sendFile( absFilePath( args ) ); |
508 | } | 508 | } |
509 | else { | 509 | else { |
510 | qDebug("550 Requested action not taken"); | 510 | qDebug("550 Requested action not taken"); |
511 | send( "550 Requested action not taken" ); | 511 | send( "550 Requested action not taken" ); |
512 | } | 512 | } |
513 | 513 | ||
514 | // store (STOR) | 514 | // store (STOR) |
515 | else if ( cmd == "STOR" ) | 515 | else if ( cmd == "STOR" ) |
516 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 516 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
517 | send( "150 File status okay" ); | 517 | send( "150 File status okay" ); |
518 | retrieveFile( absFilePath( args ) ); | 518 | retrieveFile( absFilePath( args ) ); |
519 | } | 519 | } |
520 | else | 520 | else |
521 | send( "550 Requested action not taken" ); | 521 | send( "550 Requested action not taken" ); |
522 | 522 | ||
523 | // store unique (STOU) | 523 | // store unique (STOU) |
524 | else if ( cmd == "STOU" ) { | 524 | else if ( cmd == "STOU" ) { |
525 | send( "502 Command not implemented" ); | 525 | send( "502 Command not implemented" ); |
526 | } | 526 | } |
527 | 527 | ||
528 | // append (APPE) | 528 | // append (APPE) |
529 | else if ( cmd == "APPE" ) { | 529 | else if ( cmd == "APPE" ) { |
530 | send( "502 Command not implemented" ); | 530 | send( "502 Command not implemented" ); |
531 | } | 531 | } |
532 | 532 | ||
533 | // allocate (ALLO) | 533 | // allocate (ALLO) |
534 | else if ( cmd == "ALLO" ) { | 534 | else if ( cmd == "ALLO" ) { |
535 | send( "200 Command okay" ); | 535 | send( "200 Command okay" ); |
536 | } | 536 | } |
537 | 537 | ||
538 | // restart (REST) | 538 | // restart (REST) |
539 | else if ( cmd == "REST" ) { | 539 | else if ( cmd == "REST" ) { |
540 | send( "502 Command not implemented" ); | 540 | send( "502 Command not implemented" ); |
541 | } | 541 | } |
542 | 542 | ||
543 | // rename from (RNFR) | 543 | // rename from (RNFR) |
544 | else if ( cmd == "RNFR" ) { | 544 | else if ( cmd == "RNFR" ) { |
545 | renameFrom = QString::null; | 545 | renameFrom = QString::null; |
546 | if ( args.isEmpty() ) | 546 | if ( args.isEmpty() ) |
547 | send( "500 Syntax error, command unrecognized" ); | 547 | send( "500 Syntax error, command unrecognized" ); |
548 | else { | 548 | else { |
549 | QFile file( absFilePath( args ) ); | 549 | QFile file( absFilePath( args ) ); |
550 | if ( file.exists() ) { | 550 | if ( file.exists() ) { |
551 | send( "350 File exists, ready for destination name" ); | 551 | send( "350 File exists, ready for destination name" ); |
552 | renameFrom = absFilePath( args ); | 552 | renameFrom = absFilePath( args ); |
553 | } | 553 | } |
554 | else | 554 | else |
555 | send( "550 Requested action not taken" ); | 555 | send( "550 Requested action not taken" ); |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
559 | // rename to (RNTO) | 559 | // rename to (RNTO) |
560 | else if ( cmd == "RNTO" ) { | 560 | else if ( cmd == "RNTO" ) { |
561 | if ( lastCommand != "RNFR" ) | 561 | if ( lastCommand != "RNFR" ) |
562 | send( "503 Bad sequence of commands" ); | 562 | send( "503 Bad sequence of commands" ); |
563 | else if ( args.isEmpty() ) | 563 | else if ( args.isEmpty() ) |
564 | send( "500 Syntax error, command unrecognized" ); | 564 | send( "500 Syntax error, command unrecognized" ); |
565 | else { | 565 | else { |
566 | QDir dir( absFilePath( args ) ); | 566 | QDir dir( absFilePath( args ) ); |
567 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) | 567 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) |
568 | send( "250 Requested file action okay, completed." ); | 568 | send( "250 Requested file action okay, completed." ); |
569 | else | 569 | else |
570 | send( "550 Requested action not taken" ); | 570 | send( "550 Requested action not taken" ); |
571 | } | 571 | } |
572 | } | 572 | } |
573 | 573 | ||
574 | // abort (ABOR) | 574 | // abort (ABOR) |
575 | else if ( cmd.contains( "ABOR" ) ) { | 575 | else if ( cmd.contains( "ABOR" ) ) { |
576 | dtp->close(); | 576 | dtp->close(); |
577 | if ( dtp->dtpMode() != ServerDTP::Idle ) | 577 | if ( dtp->dtpMode() != ServerDTP::Idle ) |
578 | send( "426 Connection closed; transfer aborted" ); | 578 | send( "426 Connection closed; transfer aborted" ); |
579 | else | 579 | else |
580 | send( "226 Closing data connection" ); | 580 | send( "226 Closing data connection" ); |
581 | } | 581 | } |
582 | 582 | ||
583 | // delete (DELE) | 583 | // delete (DELE) |
584 | else if ( cmd == "DELE" ) { | 584 | else if ( cmd == "DELE" ) { |
585 | if ( args.isEmpty() ) | 585 | if ( args.isEmpty() ) |
586 | send( "500 Syntax error, command unrecognized" ); | 586 | send( "500 Syntax error, command unrecognized" ); |
587 | else { | 587 | else { |
588 | QFile file( absFilePath( args ) ) ; | 588 | QFile file( absFilePath( args ) ) ; |
589 | if ( file.remove() ) { | 589 | if ( file.remove() ) { |
590 | send( "250 Requested file action okay, completed" ); | 590 | send( "250 Requested file action okay, completed" ); |
591 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 591 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
592 | e << file.name(); | 592 | e << file.name(); |
593 | } else { | 593 | } else { |
594 | send( "550 Requested action not taken" ); | 594 | send( "550 Requested action not taken" ); |
595 | } | 595 | } |
596 | } | 596 | } |
597 | } | 597 | } |
598 | 598 | ||
599 | // remove directory (RMD) | 599 | // remove directory (RMD) |
600 | else if ( cmd == "RMD" ) { | 600 | else if ( cmd == "RMD" ) { |
601 | if ( args.isEmpty() ) | 601 | if ( args.isEmpty() ) |
602 | send( "500 Syntax error, command unrecognized" ); | 602 | send( "500 Syntax error, command unrecognized" ); |
603 | else { | 603 | else { |
604 | QDir dir; | 604 | QDir dir; |
605 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 605 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
606 | send( "250 Requested file action okay, completed" ); | 606 | send( "250 Requested file action okay, completed" ); |
607 | else | 607 | else |
608 | send( "550 Requested action not taken" ); | 608 | send( "550 Requested action not taken" ); |
609 | } | 609 | } |
610 | } | 610 | } |
611 | 611 | ||
612 | // make directory (MKD) | 612 | // make directory (MKD) |
613 | else if ( cmd == "MKD" ) { | 613 | else if ( cmd == "MKD" ) { |
614 | if ( args.isEmpty() ) { | 614 | if ( args.isEmpty() ) { |
615 | qDebug(" Error: no arg"); | 615 | qDebug(" Error: no arg"); |
616 | send( "500 Syntax error, command unrecognized" ); | 616 | send( "500 Syntax error, command unrecognized" ); |
617 | } | 617 | } |
618 | else { | 618 | else { |
619 | QDir dir; | 619 | QDir dir; |
620 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 620 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
621 | send( "250 Requested file action okay, completed." ); | 621 | send( "250 Requested file action okay, completed." ); |
622 | else | 622 | else |
623 | send( "550 Requested action not taken" ); | 623 | send( "550 Requested action not taken" ); |
624 | } | 624 | } |
625 | } | 625 | } |
626 | 626 | ||
627 | // print working directory (PWD) | 627 | // print working directory (PWD) |
628 | else if ( cmd == "PWD" ) { | 628 | else if ( cmd == "PWD" ) { |
629 | send( "257 \"" + directory.path() +"\"" ); | 629 | send( "257 \"" + directory.path() +"\"" ); |
630 | } | 630 | } |
631 | 631 | ||
632 | // list (LIST) | 632 | // list (LIST) |
633 | else if ( cmd == "LIST" ) { | 633 | else if ( cmd == "LIST" ) { |
634 | if ( sendList( absFilePath( args ) ) ) | 634 | if ( sendList( absFilePath( args ) ) ) |
635 | send( "150 File status okay" ); | 635 | send( "150 File status okay" ); |
636 | else | 636 | else |
637 | send( "500 Syntax error, command unrecognized" ); | 637 | send( "500 Syntax error, command unrecognized" ); |
638 | } | 638 | } |
639 | 639 | ||
640 | // size (SIZE) | 640 | // size (SIZE) |
641 | else if ( cmd == "SIZE" ) { | 641 | else if ( cmd == "SIZE" ) { |
642 | QString filePath = absFilePath( args ); | 642 | QString filePath = absFilePath( args ); |
643 | QFileInfo fi( filePath ); | 643 | QFileInfo fi( filePath ); |
644 | bool gzipfile = backupRestoreGzip( filePath ); | 644 | bool gzipfile = backupRestoreGzip( filePath ); |
645 | if ( !fi.exists() && !gzipfile ) | 645 | if ( !fi.exists() && !gzipfile ) |
646 | send( "500 Syntax error, command unrecognized" ); | 646 | send( "500 Syntax error, command unrecognized" ); |
647 | else { | 647 | else { |
648 | if ( !gzipfile ) | 648 | if ( !gzipfile ) |
649 | send( "213 " + QString::number( fi.size() ) ); | 649 | send( "213 " + QString::number( fi.size() ) ); |
650 | else { | 650 | else { |
651 | Process duproc( QString("du") ); | 651 | Process duproc( QString("du") ); |
652 | duproc.addArgument("-s"); | 652 | duproc.addArgument("-s"); |
653 | QString in, out; | 653 | QString in, out; |
654 | if ( !duproc.exec(in, out) ) { | 654 | if ( !duproc.exec(in, out) ) { |
655 | qDebug("du process failed; just sending back 1K"); | 655 | qDebug("du process failed; just sending back 1K"); |
656 | send( "213 1024"); | 656 | send( "213 1024"); |
657 | } | 657 | } |
658 | else { | 658 | else { |
659 | QString size = out.left( out.find("\t") ); | 659 | QString size = out.left( out.find("\t") ); |
660 | int guess = size.toInt()/5; | 660 | int guess = size.toInt()/5; |
661 | if ( filePath.contains("doc") ) | 661 | if ( filePath.contains("doc") ) |
662 | guess *= 1000; | 662 | guess *= 1000; |
663 | qDebug("sending back gzip guess of %d", guess); | 663 | qDebug("sending back gzip guess of %d", guess); |
664 | send( "213 " + QString::number(guess) ); | 664 | send( "213 " + QString::number(guess) ); |
665 | } | 665 | } |
666 | } | 666 | } |
667 | } | 667 | } |
668 | } | 668 | } |
669 | // name list (NLST) | 669 | // name list (NLST) |
670 | else if ( cmd == "NLST" ) { | 670 | else if ( cmd == "NLST" ) { |
671 | send( "502 Command not implemented" ); | 671 | send( "502 Command not implemented" ); |
672 | } | 672 | } |
673 | 673 | ||
674 | // site parameters (SITE) | 674 | // site parameters (SITE) |
675 | else if ( cmd == "SITE" ) { | 675 | else if ( cmd == "SITE" ) { |
676 | send( "502 Command not implemented" ); | 676 | send( "502 Command not implemented" ); |
677 | } | 677 | } |
678 | 678 | ||
679 | // system (SYST) | 679 | // system (SYST) |
680 | else if ( cmd == "SYST" ) { | 680 | else if ( cmd == "SYST" ) { |
681 | send( "215 UNIX Type: L8" ); | 681 | send( "215 UNIX Type: L8" ); |
682 | } | 682 | } |
683 | 683 | ||
684 | // status (STAT) | 684 | // status (STAT) |
685 | else if ( cmd == "STAT" ) { | 685 | else if ( cmd == "STAT" ) { |
686 | send( "502 Command not implemented" ); | 686 | send( "502 Command not implemented" ); |
687 | } | 687 | } |
688 | 688 | ||
689 | // help (HELP ) | 689 | // help (HELP ) |
690 | else if ( cmd == "HELP" ) { | 690 | else if ( cmd == "HELP" ) { |
691 | send( "502 Command not implemented" ); | 691 | send( "502 Command not implemented" ); |
692 | } | 692 | } |
693 | 693 | ||
694 | // noop (NOOP) | 694 | // noop (NOOP) |
695 | else if ( cmd == "NOOP" ) { | 695 | else if ( cmd == "NOOP" ) { |
696 | send( "200 Command okay" ); | 696 | send( "200 Command okay" ); |
697 | } | 697 | } |
698 | 698 | ||
699 | // not implemented | 699 | // not implemented |
700 | else | 700 | else |
701 | send( "502 Command not implemented" ); | 701 | send( "502 Command not implemented" ); |
702 | 702 | ||
703 | lastCommand = cmd; | 703 | lastCommand = cmd; |
704 | } | 704 | } |
705 | 705 | ||
706 | bool ServerPI::backupRestoreGzip( const QString &file ) | 706 | bool ServerPI::backupRestoreGzip( const QString &file ) |
707 | { | 707 | { |
708 | return (file.find( "backup" ) != -1 && | 708 | return (file.find( "backup" ) != -1 && |
709 | file.findRev( ".tgz" ) == (int)file.length()-4 ); | 709 | file.findRev( ".tgz" ) == (int)file.length()-4 ); |
710 | } | 710 | } |
711 | 711 | ||
712 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | 712 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) |
713 | { | 713 | { |
714 | if ( file.find( "backup" ) != -1 && | 714 | if ( file.find( "backup" ) != -1 && |
715 | file.findRev( ".tgz" ) == (int)file.length()-4 ) { | 715 | file.findRev( ".tgz" ) == (int)file.length()-4 ) { |
716 | QFileInfo info( file ); | 716 | QFileInfo info( file ); |
717 | targets = info.dirPath( TRUE ); | 717 | targets = info.dirPath( TRUE ); |
718 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), | 718 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), |
719 | targets.join(" ").latin1() ); | 719 | targets.join(" ").latin1() ); |
720 | return true; | 720 | return true; |
721 | } | 721 | } |
722 | return false; | 722 | return false; |
723 | } | 723 | } |
724 | 724 | ||
725 | void ServerPI::sendFile( const QString& file ) | 725 | void ServerPI::sendFile( const QString& file ) |
726 | { | 726 | { |
727 | if ( passiv ) { | 727 | if ( passiv ) { |
728 | wait[SendFile] = TRUE; | 728 | wait[SendFile] = TRUE; |
729 | waitfile = file; | 729 | waitfile = file; |
730 | if ( waitsocket ) | 730 | if ( waitsocket ) |
731 | newConnection( waitsocket ); | 731 | newConnection( waitsocket ); |
732 | } | 732 | } |
733 | else { | 733 | else { |
734 | QStringList targets; | 734 | QStringList targets; |
735 | if ( backupRestoreGzip( file, targets ) ) | 735 | if ( backupRestoreGzip( file, targets ) ) |
736 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 736 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
737 | else dtp->sendFile( file, peeraddress, peerport ); | 737 | else dtp->sendFile( file, peeraddress, peerport ); |
738 | } | 738 | } |
739 | } | 739 | } |
740 | 740 | ||
741 | void ServerPI::retrieveFile( const QString& file ) | 741 | void ServerPI::retrieveFile( const QString& file ) |
742 | { | 742 | { |
743 | if ( passiv ) { | 743 | if ( passiv ) { |
744 | wait[RetrieveFile] = TRUE; | 744 | wait[RetrieveFile] = TRUE; |
745 | waitfile = file; | 745 | waitfile = file; |