https://git.reactos.org/?p=reactos.git;a=commitdiff;h=334fe302a1899d3d049adf08a166c7830aba86e1

commit 334fe302a1899d3d049adf08a166c7830aba86e1
Author:     Eric Kohl <eric.k...@reactos.org>
AuthorDate: Sun May 27 15:29:31 2018 +0200
Commit:     Eric Kohl <eric.k...@reactos.org>
CommitDate: Sun May 27 15:31:43 2018 +0200

    [USERENV] Implement CopySystemProfile Part 1 (Add a new profile subkey and 
values to the profile list)
    
    CORE-12541
---
 dll/win32/userenv/profile.c    | 107 ++++++++++++++++++++++++++++++++++++++++-
 dll/win32/userenv/userenv.spec |   2 +-
 sdk/include/psdk/userenv.h     |   1 +
 3 files changed, 108 insertions(+), 2 deletions(-)

diff --git a/dll/win32/userenv/profile.c b/dll/win32/userenv/profile.c
index 975a71f08c..8acbb90a91 100644
--- a/dll/win32/userenv/profile.c
+++ b/dll/win32/userenv/profile.c
@@ -106,6 +106,111 @@ AcquireRemoveRestorePrivilege(IN BOOL bAcquire)
 }
 
 
+BOOL
+WINAPI
+CopySystemProfile(
+    IN ULONG Unused)
+{
+    WCHAR szKeyName[MAX_PATH];
+    WCHAR szImagePath[MAX_PATH];
+    UNICODE_STRING SidString = {0, 0, NULL};
+    HANDLE hToken = NULL;
+    PSID pUserSid = NULL;
+    HKEY hProfileKey = NULL;
+    DWORD dwDisposition;
+    BOOL bResult = FALSE;
+    DWORD dwError;
+
+    DPRINT1("CopySystemProfile()\n");
+
+    if (!OpenProcessToken(GetCurrentProcess(),
+                          TOKEN_QUERY | TOKEN_IMPERSONATE,
+                          &hToken))
+    {
+        DPRINT1("Failed to open the process token (Error %lu)\n", 
GetLastError());
+        return FALSE;
+    }
+
+    pUserSid = GetUserSid(hToken);
+    if (pUserSid == NULL)
+    {
+        DPRINT1("Failed to get the users SID (Error %lu)\n", GetLastError());
+        goto done;
+    }
+
+    /* Get the user SID string */
+    if (!GetUserSidStringFromToken(hToken, &SidString))
+    {
+        DPRINT1("GetUserSidStringFromToken() failed\n");
+        goto done;
+    }
+
+    StringCbCopyW(szKeyName, sizeof(szKeyName),
+                  L"SOFTWARE\\Microsoft\\Windows 
NT\\CurrentVersion\\ProfileList\\");
+    StringCbCatW(szKeyName, sizeof(szKeyName), SidString.Buffer);
+
+    RtlFreeUnicodeString(&SidString);
+
+    dwError = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+                              szKeyName,
+                              0, NULL, 0,
+                              KEY_WRITE,
+                              NULL,
+                              &hProfileKey,
+                              &dwDisposition);
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Failed to create the profile key for the %s profile (Error 
%lu)\n",
+                SidString.Buffer, dwError);
+        goto done;
+    }
+
+    dwError = RegSetValueExW(hProfileKey,
+                             L"Sid",
+                             0,
+                             REG_BINARY,
+                             (PBYTE)pUserSid,
+                             RtlLengthSid(pUserSid));
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Failed to set the SID value (Error %lu)\n", dwError);
+        goto done;
+    }
+
+    wcscpy(szImagePath,
+           L"%systemroot%\\system32\\config\\systemprofile");
+
+    dwError = RegSetValueExW(hProfileKey,
+                             L"ProfileImagePath",
+                             0,
+                             REG_EXPAND_SZ,
+                             (PBYTE)szImagePath,
+                             (wcslen(szImagePath) + 1) * sizeof(WCHAR));
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Failed to set the ProfileImagePath value (Error %lu)\n", 
dwError);
+        goto done;
+    }
+
+
+    bResult = TRUE;
+
+done:
+    if (hProfileKey != NULL)
+        RegCloseKey(hProfileKey);
+
+    RtlFreeUnicodeString(&SidString);
+
+    if (pUserSid != NULL)
+        LocalFree(pUserSid);
+
+    if (hToken != NULL)
+        CloseHandle(hToken);
+
+    return bResult;
+}
+
+
 BOOL
 WINAPI
 CreateUserProfileA(
@@ -1030,7 +1135,7 @@ GetUserProfileDirectoryW(
                                    szImagePath,
                                    ARRAYSIZE(szImagePath)))
     {
-        DPRINT1 ("Error: %lu\n", GetLastError());
+        DPRINT1("Error: %lu\n", GetLastError());
         return FALSE;
     }
 
diff --git a/dll/win32/userenv/userenv.spec b/dll/win32/userenv/userenv.spec
index 0de19c7dd5..b8826bcfef 100644
--- a/dll/win32/userenv/userenv.spec
+++ b/dll/win32/userenv/userenv.spec
@@ -98,7 +98,7 @@
 152 stub -noname IsSyncForegroundPolicyRefresh                        #stdcall 
-noname IsSyncForegroundPolicyRefresh(8)
 153 stdcall -noname CreateUserProfileExA(ptr str str str long long)
 154 stdcall -noname CreateUserProfileExW(ptr wstr wstr wstr long long)
-155 stub -noname CopySystemProfile                                    #stdcall 
-noname CopySystemProfile(4)
+155 stdcall -noname CopySystemProfile(long)
 156 stub -noname GetUserProfileDirFromSidA                            #stdcall 
-noname GetUserProfileDirFromSidA(12)
 157 stub -noname GetUserProfileDirFromSidW                            #stdcall 
-noname GetUserProfileDirFromSidW(12)
 158 stub -noname SetNextFgPolicyRefreshInfo                           #stdcall 
-noname SetNextFgPolicyRefreshInfo(12)
diff --git a/sdk/include/psdk/userenv.h b/sdk/include/psdk/userenv.h
index 836de5c3a0..3b5054e0f1 100644
--- a/sdk/include/psdk/userenv.h
+++ b/sdk/include/psdk/userenv.h
@@ -106,6 +106,7 @@ BOOL WINAPI DeleteItemW (LPCWSTR, BOOL, LPCWSTR, BOOL);
 BOOL WINAPI CopyProfileDirectoryA(LPCSTR, LPCSTR, DWORD);
 BOOL WINAPI CopyProfileDirectoryW(LPCWSTR, LPCWSTR, DWORD);
 PSID WINAPI GetUserSid(HANDLE);
+BOOL WINAPI CopySystemProfile(ULONG);
 /* end private */
 BOOL WINAPI LoadUserProfileA (HANDLE, LPPROFILEINFOA);
 BOOL WINAPI LoadUserProfileW (HANDLE, LPPROFILEINFOW);

Reply via email to