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