/** Gather the Major and Minor version from Product version Parameters: version - Product version, its format like 11.23.32, REV- or 0.4b41 */ void InstalledSoftwareInstance::SetDetailedVersion(const wstring& version) { size_t pos = version.find_first_of('.'); if( pos != wstring::npos ) { wstring left = version.substr(0, pos); wstring right = version.substr(pos+1); try { m_versionMajor = StrToUInt(left); // Exclude characters for(pos = 0; pos< right.size(); pos++) { if( right[pos] < '0' || right[pos] > '9' ) { break; } } if(pos > 0) { left = right.substr(0, pos); m_versionMinor = StrToUInt(left); } } catch (const SCXException& e) { SCX_LOGWARNING(m_log, StrAppend(L"parse InstalledSoftwareInstance version fails:", version).append(L" - ").append(e.What())); } } }
const bool CLevel::LoadHeader( std::fstream& stream ) { Log.Log( "GLEVEL( " + file + " ): £adowanie nag³ówka."); std::string str, name, value; while( stream ) { str = GetLine( stream ); if( str == "END HEADER" ) return true; if( !ParseNameValue( str, name, value ) ) { Log.Error( "GLEVEL( " + file + " ): Nieprawid³owy ci¹g w nag³ówku: " + str + "." ); continue; } if( name == "NAME" ) LevName = value; else if( name == "ROWS" ) Rows = StrToUInt( value ); else if( name == "COLS" ) Cols = StrToUInt( value ); else Log.Error( "GLEVEL( " + file + " ): Nierozpoznana wartoœæ " + name + " w ci¹gu: " + str + "." ); } Log.Error( "GLEVEL( " + file + " ): Brak koñca nag³ówka." ); return false; }
/** Read a list of application server instances from disk. \param[out] instances - vector of Application Server Instances to insert the values read from disk into */ void PersistAppServerInstances::ReadFromDisk( vector<SCXHandle<AppServerInstance> >& instances) { try { SCXHandle<SCXPersistDataReader> preader = m_pmedia->CreateReader(APP_SERVER_PROVIDER); preader->ConsumeStartGroup(APP_SERVER_METADATA, true); wstring sizeFromCache = preader->ConsumeValue(APP_SERVER_NUMBER); preader->ConsumeEndGroup(true); // Closing APP_SERVER_NUMBER unsigned int size = StrToUInt(sizeFromCache); while(ReadFromDiskHelper(preader, instances)) { } // If the size read does not match the actual number // of instances read (for instance, some has truncated // the cache), then the cache probably has been corrupted. // For this case, throw away all the cache information. if (instances.size() != size) { instances.clear(); } RemoveNonExistentInstances(instances); } // Could have gotten here is the cache does not // exist or is corrupt. If it does not exist, then // the exception is thrown when doing the first read // and nothing has been added to the array. In this case, // the goal is to not surface the error. // // If corruption has occurred, then the cache should be // deleted (which should happen when we re-persist the current // state. catch(SCXNotSupportedException& snse) { SCX_LOGTRACE(m_log, snse.What()); instances.clear(); } catch(PersistDataNotFoundException& pdnfe) { SCX_LOGTRACE(m_log, pdnfe.What()); instances.clear(); } catch(PersistUnexpectedDataException& pude) { SCX_LOGTRACE(m_log, pude.What()); instances.clear(); } }
/** Constructor. \param[in] path Path where persisted data should be read. */ SCXFilePersistDataReader::SCXFilePersistDataReader(const SCXFilePath& path) : m_StartedGroups() { m_Stream = SCXFile::OpenFstream(path, std::ios_base::in); std::wstreampos pos = m_Stream->tellg(); try { Consume(L"<?xml"); Consume(L"version"); Consume(L"="); ConsumeString(L"1.0"); Consume(L"encoding"); Consume(L"="); Consume(L"'UTF-8'"); Consume(L"standalone"); Consume(L"="); Consume(L"'yes'"); Consume(L"?>"); Consume(L"<"); Consume(L"SCXPersistedData"); Consume(L"Version"); Consume(L"="); std::wstring versionString = ConsumeString(); Consume(L">"); m_Version = StrToUInt(versionString); } catch (PersistUnexpectedDataException& e) { m_Stream->seekg(pos); throw e; } catch (SCXCoreLib::SCXNotSupportedException&) { std::wstreampos errorpos = m_Stream->tellg(); m_Stream->seekg(pos); throw PersistUnexpectedDataException(L"The Version attribute should have an unsigned integer value", errorpos, SCXSRCLOCATION); } }
/** Consumes an XML-encoded character. XML-encoded characters are the characters starting with & and ending with ; Example < " . This method is called after the initial & has been encountered to consume everything after the '&' character and return the encoded character. \returns Consumed character. \throws PersistUnexpectedDataException if data is not the next data in the stream. */ wchar_t SCXFilePersistDataReader::ConsumeEncodedChar() { std::wstring entity(L""); for (wchar_t ch = GetUTF8Char(); ch != ';'; ch = GetUTF8Char()) { entity.push_back(ch); } wchar_t c = 0; if (L"lt" == entity) { c = L'<'; } else if (L"amp" == entity) { c = L'&'; } else if (L"apos" == entity) { c = L'\''; } else if (L"quot" == entity) { c = L'\"'; } else if (entity.size() > 0 && entity[0] == L'#') { c = static_cast<wchar_t>(StrToUInt(std::wstring(entity, 1))); } else { throw PersistUnexpectedDataException(L"XML encoded character.", m_Stream->tellg(), SCXSRCLOCATION); } return c; }
/** Extract the major version number from the complete version \param[in] version version of the application server Retval: major version number */ wstring WebLogicAppServerInstance::ExtractMajorVersion(const wstring& version) { vector<wstring> parts; StrTokenizeStr(version, parts, L"."); wstring returnValue = L""; if (parts.size() >= 3) { // version consists of: // // major.minor.revision // // i.e. 10.3.2 maps to // // major: 10 // minor: 3 // revision: 2 unsigned int major = StrToUInt(parts[0]); unsigned int minor = StrToUInt(parts[1]); unsigned int revision = StrToUInt(parts[2]); switch (major) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: returnValue = parts[0]; break; case 10: if (WEBLOGIC_VERSION_MINOR == minor) { if (0 == revision) { returnValue = WEBLOGIC_BRANDED_VERSION_10; } else { returnValue = WEBLOGIC_BRANDED_VERSION_11; } } else if (minor < WEBLOGIC_VERSION_MINOR) { returnValue = WEBLOGIC_BRANDED_VERSION_10; } else //if (minor > WEBLOGIC_VERSION_MINOR) { returnValue = WEBLOGIC_BRANDED_VERSION_11; } break; case 12: returnValue = parts[0]; break; default: returnValue = WEBLOGIC_BRANDED_VERSION_11; } } return returnValue; }
std::vector<NetworkInterfaceConfigurationInstance> NetworkInterfaceConfigurationEnumeration::FindAll() { // Use NetworkInterface provider to get all the interfaces std::vector<NetworkInterfaceInfo> interfaces = NetworkInterfaceInfo::FindAll(m_deps); std::vector<NetworkInterfaceConfigurationInstance> resultList; for (size_t nr = 0; nr < interfaces.size(); nr++) { NetworkInterfaceConfigurationInstance instance(interfaces[nr]); // Set m_Index instance.m_Index = static_cast<Uint32>(nr); instance.SetKnown(NetworkInterfaceConfigurationInstance::eIndex); // Get if interface is enabled. If up interface has the address set. If running inteface has the resources // allocated and is ready to receive/transmit. if (interfaces[nr].IsKnownIfUp() && interfaces[nr].IsKnownIfRunning()) { instance.SetKnown(NetworkInterfaceConfigurationInstance::eIPEnabled); instance.m_IPEnabled = false; if (interfaces[nr].IsUp() && interfaces[nr].IsRunning()) { instance.m_IPEnabled = true; } } // (WI 468917) Activate MAC Address to be reported by the provider. interfaces[nr].GetMACAddress(instance.m_MACAddress); instance.SetKnown(NetworkInterfaceConfigurationInstance::eMACAddress); instance.m_IPAddress.clear(); if (interfaces[nr].IsIPAddressKnown()) { instance.m_IPAddress.push_back(interfaces[nr].GetIPAddress()); } vector<wstring> tmpIPv6 = interfaces[nr].GetIPV6Address(); instance.m_IPAddress.insert(instance.m_IPAddress.end(), tmpIPv6.begin(), tmpIPv6.end()); if (instance.m_IPAddress.empty() == false) { instance.SetKnown(NetworkInterfaceConfigurationInstance::eIPAddress); } if (interfaces[nr].IsNetmaskKnown()) { instance.m_IPSubnet.resize(1); instance.m_IPSubnet[0] = interfaces[nr].GetNetmask(); instance.SetKnown(NetworkInterfaceConfigurationInstance::eIPSubnet); } // Determine m_ArpUseEtherSNAP // ARP packets can be sent using EtherType fields in Ethernet II (DIX) format or in 802.3 (SNAP) format. // Both are permitted. Some operating systems can force ARP packets to be sent in the newer 802.3 // format, but due to its simplicity, the older DIX format is still widely used. #if defined(linux) || defined(sun) instance.m_ArpUseEtherSNAP = false; instance.SetKnown(NetworkInterfaceConfigurationInstance::eArpUseEtherSNAP); #endif // Determine m_Caption // Index in format [nnnnnnnn] followed by a short textual description (one-line string) of the object. ostringstream ixstr; ixstr << '[' << setfill('0') << setw(8) << nr << "] "; instance.m_Caption = StrFromMultibyte(ixstr.str()) + instance.GetName(); instance.SetKnown(NetworkInterfaceConfigurationInstance::eCaption); // Determine m_Description // Description of the CIM_Setting object. This property is inherited from CIM_Setting. instance.m_Description = instance.GetName(); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDescription); // Determine m_DeadGWDetectEnabled // If TRUE, dead gateway detection occurs. With this feature enabled, Transmission // Control Protocol (TCP) asks Internet Protocol (IP) to change to a backup gateway // if it retransmits a segment several times without receiving a response. // // For Linux, this capability was added with IPv6 via its Neighbor Discovery protocol // Solaris also. #if defined(linux) // Subset of neighbor reachability problems solved by IPv6 instance.m_DeadGWDetectEnabled = SCXDirectory::Exists(L"/proc/sys/net/ipv6"); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDeadGWDetectEnabled); #endif // Determine m_DefaultTOS // Default Type Of Service (TOS) value set in the header of outgoing IP packets. // Request for Comments (RFC) 791 defines the values. Default: 0 (zero), // Valid Range: 0 - 255. // This is deprecated. Implementations also are not uniform. // NOT SET-------------- // Determine m_DefaultTTL // Default Time To Live (TTL) value set in the header of outgoing IP packets. // The TTL specifies the number of routers an IP packet can pass through to // reach its destination before being discarded. Each router decrements by // one the TTL count of a packet as it passes through and discards the // packets if the TTL is 0 (zero). Default: 32, Valid Range: 1 - 255. std::vector<wstring> lines; SCXStream::NLFs nlfs; #if defined(PF_DISTRO_REDHAT) || defined(sun) // This is hardcoded in Linux microkernel source. Since V2.2 it has been in net/ipv4/ipconfig.c // For Solaris it has been 64 since version 2.8 instance.m_DefaultTTL = 64; instance.SetKnown(NetworkInterfaceConfigurationInstance::eDefaultTTL); #elif defined(PF_DISTRO_SUSE) || defined(PF_DISTRO_ULINUX) // if /proc/sys/net/ipv4/ip_default_ttl exists, then override 64 as the default with what is contained SCXFile::ReadAllLines(SCXFilePath(L"/proc/sys/net/ipv4/ip_default_ttl"), lines, nlfs); if (lines.size() > 0) { instance.m_DefaultTTL = (Uint8) StrToUInt(lines[0]); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDefaultTTL); } #endif // Determine m_DHCPEnabled // If TRUE, the dynamic host configuration protocol (DHCP) server automatically // assigns an IP address to the computer system when establishing a network connection. // First fetch config data from the appropriate file wstring interface = instance.GetName(); lines.clear(); bool performRead = true; #if defined(PF_DISTRO_SUSE) // Determine DHCP Enabled by looking for process dhcpcd w/param matching this interface name instance.m_DHCPEnabled = GetDHCPEnabledFromProcessList(interface); #elif defined(PF_DISTRO_REDHAT) SCXFile::ReadAllLines(SCXFilePath(SCXCoreLib::StrAppend(L"/etc/sysconfig/network-scripts/ifcfg-", interface)), lines, nlfs); #elif defined(PF_DISTRO_ULINUX) instance.m_DHCPEnabled = GetDHCPEnabledFromProcessList(interface); if (!instance.m_DHCPEnabled) { if (SCXFile::Exists(SCXCoreLib::StrAppend(L"/etc/sysconfig/network-scripts/ifcfg-", interface))) { SCXFile::ReadAllLines(SCXFilePath(SCXCoreLib::StrAppend(L"/etc/sysconfig/network-scripts/ifcfg-", interface)), lines, nlfs); } else if (SCXFile::Exists(SCXCoreLib::StrAppend(L"/etc/sysconfig/network/ifcfg-", interface))) { SCXFile::ReadAllLines(SCXFilePath(SCXCoreLib::StrAppend(L"/etc/sysconfig/network/ifcfg-", interface)), lines, nlfs); } else { performRead = false; } } #elif defined(sun) SCXFile::ReadAllLines(SCXFilePath(SCXCoreLib::StrAppend(L"/etc/hostname.", interface)), lines, nlfs); #elif defined(hpux) SCXFile::ReadAllLines(SCXFilePath(L"/etc/rc.config.d/netconf"), lines, nlfs); #elif defined(aix) SCXFile::ReadAllLines(SCXFilePath(L"/etc/dhcpcd.ini"), lines, nlfs); #endif if (performRead) { instance.m_DHCPEnabled = GetDHCPEnabledFromConfigData(lines, interface); } #if defined(linux) // Determine DHCP Enabled by looking for process dhcpcd w/param matching this interface name if (!instance.m_DHCPEnabled) { instance.m_DHCPEnabled = GetDHCPEnabledFromProcessList(interface); } #endif instance.SetKnown(NetworkInterfaceConfigurationInstance::eDHCPEnabled); #if defined(linux) || defined(sun) || defined(hpux) // Initialize the DHCP lease information DHCPLeaseInfo dhcpLeaseInfo(interface); // Determine m_DHCPLeaseExpires // Expiration date and time for a leased IP address that was assigned to the // computer by the dynamic host configuration protocol (DHCP) server. // Example: 20521201000230.000000000 instance.m_DHCPLeaseExpires = dhcpLeaseInfo.getLeaseExpires(); if (instance.m_DHCPLeaseExpires.IsInitialized()) { instance.SetKnown(NetworkInterfaceConfigurationInstance::eDHCPLeaseExpires); } // Determine m_DHCPLeaseObtained // Date and time the lease was obtained for the IP address assigned to the // computer by the dynamic host configuration protocol (DHCP) server. // Example: 19521201000230.000000000 instance.m_DHCPLeaseObtained = dhcpLeaseInfo.getLeaseObtained(); if (instance.m_DHCPLeaseObtained.IsInitialized()) { instance.SetKnown(NetworkInterfaceConfigurationInstance::eDHCPLeaseObtained); } #endif // Determine m_DHCPServer // IP address of the dynamic host configuration protocol (DHCP) server. // Example: 10.55.34.2 #if defined(linux) instance.m_DHCPServer = dhcpLeaseInfo.getDHCPServer(); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDHCPServer); #endif // Determine m_DefaultIPGateway // Array of IP addresses of default gateways that the computer system uses. // Example: 192.168.12.1 192.168.46.1 #if defined(linux) || defined(sun) wstring gwip; if (GatewayInfo::get_gatewayip(gwip, m_deps)) { instance.m_DefaultIPGateway.push_back(gwip); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDefaultIPGateway); } #elif defined(hpux) // The HPUX DHCP info file also contains the default gateway wstring defaultGateway = dhcpLeaseInfo.getDefaultGateway(); if (defaultGateway.size() > 0) { instance.m_DefaultIPGateway.push_back(defaultGateway); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDefaultIPGateway); } #endif // Determine m_DNSDomain // Organization name followed by a period and an extension that indicates // the type of organization, such as microsoft.com. The name can be any // combination of the letters A through Z, the numerals 0 through 9, and // the hyphen (-), plus the period (.) character used as a separator. // Example: microsoft.com #if defined(linux) || defined(sun) || defined(hpux) instance.m_DNSDomain = dhcpLeaseInfo.getDomainName(); instance.SetKnown(NetworkInterfaceConfigurationInstance::eDNSDomain); #endif // Determine m_DNSDomainSuffixSearchOrder // Array of DNS domain suffixes to be appended to the end of host names // during name resolution. When attempting to resolve a fully qualified // domain name (FQDN) from a host-only name, the system will first append // the local domain name. If this is not successful, the system will use // the domain suffix list to create additional FQDNs in the order listed // and query DNS servers for each. // Example: samples.microsoft.com example.microsoft.com // Linux doesn't add missing suffixes -----NOT SET // Determine m_DNSEnabledForWINSResolution // If TRUE, the Domain Name System (DNS) is enabled for name resolution // over Windows Internet Naming Service (WINS) resolution. If the name // cannot be resolved using DNS, the name request is forwarded to WINS // for resolution. // Windows only --------NOT SET // Determine m_DNSHostName // Host name used to identify the local computer for authentication by // some utilities. Other TCP/IP-based utilities can use this value to // acquire the name of the local computer. Host names are stored on DNS // servers in a table that maps names to IP addresses for use by DNS. // The name can be any combination of the letters A through Z, the // numerals 0 through 9, and the hyphen (-), plus the period (.) character // used as a separator. By default, this value is the Microsoft networking // computer name, but the network administrator can assign another host // name without affecting the computer name. // Example: corpdns // Probably utility authentication for Windows only ----------NOT SET // Determine m_DNSServerSearchOrder // Array of server IP addresses to be used in querying for DNS servers. #if defined(linux) || defined(sun) || defined(hpux) lines.clear(); instance.m_DNSServerSearchOrder.clear(); SCXFile::ReadAllLines(SCXFilePath(L"/etc/resolv.conf"), lines, nlfs); for (uint i = 0; i < lines.size(); i++) { // remove all comments from the current line, as they should be ignored wstring curLine = lines[i]; wstring::size_type pos; pos = curLine.find(L";"); if (pos != wstring::npos) { curLine.erase(pos, curLine.length()); } if (curLine.empty()) { continue; } std::vector<wstring> tokens; StrTokenize(curLine, tokens, L" \t"); if (tokens.size() > 1 && tokens[0].compare(L"nameserver") == 0) { instance.m_DNSServerSearchOrder.push_back(tokens[1]); } } if(instance.m_DNSServerSearchOrder.size() > 0) { instance.SetKnown(NetworkInterfaceConfigurationInstance::eDNSServerSearchOrder); } #endif // Determine m_DomainDNSRegistrationEnabled // If TRUE, the IP addresses for this connection are registered in DNS under the domain // name of this connection in addition to being registered under the computer's // full DNS name. The domain name of this connection is either set using the // SetDNSDomain() method or assigned by DSCP. The registered name is the host // name of the computer with the domain name appended. // Windows 2000: This property is not available. // NOT SET for Linux------------------------------------------------------ // Determine m_ArpAlwaysSourceRoute // If TRUE, TCP/IP transmits Address Resolution Protocol (ARP) queries with // source routing enabled on Token Ring networks. By default (FALSE), ARP first // queries without source routing, and then retries with source routing enabled // if no reply is received. Source routing allows the routing of network packets // across different types of networks. // See http://www.rapid7.com/vulndb/lookup/generic-ip-source-routing-enabled for AIX/Linux/Solaris // This property seems to be set to prevent ARP spoofing. The // principle of ARP spoofing is to send fake ARP messages onto a LAN. // Generally, the aim is to associate the attacker's MAC address with // the IP address of another host (such as the default gateway). // // Operating System Approaches // Static ARP entries: entries in the local ARP cache can be defined as // static to prevent overwrite. While static entries provide perfect security // against spoofing if the operating systems handles them correctly, they // result in quadratic maintenance efforts as IP-MAC mappings of all machines // in the network have to be distributed to all other machines. // OS security: Operating systems react differently, e.g. Linux ignores // unsolicited replies, but on the other hand uses seen requests from // other machines to update its cache. Solaris only accepts updates on // entries after a timeout. In Microsoft Windows, the behavior of the // ARP cache can be configured through several registry entries under // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters, // namely ArpCacheLife, ArpCacheMinReferenceLife, ArpUseEtherSNAP, ArpTRSingleRoute, // ArpAlwaysSourceRoute, ArpRetryCount. #if defined(linux) instance.m_ArpAlwaysSourceRoute = false; lines.clear(); SCXFile::ReadAllLines(SCXFilePath(L"/etc/sysctl.conf"), lines, nlfs); SCXRegex r(L"accept_source_route\\s*=\\s*([01])"); instance.m_ArpAlwaysSourceRoute = false; for (int i = 0; i < (int)lines.size(); i++) { if (r.IsMatch(lines[i])) { instance.m_ArpAlwaysSourceRoute = true; break; } } instance.SetKnown(NetworkInterfaceConfigurationInstance::eArpAlwaysSourceRoute); #endif resultList.push_back(instance); } return resultList; }
/** Get DHCPEnabled status from the platform's config file \param configData - contents of the DHCP config file \param interface - the interface for which we want DHCPEnabled status */ bool NetworkInterfaceConfigurationEnumeration::GetDHCPEnabledFromConfigData ( std::vector<wstring>configData, wstring interface ) { if (interface.size() + configData.size() == 0) { return false; } #if defined(PF_DISTRO_REDHAT) || defined(PF_DISTRO_ULINUX) || defined(PF_DISTRO_SUSE) /* Typical file DEVICE="eth0" # This is also in the file name BOOTPROTO="dhcp" HWADDR="00:21:5E:DB:AC:98" ONBOOT="yes" */ bool result = false; SCXRegex bootproto(L"BOOTPROTO.*dhcp"); for (uint i = 0; i < configData.size(); i++) { wstring line = configData[i]; if (bootproto.IsMatch(configData[i])) { result = true; } } return result; #elif defined(sun) return configData.size() > 0; // If the file exists and has data that means DHCP is enabled #elif defined(hpux) // We are looking for a line // // DHCP_ENABLED[<i>]="<1|0>" // // where 1 means enabled and <i> corresponds to a line of the form // // INTERFACE_NAME[<i>]="<interface name>" // // and <interface name> matches the member variable of NetworkInterfaceConfigurationInstance instance // // Example file where we are looking for network interface "lan0" /* INTERFACE_NAME[0]=lan0 #<---------- for interface "lan0" this means we are looking for index 0 IP_ADDRESS[0]=10.217.5.127 SUBNET_MASK[0]=255.255.254.0 BROADCAST_ADDRESS[0]="" INTERFACE_STATE[0]="" DHCP_ENABLE[0]=1 #<----------- this is the DHCP_ENABLED line we are therefore interested in INTERFACE_MODULES[0]="" INTERFACE_NAME[1]=lan666 IP_ADDRESS[1]=55.5.12.12 DHCP_ENABLE[1]=0 */ bool result = false; uint idx = numeric_limits<unsigned int>::max(); vector<wstring> tokens; for (uint i = 0; i < configData.size(); i++) { wstring line = configData[i]; StrTokenize(line, tokens, L"[]="); if (tokens.size() < 1) { continue; } if (tokens[0].compare(L"INTERFACE_NAME") == 0) { if (tokens[2].compare(interface) == 0) { idx = StrToUInt(tokens[1]); } } else if (line.find(L"DHCP_ENABLE") == 0) { if (idx == StrToUInt(tokens[1])); { result = (tokens[2].compare(L"1") == 0) ? 1 : 0; } } } return result; #elif defined(aix) // The file has entries that look like this: // // # Blah // Mumble ... // interface en1 // { // option 13 0 // option 54 10.152.203.45 // option 9 0 // } // We want the interface name to match our interface // Then search for option 54, which is 'Server Identifier' according // to 'DHCP Server Configuration File' section of 'AIX 6.1 Information' doc // from IBM. // The number at the end of that line is address of the server, or '0' (or blank) // if DHCP is not enabled on this interface. bool result = false; vector<wstring> tokens; for(uint i = 0; i < configData.size(); ++i) { wstring line = configData[i]; StrTokenize(line, tokens, L"\t "); if(tokens.size() < 2) { continue; } // look for "interface" tag followed by our interface, e.g. "interface en1" if(tokens[0].compare(L"interface") == 0 && tokens[1].compare(interface) == 0) { // we could get cute with recursion here but let's just look for // our line .. if we hit a closing curly brace or "interface" tag // call it quits // Loop starting at the same position in the vector .. for(/* i does not change */ ; i < configData.size() ; ++i) { line = configData[i]; StrTokenize(line, tokens, L"\t "); if(tokens.size() < 1) continue; // if this hits we ran past the end of this interface section .. // since we are searching in the interface specified by client, we are done ... if(tokens[0].compare(L"}") == 0) return false; // The only interesting line looks like "option 54 <IPAddress | 0>" so must have 3 tokens if(tokens.size() < 2) continue; // Get line with an address, look at it .. if(tokens[0].compare(L"option") == 0 && tokens[1].compare(L"54") == 0) { // no ip address, no DHCP .... if(tokens[2].compare(L"0") == 0) break; // back to searching for "interface" block // If address has even one ['.' | ':'] char we will assume it is a good [IP | IPv6] address and return true if(tokens[2].find(L'.') != wstring::npos || tokens[2].find(L':') != wstring::npos) return true; // There can be no two entries of the form "interface <our_interface>" in a file // so no good IP address here means we are done ... else return false; } } } } return result; #else throw SCXNotSupportedException(L"GetDHCPEnabledFromConfigData", SCXSRCLOCATION); #endif }
const bool CLevel::LoadItemList( std::fstream& stream ) { Log.Log( "GLEVEL( " + file + " ): £adowanie listy przedmiotów."); std::string str; std::vector<std::string> params; ITEM_TYPE type; int x, y; while( stream ) { str = GetLine( stream ); if( str == "END ITEMLIST" ) return true; str = ClearWhiteSpace( str ); params.clear(); if( ParseItem( str, x, y, type, params ) ) { CItem* item = nullptr; switch (type) { break; case ITEM_TYPE::AMMO: item = new CItemAmmo( ParseWeapon( params[0] ) , StrToUInt( params[1] ) ); break; case ITEM_TYPE::HEALTH: item = new CItemHealth( StrToFloat( params[0] ) ); break; case ITEM_TYPE::ARMOR: item = new CItemArmor( StrToFloat( params[0] ) ); break; case ITEM_TYPE::WEAPON: item = new CItemWeapon( ParseWeapon( params[0] ), StrToUInt( params[1] ) ); break; case ITEM_TYPE::UNKNOWN: default: Log.Error("GLEVEL( " + file + " ): B³¹d parsowania przedmiotu, nieznany typ z parsowania ci¹gu: " + str + "."); break; } if(item != nullptr) { item->Pos = GetBlockPos( x, y ); AddEntity( item ); Items.push_back( item ); } } else { Log.Error("GLEVEL( " + file + " ): B³¹d parsowania przedmiotu dla ci¹gu: " + str + "."); } } Log.Error( "GLEVEL( " + file + " ): Brak koñca listy przedmiotów!" ); return false; }
/** Update the Solaris Sparc instance. */ void StaticDiskPartitionInstance::Update_Solaris() { SCX_LOGTRACE(m_log, L"DiskPartition::Update_Solaris():: Entering, DeviceID is:" + m_deviceID); // Execute 'df -g' and retrieve result to determine filesystem that is mounted on // and block size. Then, go through output of prtvtoc for this filesystem to // retrieve the remaining partition information. #if PF_MAJOR == 5 && (PF_MINOR == 9 || PF_MINOR == 10) wstring cmdStringDf = L"/usr/sbin/df -g"; #elif PF_MAJOR == 5 && PF_MINOR == 11 wstring cmdStringDf = L"/sbin/df -g"; #else #error "Platform not supported" #endif int status; std::istringstream processInputDf; std::ostringstream processOutputDf; std::ostringstream processErrDf; wstring curLine; curLine.clear(); wstring mountedStr; wstring blockSizeStr; std::string dfResult; vector<wstring> allLines; // all lines read from output allLines.clear(); SCXStream::NLFs nlfs; bool foundIt = false; vector<wstring> matchingVector; SCXRegexPtr solDfPatternPtr(NULL); SCXRegexPtr solPrtvtocBpSPatternPtr(NULL); SCXRegexPtr solPrtvtocDetailPatternPtr(NULL); // Let's build our RegEx: try { solDfPatternPtr = new SCXCoreLib::SCXRegex(c_SolDfPattern); solPrtvtocBpSPatternPtr = new SCXCoreLib::SCXRegex(c_SolPrtvtocBpSPattern); solPrtvtocDetailPatternPtr = new SCXCoreLib::SCXRegex(c_SolprtvtocDetailPattern); } catch(SCXCoreLib::SCXInvalidRegexException &e) { SCX_LOGERROR(m_log, L"Exception caught in compiling regex: " + e.What()); return; } try { status = SCXCoreLib::SCXProcess::Run(cmdStringDf, processInputDf, processOutputDf, processErrDf, 15000); if (status != 0) { SCX_LOGERROR(m_log, StrAppend(L"Error on command " + cmdStringDf + L" - status ", status)); SCX_LOGERROR(m_log, StrFromUTF8("Output - " + processOutputDf.str())); SCX_LOGERROR(m_log, StrFromUTF8("Error - " + processErrDf.str())); return; } dfResult = processOutputDf.str(); } catch(SCXCoreLib::SCXException &e) { SCX_LOGERROR(m_log, L"Unable to retrieve partition information from OS using 'df -g'..." + e.What()); } std::istringstream stringStrmDf_g(dfResult); allLines.clear(); size_t dfLineCt = 100; allLines.reserve(dfLineCt); foundIt = false; SCXCoreLib::SCXStream::ReadAllLinesAsUTF8(stringStrmDf_g, allLines, nlfs); for (vector<wstring>::iterator it = allLines.begin(); it != allLines.end() && !foundIt; it++) { curLine.assign(*it); matchingVector.clear(); if ((solDfPatternPtr->ReturnMatch(curLine, matchingVector, 0)) && (matchingVector.size() >= 4) && (m_deviceID == matchingVector[2])) { mountedStr = matchingVector[1]; blockSizeStr = matchingVector[3]; foundIt = true; } else if (matchingVector.size() > 0) { //Have an error message SCX_LOGINFO(m_log, L"No match found! Error: " + matchingVector[0]); } } //Check the results if (!foundIt || mountedStr .size() == 0) { SCX_LOGERROR(m_log, L"Failed to find this partition info with df -g: " + m_deviceID ); return; } //The next (and last) step is to do a prtvtoc [dir] command to retrieve the rest of the partition info: #if PF_MAJOR == 5 && (PF_MINOR == 9 || PF_MINOR == 10) wstring cmdStringPrtvToc = L"/usr/sbin/prtvtoc " + m_deviceID; #elif PF_MAJOR == 5 && PF_MINOR == 11 wstring cmdStringPrtvToc = L"/sbin/prtvtoc " + m_deviceID; #else #error "Platform not supported" #endif std::istringstream processInputPrtvtoc; std::ostringstream processOutputPrtvtoc; std::ostringstream processErrPrtvtoc; curLine.clear(); wstring firstSectorStr; wstring sectorCountStr; wstring bytesPerSectorStr; std::string prtResult(""); try { SCXCoreLib::SCXProcess::Run(cmdStringPrtvToc, processInputPrtvtoc, processOutputPrtvtoc, processErrPrtvtoc, 15000); prtResult = processOutputPrtvtoc.str(); size_t lengthCaptured = prtResult.length(); // Truncate trailing newline if there in captured output if (lengthCaptured > 0) { if (prtResult[lengthCaptured - 1] == '\n') { prtResult[lengthCaptured - 1] = '\0'; } } } catch(SCXCoreLib::SCXException &e) { SCX_LOGERROR(m_log, L"Unable to retrieve partition information from OS using 'df -g'..." + e.What()); } std::istringstream stringStrmPrtvtoc(prtResult); allLines.clear(); foundIt = false; SCXCoreLib::SCXStream::ReadAllLinesAsUTF8(stringStrmPrtvtoc, allLines, nlfs);; for(vector<wstring>::iterator it = allLines.begin(); it != allLines.end() && !foundIt; it++) { curLine.assign(*it); matchingVector.clear(); // First, we match on a comment line that tells us the Sector Size if (solPrtvtocBpSPatternPtr->ReturnMatch(curLine, matchingVector, 0)) { bytesPerSectorStr = matchingVector[1]; } // Next, we look for a detail line that matches our index: else if ((solPrtvtocDetailPatternPtr->ReturnMatch(curLine, matchingVector, 0)) && (matchingVector.size() >= 5) && (m_index == SCXCoreLib::StrToUInt(matchingVector[1]))) { // This is our row in the Partion info output firstSectorStr = matchingVector[2]; sectorCountStr = matchingVector[3]; foundIt = true; } } //Check the results if (!foundIt || bytesPerSectorStr.size() == 0) { SCX_LOGERROR(m_log, L"Failed to find this partition info with prtvtoc: " + m_deviceID + L" And Regex Error Msg: " + matchingVector[0]); return; } // If we reached here we have everything we need // just need to do a little arithmetic and fill in our Properties struct: m_blockSize = SCXCoreLib::StrToULong(blockSizeStr); char dummyChar; unsigned int sectorSz = StrToUInt(bytesPerSectorStr); unsigned long long totalSectors = StrToUInt(sectorCountStr); unsigned long long startingSector = StrToUInt(firstSectorStr); m_partitionSize = totalSectors * sectorSz; m_startingOffset = startingSector * sectorSz; m_numberOfBlocks = RoundToUnsignedInt(static_cast<double>(m_partitionSize) / static_cast<double>(m_blockSize)); return; }