public EcasTrigger CloneDeep() { EcasTrigger e = new EcasTrigger(false); e.m_uuid = m_uuid; // PwUuid is immutable e.m_strName = m_strName; e.m_strComments = m_strComments; e.m_bEnabled = m_bEnabled; e.m_bInitiallyOn = m_bInitiallyOn; e.m_bOn = m_bOn; e.m_bTurnOffAfterAction = m_bTurnOffAfterAction; for (uint i = 0; i < m_events.UCount; ++i) { e.m_events.Add(m_events.GetAt(i).CloneDeep()); } for (uint j = 0; j < m_conds.UCount; ++j) { e.m_conds.Add(m_conds.GetAt(j).CloneDeep()); } for (uint k = 0; k < m_acts.UCount; ++k) { e.m_acts.Add(m_acts.GetAt(k).CloneDeep()); } return(e); }
public void GetAllUserRootNodesReturnsOnlyValidRootNodes() { m_treeManager.Initialize(m_database); PwEntry root1 = new PwEntry(true, true); PwEntry root2 = new PwEntry(true, true); PwEntry root3 = new PwEntry(true, true); PwEntry normalEntry1 = new PwEntry(true, true); PwEntry normalEntry2 = new PwEntry(true, true); PwGroup level1 = new PwGroup(); //initial data root1.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString(false, root1.Uuid.ToHexString())); root2.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString(false, root2.Uuid.ToHexString())); root3.Strings.Set(KeeShare.KeeShare.UuidLinkField, new ProtectedString(false, root3.Uuid.ToHexString())); m_database.RootGroup.AddEntry(root1, true); m_database.RootGroup.AddEntry(root2, true); m_database.RootGroup.AddEntry(normalEntry1, true); m_database.RootGroup.AddGroup(level1, true); level1.AddEntry(normalEntry2, true); level1.AddEntry(root3, true); PwObjectList <PwEntry> rootNodes = m_database.GetAllUserNodes(); Assert.AreEqual(3, rootNodes.UCount); Assert.AreEqual(root1, rootNodes.GetAt(0)); Assert.AreEqual(root2, rootNodes.GetAt(1)); Assert.AreEqual(root3, rootNodes.GetAt(2)); }
public EcasTriggerSystem CloneDeep() { EcasTriggerSystem c = new EcasTriggerSystem(); c.m_bEnabled = m_bEnabled; for (uint i = 0; i < m_vTriggers.UCount; ++i) { c.m_vTriggers.Add(m_vTriggers.GetAt(i).CloneDeep()); } return(c); }
public void SharedFoldersCollectsAllSharedFoldersForAuser() { PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0); Assert.AreEqual("mrX", mrX.Strings.ReadSafe(KeeShare.KeeShare.TitleField)); //according to our testDatabase we want to ensure that GetSharedFolders(mrX) //returns a list of groups with only two members: "grp1" and the home of "mrX" PwObjectList <PwGroup> sharedFolders = m_syncManager.GetSharedFolders(mrX); Assert.AreEqual(2, sharedFolders.UCount); Assert.AreEqual("grp1", sharedFolders.GetAt(0).Name); Assert.AreEqual("mrX", sharedFolders.GetAt(1).Name); }
public async void CheckAll() { bulkCheck = true; var progressDisplay = new ProgressDisplay(); progressDisplay.Show(); var allEntries = new PwObjectList <PwEntry>(); Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries); for (uint i = 0; i < allEntries.UCount; i++) { PasswordEntry = allEntries.GetAt(i); await System.Threading.Tasks.Task.Run(() => PasswordCheckWorker()); TouchEntry(PasswordEntry); progressDisplay.progressBar.Value = ((int)i + 1) * 100 / ((int)allEntries.UCount); if (progressDisplay.UserTerminated) { progressDisplay.Close(); break; } } UpdateUI(); progressDisplay.Close(); }
public static PwEntry GetConfPwEntry(PwDatabase pwDatabase) { var sp = new SearchParameters { SearchString = YANDEX_DISC_CONFIGURATION_ENTRY, ComparisonMode = StringComparison.OrdinalIgnoreCase, RespectEntrySearchingDisabled = false, SearchInGroupNames = false, SearchInNotes = false, SearchInOther = false, SearchInPasswords = false, SearchInTags = false, SearchInTitles = true, SearchInUrls = true, SearchInUserNames = false, SearchInUuids = false }; PwObjectList <PwEntry> accounts = new PwObjectList <PwEntry>(); pwDatabase.RootGroup.SearchEntries(sp, accounts); return((accounts.UCount >= 1) ? accounts.GetAt(0) : null); }
public void ClearAll() { DialogResult dialog = MessageBox.Show("This will remove the HIBP status for all entries in the database. Continue?", String.Empty, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dialog == DialogResult.Cancel) { return; } bulkCheck = true; MainForm mainForm = Host.MainWindow; PwObjectList <PwEntry> allEntries = new PwObjectList <PwEntry>(); Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries); for (uint i = 0; i < allEntries.UCount; i++) { var entry = allEntries.GetAt(i); entry.Strings.Remove(PluginOptions.ColumnName); Status = null; receivedStatus = true; TouchEntry(entry); } UpdateUI(); }
/// <summary> /// Load the current configuration /// </summary> private bool LoadConfiguration() { m_entry = null; m_clientId = string.Empty; m_clientSecret = null; m_refreshToken = null; if (!m_host.Database.IsOpen) { return(false); } // find the active account PwObjectList <PwEntry> accounts = FindActiveAccounts(); if (accounts != null && accounts.UCount == 1) { m_entry = accounts.GetAt(0); } else { // alternatively try to find the active account in the config file (old configuration) (may be removed in later versions) string strUuid = m_host.CustomConfig.GetString(Defs.ConfigUUID); try { m_entry = m_host.Database.RootGroup.FindEntry(new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(strUuid)), true); } catch (ArgumentException) { } } if (m_entry == null) { return(false); } // read OAuth 2.0 credentials ProtectedString pstr = m_entry.Strings.Get(Defs.ConfigClientId); if (pstr != null) { m_clientId = pstr.ReadString(); } m_clientSecret = m_entry.Strings.Get(Defs.ConfigClientSecret); m_refreshToken = m_entry.Strings.Get(Defs.ConfigRefreshToken); // use default OAuth 2.0 credentials if missing if (String.IsNullOrEmpty(m_clientId)) { m_clientId = DefaultClientId; m_clientSecret = new ProtectedString(true, DefaultClientSecret); } // something missing? if (m_entry == null || String.IsNullOrEmpty(m_clientId) || m_clientSecret == null || m_clientSecret.IsEmpty) { return(false); } return(true); }
public PwEntry Get(string text) { var unlocker = new Unlocker { Host = Host }; unlocker.Unlock(); var p = new SearchParameters { SearchInTitles = true, SearchString = text }; var databases = Host.MainWindow.DocumentManager.GetOpenDatabases(); foreach (var database in databases) { var list = new PwObjectList <PwEntry>(); database.RootGroup.SearchEntries(p, list); if (list.UCount > 0) { var e = list.GetAt(0); var title = e.Strings.ReadSafe(PwDefs.TitleField); ShowBalloonNotification($"Entry {title} was read."); return(e); } } throw new Exception("No " + text + " entry found!"); }
public static string CreateSummaryList(PwGroup pgSubGroups, PwEntry[] vEntries) { int nMaxEntries = 10; string strSummary = string.Empty; if (pgSubGroups != null) { PwObjectList <PwGroup> vGroups = pgSubGroups.GetGroups(true); if (vGroups.UCount > 0) { StringBuilder sbGroups = new StringBuilder(); sbGroups.Append("- "); uint uToList = Math.Min(3U, vGroups.UCount); for (uint u = 0; u < uToList; ++u) { if (sbGroups.Length > 2) { sbGroups.Append(", "); } sbGroups.Append(vGroups.GetAt(u).Name); } if (uToList < vGroups.UCount) { sbGroups.Append(", ..."); } strSummary += sbGroups.ToString(); // New line below nMaxEntries -= 2; } } int nSummaryShow = Math.Min(nMaxEntries, vEntries.Length); if (nSummaryShow == (vEntries.Length - 1)) { --nSummaryShow; // Plural msg } for (int iSumEnum = 0; iSumEnum < nSummaryShow; ++iSumEnum) { if (strSummary.Length > 0) { strSummary += MessageService.NewLine; } PwEntry pe = vEntries[iSumEnum]; strSummary += ("- " + StrUtil.CompactString3Dots( pe.Strings.ReadSafe(PwDefs.TitleField), 39)); if (PwDefs.IsTanEntry(pe)) { string strTanIdx = pe.Strings.ReadSafe(PwDefs.UserNameField); if (!string.IsNullOrEmpty(strTanIdx)) { strSummary += (@" (#" + strTanIdx + @")"); } } } return(strSummary); }
private static void ExportDatabaseFile(EcasAction a, EcasContext ctx) { string strPath = EcasUtil.GetParamString(a.Parameters, 0, true); // if(string.IsNullOrEmpty(strPath)) return; // Allow no-file exports string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true); if (string.IsNullOrEmpty(strFormat)) { return; } string strGroup = EcasUtil.GetParamString(a.Parameters, 2, true); string strTag = EcasUtil.GetParamString(a.Parameters, 3, true); PwDatabase pd = Program.MainForm.ActiveDatabase; if ((pd == null) || !pd.IsOpen) { return; } PwGroup pg = pd.RootGroup; if (!string.IsNullOrEmpty(strGroup)) { char chSep = strGroup[0]; PwGroup pgSub = pg.FindCreateSubTree(strGroup.Substring(1), new char[] { chSep }, false); pg = (pgSub ?? (new PwGroup(true, true, KPRes.Group, PwIcon.Folder))); } if (!string.IsNullOrEmpty(strTag)) { pg = pg.CloneDeep(); GroupHandler gh = delegate(PwGroup pgSub) { PwObjectList <PwEntry> l = pgSub.Entries; long n = (long)l.UCount; for (long i = n - 1; i >= 0; --i) { if (!l.GetAt((uint)i).HasTag(strTag)) { l.RemoveAt((uint)i); } } return(true); }; gh(pg); pg.TraverseTree(TraversalMethod.PreOrder, gh, null); } PwExportInfo pei = new PwExportInfo(pg, pd, true); IOConnectionInfo ioc = (!string.IsNullOrEmpty(strPath) ? IOConnectionInfo.FromPath(strPath) : null); ExportUtil.Export(pei, strFormat, ioc); }
/// <summary> /// Method to check whether a reordering is required. This fast test /// allows to skip the reordering routine, resulting in a large /// performance increase. /// </summary> internal bool ObjectListRequiresReorder<T>(PwObjectList<T> vItems, PwObjectPool ppOrgStructure, PwObjectPool ppSrcStructure, bool bEntries) where T : class, IStructureItem, IDeepClonable<T> { Debug.Assert(ppOrgStructure.ContainsOnlyType(bEntries ? typeof(PwEntry) : typeof(PwGroup))); Debug.Assert(ppSrcStructure.ContainsOnlyType(bEntries ? typeof(PwEntry) : typeof(PwGroup))); if(vItems.UCount <= 1) return false; if((m_slStatus != null) && !m_slStatus.ContinueWork()) return false; T ptFirst = vItems.GetAt(0); // IStructureItem ptOrg = pgOrgStructure.FindObject(ptFirst.Uuid, true, bEntries); IStructureItem ptOrg = ppOrgStructure.Get(ptFirst.Uuid); if(ptOrg == null) return true; // IStructureItem ptSrc = pgSrcStructure.FindObject(ptFirst.Uuid, true, bEntries); IStructureItem ptSrc = ppSrcStructure.Get(ptFirst.Uuid); if(ptSrc == null) return true; if(ptFirst.ParentGroup == null) { Debug.Assert(false); return true; } PwGroup pgOrgParent = ptOrg.ParentGroup; if(pgOrgParent == null) return true; // Root might be in tree PwGroup pgSrcParent = ptSrc.ParentGroup; if(pgSrcParent == null) return true; // Root might be in tree if(!ptFirst.ParentGroup.Uuid.EqualsValue(pgOrgParent.Uuid)) return true; if(!pgOrgParent.Uuid.EqualsValue(pgSrcParent.Uuid)) return true; List<IStructureItem> lOrg = pgOrgParent.GetObjects(false, bEntries); List<IStructureItem> lSrc = pgSrcParent.GetObjects(false, bEntries); if(vItems.UCount != (uint)lOrg.Count) return true; if(lOrg.Count != lSrc.Count) return true; for(uint u = 0; u < vItems.UCount; ++u) { IStructureItem pt = vItems.GetAt(u); Debug.Assert(pt.ParentGroup == ptFirst.ParentGroup); if(!pt.Uuid.EqualsValue(lOrg[(int)u].Uuid)) return true; if(!pt.Uuid.EqualsValue(lSrc[(int)u].Uuid)) return true; if(pt.LocationChanged != lOrg[(int)u].LocationChanged) return true; if(pt.LocationChanged != lSrc[(int)u].LocationChanged) return true; } return false; }
public void SharedFoldersCollectsOnlySharedFolders() { PwEntry mrY = TestHelper.GetUserRootNodeFor(m_database, 1); Assert.AreEqual("mrY", mrY.Strings.ReadSafe(KeeShare.KeeShare.TitleField)); PwObjectList <PwGroup> sharedFoldersY = m_syncManager.GetSharedFolders(mrY); Assert.AreEqual(1, sharedFoldersY.UCount); Assert.AreEqual("mrY", sharedFoldersY.GetAt(0).Name); }
private void GoogleOAuthCredentialsForm_Load(object sender, EventArgs e) { lblTitle.Text = Defs.ProductName() + " 配置"; lblVersion.Text = Defs.VersionString(); cbAccount.Items.Add("自定义 KeePass UUID"); foreach (PwEntry entry in m_accounts) { cbAccount.Items.Add(entry.Strings.GetSafe(PwDefs.UserNameField).ReadString() + " - " + entry.Strings.GetSafe(PwDefs.TitleField).ReadString()); } // preselect first account found when not configured //if (m_accidx < 0 && m_accounts.UCount > 0) // m_accidx = 0; cbAccount.SelectedIndex = m_accidx + 1; if (m_accidx >= 0) { PwEntry entry = m_accounts.GetAt((uint)cbAccount.SelectedIndex - 1); txtUuid.Text = entry.Uuid.ToHexString(); ProtectedString pstr = entry.Strings.Get(Defs.ConfigClientId); if (pstr != null) { txtClientId.Text = pstr.ReadString(); } pstr = entry.Strings.Get(Defs.ConfigClientSecret); if (pstr != null) { txtClientSecret.Text = pstr.ReadString(); } } txtUuid.Enabled = m_accidx < 0; chkOAuth.Checked = !String.IsNullOrEmpty(txtClientId.Text) || !String.IsNullOrEmpty(txtClientSecret.Text); txtClientId.Enabled = chkOAuth.Checked; txtClientSecret.Enabled = chkOAuth.Checked; cbAutoSync.SelectedIndex = (int)m_autoSync; }
internal static uint FindLocationChangedPivot<T>(PwObjectList<T> vItems, KeyValuePair<uint, uint> kvpRange, PwObjectPool ppOrgStructure, PwObjectPool ppSrcStructure, Queue<PwUuid> qBefore, Queue<PwUuid> qAfter, bool bEntries) where T : class, IStructureItem, IDeepClonable<T> { uint uPosMax = kvpRange.Key; DateTime dtMax = DateTime.MinValue; List<IStructureItem> vNeighborSrc = null; for(uint u = kvpRange.Key; u <= kvpRange.Value; ++u) { T pt = vItems.GetAt(u); // IStructureItem ptOrg = pgOrgStructure.FindObject(pt.Uuid, true, bEntries); IStructureItem ptOrg = ppOrgStructure.Get(pt.Uuid); if((ptOrg != null) && (ptOrg.LocationChanged > dtMax)) { uPosMax = u; dtMax = ptOrg.LocationChanged; // No 'continue' vNeighborSrc = ptOrg.ParentGroup.GetObjects(false, bEntries); } // IStructureItem ptSrc = pgSrcStructure.FindObject(pt.Uuid, true, bEntries); IStructureItem ptSrc = ppSrcStructure.Get(pt.Uuid); if((ptSrc != null) && (ptSrc.LocationChanged > dtMax)) { uPosMax = u; dtMax = ptSrc.LocationChanged; // No 'continue' vNeighborSrc = ptSrc.ParentGroup.GetObjects(false, bEntries); } } GetNeighborItems(vNeighborSrc, vItems.GetAt(uPosMax).Uuid, qBefore, qAfter); return uPosMax; }
private void SetGrouping(AceListGrouping lgPrimary) { Debug.Assert(((int)lgPrimary & ~(int)AceListGrouping.Primary) == 0); if ((int)lgPrimary == (Program.Config.MainWindow.ListGrouping & (int)AceListGrouping.Primary)) { return; } Program.Config.MainWindow.ListGrouping &= ~(int)AceListGrouping.Primary; Program.Config.MainWindow.ListGrouping |= (int)lgPrimary; Debug.Assert((Program.Config.MainWindow.ListGrouping & (int)AceListGrouping.Primary) == (int)lgPrimary); UpdateUI(); if (m_mf == null) { Debug.Assert(false); return; } PwDatabase pd = m_mf.ActiveDatabase; PwGroup pg = m_mf.GetCurrentEntries(); if ((pd == null) || !pd.IsOpen || (pg == null)) { return; // No assert } PwObjectList <PwEntry> pwl = pg.GetEntries(true); if ((pwl.UCount > 0) && EntryUtil.EntriesHaveSameParent(pwl)) { m_mf.UpdateUI(false, null, true, pwl.GetAt(0).ParentGroup, true, null, false); } else { EntryUtil.ReorderEntriesAsInDatabase(pwl, pd); // Requires open DB pg = new PwGroup(true, true); pg.IsVirtual = true; foreach (PwEntry pe in pwl) { pg.AddEntry(pe, false); } m_mf.UpdateUI(false, null, false, null, true, pg, false); } }
/// <summary> /// Restore an entry snapshot from backups. /// </summary> /// <param name="uBackupIndex">Index of the backup item, to which /// should be reverted.</param> public void RestoreFromBackup(uint uBackupIndex) { Debug.Assert(uBackupIndex < m_listHistory.UCount); if (uBackupIndex >= m_listHistory.UCount) { throw new ArgumentOutOfRangeException("uBackupIndex"); } PwEntry pe = m_listHistory.GetAt(uBackupIndex); Debug.Assert(pe != null); if (pe == null) { throw new InvalidOperationException(); } CreateBackup(); AssignProperties(pe, false, false); }
private Changes EnsureMatchingNamingAndIcons(PwEntry userNode, PwGroup userHome, PwGroup usersGroup) { string userName = userNode.Strings.ReadSafe(KeeShare.TitleField); //we are located in our home => check for new names.. and icons if (userNode.ParentGroup.Name == userNode.Strings.ReadSafe(KeeShare.TitleField) && userNode.IconId == userNode.ParentGroup.IconId) { return(Changes.None); } if (userNode.LastModificationTime.Ticks >= userNode.ParentGroup.LastModificationTime.Ticks) { //if last change was in the rootNode the group has to become the new name PwObjectList <PwEntry> history = userNode.History; Changes changeFlags = Changes.None; string lastName = null; if (history.UCount > 0) { lastName = history.GetAt(history.UCount - 1u).Strings.ReadSafe(KeeShare.TitleField); } if (lastName != userName && lastName == userNode.ParentGroup.Name) { userNode.ParentGroup.Name = userName; changeFlags |= Changes.GroupChanged; } if (userNode.IconId != userNode.ParentGroup.IconId) { userNode.ParentGroup.IconId = userNode.IconId; changeFlags |= Changes.GroupChanged; } return(changeFlags); } //otherwise the name of the group was the actual name userName = userNode.ParentGroup.Name; userNode.CreateBackup(m_database); userNode.Strings.Set(KeeShare.TitleField, new ProtectedString(false, userName)); //icons should also be the same! userNode.IconId = userNode.ParentGroup.IconId; userNode.Touch(true, false); return(Changes.GroupChanged); }
public static bool EntriesHaveSameParent(PwObjectList <PwEntry> v) { if (v == null) { Debug.Assert(false); return(true); } if (v.UCount == 0) { return(true); } PwGroup pg = v.GetAt(0).ParentGroup; foreach (PwEntry pe in v) { if (pe.ParentGroup != pg) { return(false); } } return(true); }
/// <summary> /// Find active configured Google Accounts /// Should only return one account /// </summary> private PwObjectList <PwEntry> FindActiveAccounts() { if (!m_host.Database.IsOpen) { return(null); } PwObjectList <PwEntry> accounts = new PwObjectList <PwEntry>(); SearchParameters sp = new SearchParameters(); sp.SearchString = Defs.ConfigActiveAccountTrue; sp.ComparisonMode = StringComparison.Ordinal; sp.RespectEntrySearchingDisabled = false; sp.SearchInGroupNames = false; sp.SearchInNotes = false; sp.SearchInOther = true; sp.SearchInPasswords = false; sp.SearchInTags = false; sp.SearchInTitles = false; sp.SearchInUrls = false; sp.SearchInUserNames = false; sp.SearchInUuids = false; m_host.Database.RootGroup.SearchEntries(sp, accounts); for (int idx = 0; idx < accounts.UCount; idx++) { PwEntry entry = accounts.GetAt((uint)idx); if (!(entry.Strings.Exists(Defs.ConfigActiveAccount) && entry.Strings.Get(Defs.ConfigActiveAccount).ReadString().Equals(Defs.ConfigActiveAccountTrue))) { accounts.RemoveAt((uint)idx--); } } return(accounts); }
public PwEntry Get(string text) { var unlocker = new Unlocker { Host = Host }; unlocker.Unlock(); var p = new SearchParameters { SearchInTitles = true, SearchString = text }; var list = new PwObjectList <PwEntry>(); Host.Database.RootGroup.SearchEntries(p, list); var e = list.GetAt(0); // TODO(djherbis): might throw var title = e.Strings.ReadSafe(PwDefs.TitleField); ShowBalloonNotification($"Entry {title} was read."); return(e); }
public static PwEntry FindRefTarget(string strFullRef, SprContext ctx, out char chScan, out char chWanted) { chScan = char.MinValue; chWanted = char.MinValue; if (strFullRef == null) { Debug.Assert(false); return(null); } if (!strFullRef.StartsWith(StrRefStart, SprEngine.ScMethod) || !strFullRef.EndsWith(StrRefEnd, SprEngine.ScMethod)) { return(null); } if ((ctx == null) || (ctx.Database == null)) { Debug.Assert(false); return(null); } string strRef = strFullRef.Substring(StrRefStart.Length, strFullRef.Length - StrRefStart.Length - StrRefEnd.Length); if (strRef.Length <= 4) { return(null); } if (strRef[1] != '@') { return(null); } if (strRef[3] != ':') { return(null); } chScan = char.ToUpper(strRef[2]); chWanted = char.ToUpper(strRef[0]); SearchParameters sp = SearchParameters.None; sp.SearchString = strRef.Substring(4); sp.RespectEntrySearchingDisabled = false; if (chScan == 'T') { sp.SearchInTitles = true; } else if (chScan == 'U') { sp.SearchInUserNames = true; } else if (chScan == 'A') { sp.SearchInUrls = true; } else if (chScan == 'P') { sp.SearchInPasswords = true; } else if (chScan == 'N') { sp.SearchInNotes = true; } else if (chScan == 'I') { sp.SearchInUuids = true; } else if (chScan == 'O') { sp.SearchInOther = true; } else { return(null); } PwObjectList <PwEntry> lFound = new PwObjectList <PwEntry>(); ctx.Database.RootGroup.SearchEntries(sp, lFound); return((lFound.UCount > 0) ? lFound.GetAt(0) : null); }
private static string FillRefPlaceholders(string strSeq, PwDatabase pwDatabase, SprContentFlags cf, uint uRecursionLevel, SprRefsCache vRefsCache) { if(pwDatabase == null) return strSeq; string str = strSeq; const string strStart = @"{REF:"; const string strEnd = @"}"; int nOffset = 0; for(int iLoop = 0; iLoop < 20; ++iLoop) { str = SprEngine.FillRefsUsingCache(str, vRefsCache); int nStart = str.IndexOf(strStart, nOffset, SprEngine.ScMethod); if(nStart < 0) break; int nEnd = str.IndexOf(strEnd, nStart, SprEngine.ScMethod); if(nEnd < 0) break; string strFullRef = str.Substring(nStart, nEnd - nStart + 1); string strRef = str.Substring(nStart + strStart.Length, nEnd - nStart - strStart.Length); if(strRef.Length <= 4) { nOffset = nStart + 1; continue; } if(strRef[1] != '@') { nOffset = nStart + 1; continue; } if(strRef[3] != ':') { nOffset = nStart + 1; continue; } char chScan = char.ToUpper(strRef[2]); char chWanted = char.ToUpper(strRef[0]); SearchParameters sp = SearchParameters.None; sp.SearchString = strRef.Substring(4); if(chScan == 'T') sp.SearchInTitles = true; else if(chScan == 'U') sp.SearchInUserNames = true; else if(chScan == 'A') sp.SearchInUrls = true; else if(chScan == 'P') sp.SearchInPasswords = true; else if(chScan == 'N') sp.SearchInNotes = true; else if(chScan == 'I') sp.SearchInUuids = true; else if(chScan == 'O') sp.SearchInOther = true; else { nOffset = nStart + 1; continue; } PwObjectList<PwEntry> lFound = new PwObjectList<PwEntry>(); pwDatabase.RootGroup.SearchEntries(sp, lFound, true); if(lFound.UCount > 0) { PwEntry peFound = lFound.GetAt(0); string strInsData; if(chWanted == 'T') strInsData = peFound.Strings.ReadSafe(PwDefs.TitleField); else if(chWanted == 'U') strInsData = peFound.Strings.ReadSafe(PwDefs.UserNameField); else if(chWanted == 'A') strInsData = peFound.Strings.ReadSafe(PwDefs.UrlField); else if(chWanted == 'P') strInsData = peFound.Strings.ReadSafe(PwDefs.PasswordField); else if(chWanted == 'N') strInsData = peFound.Strings.ReadSafe(PwDefs.NotesField); else if(chWanted == 'I') strInsData = peFound.Uuid.ToHexString(); else { nOffset = nStart + 1; continue; } string strInnerContent = SprEngine.CompileInternal(strInsData, peFound, pwDatabase, null, uRecursionLevel + 1, vRefsCache); strInnerContent = SprEngine.TransformContent(strInnerContent, cf); // str = str.Substring(0, nStart) + strInnerContent + str.Substring(nEnd + 1); SprEngine.AddRefToCache(strFullRef, strInnerContent, vRefsCache); str = SprEngine.FillRefsUsingCache(str, vRefsCache); } else { nOffset = nStart + 1; continue; } } return str; }
public static bool PerformGlobal(List<PwDatabase> vSources, ImageList ilIcons) { Debug.Assert(vSources != null); if(vSources == null) return false; IntPtr hWnd; string strWindow; try { hWnd = NativeMethods.GetForegroundWindow(); strWindow = NativeMethods.GetWindowText(hWnd); } catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } if((strWindow == null) || (strWindow.Length == 0)) return false; PwObjectList<PwEntry> m_vList = new PwObjectList<PwEntry>(); DateTime dtNow = DateTime.Now; EntryHandler eh = delegate(PwEntry pe) { // Ignore expired entries if(pe.Expires && (pe.ExpiryTime < dtNow)) return true; if(GetSequenceForWindow(pe, strWindow, true) != null) m_vList.Add(pe); return true; }; foreach(PwDatabase pwSource in vSources) { if(pwSource.IsOpen == false) continue; pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } if(m_vList.UCount == 1) AutoType.PerformInternal(m_vList.GetAt(0), strWindow); else if(m_vList.UCount > 1) { EntryListForm elf = new EntryListForm(); elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort, KPRes.AutoTypeEntrySelectionDescLong, Properties.Resources.B48x48_KGPG_Key2, ilIcons, m_vList); elf.EnsureForeground = true; if(elf.ShowDialog() == DialogResult.OK) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch(Exception) { Debug.Assert(false); } if(elf.SelectedEntry != null) AutoType.PerformInternal(elf.SelectedEntry, strWindow); } } return true; }
public bool EqualsEntry(PwEntry pe, PwCompareOptions pwOpt, MemProtCmpMode mpCmpStr) { if (pe == null) { Debug.Assert(false); return(false); } bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) != PwCompareOptions.None); bool bIgnoreLastAccess = ((pwOpt & PwCompareOptions.IgnoreLastAccess) != PwCompareOptions.None); bool bIgnoreLastMod = ((pwOpt & PwCompareOptions.IgnoreLastMod) != PwCompareOptions.None); if (!m_uuid.Equals(pe.m_uuid)) { return(false); } if ((pwOpt & PwCompareOptions.IgnoreParentGroup) == PwCompareOptions.None) { if (m_pParentGroup != pe.m_pParentGroup) { return(false); } if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod)) { return(false); } } if (!m_listStrings.EqualsDictionary(pe.m_listStrings, pwOpt, mpCmpStr)) { return(false); } if (!m_listBinaries.EqualsDictionary(pe.m_listBinaries)) { return(false); } if (!m_listAutoType.Equals(pe.m_listAutoType)) { return(false); } if ((pwOpt & PwCompareOptions.IgnoreHistory) == PwCompareOptions.None) { bool bIgnoreLastBackup = ((pwOpt & PwCompareOptions.IgnoreLastBackup) != PwCompareOptions.None); if (!bIgnoreLastBackup && (m_listHistory.UCount != pe.m_listHistory.UCount)) { return(false); } if (bIgnoreLastBackup && (m_listHistory.UCount == 0)) { Debug.Assert(false); return(false); } if (bIgnoreLastBackup && ((m_listHistory.UCount - 1) != pe.m_listHistory.UCount)) { return(false); } PwCompareOptions cmpSub = PwCompareOptions.IgnoreParentGroup; if (bNeEqStd) { cmpSub |= PwCompareOptions.NullEmptyEquivStd; } if (bIgnoreLastMod) { cmpSub |= PwCompareOptions.IgnoreLastMod; } if (bIgnoreLastAccess) { cmpSub |= PwCompareOptions.IgnoreLastAccess; } for (uint uHist = 0; uHist < pe.m_listHistory.UCount; ++uHist) { if (!m_listHistory.GetAt(uHist).EqualsEntry(pe.m_listHistory.GetAt( uHist), cmpSub, MemProtCmpMode.None)) { return(false); } } } if (m_pwIcon != pe.m_pwIcon) { return(false); } if (!m_pwCustomIconID.Equals(pe.m_pwCustomIconID)) { return(false); } if (m_clrForeground != pe.m_clrForeground) { return(false); } if (m_clrBackground != pe.m_clrBackground) { return(false); } if (m_tCreation != pe.m_tCreation) { return(false); } if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod)) { return(false); } if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess)) { return(false); } if (m_tExpire != pe.m_tExpire) { return(false); } if (m_bExpires != pe.m_bExpires) { return(false); } if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount)) { return(false); } if (m_strOverrideUrl != pe.m_strOverrideUrl) { return(false); } if (m_vTags.Count != pe.m_vTags.Count) { return(false); } for (int iTag = 0; iTag < m_vTags.Count; ++iTag) { if (m_vTags[iTag] != pe.m_vTags[iTag]) { return(false); } } return(true); }
public bool EqualsEntry(PwEntry pe, bool bIgnoreParentGroup, bool bIgnoreLastMod, bool bIgnoreLastAccess, bool bIgnoreHistory, bool bIgnoreThisLastBackup) { if (pe == null) { Debug.Assert(false); return(false); } if (!m_uuid.EqualsValue(pe.m_uuid)) { return(false); } if (!bIgnoreParentGroup) { if (m_pParentGroup != pe.m_pParentGroup) { return(false); } if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod)) { return(false); } } if (!m_listStrings.EqualsDictionary(pe.m_listStrings)) { return(false); } if (!m_listBinaries.EqualsDictionary(pe.m_listBinaries)) { return(false); } if (!m_listAutoType.EqualsConfig(pe.m_listAutoType)) { return(false); } if (!bIgnoreHistory) { if (!bIgnoreThisLastBackup && (m_listHistory.UCount != pe.m_listHistory.UCount)) { return(false); } if (bIgnoreThisLastBackup && (m_listHistory.UCount == 0)) { Debug.Assert(false); return(false); } if (bIgnoreThisLastBackup && ((m_listHistory.UCount - 1) != pe.m_listHistory.UCount)) { return(false); } for (uint uHist = 0; uHist < pe.m_listHistory.UCount; ++uHist) { if (!m_listHistory.GetAt(uHist).EqualsEntry(pe.m_listHistory.GetAt( uHist), true, bIgnoreLastMod, bIgnoreLastAccess, false, false)) { return(false); } } } if (m_pwIcon != pe.m_pwIcon) { return(false); } if (!m_pwCustomIconID.EqualsValue(pe.m_pwCustomIconID)) { return(false); } if (m_clrForeground != pe.m_clrForeground) { return(false); } if (m_clrBackground != pe.m_clrBackground) { return(false); } if (m_tCreation != pe.m_tCreation) { return(false); } if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod)) { return(false); } if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess)) { return(false); } if (m_tExpire != pe.m_tExpire) { return(false); } if (m_bExpires != pe.m_bExpires) { return(false); } if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount)) { return(false); } if (m_strOverrideUrl != pe.m_strOverrideUrl) { return(false); } return(true); }
internal void ReorderObjectList<T>(PwObjectList<T> vItems, PwObjectPool ppOrgStructure, PwObjectPool ppSrcStructure, bool bEntries) where T : class, IStructureItem, IDeepClonable<T> { if(!ObjectListRequiresReorder<T>(vItems, ppOrgStructure, ppSrcStructure, bEntries)) return; #if DEBUG PwObjectList<T> vOrgListItems = vItems.CloneShallow(); #endif Queue<KeyValuePair<uint, uint>> qToDo = new Queue<KeyValuePair<uint, uint>>(); qToDo.Enqueue(new KeyValuePair<uint, uint>(0, vItems.UCount - 1)); while(qToDo.Count > 0) { if((m_slStatus != null) && !m_slStatus.ContinueWork()) break; KeyValuePair<uint, uint> kvp = qToDo.Dequeue(); if(kvp.Value <= kvp.Key) { Debug.Assert(false); continue; } Queue<PwUuid> qRelBefore = new Queue<PwUuid>(); Queue<PwUuid> qRelAfter = new Queue<PwUuid>(); uint uPivot = FindLocationChangedPivot<T>(vItems, kvp, ppOrgStructure, ppSrcStructure, qRelBefore, qRelAfter, bEntries); T ptPivot = vItems.GetAt(uPivot); List<T> vToSort = vItems.GetRange(kvp.Key, kvp.Value); Queue<T> qBefore = new Queue<T>(); Queue<T> qAfter = new Queue<T>(); bool bBefore = true; foreach(T pt in vToSort) { if(pt == ptPivot) { bBefore = false; continue; } bool bAdded = false; foreach(PwUuid puBefore in qRelBefore) { if(puBefore.EqualsValue(pt.Uuid)) { qBefore.Enqueue(pt); bAdded = true; break; } } if(bAdded) continue; foreach(PwUuid puAfter in qRelAfter) { if(puAfter.EqualsValue(pt.Uuid)) { qAfter.Enqueue(pt); bAdded = true; break; } } if(bAdded) continue; if(bBefore) qBefore.Enqueue(pt); else qAfter.Enqueue(pt); } Debug.Assert(bBefore == false); uint uPos = kvp.Key; while(qBefore.Count > 0) vItems.SetAt(uPos++, qBefore.Dequeue()); vItems.SetAt(uPos++, ptPivot); while(qAfter.Count > 0) vItems.SetAt(uPos++, qAfter.Dequeue()); Debug.Assert(uPos == (kvp.Value + 1)); int iNewPivot = vItems.IndexOf(ptPivot); if((iNewPivot < (int)kvp.Key) || (iNewPivot > (int)kvp.Value)) { Debug.Assert(false); continue; } if((iNewPivot - 1) > (int)kvp.Key) qToDo.Enqueue(new KeyValuePair<uint, uint>(kvp.Key, (uint)(iNewPivot - 1))); if((iNewPivot + 1) < (int)kvp.Value) qToDo.Enqueue(new KeyValuePair<uint, uint>((uint)(iNewPivot + 1), kvp.Value)); } #if DEBUG foreach(T ptItem in vOrgListItems) { Debug.Assert(vItems.IndexOf(ptItem) >= 0); } #endif }
private PwGroup SrxpFilterCloneSelf(SearchParameters sp) { PwGroup pgNew = CloneDeep(); pgNew.ParentGroup = null; DateTime dtNow = DateTime.UtcNow; GroupHandler gh = delegate(PwGroup pg) { if (!sp.SearchInGroupNames) { pg.Name = string.Empty; } if (!sp.SearchInTags) { pg.Tags.Clear(); } PwObjectList <PwEntry> l = pg.Entries; for (int i = (int)l.UCount - 1; i >= 0; --i) { PwEntry pe = l.GetAt((uint)i); if (sp.ExcludeExpired && pe.Expires && (pe.ExpiryTime <= dtNow)) { } else if (sp.RespectEntrySearchingDisabled && !pe.GetSearchingEnabled()) { } else { continue; } l.RemoveAt((uint)i); } return(true); }; EntryHandler eh = delegate(PwEntry pe) { SrxpClearString(!sp.SearchInTitles, pe, PwDefs.TitleField); SrxpClearString(!sp.SearchInUserNames, pe, PwDefs.UserNameField); SrxpClearString(!sp.SearchInPasswords, pe, PwDefs.PasswordField); SrxpClearString(!sp.SearchInUrls, pe, PwDefs.UrlField); SrxpClearString(!sp.SearchInNotes, pe, PwDefs.NotesField); if (!sp.SearchInOther) { List <string> lKeys = pe.Strings.GetKeys(); foreach (string strKey in lKeys) { SrxpClearString(!PwDefs.IsStandardField(strKey), pe, strKey); } } if (!sp.SearchInTags) { pe.Tags.Clear(); } if (!sp.SearchInHistory) { pe.History.Clear(); } return(true); }; gh(pgNew); pgNew.TraverseTree(TraversalMethod.PreOrder, gh, eh); return(pgNew); }
private void OnTrayOpening(object sender, EventArgs e) { PluginDebug.AddInfo("Tray setup: Start", 0); m_TrayMenu.DropDownItems.Clear(); List <PwDatabase> lDB = m_host.MainWindow.DocumentManager.GetOpenDatabases(); SearchParameters sp = new SearchParameters(); sp.ExcludeExpired = !Program.Config.Integration.AutoTypeExpiredCanMatch; //exclude expired entries only if they can not match sp.SearchInStringNames = true; Dictionary <string, PwObjectList <PwEntry> > dEntries = new Dictionary <string, PwObjectList <PwEntry> >(); foreach (PwDatabase db in lDB) { string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path); if (!string.IsNullOrEmpty(db.Name)) { dbName = db.Name + " (" + dbName + ")"; } PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>(); if (Config.UseDBForOTPSeeds(db)) { sp.SearchString = OTPDAO.OTPHandler_DB.DBNAME; } else { sp.SearchString = Config.OTPFIELD; // Config.SEED + " " + Config.SETTINGS; } db.RootGroup.SearchEntries(sp, entries); PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.UCount.ToString()); if ((entries == null) || (entries.UCount == 0)) { continue; } //Ignore deleted entries PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null; if (pgRecycle != null) { for (int i = (int)entries.UCount - 1; i >= 0; i--) { PwEntry pe = entries.GetAt((uint)i); if (pe.IsContainedIn(pgRecycle)) { entries.Remove(pe); } } } entries.Sort(SortEntries); dEntries.Add(dbName, entries); } foreach (var kvp in dEntries) { ToolStripMenuItem parent = null; //If entries of only one DB are found don't include the DB as additional menu level if (dEntries.Count == 1) { parent = m_TrayMenu; } else { parent = new ToolStripMenuItem(kvp.Key); m_TrayMenu.DropDownItems.Add(parent); } foreach (PwEntry pe in kvp.Value) { ToolStripMenuItem entry = new ToolStripMenuItem(); string[] text = GetTrayText(pe); PluginDebug.AddInfo("Tray setup: Add entry", 0, "Uuid: " + text[2]); // Do NOT add username and entry title to debugfile if (text[0] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(string.Format(PluginTranslate.User, text[1])); } else if (text[1] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(text[0]); } else { entry.Text = StrUtil.EncodeMenuText(text[0] + " (" + text[1] + ")"); } entry.Name = "KPOTP_" + pe.Uuid.ToString(); entry.Click += OnOTPTray; entry.Tag = pe; parent.DropDownItems.Add(entry); } } m_TrayMenu.Enabled = dEntries.Count > 0; m_TrayMenu.Text = m_TrayMenu.Enabled ? PluginTranslate.OTPCopyTrayEntries : PluginTranslate.OTPCopyTrayNoEntries; }
private static string FillRefPlaceholders(string strSeq, PwDatabase pwDatabase, SprContentFlags cf, uint uRecursionLevel, SprRefsCache vRefsCache) { if (pwDatabase == null) { return(strSeq); } string str = strSeq; const string strStart = @"{REF:"; const string strEnd = @"}"; int nOffset = 0; for (int iLoop = 0; iLoop < 20; ++iLoop) { str = SprEngine.FillRefsUsingCache(str, vRefsCache); int nStart = str.IndexOf(strStart, nOffset, SprEngine.ScMethod); if (nStart < 0) { break; } int nEnd = str.IndexOf(strEnd, nStart, SprEngine.ScMethod); if (nEnd < 0) { break; } string strFullRef = str.Substring(nStart, nEnd - nStart + 1); string strRef = str.Substring(nStart + strStart.Length, nEnd - nStart - strStart.Length); if (strRef.Length <= 4) { nOffset = nStart + 1; continue; } if (strRef[1] != '@') { nOffset = nStart + 1; continue; } if (strRef[3] != ':') { nOffset = nStart + 1; continue; } char chScan = char.ToUpper(strRef[2]); char chWanted = char.ToUpper(strRef[0]); SearchParameters sp = SearchParameters.None; sp.SearchString = strRef.Substring(4); if (chScan == 'T') { sp.SearchInTitles = true; } else if (chScan == 'U') { sp.SearchInUserNames = true; } else if (chScan == 'A') { sp.SearchInUrls = true; } else if (chScan == 'P') { sp.SearchInPasswords = true; } else if (chScan == 'N') { sp.SearchInNotes = true; } else if (chScan == 'I') { sp.SearchInUuids = true; } else if (chScan == 'O') { sp.SearchInOther = true; } else { nOffset = nStart + 1; continue; } PwObjectList <PwEntry> lFound = new PwObjectList <PwEntry>(); pwDatabase.RootGroup.SearchEntries(sp, lFound, true); if (lFound.UCount > 0) { PwEntry peFound = lFound.GetAt(0); string strInsData; if (chWanted == 'T') { strInsData = peFound.Strings.ReadSafe(PwDefs.TitleField); } else if (chWanted == 'U') { strInsData = peFound.Strings.ReadSafe(PwDefs.UserNameField); } else if (chWanted == 'A') { strInsData = peFound.Strings.ReadSafe(PwDefs.UrlField); } else if (chWanted == 'P') { strInsData = peFound.Strings.ReadSafe(PwDefs.PasswordField); } else if (chWanted == 'N') { strInsData = peFound.Strings.ReadSafe(PwDefs.NotesField); } else if (chWanted == 'I') { strInsData = peFound.Uuid.ToHexString(); } else { nOffset = nStart + 1; continue; } string strInnerContent = SprEngine.CompileInternal(strInsData, peFound, pwDatabase, null, uRecursionLevel + 1, vRefsCache); strInnerContent = SprEngine.TransformContent(strInnerContent, cf); // str = str.Substring(0, nStart) + strInnerContent + str.Substring(nEnd + 1); SprEngine.AddRefToCache(strFullRef, strInnerContent, vRefsCache); str = SprEngine.FillRefsUsingCache(str, vRefsCache); } else { nOffset = nStart + 1; continue; } } return(str); }
public bool EqualsEntry(PwEntry pe, PwCompareOptions pwOpt, MemProtCmpMode mpCmpStr) { if (pe == null) { Debug.Assert(false); return(false); } bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) != PwCompareOptions.None); bool bIgnoreLastAccess = ((pwOpt & PwCompareOptions.IgnoreLastAccess) != PwCompareOptions.None); bool bIgnoreLastMod = ((pwOpt & PwCompareOptions.IgnoreLastMod) != PwCompareOptions.None); if (!m_uuid.Equals(pe.m_uuid)) { return(false); } if ((pwOpt & PwCompareOptions.IgnoreParentGroup) == PwCompareOptions.None) { if (m_pParentGroup != pe.m_pParentGroup) { return(false); } if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod)) { return(false); } if (!m_puPrevParentGroup.Equals(pe.m_puPrevParentGroup)) { return(false); } } if (!m_dStrings.EqualsDictionary(pe.m_dStrings, pwOpt, mpCmpStr)) { return(false); } if (!m_dBinaries.EqualsDictionary(pe.m_dBinaries)) { return(false); } if (!m_cfgAutoType.Equals(pe.m_cfgAutoType)) { return(false); } if ((pwOpt & PwCompareOptions.IgnoreHistory) == PwCompareOptions.None) { bool bIgnoreLastBackup = ((pwOpt & PwCompareOptions.IgnoreLastBackup) != PwCompareOptions.None); if (!bIgnoreLastBackup && (m_lHistory.UCount != pe.m_lHistory.UCount)) { return(false); } if (bIgnoreLastBackup && (m_lHistory.UCount == 0)) { Debug.Assert(false); return(false); } if (bIgnoreLastBackup && ((m_lHistory.UCount - 1) != pe.m_lHistory.UCount)) { return(false); } PwCompareOptions cmpSub = PwCompareOptions.IgnoreParentGroup; if (bNeEqStd) { cmpSub |= PwCompareOptions.NullEmptyEquivStd; } if (bIgnoreLastMod) { cmpSub |= PwCompareOptions.IgnoreLastMod; } if (bIgnoreLastAccess) { cmpSub |= PwCompareOptions.IgnoreLastAccess; } for (uint uHist = 0; uHist < pe.m_lHistory.UCount; ++uHist) { if (!m_lHistory.GetAt(uHist).EqualsEntry(pe.m_lHistory.GetAt( uHist), cmpSub, MemProtCmpMode.None)) { return(false); } } } if (m_pwIcon != pe.m_pwIcon) { return(false); } if (!m_puCustomIcon.Equals(pe.m_puCustomIcon)) { return(false); } if (m_clrForeground != pe.m_clrForeground) { return(false); } if (m_clrBackground != pe.m_clrBackground) { return(false); } if (m_tCreation != pe.m_tCreation) { return(false); } if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod)) { return(false); } if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess)) { return(false); } if (m_tExpire != pe.m_tExpire) { return(false); } if (m_bExpires != pe.m_bExpires) { return(false); } if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount)) { return(false); } if (m_strOverrideUrl != pe.m_strOverrideUrl) { return(false); } if (m_bQualityCheck != pe.m_bQualityCheck) { return(false); } // The Tags property normalizes if (!MemUtil.ListsEqual <string>(this.Tags, pe.Tags)) { return(false); } if (!m_dCustomData.Equals(pe.m_dCustomData)) { return(false); } return(true); }
public static bool EntriesHaveSameParent(PwObjectList<PwEntry> v) { if(v == null) { Debug.Assert(false); return true; } if(v.UCount == 0) return true; PwGroup pg = v.GetAt(0).ParentGroup; foreach(PwEntry pe in v) { if(pe.ParentGroup != pg) return false; } return true; }
public static bool PerformGlobal(List <PwDatabase> vSources, ImageList ilIcons) { Debug.Assert(vSources != null); if (vSources == null) { return(false); } IntPtr hWnd; string strWindow; try { hWnd = NativeMethods.GetForegroundWindow(); strWindow = NativeMethods.GetWindowText(hWnd); } catch (Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } if ((strWindow == null) || (strWindow.Length == 0)) { return(false); } PwObjectList <PwEntry> m_vList = new PwObjectList <PwEntry>(); DateTime dtNow = DateTime.Now; EntryHandler eh = delegate(PwEntry pe) { // Ignore expired entries if (pe.Expires && (pe.ExpiryTime < dtNow)) { return(true); } if (GetSequenceForWindow(pe, strWindow, true) != null) { m_vList.Add(pe); } return(true); }; foreach (PwDatabase pwSource in vSources) { if (pwSource.IsOpen == false) { continue; } pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } if (m_vList.UCount == 1) { AutoType.PerformInternal(m_vList.GetAt(0), strWindow); } else if (m_vList.UCount > 1) { EntryListForm elf = new EntryListForm(); elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort, KPRes.AutoTypeEntrySelectionDescLong, Properties.Resources.B48x48_KGPG_Key2, ilIcons, m_vList); elf.EnsureForeground = true; if (elf.ShowDialog() == DialogResult.OK) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch (Exception) { Debug.Assert(false); } if (elf.SelectedEntry != null) { AutoType.PerformInternal(elf.SelectedEntry, strWindow); } } } return(true); }
public static PwEntry FindRefTarget(string strFullRef, SprContext ctx, out char chScan, out char chWanted) { chScan = char.MinValue; chWanted = char.MinValue; if(strFullRef == null) { Debug.Assert(false); return null; } if(!strFullRef.StartsWith(StrRefStart, SprEngine.ScMethod) || !strFullRef.EndsWith(StrRefEnd, SprEngine.ScMethod)) return null; if((ctx == null) || (ctx.Database == null)) { Debug.Assert(false); return null; } string strRef = strFullRef.Substring(StrRefStart.Length, strFullRef.Length - StrRefStart.Length - StrRefEnd.Length); if(strRef.Length <= 4) return null; if(strRef[1] != '@') return null; if(strRef[3] != ':') return null; chScan = char.ToUpper(strRef[2]); chWanted = char.ToUpper(strRef[0]); SearchParameters sp = SearchParameters.None; sp.SearchString = strRef.Substring(4); sp.RespectEntrySearchingDisabled = false; if(chScan == 'T') sp.SearchInTitles = true; else if(chScan == 'U') sp.SearchInUserNames = true; else if(chScan == 'A') sp.SearchInUrls = true; else if(chScan == 'P') sp.SearchInPasswords = true; else if(chScan == 'N') sp.SearchInNotes = true; else if(chScan == 'I') sp.SearchInUuids = true; else if(chScan == 'O') sp.SearchInOther = true; else return null; PwObjectList<PwEntry> lFound = new PwObjectList<PwEntry>(); ctx.Database.RootGroup.SearchEntries(sp, lFound); return ((lFound.UCount > 0) ? lFound.GetAt(0) : null); }
public static bool PerformGlobal(List<PwDatabase> vSources, ImageList ilIcons) { Debug.Assert(vSources != null); if(vSources == null) return false; if(KeePassLib.Native.NativeLib.IsUnix()) { if(!NativeMethods.TryXDoTool(true)) { MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer); return false; } } IntPtr hWnd; string strWindow; try { // hWnd = NativeMethods.GetForegroundWindowHandle(); // strWindow = NativeMethods.GetWindowText(hWnd); NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } if(string.IsNullOrEmpty(strWindow)) return false; if(!IsValidAutoTypeWindow(hWnd, true)) return false; PwObjectList<PwEntry> vList = new PwObjectList<PwEntry>(); DateTime dtNow = DateTime.Now; EntryHandler eh = delegate(PwEntry pe) { // Ignore expired entries if(pe.Expires && (pe.ExpiryTime < dtNow)) return true; if(GetSequenceForWindow(pe, strWindow, true) != null) vList.Add(pe); return true; }; foreach(PwDatabase pwSource in vSources) { if(pwSource.IsOpen == false) continue; pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } if(vList.UCount == 1) AutoType.PerformInternal(vList.GetAt(0), strWindow); else if(vList.UCount > 1) { EntryListForm elf = new EntryListForm(); elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort, KPRes.AutoTypeEntrySelectionDescLong, Properties.Resources.B48x48_KGPG_Key2, ilIcons, vList); elf.EnsureForeground = true; if(elf.ShowDialog() == DialogResult.OK) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch(Exception) { Debug.Assert(false); } if(elf.SelectedEntry != null) AutoType.PerformInternal(elf.SelectedEntry, strWindow); } UIUtil.DestroyForm(elf); } return true; }