/// <summary> /// This function creates the correct structured database which will be used /// to create the delta container. /// </summary> /// <param name="sharedFolders">All PwGroups that should be placed in the delta /// container. Usually that are the PwGroups that are shared with the specified user.</param> /// <returns>A PwDatabae that conatins the hierarchically correct structured database /// which could be used to create a delta container.</returns> public PwDatabase CreateDeltaDb(PwDatabase database, PwObjectList <PwGroup> sharedFolders) { PwDatabase deltaDB = new PwDatabase(); deltaDB.RootGroup = new PwGroup(true, true) { //Uuid = database.RootGroup.Uuid // We set the root group to the same Uuid to identify the source database (does not work for cycles with more hops) }; foreach (PwGroup group in sharedFolders) { foreach (PwEntry entry in group.Entries) { PwEntry copyEntry = null; //do we handle a normal pwentry if (entry.IsNormalPwEntry()) { //we dont want to share a PwEntry more than once! if (null != deltaDB.RootGroup.FindEntry(entry.Uuid, true)) { continue; } // check if our origParent was a normal folder or some KeeShare specific Folder ("Users" / "Groups" / "SyncGroup") if (IsKeeShareFolder(database, group)) { entry.SetParent(deltaDB.RootGroup); copyEntry = entry; } else //the entry was located in a normal PwGroup { copyEntry = database.DuplicateEntryTo(entry, deltaDB); } } //or a pwproxy if (database.IsPasswordProxy(entry)) { //we only add the rootNode to the copy, because all proxies are only information for KeeShare PwEntry entryRoot = database.GetProxyTargetFor(entry); //we dont want to share a PwEntry more than once! if (null != deltaDB.RootGroup.FindEntry(entryRoot.Uuid, true)) { continue; } copyEntry = database.DuplicateEntryTo(entryRoot, deltaDB); } if (copyEntry != null) { copyEntry.AddExportSource(database.RootGroup.Uuid.ToHexString()); } //everything else (UserProxy and UserRootNodes) we have to ignore! //Debug.Assert(!copyDB.HasDuplicateUuids()); } } return(deltaDB); }
/// <summary> /// The function checks if thelast made change has to be propageted to /// some referenced PwEntries /// </summary> /// <returns>True if the function has made changes to the database.</returns> private Changes CheckReferences() { PwEntry lastModifiedEntry = GetLastModifiedEntry(); //if there are no changes, then we have nothing to do if (lastModifiedEntry == null) { return(Changes.None); } //was it a proxy or not? Changes changeFlag = Changes.None; if (lastModifiedEntry.IsProxyNode()) { //lets update the root so we later can update all proxies PwEntry root = m_database.GetProxyTargetFor(lastModifiedEntry); //check if there are real changes! if not we are done here if (lastModifiedEntry.IsSimilarTo(root, true)) { return(Changes.None); } PwGroup parent = root.ParentGroup; root.CreateBackup(m_database); //rootNode_X should save all modifications in history parent.Entries.Remove(root); PwEntry updatedRoot = lastModifiedEntry.CloneDeep(); updatedRoot.Uuid = root.Uuid; updatedRoot.SetParent(parent); //special handling for userRootNodes because they have a homefolder if (root.IsUserRootNode()) { //maybe the oldUserName has changed to => the homefolder should have the new name also //we also want to have the same icons everywhere parent.Name = updatedRoot.GetTitle(); parent.IconId = updatedRoot.IconId; } else { updatedRoot.Strings.Remove(KeeShare.UuidLinkField); } changeFlag |= UpdateProxyInformation(updatedRoot); changeFlag |= Changes.GroupDeleted; } else { changeFlag |= UpdateProxyInformation(lastModifiedEntry); } pe_lastModedEntry = GetLastModifiedEntry(); return(changeFlag); }
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)); } } } }