author | wimpie <wimpie> | 2004-04-05 01:13:11 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-05 01:13:11 (UTC) |
commit | 6be3d148fc1d610ebfa193012657b3b77d9368e3 (patch) (unidiff) | |
tree | d7bbd308d17ffe7557c7749776f4945e499d7c10 | |
parent | b0ceb8843ebe9ee3054faa98f08bd255df955aa3 (diff) | |
download | opie-6be3d148fc1d610ebfa193012657b3b77d9368e3.zip opie-6be3d148fc1d610ebfa193012657b3b77d9368e3.tar.gz opie-6be3d148fc1d610ebfa193012657b3b77d9368e3.tar.bz2 |
For usb this seems to be working
Also for non-root users (requires using SUDO)
11 files changed, 270 insertions, 36 deletions
diff --git a/noncore/settings/networksettings2/activateprofile.cpp b/noncore/settings/networksettings2/activateprofile.cpp index ba726bb..e4064e3 100644 --- a/noncore/settings/networksettings2/activateprofile.cpp +++ b/noncore/settings/networksettings2/activateprofile.cpp | |||
@@ -1,16 +1,18 @@ | |||
1 | #include <qlistbox.h> | 1 | #include <qlistbox.h> |
2 | #include <qlabel.h> | ||
2 | #include "activateprofile.h" | 3 | #include "activateprofile.h" |
3 | 4 | ||
4 | ActivateProfile::ActivateProfile( const char * Interface ) : | 5 | ActivateProfile::ActivateProfile( const char * Interface ) : |
5 | ActivateProfileGUI( 0, 0, TRUE ), NSD() { | 6 | ActivateProfileGUI( 0, 0, TRUE ), NSD() { |
6 | 7 | ||
7 | Possible = NSD.collectPossible( Interface ); | 8 | Possible = NSD.collectPossible( Interface ); |
8 | 9 | ||
10 | DeviceName_LBL->setText( Interface ); | ||
9 | Profiles_LB->clear(); | 11 | Profiles_LB->clear(); |
10 | for( NodeCollection * NC = Possible.first(); | 12 | for( NodeCollection * NC = Possible.first(); |
11 | NC; | 13 | NC; |
12 | NC = Possible.next() ) { | 14 | NC = Possible.next() ) { |
13 | Profiles_LB->insertItem( NC->devicePixmap(), | 15 | Profiles_LB->insertItem( NC->devicePixmap(), |
14 | NC->name() ); | 16 | NC->name() ); |
15 | } | 17 | } |
16 | } | 18 | } |
diff --git a/noncore/settings/networksettings2/activateprofileGUI.ui b/noncore/settings/networksettings2/activateprofileGUI.ui index 296e044..12ab051 100644 --- a/noncore/settings/networksettings2/activateprofileGUI.ui +++ b/noncore/settings/networksettings2/activateprofileGUI.ui | |||
@@ -12,17 +12,17 @@ | |||
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>231</width> | 14 | <width>231</width> |
15 | <height>121</height> | 15 | <height>121</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Activate Profile</string> | 20 | <string>Activate Network</string> |
21 | </property> | 21 | </property> |
22 | <property> | 22 | <property> |
23 | <name>layoutMargin</name> | 23 | <name>layoutMargin</name> |
24 | </property> | 24 | </property> |
25 | <property> | 25 | <property> |
26 | <name>layoutSpacing</name> | 26 | <name>layoutSpacing</name> |
27 | </property> | 27 | </property> |
28 | <vbox> | 28 | <vbox> |
@@ -52,17 +52,17 @@ | |||
52 | <widget> | 52 | <widget> |
53 | <class>QLabel</class> | 53 | <class>QLabel</class> |
54 | <property stdset="1"> | 54 | <property stdset="1"> |
55 | <name>name</name> | 55 | <name>name</name> |
56 | <cstring>TextLabel1</cstring> | 56 | <cstring>TextLabel1</cstring> |
57 | </property> | 57 | </property> |
58 | <property stdset="1"> | 58 | <property stdset="1"> |
59 | <name>text</name> | 59 | <name>text</name> |
60 | <string>Select profile for device :</string> | 60 | <string>Select profile to activate for </string> |
61 | </property> | 61 | </property> |
62 | </widget> | 62 | </widget> |
63 | <widget> | 63 | <widget> |
64 | <class>QLabel</class> | 64 | <class>QLabel</class> |
65 | <property stdset="1"> | 65 | <property stdset="1"> |
66 | <name>name</name> | 66 | <name>name</name> |
67 | <cstring>DeviceName_LBL</cstring> | 67 | <cstring>DeviceName_LBL</cstring> |
68 | </property> | 68 | </property> |
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 7ec26a7..e2c00f6 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp | |||
@@ -1,11 +1,12 @@ | |||
1 | #include "nsdata.h" | 1 | #include "nsdata.h" |
2 | #include "activateprofile.h" | 2 | #include "activateprofile.h" |
3 | #include "networksettings.h" | 3 | #include "networksettings.h" |
4 | |||
4 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
5 | 6 | ||
6 | #include <opie/oapplicationfactory.h> | 7 | #include <opie/oapplicationfactory.h> |
7 | 8 | ||
8 | #ifdef GONE | 9 | #ifdef GONE |
9 | 10 | ||
10 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) | 11 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) |
11 | 12 | ||
@@ -71,17 +72,29 @@ int main( int argc, char * argv[] ) { | |||
71 | TheApp = new QApplication( argc, argv, GuiType ); | 72 | TheApp = new QApplication( argc, argv, GuiType ); |
72 | #endif | 73 | #endif |
73 | 74 | ||
74 | // init qt with app widget | 75 | // init qt with app widget |
75 | 76 | ||
76 | switch( Action ) { | 77 | switch( Action ) { |
77 | case ACT_REQUEST : | 78 | case ACT_REQUEST : |
78 | { NetworkSettingsData NS; | 79 | { NetworkSettingsData NS; |
79 | NS.canStart( argv[1] ); | 80 | if( NS.canStart( argv[1] ) ) { |
81 | QString S; | ||
82 | S.sprintf( QPEApplication::qpeDir()+ | ||
83 | "/bin/networksettings2" ); | ||
84 | char * MyArgv[4]; | ||
85 | MyArgv[0] = "networksettings2"; | ||
86 | MyArgv[1] = "--prompt"; | ||
87 | MyArgv[2] = argv[1]; | ||
88 | MyArgv[3] = NULL; | ||
89 | NSResources->system().execAsUser( S, MyArgv ); | ||
90 | // if we come here , failed | ||
91 | printf( "%s-cNN-disallowed", argv[1] ); | ||
92 | } | ||
80 | } | 93 | } |
81 | break; | 94 | break; |
82 | case ACT_REGEN : | 95 | case ACT_REGEN : |
83 | { NetworkSettingsData NS; | 96 | { NetworkSettingsData NS; |
84 | // regen returns 0 if OK | 97 | // regen returns 0 if OK |
85 | rv = (NS.regenerate()) ? 1 : 0; | 98 | rv = (NS.regenerate()) ? 1 : 0; |
86 | } | 99 | } |
87 | break; | 100 | break; |
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 054385a..3e368a2 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp | |||
@@ -104,33 +104,54 @@ bool ANetwork::hasDataFor( const QString & S ) { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { | 106 | bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { |
107 | QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); | 107 | QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); |
108 | 108 | ||
109 | if( S.name() == "interfaces" ) { | 109 | if( S.name() == "interfaces" ) { |
110 | // we can safely call from here since device item is deeper | 110 | // we can safely call from here since device item is deeper |
111 | if( Data.UseDHCP ) { | 111 | if( Data.UseDHCP ) { |
112 | S << "iface " << NIC << "-c" << connection()->number() << | 112 | S << "iface " |
113 | "-allowed inet dhcp" << endl; | 113 | << NIC |
114 | S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << | 114 | << "-c" |
115 | ".up" << Data.IPAddress << endl; | 115 | << connection()->number() |
116 | << "-allowed inet dhcp" | ||
117 | << endl; | ||
118 | S << " up echo \"" | ||
119 | << NIC | ||
120 | << "\" > /tmp/profile-" | ||
121 | << connection()->number() | ||
122 | << ".up" | ||
123 | << endl; | ||
116 | if( Data.SendHostname ) { | 124 | if( Data.SendHostname ) { |
117 | S << " hostname "<< Data.Hostname << endl; | 125 | S << " hostname " |
126 | << Data.Hostname | ||
127 | << endl; | ||
118 | } | 128 | } |
119 | 129 | ||
120 | S << " down rm -f /tmp/profile-" << connection()->number() << | 130 | S << " down rm -f /tmp/profile-" |
121 | ".up" << Data.IPAddress << endl; | 131 | << connection()->number() |
132 | << ".up" | ||
133 | << endl; | ||
122 | } else { | 134 | } else { |
123 | S << "iface " << NIC << "-c" << connection()->number() << | 135 | S << "iface " |
124 | "-allowed inet static" << endl; | 136 | << NIC << "-c" |
125 | S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << | 137 | << connection()->number() |
126 | ".up" << Data.IPAddress << endl; | 138 | << "-allowed inet static" |
127 | S << " down rm -f /tmp/profile-" << connection()->number() << | 139 | << endl; |
128 | ".up" << Data.IPAddress << endl; | 140 | S << " up echo \"" |
141 | << NIC | ||
142 | << "\" > /tmp/profile-" | ||
143 | << connection()->number() | ||
144 | << ".up" | ||
145 | << endl; | ||
146 | S << " down rm -f /tmp/profile-" | ||
147 | << connection()->number() | ||
148 | << ".up" | ||
149 | << endl; | ||
129 | S << " address " << Data.IPAddress << endl; | 150 | S << " address " << Data.IPAddress << endl; |
130 | S << " broadcast " << Data.Broadcast << endl; | 151 | S << " broadcast " << Data.Broadcast << endl; |
131 | S << " netmask " << Data.NetMask << endl; | 152 | S << " netmask " << Data.NetMask << endl; |
132 | 153 | ||
133 | // derive network address = IPAddress & netmask | 154 | // derive network address = IPAddress & netmask |
134 | { QString NW; | 155 | { QString NW; |
135 | QStringList ipal = QStringList::split( '.', Data.IPAddress ); | 156 | QStringList ipal = QStringList::split( '.', Data.IPAddress ); |
136 | QStringList nmal = QStringList::split( '.', Data.NetMask ); | 157 | QStringList nmal = QStringList::split( '.', Data.NetMask ); |
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index ddb9a5f..c19235a 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp | |||
@@ -25,26 +25,26 @@ bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { | |||
25 | 25 | ||
26 | if( A == Up ) { | 26 | if( A == Up ) { |
27 | // we can bring UP if lower level is available | 27 | // we can bring UP if lower level is available |
28 | if( NC->currentState() == Available ) { | 28 | if( NC->currentState() == Available ) { |
29 | QString S; | 29 | QString S; |
30 | S.sprintf( "ifup %s=%s-c%d-allowed", | 30 | S.sprintf( "ifup %s=%s-c%d-allowed", |
31 | II->Name.latin1(), II->Name.latin1(), | 31 | II->Name.latin1(), II->Name.latin1(), |
32 | connection()->number() ); | 32 | connection()->number() ); |
33 | NSResources->system().execute( S ); | 33 | NSResources->system().runAsRoot( S ); |
34 | } | 34 | } |
35 | return 1; | 35 | return 1; |
36 | } else if( A == Down ) { | 36 | } else if( A == Down ) { |
37 | if( NC->currentState() == IsUp ) { | 37 | if( NC->currentState() == IsUp ) { |
38 | QString S; | 38 | QString S; |
39 | S.sprintf( "ifdown %s=%s-c%d-allowed", | 39 | S.sprintf( "ifdown %s=%s-c%d-allowed", |
40 | II->Name.latin1(), II->Name.latin1(), | 40 | II->Name.latin1(), II->Name.latin1(), |
41 | connection()->number() ); | 41 | connection()->number() ); |
42 | NSResources->system().execute( S ); | 42 | NSResources->system().runAsRoot( S ); |
43 | } | 43 | } |
44 | return 1; | 44 | return 1; |
45 | } | 45 | } |
46 | // delegate | 46 | // delegate |
47 | return RI->setState( NC, A ); | 47 | return RI->setState( NC, A ); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool NetworkRun::canSetState( State_t Curr, Action_t A ) { | 50 | bool NetworkRun::canSetState( State_t Curr, Action_t A ) { |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 0301361..e6ce2b7 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -1,12 +1,16 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <errno.h> | ||
3 | #include <fcntl.h> | ||
4 | #include <pwd.h> | ||
1 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qdir.h> | ||
2 | #include <qpe/qlibrary.h> | 7 | #include <qpe/qlibrary.h> |
3 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
4 | #include <qdir.h> | ||
5 | #include <opie2/odebug.h> | 9 | #include <opie2/odebug.h> |
6 | #include <qtopia/resource.h> | 10 | #include <qtopia/resource.h> |
7 | 11 | ||
8 | #include "netnode.h" | 12 | #include "netnode.h" |
9 | #include "resources.h" | 13 | #include "resources.h" |
10 | 14 | ||
11 | #define PLUGINDIR "plugins/networksettings2" | 15 | #define PLUGINDIR "plugins/networksettings2" |
12 | #define ICONDIR "/pics/networksettings2/" | 16 | #define ICONDIR "/pics/networksettings2/" |
@@ -70,16 +74,18 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | |||
70 | NodeTypeDescriptionMap.insert( "fullsetup", | 74 | NodeTypeDescriptionMap.insert( "fullsetup", |
71 | tr( "<p>Fully configured connection profile</p>" ) ); | 75 | tr( "<p>Fully configured connection profile</p>" ) ); |
72 | 76 | ||
73 | // define system files | 77 | // define system files |
74 | addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); | 78 | addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); |
75 | 79 | ||
76 | // get access to the system | 80 | // get access to the system |
77 | TheSystem = new System(); | 81 | TheSystem = new System(); |
82 | |||
83 | detectCurrentUser(); | ||
78 | } | 84 | } |
79 | 85 | ||
80 | TheNSResources::~TheNSResources( void ) { | 86 | TheNSResources::~TheNSResources( void ) { |
81 | delete TheSystem; | 87 | delete TheSystem; |
82 | } | 88 | } |
83 | 89 | ||
84 | /** | 90 | /** |
85 | * Load all modules that are found in the path | 91 | * Load all modules that are found in the path |
@@ -227,8 +233,137 @@ void TheNSResources::renumberConnections( void ) { | |||
227 | for( QDictIterator<NodeCollection> it(M); | 233 | for( QDictIterator<NodeCollection> it(M); |
228 | it.current(); | 234 | it.current(); |
229 | ++it ) { | 235 | ++it ) { |
230 | NC = it.current(); | 236 | NC = it.current(); |
231 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 237 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
232 | NC->setModified( 1 ); | 238 | NC->setModified( 1 ); |
233 | } | 239 | } |
234 | } | 240 | } |
241 | |||
242 | typedef struct EnvVars { | ||
243 | char * Name; | ||
244 | int Len; | ||
245 | } EnvVar_t; | ||
246 | |||
247 | #define AnEV(x) x, sizeof(x)-1 | ||
248 | |||
249 | static EnvVar_t EV[] = { | ||
250 | // AnEV( "HOME=" ), -> SPECIAL | ||
251 | // AnEV( "LOGNAME=" ), -> SPECIAL | ||
252 | AnEV( "USER=" ), | ||
253 | AnEV( "LD_LIBRARY_PATH=" ), | ||
254 | AnEV( "PATH=" ), | ||
255 | AnEV( "QTDIR=" ), | ||
256 | AnEV( "OPIEDIR=" ), | ||
257 | AnEV( "SHELL=" ), | ||
258 | { NULL, 0 } | ||
259 | }; | ||
260 | |||
261 | void TheNSResources::detectCurrentUser( void ) { | ||
262 | // find current running qpe | ||
263 | QString QPEEnvFile = ""; | ||
264 | |||
265 | // open proc dir and find all dirs in it | ||
266 | { QRegExp R("[0-9]+"); | ||
267 | QDir ProcDir( "/proc" ); | ||
268 | QString QPELoc = QPEApplication::qpeDir() + "bin/qpe"; | ||
269 | QFileInfo FI; | ||
270 | QStringList EL = ProcDir.entryList( QDir::Dirs ); | ||
271 | |||
272 | // print it out | ||
273 | for ( QStringList::Iterator it = EL.begin(); | ||
274 | it != EL.end(); | ||
275 | ++it ) { | ||
276 | if( R.match( (*it) ) >= 0 ) { | ||
277 | QString S = ProcDir.path()+"/"+ (*it); | ||
278 | S.append( "/exe" ); | ||
279 | FI.setFile( S ); | ||
280 | // get the linke | ||
281 | S = FI.readLink(); | ||
282 | if( S == QPELoc ) { | ||
283 | // found running qpe | ||
284 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); | ||
285 | break; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | if( QPEEnvFile.isEmpty() ) { | ||
292 | // could not find qpe | ||
293 | fprintf( stderr, "Could not find qpe\n" ); | ||
294 | return; | ||
295 | } | ||
296 | |||
297 | // FI now contains path ProcDir to the cmd dir | ||
298 | { char * Buf = 0; | ||
299 | char TB[1024]; | ||
300 | long BufSize = 0; | ||
301 | int fd; | ||
302 | int rd; | ||
303 | |||
304 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); | ||
305 | if( fd < 0 ) { | ||
306 | fprintf( stderr, "Could not open %s : %d\n", | ||
307 | QPEEnvFile.latin1(), errno ); | ||
308 | return; | ||
309 | } | ||
310 | |||
311 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { | ||
312 | Buf = (char *)realloc( Buf, BufSize+rd ); | ||
313 | memcpy( Buf+BufSize, TB, rd ); | ||
314 | BufSize += rd; | ||
315 | } | ||
316 | |||
317 | char * Data = Buf; | ||
318 | char * DataEnd = Data+BufSize-1; | ||
319 | |||
320 | // get env items out of list | ||
321 | while( Data < DataEnd ) { | ||
322 | if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { | ||
323 | CurrentUser.UserName = Data+8; | ||
324 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | ||
325 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | ||
326 | strdup( Data ); | ||
327 | } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { | ||
328 | CurrentUser.HomeDir = Data+5; | ||
329 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | ||
330 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | ||
331 | strdup( Data ); | ||
332 | } else { | ||
333 | EnvVar_t * Run = EV; | ||
334 | while( Run->Name ) { | ||
335 | if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { | ||
336 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | ||
337 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | ||
338 | strdup( Data ); | ||
339 | break; | ||
340 | } | ||
341 | Run ++; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | Data += strlen( Data )+1; | ||
346 | } | ||
347 | |||
348 | free( Buf ); | ||
349 | |||
350 | if( ! CurrentUser.UserName.isEmpty() ) { | ||
351 | // find user info | ||
352 | struct passwd pwd; | ||
353 | struct passwd * pwdres; | ||
354 | |||
355 | if( getpwnam_r( CurrentUser.UserName.latin1(), | ||
356 | &pwd, TB, sizeof(TB), &pwdres ) || | ||
357 | pwdres == 0 ) { | ||
358 | fprintf( stderr, "Could not determine user %s : %d\n", | ||
359 | CurrentUser.UserName.latin1(), errno ); | ||
360 | return; | ||
361 | } | ||
362 | CurrentUser.Uid = pwd.pw_uid; | ||
363 | CurrentUser.Gid = pwd.pw_gid; | ||
364 | } else{ | ||
365 | CurrentUser.Uid = | ||
366 | CurrentUser.Gid = -1; | ||
367 | } | ||
368 | } | ||
369 | } | ||
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 4df3ce3..3048fb3 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h | |||
@@ -17,16 +17,28 @@ class ANetNodeInstance; | |||
17 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); | 17 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); |
18 | 18 | ||
19 | typedef struct NetNode_S { | 19 | typedef struct NetNode_S { |
20 | ANetNode * NetNode; | 20 | ANetNode * NetNode; |
21 | QLibrary * TheLibrary; | 21 | QLibrary * TheLibrary; |
22 | long NodeCountInLib; | 22 | long NodeCountInLib; |
23 | } NetNode_t; | 23 | } NetNode_t; |
24 | 24 | ||
25 | class CurrentQPEUser { | ||
26 | |||
27 | public : | ||
28 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} | ||
29 | |||
30 | QString UserName; | ||
31 | QString HomeDir; | ||
32 | int Uid; | ||
33 | int Gid; | ||
34 | QArray<char *> EnvList; | ||
35 | }; | ||
36 | |||
25 | typedef QDict<NetNode_t> Name2NetNode_t; | 37 | typedef QDict<NetNode_t> Name2NetNode_t; |
26 | typedef QDict<ANetNodeInstance > Name2Instance_t; | 38 | typedef QDict<ANetNodeInstance > Name2Instance_t; |
27 | typedef QDict<NodeCollection> Name2Connection_t; | 39 | typedef QDict<NodeCollection> Name2Connection_t; |
28 | typedef QDict<SystemFile> Name2SystemFile_t; | 40 | typedef QDict<SystemFile> Name2SystemFile_t; |
29 | 41 | ||
30 | class TheNSResources { | 42 | class TheNSResources { |
31 | 43 | ||
32 | public : | 44 | public : |
@@ -78,18 +90,22 @@ public : | |||
78 | 90 | ||
79 | void renumberConnections( void ); | 91 | void renumberConnections( void ); |
80 | void addConnection( NodeCollection * NC ); | 92 | void addConnection( NodeCollection * NC ); |
81 | void removeConnection( const QString & N ); | 93 | void removeConnection( const QString & N ); |
82 | NodeCollection * findConnection( const QString & N ); | 94 | NodeCollection * findConnection( const QString & N ); |
83 | Name2Connection_t & connections( void ) | 95 | Name2Connection_t & connections( void ) |
84 | { return ConnectionsMap; } | 96 | { return ConnectionsMap; } |
85 | 97 | ||
98 | CurrentQPEUser & currentUser( void ) | ||
99 | { return CurrentUser; } | ||
100 | |||
86 | private : | 101 | private : |
87 | 102 | ||
103 | void detectCurrentUser( void ); | ||
88 | QString tr( const char * path ); | 104 | QString tr( const char * path ); |
89 | void findAvailableNetNodes( const QString &path ); | 105 | void findAvailableNetNodes( const QString &path ); |
90 | bool loadNetNode( | 106 | bool loadNetNode( |
91 | const QString &pluginFileName, | 107 | const QString &pluginFileName, |
92 | const QString &resolveString = "create_plugin"); | 108 | const QString &resolveString = "create_plugin"); |
93 | 109 | ||
94 | QMap< QString, QString> NodeTypeNameMap; | 110 | QMap< QString, QString> NodeTypeNameMap; |
95 | QMap< QString, QString> NodeTypeDescriptionMap; | 111 | QMap< QString, QString> NodeTypeDescriptionMap; |
@@ -97,14 +113,16 @@ private : | |||
97 | System * TheSystem; | 113 | System * TheSystem; |
98 | Name2SystemFile_t SystemFiles; | 114 | Name2SystemFile_t SystemFiles; |
99 | 115 | ||
100 | // all node type classes | 116 | // all node type classes |
101 | Name2NetNode_t AllNodeTypes; | 117 | Name2NetNode_t AllNodeTypes; |
102 | 118 | ||
103 | // all nodes | 119 | // all nodes |
104 | Name2Instance_t AllNodes; | 120 | Name2Instance_t AllNodes; |
121 | |||
122 | CurrentQPEUser CurrentUser; | ||
105 | }; | 123 | }; |
106 | 124 | ||
107 | extern TheNSResources * _NSResources; | 125 | extern TheNSResources * _NSResources; |
108 | #define NSResources _NSResources | 126 | #define NSResources _NSResources |
109 | 127 | ||
110 | #endif | 128 | #endif |
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index a68f3c0..2133d34 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp | |||
@@ -1,19 +1,27 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <sys/types.h> | 1 | #include <sys/types.h> |
3 | #include <sys/wait.h> | 2 | #include <sys/wait.h> |
4 | #include <qfile.h> | 3 | |
5 | #include <qtextstream.h> | ||
6 | #include <net/if.h> | 4 | #include <net/if.h> |
7 | #include <net/if_arp.h> | 5 | #include <net/if_arp.h> |
8 | #include <netinet/in.h> | 6 | #include <netinet/in.h> |
9 | #include <arpa/inet.h> | 7 | #include <arpa/inet.h> |
10 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
11 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
10 | #include <stdlib.h> | ||
11 | #include <fcntl.h> | ||
12 | #include <errno.h> | ||
13 | #include <unistd.h> | ||
14 | |||
15 | #include <qdir.h> | ||
16 | #include <qregexp.h> | ||
17 | #include <qstringlist.h> | ||
18 | #include <qfile.h> | ||
19 | #include <qtextstream.h> | ||
12 | 20 | ||
13 | #include "resources.h" | 21 | #include "resources.h" |
14 | #include "system.h" | 22 | #include "system.h" |
15 | 23 | ||
16 | #define PROCNETDEV "/proc/net/dev" | 24 | #define PROCNETDEV "/proc/net/dev" |
17 | 25 | ||
18 | static char Dig2Hex[] = { | 26 | static char Dig2Hex[] = { |
19 | '0', '1', '2', '3', | 27 | '0', '1', '2', '3', |
@@ -31,17 +39,17 @@ System::System( void ) : ProbedInterfaces() { | |||
31 | probeInterfaces(); | 39 | probeInterfaces(); |
32 | } | 40 | } |
33 | 41 | ||
34 | System::~System( void ) { | 42 | System::~System( void ) { |
35 | if( ProcDevNet ) | 43 | if( ProcDevNet ) |
36 | delete ProcDevNet; | 44 | delete ProcDevNet; |
37 | } | 45 | } |
38 | 46 | ||
39 | int System::execute( const QString & S ) { | 47 | int System::runAsRoot( const QString & S ) { |
40 | QString MyS = S; | 48 | QString MyS = S; |
41 | char * usr = getenv("USER"); | 49 | char * usr = getenv("USER"); |
42 | int rv; | 50 | int rv; |
43 | 51 | ||
44 | if( S.isEmpty() ) { | 52 | if( S.isEmpty() ) { |
45 | // loophole to start shell | 53 | // loophole to start shell |
46 | return 8888; | 54 | return 8888; |
47 | } | 55 | } |
@@ -313,8 +321,35 @@ void System::probeInterfaces( void ) { | |||
313 | IFI->Netmask = | 321 | IFI->Netmask = |
314 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); | 322 | inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); |
315 | } else { | 323 | } else { |
316 | IFI->Netmask = ""; | 324 | IFI->Netmask = ""; |
317 | } | 325 | } |
318 | fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ); | 326 | fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ); |
319 | } | 327 | } |
320 | } | 328 | } |
329 | |||
330 | void System::execAsUser( QString & Cmd, char * argv[] ) { | ||
331 | CurrentQPEUser CU = NSResources->currentUser(); | ||
332 | |||
333 | if( CU.UserName.isEmpty() ) { | ||
334 | // if we come here, the exec was not successfull | ||
335 | fprintf( stderr, "User not known \n" ); | ||
336 | return; | ||
337 | } | ||
338 | |||
339 | // now we are ready to exec the requested command | ||
340 | setuid( CU.Uid ); | ||
341 | setgid( CU.Gid ); | ||
342 | |||
343 | char ** envp = (char **)alloca( sizeof( char *) * | ||
344 | (CU.EnvList.count()+1) ); | ||
345 | |||
346 | for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { | ||
347 | *(envp+i) = CU.EnvList[i]; | ||
348 | } | ||
349 | envp[CU.EnvList.count()]=NULL; | ||
350 | |||
351 | execve( Cmd.latin1(), argv, envp ); | ||
352 | |||
353 | // if we come here, the exec was not successfull | ||
354 | fprintf( stderr, "Could not exec : %d\n", errno ); | ||
355 | } | ||
diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index f89fe5d..96ee9bd 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h | |||
@@ -54,17 +54,22 @@ public : | |||
54 | System( void ); | 54 | System( void ); |
55 | ~System( void ); | 55 | ~System( void ); |
56 | 56 | ||
57 | QDict<InterfaceInfo> & interfaces( void ) | 57 | QDict<InterfaceInfo> & interfaces( void ) |
58 | { return ProbedInterfaces; } | 58 | { return ProbedInterfaces; } |
59 | InterfaceInfo * interface( const QString& N ) | 59 | InterfaceInfo * interface( const QString& N ) |
60 | { return ProbedInterfaces[N]; } | 60 | { return ProbedInterfaces[N]; } |
61 | 61 | ||
62 | int execute( const QString & S ); | 62 | // exec command as root |
63 | int runAsRoot( const QString & S ); | ||
64 | |||
65 | // exec command as user | ||
66 | void execAsUser( QString & Cmd, char * argv[] ); | ||
67 | |||
63 | // refresh stats for this interface | 68 | // refresh stats for this interface |
64 | void refreshStatistics( InterfaceInfo & ); | 69 | void refreshStatistics( InterfaceInfo & ); |
65 | 70 | ||
66 | // reloads interfaces | 71 | // reloads interfaces |
67 | void probeInterfaces( void ); | 72 | void probeInterfaces( void ); |
68 | 73 | ||
69 | private : | 74 | private : |
70 | 75 | ||
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index eb63e02..b4d9aaa 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -10,17 +10,19 @@ | |||
10 | #include <resources.h> | 10 | #include <resources.h> |
11 | 11 | ||
12 | static QString CfgFile; | 12 | static QString CfgFile; |
13 | 13 | ||
14 | NetworkSettingsData::NetworkSettingsData( void ) { | 14 | NetworkSettingsData::NetworkSettingsData( void ) { |
15 | // init global resources structure | 15 | // init global resources structure |
16 | new TheNSResources(); | 16 | new TheNSResources(); |
17 | 17 | ||
18 | CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") ); | 18 | CfgFile.sprintf( "%s/NETCONFIG", |
19 | NSResources->currentUser().HomeDir.latin1() ); | ||
20 | fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() ); | ||
19 | 21 | ||
20 | // load settings | 22 | // load settings |
21 | Force = 0; | 23 | Force = 0; |
22 | IsModified = 0; | 24 | IsModified = 0; |
23 | loadSettings(); | 25 | loadSettings(); |
24 | } | 26 | } |
25 | 27 | ||
26 | // saving is done by caller | 28 | // saving is done by caller |
@@ -348,51 +350,52 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa | |||
348 | Name2Connection_t & M = NSResources->connections(); | 350 | Name2Connection_t & M = NSResources->connections(); |
349 | 351 | ||
350 | // for all connections | 352 | // for all connections |
351 | for( QDictIterator<NodeCollection> it(M); | 353 | for( QDictIterator<NodeCollection> it(M); |
352 | it.current(); | 354 | it.current(); |
353 | ++it ) { | 355 | ++it ) { |
354 | NC = it.current(); | 356 | NC = it.current(); |
355 | // check if this profile handles the requested interface | 357 | // check if this profile handles the requested interface |
358 | fprintf( stderr, "check %s\n", NC->name().latin1() ); | ||
356 | if( NC->handlesInterface( Interface ) && // if different Intf. | 359 | if( NC->handlesInterface( Interface ) && // if different Intf. |
357 | NC->state() != Disabled && // if not enabled | 360 | NC->state() != Disabled && // if not enabled |
358 | NC->state() != IsUp // if already used | 361 | NC->state() != IsUp // if already used |
359 | ) { | 362 | ) { |
363 | fprintf( stderr, "Append %s\n", NC->name().latin1() ); | ||
360 | PossibleConnections.append( NC ); | 364 | PossibleConnections.append( NC ); |
361 | } | 365 | } |
362 | } | 366 | } |
363 | return PossibleConnections; | 367 | return PossibleConnections; |
364 | } | 368 | } |
365 | 369 | ||
366 | 370 | ||
367 | /* | 371 | /* |
368 | Called by the system to see if interface can be brought UP | 372 | Called by the system to see if interface can be brought UP |
369 | 373 | ||
370 | if allowed, echo Interface-allowed else Interface-disallowed | 374 | if allowed, echo Interface-allowed else Interface-disallowed |
371 | */ | 375 | */ |
372 | 376 | ||
373 | void NetworkSettingsData::canStart( const char * Interface ) { | 377 | bool NetworkSettingsData::canStart( const char * Interface ) { |
374 | // load situation | 378 | // load situation |
375 | NodeCollection * NC = 0; | 379 | NodeCollection * NC = 0; |
376 | QList<NodeCollection> PossibleConnections; | 380 | QList<NodeCollection> PossibleConnections; |
377 | 381 | ||
378 | PossibleConnections = collectPossible( Interface ); | 382 | PossibleConnections = collectPossible( Interface ); |
379 | 383 | ||
384 | fprintf( stderr, "Possiblilies %d\n", | ||
385 | PossibleConnections.count() ); | ||
380 | switch( PossibleConnections.count() ) { | 386 | switch( PossibleConnections.count() ) { |
381 | case 0 : // no connections | 387 | case 0 : // no connections |
382 | break; | 388 | break; |
383 | case 1 : // one connection | 389 | case 1 : // one connection |
384 | NC = PossibleConnections.first(); | 390 | NC = PossibleConnections.first(); |
385 | break; | 391 | break; |
386 | default : // need to ask user ? | 392 | default : // need to ask user ? |
387 | // are we connected to a server | 393 | return 1; |
388 | // system( "su %d networksettings2 --prompt %s\n", | ||
389 | // "", Interface ); | ||
390 | break; | ||
391 | } | 394 | } |
392 | 395 | ||
393 | if( NC ) { | 396 | if( NC ) { |
394 | switch( NC->state() ) { | 397 | switch( NC->state() ) { |
395 | case Unchecked : | 398 | case Unchecked : |
396 | case Unknown : | 399 | case Unknown : |
397 | case Unavailable : | 400 | case Unavailable : |
398 | case Disabled : | 401 | case Disabled : |
@@ -405,22 +408,23 @@ void NetworkSettingsData::canStart( const char * Interface ) { | |||
405 | // cannot bring device Online -> try other alters | 408 | // cannot bring device Online -> try other alters |
406 | break; | 409 | break; |
407 | } | 410 | } |
408 | // FT | 411 | // FT |
409 | case Available : | 412 | case Available : |
410 | case IsUp : // also called for 'ifdown' | 413 | case IsUp : // also called for 'ifdown' |
411 | // device is ready -> done | 414 | // device is ready -> done |
412 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | 415 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); |
413 | return; | 416 | return 0; |
414 | } | 417 | } |
415 | } else { | 418 | } |
416 | // if we come here no alternatives are possible | 419 | |
417 | printf( "%s-cnn-disallowed\n", Interface ); | 420 | // if we come here no alternatives are possible |
418 | } | 421 | printf( "%s-cnn-disallowed\n", Interface ); |
422 | return 0; | ||
419 | } | 423 | } |
420 | 424 | ||
421 | /* | 425 | /* |
422 | Called by the system to regenerate config files | 426 | Called by the system to regenerate config files |
423 | */ | 427 | */ |
424 | 428 | ||
425 | bool NetworkSettingsData::regenerate( void ) { | 429 | bool NetworkSettingsData::regenerate( void ) { |
426 | QString S; | 430 | QString S; |
diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index b54df24..eb96930 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h | |||
@@ -16,17 +16,18 @@ public : | |||
16 | QString generateSettings( bool Force = FALSE ); | 16 | QString generateSettings( bool Force = FALSE ); |
17 | 17 | ||
18 | bool isModified( void ) | 18 | bool isModified( void ) |
19 | { return IsModified; } | 19 | { return IsModified; } |
20 | void setModified( bool m ) | 20 | void setModified( bool m ) |
21 | { IsModified = m; } | 21 | { IsModified = m; } |
22 | 22 | ||
23 | QList<NodeCollection> collectPossible( const char * Interface ); | 23 | QList<NodeCollection> collectPossible( const char * Interface ); |
24 | void canStart( const char * Interface ); | 24 | // return TRUE if we need gui to decide |
25 | bool canStart( const char * Interface ); | ||
25 | bool regenerate( void ); | 26 | bool regenerate( void ); |
26 | 27 | ||
27 | void forceGeneration( bool m ) | 28 | void forceGeneration( bool m ) |
28 | { Force = m; } | 29 | { Force = m; } |
29 | 30 | ||
30 | private : | 31 | private : |
31 | 32 | ||
32 | QString NetworkSettingsData::generateSystemFileNode( | 33 | QString NetworkSettingsData::generateSystemFileNode( |