public void RenamePwdProxyNodesTest() { m_treeManager.Initialize(m_database); PwEntry pwd1 = new PwEntry(true, true); pwd1.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "pwd1")); m_database.RootGroup.AddEntry(pwd1, true); pwd1.Touch(true); DateTime lastTouch = pwd1.LastModificationTime; PwEntry pwdProxy = pwd1.CreateProxyNode(); m_database.GetGroupsGroup().AddEntry(pwdProxy, true); pwdProxy.LastModificationTime = lastTouch.AddTicks(10); m_treeManager.CorrectStructure(); Assert.AreEqual(2, NumberOfEntriesIn(m_database)); string pwdId = m_database.RootGroup.Entries.GetAt(0).Uuid.ToHexString(); pwdProxy = m_database.GetGroupsGroup().Entries.GetAt(0); Assert.AreEqual(pwdId, pwdProxy.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField)); pwdProxy.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "new Title")); pwdProxy.LastModificationTime = lastTouch.AddTicks(23); m_treeManager.CorrectStructure(); Assert.AreEqual("new Title", m_database.RootGroup.Entries.GetAt(0).Strings.ReadSafe(KeeShare.KeeShare.TitleField)); }
/// <summary> /// initializes the Usermanager. /// for now it only creates the relevant PwGroups if they are not existing yet. /// </summary> public void Initialize(PwDatabase database) { Debug.Assert(null != database); m_database = database; //====================== autocreating the neccassary groups ================================== m_database.GetUsersGroup(); m_database.GetGroupsGroup(); }
/// <summary> /// The functions tests if a group is a special group which was created for /// PwdSahre only. /// </summary> /// <param name="group">The group we want to test.</param> /// <returns>True if the specified group was a special KeeShare group.</returns> private bool IsKeeShareFolder(PwDatabase database, PwGroup group) { Debug.Assert(group != null); //only three groups are interesting for us: "Users" / "Groups" / "SyncGroup" return(group.ParentGroup != null && (group.IsInsideParent(database.GetUsersGroup()) || group.IsInsideParent(database.GetGroupsGroup()) || group.IsInsideParent(database.GetSyncGroup()))); }
private void ExportUsingGroupsOfUser(PwDatabase database, PwGroup selectedGroup) { //if the menu was called from a GroupsGroup we try to find all users in that group and then export //the pwds for all of them. PwGroup groupsGroup = database.GetGroupsGroup(); if (selectedGroup == groupsGroup || selectedGroup.IsInsideParent(groupsGroup)) { foreach (PwEntry entry in selectedGroup.GetEntries(true)) { if (database.IsUserProxy(entry)) { Export(database, database.GetProxyTargetFor(entry)); } } } }
/// <summary> /// Checks if a PwEntry was copied into the "Users"- or "Groups"-folder. /// If so, we should brand it as a proxy /// </summary> /// <returns>True if there are made any changes to the dataStructure</returns> private Changes ConvertCopiedPasswordsToPasswordProxies() { Changes changeFlag = Changes.None; var usersGroup = m_database.GetUsersGroup(); var userGroupsGroup = m_database.GetGroupsGroup(); var potentialProxyNodes = (usersGroup.GetEntries(true).Union(userGroupsGroup.GetEntries(true))) .Where(e => !e.IsUserNode() && !e.IsProxyNode()) .ToDictionary(e => e.Uuid); var potentialProxyRoots = m_database.RootGroup.GetEntries(true) .Where(e => !e.IsUserNode() && !e.IsProxyNode() && !e.IsInsideParent(usersGroup) && !e.IsInsideParent(userGroupsGroup) && !potentialProxyNodes.ContainsKey(e.Uuid)) .ToList(); //allPws shouldn't hold entries from inside of the usersGroup because we want //to use them as pwdRoots and in that case we would create a inconsistent state foreach (var potentialProxy in potentialProxyNodes.Values) { PwEntry potentialRoot = null; //find the most actual root in the possilbe rootNodes and use the Uuid from that root foreach (PwEntry entry in potentialProxyRoots) { if (potentialProxy.IsSimilarTo(entry, false) && (potentialRoot == null || potentialRoot.LastModificationTime.Ticks > entry.LastModificationTime.Ticks)) { potentialRoot = entry; } } if (potentialRoot != null) { potentialProxy.MakeToProxyOf(potentialRoot); potentialProxy.Touch(true); changeFlag |= Changes.EntryConverted; } } return(changeFlag); }