From d5df2032280242a44c44e3e6e875361756587cd6 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Thu, 10 Apr 2003 22:23:47 +0000 Subject: add sanity (non-root & dhcp running) checks for startup phase --- (limited to 'noncore/net/wellenreiter/gui/main.cpp') diff --git a/noncore/net/wellenreiter/gui/main.cpp b/noncore/net/wellenreiter/gui/main.cpp index 8d4ef57..03da135 100644 --- a/noncore/net/wellenreiter/gui/main.cpp +++ b/noncore/net/wellenreiter/gui/main.cpp @@ -20,6 +20,20 @@ #include #endif +#include +#include + +// ==> OProcess +#include +#include +#include +#include + +#include +#include +#include +#include + int main( int argc, char **argv ) { #ifdef QWS @@ -34,6 +48,51 @@ int main( int argc, char **argv ) a.setMainWidget( w ); w->show(); #endif + + a.processEvents(); // show the window before doing the safety checks + int result = -1; + + // root check + if ( getuid() ) + { + qWarning( "Wellenreiter: trying to run as non-root!" ); + result = QMessageBox::warning( w, " - Wellenreiter II - (non-root)", "You have started Wellenreiter II\n" + "as non-root. You will have\nonly limited functionality.\nProceed anyway?", + QMessageBox::Yes, QMessageBox::No ); + if ( result == QMessageBox::No ) return -1; + } + + // dhcp check - NOT HERE! This really belongs as a static member to OProcess + // and I want to call it like that: if ( OProcess::isRunning( QString& ) ) ... + + QString line; + QDir d = QDir( "/proc" ); + QStringList dirs = d.entryList( QDir::Dirs ); + QStringList::Iterator it; + for ( it = dirs.begin(); it != dirs.end(); ++it ) + { + //qDebug( "next entry: %s", (const char*) *it ); + QFile file( "/proc/"+*it+"/cmdline" ); + file.open( IO_ReadOnly ); + if ( !file.isOpen() ) continue; + QTextStream t( &file ); + line = t.readLine(); + //qDebug( "cmdline = %s", (const char*) line ); + if ( line.contains( "dhcp" ) ) break; + } + if ( line.contains( "dhcp" ) ) + { + qWarning( "Wellenreiter: found dhcp process #%d", (*it).toInt() ); + result = QMessageBox::warning( w, " - Wellenreiter II - (dhcp)", "You have a dhcp client running.\n" + "This can severly limit scanning!\nShould I kill it for you?", + QMessageBox::Yes, QMessageBox::No ); + if ( result == QMessageBox::Yes ) + { + if ( -1 == ::kill( (*it).toInt(), SIGTERM ) ) + qWarning( "Wellenreiter: can't kill process (%s)", result, strerror( errno ) ); + } + } + a.exec(); delete w; return 0; -- cgit v0.9.0.2