summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-04 21:16:03 (UTC)
committer zecke <zecke>2002-10-04 21:16:03 (UTC)
commit10048c2dd7f7cd26c582d64b5e255b00b47de304 (patch) (unidiff)
tree3b2a79d8218efe5f80d1b2e79e77b22cbc27c2ba
parentdc0344e987ba9b386056dd7bab7c5e34922eff5c (diff)
downloadopie-10048c2dd7f7cd26c582d64b5e255b00b47de304.zip
opie-10048c2dd7f7cd26c582d64b5e255b00b47de304.tar.gz
opie-10048c2dd7f7cd26c582d64b5e255b00b47de304.tar.bz2
Weird for some of you
_OS_LINUX_ does not get defined so now it's a if !define(_OS_LINUX) but this means you need to libuuid again I don't know how to fix that right. I should ask tt
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/transferserver.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index a20df2f..f9204ab 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,238 +1,238 @@
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#ifndef _OS_LINUX_ 28#ifndef _OS_LINUX_
29 29
30extern "C" { 30extern "C" {
31#include <uuid/uuid.h> 31#include <uuid/uuid.h>
32#define UUID_H_INCLUDED 32#define UUID_H_INCLUDED
33} 33}
34 34
35#endif // not defined linux 35#endif // not defined linux
36 36
37#if defined(_OS_LINUX_) 37#if defined(_OS_LINUX_)
38#include <shadow.h> 38#include <shadow.h>
39#endif 39#endif
40 40
41#include <qdir.h> 41#include <qdir.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qtextstream.h> 43#include <qtextstream.h>
44#include <qdatastream.h> 44#include <qdatastream.h>
45#include <qmessagebox.h> 45#include <qmessagebox.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qfileinfo.h> 47#include <qfileinfo.h>
48#include <qregexp.h> 48#include <qregexp.h>
49//#include <qpe/qcopchannel_qws.h> 49//#include <qpe/qcopchannel_qws.h>
50#include <qpe/process.h> 50#include <qpe/process.h>
51#include <qpe/global.h> 51#include <qpe/global.h>
52#include <qpe/config.h> 52#include <qpe/config.h>
53#include <qpe/contact.h> 53#include <qpe/contact.h>
54#include <qpe/quuid.h> 54#include <qpe/quuid.h>
55#include <qpe/version.h> 55#include <qpe/version.h>
56#ifdef QWS 56#ifdef QWS
57#include <qpe/qcopenvelope_qws.h> 57#include <qpe/qcopenvelope_qws.h>
58#endif 58#endif
59 59
60#include "transferserver.h" 60#include "transferserver.h"
61#include "qprocess.h" 61#include "qprocess.h"
62 62
63const int block_size = 51200; 63const int block_size = 51200;
64 64
65TransferServer::TransferServer( Q_UINT16 port, QObject *parent , 65TransferServer::TransferServer( Q_UINT16 port, QObject *parent ,
66 const char* name ) 66 const char* name )
67 : QServerSocket( port, 1, parent, name ) 67 : QServerSocket( port, 1, parent, name )
68{ 68{
69 if ( !ok() ) 69 if ( !ok() )
70 qWarning( "Failed to bind to port %d", port ); 70 qWarning( "Failed to bind to port %d", port );
71} 71}
72 72
73TransferServer::~TransferServer() 73TransferServer::~TransferServer()
74{ 74{
75 75
76} 76}
77 77
78void TransferServer::newConnection( int socket ) 78void TransferServer::newConnection( int socket )
79{ 79{
80 (void) new ServerPI( socket, this ); 80 (void) new ServerPI( socket, this );
81} 81}
82 82
83/* 83/*
84 * small class in anonymous namespace 84 * small class in anonymous namespace
85 * to generate a QUUid for us 85 * to generate a QUUid for us
86 */ 86 */
87namespace { 87namespace {
88 struct UidGen { 88 struct UidGen {
89 QString uuid(); 89 QString uuid();
90 }; 90 };
91#if defined(_OS_LINUX_) 91#if !defined(_OS_LINUX_)
92 QString UidGen::uuid() {
93 uuid_t uuid;
94 uuid_generate( uuid );
95 return QUUid( uuid ).toString();
96 }
97#else
92 /* 98 /*
93 * linux got a /proc/sys/kernel/random/uuid file 99 * linux got a /proc/sys/kernel/random/uuid file
94 * it'll generate the uuids for us 100 * it'll generate the uuids for us
95 */ 101 */
96 QString UidGen::uuid() { 102 QString UidGen::uuid() {
97 QFile file( "/proc/sys/kernel/random/uuid" ); 103 QFile file( "/proc/sys/kernel/random/uuid" );
98 if (!file.open(IO_ReadOnly ) ) 104 if (!file.open(IO_ReadOnly ) )
99 return QString::null; 105 return QString::null;
100 106
101 QTextStream stream(&file); 107 QTextStream stream(&file);
102 108
103 return "{" + stream.read().stripWhiteSpace() + "}"; 109 return "{" + stream.read().stripWhiteSpace() + "}";
104 } 110 }
105#else
106 QString UidGen::uuid() {
107 uuid_t uuid;
108 uuid_generate( uuid );
109 return QUUid( uuid ).toString();
110 }
111#endif 111#endif
112} 112}
113 113
114QString SyncAuthentication::serverId() 114QString SyncAuthentication::serverId()
115{ 115{
116 Config cfg("Security"); 116 Config cfg("Security");
117 cfg.setGroup("Sync"); 117 cfg.setGroup("Sync");
118 QString r=cfg.readEntry("serverid"); 118 QString r=cfg.readEntry("serverid");
119 if ( r.isEmpty() ) { 119 if ( r.isEmpty() ) {
120 UidGen gen; 120 UidGen gen;
121 r = gen.uuid(); 121 r = gen.uuid();
122 cfg.writeEntry("serverid", r ); 122 cfg.writeEntry("serverid", r );
123 } 123 }
124 return r; 124 return r;
125} 125}
126 126
127QString SyncAuthentication::ownerName() 127QString SyncAuthentication::ownerName()
128{ 128{
129 QString vfilename = Global::applicationFileName("addressbook", 129 QString vfilename = Global::applicationFileName("addressbook",
130 "businesscard.vcf"); 130 "businesscard.vcf");
131 if (QFile::exists(vfilename)) { 131 if (QFile::exists(vfilename)) {
132 Contact c; 132 Contact c;
133 c = Contact::readVCard( vfilename )[0]; 133 c = Contact::readVCard( vfilename )[0];
134 return c.fullName(); 134 return c.fullName();
135 } 135 }
136 136
137 return ""; 137 return "";
138} 138}
139 139
140QString SyncAuthentication::loginName() 140QString SyncAuthentication::loginName()
141{ 141{
142 struct passwd *pw; 142 struct passwd *pw;
143 pw = getpwuid( geteuid() ); 143 pw = getpwuid( geteuid() );
144 return QString::fromLocal8Bit( pw->pw_name ); 144 return QString::fromLocal8Bit( pw->pw_name );
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 return (peeraddress.ip4Addr() & mask) == auth_peer; 160 return (peeraddress.ip4Addr() & mask) == auth_peer;
161} 161}
162 162
163bool SyncAuthentication::checkUser( const QString& user ) 163bool SyncAuthentication::checkUser( const QString& user )
164{ 164{
165 if ( user.isEmpty() ) return FALSE; 165 if ( user.isEmpty() ) return FALSE;
166 QString euser = loginName(); 166 QString euser = loginName();
167 return user == euser; 167 return user == euser;
168} 168}
169 169
170bool SyncAuthentication::checkPassword( const QString& password ) 170bool SyncAuthentication::checkPassword( const QString& password )
171{ 171{
172#ifdef ALLOW_UNIX_USER_FTP 172#ifdef ALLOW_UNIX_USER_FTP
173 // First, check system password... 173 // First, check system password...
174 174
175 struct passwd *pw = 0; 175 struct passwd *pw = 0;
176 struct spwd *spw = 0; 176 struct spwd *spw = 0;
177 177
178 pw = getpwuid( geteuid() ); 178 pw = getpwuid( geteuid() );
179 spw = getspnam( pw->pw_name ); 179 spw = getspnam( pw->pw_name );
180 180
181 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 181 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
182 if ( cpwd == "x" && spw ) 182 if ( cpwd == "x" && spw )
183 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 183 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
184 184
185 // Note: some systems use more than crypt for passwords. 185 // Note: some systems use more than crypt for passwords.
186 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 186 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
187 if ( cpwd == cpassword ) 187 if ( cpwd == cpassword )
188 return TRUE; 188 return TRUE;
189#endif 189#endif
190 190
191 static int lastdenial=0; 191 static int lastdenial=0;
192 static int denials=0; 192 static int denials=0;
193 int now = time(0); 193 int now = time(0);
194 194
195 // Detect old Qtopia Desktop (no password) 195 // Detect old Qtopia Desktop (no password)
196 if ( password.isEmpty() ) { 196 if ( password.isEmpty() ) {
197 if ( denials < 1 || now > lastdenial+600 ) { 197 if ( denials < 1 || now > lastdenial+600 ) {
198 QMessageBox::warning( 0,tr("Sync Connection"), 198 QMessageBox::warning( 0,tr("Sync Connection"),
199 tr("<p>An unauthorized system is requesting access to this device." 199 tr("<p>An unauthorized system is requesting access to this device."
200 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 200 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
201 "please upgrade."), 201 "please upgrade."),
202 tr("Deny") ); 202 tr("Deny") );
203 denials++; 203 denials++;
204 lastdenial=now; 204 lastdenial=now;
205 } 205 }
206 return FALSE; 206 return FALSE;
207 } 207 }
208 208
209 // Second, check sync password... 209 // Second, check sync password...
210 QString pass = password.left(6); 210 QString pass = password.left(6);
211 /* old QtopiaDesktops are sending 211 /* old QtopiaDesktops are sending
212 * rootme newer versions got a Qtopia 212 * rootme newer versions got a Qtopia
213 * prefixed. Qtopia prefix will suceed 213 * prefixed. Qtopia prefix will suceed
214 * until the sync software syncs up 214 * until the sync software syncs up
215 * FIXME 215 * FIXME
216 */ 216 */
217 if ( pass == "rootme" || pass == "Qtopia") { 217 if ( pass == "rootme" || pass == "Qtopia") {
218 218
219 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) ); 219 QString cpassword = QString::fromLocal8Bit( crypt( password.mid(8).local8Bit(), "qp" ) );
220 Config cfg("Security"); 220 Config cfg("Security");
221 cfg.setGroup("Sync"); 221 cfg.setGroup("Sync");
222 QString pwds = cfg.readEntry("Passwords"); 222 QString pwds = cfg.readEntry("Passwords");
223 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) ) 223 if ( QStringList::split(QChar(' '),pwds).contains(cpassword) )
224 return TRUE; 224 return TRUE;
225 225
226 // Unrecognized system. Be careful... 226 // Unrecognized system. Be careful...
227 227
228 if ( (denials > 2 && now < lastdenial+600) 228 if ( (denials > 2 && now < lastdenial+600)
229 || QMessageBox::warning(0,tr("Sync Connection"), 229 || QMessageBox::warning(0,tr("Sync Connection"),
230 tr("<p>An unrecognized system is requesting access to this device." 230 tr("<p>An unrecognized system is requesting access to this device."
231 "<p>If you have just initiated a Sync for the first time, this is normal."), 231 "<p>If you have just initiated a Sync for the first time, this is normal."),
232 tr("Allow"),tr("Deny"))==1 ) 232 tr("Allow"),tr("Deny"))==1 )
233 { 233 {
234 denials++; 234 denials++;
235 lastdenial=now; 235 lastdenial=now;
236 return FALSE; 236 return FALSE;
237 } else { 237 } else {
238 denials=0; 238 denials=0;