msi: Allocate the user token dynamically.
This commit is contained in:
parent
419496d0c8
commit
6ad992c407
|
@ -492,29 +492,37 @@ BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
|
||||||
return r == ERROR_SUCCESS && type == REG_DWORD;
|
return r == ERROR_SUCCESS && type == REG_DWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT get_user_sid(LPWSTR *usersid)
|
static WCHAR *get_user_sid(void)
|
||||||
{
|
{
|
||||||
HANDLE token;
|
HANDLE token;
|
||||||
BYTE buf[1024];
|
DWORD size = 256;
|
||||||
DWORD size;
|
TOKEN_USER *user;
|
||||||
PTOKEN_USER user;
|
WCHAR *ret;
|
||||||
|
|
||||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
|
if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token )) return NULL;
|
||||||
return ERROR_FUNCTION_FAILED;
|
if (!(user = msi_alloc( size )))
|
||||||
|
{
|
||||||
size = sizeof(buf);
|
CloseHandle( token );
|
||||||
if (!GetTokenInformation(token, TokenUser, buf, size, &size)) {
|
return NULL;
|
||||||
CloseHandle(token);
|
|
||||||
return ERROR_FUNCTION_FAILED;
|
|
||||||
}
|
}
|
||||||
|
if (!GetTokenInformation( token, TokenUser, user, size, &size ))
|
||||||
user = (PTOKEN_USER)buf;
|
{
|
||||||
if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
|
msi_free( user );
|
||||||
CloseHandle(token);
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || !(user = msi_alloc( size )))
|
||||||
return ERROR_FUNCTION_FAILED;
|
{
|
||||||
|
CloseHandle( token );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
GetTokenInformation( token, TokenUser, user, size, &size );
|
||||||
}
|
}
|
||||||
CloseHandle(token);
|
CloseHandle( token );
|
||||||
return ERROR_SUCCESS;
|
if (!ConvertSidToStringSidW( user->User.Sid, &ret ))
|
||||||
|
{
|
||||||
|
msi_free( user );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
msi_free( user );
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT MSIREG_OpenUninstallKey(MSIPACKAGE *package, HKEY *key, BOOL create)
|
UINT MSIREG_OpenUninstallKey(MSIPACKAGE *package, HKEY *key, BOOL create)
|
||||||
|
@ -554,7 +562,6 @@ UINT MSIREG_DeleteUninstallKey(MSIPACKAGE *package)
|
||||||
UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
|
UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
|
||||||
MSIINSTALLCONTEXT context, HKEY *key, BOOL create)
|
MSIINSTALLCONTEXT context, HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT r;
|
|
||||||
LPWSTR usersid = NULL;
|
LPWSTR usersid = NULL;
|
||||||
HKEY root = HKEY_LOCAL_MACHINE;
|
HKEY root = HKEY_LOCAL_MACHINE;
|
||||||
WCHAR squished_pc[GUID_SIZE];
|
WCHAR squished_pc[GUID_SIZE];
|
||||||
|
@ -580,18 +587,14 @@ UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
|
||||||
{
|
{
|
||||||
if (!szUserSid)
|
if (!szUserSid)
|
||||||
{
|
{
|
||||||
r = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (r != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", r);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return r;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
szUserSid = usersid;
|
szUserSid = usersid;
|
||||||
}
|
}
|
||||||
|
sprintfW(keypath, szInstaller_LocalManagedProd_fmt, szUserSid, squished_pc);
|
||||||
sprintfW(keypath, szInstaller_LocalManagedProd_fmt,
|
|
||||||
szUserSid, squished_pc);
|
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +643,6 @@ UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
|
||||||
UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
|
UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
|
||||||
HKEY *key, BOOL create)
|
HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT r;
|
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
HKEY root = HKEY_LOCAL_MACHINE;
|
HKEY root = HKEY_LOCAL_MACHINE;
|
||||||
WCHAR squished_pc[GUID_SIZE];
|
WCHAR squished_pc[GUID_SIZE];
|
||||||
|
@ -664,13 +666,11 @@ UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (r != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", r);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return r;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
|
sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -719,7 +719,6 @@ static UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL c
|
||||||
UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
|
UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
|
||||||
HKEY *key, BOOL create)
|
HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT r;
|
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
WCHAR squished_pc[GUID_SIZE];
|
WCHAR squished_pc[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
|
@ -737,13 +736,11 @@ UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (r != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", r);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return r;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
|
sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -790,11 +787,10 @@ UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
|
||||||
|
|
||||||
if (!szUserSid)
|
if (!szUserSid)
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
|
sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
|
||||||
|
@ -813,7 +809,6 @@ UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
|
||||||
|
|
||||||
UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
|
UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
|
||||||
{
|
{
|
||||||
UINT rc;
|
|
||||||
WCHAR comp[GUID_SIZE];
|
WCHAR comp[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
|
@ -825,13 +820,11 @@ UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
|
||||||
|
|
||||||
if (!szUserSid)
|
if (!szUserSid)
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
|
sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -860,11 +853,10 @@ UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContex
|
||||||
sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc);
|
sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
|
sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
|
||||||
|
@ -882,7 +874,6 @@ UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContex
|
||||||
UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
|
UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
|
||||||
HKEY *key, BOOL create)
|
HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT rc;
|
|
||||||
WCHAR squished_patch[GUID_SIZE];
|
WCHAR squished_patch[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
|
@ -896,13 +887,11 @@ UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
|
||||||
sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
|
sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
|
sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -915,7 +904,6 @@ UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
|
||||||
|
|
||||||
UINT MSIREG_DeleteUserDataPatchKey(LPCWSTR patch, MSIINSTALLCONTEXT context)
|
UINT MSIREG_DeleteUserDataPatchKey(LPCWSTR patch, MSIINSTALLCONTEXT context)
|
||||||
{
|
{
|
||||||
UINT r;
|
|
||||||
WCHAR squished_patch[GUID_SIZE];
|
WCHAR squished_patch[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
|
@ -929,13 +917,11 @@ UINT MSIREG_DeleteUserDataPatchKey(LPCWSTR patch, MSIINSTALLCONTEXT context)
|
||||||
sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
|
sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (r != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", r);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return r;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
|
sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -946,7 +932,6 @@ UINT MSIREG_DeleteUserDataPatchKey(LPCWSTR patch, MSIINSTALLCONTEXT context)
|
||||||
UINT MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product, MSIINSTALLCONTEXT context,
|
UINT MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product, MSIINSTALLCONTEXT context,
|
||||||
HKEY *key, BOOL create)
|
HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT rc;
|
|
||||||
WCHAR squished_product[GUID_SIZE];
|
WCHAR squished_product[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
|
@ -959,13 +944,11 @@ UINT MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product, MSIINSTALLCONTEXT con
|
||||||
sprintfW(keypath, szUserDataProductPatches_fmt, szLocalSid, squished_product);
|
sprintfW(keypath, szUserDataProductPatches_fmt, szLocalSid, squished_product);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataProductPatches_fmt, usersid, squished_product);
|
sprintfW(keypath, szUserDataProductPatches_fmt, usersid, squished_product);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -979,7 +962,6 @@ UINT MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product, MSIINSTALLCONTEXT con
|
||||||
UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
|
UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
|
||||||
LPCWSTR szUserSid, HKEY *key, BOOL create)
|
LPCWSTR szUserSid, HKEY *key, BOOL create)
|
||||||
{
|
{
|
||||||
UINT rc;
|
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
WCHAR squished_pc[GUID_SIZE];
|
WCHAR squished_pc[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
|
@ -995,13 +977,11 @@ UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
|
||||||
sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc);
|
sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
|
sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
}
|
}
|
||||||
|
@ -1014,7 +994,6 @@ UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
|
||||||
|
|
||||||
UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
|
UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
|
||||||
{
|
{
|
||||||
UINT rc;
|
|
||||||
WCHAR squished_pc[GUID_SIZE];
|
WCHAR squished_pc[GUID_SIZE];
|
||||||
WCHAR keypath[0x200];
|
WCHAR keypath[0x200];
|
||||||
LPWSTR usersid;
|
LPWSTR usersid;
|
||||||
|
@ -1024,16 +1003,14 @@ UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
|
||||||
return ERROR_FUNCTION_FAILED;
|
return ERROR_FUNCTION_FAILED;
|
||||||
TRACE("squished (%s)\n", debugstr_w(squished_pc));
|
TRACE("squished (%s)\n", debugstr_w(squished_pc));
|
||||||
|
|
||||||
rc = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (rc != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", rc);
|
ERR("Failed to retrieve user SID\n");
|
||||||
return rc;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
|
sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
|
||||||
|
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
|
|
||||||
return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
|
return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1362,12 +1339,11 @@ UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
|
|
||||||
key = 0;
|
key = 0;
|
||||||
r = get_user_sid(&usersid);
|
if (!(usersid = get_user_sid()))
|
||||||
if (r != ERROR_SUCCESS || !usersid)
|
|
||||||
{
|
{
|
||||||
ERR("Failed to retrieve user SID: %d\n", r);
|
ERR("Failed to retrieve user SID\n");
|
||||||
last_index = 0;
|
last_index = 0;
|
||||||
return r;
|
return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
sprintfW(keypath, szInstaller_LocalManaged_fmt, usersid);
|
sprintfW(keypath, szInstaller_LocalManaged_fmt, usersid);
|
||||||
LocalFree(usersid);
|
LocalFree(usersid);
|
||||||
|
@ -2089,8 +2065,8 @@ static UINT msi_enum_patches(LPCWSTR szProductCode, LPCWSTR szUserSid,
|
||||||
|
|
||||||
if (!szUserSid)
|
if (!szUserSid)
|
||||||
{
|
{
|
||||||
get_user_sid(&usersid);
|
szUserSid = usersid = get_user_sid();
|
||||||
szUserSid = usersid;
|
if (!usersid) return ERROR_FUNCTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
|
if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
|
||||||
|
|
Loading…
Reference in New Issue