From 6488a6a5e4e70f00a988d951e6877a576d07ce20 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 9 Jan 2013 11:43:48 +0100 Subject: [PATCH] msi: Extend registry helpers to support opening the features key for a specific user. --- dlls/msi/action.c | 8 ++++---- dlls/msi/msi.c | 10 +++++----- dlls/msi/msipriv.h | 4 ++-- dlls/msi/registry.c | 36 ++++++++++++++++++++++-------------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index babf0f0c03c..22fa388f7d4 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -4852,12 +4852,12 @@ static UINT ACTION_PublishFeatures(MSIPACKAGE *package) if (!msi_check_publish(package)) return ERROR_SUCCESS; - rc = MSIREG_OpenFeaturesKey(package->ProductCode, package->Context, + rc = MSIREG_OpenFeaturesKey(package->ProductCode, NULL, package->Context, &hkey, TRUE); if (rc != ERROR_SUCCESS) goto end; - rc = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, package->Context, + rc = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, NULL, package->Context, &userdata, TRUE); if (rc != ERROR_SUCCESS) goto end; @@ -4957,7 +4957,7 @@ static UINT msi_unpublish_feature(MSIPACKAGE *package, MSIFEATURE *feature) TRACE("unpublishing feature %s\n", debugstr_w(feature->Feature)); - r = MSIREG_OpenFeaturesKey(package->ProductCode, package->Context, + r = MSIREG_OpenFeaturesKey(package->ProductCode, NULL, package->Context, &hkey, FALSE); if (r == ERROR_SUCCESS) { @@ -4965,7 +4965,7 @@ static UINT msi_unpublish_feature(MSIPACKAGE *package, MSIFEATURE *feature) RegCloseKey(hkey); } - r = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, package->Context, + r = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, NULL, package->Context, &hkey, FALSE); if (r == ERROR_SUCCESS) { diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 92ef52cbc15..0e57f093309 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -2982,12 +2982,12 @@ INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature) SetLastError( ERROR_SUCCESS ); - if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + if (MSIREG_OpenFeaturesKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED, &hkey, FALSE) != ERROR_SUCCESS && - MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + MSIREG_OpenFeaturesKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, &hkey, FALSE) != ERROR_SUCCESS) { - rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + rc = MSIREG_OpenFeaturesKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE, &hkey, FALSE); if (rc != ERROR_SUCCESS) return INSTALLSTATE_UNKNOWN; @@ -3007,11 +3007,11 @@ INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature) return r; if (machine) - rc = MSIREG_OpenUserDataFeaturesKey(szProduct, + rc = MSIREG_OpenUserDataFeaturesKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE, &hkey, FALSE); else - rc = MSIREG_OpenUserDataFeaturesKey(szProduct, + rc = MSIREG_OpenUserDataFeaturesKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, &hkey, FALSE); diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index c7a42cb014b..a3e1e0df8df 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -885,10 +885,10 @@ extern UINT MSIREG_OpenUninstallKey(const WCHAR *, enum platform, HKEY *, BOOL) extern UINT MSIREG_DeleteUninstallKey(const WCHAR *, enum platform) DECLSPEC_HIDDEN; extern UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid, MSIINSTALLCONTEXT context, HKEY* key, BOOL create) DECLSPEC_HIDDEN; -extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, +extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, LPCWSTR szUserSid, MSIINSTALLCONTEXT context, HKEY *key, BOOL create) DECLSPEC_HIDDEN; extern UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create) DECLSPEC_HIDDEN; -UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, +UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, LPCWSTR szUserSid, MSIINSTALLCONTEXT context, HKEY *key, BOOL create) DECLSPEC_HIDDEN; extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create) DECLSPEC_HIDDEN; extern UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid, diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index 388c0772808..bb564d81cea 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -562,12 +562,12 @@ UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY *key, BOOL create) return RegOpenKeyW(HKEY_CURRENT_USER, keypath, key); } -UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, HKEY *key, BOOL create) +UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, LPCWSTR szUserSid, MSIINSTALLCONTEXT context, + HKEY *key, BOOL create) { - LPWSTR usersid; HKEY root = HKEY_LOCAL_MACHINE; REGSAM access = KEY_WOW64_64KEY | KEY_ALL_ACCESS; - WCHAR squished_pc[GUID_SIZE], keypath[MAX_PATH]; + WCHAR squished_pc[GUID_SIZE], keypath[MAX_PATH], *usersid = NULL; if (!squash_guid(szProduct, squished_pc)) return ERROR_FUNCTION_FAILED; TRACE("%s squished %s\n", debugstr_w(szProduct), debugstr_w(squished_pc)); @@ -585,12 +585,16 @@ UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, HKEY * } else { - if (!(usersid = get_user_sid())) + if (!szUserSid) { - ERR("Failed to retrieve user SID\n"); - return ERROR_FUNCTION_FAILED; + if (!(usersid = get_user_sid())) + { + ERR("Failed to retrieve user SID\n"); + return ERROR_FUNCTION_FAILED; + } + szUserSid = usersid; } - sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc); + sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, szUserSid, squished_pc); LocalFree(usersid); } if (create) return RegCreateKeyExW(root, keypath, 0, NULL, 0, access, NULL, key, NULL); @@ -624,11 +628,11 @@ static UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL c return RegOpenKeyExW(HKEY_LOCAL_MACHINE, keypath, 0, access, key); } -UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, HKEY *key, BOOL create) +UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, LPCWSTR szUserSid, MSIINSTALLCONTEXT context, + HKEY *key, BOOL create) { - LPWSTR usersid; REGSAM access = KEY_WOW64_64KEY | KEY_ALL_ACCESS; - WCHAR squished_pc[GUID_SIZE], keypath[0x200]; + WCHAR squished_pc[GUID_SIZE], keypath[0x200], *usersid = NULL; if (!squash_guid(szProduct, squished_pc)) return ERROR_FUNCTION_FAILED; TRACE("%s squished %s\n", debugstr_w(szProduct), debugstr_w(squished_pc)); @@ -639,12 +643,16 @@ UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context } else { - if (!(usersid = get_user_sid())) + if (!szUserSid) { - ERR("Failed to retrieve user SID\n"); - return ERROR_FUNCTION_FAILED; + if (!(usersid = get_user_sid())) + { + ERR("Failed to retrieve user SID\n"); + return ERROR_FUNCTION_FAILED; + } + szUserSid = usersid; } - sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc); + sprintfW(keypath, szUserDataFeatures_fmt, szUserSid, squished_pc); LocalFree(usersid); } if (create) return RegCreateKeyExW(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, key, NULL);