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,12 +1,14 @@ | |||
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() ) { |
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 | |||
@@ -16,9 +16,9 @@ | |||
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> |
@@ -56,9 +56,9 @@ | |||
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> |
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,7 +1,8 @@ | |||
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 | ||
@@ -75,9 +76,21 @@ int main( int argc, char * argv[] ) { | |||
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; |
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 | |||
@@ -108,25 +108,46 @@ bool ANetwork::generateDataForCommonFile( SystemFile & S, long 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 | ||
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 | |||
@@ -29,18 +29,18 @@ bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { | |||
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 |
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,8 +1,12 @@ | |||
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" |
@@ -74,8 +78,10 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | |||
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; |
@@ -231,4 +237,133 @@ void TheNSResources::renumberConnections( void ) { | |||
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 | |||
@@ -21,8 +21,20 @@ typedef struct NetNode_S { | |||
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; |
@@ -82,10 +94,14 @@ public : | |||
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, |
@@ -101,8 +117,10 @@ private : | |||
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 |
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,15 +1,23 @@ | |||
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 | ||
@@ -35,9 +43,9 @@ 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 | ||
@@ -317,4 +325,31 @@ void System::probeInterfaces( void ) { | |||
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 | |||
@@ -58,9 +58,14 @@ public : | |||
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 |
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 | |||
@@ -14,9 +14,11 @@ static QString CfgFile; | |||
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; |
@@ -352,12 +354,14 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa | |||
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; |
@@ -369,26 +373,25 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa | |||
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() ) { |
@@ -409,14 +412,15 @@ void NetworkSettingsData::canStart( const char * Interface ) { | |||
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 |
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 | |||
@@ -20,9 +20,10 @@ public : | |||
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; } |