advapi32: Set last error directly in GetUserName.
[wine.git] / dlls / advapi32 / advapi.c
blob589405b59e66f7394631a718d8f019239cd18f89
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/unicode.h"
36 #include "wine/debug.h"
38 #include "advapi32_misc.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
42 /******************************************************************************
43 * GetUserNameA [ADVAPI32.@]
45 BOOL WINAPI GetUserNameA( LPSTR name, LPDWORD size )
47 DWORD len = GetEnvironmentVariableA( "WINEUSERNAME", name, *size );
48 BOOL ret;
50 if (!len) return FALSE;
51 if ((ret = (len < *size))) len++;
52 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
53 *size = len;
54 return ret;
57 /******************************************************************************
58 * GetUserNameW [ADVAPI32.@]
60 BOOL WINAPI GetUserNameW( LPWSTR name, LPDWORD size )
62 static const WCHAR wineusernameW[] = {'W','I','N','E','U','S','E','R','N','A','M','E',0};
63 DWORD len = GetEnvironmentVariableW( wineusernameW, name, *size );
64 BOOL ret;
66 if (!len) return FALSE;
67 if ((ret = (len < *size))) len++;
68 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
69 *size = len;
70 return ret;
73 /******************************************************************************
74 * GetCurrentHwProfileA [ADVAPI32.@]
76 * Get the current hardware profile.
78 * PARAMS
79 * pInfo [O] Destination for hardware profile information.
81 * RETURNS
82 * Success: TRUE. pInfo is updated with the hardware profile details.
83 * Failure: FALSE.
85 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
87 FIXME("(%p) semi-stub\n", pInfo);
88 pInfo->dwDockInfo = DOCKINFO_DOCKED;
89 strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
90 strcpy(pInfo->szHwProfileName,"Wine Profile");
91 return TRUE;
94 /******************************************************************************
95 * GetCurrentHwProfileW [ADVAPI32.@]
97 * See GetCurrentHwProfileA.
99 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
101 FIXME("(%p)\n", pInfo);
102 return FALSE;
106 /**************************************************************************
107 * IsTextUnicode (ADVAPI32.@)
109 * Attempt to guess whether a text buffer is Unicode.
111 * PARAMS
112 * buf [I] Text buffer to test
113 * len [I] Length of buf
114 * flags [O] Destination for test results
116 * RETURNS
117 * TRUE if the buffer is likely Unicode, FALSE otherwise.
119 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
121 return RtlIsTextUnicode( buf, len, flags );
125 /******************************************************************************
126 * AbortSystemShutdownA [ADVAPI32.@]
128 * Stop a system shutdown if one is in progress.
130 * PARAMS
131 * lpMachineName [I] Name of machine to not shutdown.
133 * RETURNS
134 * Success: TRUE.
135 * Failure: FALSE.
137 * NOTES
138 * The Wine implementation of this function is a harmless stub.
140 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
142 TRACE("stub %s (harmless)\n", debugstr_a(lpMachineName));
143 return TRUE;
146 /******************************************************************************
147 * AbortSystemShutdownW [ADVAPI32.@]
149 * See AbortSystemShutdownA.
151 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
153 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
154 return TRUE;
157 /******************************************************************************
158 * InitiateSystemShutdownExA [ADVAPI32.@]
160 * Initiate a shutdown or optionally restart the computer.
162 * PARAMS
163 * lpMachineName [I] Network name of machine to shutdown.
164 * lpMessage [I] Message displayed in shutdown dialog box.
165 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
166 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
167 * displayed requesting user to close apps.
168 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
169 * system flushes all caches to disk and clears
170 * the screen
171 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
172 * code.
174 * RETURNS
175 * Success: TRUE
176 * Failure: FALSE
178 * NOTES
179 * if lpMachineName is NULL, the local computer is shutdown.
181 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
182 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
183 DWORD dwReason)
185 FIXME("%s %s %d %d %d %#x\n", debugstr_a(lpMachineName),
186 debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
187 bRebootAfterShutdown, dwReason);
188 return TRUE;
191 /******************************************************************************
192 * InitiateSystemShutdownExW [ADVAPI32.@]
194 * See InitiateSystemShutdownExA.
196 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
197 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
198 DWORD dwReason)
200 FIXME("%s %s %d %d %d %#x\n", debugstr_w(lpMachineName),
201 debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
202 bRebootAfterShutdown, dwReason);
203 return TRUE;
206 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
207 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
209 return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
210 bForceAppsClosed, bRebootAfterShutdown,
211 SHTDN_REASON_MAJOR_LEGACY_API );
214 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
215 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
217 return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
218 bForceAppsClosed, bRebootAfterShutdown,
219 SHTDN_REASON_MAJOR_LEGACY_API );
222 /***********************************************************************
223 * InitiateShutdownA [ADVAPI32.@]
225 DWORD WINAPI InitiateShutdownA(char *name, char *message, DWORD seconds, DWORD flags, DWORD reason)
227 FIXME("%s, %s, %d, %d, %d stub\n", debugstr_a(name), debugstr_a(message), seconds, flags, reason);
228 return ERROR_CALL_NOT_IMPLEMENTED;
231 /***********************************************************************
232 * InitiateShutdownW [ADVAPI32.@]
234 DWORD WINAPI InitiateShutdownW(WCHAR *name, WCHAR *message, DWORD seconds, DWORD flags, DWORD reason)
236 FIXME("%s, %s, %d, %d, %d stub\n", debugstr_w(name), debugstr_w(message), seconds, flags, reason);
237 return ERROR_CALL_NOT_IMPLEMENTED;
240 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
241 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
243 WCHAR *usernameW = NULL, *domainW = NULL, *passwordW = NULL;
244 BOOL ret = FALSE;
246 TRACE("%s %s %p 0x%08x 0x%08x %p\n", debugstr_a(lpszUsername),
247 debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
249 if (lpszUsername && !(usernameW = strdupAW( lpszUsername ))) return FALSE;
250 if (lpszDomain && !(domainW = strdupAW( lpszUsername ))) goto done;
251 if (lpszPassword && !(passwordW = strdupAW( lpszPassword ))) goto done;
253 ret = LogonUserW( usernameW, domainW, passwordW, dwLogonType, dwLogonProvider, phToken );
255 done:
256 heap_free( usernameW );
257 heap_free( domainW );
258 heap_free( passwordW );
259 return ret;
262 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
263 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
265 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
266 debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
268 *phToken = (HANDLE *)0xdeadbeef;
269 return TRUE;
272 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
274 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
275 WCHAR *szCommandLine, DWORD *pcchCommandLine )
277 static const WCHAR szMsi[] = { 'm','s','i',0 };
278 fnMsiProvideComponentFromDescriptor mpcfd;
279 HMODULE hmsi;
280 UINT r = ERROR_CALL_NOT_IMPLEMENTED;
282 TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
284 hmsi = LoadLibraryW( szMsi );
285 if (!hmsi)
286 return r;
287 mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
288 "MsiProvideComponentFromDescriptorW" );
289 if (mpcfd)
290 r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
291 FreeLibrary( hmsi );
292 return r;
295 /***********************************************************************
296 * RegisterWaitChainCOMCallback (ole32.@)
298 void WINAPI RegisterWaitChainCOMCallback(PCOGETCALLSTATE call_state_cb,
299 PCOGETACTIVATIONSTATE activation_state_cb)
301 FIXME("%p, %p\n", call_state_cb, activation_state_cb);