ntoskrnl.exe/tests: Fix path buffer allocation size.
[wine.git] / dlls / advapi32 / advapi.c
blob1c528ef7419d5e40997489d2411628441ad18488
1 /*
2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
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 <errno.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "winerror.h"
32 #include "wincred.h"
33 #include "wct.h"
35 #include "wine/library.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 #include "advapi32_misc.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
43 /******************************************************************************
44 * GetUserNameA [ADVAPI32.@]
46 * Get the current user name.
48 * PARAMS
49 * lpszName [O] Destination for the user name.
50 * lpSize [I/O] Size of lpszName.
52 * RETURNS
53 * Success: The length of the user name, including terminating NUL.
54 * Failure: ERROR_MORE_DATA if *lpSize is too small.
56 BOOL WINAPI
57 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
59 WCHAR *buffer;
60 BOOL ret;
61 DWORD sizeW = *lpSize;
63 if (!(buffer = heap_alloc( sizeW * sizeof(WCHAR) )))
65 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
66 return FALSE;
69 ret = GetUserNameW( buffer, &sizeW );
70 if (ret)
71 *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL );
72 else
73 *lpSize = sizeW;
75 heap_free( buffer );
76 return ret;
79 /******************************************************************************
80 * GetUserNameW [ADVAPI32.@]
82 * See GetUserNameA.
84 BOOL WINAPI
85 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
87 const char *name = wine_get_user_name();
88 DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
89 LPWSTR backslash;
91 if (len > *lpSize)
93 SetLastError( ERROR_INSUFFICIENT_BUFFER );
94 *lpSize = len;
95 return FALSE;
98 *lpSize = len;
99 MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
101 /* Word uses the user name to create named mutexes and file mappings,
102 * and backslashes in the name cause the creation to fail.
103 * Also, Windows doesn't return the domain name in the user name even when
104 * joined to a domain. A Unix box joined to a domain using winbindd will
105 * contain the domain name in the username. So we need to cut this off.
106 * FIXME: Only replaces forward and backslashes for now, should get the
107 * winbind separator char from winbindd and replace that.
109 for (i = 0; lpszName[i]; i++)
110 if (lpszName[i] == '/') lpszName[i] = '\\';
112 backslash = strrchrW(lpszName, '\\');
113 if (backslash == NULL)
114 return TRUE;
116 len = lstrlenW(backslash);
117 memmove(lpszName, backslash + 1, len * sizeof(WCHAR));
118 *lpSize = len;
119 return TRUE;
122 /******************************************************************************
123 * GetCurrentHwProfileA [ADVAPI32.@]
125 * Get the current hardware profile.
127 * PARAMS
128 * pInfo [O] Destination for hardware profile information.
130 * RETURNS
131 * Success: TRUE. pInfo is updated with the hardware profile details.
132 * Failure: FALSE.
134 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
136 FIXME("(%p) semi-stub\n", pInfo);
137 pInfo->dwDockInfo = DOCKINFO_DOCKED;
138 strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
139 strcpy(pInfo->szHwProfileName,"Wine Profile");
140 return TRUE;
143 /******************************************************************************
144 * GetCurrentHwProfileW [ADVAPI32.@]
146 * See GetCurrentHwProfileA.
148 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
150 FIXME("(%p)\n", pInfo);
151 return FALSE;
155 /**************************************************************************
156 * IsTextUnicode (ADVAPI32.@)
158 * Attempt to guess whether a text buffer is Unicode.
160 * PARAMS
161 * buf [I] Text buffer to test
162 * len [I] Length of buf
163 * flags [O] Destination for test results
165 * RETURNS
166 * TRUE if the buffer is likely Unicode, FALSE otherwise.
168 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
170 return RtlIsTextUnicode( buf, len, flags );
174 /******************************************************************************
175 * AbortSystemShutdownA [ADVAPI32.@]
177 * Stop a system shutdown if one is in progress.
179 * PARAMS
180 * lpMachineName [I] Name of machine to not shutdown.
182 * RETURNS
183 * Success: TRUE.
184 * Failure: FALSE.
186 * NOTES
187 * The Wine implementation of this function is a harmless stub.
189 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
191 TRACE("stub %s (harmless)\n", debugstr_a(lpMachineName));
192 return TRUE;
195 /******************************************************************************
196 * AbortSystemShutdownW [ADVAPI32.@]
198 * See AbortSystemShutdownA.
200 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
202 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
203 return TRUE;
206 /******************************************************************************
207 * InitiateSystemShutdownExA [ADVAPI32.@]
209 * Initiate a shutdown or optionally restart the computer.
211 * PARAMS
212 * lpMachineName [I] Network name of machine to shutdown.
213 * lpMessage [I] Message displayed in shutdown dialog box.
214 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
215 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
216 * displayed requesting user to close apps.
217 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
218 * system flushes all caches to disk and clears
219 * the screen
220 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
221 * code.
223 * RETURNS
224 * Success: TRUE
225 * Failure: FALSE
227 * NOTES
228 * if lpMachineName is NULL, the local computer is shutdown.
230 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
231 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
232 DWORD dwReason)
234 FIXME("%s %s %d %d %d %#x\n", debugstr_a(lpMachineName),
235 debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
236 bRebootAfterShutdown, dwReason);
237 return TRUE;
240 /******************************************************************************
241 * InitiateSystemShutdownExW [ADVAPI32.@]
243 * See InitiateSystemShutdownExA.
245 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
246 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
247 DWORD dwReason)
249 FIXME("%s %s %d %d %d %#x\n", debugstr_w(lpMachineName),
250 debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
251 bRebootAfterShutdown, dwReason);
252 return TRUE;
255 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
256 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
258 return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
259 bForceAppsClosed, bRebootAfterShutdown,
260 SHTDN_REASON_MAJOR_LEGACY_API );
263 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
264 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
266 return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
267 bForceAppsClosed, bRebootAfterShutdown,
268 SHTDN_REASON_MAJOR_LEGACY_API );
271 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
272 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
274 WCHAR *usernameW = NULL, *domainW = NULL, *passwordW = NULL;
275 BOOL ret = FALSE;
277 TRACE("%s %s %p 0x%08x 0x%08x %p\n", debugstr_a(lpszUsername),
278 debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
280 if (lpszUsername && !(usernameW = strdupAW( lpszUsername ))) return FALSE;
281 if (lpszDomain && !(domainW = strdupAW( lpszUsername ))) goto done;
282 if (lpszPassword && !(passwordW = strdupAW( lpszPassword ))) goto done;
284 ret = LogonUserW( usernameW, domainW, passwordW, dwLogonType, dwLogonProvider, phToken );
286 done:
287 heap_free( usernameW );
288 heap_free( domainW );
289 heap_free( passwordW );
290 return ret;
293 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
294 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
296 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
297 debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
299 *phToken = (HANDLE *)0xdeadbeef;
300 return TRUE;
303 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
305 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
306 WCHAR *szCommandLine, DWORD *pcchCommandLine )
308 static const WCHAR szMsi[] = { 'm','s','i',0 };
309 fnMsiProvideComponentFromDescriptor mpcfd;
310 HMODULE hmsi;
311 UINT r = ERROR_CALL_NOT_IMPLEMENTED;
313 TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
315 hmsi = LoadLibraryW( szMsi );
316 if (!hmsi)
317 return r;
318 mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
319 "MsiProvideComponentFromDescriptorW" );
320 if (mpcfd)
321 r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
322 FreeLibrary( hmsi );
323 return r;
326 /***********************************************************************
327 * RegisterWaitChainCOMCallback (ole32.@)
329 void WINAPI RegisterWaitChainCOMCallback(PCOGETCALLSTATE call_state_cb,
330 PCOGETACTIVATIONSTATE activation_state_cb)
332 FIXME("%p, %p\n", call_state_cb, activation_state_cb);