advapi32: Avoid slashes and backslashes in user names.
[wine/multimedia.git] / dlls / advapi32 / advapi.c
blob126f8d1f849712f87dac76f60985f91061feb3c3
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"
33 #include "wine/library.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
38 /******************************************************************************
39 * GetUserNameA [ADVAPI32.@]
41 * Get the current user name.
43 * PARAMS
44 * lpszName [O] Destination for the user name.
45 * lpSize [I/O] Size of lpszName.
47 * RETURNS
48 * Success: The length of the user name, including terminating NUL.
49 * Failure: ERROR_MORE_DATA if *lpSize is too small.
51 BOOL WINAPI
52 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
54 WCHAR *buffer;
55 BOOL ret;
56 DWORD sizeW = *lpSize * 2;
58 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
60 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
61 return FALSE;
63 ret = GetUserNameW( buffer, &sizeW );
64 if (ret)
66 if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
68 *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
69 SetLastError( ERROR_MORE_DATA );
70 ret = FALSE;
73 else *lpSize = sizeW * 2;
74 HeapFree( GetProcessHeap(), 0, 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 );
89 if (len > *lpSize)
91 SetLastError(ERROR_MORE_DATA);
92 *lpSize = len;
93 return FALSE;
96 *lpSize = len;
97 MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
99 /* Word uses the user name to create named mutexes and file mappings,
100 * and backslashes in the name cause the creation to fail.
102 for (i = 0; lpszName[i]; i++)
103 if (lpszName[i] == '\\' || lpszName[i] == '/') lpszName[i] = '_';
104 return TRUE;
107 /******************************************************************************
108 * GetCurrentHwProfileA [ADVAPI32.@]
110 * Get the current hardware profile.
112 * PARAMS
113 * pInfo [O] Destination for hardware profile information.
115 * RETURNS
116 * Success: TRUE. pInfo is updated with the hardware profile details.
117 * Failure: FALSE.
119 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
121 FIXME("(%p) semi-stub\n", pInfo);
122 pInfo->dwDockInfo = DOCKINFO_DOCKED;
123 strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-1233456789012}");
124 strcpy(pInfo->szHwProfileName,"Wine Profile");
125 return 1;
128 /******************************************************************************
129 * GetCurrentHwProfileW [ADVAPI32.@]
131 * See GetCurrentHwProfileA.
133 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
135 FIXME("(%p)\n", pInfo);
136 return FALSE;
140 /**************************************************************************
141 * IsTextUnicode (ADVAPI32.@)
143 * Attempt to guess whether a text buffer is Unicode.
145 * PARAMS
146 * buf [I] Text buffer to test
147 * len [I] Length of buf
148 * flags [O] Destination for test results
150 * RETURNS
151 * TRUE if the buffer is likely Unicode, FALSE otherwise.
153 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
155 return RtlIsTextUnicode( buf, len, flags );
159 /******************************************************************************
160 * AbortSystemShutdownA [ADVAPI32.@]
162 * Stop a system shutdown if one is in progress.
164 * PARAMS
165 * lpMachineName [I] Name of machine to not shutdown.
167 * RETURNS
168 * Success: TRUE.
169 * Failure: FALSE.
171 * NOTES
172 * The Wine implementation of this function is a harmless stub.
174 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
176 TRACE("stub %s (harmless)\n", lpMachineName);
177 return TRUE;
180 /******************************************************************************
181 * AbortSystemShutdownW [ADVAPI32.@]
183 * See AbortSystemShutdownA.
185 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
187 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
188 return TRUE;
191 /******************************************************************************
192 * InitiateSystemShutdownExA [ADVAPI32.@]
194 * Initiate a shutdown or optionally restart the computer.
196 * PARAMS
197 * lpMachineName [I] Network name of machine to shutdown.
198 * lpMessage [I] Message displayed in shutdown dialog box.
199 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
200 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
201 * displayed requesting user to close apps.
202 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
203 * system flushes all caches to disk and clears
204 * the screen
205 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
206 * code.
208 * RETURNS
209 * Success: TRUE
210 * Failure: FALSE
212 * NOTES
213 * if lpMachineName is NULL, the local computer is shutdown.
215 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
216 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
217 DWORD dwReason)
219 FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
220 debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
221 bRebootAfterShutdown, dwReason);
222 return TRUE;
225 /******************************************************************************
226 * InitiateSystemShutdownExW [ADVAPI32.@]
228 * See InitiateSystemShutdownExA.
230 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
231 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
232 DWORD dwReason)
234 FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
235 debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
236 bRebootAfterShutdown, dwReason);
237 return TRUE;
240 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
241 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
243 return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
244 bForceAppsClosed, bRebootAfterShutdown,
245 SHTDN_REASON_MAJOR_LEGACY_API );
248 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
249 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
251 return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
252 bForceAppsClosed, bRebootAfterShutdown,
253 SHTDN_REASON_MAJOR_LEGACY_API );
256 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
257 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
259 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
260 debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
262 return TRUE;
265 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
266 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
268 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
269 debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
271 return TRUE;
274 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
276 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
277 WCHAR *szCommandLine, DWORD *pcchCommandLine )
279 static const WCHAR szMsi[] = { 'm','s','i',0 };
280 fnMsiProvideComponentFromDescriptor mpcfd;
281 HMODULE hmsi;
282 UINT r = ERROR_CALL_NOT_IMPLEMENTED;
284 TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
286 hmsi = LoadLibraryW( szMsi );
287 if (!hmsi)
288 return r;
289 mpcfd = (void*) GetProcAddress( hmsi, "MsiProvideComponentFromDescriptorW" );
290 if (mpcfd)
291 r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
292 FreeLibrary( hmsi );
293 return r;