inline wostream& print_field_value(wostream &os, wchar_t tag, const CItemData &item, CItemData::FieldType ft) { StringX fieldValue; switch (ft) { case CItemData::DCA: case CItemData::SHIFTDCA: { int16 dca = -1; if (item.GetDCA(dca) != -1) { LoadAString(fieldValue, dca2str(dca)); } break; } case CItemData::PWHIST: { const StringX pwh_str = item.GetPWHistory(); if (!pwh_str.empty()) { StringXStream value_stream; size_t ignored; PWHistList pwhl; const bool save_pwhistory = CreatePWHistoryList(pwh_str, ignored, ignored, pwhl, PWSUtil::TMC_LOCALE); value_stream << L"Save: " << (save_pwhistory? L"Yes" : L"No"); if ( !pwhl.empty() ) value_stream << endl; for( const auto &pwh: pwhl) value_stream << pwh.changedate << L": " << pwh.password << endl; fieldValue = value_stream.str(); } break; } case CItemData::POLICY: { PWPolicy policy; item.GetPWPolicy(policy); fieldValue = policy.GetDisplayString(); break; } default: fieldValue = item.GetFieldValue(ft); break; } const StringX sep1{L' '}, sep2{L": "}; StringXStream tmpStream; tmpStream << tag << L' ' << item.FieldName(ft) << L": " << fieldValue; const auto offset = 1 /*tag*/ + sep1.size() + sep2.size() + item.FieldName(ft).size(); lines_vec lines{ stream2vec(tmpStream)}; if ( lines.size() > 1) { std::for_each( lines.begin()+1, lines.end(), [offset](StringX &line) { line.insert(0, offset, L' '); }); } for( const auto &line: lines ) os << line << endl; return os; }
bool PWSFilterManager::PassesPWHFiltering(const CItemData *pci) const { bool thistest_rc, bPresent; bool bValue(false); int iValue(0); size_t pwh_max, err_num; PWHistList pwhistlist; bool status = CreatePWHistoryList(pci->GetPWHistory(), pwh_max, err_num, pwhistlist, PWSUtil::TMC_EXPORT_IMPORT); bPresent = pwh_max > 0 || !pwhistlist.empty(); for (auto group_iter = m_vHflgroups.begin(); group_iter != m_vHflgroups.end(); group_iter++) { const vfiltergroup &group = *group_iter; int tests(0); bool thisgroup_rc = false; for (auto num_iter = group.begin(); num_iter != group.end(); num_iter++) { const int &num = *num_iter; if (num == -1) // Padding for FT_PWHIST & FT_POLICY - shouldn't happen here continue; const st_FilterRow &st_fldata = m_currentfilter.vHfldata.at(num); thistest_rc = false; PWSMatch::MatchType mt(PWSMatch::MT_INVALID); const FieldType ft = st_fldata.ftype; switch (ft) { case HT_PRESENT: bValue = bPresent; mt = PWSMatch::MT_BOOL; break; case HT_ACTIVE: bValue = status == TRUE; mt = PWSMatch::MT_BOOL; break; case HT_NUM: iValue = (int)pwhistlist.size(); mt = PWSMatch::MT_INTEGER; break; case HT_MAX: iValue = (int)pwh_max; mt = PWSMatch::MT_INTEGER; break; case HT_CHANGEDATE: mt = PWSMatch::MT_DATE; break; case HT_PASSWORDS: mt = PWSMatch::MT_STRING; break; default: ASSERT(0); } const int ifunction = (int)st_fldata.rule; switch (mt) { case PWSMatch::MT_STRING: for (auto pwshe_iter = pwhistlist.begin(); pwshe_iter != pwhistlist.end(); pwshe_iter++) { PWHistEntry pwshe = *pwshe_iter; thistest_rc = PWSMatch::Match(st_fldata.fstring, pwshe.password, st_fldata.fcase ? -ifunction : ifunction); tests++; if (thistest_rc) break; } break; case PWSMatch::MT_INTEGER: thistest_rc = PWSMatch::Match(st_fldata.fnum1, st_fldata.fnum2, iValue, ifunction); tests++; break; case PWSMatch::MT_DATE: for (auto pwshe_iter = pwhistlist.begin(); pwshe_iter != pwhistlist.end(); pwshe_iter++) { const PWHistEntry pwshe = *pwshe_iter; // Following throws away hours/min/sec from changetime, for proper date comparison time_t changetime = pwshe.changetttdate - (pwshe.changetttdate % (24*60*60)); thistest_rc = PWSMatch::Match(st_fldata.fdate1, st_fldata.fdate2, changetime, ifunction); tests++; if (thistest_rc) break; } break; case PWSMatch::MT_BOOL: thistest_rc = PWSMatch::Match(bValue, ifunction); tests++; break; default: ASSERT(0); } if (tests <= 1) thisgroup_rc = thistest_rc; else { //Within groups, tests are always "AND" connected thisgroup_rc = thistest_rc && thisgroup_rc; } } // This group of tests completed - // if 'thisgroup_rc == true', leave now; else go on to next group if (thisgroup_rc) return true; } // We finished all the groups and haven't found one that is true - exclude entry. return false; }