-rw-r--r-- | core/qws/transferserver.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/core/qws/transferserver.cpp b/core/qws/transferserver.cpp index 0337a94..239c824 100644 --- a/core/qws/transferserver.cpp +++ b/core/qws/transferserver.cpp | |||
@@ -1,212 +1,231 @@ | |||
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 | |||
27 | #ifndef Q_OS_MACX | ||
26 | #include <shadow.h> | 28 | #include <shadow.h> |
29 | #endif /* Q_OS_MACX */ | ||
27 | 30 | ||
28 | /* we need the _OS_LINUX stuff first ! */ | 31 | /* we need the _OS_LINUX stuff first ! */ |
29 | #include <qglobal.h> | 32 | #include <qglobal.h> |
30 | 33 | ||
31 | #ifndef _OS_LINUX_ | 34 | #ifndef _OS_LINUX_ |
35 | // Is anybody able to review this ? The include "uuid/uuid.h" couldn't be found | ||
36 | // anywhere ? Therfore I removed it completely.. | ||
37 | // I think it should be made permanentyl !? (eilers) | ||
38 | #warning "Where should uuid/uuid.h be found ? Removed this part .. (eilers)" | ||
39 | #if 0 | ||
32 | 40 | ||
33 | extern "C" | 41 | extern "C" |
34 | { | 42 | { |
35 | #include <uuid/uuid.h> | 43 | #include <uuid/uuid.h> |
36 | #define UUID_H_INCLUDED | 44 | #define UUID_H_INCLUDED |
37 | } | 45 | } |
38 | 46 | ||
47 | #endif | ||
48 | |||
39 | #endif // not defined linux | 49 | #endif // not defined linux |
40 | 50 | ||
41 | #if defined(_OS_LINUX_) | 51 | #if defined(_OS_LINUX_) |
42 | #include <shadow.h> | 52 | #include <shadow.h> |
53 | #elif defined(Q_OS_MACX) | ||
54 | #include <stdlib.h> | ||
43 | #endif | 55 | #endif |
44 | 56 | ||
45 | #include <qdir.h> | 57 | #include <qdir.h> |
46 | #include <qfile.h> | 58 | #include <qfile.h> |
47 | #include <qtextstream.h> | 59 | #include <qtextstream.h> |
48 | #include <qdatastream.h> | 60 | #include <qdatastream.h> |
49 | #include <qmessagebox.h> | 61 | #include <qmessagebox.h> |
50 | #include <qstringlist.h> | 62 | #include <qstringlist.h> |
51 | #include <qfileinfo.h> | 63 | #include <qfileinfo.h> |
52 | #include <qregexp.h> | 64 | #include <qregexp.h> |
53 | //#include <qpe/qcopchannel_qws.h> | 65 | //#include <qpe/qcopchannel_qws.h> |
54 | #include <qpe/process.h> | 66 | #include <qpe/process.h> |
55 | #include <qpe/global.h> | 67 | #include <qpe/global.h> |
56 | #include <qpe/config.h> | 68 | #include <qpe/config.h> |
57 | #include <qpe/contact.h> | 69 | #include <qpe/contact.h> |
58 | #include <qpe/quuid.h> | 70 | #include <qpe/quuid.h> |
59 | #include <qpe/version.h> | 71 | #include <qpe/version.h> |
60 | #include <qpe/qcopenvelope_qws.h> | 72 | #include <qpe/qcopenvelope_qws.h> |
61 | 73 | ||
62 | #include "transferserver.h" | 74 | #include "transferserver.h" |
63 | #include <opie/oprocess.h> | 75 | #include <opie/oprocess.h> |
64 | 76 | ||
65 | const int block_size = 51200; | 77 | const int block_size = 51200; |
66 | 78 | ||
67 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , | 79 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent , |
68 | const char* name ) | 80 | const char* name ) |
69 | : QServerSocket( port, 1, parent, name ) | 81 | : QServerSocket( port, 1, parent, name ) |
70 | { | 82 | { |
71 | if ( !ok() ) | 83 | if ( !ok() ) |
72 | qWarning( "Failed to bind to port %d", port ); | 84 | qWarning( "Failed to bind to port %d", port ); |
73 | } | 85 | } |
74 | 86 | ||
75 | TransferServer::~TransferServer() | 87 | TransferServer::~TransferServer() |
76 | { | 88 | { |
77 | } | 89 | } |
78 | 90 | ||
79 | void TransferServer::newConnection( int socket ) | 91 | void TransferServer::newConnection( int socket ) |
80 | { | 92 | { |
81 | (void) new ServerPI( socket, this ); | 93 | (void) new ServerPI( socket, this ); |
82 | } | 94 | } |
83 | 95 | ||
84 | /* | 96 | /* |
85 | * small class in anonymous namespace | 97 | * small class in anonymous namespace |
86 | * to generate a QUUid for us | 98 | * to generate a QUUid for us |
87 | */ | 99 | */ |
88 | namespace | 100 | namespace |
89 | { | 101 | { |
90 | struct UidGen | 102 | struct UidGen |
91 | { | 103 | { |
92 | QString uuid(); | 104 | QString uuid(); |
93 | }; | 105 | }; |
94 | #if !defined(_OS_LINUX_) | 106 | #if defined(Q_OS_MACX) |
95 | |||
96 | QString UidGen::uuid() | 107 | QString UidGen::uuid() |
97 | { | 108 | { |
98 | uuid_t uuid; | 109 | srandom( random() ); |
99 | uuid_generate( uuid ); | 110 | QString numStr = QString::number( random() ); |
100 | return QUUid( uuid ).toString(); | 111 | |
112 | return "{" + numStr + "}"; | ||
101 | } | 113 | } |
102 | #else | 114 | #elif defined(_OS_LINUX_) |
103 | /* | 115 | /* |
104 | * linux got a /proc/sys/kernel/random/uuid file | 116 | * linux got a /proc/sys/kernel/random/uuid file |
105 | * it'll generate the uuids for us | 117 | * it'll generate the uuids for us |
106 | */ | 118 | */ |
107 | QString UidGen::uuid() | 119 | QString UidGen::uuid() |
108 | { | 120 | { |
109 | QFile file( "/proc/sys/kernel/random/uuid" ); | 121 | QFile file( "/proc/sys/kernel/random/uuid" ); |
110 | if (!file.open(IO_ReadOnly ) ) | 122 | if (!file.open(IO_ReadOnly ) ) |
111 | return QString::null; | 123 | return QString::null; |
112 | 124 | ||
113 | QTextStream stream(&file); | 125 | QTextStream stream(&file); |
114 | 126 | ||
115 | return "{" + stream.read().stripWhiteSpace() + "}"; | 127 | return "{" + stream.read().stripWhiteSpace() + "}"; |
116 | } | 128 | } |
129 | #else | ||
130 | QString UidGen::uuid() | ||
131 | { | ||
132 | uuid_t uuid; | ||
133 | ::uuid_generate( uuid ); | ||
134 | return QUUid( uuid ).toString(); | ||
135 | } | ||
117 | #endif | 136 | #endif |
118 | } | 137 | } |
119 | 138 | ||
120 | QString SyncAuthentication::serverId() | 139 | QString SyncAuthentication::serverId() |
121 | { | 140 | { |
122 | Config cfg("Security"); | 141 | Config cfg("Security"); |
123 | cfg.setGroup("Sync"); | 142 | cfg.setGroup("Sync"); |
124 | QString r = cfg.readEntry("serverid"); | 143 | QString r = cfg.readEntry("serverid"); |
125 | if ( r.isEmpty() ) { | 144 | if ( r.isEmpty() ) { |
126 | UidGen gen; | 145 | UidGen gen; |
127 | r = gen.uuid(); | 146 | r = gen.uuid(); |
128 | cfg.writeEntry("serverid", r ); | 147 | cfg.writeEntry("serverid", r ); |
129 | } | 148 | } |
130 | return r; | 149 | return r; |
131 | } | 150 | } |
132 | 151 | ||
133 | QString SyncAuthentication::ownerName() | 152 | QString SyncAuthentication::ownerName() |
134 | { | 153 | { |
135 | QString vfilename = Global::applicationFileName("addressbook", | 154 | QString vfilename = Global::applicationFileName("addressbook", |
136 | "businesscard.vcf"); | 155 | "businesscard.vcf"); |
137 | if (QFile::exists(vfilename)) { | 156 | if (QFile::exists(vfilename)) { |
138 | Contact c; | 157 | Contact c; |
139 | c = Contact::readVCard( vfilename )[0]; | 158 | c = Contact::readVCard( vfilename )[0]; |
140 | return c.fullName(); | 159 | return c.fullName(); |
141 | } | 160 | } |
142 | 161 | ||
143 | return ""; | 162 | return ""; |
144 | } | 163 | } |
145 | 164 | ||
146 | QString SyncAuthentication::loginName() | 165 | QString SyncAuthentication::loginName() |
147 | { | 166 | { |
148 | struct passwd *pw; | 167 | struct passwd *pw; |
149 | pw = getpwuid( geteuid() ); | 168 | pw = getpwuid( geteuid() ); |
150 | return QString::fromLocal8Bit( pw->pw_name ); | 169 | return QString::fromLocal8Bit( pw->pw_name ); |
151 | } | 170 | } |
152 | 171 | ||
153 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 172 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
154 | { | 173 | { |
155 | Config cfg("Security"); | 174 | Config cfg("Security"); |
156 | cfg.setGroup("Sync"); | 175 | cfg.setGroup("Sync"); |
157 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 176 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
158 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); | 177 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); |
159 | 178 | ||
160 | // QHostAddress allowed; | 179 | // QHostAddress allowed; |
161 | // allowed.setAddress(allowedstr); | 180 | // allowed.setAddress(allowedstr); |
162 | // uint auth_peer = allowed.ip4Addr(); | 181 | // uint auth_peer = allowed.ip4Addr(); |
163 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); | 182 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); |
164 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 183 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
165 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); | 184 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); |
166 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 185 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
167 | } | 186 | } |
168 | 187 | ||
169 | bool SyncAuthentication::checkUser( const QString& user ) | 188 | bool SyncAuthentication::checkUser( const QString& user ) |
170 | { | 189 | { |
171 | if ( user.isEmpty() ) | 190 | if ( user.isEmpty() ) |
172 | return FALSE; | 191 | return FALSE; |
173 | QString euser = loginName(); | 192 | QString euser = loginName(); |
174 | return user == euser; | 193 | return user == euser; |
175 | } | 194 | } |
176 | 195 | ||
177 | bool SyncAuthentication::checkPassword( const QString& password ) | 196 | bool SyncAuthentication::checkPassword( const QString& password ) |
178 | { | 197 | { |
179 | #ifdef ALLOW_UNIX_USER_FTP | 198 | #ifdef ALLOW_UNIX_USER_FTP |
180 | // First, check system password... | 199 | // First, check system password... |
181 | 200 | ||
182 | struct passwd *pw = 0; | 201 | struct passwd *pw = 0; |
183 | struct spwd *spw = 0; | 202 | struct spwd *spw = 0; |
184 | 203 | ||
185 | pw = getpwuid( geteuid() ); | 204 | pw = getpwuid( geteuid() ); |
186 | spw = getspnam( pw->pw_name ); | 205 | spw = getspnam( pw->pw_name ); |
187 | 206 | ||
188 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 207 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
189 | if ( cpwd == "x" && spw ) | 208 | if ( cpwd == "x" && spw ) |
190 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 209 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
191 | 210 | ||
192 | // Note: some systems use more than crypt for passwords. | 211 | // Note: some systems use more than crypt for passwords. |
193 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 212 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
194 | if ( cpwd == cpassword ) | 213 | if ( cpwd == cpassword ) |
195 | return TRUE; | 214 | return TRUE; |
196 | #endif | 215 | #endif |
197 | 216 | ||
198 | static int lastdenial = 0; | 217 | static int lastdenial = 0; |
199 | static int denials = 0; | 218 | static int denials = 0; |
200 | int now = time(0); | 219 | int now = time(0); |
201 | 220 | ||
202 | // Detect old Qtopia Desktop (no password) | 221 | // Detect old Qtopia Desktop (no password) |
203 | if ( password.isEmpty() ) { | 222 | if ( password.isEmpty() ) { |
204 | if ( denials < 1 || now > lastdenial + 600 ) { | 223 | if ( denials < 1 || now > lastdenial + 600 ) { |
205 | QMessageBox::warning( 0, tr("Sync Connection"), | 224 | QMessageBox::warning( 0, tr("Sync Connection"), |
206 | tr("<p>An unauthorized system is requesting access to this device." | 225 | tr("<p>An unauthorized system is requesting access to this device." |
207 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 226 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
208 | "please upgrade."), | 227 | "please upgrade."), |
209 | tr("Deny") ); | 228 | tr("Deny") ); |
210 | denials++; | 229 | denials++; |
211 | lastdenial = now; | 230 | lastdenial = now; |
212 | } | 231 | } |