cryptext: Add stubs for CryptExtAddPFX/CryptExtAddPFXW.
[wine.git] / dlls / advapi32 / advapi.c
blob646be59503b2a52be5e0247398cd2746f23586dc
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"
34 #include "wine/library.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 * Get the current user name.
47 * PARAMS
48 * lpszName [O] Destination for the user name.
49 * lpSize [I/O] Size of lpszName.
51 * RETURNS
52 * Success: The length of the user name, including terminating NUL.
53 * Failure: ERROR_MORE_DATA if *lpSize is too small.
55 BOOL WINAPI
56 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
58 WCHAR *buffer;
59 BOOL ret;
60 DWORD sizeW = *lpSize;
62 if (!(buffer = heap_alloc( sizeW * sizeof(WCHAR) )))
64 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
65 return FALSE;
68 ret = GetUserNameW( buffer, &sizeW );
69 if (ret)
70 *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL );
71 else
72 *lpSize = sizeW;
74 heap_free( buffer );
75 return ret;
78 /******************************************************************************
79 * GetUserNameW [ADVAPI32.@]
81 * See GetUserNameA.
83 BOOL WINAPI
84 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
86 const char *name = wine_get_user_name();
87 DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
88 LPWSTR backslash;
90 if (len > *lpSize)
92 SetLastError( ERROR_INSUFFICIENT_BUFFER );
93 *lpSize = len;
94 return FALSE;
97 *lpSize = len;
98 MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
100 /* Word uses the user name to create named mutexes and file mappings,
101 * and backslashes in the name cause the creation to fail.
102 * Also, Windows doesn't return the domain name in the user name even when
103 * joined to a domain. A Unix box joined to a domain using winbindd will
104 * contain the domain name in the username. So we need to cut this off.
105 * FIXME: Only replaces forward and backslashes for now, should get the
106 * winbind separator char from winbindd and replace that.
108 for (i = 0; lpszName[i]; i++)
109 if (lpszName[i] == '/') lpszName[i] = '\\';
111 backslash = strrchrW(lpszName, '\\');
112 if (backslash == NULL)
113 return TRUE;
115 len = lstrlenW(backslash);
116 memmove(lpszName, backslash + 1, len * sizeof(WCHAR));
117 *lpSize = len;
118 return TRUE;
121 /******************************************************************************
122 * GetCurrentHwProfileA [ADVAPI32.@]
124 * Get the current hardware profile.
126 * PARAMS
127 * pInfo [O] Destination for hardware profile information.
129 * RETURNS
130 * Success: TRUE. pInfo is updated with the hardware profile details.
131 * Failure: FALSE.
133 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
135 FIXME("(%p) semi-stub\n", pInfo);
136 pInfo->dwDockInfo = DOCKINFO_DOCKED;
137 strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
138 strcpy(pInfo->szHwProfileName,"Wine Profile");
139 return TRUE;
142 /******************************************************************************
143 * GetCurrentHwProfileW [ADVAPI32.@]
145 * See GetCurrentHwProfileA.
147 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
149 FIXME("(%p)\n", pInfo);
150 return FALSE;
154 /**************************************************************************
155 * IsTextUnicode (ADVAPI32.@)
157 * Attempt to guess whether a text buffer is Unicode.
159 * PARAMS
160 * buf [I] Text buffer to test
161 * len [I] Length of buf
162 * flags [O] Destination for test results
164 * RETURNS
165 * TRUE if the buffer is likely Unicode, FALSE otherwise.
167 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
169 return RtlIsTextUnicode( buf, len, flags );
173 /******************************************************************************
174 * AbortSystemShutdownA [ADVAPI32.@]
176 * Stop a system shutdown if one is in progress.
178 * PARAMS
179 * lpMachineName [I] Name of machine to not shutdown.
181 * RETURNS
182 * Success: TRUE.
183 * Failure: FALSE.
185 * NOTES
186 * The Wine implementation of this function is a harmless stub.
188 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
190 TRACE("stub %s (harmless)\n", lpMachineName);
191 return TRUE;
194 /******************************************************************************
195 * AbortSystemShutdownW [ADVAPI32.@]
197 * See AbortSystemShutdownA.
199 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
201 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
202 return TRUE;
205 /******************************************************************************
206 * InitiateSystemShutdownExA [ADVAPI32.@]
208 * Initiate a shutdown or optionally restart the computer.
210 * PARAMS
211 * lpMachineName [I] Network name of machine to shutdown.
212 * lpMessage [I] Message displayed in shutdown dialog box.
213 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
214 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
215 * displayed requesting user to close apps.
216 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
217 * system flushes all caches to disk and clears
218 * the screen
219 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
220 * code.
222 * RETURNS
223 * Success: TRUE
224 * Failure: FALSE
226 * NOTES
227 * if lpMachineName is NULL, the local computer is shutdown.
229 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
230 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
231 DWORD dwReason)
233 FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
234 debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
235 bRebootAfterShutdown, dwReason);
236 return TRUE;
239 /******************************************************************************
240 * InitiateSystemShutdownExW [ADVAPI32.@]
242 * See InitiateSystemShutdownExA.
244 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
245 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
246 DWORD dwReason)
248 FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
249 debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
250 bRebootAfterShutdown, dwReason);
251 return TRUE;
254 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
255 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
257 return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
258 bForceAppsClosed, bRebootAfterShutdown,
259 SHTDN_REASON_MAJOR_LEGACY_API );
262 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
263 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
265 return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
266 bForceAppsClosed, bRebootAfterShutdown,
267 SHTDN_REASON_MAJOR_LEGACY_API );
270 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
271 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
273 WCHAR *usernameW = NULL, *domainW = NULL, *passwordW = NULL;
274 BOOL ret = FALSE;
276 TRACE("%s %s %p 0x%08x 0x%08x %p\n", debugstr_a(lpszUsername),
277 debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
279 if (lpszUsername && !(usernameW = strdupAW( lpszUsername ))) return FALSE;
280 if (lpszDomain && !(domainW = strdupAW( lpszUsername ))) goto done;
281 if (lpszPassword && !(passwordW = strdupAW( lpszPassword ))) goto done;
283 ret = LogonUserW( usernameW, domainW, passwordW, dwLogonType, dwLogonProvider, phToken );
285 done:
286 heap_free( usernameW );
287 heap_free( domainW );
288 heap_free( passwordW );
289 return ret;
292 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
293 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
295 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
296 debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
298 *phToken = (HANDLE *)0xdeadbeef;
299 return TRUE;
302 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
304 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
305 WCHAR *szCommandLine, DWORD *pcchCommandLine )
307 static const WCHAR szMsi[] = { 'm','s','i',0 };
308 fnMsiProvideComponentFromDescriptor mpcfd;
309 HMODULE hmsi;
310 UINT r = ERROR_CALL_NOT_IMPLEMENTED;
312 TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
314 hmsi = LoadLibraryW( szMsi );
315 if (!hmsi)
316 return r;
317 mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
318 "MsiProvideComponentFromDescriptorW" );
319 if (mpcfd)
320 r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
321 FreeLibrary( hmsi );
322 return r;