Skip to content

Commit 61a2bbb

Browse files
committed
unmount all fs on shutdown (WM_ENDSESSION)
1 parent 15045f2 commit 61a2bbb

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

cppcryptfs/ui/CryptPropertySheet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ BEGIN_MESSAGE_MAP(CCryptPropertySheet, CPropertySheet)
103103
ON_WM_COPYDATA()
104104
ON_WM_WINDOWPOSCHANGING()
105105
ON_WM_DEVICECHANGE()
106+
// ON_WM_QUERYENDSESSION()
107+
ON_WM_ENDSESSION()
106108
END_MESSAGE_MAP()
107109

108110

@@ -288,3 +290,14 @@ BOOL CCryptPropertySheet::OnDeviceChange( UINT nEventType, DWORD_PTR dwData )
288290

289291
return CPropertySheet::OnDeviceChange(nEventType, dwData);
290292
}
293+
294+
295+
void CCryptPropertySheet::OnEndSession(BOOL bEnding)
296+
{
297+
CPropertySheet::OnEndSession(bEnding);
298+
299+
if (bEnding) {
300+
unmount_all(false);
301+
wait_for_all_unmounted();
302+
}
303+
}

cppcryptfs/ui/CryptPropertySheet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CCryptPropertySheet : public CPropertySheet
6565
afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct);
6666
afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos);
6767
afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);
68+
afx_msg void OnEndSession(BOOL bEnding);
6869
};
6970

7071

cppcryptfs/ui/SettingsPropertyPage.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ static int buffer_sizes[] = { 4, 8, 16, 32, 64, 128, 256, 512, 1024 };
8181

8282
static int ttls[] = { 0, 1, 2, 5, 10, 15, 30, 45, 60, 90, 120, 300, 600, 900, 1800, 3600};
8383

84-
static const WCHAR* ttl_strings[] = { L"infinite", L"1 second", L"2 seconds", L"5 seconds", L"10 seconds", L"15 seconds", L"30 seconds", L"45 seconds", L"60 seconds", L"90 seconds", L"2 minutes", L"5 minutes", L"10 minutes", L"15 minutes", L"30 minutes", L"1 hour" };
84+
static const WCHAR* ttl_strings[] = { L"infinite", L"1 second", L"2 seconds", L"5 seconds",
85+
L"10 seconds", L"15 seconds", L"30 seconds", L"45 seconds",
86+
L"60 seconds", L"90 seconds", L"2 minutes", L"5 minutes",
87+
L"10 minutes", L"15 minutes", L"30 minutes", L"1 hour" };
8588

8689
BOOL CSettingsPropertyPage::OnInitDialog()
8790
{
@@ -99,15 +102,17 @@ BOOL CSettingsPropertyPage::OnInitDialog()
99102

100103
bool bMountManager = theApp.GetProfileInt(L"Settings", L"MountManager", MOUNTMANAGER_DEFAULT) != 0;
101104

102-
bool bEnableSavingPasswords = theApp.GetProfileInt(L"Settings", L"EnableSavingPasswords", ENABLE_SAVING_PASSWORDS_DEFAULT) != 0;
105+
bool bEnableSavingPasswords = theApp.GetProfileInt(L"Settings", L"EnableSavingPasswords",
106+
ENABLE_SAVING_PASSWORDS_DEFAULT) != 0;
103107

104108
bool bNeverSaveHistory = NeverSaveHistory();
105109

106-
return SetControls(nThreads, bufferblocks, cachettl, bCaseInsensitive, bMountManager, bEnableSavingPasswords, bNeverSaveHistory);
110+
return SetControls(nThreads, bufferblocks, cachettl, bCaseInsensitive, bMountManager,
111+
bEnableSavingPasswords, bNeverSaveHistory);
107112
}
108113

109-
BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cachettl, bool bCaseInsensitive, bool bMountManager, bool bEnableSavingPasswords,
110-
bool bNeverSaveHistory)
114+
BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cachettl,
115+
bool bCaseInsensitive, bool bMountManager, bool bEnableSavingPasswords, bool bNeverSaveHistory)
111116
{
112117

113118
m_bCaseInsensitive = bCaseInsensitive;
@@ -172,7 +177,8 @@ BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cach
172177

173178
pBox->ResetContent();
174179

175-
static_assert(sizeof(ttls) / sizeof(ttls[0]) == sizeof(ttl_strings) / sizeof(ttl_strings[0]), "mismatch in sizes of ttls/ttl_strings");
180+
static_assert(sizeof(ttls) / sizeof(ttls[0]) == sizeof(ttl_strings) / sizeof(ttl_strings[0]),
181+
"mismatch in sizes of ttls/ttl_strings");
176182

177183
int selitem = 0;
178184

@@ -279,8 +285,9 @@ void CSettingsPropertyPage::OnBnClickedDefaults()
279285
{
280286
// TODO: Add your control notification handler code here
281287

282-
SetControls(PER_FILESYSTEM_THREADS_DEFAULT, BUFFERBLOCKS_DEFAULT, CACHETTL_DEFAULT, CASEINSENSITIVE_DEFAULT, MOUNTMANAGER_DEFAULT, ENABLE_SAVING_PASSWORDS_DEFAULT,
283-
NEVER_SAVE_HISTORY_RECOMMENDED);
288+
SetControls(PER_FILESYSTEM_THREADS_DEFAULT, BUFFERBLOCKS_DEFAULT, CACHETTL_DEFAULT,
289+
CASEINSENSITIVE_DEFAULT, MOUNTMANAGER_DEFAULT, ENABLE_SAVING_PASSWORDS_DEFAULT,
290+
NEVER_SAVE_HISTORY_DEFAULT);
284291

285292
SaveSettings();
286293
}
@@ -290,7 +297,8 @@ void CSettingsPropertyPage::OnBnClickedRecommended()
290297
{
291298
// TODO: Add your control notification handler code here
292299

293-
SetControls(PER_FILESYSTEM_THREADS_RECOMMENDED, BUFFERBLOCKS_RECOMMENDED, CACHETTL_RECOMMENDED, CASEINSENSITIVE_RECOMMENDED, MOUNTMANAGER_RECOMMENDED, ENABLE_SAVING_PASSWORDS_RECOMMENDED,
300+
SetControls(PER_FILESYSTEM_THREADS_RECOMMENDED, BUFFERBLOCKS_RECOMMENDED, CACHETTL_RECOMMENDED,
301+
CASEINSENSITIVE_RECOMMENDED, MOUNTMANAGER_RECOMMENDED, ENABLE_SAVING_PASSWORDS_RECOMMENDED,
294302
NEVER_SAVE_HISTORY_RECOMMENDED);
295303

296304
SaveSettings();
@@ -327,6 +335,11 @@ void CSettingsPropertyPage::OnClickedEnableSavingPasswords()
327335
CheckDlgButton(IDC_ENABLE_SAVING_PASSWORDS, m_bEnableSavingPasswords ? 1 : 0);
328336

329337
if (m_bEnableSavingPasswords) {
338+
339+
if (m_bNeverSaveHistory) {
340+
MessageBox(L"Passwords will not be saved if \"Never save history\" is turned on.",
341+
L"cppcryptfs", MB_OK | MB_ICONINFORMATION);
342+
}
330343
theApp.WriteProfileInt(L"Settings", L"EnableSavingPasswords", TRUE);
331344
} else {
332345
theApp.WriteProfileInt(L"Settings", L"EnableSavingPasswords", FALSE);
@@ -356,6 +369,13 @@ void CSettingsPropertyPage::OnClickedNeverSaveHistory()
356369
theApp.WriteProfileInt(L"Settings", L"NeverSaveHistory", !!m_bNeverSaveHistory);
357370

358371
if (m_bNeverSaveHistory) {
372+
373+
if (m_bEnableSavingPasswords) {
374+
MessageBox(L"If you turn on \"Never save history\", saved passwords will not be deleted, but new passwords will not "
375+
L"be saved. To delete any saved passwords, uncheck \"Enable saved passwords\".",
376+
L"cppcryptfs", MB_OK | MB_ICONINFORMATION);
377+
}
378+
359379
wstring mes;
360380
wstring error;
361381

@@ -376,7 +396,8 @@ void CSettingsPropertyPage::OnClickedNeverSaveHistory()
376396
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH L"CreateOptions", mes);
377397
error += mes;
378398
if (!error.empty()) {
379-
MessageBox(L"unable to delete history from registry", L"cppcryptfs", MB_OK | MB_ICONEXCLAMATION);
399+
MessageBox(L"unable to delete history from registry", L"cppcryptfs",
400+
MB_OK | MB_ICONEXCLAMATION);
380401
}
381402
}
382403
}

0 commit comments

Comments
 (0)