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

commit c8d44606d61e3bbace3068a989249383fba3209d
Author:     Eric Kohl <[email protected]>
AuthorDate: Sun Mar 17 17:51:32 2019 +0100
Commit:     Eric Kohl <[email protected]>
CommitDate: Sun Mar 17 17:51:32 2019 +0100

    [USERENV] Implement GetProfileType().
---
 dll/win32/userenv/profile.c | 95 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 2 deletions(-)

diff --git a/dll/win32/userenv/profile.c b/dll/win32/userenv/profile.c
index cf5424288a..6a079076bf 100644
--- a/dll/win32/userenv/profile.c
+++ b/dll/win32/userenv/profile.c
@@ -1566,8 +1566,99 @@ WINAPI
 GetProfileType(
     _Out_ PDWORD pdwFlags)
 {
-    DPRINT1("GetProfileType() not implemented!\n");
-    return FALSE;
+    UNICODE_STRING SidString = {0, 0, NULL};
+    HANDLE hToken;
+    HKEY hProfilesKey = NULL, hProfileKey = NULL;
+    DWORD dwType, dwLength, dwState = 0;
+    DWORD dwError;
+    BOOL bResult = FALSE;
+
+    DPRINT("GetProfileType(%p)\n", pdwFlags);
+
+    if (pdwFlags == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &hToken))
+    {
+        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
+        {
+            DPRINT1("Failed to open a token (Error %lu)\n", GetLastError());
+            return FALSE;
+        }
+    }
+
+    /* Get the user SID string */
+    if (!GetUserSidStringFromToken(hToken, &SidString))
+    {
+        DPRINT1("GetUserSidStringFromToken() failed\n");
+        goto done;
+    }
+
+    DPRINT("SID: %wZ\n", &SidString);
+
+    dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                            L"SOFTWARE\\Microsoft\\Windows 
NT\\CurrentVersion\\ProfileList",
+                            0,
+                            KEY_QUERY_VALUE,
+                            &hProfilesKey);
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Error: %lu\n", dwError);
+        SetLastError(dwError);
+        goto done;
+    }
+
+    dwError = RegOpenKeyExW(hProfilesKey,
+                            SidString.Buffer,
+                            0,
+                            KEY_QUERY_VALUE | KEY_SET_VALUE,
+                            &hProfileKey);
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Error: %lu\n", dwError);
+        SetLastError(dwError);
+        goto done;
+    }
+
+    /* Get the State value */
+    dwLength = sizeof(dwState);
+    dwError = RegQueryValueExW(hProfileKey,
+                               L"State",
+                               NULL,
+                               &dwType,
+                               (PBYTE)&dwState,
+                               &dwLength);
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("Error: %lu\n", dwError);
+        SetLastError(dwError);
+        goto done;
+    }
+
+    *pdwFlags = 0;
+
+    if (dwState & 0x80) /* PROFILE_GUEST_USER */
+        *pdwFlags |= PT_TEMPORARY;
+
+    /* FIXME: Add checks for PT_MANDATORY and PT_ROAMING */
+
+    bResult = TRUE;
+
+done:
+    if (hProfileKey != NULL)
+        RegCloseKey(hProfileKey);
+
+    if (hProfilesKey != NULL)
+        RegCloseKey(hProfilesKey);
+
+    RtlFreeUnicodeString(&SidString);
+
+    CloseHandle(hToken);
+
+    return bResult;
 }
 
 

Reply via email to