From: Jeffrey Altman Date: Mon, 11 Feb 2008 16:42:45 +0000 (+0000) Subject: windows-afscreds-vista-uac-20080211 X-Git-Tag: BP-openafs-windows-kdfs-ifs~117 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=7a8d8da95f5bd23fbb97d93840f3a2c5a145a695 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. --- diff --git a/src/WINNT/client_creds/advtab.cpp b/src/WINNT/client_creds/advtab.cpp index ce77373..58256f9 100644 --- a/src/WINNT/client_creds/advtab.cpp +++ b/src/WINNT/client_creds/advtab.cpp @@ -295,18 +295,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 947a32d..709ce4e 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 c7bda7c..9f17610 100644 --- a/src/WINNT/client_creds/main.cpp +++ b/src/WINNT/client_creds/main.cpp @@ -151,7 +151,7 @@ BOOL InitApp (LPSTR pszCmdLineA) fUninstall = TRUE; break; - case ':': + case ':': CopyAnsiToString(g.SmbName,pszCmdLineA); MapShareName(pszCmdLineA); break; @@ -178,7 +178,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 701059f..093bd47 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 7853968..3ef523a 100644 --- a/src/WINNT/client_creds/shortcut.cpp +++ b/src/WINNT/client_creds/shortcut.cpp @@ -82,9 +82,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) @@ -136,11 +137,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 ae82d5d..8f9205b 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