void ToAppRule( Kxe_AppRule_Param& ruleParam, KAppRule& rule ) { ToGUID( &(ruleParam.id), &(rule.m_id) ); rule.SetType( (AppRuleType)(ruleParam.nRuleType) ); rule.SetExePath( (LPWSTR)(ruleParam.strExePath.c_str()) ); ToMd5( &(ruleParam.checkSum), rule.m_checkSum ); rule.SetLastFileTime( ruleParam.ftLast ); rule.SetLastTrustRepTime( ruleParam.ftLastTrustRep ); rule.SetCreator( (LPWSTR)(ruleParam.strCreator.c_str()) ); rule.SetCreateDate( ruleParam.ftCreate ); rule.SetCreateReason( (LPWSTR)(ruleParam.strReason.c_str()) ); rule.SetLastModifyDate( ruleParam.ftLastModify ); rule.SetLastModifyer( (LPWSTR)(ruleParam.m_strModifyer.c_str()) ); rule.m_tcpRemoteDenyRange = ruleParam.tcpRemoteDenyRange; rule.m_tcpLocalDenyRange = ruleParam.tcpLocalDenyRange; rule.m_udpRemoteDenyRange = ruleParam.udpRemoteDenyRange; rule.m_udpLocalDenyRange = ruleParam.udpLocalDenyRange; rule.m_userMode = ruleParam.nUserMode; rule.m_trustMode = ruleParam.nTrustMode; rule.m_pathhashCode = ruleParam.lPathhashCode; rule.m_pExternData = (LPVOID)(ruleParam.pExternData); }
inline HRESULT KAppFile::ReadRule(KRecord* pRecord) { HRESULT hr = S_OK; ASSERT(pRecord->GetType() == AppRule_Rule); KAppRule* pRule = m_pAppMgr->CreateRule(); KRecord rule = pRecord->FirstSubRecord(); while (pRecord->IsSubRecord(rule)) { if (!rule.Ok()) { hr = E_APP_FILE_UNKNOWN_FMT; break; } switch (rule.GetType()) { case AppRule_RuleID: { ASSERT(rule.GetDataSize() == sizeof(GUID)); pRule->SetID(*(GUID*)rule.GetData()); } break; case AppRule_ExePath: { pRule->SetExePath( (LPWSTR)rule.GetData() ); kis::KPath path(pRule->GetExePath()); if (!path.Exists()) { hr = E_FAIL; goto EXIT0; //break; } if (m_pAppMgr->FindRule(pRule->GetExePath()) != NULL) { hr = E_FAIL; goto EXIT0; } } break; case AppRule_UserMode: { ASSERT(rule.GetDataSize() == sizeof(INT)); pRule->SetUserMode(*(INT*)rule.GetData()); } break; case AppRule_TrustMode: { ASSERT(rule.GetDataSize() == sizeof(INT)); pRule->SetTrustMode(*(INT*)rule.GetData()); } break; case AppRule_CheckSum: { ASSERT(rule.GetDataSize() == sizeof(pRule->m_checkSum)); memcpy(pRule->m_checkSum, rule.GetData(), sizeof(pRule->m_checkSum)); } break; case AppRule_LastFileTime: { ASSERT(rule.GetDataSize() == sizeof(FILETIME)); pRule->SetLastFileTime( *(FILETIME*)rule.GetData() ); } break; case AppRule_Creator: { pRule->SetCreator( (LPWSTR)rule.GetData() ); } break; case AppRule_CreateDate: { ASSERT(rule.GetDataSize() == sizeof(FILETIME)); pRule->SetCreateDate( *(FILETIME*)rule.GetData() ); } break; case AppRule_CreateReason: { pRule->SetCreateReason( (LPWSTR)rule.GetData() ); } break; case AppRule_LastModifyDate: { ASSERT(rule.GetDataSize() == sizeof(FILETIME)); pRule->SetLastModifyDate( *(FILETIME*)rule.GetData() ); } break; case AppRule_LastModifyer: { pRule->SetLastModifyer( (LPWSTR)rule.GetData() ); } break; case AppRule_DenyPortList: { hr = ReadDenyPortList( &rule , pRule); if (FAILED(hr)) break; } break; } rule = rule.NextRecord(); } EXIT0: if (SUCCEEDED(hr)) { if (SUCCEEDED(m_pAppMgr->AddRule(pRule))) return hr; } delete pRule; return hr; }