- Implement DeleteGroup().
[reactos.git] / reactos / lib / userenv / profile.c
1 /* $Id: profile.c,v 1.11 2004/05/03 12:05:44 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/userenv/profile.c
6 * PURPOSE: User profile code
7 * PROGRAMMER: Eric Kohl
8 */
9
10 #include <ntos.h>
11 #include <windows.h>
12 #include <string.h>
13
14 #include <userenv.h>
15
16 #include "internal.h"
17
18
19 /* FUNCTIONS ***************************************************************/
20
21 BOOL
22 AppendSystemPostfix (LPWSTR lpName,
23 DWORD dwMaxLength)
24 {
25 WCHAR szSystemRoot[MAX_PATH];
26 WCHAR szDrivePostfix[3];
27 LPWSTR lpszPostfix;
28 LPWSTR lpszPtr;
29 DWORD dwPostfixLength;
30
31 /* Build profile name postfix */
32 if (!ExpandEnvironmentStringsW (L"%SystemRoot%",
33 szSystemRoot,
34 MAX_PATH))
35 {
36 DPRINT1("Error: %lu\n", GetLastError());
37 return FALSE;
38 }
39
40 _wcsupr (szSystemRoot);
41
42 /* Get name postfix */
43 szSystemRoot[2] = L'.';
44 lpszPostfix = &szSystemRoot[2];
45 lpszPtr = lpszPostfix;
46 while (*lpszPtr != (WCHAR)0)
47 {
48 if (*lpszPtr == L'\\')
49 *lpszPtr = '_';
50 lpszPtr++;
51 }
52
53 dwPostfixLength = wcslen (lpszPostfix);
54 if (szSystemRoot[0] != L'C')
55 {
56 dwPostfixLength += 2;
57 szDrivePostfix[0] = L'_';
58 szDrivePostfix[1] = szSystemRoot[0];
59 szDrivePostfix[2] = (WCHAR)0;
60 }
61
62 if (wcslen (lpName) + dwPostfixLength >= dwMaxLength)
63 {
64 DPRINT1("Error: buffer overflow\n");
65 return FALSE;
66 }
67
68 wcscat (lpName, lpszPostfix);
69 if (szSystemRoot[0] != L'C')
70 {
71 wcscat (lpName, szDrivePostfix);
72 }
73
74 return TRUE;
75 }
76
77
78 BOOL WINAPI
79 CreateUserProfileA (PSID Sid,
80 LPCSTR lpUserName)
81 {
82 UNICODE_STRING UserName;
83 BOOL bResult;
84 NTSTATUS Status;
85
86 Status = RtlCreateUnicodeStringFromAsciiz (&UserName,
87 (LPSTR)lpUserName);
88 if (!NT_SUCCESS(Status))
89 {
90 SetLastError (RtlNtStatusToDosError (Status));
91 return FALSE;
92 }
93
94 bResult = CreateUserProfileW (Sid,
95 UserName.Buffer);
96
97 RtlFreeUnicodeString (&UserName);
98
99 return bResult;
100 }
101
102
103 BOOL WINAPI
104 CreateUserProfileW (PSID Sid,
105 LPCWSTR lpUserName)
106 {
107 WCHAR szRawProfilesPath[MAX_PATH];
108 WCHAR szProfilesPath[MAX_PATH];
109 WCHAR szUserProfilePath[MAX_PATH];
110 WCHAR szDefaultUserPath[MAX_PATH];
111 WCHAR szBuffer[MAX_PATH];
112 UNICODE_STRING SidString;
113 DWORD dwLength;
114 DWORD dwDisposition;
115 HKEY hKey;
116 NTSTATUS Status;
117
118 DPRINT ("CreateUserProfileW() called\n");
119
120 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
121 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
122 0,
123 KEY_ALL_ACCESS,
124 &hKey))
125 {
126 DPRINT1("Error: %lu\n", GetLastError());
127 return FALSE;
128 }
129
130 /* Get profiles path */
131 dwLength = MAX_PATH * sizeof(WCHAR);
132 if (RegQueryValueExW (hKey,
133 L"ProfilesDirectory",
134 NULL,
135 NULL,
136 (LPBYTE)szRawProfilesPath,
137 &dwLength))
138 {
139 DPRINT1("Error: %lu\n", GetLastError());
140 RegCloseKey (hKey);
141 return FALSE;
142 }
143
144 /* Expand it */
145 if (!ExpandEnvironmentStringsW (szRawProfilesPath,
146 szProfilesPath,
147 MAX_PATH))
148 {
149 DPRINT1("Error: %lu\n", GetLastError());
150 RegCloseKey (hKey);
151 return FALSE;
152 }
153
154 /* Get default user path */
155 dwLength = MAX_PATH * sizeof(WCHAR);
156 if (RegQueryValueExW (hKey,
157 L"DefaultUserProfile",
158 NULL,
159 NULL,
160 (LPBYTE)szBuffer,
161 &dwLength))
162 {
163 DPRINT1("Error: %lu\n", GetLastError());
164 RegCloseKey (hKey);
165 return FALSE;
166 }
167
168 RegCloseKey (hKey);
169
170 wcscpy (szUserProfilePath, szProfilesPath);
171 wcscat (szUserProfilePath, L"\\");
172 wcscat (szUserProfilePath, lpUserName);
173 if (!AppendSystemPostfix (szUserProfilePath, MAX_PATH))
174 {
175 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
176 RtlFreeUnicodeString (&SidString);
177 RegCloseKey (hKey);
178 return FALSE;
179 }
180
181 wcscpy (szDefaultUserPath, szProfilesPath);
182 wcscat (szDefaultUserPath, L"\\");
183 wcscat (szDefaultUserPath, szBuffer);
184
185 /* Create user profile directory */
186 if (!CreateDirectoryW (szUserProfilePath, NULL))
187 {
188 if (GetLastError () != ERROR_ALREADY_EXISTS)
189 {
190 DPRINT1("Error: %lu\n", GetLastError());
191 return FALSE;
192 }
193 }
194
195 /* Copy default user directory */
196 if (!CopyDirectory (szUserProfilePath, szDefaultUserPath))
197 {
198 DPRINT1("Error: %lu\n", GetLastError());
199 return FALSE;
200 }
201
202 /* Add profile to profile list */
203 Status = RtlConvertSidToUnicodeString (&SidString, Sid, TRUE);
204 if (!NT_SUCCESS(Status))
205 {
206 DPRINT1("Status: %lx\n", Status);
207 return FALSE;
208 }
209
210 wcscpy (szBuffer,
211 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
212 wcscat (szBuffer, SidString.Buffer);
213
214 /* Create user profile key */
215 if (RegCreateKeyExW (HKEY_LOCAL_MACHINE,
216 szBuffer,
217 0,
218 NULL,
219 REG_OPTION_NON_VOLATILE,
220 KEY_ALL_ACCESS,
221 NULL,
222 &hKey,
223 &dwDisposition))
224 {
225 DPRINT1("Error: %lu\n", GetLastError());
226 RtlFreeUnicodeString (&SidString);
227 return FALSE;
228 }
229
230 /* Create non-expanded user profile path */
231 wcscpy (szBuffer, szRawProfilesPath);
232 wcscat (szBuffer, L"\\");
233 wcscat (szBuffer, lpUserName);
234 if (!AppendSystemPostfix (szBuffer, MAX_PATH))
235 {
236 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
237 RtlFreeUnicodeString (&SidString);
238 RegCloseKey (hKey);
239 return FALSE;
240 }
241
242 /* Set 'ProfileImagePath' value (non-expanded) */
243 if (RegSetValueExW (hKey,
244 L"ProfileImagePath",
245 0,
246 REG_EXPAND_SZ,
247 (LPBYTE)szBuffer,
248 (wcslen (szBuffer) + 1) * sizeof(WCHAR)))
249 {
250 DPRINT1("Error: %lu\n", GetLastError());
251 RtlFreeUnicodeString (&SidString);
252 RegCloseKey (hKey);
253 return FALSE;
254 }
255
256 /* Set 'Sid' value */
257 if (RegSetValueExW (hKey,
258 L"Sid",
259 0,
260 REG_BINARY,
261 Sid,
262 RtlLengthSid (Sid)))
263 {
264 DPRINT1("Error: %lu\n", GetLastError());
265 RtlFreeUnicodeString (&SidString);
266 RegCloseKey (hKey);
267 return FALSE;
268 }
269
270 RegCloseKey (hKey);
271
272 /* Create user hive name */
273 wcscat (szUserProfilePath, L"\\ntuser.dat");
274
275 /* Create new user hive */
276 if (RegLoadKeyW (HKEY_USERS,
277 SidString.Buffer,
278 szUserProfilePath))
279 {
280 DPRINT1("Error: %lu\n", GetLastError());
281 RtlFreeUnicodeString (&SidString);
282 return FALSE;
283 }
284
285 /* Initialize user hive */
286 if (!CreateUserHive (SidString.Buffer))
287 {
288 DPRINT1("Error: %lu\n", GetLastError());
289 RtlFreeUnicodeString (&SidString);
290 return FALSE;
291 }
292
293 RegUnLoadKeyW (HKEY_USERS,
294 SidString.Buffer);
295
296 RtlFreeUnicodeString (&SidString);
297
298 DPRINT ("CreateUserProfileW() done\n");
299
300 return TRUE;
301 }
302
303
304 BOOL WINAPI
305 GetAllUsersProfileDirectoryA (LPSTR lpProfileDir,
306 LPDWORD lpcchSize)
307 {
308 LPWSTR lpBuffer;
309 BOOL bResult;
310
311 lpBuffer = GlobalAlloc (GMEM_FIXED,
312 *lpcchSize * sizeof(WCHAR));
313 if (lpBuffer == NULL)
314 return FALSE;
315
316 bResult = GetAllUsersProfileDirectoryW (lpBuffer,
317 lpcchSize);
318 if (bResult)
319 {
320 WideCharToMultiByte (CP_ACP,
321 0,
322 lpBuffer,
323 -1,
324 lpProfileDir,
325 *lpcchSize,
326 NULL,
327 NULL);
328 }
329
330 GlobalFree (lpBuffer);
331
332 return bResult;
333 }
334
335
336 BOOL WINAPI
337 GetAllUsersProfileDirectoryW (LPWSTR lpProfileDir,
338 LPDWORD lpcchSize)
339 {
340 WCHAR szProfilePath[MAX_PATH];
341 WCHAR szBuffer[MAX_PATH];
342 DWORD dwLength;
343 HKEY hKey;
344
345 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
346 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
347 0,
348 KEY_READ,
349 &hKey))
350 {
351 DPRINT1("Error: %lu\n", GetLastError());
352 return FALSE;
353 }
354
355 /* Get profiles path */
356 dwLength = MAX_PATH * sizeof(WCHAR);
357 if (RegQueryValueExW (hKey,
358 L"ProfilesDirectory",
359 NULL,
360 NULL,
361 (LPBYTE)szBuffer,
362 &dwLength))
363 {
364 DPRINT1("Error: %lu\n", GetLastError());
365 RegCloseKey (hKey);
366 return FALSE;
367 }
368
369 /* Expand it */
370 if (!ExpandEnvironmentStringsW (szBuffer,
371 szProfilePath,
372 MAX_PATH))
373 {
374 DPRINT1("Error: %lu\n", GetLastError());
375 RegCloseKey (hKey);
376 return FALSE;
377 }
378
379 /* Get 'AllUsersProfile' name */
380 dwLength = MAX_PATH * sizeof(WCHAR);
381 if (RegQueryValueExW (hKey,
382 L"AllUsersProfile",
383 NULL,
384 NULL,
385 (LPBYTE)szBuffer,
386 &dwLength))
387 {
388 DPRINT1("Error: %lu\n", GetLastError());
389 RegCloseKey (hKey);
390 return FALSE;
391 }
392
393 RegCloseKey (hKey);
394
395 wcscat (szProfilePath, L"\\");
396 wcscat (szProfilePath, szBuffer);
397
398 dwLength = wcslen (szProfilePath);
399 if (lpProfileDir != NULL)
400 {
401 if (*lpcchSize < dwLength)
402 {
403 *lpcchSize = dwLength;
404 SetLastError (ERROR_INSUFFICIENT_BUFFER);
405 return FALSE;
406 }
407
408 wcscpy (lpProfileDir, szProfilePath);
409 }
410
411 *lpcchSize = dwLength;
412
413 return TRUE;
414 }
415
416
417 BOOL WINAPI
418 GetDefaultUserProfileDirectoryA (LPSTR lpProfileDir,
419 LPDWORD lpcchSize)
420 {
421 LPWSTR lpBuffer;
422 BOOL bResult;
423
424 lpBuffer = GlobalAlloc (GMEM_FIXED,
425 *lpcchSize * sizeof(WCHAR));
426 if (lpBuffer == NULL)
427 return FALSE;
428
429 bResult = GetDefaultUserProfileDirectoryW (lpBuffer,
430 lpcchSize);
431 if (bResult)
432 {
433 WideCharToMultiByte (CP_ACP,
434 0,
435 lpBuffer,
436 -1,
437 lpProfileDir,
438 *lpcchSize,
439 NULL,
440 NULL);
441 }
442
443 GlobalFree (lpBuffer);
444
445 return bResult;
446 }
447
448
449 BOOL WINAPI
450 GetDefaultUserProfileDirectoryW (LPWSTR lpProfileDir,
451 LPDWORD lpcchSize)
452 {
453 WCHAR szProfilePath[MAX_PATH];
454 WCHAR szBuffer[MAX_PATH];
455 DWORD dwLength;
456 HKEY hKey;
457
458 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
459 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
460 0,
461 KEY_READ,
462 &hKey))
463 {
464 DPRINT1("Error: %lu\n", GetLastError());
465 return FALSE;
466 }
467
468 /* Get profiles path */
469 dwLength = MAX_PATH * sizeof(WCHAR);
470 if (RegQueryValueExW (hKey,
471 L"ProfilesDirectory",
472 NULL,
473 NULL,
474 (LPBYTE)szBuffer,
475 &dwLength))
476 {
477 DPRINT1("Error: %lu\n", GetLastError());
478 RegCloseKey (hKey);
479 return FALSE;
480 }
481
482 /* Expand it */
483 if (!ExpandEnvironmentStringsW (szBuffer,
484 szProfilePath,
485 MAX_PATH))
486 {
487 DPRINT1("Error: %lu\n", GetLastError());
488 RegCloseKey (hKey);
489 return FALSE;
490 }
491
492 /* Get 'DefaultUserProfile' name */
493 dwLength = MAX_PATH * sizeof(WCHAR);
494 if (RegQueryValueExW (hKey,
495 L"DefaultUserProfile",
496 NULL,
497 NULL,
498 (LPBYTE)szBuffer,
499 &dwLength))
500 {
501 DPRINT1("Error: %lu\n", GetLastError());
502 RegCloseKey (hKey);
503 return FALSE;
504 }
505
506 RegCloseKey (hKey);
507
508 wcscat (szProfilePath, L"\\");
509 wcscat (szProfilePath, szBuffer);
510
511 dwLength = wcslen (szProfilePath);
512 if (lpProfileDir != NULL)
513 {
514 if (*lpcchSize < dwLength)
515 {
516 *lpcchSize = dwLength;
517 SetLastError (ERROR_INSUFFICIENT_BUFFER);
518 return FALSE;
519 }
520
521 wcscpy (lpProfileDir, szProfilePath);
522 }
523
524 *lpcchSize = dwLength;
525
526 return TRUE;
527 }
528
529
530 BOOL WINAPI
531 GetProfilesDirectoryA (LPSTR lpProfileDir,
532 LPDWORD lpcchSize)
533 {
534 LPWSTR lpBuffer;
535 BOOL bResult;
536
537 lpBuffer = GlobalAlloc (GMEM_FIXED,
538 *lpcchSize * sizeof(WCHAR));
539 if (lpBuffer == NULL)
540 return FALSE;
541
542 bResult = GetProfilesDirectoryW (lpBuffer,
543 lpcchSize);
544 if (bResult)
545 {
546 WideCharToMultiByte (CP_ACP,
547 0,
548 lpBuffer,
549 -1,
550 lpProfileDir,
551 *lpcchSize,
552 NULL,
553 NULL);
554 }
555
556 GlobalFree (lpBuffer);
557
558 return bResult;
559 }
560
561
562 BOOL WINAPI
563 GetProfilesDirectoryW (LPWSTR lpProfilesDir,
564 LPDWORD lpcchSize)
565 {
566 WCHAR szProfilesPath[MAX_PATH];
567 WCHAR szBuffer[MAX_PATH];
568 DWORD dwLength;
569 HKEY hKey;
570
571 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
572 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
573 0,
574 KEY_READ,
575 &hKey))
576 {
577 DPRINT1("Error: %lu\n", GetLastError());
578 return FALSE;
579 }
580
581 /* Get profiles path */
582 dwLength = MAX_PATH * sizeof(WCHAR);
583 if (RegQueryValueExW (hKey,
584 L"ProfilesDirectory",
585 NULL,
586 NULL,
587 (LPBYTE)szBuffer,
588 &dwLength))
589 {
590 DPRINT1("Error: %lu\n", GetLastError());
591 RegCloseKey (hKey);
592 return FALSE;
593 }
594
595 RegCloseKey (hKey);
596
597 /* Expand it */
598 if (!ExpandEnvironmentStringsW (szBuffer,
599 szProfilesPath,
600 MAX_PATH))
601 {
602 DPRINT1("Error: %lu\n", GetLastError());
603 return FALSE;
604 }
605
606 dwLength = wcslen (szProfilesPath);
607 if (lpProfilesDir != NULL)
608 {
609 if (*lpcchSize < dwLength)
610 {
611 *lpcchSize = dwLength;
612 SetLastError (ERROR_INSUFFICIENT_BUFFER);
613 return FALSE;
614 }
615
616 wcscpy (lpProfilesDir, szProfilesPath);
617 }
618
619 *lpcchSize = dwLength;
620
621 return TRUE;
622 }
623
624
625 BOOL WINAPI
626 GetUserProfileDirectoryA (HANDLE hToken,
627 LPSTR lpProfileDir,
628 LPDWORD lpcchSize)
629 {
630 LPWSTR lpBuffer;
631 BOOL bResult;
632
633 lpBuffer = GlobalAlloc (GMEM_FIXED,
634 *lpcchSize * sizeof(WCHAR));
635 if (lpBuffer == NULL)
636 return FALSE;
637
638 bResult = GetUserProfileDirectoryW (hToken,
639 lpBuffer,
640 lpcchSize);
641 if (bResult)
642 {
643 WideCharToMultiByte (CP_ACP,
644 0,
645 lpBuffer,
646 -1,
647 lpProfileDir,
648 *lpcchSize,
649 NULL,
650 NULL);
651 }
652
653 GlobalFree (lpBuffer);
654
655 return bResult;
656 }
657
658
659 BOOL WINAPI
660 GetUserProfileDirectoryW (HANDLE hToken,
661 LPWSTR lpProfileDir,
662 LPDWORD lpcchSize)
663 {
664 UNICODE_STRING SidString;
665 WCHAR szKeyName[MAX_PATH];
666 WCHAR szRawImagePath[MAX_PATH];
667 WCHAR szImagePath[MAX_PATH];
668 DWORD dwLength;
669 HKEY hKey;
670
671 if (!GetUserSidFromToken (hToken,
672 &SidString))
673 {
674 DPRINT1 ("GetUserSidFromToken() failed\n");
675 return FALSE;
676 }
677
678 DPRINT ("SidString: '%wZ'\n", &SidString);
679
680 wcscpy (szKeyName,
681 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
682 wcscat (szKeyName,
683 SidString.Buffer);
684
685 RtlFreeUnicodeString (&SidString);
686
687 DPRINT ("KeyName: '%S'\n", szKeyName);
688
689 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
690 szKeyName,
691 0,
692 KEY_ALL_ACCESS,
693 &hKey))
694 {
695 DPRINT1 ("Error: %lu\n", GetLastError());
696 return FALSE;
697 }
698
699 dwLength = MAX_PATH * sizeof(WCHAR);
700 if (RegQueryValueExW (hKey,
701 L"ProfileImagePath",
702 NULL,
703 NULL,
704 (LPBYTE)szRawImagePath,
705 &dwLength))
706 {
707 DPRINT1 ("Error: %lu\n", GetLastError());
708 RegCloseKey (hKey);
709 return FALSE;
710 }
711
712 RegCloseKey (hKey);
713
714 DPRINT ("RawImagePath: '%S'\n", szRawImagePath);
715
716 /* Expand it */
717 if (!ExpandEnvironmentStringsW (szRawImagePath,
718 szImagePath,
719 MAX_PATH))
720 {
721 DPRINT1 ("Error: %lu\n", GetLastError());
722 return FALSE;
723 }
724
725 DPRINT ("ImagePath: '%S'\n", szImagePath);
726
727 dwLength = wcslen (szImagePath);
728 if (dwLength > *lpcchSize)
729 {
730 DPRINT1 ("Buffer too small\n");
731 SetLastError (ERROR_INSUFFICIENT_BUFFER);
732 return FALSE;
733 }
734
735 *lpcchSize = dwLength;
736 wcscpy (lpProfileDir,
737 szImagePath);
738
739 return TRUE;
740 }
741
742
743 static BOOL
744 CheckForLoadedProfile (HANDLE hToken)
745 {
746 UNICODE_STRING SidString;
747 HKEY hKey;
748
749 DPRINT ("CheckForLoadedProfile() called \n");
750
751 if (!GetUserSidFromToken (hToken,
752 &SidString))
753 {
754 DPRINT1 ("GetUserSidFromToken() failed\n");
755 return FALSE;
756 }
757
758 if (RegOpenKeyExW (HKEY_USERS,
759 SidString.Buffer,
760 0,
761 KEY_ALL_ACCESS,
762 &hKey))
763 {
764 DPRINT ("Profile not loaded\n");
765 RtlFreeUnicodeString (&SidString);
766 return FALSE;
767 }
768
769 RegCloseKey (hKey);
770
771 RtlFreeUnicodeString (&SidString);
772
773 DPRINT ("Profile already loaded\n");
774
775 return TRUE;
776 }
777
778
779 BOOL WINAPI
780 LoadUserProfileA (HANDLE hToken,
781 LPPROFILEINFOA lpProfileInfo)
782 {
783 DPRINT ("LoadUserProfileA() not implemented\n");
784 return FALSE;
785 }
786
787
788 BOOL WINAPI
789 LoadUserProfileW (HANDLE hToken,
790 LPPROFILEINFOW lpProfileInfo)
791 {
792 WCHAR szUserHivePath[MAX_PATH];
793 UNICODE_STRING SidString;
794 DWORD dwLength;
795
796 DPRINT ("LoadUserProfileW() called\n");
797
798 /* Check profile info */
799 if (lpProfileInfo->dwSize != sizeof(PROFILEINFOW) ||
800 lpProfileInfo->lpUserName == NULL ||
801 lpProfileInfo->lpUserName[0] == 0)
802 {
803 SetLastError (ERROR_INVALID_PARAMETER);
804 return FALSE;
805 }
806
807 /* Don't load a profile twice */
808 if (CheckForLoadedProfile (hToken))
809 {
810 DPRINT ("Profile already loaded\n");
811 lpProfileInfo->hProfile = NULL;
812 return TRUE;
813 }
814
815 if (!GetProfilesDirectoryW (szUserHivePath,
816 &dwLength))
817 {
818 DPRINT1("GetProfilesDirectoryW() failed\n", GetLastError());
819 return FALSE;
820 }
821
822 wcscat (szUserHivePath, L"\\");
823 wcscat (szUserHivePath, lpProfileInfo->lpUserName);
824 if (!AppendSystemPostfix (szUserHivePath, MAX_PATH))
825 {
826 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
827 return FALSE;
828 }
829
830 /* Create user hive name */
831 wcscat (szUserHivePath, L"\\ntuser.dat");
832
833 DPRINT ("szUserHivePath: %S\n", szUserHivePath);
834
835 if (!GetUserSidFromToken (hToken,
836 &SidString))
837 {
838 DPRINT1 ("GetUserSidFromToken() failed\n");
839 return FALSE;
840 }
841
842 DPRINT ("SidString: '%wZ'\n", &SidString);
843
844 if (RegLoadKeyW (HKEY_USERS,
845 SidString.Buffer,
846 szUserHivePath))
847 {
848 DPRINT1 ("RegLoadKeyW() failed (Error %ld)\n", GetLastError());
849 RtlFreeUnicodeString (&SidString);
850 return FALSE;
851 }
852
853 if (RegOpenKeyExW (HKEY_USERS,
854 SidString.Buffer,
855 0,
856 KEY_ALL_ACCESS,
857 (PHKEY)&lpProfileInfo->hProfile))
858 {
859 DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", GetLastError());
860 RtlFreeUnicodeString (&SidString);
861 return FALSE;
862 }
863
864 RtlFreeUnicodeString (&SidString);
865
866 DPRINT ("LoadUserProfileW() done\n");
867
868 return TRUE;
869 }
870
871
872 BOOL WINAPI
873 UnloadUserProfile (HANDLE hToken,
874 HANDLE hProfile)
875 {
876 UNICODE_STRING SidString;
877
878 DPRINT ("UnloadUserProfile() called\n");
879
880 if (hProfile == NULL)
881 {
882 DPRINT1 ("Invalide profile handle\n");
883 SetLastError (ERROR_INVALID_PARAMETER);
884 return FALSE;
885 }
886
887 RegCloseKey (hProfile);
888
889 if (!GetUserSidFromToken (hToken,
890 &SidString))
891 {
892 DPRINT1 ("GetUserSidFromToken() failed\n");
893 return FALSE;
894 }
895
896 DPRINT ("SidString: '%wZ'\n", &SidString);
897
898 if (RegUnLoadKeyW (HKEY_USERS,
899 SidString.Buffer))
900 {
901 DPRINT1 ("RegUnLoadKeyW() failed (Error %ld)\n", GetLastError());
902 RtlFreeUnicodeString (&SidString);
903 return FALSE;
904 }
905
906 RtlFreeUnicodeString (&SidString);
907
908 DPRINT ("UnloadUserProfile() done\n");
909
910 return TRUE;
911 }
912
913 /* EOF */