5 files changed, 77 insertions, 58 deletions
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 200e31b..9004d19 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -74,64 +74,68 @@ int main( int argc, char * argv[] ) { // TheApp anymore ... TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); } else { TheApp = new QPEApplication( argc, argv, GuiType ); } #else TheApp = new QApplication( argc, argv, GuiType ); #endif // init qt with app widget switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; if( NS.canStart( argv[1] ) ) { QString S; S.sprintf( QPEApplication::qpeDir()+ "/bin/networksettings2" ); char * MyArgv[4]; MyArgv[0] = "networksettings2"; MyArgv[1] = "--prompt"; MyArgv[2] = argv[1]; MyArgv[3] = NULL; NSResources->system().execAsUser( S, MyArgv ); + Log(("FAILED %s-cNN-allowed\n", argv[1] )); // if we come here , failed printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_REGEN : { NetworkSettingsData NS; // regen returns 0 if OK rv = (NS.regenerate()) ? 1 : 0; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); if( AP.exec() == QDialog::Accepted ) { + Log(("%s-c%ld-allowed\n", + argv[1], AP.selectedProfile() )); printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); } else { + Log(("%s-c%NN-disallowed\n", argv[1] )); printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_VPN : { ActivateVPN AVPN; AVPN.exec(); } break; case ACT_GUI : { QWidget * W = new NetworkSettings(0); TheApp->setMainWidget( W ); W->show(); #ifdef _WS_QWS_ W->showMaximized(); #else W->resize( W->sizeHint() ); #endif rv = TheApp->exec(); delete W; } break; } diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index 1feffdb..b5c41bf 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,24 +1,25 @@ +#include <qpe/qpeapplication.h> #include <asdevice.h> #include "network_NN.h" #include "network_NNI.h" static const char * NetworkNeeds[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { } /** * Delete any interfaces that we own. */ NetworkNetNode::~NetworkNetNode(){ } const QString NetworkNetNode::nodeDescription(){ return tr("\ <p>Sets up TCP/IP options.</p>\ @@ -32,49 +33,51 @@ ANetNodeInstance * NetworkNetNode::createInstance( void ) { } bool NetworkNetNode::hasDataForFile( const QString & S ) { return S == "interfaces"; } short NetworkNetNode::generateFile( const QString & ID, const QString & , QTextStream & TS, ANetNodeInstance * NNI, long DevNr ) { QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); if( ID == "interfaces" ) { Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); // generate mapping stanza for this interface TS << "# check if " << NIC << " can be brought UP" << endl; TS << "mapping " << NIC << endl; - TS << " script networksettings2-request" + TS << " script " + << QPEApplication::qpeDir() + << "/bin/networksettings2-request" << endl << endl; return 0; } return 1; } const char ** NetworkNetNode::needs( void ) { return NetworkNeeds; } const char * NetworkNetNode::provides( void ) { return "connection"; } void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { } void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new NetworkNetNode() ); diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 7ece817..2f17693 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -273,63 +273,66 @@ NodeCollection * TheNSResources::findConnection( const QString & S ) { void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } */ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { - // AnEV( "HOME=" ), -> SPECIAL - // AnEV( "LOGNAME=" ), -> SPECIAL - AnEV( "USER=" ), - AnEV( "LD_LIBRARY_PATH=" ), - AnEV( "PATH=" ), - AnEV( "QTDIR=" ), - AnEV( "OPIEDIR=" ), - AnEV( "SHELL=" ), + AnEV( "HOME" ), + AnEV( "LOGNAME" ), + AnEV( "USER" ), + AnEV( "LD_LIBRARY_PATH" ), + AnEV( "PATH" ), + AnEV( "QTDIR" ), + AnEV( "OPIEDIR" ), + AnEV( "SHELL" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; + CurrentUser.UserName = ""; + CurrentUser.HomeDir = ""; + if( getenv( "OPIEDIR" ) == 0 ) { // nothing known { // open proc dir and find all dirs in it QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); // get the link S = FI.readLink(); if( S.right( 8 ) == "/bin/qpe" ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } @@ -346,108 +349,102 @@ void TheNSResources::detectCurrentUser( void ) { { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { Log(("Could not open %s : %d\n", QPEEnvFile.latin1(), errno )); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); BufSize += rd; } char * Data = Buf; char * DataEnd = Data+BufSize-1; // get env items out of list while( Data < DataEnd ) { - if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { - CurrentUser.UserName = Data+8; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { - CurrentUser.HomeDir = Data+5; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else { - EnvVar_t * Run = EV; - while( Run->Name ) { - if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - // put OPIEDIR in env - if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) { - putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); - } - break; + EnvVar_t * Run = EV; + while( Run->Name ) { + if( strncmp( Data, Run->Name, Run->Len ) == 0 && + Data[Run->Len] == '=' + ) { + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( Data ); + + if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { + // put OPIEDIR in env + putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); + } else if( strcmp( Run->Name, "HOME" ) == 0 ) { + CurrentUser.HomeDir = Data+5; + } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { + CurrentUser.UserName = Data+8; } - Run ++; + break; } + Run ++; } Data += strlen( Data )+1; } free( Buf ); if( ! CurrentUser.UserName.isEmpty() ) { // find user info struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { Log(("Could not determine user %s : %d\n", CurrentUser.UserName.latin1(), errno )); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } } else { - CurrentUser.UserName = getenv( "LOGNAME" ); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( CurrentUser.UserName ); - - CurrentUser.HomeDir = getenv( "HOME" ); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( CurrentUser.HomeDir ); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL"); + char * X; + QString S; + + EnvVar_t * Run = EV; + while( Run->Name ) { + + if( ( X = getenv( Run->Name ) ) ) { + Log(( "Env : %s = %s\n", Run->Name, X )); + + S.sprintf( "%s=%s", Run->Name, X ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( S.latin1() ); + + if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { + CurrentUser.UserName = X; + } else if( strcmp( Run->Name, "HOME" ) == 0 ) { + CurrentUser.HomeDir = X; + } // regulare env var + } else { + Log(("Could not determine %s\n", Run->Name )); + } + Run ++; + } CurrentUser.Uid = getuid(); CurrentUser.Gid = getgid(); } } diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 16355ba..23b120e 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -6,48 +6,51 @@ #include <qmap.h> #include <qlist.h> #include "netnode.h" #include "systemfile.h" #include "system.h" class QLibrary; class QPixmap; class ANetNode; class ANetNodeInstance; typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); typedef struct NetNode_S { ANetNode * NetNode; QLibrary * TheLibrary; long NodeCountInLib; } NetNode_t; class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} + inline bool known( void ) + { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } + QString UserName; QString HomeDir; int Uid; int Gid; QArray<char *> EnvList; }; typedef QDict<NetNode_t> Name2NetNode_t; typedef QDict<ANetNodeInstance > Name2Instance_t; typedef QDict<NodeCollection> Name2Connection_t; typedef QDict<SystemFile> Name2SystemFile_t; class TheNSResources { public : TheNSResources( void ); ~TheNSResources( ); // give busy feedback void busy( bool B ); System & system() { return *TheSystem; } @@ -78,48 +81,50 @@ public : } NNI = NNT->NetNode->createInstance(); NNI->initialize(); return NNI; } Name2Instance_t & netNodeInstances( void ) { return AllNodes; } void addNodeInstance( ANetNodeInstance * I ) { AllNodes.insert( I->name(), I ); } void removeNodeInstance( const QString & N ) { AllNodes.remove( N );} ANetNodeInstance * findNodeInstance( const QString & S ) { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); void addConnection( NodeCollection * NC ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); Name2Connection_t & connections( void ) { return ConnectionsMap; } + inline bool userKnown( void ) + { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); void findAvailableNetNodes( const QString &path ); bool loadNetNode( const QString &pluginFileName, const QString &resolveString = "create_plugin"); QMap< QString, QString> NodeTypeNameMap; QMap< QString, QString> NodeTypeDescriptionMap; Name2Connection_t ConnectionsMap; System * TheSystem; Name2SystemFile_t SystemFiles; // all node type classes Name2NetNode_t AllNodeTypes; // all nodes Name2Instance_t AllNodes; diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index d709c0a..e2dd5b5 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -1,41 +1,48 @@ #include <stdlib.h> #include <qpe/qpeapplication.h> #include <qtextstream.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include "nsdata.h" #include <asdevice.h> #include <resources.h> static QString CfgFile; NetworkSettingsData::NetworkSettingsData( void ) { // init global resources structure new TheNSResources(); + if( ! NSResources->userKnown() ) { + Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", + NSResources->currentUser().HomeDir.latin1(), + NSResources->currentUser().UserName.latin1() )); + return; + } + CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings IsModified = 0; loadSettings(); } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; } void NetworkSettingsData::loadSettings( void ) { QString Line, S; QString Attr, Value; long idx; QFile F( CfgFile ); QTextStream TS( &F ); do { @@ -518,76 +525,79 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa NC->state() != Disabled && // if not enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); PossibleConnections.append( NC ); } } return PossibleConnections; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ bool NetworkSettingsData::canStart( const char * Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); - Log( ( "Possiblilies %d\n", PossibleConnections.count() )); + Log( ( "for %s : Possiblilies %d\n", + Interface, PossibleConnections.count() )); switch( PossibleConnections.count() ) { case 0 : // no connections break; case 1 : // one connection NC = PossibleConnections.first(); break; default : // need to ask user ? return 1; } if( NC ) { switch( NC->state() ) { case Unchecked : case Unknown : case Unavailable : case Disabled : // this profile does not allow interface to be UP // -> try others break; case Off : // try to UP the device if( ! NC->setState( Activate ) ) { // cannot bring device Online -> try other alters break; } // FT case Available : case IsUp : // also called for 'ifdown' // device is ready -> done + Log(( "%s-c%d-allowed\n", Interface, NC->number() )); printf( "%s-c%d-allowed\n", Interface, NC->number() ); return 0; } } // if we come here no alternatives are possible + Log(( "%s-cnn-disallowed\n", Interface )); printf( "%s-cnn-disallowed\n", Interface ); return 0; } /* Called by the system to regenerate config files */ bool NetworkSettingsData::regenerate( void ) { QString S = generateSettings(); if( ! S.isEmpty() ) { fprintf( stdout, "%s\n", S.latin1() ); return 1; } return 0; } |