From 50de73ac4a6f1b7c3b3d2a9b14ac73353721e2f8 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 11 Feb 2008 16:44:27 +0000 Subject: [PATCH] DEVEL15-windows-afscreds-vista-uac-20080211 LICENSE MIT FIXES 82701 Modifying the registry and the startup shortcuts is not permitted under Vista UAC. Generate an error dialog and notify the end user. (cherry picked from commit 7a8d8da95f5bd23fbb97d93840f3a2c5a145a695) --- src/WINNT/client_creds/advtab.cpp | 32 ++++++++++++------- src/WINNT/client_creds/lang/en_US/afscreds.rc | 2 ++ src/WINNT/client_creds/main.cpp | 4 +-- src/WINNT/client_creds/resource.h | 2 ++ src/WINNT/client_creds/shortcut.cpp | 9 ++++-- src/WINNT/client_creds/shortcut.h | 2 +- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/WINNT/client_creds/advtab.cpp b/src/WINNT/client_creds/advtab.cpp index 8721414c5..cf16a8b33 100644 --- a/src/WINNT/client_creds/advtab.cpp +++ b/src/WINNT/client_creds/advtab.cpp @@ -292,18 +292,28 @@ void Advanced_OnOpenCPL (HWND hDlg) void Advanced_OnStartup (HWND hDlg) { - g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP); + BOOL bSuccess = FALSE; + g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP); - HKEY hk; - if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, TEXT(AFSREG_CLT_SVC_PARAM_SUBKEY), 0, NULL, 0, - (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, NULL, &hk, NULL) == 0) - { - DWORD dwSize = sizeof(g.fStartup); - DWORD dwType = REG_DWORD; - RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize); - RegCloseKey (hk); - } + HKEY hk; + if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, TEXT(AFSREG_CLT_SVC_PARAM_SUBKEY), 0, NULL, 0, + (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, NULL, &hk, NULL) == 0) + { + DWORD dwSize = sizeof(g.fStartup); + DWORD dwType = REG_DWORD; + RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize); + RegCloseKey (hk); - Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup); + bSuccess = Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup); + } + + if (!bSuccess) { + // Reset the state + g.fStartup = !g.fStartup; + CheckDlgButton(hDlg, IDC_STARTUP, g.fStartup); + + // Report error to user + Message (MB_OK | MB_ICONHAND, IDS_STARTUP_CHANGE_TITLE, IDS_STARTUP_CHANGE_ERROR); + } } diff --git a/src/WINNT/client_creds/lang/en_US/afscreds.rc b/src/WINNT/client_creds/lang/en_US/afscreds.rc index 947a32dcd..709ce4e6a 100644 --- a/src/WINNT/client_creds/lang/en_US/afscreds.rc +++ b/src/WINNT/client_creds/lang/en_US/afscreds.rc @@ -561,6 +561,8 @@ BEGIN IDS_BADSUB_DESC "The drive letter description you entered cannot be used.\n\nA drive letter description may have no more than 12 characters, and may not contain spaces or tabs." IDS_TITLE_95 "AFS Light" IDS_CREDS_EXPIRED "%1 (expired)" + IDS_STARTUP_CHANGE_TITLE "Error - Startup Setting" + IDS_STARTUP_CHANGE_ERROR "Unable to change startup state.\nPermission denied." END #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/WINNT/client_creds/main.cpp b/src/WINNT/client_creds/main.cpp index acc41d7a5..9a907dc19 100644 --- a/src/WINNT/client_creds/main.cpp +++ b/src/WINNT/client_creds/main.cpp @@ -148,7 +148,7 @@ BOOL InitApp (LPSTR pszCmdLineA) fUninstall = TRUE; break; - case ':': + case ':': CopyAnsiToString(g.SmbName,pszCmdLineA); MapShareName(pszCmdLineA); break; @@ -175,7 +175,7 @@ BOOL InitApp (LPSTR pszCmdLineA) else if (fUninstall) Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE); - if (fInstall) + if (fInstall || fUninstall) { HKEY hk; if (RegCreateKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, 0, NULL, 0, diff --git a/src/WINNT/client_creds/resource.h b/src/WINNT/client_creds/resource.h index 701059ffa..093bd4756 100644 --- a/src/WINNT/client_creds/resource.h +++ b/src/WINNT/client_creds/resource.h @@ -59,6 +59,8 @@ #define IDS_BADSUB_DESC 49 #define IDS_TITLE_95 50 #define IDS_CREDS_EXPIRED 51 +#define IDS_STARTUP_CHANGE_TITLE 52 +#define IDS_STARTUP_CHANGE_ERROR 53 #define IDI_MAIN 100 #define IDD_MAIN 101 diff --git a/src/WINNT/client_creds/shortcut.cpp b/src/WINNT/client_creds/shortcut.cpp index b777b2f38..1f3dbda7e 100644 --- a/src/WINNT/client_creds/shortcut.cpp +++ b/src/WINNT/client_creds/shortcut.cpp @@ -79,9 +79,10 @@ BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTST } -void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart) +BOOL Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart) { TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT(""); + BOOL bSuccess; HKEY hk; if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0) @@ -133,11 +134,13 @@ void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart) RegCloseKey (hk); } } - Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams); + bSuccess = Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams); } else // (!g.fAutoStart) { - DeleteFile (szShortcut); + bSuccess = DeleteFile (szShortcut); } + + return bSuccess; } diff --git a/src/WINNT/client_creds/shortcut.h b/src/WINNT/client_creds/shortcut.h index ae82d5de9..8f9205bc5 100644 --- a/src/WINNT/client_creds/shortcut.h +++ b/src/WINNT/client_creds/shortcut.h @@ -19,7 +19,7 @@ void Shortcut_Init (void); void Shortcut_Exit (void); BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc = NULL, LPTSTR pszArgs = NULL); -void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart); +BOOL Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart); #endif -- 2.39.5