StringX PWSAuxParse::GetAutoTypeString(const CItemData &ci, const PWScore &core, std::vector<size_t> &vactionverboffsets) { // Set up all the data (a shortcut entry will change all of them!) StringX sxgroup = ci.GetGroup(); StringX sxtitle = ci.GetTitle(); StringX sxuser = ci.GetUser(); StringX sxpwd = ci.GetPassword(); StringX sxnotes = ci.GetNotes(); StringX sxurl = ci.GetURL(); StringX sxemail = ci.GetEmail(); StringX sxautotype = ci.GetAutoType(); if (ci.IsAlias()) { const CItemData *pbci = core.GetBaseEntry(&ci); if (pbci != NULL) { sxpwd = pbci->GetPassword(); } else { // Problem - alias entry without a base! ASSERT(0); } } else if (ci.IsShortcut()) { const CItemData *pbci = core.GetBaseEntry(&ci); if (pbci != NULL) { sxgroup = pbci->GetGroup(); sxtitle = pbci->GetTitle(); sxuser = pbci->GetUser(); sxpwd = pbci->GetPassword(); sxnotes = pbci->GetNotes(); sxurl = pbci->GetURL(); sxemail = pbci->GetEmail(); sxautotype = pbci->GetAutoType(); } else { // Problem - shortcut entry without a base! ASSERT(0); } } // ci.IsShortcut() // If empty, try the database default if (sxautotype.empty()) { sxautotype = PWSprefs::GetInstance()-> GetPref(PWSprefs::DefaultAutotypeString); // If still empty, take this default if (sxautotype.empty()) { // checking for user and password for default settings if (!sxpwd.empty()){ if (!sxuser.empty()) sxautotype = DEFAULT_AUTOTYPE; else sxautotype = _T("\\p\\n"); } } } return PWSAuxParse::GetAutoTypeString(sxautotype, sxgroup, sxtitle, sxuser, sxpwd, sxnotes, sxurl, sxemail, vactionverboffsets); }
bool PWSFilterManager::PassesFiltering(const CItemData &ci, const PWScore &core) { bool thistest_rc; bool bValue(false); bool bFilterForStatus(false), bFilterForType(false); const CItemData *pci; if (!m_currentfilter.IsActive()) return true; const CItemData::EntryType entrytype = ci.GetEntryType(); for (auto groups_iter = m_vMflgroups.begin(); groups_iter != m_vMflgroups.end(); groups_iter++) { const vfiltergroup &group = *groups_iter; int tests(0); bool thisgroup_rc = false; for (auto iter = group.begin(); iter != group.end(); iter++) { const int &num = *iter; if (num == -1) // Padding to ensure group size is correct for FT_PWHIST & FT_POLICY continue; const st_FilterRow &st_fldata = m_currentfilter.vMfldata.at(num); thistest_rc = false; PWSMatch::MatchType mt(PWSMatch::MT_INVALID); const FieldType ft = m_currentfilter.vMfldata[num].ftype; const int ifunction = (int)st_fldata.rule; switch (ft) { case FT_GROUPTITLE: case FT_GROUP: case FT_TITLE: case FT_USER: case FT_NOTES: case FT_URL: case FT_AUTOTYPE: case FT_RUNCMD: case FT_EMAIL: case FT_SYMBOLS: case FT_POLICYNAME: mt = PWSMatch::MT_STRING; break; case FT_PASSWORD: mt = PWSMatch::MT_PASSWORD; break; case FT_DCA: mt = PWSMatch::MT_DCA; break; case FT_SHIFTDCA: mt = PWSMatch::MT_SHIFTDCA; break; case FT_CTIME: case FT_PMTIME: case FT_ATIME: case FT_XTIME: case FT_RMTIME: mt = PWSMatch::MT_DATE; break; case FT_PWHIST: mt = PWSMatch::MT_PWHIST; break; case FT_POLICY: mt = PWSMatch::MT_POLICY; break; case FT_XTIME_INT: mt = PWSMatch::MT_INTEGER; break; case FT_KBSHORTCUT: bValue = !ci.GetKBShortcut().empty(); mt = PWSMatch::MT_BOOL; break; case FT_UNKNOWNFIELDS: bValue = ci.NumberUnknownFields() > 0; mt = PWSMatch::MT_BOOL; break; case FT_PROTECTED: bValue = ci.IsProtected(); mt = PWSMatch::MT_BOOL; break; case FT_PASSWORDLEN: mt = PWSMatch::MT_INTEGER; break; case FT_ENTRYTYPE: mt = PWSMatch::MT_ENTRYTYPE; break; case FT_ENTRYSTATUS: mt = PWSMatch::MT_ENTRYSTATUS; break; case FT_ENTRYSIZE: mt = PWSMatch::MT_ENTRYSIZE; break; case FT_ATTACHMENT: mt = PWSMatch::MT_ATTACHMENT; break; default: ASSERT(0); } if (ft == FT_ENTRYSTATUS) { bFilterForStatus = true; } if (ft == FT_ENTRYTYPE) { bFilterForType = true; } pci = &ci; if (ft == FT_PASSWORD && entrytype == CItemData::ET_ALIAS) { pci = core.GetBaseEntry(pci); // This is an alias } if (entrytype == CItemData::ET_SHORTCUT && !bFilterForStatus && !bFilterForType) { // Only include shortcuts if the filter is on the group, title or user fields // Note: "GROUPTITLE = 0x00", "GROUP = 0x02", "TITLE = 0x03", "USER = 0x04" // "UUID = 0x01" but no filter is implemented against this field // The following is a simple single test rather than testing against every value if (ft > FT_USER) { pci = core.GetBaseEntry(pci); // This is an shortcut } } switch (mt) { case PWSMatch::MT_PASSWORD: if (ifunction == PWSMatch::MR_EXPIRED) { // Special Password "string" case thistest_rc = pci->IsExpired(); tests++; break; } else if (ifunction == PWSMatch::MR_WILLEXPIRE) { // Special Password "string" case thistest_rc = pci->WillExpire(st_fldata.fnum1); tests++; break; } // Note: purpose drop through to standard 'string' processing case PWSMatch::MT_STRING: thistest_rc = pci->Matches(st_fldata.fstring.c_str(), (int)ft, st_fldata.fcase ? -ifunction : ifunction); tests++; break; case PWSMatch::MT_INTEGER: thistest_rc = pci->Matches(st_fldata.fnum1, st_fldata.fnum2, (int)ft, ifunction); tests++; break; case PWSMatch::MT_DATE: { time_t t1(st_fldata.fdate1), t2(st_fldata.fdate2); if (st_fldata.fdatetype == 1 /* Relative */) { time_t now; time(&now); t1 = now + (st_fldata.fnum1 * 86400); if (ifunction == PWSMatch::MR_BETWEEN) t2 = now + (st_fldata.fnum2 * 86400); } thistest_rc = pci->MatchesTime(t1, t2, (int)ft, ifunction); tests++; break; } case PWSMatch::MT_PWHIST: if (m_currentfilter.num_Hactive != 0) { thistest_rc = PassesPWHFiltering(pci); tests++; } break; case PWSMatch::MT_POLICY: if (m_currentfilter.num_Pactive != 0) { thistest_rc = PassesPWPFiltering(pci); tests++; } break; case PWSMatch::MT_BOOL: thistest_rc = PWSMatch::Match(bValue, ifunction); tests++; break; case PWSMatch::MT_ENTRYTYPE: thistest_rc = pci->Matches(st_fldata.etype, ifunction); tests++; break; case PWSMatch::MT_DCA: case PWSMatch::MT_SHIFTDCA: thistest_rc = pci->Matches(st_fldata.fdca, ifunction, mt == PWSMatch::MT_SHIFTDCA); tests++; break; case PWSMatch::MT_ENTRYSTATUS: thistest_rc = pci->Matches(st_fldata.estatus, ifunction); tests++; break; case PWSMatch::MT_ENTRYSIZE: thistest_rc = pci->Matches(st_fldata.fnum1, st_fldata.fnum2, (int)ft, ifunction); tests++; break; case PWSMatch::MT_ATTACHMENT: if (m_currentfilter.num_Aactive != 0) { thistest_rc = PassesAttFiltering(pci, core); 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; }