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
24 #define WIN32_NO_STATUS
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL( userenv );
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
39 TRACE("%p %d %p\n", hinstDLL, fdwReason, lpvReserved);
43 case DLL_WINE_PREATTACH:
44 return FALSE; /* prefer native version */
45 case DLL_PROCESS_ATTACH:
46 DisableThreadLibraryCalls(hinstDLL);
48 case DLL_PROCESS_DETACH:
54 BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
55 HANDLE hToken, BOOL bInherit )
59 TRACE("%p %p %d\n", lpEnvironment, hToken, bInherit );
64 r = RtlCreateEnvironment(bInherit, (WCHAR **)lpEnvironment);
65 if (r == STATUS_SUCCESS)
70 BOOL WINAPI DestroyEnvironmentBlock(LPVOID lpEnvironment)
74 TRACE("%p\n", lpEnvironment);
75 r = RtlDestroyEnvironment(lpEnvironment);
76 if (r == STATUS_SUCCESS)
81 BOOL WINAPI ExpandEnvironmentStringsForUserA( HANDLE hToken, LPCSTR lpSrc,
82 LPSTR lpDest, DWORD dwSize )
86 TRACE("%p %s %p %d\n", hToken, debugstr_a(lpSrc), lpDest, dwSize);
88 ret = ExpandEnvironmentStringsA( lpSrc, lpDest, dwSize );
89 TRACE("<- %s\n", debugstr_a(lpDest));
93 BOOL WINAPI ExpandEnvironmentStringsForUserW( HANDLE hToken, LPCWSTR lpSrc,
94 LPWSTR lpDest, DWORD dwSize )
98 TRACE("%p %s %p %d\n", hToken, debugstr_w(lpSrc), lpDest, dwSize);
100 ret = ExpandEnvironmentStringsW( lpSrc, lpDest, dwSize );
101 TRACE("<- %s\n", debugstr_w(lpDest));
105 BOOL WINAPI GetDefaultUserProfileDirectoryA( LPSTR lpProfileDir, LPDWORD lpcchSize )
107 FIXME("%p %p\n", lpProfileDir, lpcchSize );
111 BOOL WINAPI GetDefaultUserProfileDirectoryW( LPWSTR lpProfileDir, LPDWORD lpcchSize )
113 FIXME("%p %p\n", lpProfileDir, lpcchSize );
117 BOOL WINAPI GetUserProfileDirectoryA( HANDLE hToken, LPSTR lpProfileDir,
123 TRACE( "%p %p %p\n", hToken, lpProfileDir, lpcchSize );
125 if (!lpProfileDir || !lpcchSize)
127 SetLastError( ERROR_INVALID_PARAMETER );
130 if (!(dirW = HeapAlloc( GetProcessHeap(), 0, *lpcchSize * sizeof(WCHAR) )))
133 if ((ret = GetUserProfileDirectoryW( hToken, dirW, lpcchSize )))
134 WideCharToMultiByte( CP_ACP, 0, dirW, *lpcchSize, lpProfileDir, *lpcchSize, NULL, NULL );
136 HeapFree( GetProcessHeap(), 0, dirW );
140 BOOL WINAPI GetUserProfileDirectoryW( HANDLE hToken, LPWSTR lpProfileDir,
143 static const WCHAR slashW[] = {'\\',0};
145 WCHAR *userW = NULL, *dirW = NULL;
146 DWORD len, dir_len, domain_len;
150 TRACE( "%p %p %p\n", hToken, lpProfileDir, lpcchSize );
154 SetLastError( ERROR_INVALID_PARAMETER );
159 GetTokenInformation( hToken, TokenUser, NULL, 0, &len );
160 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE;
161 if (!(t = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
162 if (!GetTokenInformation( hToken, TokenUser, t, len, &len )) goto done;
164 len = domain_len = 0;
165 LookupAccountSidW( NULL, t->User.Sid, NULL, &len, NULL, &domain_len, NULL );
166 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
167 if (!(userW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto done;
168 if (!LookupAccountSidW( NULL, t->User.Sid, userW, &len, NULL, &domain_len, &use )) goto done;
171 GetProfilesDirectoryW( NULL, &dir_len );
172 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
173 if (!(dirW = HeapAlloc( GetProcessHeap(), 0, (dir_len + 1) * sizeof(WCHAR) ))) goto done;
174 if (!GetProfilesDirectoryW( dirW, &dir_len )) goto done;
177 if (*lpcchSize < len)
179 SetLastError( ERROR_INSUFFICIENT_BUFFER );
183 strcpyW( lpProfileDir, dirW );
184 strcatW( lpProfileDir, slashW );
185 strcatW( lpProfileDir, userW );
190 HeapFree( GetProcessHeap(), 0, t );
191 HeapFree( GetProcessHeap(), 0, userW );
192 HeapFree( GetProcessHeap(), 0, dirW );
196 static const char ProfileListA[] = "Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
198 BOOL WINAPI GetProfilesDirectoryA( LPSTR lpProfilesDir, LPDWORD lpcchSize )
200 static const char ProfilesDirectory[] = "ProfilesDirectory";
204 DWORD len = 0, expanded_len;
205 LPSTR unexpanded_profiles_dir = NULL;
207 TRACE("%p %p\n", lpProfilesDir, lpcchSize );
209 if (!lpProfilesDir || !lpcchSize)
211 SetLastError(ERROR_INVALID_PARAMETER);
215 l = RegOpenKeyExA(HKEY_LOCAL_MACHINE, ProfileListA, 0, KEY_READ, &key);
221 l = RegQueryValueExA(key, ProfilesDirectory, NULL, NULL, NULL, &len);
227 unexpanded_profiles_dir = HeapAlloc(GetProcessHeap(), 0, len);
228 if (!unexpanded_profiles_dir)
230 SetLastError(ERROR_OUTOFMEMORY);
233 l = RegQueryValueExA(key, ProfilesDirectory, NULL, NULL,
234 (BYTE *)unexpanded_profiles_dir, &len);
240 expanded_len = ExpandEnvironmentStringsA(unexpanded_profiles_dir, NULL, 0);
241 /* The returned length doesn't include the NULL terminator. */
242 if (*lpcchSize < expanded_len - 1)
244 *lpcchSize = expanded_len - 1;
245 SetLastError(ERROR_INSUFFICIENT_BUFFER);
248 *lpcchSize = expanded_len - 1;
249 /* The return value is also the expected length. */
250 ret = ExpandEnvironmentStringsA(unexpanded_profiles_dir, lpProfilesDir,
253 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir);
258 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};
260 BOOL WINAPI GetProfilesDirectoryW( LPWSTR lpProfilesDir, LPDWORD lpcchSize )
262 static const WCHAR ProfilesDirectory[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
266 DWORD len = 0, expanded_len;
267 LPWSTR unexpanded_profiles_dir = NULL;
269 TRACE("%p %p\n", lpProfilesDir, lpcchSize );
273 SetLastError(ERROR_INVALID_PARAMETER);
277 l = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, KEY_READ, &key);
283 l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL, NULL, &len);
289 unexpanded_profiles_dir = HeapAlloc(GetProcessHeap(), 0, len);
290 if (!unexpanded_profiles_dir)
292 SetLastError(ERROR_OUTOFMEMORY);
295 l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL,
296 (BYTE *)unexpanded_profiles_dir, &len);
302 expanded_len = ExpandEnvironmentStringsW(unexpanded_profiles_dir, NULL, 0);
303 /* The returned length doesn't include the NULL terminator. */
304 if (*lpcchSize < expanded_len - 1 || !lpProfilesDir)
306 *lpcchSize = expanded_len - 1;
307 SetLastError(ERROR_INSUFFICIENT_BUFFER);
310 *lpcchSize = expanded_len - 1;
311 /* The return value is also the expected length. */
312 ret = ExpandEnvironmentStringsW(unexpanded_profiles_dir, lpProfilesDir,
315 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir);
320 BOOL WINAPI GetAllUsersProfileDirectoryA( LPSTR lpProfileDir, LPDWORD lpcchSize )
322 FIXME("%p %p\n", lpProfileDir, lpcchSize);
326 BOOL WINAPI GetAllUsersProfileDirectoryW( LPWSTR lpProfileDir, LPDWORD lpcchSize )
328 FIXME("%p %p\n", lpProfileDir, lpcchSize);
332 BOOL WINAPI GetProfileType( DWORD *pdwFlags )
334 FIXME("%p\n", pdwFlags );
339 BOOL WINAPI LoadUserProfileA( HANDLE hToken, LPPROFILEINFOA lpProfileInfo )
341 FIXME("%p %p\n", hToken, lpProfileInfo );
342 lpProfileInfo->hProfile = HKEY_CURRENT_USER;
346 BOOL WINAPI LoadUserProfileW( HANDLE hToken, LPPROFILEINFOW lpProfileInfo )
348 FIXME("%p %p\n", hToken, lpProfileInfo );
349 lpProfileInfo->hProfile = HKEY_CURRENT_USER;
353 BOOL WINAPI RegisterGPNotification( HANDLE event, BOOL machine )
355 FIXME("%p %d\n", event, machine );
359 BOOL WINAPI UnregisterGPNotification( HANDLE event )
361 FIXME("%p\n", event );
365 BOOL WINAPI UnloadUserProfile( HANDLE hToken, HANDLE hProfile )
367 FIXME("(%p, %p): stub\n", hToken, hProfile);
371 /******************************************************************************
377 * int csidl [in] well-known directory location to create link in
378 * LPCSTR lnk_dir [in] directory (relative to directory specified by csidl) to create link in
379 * LPCSTR lnk_filename [in] filename of the link file without .lnk extension
380 * LPCSTR lnk_target [in] file/directory pointed to by link
381 * LPCSTR lnk_iconfile [in] link icon resource filename
382 * DWORD lnk_iconid [in] link icon resource id in file referred by lnk_iconfile
383 * LPCSTR work_directory [in] link target's work directory
384 * WORD hotkey [in] link hotkey (virtual key id)
385 * DWORD win_state [in] initial window size (SW_SHOWMAXIMIZED to start maximized,
386 * SW_SHOWMINNOACTIVE to start minimized, everything else is default state)
387 * LPCSTR comment [in] comment - link's comment
388 * LPCSTR loc_filename_resfile [in] resource file which holds localized filename for this link file
389 * DWORD loc_filename_resid [in] resource id for this link file's localized filename
392 * TRUE: Link file was successfully created
393 * FALSE: Link file was not created
395 BOOL WINAPI USERENV_138( int csidl, LPCSTR lnk_dir, LPCSTR lnk_filename,
396 LPCSTR lnk_target, LPCSTR lnk_iconfile, DWORD lnk_iconid,
397 LPCSTR work_directory, WORD hotkey, DWORD win_state, LPCSTR comment,
398 LPCSTR loc_filename_resfile, DWORD loc_filename_resid)
400 FIXME("(%d,%s,%s,%s,%s,%d,%s,0x%x,%d,%s,%s,%d) - stub\n", csidl, debugstr_a(lnk_dir),
401 debugstr_a(lnk_filename), debugstr_a(lnk_target), debugstr_a(lnk_iconfile),
402 lnk_iconid, debugstr_a(work_directory), hotkey, win_state,
403 debugstr_a(comment), debugstr_a(loc_filename_resfile), loc_filename_resid );