/// <summary> /// Read all job settings from an entry. /// </summary> /// <param name="settingsEntry">The entry to read the settings from.</param> /// <param name="sourceDb">A database to resolve refs in the password field.</param> /// <returns>A settings object containing all the settings for this job.</returns> public static Settings Parse(PwEntry settingsEntry, PwDatabase sourceDb = null) { return(new Settings() { Password = FieldHelper.GetFieldWRef(settingsEntry, sourceDb, PwDefs.PasswordField), TargetFilePath = FieldHelper.GetFieldWRefUnprotected(settingsEntry, sourceDb, "SubsetExport_TargetFilePath"), KeyFilePath = FieldHelper.GetFieldWRefUnprotected(settingsEntry, sourceDb, "SubsetExport_KeyFilePath"), Tag = settingsEntry.Strings.ReadSafe("SubsetExport_Tag"), KeyTransformationRounds = GetUlongValue("SubsetExport_KeyTransformationRounds", settingsEntry), RootGroupName = settingsEntry.Strings.ReadSafe("SubsetExport_RootGroupName"), Group = settingsEntry.Strings.ReadSafe("SubsetExport_Group"), FlatExport = settingsEntry.Strings.ReadSafe("SubsetExport_FlatExport").ToLower().Trim() == "true", OverrideTargetDatabase = settingsEntry.Strings.ReadSafe("SubsetExport_OverrideTargetDatabase").ToLower().Trim() != "false", OverrideEntryOnlyNewer = settingsEntry.Strings.ReadSafe("SubsetExport_OverrideEntryOnlyNewer").ToLower().Trim() == "true", OverrideEntireGroup = settingsEntry.Strings.ReadSafe("SubsetExport_OverrideEntireGroup").ToLower().Trim() == "true", Argon2ParamIterations = GetUlongValue("SubsetExport_Argon2ParamIterations", settingsEntry), Argon2ParamMemory = GetUlongValue("SubsetExport_Argon2ParamMemory", settingsEntry), Argon2ParamParallelism = GetUIntValue("SubsetExport_Argon2ParamParallelism", settingsEntry), Disabled = (settingsEntry.Expires && DateTime.Now > settingsEntry.ExpiryTime), ExportUserAndPassOnly = settingsEntry.Strings.ReadSafe("SubsetExport_ExportUserAndPassOnly").ToLower().Trim() == "true" }); }
private static void CopyEntriesAndGroups(PwDatabase sourceDb, Settings settings, PwObjectList <PwEntry> entries, PwDatabase targetDatabase) { //If OverrideEntireGroup is set to true if (!settings.OverrideTargetDatabase && !settings.FlatExport && settings.OverrideEntireGroup && !string.IsNullOrEmpty(settings.Group)) { //Delete every entry in target database' groups to override them IEnumerable <PwGroup> groupsToDelete = entries.Select(x => x.ParentGroup).Distinct(); DeleteTargetGroupsInDatabase(groupsToDelete, targetDatabase); } foreach (PwEntry entry in entries) { // Get or create the target group in the target database (including hierarchy) PwGroup targetGroup = settings.FlatExport ? targetDatabase.RootGroup : CreateTargetGroupInDatebase(entry, targetDatabase, sourceDb); PwEntry peNew = null; if (!settings.OverrideTargetDatabase) { peNew = targetGroup.FindEntry(entry.Uuid, bSearchRecursive: false); // Check if the target entry is newer than the source entry if (settings.OverrideEntryOnlyNewer && peNew != null && peNew.LastModificationTime > entry.LastModificationTime) { // Yes -> skip this entry continue; } } // Was no existing entry in the target database found? if (peNew == null) { // Create a new entry peNew = new PwEntry(false, false); peNew.Uuid = entry.Uuid; // Add entry to the target group in the new database targetGroup.AddEntry(peNew, true); } // Clone entry properties if ExportUserAndPassOnly is false if (!settings.ExportUserAndPassOnly) { peNew.AssignProperties(entry, false, true, true); peNew.Strings.Set(PwDefs.UrlField, FieldHelper.GetFieldWRef(entry, sourceDb, PwDefs.UrlField)); peNew.Strings.Set(PwDefs.NotesField, FieldHelper.GetFieldWRef(entry, sourceDb, PwDefs.NotesField)); } // Copy/override some supported fields with ref resolving values peNew.Strings.Set(PwDefs.TitleField, FieldHelper.GetFieldWRef(entry, sourceDb, PwDefs.TitleField)); peNew.Strings.Set(PwDefs.UserNameField, FieldHelper.GetFieldWRef(entry, sourceDb, PwDefs.UserNameField)); peNew.Strings.Set(PwDefs.PasswordField, FieldHelper.GetFieldWRef(entry, sourceDb, PwDefs.PasswordField)); // Handle custom icon HandleCustomIcon(targetDatabase, sourceDb, entry); } }