wined3d: Drop support for WINED3DFMT_D32_UNORM.
[wine.git] / dlls / userenv / userenv_main.c
blob4a38c9a0544275fd10debdc4c148c25ee03b1d72
1 /*
2 * Implementation of userenv.dll
4 * Copyright 2006 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winternl.h"
29 #include "winnls.h"
30 #include "sddl.h"
31 #include "objbase.h"
32 #include "userenv.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL( userenv );
39 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
41 TRACE("%p %d %p\n", hinstDLL, fdwReason, lpvReserved);
43 switch (fdwReason)
45 case DLL_WINE_PREATTACH:
46 return FALSE; /* prefer native version */
47 case DLL_PROCESS_ATTACH:
48 DisableThreadLibraryCalls(hinstDLL);
49 break;
51 return TRUE;
54 static BOOL get_reg_value(WCHAR *env, HKEY hkey, const WCHAR *name, WCHAR *val, DWORD size)
56 DWORD type, res_size=0;
58 if (RegQueryValueExW(hkey, name, 0, &type, NULL, &res_size) != ERROR_SUCCESS)
59 return FALSE;
61 if (type == REG_SZ)
63 if (res_size > size)
64 return FALSE;
66 return RegQueryValueExW(hkey, name, 0, NULL, (BYTE*)val, &size) == ERROR_SUCCESS;
68 else if (type == REG_EXPAND_SZ)
70 UNICODE_STRING us_buf, us_expanded;
71 WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, res_size);
72 if (!buf)
73 return FALSE;
75 if (RegQueryValueExW(hkey, name, 0, NULL, (BYTE*)buf, &res_size) != ERROR_SUCCESS)
77 HeapFree(GetProcessHeap(), 0, buf);
78 return FALSE;
81 RtlInitUnicodeString(&us_buf, buf);
82 us_expanded.Buffer = val;
83 us_expanded.MaximumLength = size;
84 if (RtlExpandEnvironmentStrings_U(env, &us_buf, &us_expanded, &size) != STATUS_SUCCESS)
86 HeapFree(GetProcessHeap(), 0, buf);
87 return FALSE;
90 HeapFree(GetProcessHeap(), 0, buf);
91 return TRUE;
94 return FALSE;
97 static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_path)
99 static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
100 static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
101 static const WCHAR PATHW[] = {'P','A','T','H'};
103 UNICODE_STRING us_name, us_value;
104 WCHAR name[1024], value[1024];
105 DWORD ret, index, size;
107 for (index = 0; ; index++)
109 size = ARRAY_SIZE(name);
110 ret = RegEnumValueW(hkey, index, name, &size, NULL, NULL, NULL, NULL);
111 if (ret != ERROR_SUCCESS)
112 break;
114 if (!strcmpiW(name, SystemRootW)) continue;
115 if (!strcmpiW(name, SystemDriveW)) continue;
117 RtlInitUnicodeString(&us_name, name);
118 us_value.Buffer = value;
119 us_value.MaximumLength = sizeof(value);
120 if (!strncmpiW(name, PATHW, ARRAY_SIZE(PATHW)) &&
121 !RtlQueryEnvironmentVariable_U(*env, &us_name, &us_value))
123 if (!set_path)
124 continue;
126 size = strlenW(value)+1;
127 if (!get_reg_value(*env, hkey, name, value+size,
128 sizeof(value)-size*sizeof(WCHAR)))
129 continue;
131 value[size] = ';';
132 RtlInitUnicodeString(&us_value, value);
133 RtlSetEnvironmentVariable(env, &us_name, &us_value);
134 continue;
137 if (!get_reg_value(*env, hkey, name, value, sizeof(value)))
138 continue;
140 if(!value[0])
141 continue;
143 RtlInitUnicodeString(&us_value, value);
144 RtlSetEnvironmentVariable(env, &us_name, &us_value);
148 static void set_wow64_environment(WCHAR **env)
150 static const WCHAR versionW[] = {'S','o','f','t','w','a','r','e','\\',
151 'M','i','c','r','o','s','o','f','t','\\',
152 'W','i','n','d','o','w','s','\\',
153 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
154 static const WCHAR progdirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
155 static const WCHAR progdir86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
156 static const WCHAR progfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0};
157 static const WCHAR progw6432W[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0};
158 static const WCHAR commondirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
159 static const WCHAR commondir86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
160 static const WCHAR commonfilesW[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0};
161 static const WCHAR commonw6432W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0};
163 UNICODE_STRING nameW, valueW;
164 WCHAR buf[64];
165 HKEY hkey;
166 BOOL is_win64 = (sizeof(void *) > sizeof(int));
167 BOOL is_wow64;
169 IsWow64Process( GetCurrentProcess(), &is_wow64 );
171 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, versionW, 0,
172 KEY_READ|KEY_WOW64_64KEY, &hkey))
173 return;
175 /* set the ProgramFiles variables */
177 if (get_reg_value(*env, hkey, progdirW, buf, sizeof(buf)))
179 if (is_win64 || is_wow64)
181 RtlInitUnicodeString(&nameW, progw6432W);
182 RtlInitUnicodeString(&valueW, buf);
183 RtlSetEnvironmentVariable(env, &nameW, &valueW);
185 if (is_win64 || !is_wow64)
187 RtlInitUnicodeString(&nameW, progfilesW);
188 RtlInitUnicodeString(&valueW, buf);
189 RtlSetEnvironmentVariable(env, &nameW, &valueW);
192 if (is_wow64 && get_reg_value(*env, hkey, progdir86W, buf, sizeof(buf)))
194 RtlInitUnicodeString(&nameW, progfilesW);
195 RtlInitUnicodeString(&valueW, buf);
196 RtlSetEnvironmentVariable(env, &nameW, &valueW);
199 /* set the CommonProgramFiles variables */
201 if (get_reg_value(*env, hkey, commondirW, buf, sizeof(buf)))
203 if (is_win64 || is_wow64)
205 RtlInitUnicodeString(&nameW, commonw6432W);
206 RtlInitUnicodeString(&valueW, buf);
207 RtlSetEnvironmentVariable(env, &nameW, &valueW);
209 if (is_win64 || !is_wow64)
211 RtlInitUnicodeString(&nameW, commonfilesW);
212 RtlInitUnicodeString(&valueW, buf);
213 RtlSetEnvironmentVariable(env, &nameW, &valueW);
216 if (is_wow64 && get_reg_value(*env, hkey, commondir86W, buf, sizeof(buf)))
218 RtlInitUnicodeString(&nameW, commonfilesW);
219 RtlInitUnicodeString(&valueW, buf);
220 RtlSetEnvironmentVariable(env, &nameW, &valueW);
223 RegCloseKey(hkey);
226 BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
227 HANDLE hToken, BOOL bInherit )
229 static const WCHAR env_keyW[] = {'S','y','s','t','e','m','\\',
230 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
231 'C','o','n','t','r','o','l','\\',
232 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
233 'E','n','v','i','r','o','n','m','e','n','t',0};
234 static const WCHAR profile_keyW[] = {'S','o','f','t','w','a','r','e','\\',
235 'M','i','c','r','o','s','o','f','t','\\',
236 'W','i','n','d','o','w','s',' ','N','T','\\',
237 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
238 'P','r','o','f','i','l','e','L','i','s','t',0};
239 static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
240 static const WCHAR volatile_envW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
241 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
243 static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
244 static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
245 static const WCHAR PublicW[] = {'P','u','b','l','i','c',0};
246 static const WCHAR ALLUSERSPROFILEW[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0};
247 static const WCHAR USERNAMEW[] = {'U','S','E','R','N','A','M','E',0};
248 static const WCHAR USERPROFILEW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
249 static const WCHAR DefaultW[] = {'D','e','f','a','u','l','t',0};
250 static const WCHAR COMPUTERNAMEW[] = {'C','O','M','P','U','T','E','R','N','A','M','E',0};
252 WCHAR *env, buf[UNICODE_STRING_MAX_CHARS], profiles_dir[MAX_PATH];
253 UNICODE_STRING us_name, us_val;
254 DWORD len;
255 HKEY hkey, hsubkey;
257 TRACE("%p %p %d\n", lpEnvironment, hToken, bInherit );
259 if (!lpEnvironment)
260 return FALSE;
262 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, env_keyW, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
263 return FALSE;
265 if (RtlCreateEnvironment(bInherit, &env) != STATUS_SUCCESS)
267 RegCloseKey(hkey);
268 return FALSE;
271 if (!GetEnvironmentVariableW(SystemRootW, buf, UNICODE_STRING_MAX_CHARS))
273 if (!get_reg_value(env, hkey, SystemRootW, buf, UNICODE_STRING_MAX_CHARS))
275 buf[0] = 0;
276 WARN("SystemRoot variable not set\n");
279 RtlInitUnicodeString(&us_name, SystemRootW);
280 RtlInitUnicodeString(&us_val, buf);
281 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
283 if (!GetEnvironmentVariableW(SystemDriveW, buf, UNICODE_STRING_MAX_CHARS))
285 if (!get_reg_value(env, hkey, SystemRootW, buf, UNICODE_STRING_MAX_CHARS))
287 buf[0] = 0;
288 WARN("SystemDrive variable not set\n");
291 RtlInitUnicodeString(&us_name, SystemDriveW);
292 RtlInitUnicodeString(&us_val, buf);
293 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
295 set_registry_variables(&env, hkey, REG_SZ, !bInherit);
296 set_registry_variables(&env, hkey, REG_EXPAND_SZ, !bInherit);
298 if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
300 set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
301 set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
302 RegCloseKey(hsubkey);
305 if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
307 set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
308 set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
309 RegCloseKey(hsubkey);
311 RegCloseKey(hkey);
313 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, profile_keyW, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
315 if (get_reg_value(env, hkey, ProfilesDirectoryW, profiles_dir, MAX_PATH-sizeof(WCHAR)))
317 len = strlenW(profiles_dir);
318 if (profiles_dir[len-1] != '\\')
320 profiles_dir[len++] = '\\';
321 profiles_dir[len] = '\0';
324 if (get_reg_value(env, hkey, PublicW, buf, UNICODE_STRING_MAX_CHARS))
326 RtlInitUnicodeString(&us_name, ALLUSERSPROFILEW);
327 RtlInitUnicodeString(&us_val, buf);
328 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
331 else
333 profiles_dir[0] = 0;
336 RegCloseKey(hkey);
339 len = ARRAY_SIZE(buf);
340 if (GetComputerNameW(buf, &len))
342 RtlInitUnicodeString(&us_name, COMPUTERNAMEW);
343 RtlInitUnicodeString(&us_val, buf);
344 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
347 set_wow64_environment(&env);
349 if (!hToken)
351 if (profiles_dir[0])
353 len = strlenW(profiles_dir);
354 if (len*sizeof(WCHAR)+sizeof(DefaultW) < sizeof(buf))
356 memcpy(buf, profiles_dir, len*sizeof(WCHAR));
357 memcpy(buf+len, DefaultW, sizeof(DefaultW));
358 RtlInitUnicodeString(&us_name, USERPROFILEW);
359 RtlInitUnicodeString(&us_val, buf);
360 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
364 buf[0] = '.';
365 memcpy(buf+1, DefaultW, sizeof(DefaultW));
367 else
369 TOKEN_USER *token_user = NULL;
370 SID_NAME_USE use;
371 WCHAR *sidW;
372 DWORD size, tmp=0;
374 if (GetTokenInformation(hToken, TokenUser, NULL, 0, &len) ||
375 GetLastError()!=ERROR_INSUFFICIENT_BUFFER ||
376 !(token_user = HeapAlloc(GetProcessHeap(), 0, len)) ||
377 !GetTokenInformation(hToken, TokenUser, token_user, len, &len) ||
378 !ConvertSidToStringSidW(token_user->User.Sid, &sidW))
380 HeapFree(GetProcessHeap(), 0, token_user);
381 RtlDestroyEnvironment(env);
382 return FALSE;
385 len = strlenW(profiles_dir);
386 memcpy(buf, profiles_dir, len*sizeof(WCHAR));
388 size = UNICODE_STRING_MAX_CHARS-len;
389 if (LookupAccountSidW(NULL, token_user->User.Sid,
390 buf+len, &size, NULL, &tmp, &use))
392 RtlInitUnicodeString(&us_name, USERNAMEW);
393 RtlInitUnicodeString(&us_val, buf+len);
394 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
396 if (len)
398 RtlInitUnicodeString(&us_name, USERPROFILEW);
399 RtlInitUnicodeString(&us_val, buf);
400 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
404 HeapFree(GetProcessHeap(), 0, token_user);
405 strcpyW(buf, sidW);
406 LocalFree(sidW);
409 if (RegOpenKeyExW(HKEY_USERS, buf, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
411 if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
413 set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
414 set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
415 RegCloseKey(hsubkey);
418 if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
420 set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
421 set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
422 RegCloseKey(hsubkey);
424 RegCloseKey(hkey);
427 *lpEnvironment = env;
428 return TRUE;
431 BOOL WINAPI DestroyEnvironmentBlock(LPVOID lpEnvironment)
433 NTSTATUS r;
435 TRACE("%p\n", lpEnvironment);
436 r = RtlDestroyEnvironment(lpEnvironment);
437 if (r == STATUS_SUCCESS)
438 return TRUE;
439 return FALSE;
442 BOOL WINAPI ExpandEnvironmentStringsForUserA( HANDLE hToken, LPCSTR lpSrc,
443 LPSTR lpDest, DWORD dwSize )
445 BOOL ret;
447 TRACE("%p %s %p %d\n", hToken, debugstr_a(lpSrc), lpDest, dwSize);
449 ret = ExpandEnvironmentStringsA( lpSrc, lpDest, dwSize );
450 TRACE("<- %s\n", debugstr_a(lpDest));
451 return ret;
454 BOOL WINAPI ExpandEnvironmentStringsForUserW( HANDLE hToken, LPCWSTR lpSrc,
455 LPWSTR lpDest, DWORD dwSize )
457 BOOL ret;
459 TRACE("%p %s %p %d\n", hToken, debugstr_w(lpSrc), lpDest, dwSize);
461 ret = ExpandEnvironmentStringsW( lpSrc, lpDest, dwSize );
462 TRACE("<- %s\n", debugstr_w(lpDest));
463 return ret;
466 BOOL WINAPI GetDefaultUserProfileDirectoryA( LPSTR lpProfileDir, LPDWORD lpcchSize )
468 FIXME("%p %p\n", lpProfileDir, lpcchSize );
469 return FALSE;
472 BOOL WINAPI GetDefaultUserProfileDirectoryW( LPWSTR lpProfileDir, LPDWORD lpcchSize )
474 FIXME("%p %p\n", lpProfileDir, lpcchSize );
475 return FALSE;
478 BOOL WINAPI GetUserProfileDirectoryA( HANDLE hToken, LPSTR lpProfileDir,
479 LPDWORD lpcchSize )
481 BOOL ret;
482 WCHAR *dirW = NULL;
484 TRACE( "%p %p %p\n", hToken, lpProfileDir, lpcchSize );
486 if (!lpProfileDir || !lpcchSize)
488 SetLastError( ERROR_INVALID_PARAMETER );
489 return FALSE;
491 if (!(dirW = HeapAlloc( GetProcessHeap(), 0, *lpcchSize * sizeof(WCHAR) )))
492 return FALSE;
494 if ((ret = GetUserProfileDirectoryW( hToken, dirW, lpcchSize )))
495 WideCharToMultiByte( CP_ACP, 0, dirW, *lpcchSize, lpProfileDir, *lpcchSize, NULL, NULL );
497 HeapFree( GetProcessHeap(), 0, dirW );
498 return ret;
501 BOOL WINAPI GetUserProfileDirectoryW( HANDLE hToken, LPWSTR lpProfileDir,
502 LPDWORD lpcchSize )
504 static const WCHAR slashW[] = {'\\',0};
505 TOKEN_USER *t;
506 WCHAR *userW = NULL, *dirW = NULL;
507 DWORD len, dir_len, domain_len;
508 SID_NAME_USE use;
509 BOOL ret = FALSE;
511 TRACE( "%p %p %p\n", hToken, lpProfileDir, lpcchSize );
513 if (!lpcchSize)
515 SetLastError( ERROR_INVALID_PARAMETER );
516 return FALSE;
519 len = 0;
520 GetTokenInformation( hToken, TokenUser, NULL, 0, &len );
521 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE;
522 if (!(t = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
523 if (!GetTokenInformation( hToken, TokenUser, t, len, &len )) goto done;
525 len = domain_len = 0;
526 LookupAccountSidW( NULL, t->User.Sid, NULL, &len, NULL, &domain_len, NULL );
527 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
528 if (!(userW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto done;
529 if (!LookupAccountSidW( NULL, t->User.Sid, userW, &len, NULL, &domain_len, &use )) goto done;
531 dir_len = 0;
532 GetProfilesDirectoryW( NULL, &dir_len );
533 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
534 if (!(dirW = HeapAlloc( GetProcessHeap(), 0, (dir_len + 1) * sizeof(WCHAR) ))) goto done;
535 if (!GetProfilesDirectoryW( dirW, &dir_len )) goto done;
537 len += dir_len + 2;
538 if (*lpcchSize < len)
540 SetLastError( ERROR_INSUFFICIENT_BUFFER );
541 *lpcchSize = len;
542 goto done;
544 strcpyW( lpProfileDir, dirW );
545 strcatW( lpProfileDir, slashW );
546 strcatW( lpProfileDir, userW );
547 *lpcchSize = len;
548 ret = TRUE;
550 done:
551 HeapFree( GetProcessHeap(), 0, t );
552 HeapFree( GetProcessHeap(), 0, userW );
553 HeapFree( GetProcessHeap(), 0, dirW );
554 return ret;
557 static const char ProfileListA[] = "Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
559 BOOL WINAPI GetProfilesDirectoryA( LPSTR lpProfilesDir, LPDWORD lpcchSize )
561 static const char ProfilesDirectory[] = "ProfilesDirectory";
562 LONG l;
563 HKEY key;
564 BOOL ret = FALSE;
565 DWORD len = 0, expanded_len;
566 LPSTR unexpanded_profiles_dir = NULL;
568 TRACE("%p %p\n", lpProfilesDir, lpcchSize );
570 if (!lpProfilesDir || !lpcchSize)
572 SetLastError(ERROR_INVALID_PARAMETER);
573 return FALSE;
576 l = RegOpenKeyExA(HKEY_LOCAL_MACHINE, ProfileListA, 0, KEY_READ, &key);
577 if (l)
579 SetLastError(l);
580 return FALSE;
582 l = RegQueryValueExA(key, ProfilesDirectory, NULL, NULL, NULL, &len);
583 if (l)
585 SetLastError(l);
586 goto end;
588 unexpanded_profiles_dir = HeapAlloc(GetProcessHeap(), 0, len);
589 if (!unexpanded_profiles_dir)
591 SetLastError(ERROR_OUTOFMEMORY);
592 goto end;
594 l = RegQueryValueExA(key, ProfilesDirectory, NULL, NULL,
595 (BYTE *)unexpanded_profiles_dir, &len);
596 if (l)
598 SetLastError(l);
599 goto end;
601 expanded_len = ExpandEnvironmentStringsA(unexpanded_profiles_dir, NULL, 0);
602 /* The returned length doesn't include the NULL terminator. */
603 if (*lpcchSize < expanded_len - 1)
605 *lpcchSize = expanded_len - 1;
606 SetLastError(ERROR_INSUFFICIENT_BUFFER);
607 goto end;
609 *lpcchSize = expanded_len - 1;
610 /* The return value is also the expected length. */
611 ret = ExpandEnvironmentStringsA(unexpanded_profiles_dir, lpProfilesDir,
612 expanded_len) - 1;
613 end:
614 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir);
615 RegCloseKey(key);
616 return ret;
619 static const WCHAR ProfileListW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
621 BOOL WINAPI GetProfilesDirectoryW( LPWSTR lpProfilesDir, LPDWORD lpcchSize )
623 static const WCHAR ProfilesDirectory[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
624 LONG l;
625 HKEY key;
626 BOOL ret = FALSE;
627 DWORD len = 0, expanded_len;
628 LPWSTR unexpanded_profiles_dir = NULL;
630 TRACE("%p %p\n", lpProfilesDir, lpcchSize );
632 if (!lpcchSize)
634 SetLastError(ERROR_INVALID_PARAMETER);
635 return FALSE;
638 l = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, KEY_READ, &key);
639 if (l)
641 SetLastError(l);
642 return FALSE;
644 l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL, NULL, &len);
645 if (l)
647 SetLastError(l);
648 goto end;
650 unexpanded_profiles_dir = HeapAlloc(GetProcessHeap(), 0, len);
651 if (!unexpanded_profiles_dir)
653 SetLastError(ERROR_OUTOFMEMORY);
654 goto end;
656 l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL,
657 (BYTE *)unexpanded_profiles_dir, &len);
658 if (l)
660 SetLastError(l);
661 goto end;
663 expanded_len = ExpandEnvironmentStringsW(unexpanded_profiles_dir, NULL, 0);
664 /* The returned length doesn't include the NULL terminator. */
665 if (*lpcchSize < expanded_len - 1 || !lpProfilesDir)
667 *lpcchSize = expanded_len - 1;
668 SetLastError(ERROR_INSUFFICIENT_BUFFER);
669 goto end;
671 *lpcchSize = expanded_len - 1;
672 /* The return value is also the expected length. */
673 ret = ExpandEnvironmentStringsW(unexpanded_profiles_dir, lpProfilesDir,
674 expanded_len) - 1;
675 end:
676 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir);
677 RegCloseKey(key);
678 return ret;
681 BOOL WINAPI GetAllUsersProfileDirectoryA( LPSTR lpProfileDir, LPDWORD lpcchSize )
683 FIXME("%p %p\n", lpProfileDir, lpcchSize);
684 return FALSE;
687 BOOL WINAPI GetAllUsersProfileDirectoryW( LPWSTR lpProfileDir, LPDWORD lpcchSize )
689 FIXME("%p %p\n", lpProfileDir, lpcchSize);
690 return FALSE;
693 BOOL WINAPI GetProfileType( DWORD *pdwFlags )
695 FIXME("%p\n", pdwFlags );
696 *pdwFlags = 0;
697 return TRUE;
700 BOOL WINAPI LoadUserProfileA( HANDLE hToken, LPPROFILEINFOA lpProfileInfo )
702 FIXME("%p %p\n", hToken, lpProfileInfo );
703 lpProfileInfo->hProfile = HKEY_CURRENT_USER;
704 return TRUE;
707 BOOL WINAPI LoadUserProfileW( HANDLE hToken, LPPROFILEINFOW lpProfileInfo )
709 FIXME("%p %p\n", hToken, lpProfileInfo );
710 lpProfileInfo->hProfile = HKEY_CURRENT_USER;
711 return TRUE;
714 BOOL WINAPI RegisterGPNotification( HANDLE event, BOOL machine )
716 FIXME("%p %d\n", event, machine );
717 return TRUE;
720 BOOL WINAPI UnregisterGPNotification( HANDLE event )
722 FIXME("%p\n", event );
723 return TRUE;
726 BOOL WINAPI UnloadUserProfile( HANDLE hToken, HANDLE hProfile )
728 FIXME("(%p, %p): stub\n", hToken, hProfile);
729 return FALSE;
732 HANDLE WINAPI EnterCriticalPolicySection(BOOL bMachine)
734 FIXME("(%x)\n", bMachine);
735 SetLastError(ERROR_ACCESS_DENIED);
736 return NULL;
739 BOOL WINAPI LeaveCriticalPolicySection(HANDLE hSection)
741 FIXME("(%p)\n", hSection);
742 return TRUE;
745 DWORD WINAPI GetAppliedGPOListW(DWORD dwFlags, LPCWSTR pMachineName, PSID pSidUser, GUID *pGuidExtension,
746 PGROUP_POLICY_OBJECTW *ppGPOList)
748 FIXME("(%x %s %p %s %p)\n", dwFlags, debugstr_w(pMachineName), pSidUser, debugstr_guid(pGuidExtension), ppGPOList);
749 return ERROR_ACCESS_DENIED;
752 /******************************************************************************
753 * USERENV.138
755 * Create .lnk file
757 * PARAMETERS
758 * int csidl [in] well-known directory location to create link in
759 * LPCSTR lnk_dir [in] directory (relative to directory specified by csidl) to create link in
760 * LPCSTR lnk_filename [in] filename of the link file without .lnk extension
761 * LPCSTR lnk_target [in] file/directory pointed to by link
762 * LPCSTR lnk_iconfile [in] link icon resource filename
763 * DWORD lnk_iconid [in] link icon resource id in file referred by lnk_iconfile
764 * LPCSTR work_directory [in] link target's work directory
765 * WORD hotkey [in] link hotkey (virtual key id)
766 * DWORD win_state [in] initial window size (SW_SHOWMAXIMIZED to start maximized,
767 * SW_SHOWMINNOACTIVE to start minimized, everything else is default state)
768 * LPCSTR comment [in] comment - link's comment
769 * LPCSTR loc_filename_resfile [in] resource file which holds localized filename for this link file
770 * DWORD loc_filename_resid [in] resource id for this link file's localized filename
772 * RETURNS
773 * TRUE: Link file was successfully created
774 * FALSE: Link file was not created
776 BOOL WINAPI USERENV_138( int csidl, LPCSTR lnk_dir, LPCSTR lnk_filename,
777 LPCSTR lnk_target, LPCSTR lnk_iconfile, DWORD lnk_iconid,
778 LPCSTR work_directory, WORD hotkey, DWORD win_state, LPCSTR comment,
779 LPCSTR loc_filename_resfile, DWORD loc_filename_resid)
781 FIXME("(%d,%s,%s,%s,%s,%d,%s,0x%x,%d,%s,%s,%d) - stub\n", csidl, debugstr_a(lnk_dir),
782 debugstr_a(lnk_filename), debugstr_a(lnk_target), debugstr_a(lnk_iconfile),
783 lnk_iconid, debugstr_a(work_directory), hotkey, win_state,
784 debugstr_a(comment), debugstr_a(loc_filename_resfile), loc_filename_resid );
786 return FALSE;