From 1130d5909b102581fb669c7ed3339e657e85cb5f Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Mon, 2 Jul 2007 20:22:57 -0700 Subject: [PATCH] msi: Open the correct key and return INSTALLSTATE_ADVERTISED if it's missing. --- dlls/msi/msi.c | 4 +- dlls/msi/msipriv.h | 1 + dlls/msi/registry.c | 81 +++++++++++++++++++++++++++++----------- dlls/msi/tests/install.c | 35 +++++++++++++---- dlls/msi/tests/msi.c | 34 +++++++---------- 5 files changed, 105 insertions(+), 50 deletions(-) diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 5e20ce2e39c..4511f34ed15 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -1260,9 +1260,9 @@ INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature) return r; /* now check if it's complete or advertised */ - rc = MSIREG_OpenFeaturesKey(szProduct, &hkey, FALSE); + rc = MSIREG_OpenUserDataFeaturesKey(szProduct, &hkey, FALSE); if (rc != ERROR_SUCCESS) - return INSTALLSTATE_UNKNOWN; + return INSTALLSTATE_ADVERTISED; components = msi_reg_get_val_str( hkey, szFeature ); RegCloseKey(hkey); diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index a62f8d9899c..33ca02757bf 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -703,6 +703,7 @@ extern UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create extern UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create); extern UINT MSIREG_OpenFeatures(HKEY* key); extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create); +extern UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create); extern UINT MSIREG_OpenComponents(HKEY* key); extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create); extern UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create); diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index 5787bc78db3..22a2498bdb9 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -60,6 +60,16 @@ static const WCHAR szInstaller_Features[] = { 'I','n','s','t','a','l','l','e','r','\\', 'F','e','a','t','u','r','e','s',0 }; +static const WCHAR szUserDataFeatures_fmt[] = { +'S','o','f','t','w','a','r','e','\\', +'M','i','c','r','o','s','o','f','t','\\', +'W','i','n','d','o','w','s','\\', +'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', +'I','n','s','t','a','l','l','e','r','\\', +'U','s','e','r','D','a','t','a','\\', +'%','s','\\','P','r','o','d','u','c','t','s','\\', +'%','s','\\','F','e','a','t','u','r','e','s',0}; + static const WCHAR szInstaller_Features_fmt[] = { 'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', @@ -411,6 +421,27 @@ BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val) return r == ERROR_SUCCESS && type == REG_DWORD; } +static UINT get_user_sid(LPWSTR *usersid) +{ + HANDLE token; + BYTE buf[1024]; + DWORD size; + PTOKEN_USER user; + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) + return ERROR_FUNCTION_FAILED; + + size = sizeof(buf); + if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) + return ERROR_FUNCTION_FAILED; + + user = (PTOKEN_USER)buf; + if (!ConvertSidToStringSidW(user->User.Sid, usersid)) + return ERROR_FUNCTION_FAILED; + + return ERROR_SUCCESS; +} + UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create) { UINT rc; @@ -526,6 +557,35 @@ UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create) return rc; } +UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create) +{ + UINT rc; + WCHAR squished_pc[GUID_SIZE]; + WCHAR keypath[0x200]; + LPWSTR usersid; + + TRACE("%s\n", debugstr_w(szProduct)); + squash_guid(szProduct, squished_pc); + TRACE("squished (%s)\n", debugstr_w(squished_pc)); + + rc = get_user_sid(&usersid); + if (rc != ERROR_SUCCESS || !usersid) + { + ERR("Failed to retrieve user SID: %d\n", rc); + return rc; + } + + sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc); + + if (create) + rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); + else + rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); + + msi_free(usersid); + return rc; +} + UINT MSIREG_OpenComponents(HKEY* key) { return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key); @@ -571,27 +631,6 @@ UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create) return rc; } -static UINT get_user_sid(LPWSTR *usersid) -{ - HANDLE token; - BYTE buf[1024]; - DWORD size; - PTOKEN_USER user; - - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) - return ERROR_FUNCTION_FAILED; - - size = sizeof(buf); - if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) - return ERROR_FUNCTION_FAILED; - - user = (PTOKEN_USER)buf; - if (!ConvertSidToStringSidW(user->User.Sid, usersid)) - return ERROR_FUNCTION_FAILED; - - return ERROR_SUCCESS; -} - UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create) { UINT rc; diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c index 4cf3ca455b2..f64b9f79481 100644 --- a/dlls/msi/tests/install.c +++ b/dlls/msi/tests/install.c @@ -1850,7 +1850,10 @@ static void test_publish(void) ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state); state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); todo_wine @@ -1905,7 +1908,10 @@ static void test_publish(void) ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state); state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); todo_wine @@ -1960,7 +1966,10 @@ static void test_publish(void) ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state); state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); todo_wine @@ -1986,10 +1995,16 @@ static void test_publish(void) ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state); state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state); @@ -2067,10 +2082,16 @@ static void test_publish(void) ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state); state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo"); - ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state); diff --git a/dlls/msi/tests/msi.c b/dlls/msi/tests/msi.c index 72713c123c0..4e7b5e24db0 100644 --- a/dlls/msi/tests/msi.c +++ b/dlls/msi/tests/msi.c @@ -573,10 +573,7 @@ static void test_MsiQueryFeatureState(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); state = MsiQueryFeatureStateA(prodcode, "feature"); - todo_wine - { - ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); - } + ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\"); lstrcatA(keypath, usersid); @@ -606,28 +603,19 @@ static void test_MsiQueryFeatureState(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); state = MsiQueryFeatureStateA(prodcode, "feature"); - todo_wine - { - ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); - } + ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaaa", 22); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); state = MsiQueryFeatureStateA(prodcode, "feature"); - todo_wine - { - ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); - } + ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)comp_base85, 21); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); state = MsiQueryFeatureStateA(prodcode, "feature"); - todo_wine - { - ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); - } + ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\"); lstrcatA(keypath, usersid); @@ -638,10 +626,7 @@ static void test_MsiQueryFeatureState(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); state = MsiQueryFeatureStateA(prodcode, "feature"); - todo_wine - { - ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); - } + ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state); res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 1); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); @@ -652,6 +637,15 @@ static void test_MsiQueryFeatureState(void) ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); } + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"apple", 1); + ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); + + state = MsiQueryFeatureStateA(prodcode, "feature"); + todo_wine + { + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + } + RegDeleteValueA(compkey, prod_squashed); RegDeleteValueA(compkey, ""); RegDeleteValueA(localkey, "feature");