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
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.
48 * lpszName [O] Destination for the user name.
49 * lpSize [I/O] Size of lpszName.
52 * Success: The length of the user name, including terminating NUL.
53 * Failure: ERROR_MORE_DATA if *lpSize is too small.
56 GetUserNameA( LPSTR lpszName
, LPDWORD lpSize
)
60 DWORD sizeW
= *lpSize
;
62 if (!(buffer
= heap_alloc( sizeW
* sizeof(WCHAR
) )))
64 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
68 ret
= GetUserNameW( buffer
, &sizeW
);
70 *lpSize
= WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpszName
, *lpSize
, NULL
, NULL
);
78 /******************************************************************************
79 * GetUserNameW [ADVAPI32.@]
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 );
92 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
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
)
115 len
= lstrlenW(backslash
);
116 memmove(lpszName
, backslash
+ 1, len
* sizeof(WCHAR
));
121 /******************************************************************************
122 * GetCurrentHwProfileA [ADVAPI32.@]
124 * Get the current hardware profile.
127 * pInfo [O] Destination for hardware profile information.
130 * Success: TRUE. pInfo is updated with the hardware profile details.
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");
142 /******************************************************************************
143 * GetCurrentHwProfileW [ADVAPI32.@]
145 * See GetCurrentHwProfileA.
147 BOOL WINAPI
GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo
)
149 FIXME("(%p)\n", pInfo
);
154 /**************************************************************************
155 * IsTextUnicode (ADVAPI32.@)
157 * Attempt to guess whether a text buffer is Unicode.
160 * buf [I] Text buffer to test
161 * len [I] Length of buf
162 * flags [O] Destination for test results
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.
179 * lpMachineName [I] Name of machine to not shutdown.
186 * The Wine implementation of this function is a harmless stub.
188 BOOL WINAPI
AbortSystemShutdownA( LPSTR lpMachineName
)
190 TRACE("stub %s (harmless)\n", lpMachineName
);
194 /******************************************************************************
195 * AbortSystemShutdownW [ADVAPI32.@]
197 * See AbortSystemShutdownA.
199 BOOL WINAPI
AbortSystemShutdownW( LPWSTR lpMachineName
)
201 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName
));
205 /******************************************************************************
206 * InitiateSystemShutdownExA [ADVAPI32.@]
208 * Initiate a shutdown or optionally restart the computer.
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
219 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
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
,
233 FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName
),
234 debugstr_a(lpMessage
), dwTimeout
, bForceAppsClosed
,
235 bRebootAfterShutdown
, dwReason
);
239 /******************************************************************************
240 * InitiateSystemShutdownExW [ADVAPI32.@]
242 * See InitiateSystemShutdownExA.
244 BOOL WINAPI
InitiateSystemShutdownExW( LPWSTR lpMachineName
, LPWSTR lpMessage
,
245 DWORD dwTimeout
, BOOL bForceAppsClosed
, BOOL bRebootAfterShutdown
,
248 FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName
),
249 debugstr_w(lpMessage
), dwTimeout
, bForceAppsClosed
,
250 bRebootAfterShutdown
, dwReason
);
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
;
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
);
286 heap_free( usernameW
);
287 heap_free( domainW
);
288 heap_free( passwordW
);
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;
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
;
310 UINT r
= ERROR_CALL_NOT_IMPLEMENTED
;
312 TRACE("%s %p %p\n", debugstr_w(szDescriptor
), szCommandLine
, pcchCommandLine
);
314 hmsi
= LoadLibraryW( szMsi
);
317 mpcfd
= (fnMsiProvideComponentFromDescriptor
)GetProcAddress( hmsi
,
318 "MsiProvideComponentFromDescriptorW" );
320 r
= mpcfd( szDescriptor
, szCommandLine
, pcchCommandLine
, NULL
);