summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/system.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/system.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp43
1 files changed, 39 insertions, 4 deletions
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,7 +1,5 @@
-#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <qfile.h>
-#include <qtextstream.h>
+
#include <net/if.h>
#include <net/if_arp.h>
@@ -10,4 +8,14 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <qdir.h>
+#include <qregexp.h>
+#include <qstringlist.h>
+#include <qfile.h>
+#include <qtextstream.h>
#include "resources.h"
@@ -37,5 +45,5 @@ System::~System( void ) {
}
-int System::execute( const QString & S ) {
+int System::runAsRoot( const QString & S ) {
QString MyS = S;
char * usr = getenv("USER");
@@ -319,2 +327,29 @@ void System::probeInterfaces( void ) {
}
}
+
+void System::execAsUser( QString & Cmd, char * argv[] ) {
+ CurrentQPEUser CU = NSResources->currentUser();
+
+ if( CU.UserName.isEmpty() ) {
+ // if we come here, the exec was not successfull
+ fprintf( stderr, "User not known \n" );
+ return;
+ }
+
+ // now we are ready to exec the requested command
+ setuid( CU.Uid );
+ setgid( CU.Gid );
+
+ char ** envp = (char **)alloca( sizeof( char *) *
+ (CU.EnvList.count()+1) );
+
+ for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
+ *(envp+i) = CU.EnvList[i];
+ }
+ envp[CU.EnvList.count()]=NULL;
+
+ execve( Cmd.latin1(), argv, envp );
+
+ // if we come here, the exec was not successfull
+ fprintf( stderr, "Could not exec : %d\n", errno );
+}