Use the Unix codepage to convert the user name to Unicode.
[wine] / dlls / advapi32 / advapi.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "winreg.h"
33 #include "winerror.h"
34
35 #include "wine/library.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39
40 /******************************************************************************
41  * GetUserNameA [ADVAPI32.@]
42  *
43  * Get the current user name.
44  *
45  * PARAMS
46  *  lpszName [O]   Destination for the user name.
47  *  lpSize   [I/O] Size of lpszName.
48  *
49  * RETURNS
50  *  Success: The length of the user name, including terminating NUL.
51  *  Failure: ERROR_MORE_DATA if *lpSize is too small.
52  */
53 BOOL WINAPI
54 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
55 {
56     WCHAR *buffer;
57     BOOL ret;
58
59     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) )))
60     {
61         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
62         return FALSE;
63     }
64     ret = GetUserNameW( buffer, *lpSize * 2 );
65     if (ret)
66     {
67         if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
68         {
69             *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
70             SetLastError( ERROR_MORE_DATA );
71             ret = FALSE;
72         }
73     }
74     HeapFree( GetProcessHeap(), 0, buffer );
75     return ret;
76 }
77
78 /******************************************************************************
79  * GetUserNameW [ADVAPI32.@]
80  *
81  * See GetUserNameA.
82  */
83 BOOL WINAPI
84 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
85 {
86     const char *name = wine_get_user_name();
87     DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
88
89     if (len > *lpSize)
90     {
91         SetLastError(ERROR_MORE_DATA);
92         *lpSize = len;
93         return FALSE;
94     }
95
96     *lpSize = len;
97     MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
98     return TRUE;
99 }
100
101 /******************************************************************************
102  * GetCurrentHwProfileA [ADVAPI32.@]
103  *
104  * Get the current hardware profile.
105  *
106  * PARAMS
107  *  pInfo [O] Destination for hardware profile information.
108  *
109  * RETURNS
110  *  Success: TRUE. pInfo is updated with the hardware profile details.
111  *  Failure: FALSE.
112  */
113 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
114 {
115         FIXME("(%p) semi-stub\n", pInfo);
116         pInfo->dwDockInfo = DOCKINFO_DOCKED;
117         strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-1233456789012}");
118         strcpy(pInfo->szHwProfileName,"Wine Profile");
119         return 1;
120 }
121
122 /******************************************************************************
123  * AbortSystemShutdownA [ADVAPI32.@]
124  *
125  * Stop a system shutdown if one is in progress.
126  *
127  * PARAMS
128  *  lpMachineName [I] Name of machine to not shutdown.
129  *
130  * RETURNS
131  *  Success: TRUE.
132  *  Failure: FALSE.
133  *
134  * NOTES
135  *  The Wine implementation of this function is a harmless stub.
136  */
137 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
138 {
139     TRACE("stub %s (harmless)\n", lpMachineName);
140     return TRUE;
141 }
142
143 /******************************************************************************
144  * AbortSystemShutdownW [ADVAPI32.@]
145  *
146  * See AbortSystemShutdownA.
147  */
148 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
149 {
150     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
151     return TRUE;
152 }
153
154 /******************************************************************************
155  * InitiateSystemShutdownExA [ADVAPI32.@]
156  */
157 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
158          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
159          DWORD dwReason)
160 {
161      FIXME("%s %s %ld %d %d %ld\n", debugstr_a(lpMachineName),
162             debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
163             bRebootAfterShutdown, dwReason);
164      return TRUE;
165
166
167 /******************************************************************************
168  * InitiateSystemShutdownExA [ADVAPI32.@]
169  */
170 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
171          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
172          DWORD dwReason)
173 {
174      FIXME("%s %s %ld %d %d %ld\n", debugstr_w(lpMachineName),
175             debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
176             bRebootAfterShutdown, dwReason);
177      return TRUE;
178
179
180 DWORD WINAPI CommandLineFromMsiDescriptor(WCHAR *Descriptor, WCHAR *CommandLine,
181  DWORD *CommandLineLength)
182 {
183     FIXME("stub (%s)\n", debugstr_w(Descriptor));
184     return ERROR_CALL_NOT_IMPLEMENTED;
185 }