Exemple #1
0
void ChoiceParameter::parseValues(const QString& typeDefinition)
{
    QStringList values = getValues(typeDefinition);
    if (values.isEmpty())
    {
        dbgPlugins << "Wrong gmic_def" << typeDefinition << " not parsed correctly";
        return;
    }

    // choice(4,"Dots","Wireframe","Flat","Flat shaded","Gouraud","Phong")
    QString firstItem = values.at(0);
    bool isInteger = false;
    m_value = m_defaultValue = firstItem.toInt(&isInteger);
    if (isInteger)
    {
        // throw number out of choices
        values.takeFirst();
    }
    else
    {
        m_value = m_defaultValue = 0;
    }

    m_choices = values;

    for (int i = 0; i < values.size(); i++)
    {
        m_choices[i] = stripQuotes(m_choices[i].trimmed());
    }
}
Exemple #2
0
  int bridgeList(void *magic, char *line)
  {
    EVMod *mod = (EVMod *)magic;
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    // we're looking for the lines that have "name : <bridge-name>"
    // or specifically the sequence:
    // name
    // <whitespace>
    // :
    // <whitespace>
    // <bridge-name>
    // sscanf with format string "name%*[\t ]:%*[\t ]%s" works, but
    // assumes that the whitespace is not empty.  I don't think we
    // can necessarily assume that (?)
    char bridgeName[SFVS_MAX_LINELEN];
    if(sscanf(line, "name%*[\t ]:%*[\t ]%s", bridgeName) == 1) {
      // copy the bridge name
      char *br = stripQuotes(bridgeName, SFVS_QUOTES);
      myDebug(1, "bridgeList> %s", br);
      if(br && (br[0] != '\0')) {
	setStr(&mdata->bridge, br);
	// now run a command to check (and possible change) the bridge sFlow setting
	char *bridge_get_sflow_cmd[] = { SFVS_OVS_CMD, "get", "bridge", br, "sflow", NULL };
	char line[SFVS_MAX_LINELEN];
	if(myExec(mod, bridge_get_sflow_cmd, bridgeGetSFlow, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
      }
    }
    return YES;
  }
DIGESTMD5Properties DIGESTMD5Properties::parse(const ByteArray& data) {
	DIGESTMD5Properties result;
	bool inKey = true;
	ByteArray currentKey;
	ByteArray currentValue;
	for (size_t i = 0; i < data.size(); ++i) {
		char c = static_cast<char>(data[i]);
		if (inKey) {
			if (c == '=') {
				inKey = false;
			}
			else {
				currentKey.push_back(static_cast<unsigned char>(c));
			}
		}
		else {
			if (c == ',' && !insideQuotes(currentValue)) {
				std::string key = byteArrayToString(currentKey);
				if (isQuoted(key)) {
					result.setValue(key, byteArrayToString(stripQuotes(currentValue)));
				}
				else {
					result.setValue(key, byteArrayToString(currentValue));
				}
				inKey = true;
				currentKey = ByteArray();
				currentValue = ByteArray();
			}
			else {
				currentValue.push_back(static_cast<unsigned char>(c));
			}
		}
	}

	if (!currentKey.empty()) {
		std::string key = byteArrayToString(currentKey);
		if (isQuoted(key)) {
			result.setValue(key, byteArrayToString(stripQuotes(currentValue)));
		}
		else {
			result.setValue(key, byteArrayToString(currentValue));
		}
	}

	return result;
}
static int compare( const void * arg1, const void * arg2 )
{
	PSortStruct pLeft ;
	PSortStruct pRight ;
	CString		Left ;
	CString		Right ;
	int32		LeftVal, LeftLen ;
	int32		RightVal, RightLen ;

	pLeft = (PSortStruct)arg1 ;
	pRight = (PSortStruct)arg2 ;

	Left = pLeft->pEnt->GetName ();
	if (Left == "")
	{
		Left = "Unnamed";
	}

	// strip quotes from the entity name
	stripQuotes ( Left );
	
	Right = pRight->pEnt->GetName ();
	if (Right == "")
	{
		Right = "Unnamed";
	}

	// strip quotes from the entity name
	stripQuotes ( Right );

	LeftLen = Left.GetLength() ;
	Util_GetEndStringValue( Left, &LeftVal, &LeftLen ) ;
	RightLen = Right.GetLength() ;
	Util_GetEndStringValue( Right, &RightVal, &RightLen ) ;

	if( Left.Left(LeftLen) == Right.Left(RightLen) )
	{
		return LeftVal - RightVal ;
	}

	return Left.Compare( Right ) ;
}/* ::compare */
Exemple #5
0
 int bridgeGetSFlow(void *magic, char *line)
 {
   EVMod *mod = (EVMod *)magic;
   HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
   char *uuid = stripQuotes(line, SFVS_QUOTES);
   if(uuid && strcmp(uuid, mdata->sflowUUID) != 0) {
     // doesn't match
     myDebug(1, "setting sflow for bridge %s", mdata->bridge);
     addBridgeSetting(mod, "sflow", mdata->sflowUUID);
   }
   return YES;
 }
Exemple #6
0
void PositionData::pushline()
{
    string inBuffer;
    string inData;

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    //int pos = atoi(inData.data());
    intPosition.push_back(atoi(inData.data()));
    position.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    if (inData[0] > 'Z') inData[0] = inData[0] - ('a' -'A');
    refBase.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    intCoverage.push_back(atoi(inData.data()));
    coverage.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    quality.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    if (inData[0] > 'Z') inData[0] = inData[0] - ('a' -'A');
    psnp.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    intPsnpCount.push_back(atoi(inData.data()));
    psnpCount.push_back(inData.data());

    std::getline(*this, inBuffer, '\t');
    inData = stripQuotes(inBuffer);
    psnpFrequ.push_back(inData.data());

    std::getline(*this, inBuffer, '\n');
    inData = stripQuotes(inBuffer);
    pValue.push_back(inData.data());
    //long double ld = stold(inData.c_str());
    ldPValue.push_back(stold(inData.c_str()));

    linesRead++;
}
Exemple #7
0
  int submitCreate(void *magic, char *line)
  {
    EVMod *mod = (EVMod *)magic;
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    char *uuid = stripQuotes(line, SFVS_QUOTES);
    if(!uuid)
      return NO;
    if(my_strlen(uuid) < 32)
      return NO;
    char binUUID[16];
    if(parseUUID(uuid, binUUID) == NO)
      return NO;

    setStr(&mdata->sflowUUID, uuid);
    return YES;
  }
void BlockDataManagerConfig::processArgs(const map<string, string>& args, 
   bool onlyDetectNetwork)
{
   //port
   auto iter = args.find("fcgi-port");
   if (iter != args.end())
   {
      fcgiPort_ = stripQuotes(iter->second);
      int portInt = 0;
      stringstream portSS(fcgiPort_);
      portSS >> portInt;

      if (portInt < 1 || portInt > 65535)
      {
         cout << "Invalid fcgi port, falling back to default" << endl;
         fcgiPort_ = "";
      }
      else
      {
         customFcgiPort_ = true;
      }
   }
Exemple #9
0
bool Sinful::getSourceRoutes( std::vector< SourceRoute > & v, std::string * hostOut, std::string * portOut ) const {
	// The correct way to do this is to faff about with ClassAds, but
	// they make it uneccessarily hard; for now, sscanf() do.

	if( m_v1String[0] != '{' ) { return false; }

	// It is readily possible to represent addresses in what looks like
	// the V1 format that we can't actually store (using the original
	// Sinful data structures).  That contradiction will be resolved in
	// a later revision, which will probably also have a more-general
	// serialization.  For now, if we can't store the addresses, we
	// mark the Sinful to be invalid.

	// This a whole wad of code, but since regenerateV0String() needs to
	// be able to (almost) all of this anyway, we might as well do it
	// here and save the space by not having parallel data structures.
	// (regenerateV0String() doesn't need to handle generating addrs.)

	// Scan forward, looking for [bracketed] source routes.  Since the
	// default constructor produces an empty list, we accept one.
	const char * next = NULL;
	const char * remainder = m_v1String.c_str();

	while( (next = strchr( remainder, '[' )) != NULL ) {
		remainder = next;
		const char * open = remainder;
		remainder = strchr( remainder, ']' );
		if( remainder == NULL ) { return false; }

		// Yes, yes, yes, I know.
		char nameBuffer[64];
		char addressBuffer[64];
		int port = -1;
		char protocolBuffer[16];
		int matches = sscanf( open, "[ p=%16s a=%64s port=%d; n=%64s ",
			protocolBuffer, addressBuffer, & port, nameBuffer );
		if( matches != 4 ) { return false; }

		if( (! stripQuotesAndSemicolon( nameBuffer )) ||
			(! stripQuotesAndSemicolon( addressBuffer )) ||
			(! stripQuotesAndSemicolon( protocolBuffer )) ) {
			return false;
		}

		condor_protocol protocol = str_to_condor_protocol( protocolBuffer );
		if( protocol <= CP_INVALID_MIN || protocol >= CP_INVALID_MAX ) {
			if( protocol != CP_PRIMARY ) {
				return false;
			}
		}
		SourceRoute sr( protocol, addressBuffer, port, nameBuffer );

		// Look for alias, spid, ccbid, ccbspid, noUDP.  Start by scanning
		// past the spaces we know sscanf() matched above.
		const char * parsed = open;
		for( unsigned i = 0; i < 5; ++i ) {
			parsed = strchr( parsed, ' ' );
			assert( parsed != NULL );
			++parsed;
		}

		const char * next = NULL;
		while( (next = strchr( parsed, ' ' )) != NULL && next < remainder ) {
			const char * equals = strchr( parsed, '=' );
			if( equals == NULL ) { return false; }

			std::string attr( parsed, equals - parsed );
			std::string value( equals + 1, (next - 1) - (equals + 1) );

			if( attr == "alias" ) {
				if( ! stripQuotes( value ) ) { return false; }
				sr.setAlias( value );
			} else if( attr == "spid" ) {
				if( ! stripQuotes( value ) ) { return false; }
				sr.setSharedPortID( value );
			} else if( attr == "ccbid" ) {
				if( ! stripQuotes( value ) ) { return false; }
				sr.setCCBID( value );
			} else if( attr == "ccbspid" ) {
				if( ! stripQuotes( value ) ) { return false; }
				sr.setCCBSharedPortID( value );
			} else if( attr == "noUDP" ) {
				// noUDP is defined to be absent if false.
				if( (!value.empty()) && value != "true" ) { return false; }
				sr.setNoUDP( true );
			} else if( attr == "brokerIndex" ) {
				unsigned index;
				if( sscanf( value.c_str(), "%d", & index ) != 1 ) {
					return false;
				}
				sr.setBrokerIndex( index );
			}

			parsed = next;
			++parsed;
		}

		// Make sure the route is properly terminated.
		if( parsed[0] != ']' ) {
			return false;
		}

		// Only set the primary address values for non-broker primaries.
		if( protocol == CP_PRIMARY && sr.getCCBID().empty() ) {
			if( hostOut ) { * hostOut = addressBuffer; }
			if( portOut ) { formatstr( * portOut, "%d", port ); }
		}

		v.push_back( sr );
	}

	// Make sure we looked at least on source route.
	if( remainder == m_v1String.c_str() ) {
		return false;
	}

	// Make sure at least one source route was valid.
	if( v.size() == 0 ) {
		return false;
	}

	// Make sure the list is properly terminated.
	const char * closingBrace = strchr( remainder, '}' );
	if( closingBrace == NULL ) {
		return false;
	}

	return true;
}
void BlockDataManagerConfig::parseArgs(int argc, char* argv[])
{
   /***
   --testnet: run db against testnet bitcoin network

   --regtest: run db against regression test network

   --rescan: delete all processed history data and rescan blockchain from the
   first block

   --rebuild: delete all DB data and build and scan from scratch

   --rescanSSH: delete balance and txcount data and rescan it. Much faster than
   rescan or rebuild.

   --datadir: path to the operation folder

   --dbdir: path to folder containing the database files. If empty, a new db
   will be created there

   --satoshi-datadir: path to blockchain data folder (blkXXXXX.dat files)

   --ram_usage: defines the ram use during scan operations. 1 level averages
   128MB of ram (without accounting the base amount, ~400MB). Defaults at 4.
   Can't be lower than 1. Can be changed in between processes

   --thread-count: defines how many processing threads can be used during db
   builds and scans. Defaults to maximum available CPU threads. Can't be
   lower than 1. Can be changed in between processes

   --zcthread-count: defines the maximum number on threads the zc parser can
   create for processing incoming transcations from the network node

   --db-type: sets the db type:
   DB_BARE: tracks wallet history only. Smallest DB.
   DB_FULL: tracks wallet history and resolves all relevant tx hashes.
   ~750MB DB at the time of 0.95 release. Default DB type.
   DB_SUPER: tracks all blockchain history. XXL DB (100GB+).
   Not implemented yet

   db type cannot be changed in between processes. Once a db has been built
   with a certain type, it will always function according to that type.
   Specifying another type will do nothing. Build a new db to change type.

   --cookie: create a cookie file holding a random authentication key to allow
   local clients to make use of elevated commands, like shutdown.

   --fcgi-port: sets the DB listening port.

   --clear-mempool: delete all zero confirmation transactions from the DB.

   ***/

   try
   {
      //parse cli args
      map<string, string> args;
      for (int i = 1; i < argc; i++)
      {
         //check prefix
         if (strlen(argv[i]) < 2)
            throw DbErrorMsg("invalid CLI arg");

         string prefix(argv[i], 2);
         if (prefix != "--")
            throw DbErrorMsg("invalid CLI arg");

         //string prefix and tokenize
         string line(argv[i] + 2);
         auto&& argkeyval = getKeyValFromLine(line, '=');
         args.insert(make_pair(
            argkeyval.first, stripQuotes(argkeyval.second)));
      }

      processArgs(args, true);

      //figure out datadir
      auto argIter = args.find("datadir");
      if (argIter != args.end())
      {
         dataDir_ = argIter->second;
         args.erase(argIter);
      }
      else
      {
         if (!testnet_ && !regtest_)
            dataDir_ = defaultDataDir_;
         else if (!regtest_)
            dataDir_ = defaultTestnetDataDir_;
         else
            dataDir_ = defaultRegtestDataDir_;
      }

      expandPath(dataDir_);

      //get datadir
      auto configPath = dataDir_;
      appendPath(configPath, "armorydb.conf");

      if (DBUtils::fileExists(configPath, 2))
      {
         ConfigFile cf(configPath);
         auto mapIter = cf.keyvalMap_.find("datadir");
         if (mapIter != cf.keyvalMap_.end())
            throw DbErrorMsg("datadir is illegal in .conf file");

         processArgs(cf.keyvalMap_, false);
      }

      processArgs(args, false);

      //figure out defaults
      bool autoDbDir = false;
      if (dbDir_.size() == 0)
      {
         dbDir_ = dataDir_;
         appendPath(dbDir_, dbDirExtention_);
         autoDbDir = true;
      }

      if (blkFileLocation_.size() == 0)
      {
         if (!testnet_)
            blkFileLocation_ = defaultBlkFileLocation_;
         else
            blkFileLocation_ = defaultTestnetBlkFileLocation_;
      }

      //expand paths if necessary
      expandPath(dbDir_);
      expandPath(blkFileLocation_);

      if (blkFileLocation_.size() < 6 ||
         blkFileLocation_.substr(blkFileLocation_.length() - 6, 6) != "blocks")
      {
         appendPath(blkFileLocation_, "blocks");
      }

      logFilePath_ = dataDir_;
      appendPath(logFilePath_, "dbLog.txt");

      //test all paths
      auto testPath = [](const string& path, int mode)
      {
         if (!DBUtils::fileExists(path, mode))
         {
            stringstream ss;
            ss << path << " is not a valid path";

            cout << ss.str() << endl;
            throw DbErrorMsg(ss.str());
         }
      };

      testPath(dataDir_, 6);

      //create dbdir if was set automatically
      if (autoDbDir)
      {
         try
         {
            testPath(dbDir_, 0);
         }
         catch (DbErrorMsg&)
         {
#ifdef _WIN32
            CreateDirectory(dbDir_.c_str(), NULL);
#else
            mkdir(dbDir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif
         }
      }

      //now for the regular test, let it throw if it fails
      testPath(dbDir_, 6);

      testPath(blkFileLocation_, 2);

      //fcgi port
      if (useCookie_ && !customFcgiPort_)
      {
         //no custom fcgi port was provided and the db was spawned with a 
         //cookie file, fcgi port will be randomized
         srand(time(0));
         while (1)
         {
            auto port = rand() % 15000 + 49150;
            stringstream portss;
            portss << port;

            if (!testConnection("127.0.0.1", portss.str()))
            {
               fcgiPort_ = portss.str();
               break;
            }
         }
      }
   }
   catch (...)
   {
      exceptionPtr_ = current_exception();
   }
}
void CEntitiesDialog::FillInDialog()
{
	int			CurrentEnt;
	int			NumberOfEnts = (*mEntityArray).GetSize();
//	int			RealIndex = 0;
	int			ArrayIndex = 0 ;
	geBoolean	bValidSelection = FALSE ;
	int			VisibleEnt = 0 ;
	PSortStruct	pSortArray ;
	int			Index ;
	CString EntityName;

	// clear our main stuff
	m_EntityCombo.ResetContent();

	// Get a qualified list count
	for( CurrentEnt = 0; CurrentEnt < NumberOfEnts; CurrentEnt++ ) 
	{
		CEntity *pEnt;

		// get the name
		pEnt = &((*mEntityArray)[CurrentEnt]);

		if( pEnt->IsVisible() )
		{
			VisibleEnt++ ;
		}
	}

	pSortArray = (PSortStruct)geRam_Allocate(sizeof(SSortStruct)*VisibleEnt);
	if( pSortArray == NULL )
		return ;	//We're called from OnInitDialog--the best err handling we can do is leave

	// Get a qualified list
	for( CurrentEnt = 0; CurrentEnt < NumberOfEnts; CurrentEnt++ ) 
	{
		CEntity *pEnt;

		// get the name
		pEnt = &((*mEntityArray)[CurrentEnt]);

		if( pEnt->IsVisible() )
		{
			pSortArray[ArrayIndex].pEnt = pEnt ;
			pSortArray[ArrayIndex].nItem = CurrentEnt ;
			ArrayIndex++ ;
		}
	}// Qualified List

	qsort( pSortArray, VisibleEnt, sizeof( SSortStruct ), compare ) ;

	for( CurrentEnt=0; CurrentEnt < VisibleEnt; CurrentEnt++ )
	{
		EntityName = pSortArray[CurrentEnt].pEnt->GetName() ;
		if (EntityName == "")
		{
			EntityName = "Unnamed";
		}
		// strip quotes from the entity name
		stripQuotes (EntityName);
		Index = m_EntityCombo.AddString( EntityName );
		m_EntityCombo.SetItemData (Index, pSortArray[CurrentEnt].nItem );
		if( pSortArray[CurrentEnt].nItem == mCurrentEntity )
		{
			m_EntityCombo.SetCurSel( Index );
			bValidSelection = TRUE ;
		}
	}// Fill the list

	// if we have no entities set to nothing.
	if( !NumberOfEnts )
	{
		mCurrentEntity = LB_ERR;
	}
	else if( bValidSelection == FALSE ) // None of the entities populated were selected
	{
		m_EntityCombo.SetCurSel( 0 );	// Select the first one
		mCurrentEntity = m_EntityCombo.GetItemData( m_EntityCombo.GetCurSel( ) ) ;
		if( mCurrentEntity != LB_ERR )
			pDoc->SetSelectedEntity( mCurrentEntity ) ;
	}
	geRam_Free ( pSortArray ) ;

	// fill in the key/value stuff for the current entity
	FillInKeyValuePairs (0);
}/* CEntitiesDialog::FillInDialog */
Exemple #12
0
// Process admin lines
void processSOSSNMP(char *line, struct nipperConfig *nipper)
{
	// Variables
	struct ciscoCommand command;
	struct snmpCommunitySOS *communityPointer = 0;
	struct snmpHostSOS *snmpHostPointer = 0;
	int tempInt;

	if (nipper->debugMode == true)
		printf("SNMP Line: %s\n", line);

	// Init
	command = splitLine(line);

	// Create SNMP Struct if required.
	if (nipper->sos->snmp == 0)
	{
		nipper->sos->snmp = malloc(sizeof(struct snmpSOS));
		memset(nipper->sos->snmp, 0 , sizeof(struct snmpSOS));
		nipper->sos->snmp->listenPort = 161;
		nipper->sos->snmp->trapPort = 162;
		nipper->sos->snmp->authTrap = false;
	}

	// SNMP Contact...
	if (strcasecmp(command.part[2], "contact") == 0)
		stripQuotes(command.part[3], nipper->sos->snmp->contact, sizeof(nipper->sos->snmp->contact));

	// SNMP location...
	else if (strcasecmp(command.part[2], "location") == 0)
		stripQuotes(command.part[3], nipper->sos->snmp->location, sizeof(nipper->sos->snmp->location));

	// SNMP System Name...
	else if (strcasecmp(command.part[2], "name") == 0)
		stripQuotes(command.part[3], nipper->sos->snmp->systemName, sizeof(nipper->sos->snmp->systemName));

	// SNMP Listen Port...
	else if ((strcasecmp(command.part[2], "port") == 0) && (strcmp(command.part[3], "listen") == 0))
		nipper->sos->snmp->listenPort = atoi(command.part[4]);

	// SNMP Trap Port...
	else if ((strcasecmp(command.part[2], "port") == 0) && (strcmp(command.part[3], "trap") == 0))
		nipper->sos->snmp->trapPort = atoi(command.part[4]);

	// Authentication Traps...
	else if ((strcasecmp(command.part[2], "auth-trap") == 0) && (strcmp(command.part[3], "enable") == 0))
		nipper->sos->snmp->authTrap = true;

	// Community
	else if ((strcasecmp(command.part[2], "community") == 0) && (strcmp(command.part[0], "set") == 0))
	{
		// If first community...
		if (nipper->sos->snmp->community == 0)
		{
			nipper->sos->snmp->community = malloc(sizeof(struct snmpCommunitySOS));
			memset(nipper->sos->snmp->community, 0 , sizeof(struct snmpCommunitySOS));
			communityPointer = nipper->sos->snmp->community;
		}
		else
		{
			communityPointer = nipper->sos->snmp->community;
			while (communityPointer->next != 0)
				communityPointer = communityPointer->next;
			communityPointer->next = malloc(sizeof(struct snmpCommunitySOS));
			memset(communityPointer->next, 0 , sizeof(struct snmpCommunitySOS));
			communityPointer = communityPointer->next;
		}

		// Init...
		communityPointer->enableTraps = false;
		communityPointer->trafficTraps = false;
		communityPointer->version = snmp1_2;
		communityPointer->weak = false;
		communityPointer->dictionary = false;

		// Community
		stripQuotes(command.part[3], communityPointer->community, sizeof(communityPointer->community));

		// Check strength / dictionary...
		if (simplePassword(communityPointer->community, nipper) == true)
		{
			nipper->simplePasswords++;
			communityPointer->dictionary = true;
		}
		if (passwordStrength(communityPointer->community, nipper) == false)
		{
			nipper->passwordStrengths++;
			communityPointer->weak = true;
		}

		// Get other parameters...
		tempInt = 4;
		while (tempInt < command.parts)
		{
			// version
			if (strcasecmp(command.part[tempInt], "version") == 0)
			{
				tempInt++;
				if (strcasecmp(command.part[tempInt], "any") == 0)
					communityPointer->version = snmp1_2;
				else if (strcasecmp(command.part[tempInt], "v1") == 0)
					communityPointer->version = snmp1;
				else if ((strcasecmp(command.part[tempInt], "v2") == 0) || (strcmp(command.part[tempInt], "v2c") == 0))
					communityPointer->version = snmp2c;
			}

			// Trap On
			else if (strcasecmp(command.part[tempInt], "trap-on") == 0)
				communityPointer->enableTraps = true;

			// Trap Off
			else if (strcasecmp(command.part[tempInt], "trap-off") == 0)
				communityPointer->enableTraps = false;

			// Trap On
			else if (strcasecmp(command.part[tempInt], "traffic") == 0)
				communityPointer->trafficTraps = true;

			tempInt++;
		}
	}

	// Host
	else if (strcasecmp(command.part[2], "host") == 0)
	{
		// If first community...
		if (nipper->sos->snmp->host == 0)
		{
			nipper->sos->snmp->host = malloc(sizeof(struct snmpHostSOS));
			memset(nipper->sos->snmp->host, 0 , sizeof(struct snmpHostSOS));
			snmpHostPointer = nipper->sos->snmp->host;
		}
		else
		{
			snmpHostPointer = nipper->sos->snmp->host;
			while (snmpHostPointer->next != 0)
				snmpHostPointer = snmpHostPointer->next;
			snmpHostPointer->next = malloc(sizeof(struct snmpHostSOS));
			memset(snmpHostPointer->next, 0 , sizeof(struct snmpHostSOS));
			snmpHostPointer = snmpHostPointer->next;
		}

		// Init
		strcpy(snmpHostPointer->sourceInterface, "Any");
		snmpHostPointer->weak = false;
		snmpHostPointer->dictionary = false;

		// Community
		stripQuotes(command.part[3], snmpHostPointer->community, sizeof(snmpHostPointer->community));

		// Check strength / dictionary...
		if (simplePassword(snmpHostPointer->community, nipper) == true)
		{
			nipper->simplePasswords++;
			snmpHostPointer->dictionary = true;
		}
		if (passwordStrength(snmpHostPointer->community, nipper) == false)
		{
			nipper->passwordStrengths++;
			snmpHostPointer->weak = true;
		}

		// Host
		stripQuotes(command.part[4], snmpHostPointer->host, sizeof(snmpHostPointer->host));

		// Options and Trap version
		tempInt = 5;
		while (tempInt < command.parts)
		{
			// Source Interface...
			if (strcasecmp(command.part[tempInt], "src-interface") == 0)
			{
				tempInt++;
				stripQuotes(command.part[tempInt], snmpHostPointer->sourceInterface, sizeof(snmpHostPointer->sourceInterface));
			}

			// trap...
			else if (strcasecmp(command.part[tempInt], "trap") == 0)
			{
				tempInt++;
				if (strcasecmp(command.part[tempInt], "v1") == 0)
					snmpHostPointer->version = snmp1;
				else if ((strcasecmp(command.part[tempInt], "v2") == 0) || (strcasecmp(command.part[tempInt], "v2c") == 0))
					snmpHostPointer->version = snmp2c;
			}

			tempInt++;
		}
	}
}
Exemple #13
0
void writeInstance(QXmlStreamWriter &stream, const QVariantList &v)
{
    stream.writeStartElement("instance");

    writeName(stream, v[1]);

    QVariant vViewRef = v[2];
    if (vViewRef.type() == QVariant::List)
    {
        QVariantList l = vViewRef.toList();
        if (l[0].toString() == "viewRef")
        {
            writeCellRef(stream, l[2].toList());
        }
        else
        {
            qWarning("Wrong instance cell description");
        }
    }
    else
    {
        qWarning("Wrong instance description");
    }

    if (v.size() > 3)
    {
        if (v[3].type() == QVariant::List)
        {
            QVariantList l = v[3].toList();
            if (l[0].toString() == "property")
            {
                QString propertyName = l[1].toString();

                QVariant vValue = l[2];
                if (vValue.type() == QVariant::List)
                {
                    QVariantList l2 = vValue.toList();
                    QString valueType = l2[0].toString();
                    if (valueType == "string")
                    {
                        QString value = stripQuotes(l2[1].toString());
                        stream.writeStartElement("property");
                        stream.writeAttribute("name", propertyName);
                        stream.writeAttribute("value", value);
                        stream.writeEndElement();
                    }
                    else
                    {
                        qWarning("Unsupported value type '%s' for property", qPrintable(valueType));
                    }
                }
            }
            else
            {
                qWarning("Wrong instance cell description");
            }
        }
    }

    stream.writeEndElement();
}
Exemple #14
0
void processFW1Rule(char *line, struct nipperConfig *nipper, struct filterListConfig *filterListPointer)
{
    // Variables...
    struct ciscoCommand command;
    struct filterConfig *filterPointer = 0;
    struct filterConfig *filterSearchPointer = 0;
    struct filterObjectConfig *filterObjectPointer = 0;
    char tempString[nipper->maxSize];

    // Debug output
    if (nipper->debugMode == true)
        printf("Rules Line: %s\n", line);

    // If first rule...
    if (filterListPointer->filter == 0)
    {
        filterListPointer->filter = malloc(sizeof(struct filterConfig));
        filterPointer = filterListPointer->filter;
    }
    else
    {
        filterPointer = filterListPointer->filter;
        while (filterPointer->next != 0)
            filterPointer = filterPointer->next;
        filterPointer->next = malloc(sizeof(struct filterConfig));
        filterPointer = filterPointer->next;
    }

    // Init...
    memset(filterPointer, 0, sizeof(struct filterConfig));
    filterPointer->enabled = true;
    filterPointer->log = false;
    filterPointer->deleteMe = false;
    filterPointer->anySource = false;
    filterPointer->networkSource = false;
    filterPointer->anySourceService = false;
    filterPointer->anyDestination = false;
    filterPointer->networkDestination = false;
    filterPointer->anyDestinationService = false;
    filterPointer->logging = false;
    filterPointer->logDeny = false;

    // Init...
    command = splitLine(line);

    // Process lines
    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
    {
        // Read line
        memset(line, 0, LINE_SIZE + 1);
        readLine(nipper->input, line, LINE_SIZE);

        // Init...
        command = splitLine(line);

        // Debug output
        if (nipper->debugMode == true)
            printf("Rules Line: %s\n", line);

        // Action...
        if ((strcasecmp(command.part[0], ":action") == 0) && (strcasecmp(command.part[1], "()") != 0))
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Action Line: %s\n", line);

                // Action structure
                if (strcasecmp(command.part[0], ":") == 0)
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Action Line: %s\n", line);

                        // Action Type
                        if ((strcasecmp(command.part[0], ":action") == 0) || (strcasecmp(command.part[0], ":type") == 0))
                        {
                            if (strcasecmp(command.part[1], "(accept)") == 0)
                                filterPointer->action = filter_action_accept;
                            else if (strcasecmp(command.part[1], "(drop)") == 0)
                                filterPointer->action = filter_action_drop;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Admin info (UID)...
        else if ((strcasecmp(command.part[0], ":AdminInfo") == 0) && (strcasecmp(command.part[1], "(") == 0))
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Admin Line: %s\n", line);

                if ((strcasecmp(command.part[0], ":chkpf_uid") == 0) && (strcasecmp(command.part[1], "()") != 0))
                    strncpy(filterPointer->uid, command.part[1], sizeof(filterPointer->uid) -1);

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Header Text...
        else if ((strcasecmp(command.part[0], ":header_text") == 0) && (strcasecmp(command.part[1], "()") != 0))
        {
            command.part[1][strlen(command.part[1]) - 1] = 0;
            stripQuotes(command.part[1] + 1, tempString, sizeof(tempString) -1);
            insertFilterRemark(filterListPointer, filterPointer, true, tempString);
            filterPointer->deleteMe = true;
        }

        // Comments...
        else if ((strcasecmp(command.part[0], ":comments") == 0) && (strcasecmp(command.part[1], "()") != 0))
        {
            command.part[1][strlen(command.part[1]) - 1] = 0;
            stripQuotes(command.part[1] + 1, filterPointer->remark, sizeof(filterPointer->remark) -1);
        }

        // Disabled...
        else if ((strcasecmp(command.part[0], ":disabled") == 0) && (strcasecmp(command.part[1], "(false)") == 0))
            filterPointer->enabled = true;
        else if ((strcasecmp(command.part[0], ":disabled") == 0) && (strcasecmp(command.part[1], "(true)") == 0))
            filterPointer->enabled = false;

        // Track (Log)...
        else if ((strcasecmp(command.part[0], ":track") == 0) && (strcasecmp(command.part[1], "()") != 0))
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Track Line: %s\n", line);

                // Log structure
                if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "log") == 0))
                    filterPointer->log = true;

                // If reference object
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Track Line: %s\n", line);

                        if ((strcasecmp(command.part[0], ":Name") == 0) && (strcasecmp(command.part[1], "(Log)") == 0))
                            filterPointer->log = true;
                        else if ((strcasecmp(command.part[0], ":Name") == 0) && (strcasecmp(command.part[1], "(None)") == 0))
                            filterPointer->log = false;

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Destination...
        else if (strcasecmp(command.part[0], ":dst") == 0)
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Destination Line: %s\n", line);

                // Member line
                if ((strcasecmp(command.part[0], ":") == 0) && (command.part[1][0] != '('))
                {
                    filterObjectPointer = getFilterMember(filterPointer, command.part[1], object_filter_destination);
                    filterObjectPointer->type = object_type_object;
                }
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Install Line: %s\n", line);

                        // Name
                        if (strcasecmp(command.part[0], ":Name") == 0)
                        {
                            command.part[1][strlen(command.part[1]) -1] = 0;
                            filterObjectPointer = getFilterMember(filterPointer, command.part[1] + 1, object_filter_destination);
                            filterObjectPointer->type = object_type_object;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Source...
        else if (strcasecmp(command.part[0], ":src") == 0)
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Source Line: %s\n", line);

                // Member line
                if ((strcasecmp(command.part[0], ":") == 0) && (command.part[1][0] != '('))
                {
                    filterObjectPointer = getFilterMember(filterPointer, command.part[1], object_filter_source);
                    filterObjectPointer->type = object_type_object;
                }
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Install Line: %s\n", line);

                        // Name
                        if (strcasecmp(command.part[0], ":Name") == 0)
                        {
                            command.part[1][strlen(command.part[1]) -1] = 0;
                            filterObjectPointer = getFilterMember(filterPointer, command.part[1] + 1, object_filter_source);
                            filterObjectPointer->type = object_type_object;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Install...
        else if (strcasecmp(command.part[0], ":install") == 0)
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Install Line: %s\n", line);

                // Member line
                if ((strcasecmp(command.part[0], ":") == 0) && (command.part[1][0] != '('))
                {
                    filterObjectPointer = getFilterMember(filterPointer, command.part[1], object_filter_install);
                    filterObjectPointer->type = object_type_object;
                }
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Install Line: %s\n", line);

                        // Name
                        if (strcasecmp(command.part[0], ":Name") == 0)
                        {
                            command.part[1][strlen(command.part[1]) -1] = 0;
                            filterObjectPointer = getFilterMember(filterPointer, command.part[1] + 1, object_filter_install);
                            filterObjectPointer->type = object_type_object;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Through...
        else if (strcasecmp(command.part[0], ":through") == 0)
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Install Line: %s\n", line);

                // Member line
                if ((strcasecmp(command.part[0], ":") == 0) && (command.part[1][0] != '('))
                {
                    filterObjectPointer = getFilterMember(filterPointer, command.part[1], object_filter_through);
                    filterObjectPointer->type = object_type_object;
                }
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Install Line: %s\n", line);

                        // Name
                        if (strcasecmp(command.part[0], ":Name") == 0)
                        {
                            command.part[1][strlen(command.part[1]) -1] = 0;
                            filterObjectPointer = getFilterMember(filterPointer, command.part[1] + 1, object_filter_through);
                            filterObjectPointer->type = object_type_object;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Services (destination)...
        else if (strcasecmp(command.part[0], ":services") == 0)
        {
            // Process lines
            while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
            {
                // Read line
                memset(line, 0, LINE_SIZE + 1);
                readLine(nipper->input, line, LINE_SIZE);

                // Init...
                command = splitLine(line);

                // Debug output
                if (nipper->debugMode == true)
                    printf("Rules Service Line: %s\n", line);

                // Member line
                if ((strcasecmp(command.part[0], ":") == 0) && (command.part[1][0] != '('))
                {
                    filterObjectPointer = getFilterMember(filterPointer, command.part[1], object_filter_service);
                    filterObjectPointer->type = object_type_object;
                }
                else if ((strcasecmp(command.part[0], ":") == 0) && (strcasecmp(command.part[1], "(ReferenceObject") == 0))
                {
                    // Process lines
                    while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
                    {
                        // Read line
                        memset(line, 0, LINE_SIZE + 1);
                        readLine(nipper->input, line, LINE_SIZE);

                        // Init...
                        command = splitLine(line);

                        // Debug output
                        if (nipper->debugMode == true)
                            printf("Rules Install Line: %s\n", line);

                        // Name
                        if (strcasecmp(command.part[0], ":Name") == 0)
                        {
                            command.part[1][strlen(command.part[1]) -1] = 0;
                            filterObjectPointer = getFilterMember(filterPointer, command.part[1] + 1, object_filter_service);
                            filterObjectPointer->type = object_type_object;
                        }

                        // Process Unknown...
                        else
                            processFW1Unknown(nipper, line);
                    }
                    command.part[0][0] = 0;
                }

                // Process Unknown...
                else
                    processFW1Unknown(nipper, line);
            }
            command.part[0][0] = 0;
        }

        // Process Unknown...
        else
            processFW1Unknown(nipper, line);
    }

    // If the filter should be deleted...
    if (filterPointer->deleteMe == true)
    {
        // Sort out pointers...
        if (filterPointer == filterListPointer->filter)
            filterListPointer->filter = filterPointer->next;
        else
        {
            filterSearchPointer = filterListPointer->filter;
            while (filterSearchPointer->next != filterPointer)
                filterSearchPointer = filterSearchPointer->next;
            filterSearchPointer->next = filterPointer->next;
        }

        // Delete struct...
        while (filterPointer->source != 0)
        {
            filterObjectPointer = filterPointer->source->next;
            free (filterPointer->source);
            filterPointer->source = filterObjectPointer;
        }
        while (filterPointer->sourceService != 0)
        {
            filterObjectPointer = filterPointer->sourceService->next;
            free (filterPointer->sourceService);
            filterPointer->sourceService = filterObjectPointer;
        }
        while (filterPointer->destination != 0)
        {
            filterObjectPointer = filterPointer->destination->next;
            free (filterPointer->destination);
            filterPointer->destination = filterObjectPointer;
        }
        while (filterPointer->destinationService != 0)
        {
            filterObjectPointer = filterPointer->destinationService->next;
            free (filterPointer->destinationService);
            filterPointer->destinationService = filterObjectPointer;
        }
        while (filterPointer->through != 0)
        {
            filterObjectPointer = filterPointer->through->next;
            free (filterPointer->through);
            filterPointer->through = filterObjectPointer;
        }
        while (filterPointer->install != 0)
        {
            filterObjectPointer = filterPointer->install->next;
            free (filterPointer->install);
            filterPointer->install = filterObjectPointer;
        }
        free (filterPointer);
    }
}
void processFW1Rulebase(char *line, struct nipperConfig *nipper)
{
	// Variables...
	struct filterListConfig *filterListPointer = 0;
	struct filterConfig *filterPointer = 0;
	struct ciscoCommand command;
	char tempString[nipper->maxSize];
	int tempInt = false;

	// Init...
	command = splitLine(line);

	// Get Filter List Pointer...
	command.part[1][strlen(command.part[1]) - 1] = 0;
	filterListPointer = getFilterList(nipper, command.part[1] + 4, "", false);

	// Does the list already exist?
	if (filterListPointer->filter != 0)
	{
		filterPointer = filterListPointer->filter;

		// Process lines
		while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0) && (filterPointer != 0))
		{
			// Read line
			memset(line, 0, LINE_SIZE + 1);
			readLine(nipper->input, line, LINE_SIZE);
	
			// Init...
			command = splitLine(line);
	
			// Debug output
			if (nipper->debugMode == true)
				printf("Rulebase Line: %s\n", line);

			// Process Rules...
			if ((strcmp(command.part[0], ":rule") == 0) && (strcmp(command.part[1], "()") != 0))
			{
				while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0) && (filterPointer != 0))
				{
					// Read line
					memset(line, 0, LINE_SIZE + 1);
					readLine(nipper->input, line, LINE_SIZE);
			
					// Init...
					command = splitLine(line);
			
					// Debug output
					if (nipper->debugMode == true)
						printf("Rulebase Line: %s\n", line);

					// Comments...
					if ((strcasecmp(command.part[0], ":comments") == 0) && (strcasecmp(command.part[1], "()") != 0))
					{
						command.part[1][strlen(command.part[1]) - 1] = 0;
						stripQuotes(command.part[1] + 1, filterPointer->remark, sizeof(filterPointer->remark) -1);
					}

					// Header Text...
					else if ((strcasecmp(command.part[0], ":header_text") == 0) && (strcasecmp(command.part[1], "()") != 0))
					{
						command.part[1][strlen(command.part[1]) - 1] = 0;
						stripQuotes(command.part[1] + 1, tempString, sizeof(tempString) -1);
						insertFilterRemark(filterListPointer, filterPointer, true, tempString);
						tempInt = true;
					}

					// Process Unknown...
					else
						processFW1Unknown(nipper, line);
				}
				command.part[0][0] = 0;
				if (tempInt == false)
					filterPointer = filterPointer->next;
				else
					tempInt = false;
			}

			// Process Unknown...
			else
				processFW1Unknown(nipper, line);
		}
		command.part[0][0] = 0;
	}

	// List already exists...
	else
	{

		// Process lines
		while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0))
		{
			// Read line
			memset(line, 0, LINE_SIZE + 1);
			readLine(nipper->input, line, LINE_SIZE);
	
			// Init...
			command = splitLine(line);
	
			// Debug output
			if (nipper->debugMode == true)
				printf("Rulebase Line: %s\n", line);

			// Process Rules...
			if ((strcmp(command.part[0], ":rule") == 0) && (strcmp(command.part[1], "()") != 0))
				processFW1Rule(line, nipper, filterListPointer);

			// Process Unknown...
			else
				processFW1Unknown(nipper, line);
		}
	}
}
Exemple #16
0
/*
 * parse_config Parse the config file into the fields structure. Inputs:
 * configfile Output: the table of name/value pairs for the object being
 * created is filled in with values from the arg list. Returns 0 Success 1 if
 * error For every name/value pair in the config file, search for the name in
 * * the field_table (all possible argument names) and fill the value in the
 * table.
 */
int parse_config(
    char *configfile,
    struct object_field *tbl)
{
    int n,
        err = 0;
    char *name,
       *value;
    int name_len;
    FILE *fp;
    char *buf;
    int flen;
    struct stat stbuf;

    memset(parse_errstr, 0, sizeof(parse_errstr));

    if (stat(configfile, &stbuf) != 0)
    {
        fprintf(stderr, "Error getting file size %s\n", configfile);
        return 1;
    }

    flen = stbuf.st_size;
    if ((buf = calloc(flen, sizeof(char))) == NULL)
    {
        fprintf(stderr, "Memory Error\n");
        return 1;
    }

    // Open the config file
    fp = fopen(configfile, "r");
    if (fp == NULL)
    {
        fprintf(stderr, "Error Opening Config File %s\n", configfile);
        return 1;
    }

    // read each line and process
    while (fgets(buf, flen, fp) != NULL)
    {
        name = buf;
        while (isspace((int)(unsigned char)*name))
            name++;
        if ((strncmp(name, ";", 1) == 0) || strlen(buf) <= 0)
            continue;

        value = strchr(buf, '=');
        if ((value == NULL) || (strlen(value + 1) <= 0))
        {
            fprintf(stderr, "Warning: blank value (line: %s)\n", buf);
            continue;
        }

        name_len = value - name;
        if ((n = fieldInTable(name, name_len, tbl)) >= 0)
            tbl[n].value = stripQuotes(stripws(++value));
        else
        {
            if (err != 0)       // not first error, add comma
                strcat(parse_errstr, ", ");
            strcat(parse_errstr, name);
            err = 1;
        }
    }
    return err;
}
Exemple #17
0
  int sFlowList(void *magic, char *line)
  {
    EVMod *mod = (EVMod *)magic;
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    // expect lines of form <var> : <val>
    int varlen = strcspn(line, ":");
    if(varlen >= strlen(line)) {
      myLog(LOG_ERR, "expected <var> : <val>, but got <%s>", line);
      return NO;
    }
    line[varlen] = '\0';
    char *var = stripQuotes(line, SFVS_QUOTES);
    char *val = stripQuotes(line + varlen + 1, SFVS_QUOTES);
    myDebug(1, "sFlowList> %s=%s", var, val);
    if(strcmp(var, "_uuid") == 0) {
      switch(mdata->state) {
      case SFVSSTATE_SYNC_SEARCH:
	myDebug(1, "found sflow uuid %s", val);
	setStr(&mdata->sflowUUID, val);
	setState(mod, SFVSSTATE_SYNC_FOUND);
	break;
      case SFVSSTATE_SYNC_FOUND:
      case SFVSSTATE_SYNC_DESTROY:
	setState(mod, SFVSSTATE_SYNC_DESTROY);
	myDebug(1, "found extra sflow uuid %s", val);
	strArrayAdd(mdata->extras, val);
	break;
      default:
	myLog(LOG_ERR, "sFlowList: unexpected state %s", SFVSStateNames[mdata->state]);
	setState(mod, SFVSSTATE_END);
	return NO;
      }
    }
    else if (mdata->state == SFVSSTATE_SYNC_FOUND) {
      // we have adopted an existing sFlow object.  This is the one
      // we will keep. All others will be destroyed. Here we check in
      // case any of the individual parameters need to be changed too.
      if(strcmp(var, "agent") == 0) {
	char quoted[SFVS_MAX_LINELEN];
	snprintf(quoted, SFVS_MAX_LINELEN, "\"%s\"", val);
	if(strcmp(quoted, mdata->config.agent_dev) != 0) {
	  addSFlowSetting(mod, "agent", mdata->config.agent_dev);
	}
      }
      else if(strcmp(var, "header") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.header_bytes) {
	  addSFlowSetting_int(mod, "header", mdata->config.header_bytes);
	}
      }
      else if(strcmp(var, "polling") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.polling_secs) {
	  addSFlowSetting_int(mod, "polling", mdata->config.polling_secs);
	}
      }
      else if(strcmp(var, "sampling") == 0) {
	uint32_t n = strtol(val, NULL, 0);
	if(n != mdata->config.sampling_n) {
	  addSFlowSetting_int(mod, "sampling", mdata->config.sampling_n);
	}
      }
      else if(strcmp(var, "targets") == 0) {
	// the spaces between elements in the array are a nuisance, because they
	// could go away someday and break any scheme that relies on a simple
	// string-compare. So parse it into comma-separated tokens.
	// single-threaded, so we can just use strtok(3)
	UTStringArray *array = strArrayNew();
	val = stripQuotes(val, "[]");
	char *delim = ", ";
	for(char *tok = strtok(val, delim); tok != NULL; tok=strtok(NULL, delim)) {
	  strArrayAdd(array, stripQuotes(tok, SFVS_QUOTES));
	}
	strArraySort(array);
	if(!strArrayEqual(array, mdata->config.targets)) {
	  addSFlowSetting(mod, "targets", mdata->config.targetStr);
	}
	strArrayFree(array);
      }
    }
    return YES;
  }