private void OnDatabaseCloseAction(object sender, FileClosingEventArgs e) { if (this.m_config.BackupOnDbClose && e.Database.IsOpen) { this.BackupAction(e.Database); } }
private static bool IsDBLocking(FileClosingEventArgs e) { try { var FlagsProperty = typeof(FileClosingEventArgs).GetProperty("Flags"); if (FlagsProperty == null) { return(true); } var FlagsType = FlagsProperty.PropertyType; int FlagsValue = Convert.ToInt32(FlagsProperty.GetValue(e, null)); var names = Enum.GetNames(FlagsType); for (int i = 0; i != names.Length; ++i) { if (names[i] == "Locking") { int Locking = Convert.ToInt32(Enum.GetValues(FlagsType).GetValue(i)); if ((FlagsValue & Locking) != Locking) { return(false); } break; } } } catch { } return(true); }
public void OnDBClosing(object sender, FileClosingEventArgs e) { if (e == null) { Debug.Fail("Event is null"); return; } if (SystemInformation.TerminalServerSession) // RDP { return; } if (e.Cancel || e.Database == null || e.Database.IOConnectionInfo == null) { return; } var databaseMasterKey = e.Database.MasterKey; if (databaseMasterKey == null) { return; } Lock(IsDBLocking(e), e.Database.IOConnectionInfo.Path, databaseMasterKey); }
private void MainWindowOnFileClosingPre(object sender, FileClosingEventArgs fileClosingEventArgs) { if (!fileClosingEventArgs.Database.IOConnectionInfo.IsLocalFile()) { return; } this.RemoveMonitor(fileClosingEventArgs.Database.IOConnectionInfo.Path); }
private void OnFileClosingPre(object sender, FileClosingEventArgs e) { try { mRTEControl.saveEntry(); } finally { } }
/// <summary> /// Triggered when a KeePass database is closing after the database has been saved /// </summary> private void OnKeePassDatabaseClosing(object sender, FileClosingEventArgs e) { // Check if there's still a process running that we need to wait for before allowing KeePass to terminate if (IsSomethingStillRunning) { Host.MainWindow.SetStatusEx("Waiting for OneDriveSync to complete..."); do { System.Threading.Thread.Sleep(1); Application.DoEvents(); } while (IsSomethingStillRunning); } }
private void File_OnClosed(object sender, EventArgs e) { var args = new FileClosingEventArgs(); args.File = sender; FileClosing?.Invoke(this, args); if (!args.Cancel) { // Doing the cast again in case something changed args CloseFile(sender as FileViewModel); } }
/// <summary> /// Handler to be called whenever the database is closed (i.e., it is called /// when the database is locked, closed or KeePass is closed). /// If enabled by the user ("backup-on-close") and the database is opened and /// modified (or was modified and saved after the last backup), a backup will /// be triggered. /// </summary> /// <param name="sender"></param> /// <param name="e">File closing event containing the database object</param> private void OnDatabaseCloseAction(object sender, FileClosingEventArgs e) { // perform backup if "backup-on-close" is configured and database is opened // and modified (or was modified and saved since the last backup) as well // (prevent backups of unmodified database) if ( this.m_config.BackupOnDbClose && e.Database.IsOpen && (e.Database.Modified || m_databaseModifiedAfterLastBackup) ) { this.BackupAction(e.Database); } }
private void OnPreFileClosing(object sender, FileClosingEventArgs e) { try { var keyManager = _keyManagerProvider.ObtainKeyManager(); if (keyManager != null) { keyManager.OnDBClosing(sender, e); } } catch (Exception ex) { ErrorHandler.ShowError(ex); } }
/// <summary> /// Gets the masterkey before the database is closed. /// </summary> private void FileClosingPreHandler(object sender, FileClosingEventArgs e) { if (e == null) { Debug.Assert(false); return; } if (e.Cancel) { return; } if (e.Database != null && e.Database.MasterKey != null && WinHello.IsAvailable()) { _provider.CacheKeyForDB(e.Database.IOConnectionInfo.Path, e.Database.MasterKey); } }
/// <summary> /// Triggered when a KeePass database is closing after the database has been saved /// </summary> private void OnKeePassDatabaseClosing(object sender, FileClosingEventArgs e) { // Check if there's still a process running that we need to wait for before allowing KeePass to terminate if (Configuration.IsSomethingStillRunning) { Host.MainWindow.SetStatusEx("Waiting for OneDriveSync to complete..."); // Record the time until we want to wait at most before exiting var waitUntil = DateTime.Now.AddSeconds(30); do { System.Threading.Thread.Sleep(1); Application.DoEvents(); } while (Configuration.IsSomethingStillRunning && DateTime.Now < waitUntil); } }
/// <summary> /// Closes the file /// </summary> /// <param name="File">File to close</param> public virtual void CloseFile(FileViewModel file) { if (file != null) { var args = new FileClosingEventArgs(); args.File = file; FileClosing?.Invoke(this, args); if (!args.Cancel) { for (var i = OpenFiles.Count - 1; i >= 0; i--) { if (ReferenceEquals(OpenFiles[i], file)) { OpenFiles[i].Dispose(); var openFilesCount = OpenFiles.Count; try { OpenFiles.RemoveAt(i); } catch (NullReferenceException) { // There's been a bug in a dependency where OpenFiles.RemoveAt fails because of UI stuff. // If the same exception is encountered, and the file has actually been removed, then ignore it. if (openFilesCount <= OpenFiles.Count) // OpenFiles.Count should have decreased by 1. If it has not, then throw the exception. { throw; } } } } if (ReferenceEquals(file, SelectedFile)) { SelectedFile = null; } FileClosed?.Invoke(this, new FileClosedEventArgs { File = file.Model }); } } }
public void OnDBClosing(object sender, FileClosingEventArgs e) { if (e == null) { Debug.Fail("Event is null"); return; } if (e.Cancel || e.Database == null || e.Database.MasterKey == null || e.Database.IOConnectionInfo == null) { return; } try { string dbPath = e.Database.IOConnectionInfo.Path; if (!IsDBLocking(e) && Settings.Instance.GetAuthCacheType() == AuthCacheType.Local) { _keyStorage.Remove(dbPath); } else if (Settings.Instance.Enabled) { _keyStorage.AddOrUpdate(dbPath, ProtectedKey.Create(e.Database.MasterKey, _keyCipher)); } } catch (AuthProviderInvalidKeyException ex) { // It's expected not to throw exceptions ClaimCurrentCacheType(AuthCacheType.Local); ErrorHandler.ShowError(ex, "For security reasons Credential Manager storage has been turned off. Use Options dialog to turn it on."); } catch (AuthProviderUserCancelledException) { // it's OK } catch (Exception ex) { ErrorHandler.ShowError(ex); } }
public void OnDBClosing(object sender, FileClosingEventArgs e) { if (e == null) { Debug.Fail("Event is null"); return; } if (e.Cancel || e.Database == null || e.Database.MasterKey == null || e.Database.IOConnectionInfo == null) { return; } string dbPath = e.Database.IOConnectionInfo.Path; if (!IsDBLocking(e)) { _keyStorage.Remove(dbPath); } else if (AuthProviderFactory.IsAvailable() && Settings.Instance.Enabled) { _keyStorage.AddOrUpdate(dbPath, ProtectedKey.Create(e.Database.MasterKey, _keyCipher)); } }
/// <summary> /// Gets the masterkey before the database is closed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FileClosingPreHandler(object sender, FileClosingEventArgs e) { if (e == null) { Debug.Assert(false); return; } if (e.Cancel) { return; } if (e.Database != null && e.Database.MasterKey != null) { var rootGroup = e.Database.RootGroup; if (rootGroup != null) { // Check if a QuickUnlock entry is available. var entry = rootGroup.GetEntries(true).Where(en => en.Strings.GetSafe(PwDefs.TitleField).ReadString() == ShortProductName).FirstOrDefault(); if (entry != null) { var password = entry.Strings.GetSafe(PwDefs.PasswordField); if (password.IsEmpty == false) { provider.AddCachedKey(e.Database.IOConnectionInfo.Path, password, e.Database.MasterKey); return; } } } // Check if PartOfPassword is enabled... if (Host.CustomConfig.GetEnum(QuickUnlockProvider.CfgMode, Mode.Entry) == Mode.EntryOrPartOf) { // ...and there is a password available. var passwordKey = e.Database.MasterKey.UserKeys.Where(k => k is KcpPassword).FirstOrDefault() as KcpPassword; if (passwordKey != null) { var length = (int)Host.CustomConfig.GetLong(QuickUnlockProvider.CfgPartOfLength, QuickUnlockProvider.MinimumPartOfLength); if (passwordKey.Password.Length >= length) { var origin = Host.CustomConfig.GetEnum(QuickUnlockProvider.CfgPartOfOrigin, PartOfOrigin.Default); var chars = passwordKey.Password.GetChars(); var startIndex = 0; if (origin == PartOfOrigin.End) { startIndex = chars.Length - length; } provider.AddCachedKey(e.Database.IOConnectionInfo.Path, chars.ToProtectedString(startIndex, length), e.Database.MasterKey); CharUtils.ZeroCharArray(chars); return; } } } // If no key is set, remove possible cached key. provider.RemoveCachedKey(e.Database.IOConnectionInfo.Path); } }