advapi.c 9.12 KB
Newer Older
1 2 3 4
/*
 * Win32 advapi functions
 *
 * Copyright 1995 Sven Verdoolaege
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
19 20
 */

21
#include <errno.h>
22
#include <stdio.h>
23
#include <string.h>
24
#include <stdarg.h>
25

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

34
#include "wine/library.h"
35
#include "wine/debug.h"
36

37
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
38

39
/******************************************************************************
40
 * GetUserNameA [ADVAPI32.@]
41
 *
Jon Griffiths's avatar
Jon Griffiths committed
42 43 44 45 46 47 48 49 50
 * Get the current user name.
 *
 * PARAMS
 *  lpszName [O]   Destination for the user name.
 *  lpSize   [I/O] Size of lpszName.
 *
 * RETURNS
 *  Success: The length of the user name, including terminating NUL.
 *  Failure: ERROR_MORE_DATA if *lpSize is too small.
51
 */
52 53
BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
54
{
55 56
    WCHAR *buffer;
    BOOL ret;
57
    DWORD sizeW = *lpSize * 2;
58

59
    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
60 61 62 63
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return FALSE;
    }
64
    ret = GetUserNameW( buffer, &sizeW );
65 66 67 68 69 70 71 72 73
    if (ret)
    {
        if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
        {
            *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
            SetLastError( ERROR_MORE_DATA );
            ret = FALSE;
        }
    }
74
    else *lpSize = sizeW * 2;
75 76
    HeapFree( GetProcessHeap(), 0, buffer );
    return ret;
77 78
}

79
/******************************************************************************
80
 * GetUserNameW [ADVAPI32.@]
81
 *
Jon Griffiths's avatar
Jon Griffiths committed
82
 * See GetUserNameA.
83
 */
84 85
BOOL WINAPI
GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
86
{
87
    const char *name = wine_get_user_name();
88
    DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
89

90 91 92 93 94 95 96 97
    if (len > *lpSize)
    {
        SetLastError(ERROR_MORE_DATA);
        *lpSize = len;
        return FALSE;
    }

    *lpSize = len;
98
    MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
99 100 101 102 103 104

    /* Word uses the user name to create named mutexes and file mappings,
     * and backslashes in the name cause the creation to fail.
     */
    for (i = 0; lpszName[i]; i++)
        if (lpszName[i] == '\\' || lpszName[i] == '/') lpszName[i] = '_';
105
    return TRUE;
106
}
107

108 109
/******************************************************************************
 * GetCurrentHwProfileA [ADVAPI32.@]
Jon Griffiths's avatar
Jon Griffiths committed
110 111 112 113 114 115 116 117 118
 *
 * Get the current hardware profile.
 *
 * PARAMS
 *  pInfo [O] Destination for hardware profile information.
 *
 * RETURNS
 *  Success: TRUE. pInfo is updated with the hardware profile details.
 *  Failure: FALSE.
119
 */
Jon Griffiths's avatar
Jon Griffiths committed
120
BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
121
{
Jon Griffiths's avatar
Jon Griffiths committed
122 123
	FIXME("(%p) semi-stub\n", pInfo);
	pInfo->dwDockInfo = DOCKINFO_DOCKED;
Andrew Talbot's avatar
Andrew Talbot committed
124
	strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
Jon Griffiths's avatar
Jon Griffiths committed
125
	strcpy(pInfo->szHwProfileName,"Wine Profile");
126 127 128
	return 1;
}

129 130 131 132 133
/******************************************************************************
 * GetCurrentHwProfileW [ADVAPI32.@]
 *
 * See GetCurrentHwProfileA.
 */
134 135 136 137 138 139
BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
{
       FIXME("(%p)\n", pInfo);
       return FALSE;
}

140 141 142 143 144 145 146 147 148 149

/**************************************************************************
 *	IsTextUnicode (ADVAPI32.@)
 *
 * Attempt to guess whether a text buffer is Unicode.
 *
 * PARAMS
 *  buf   [I] Text buffer to test
 *  len   [I] Length of buf
 *  flags [O] Destination for test results
150 151 152
 *
 * RETURNS
 *  TRUE if the buffer is likely Unicode, FALSE otherwise.
153 154 155 156 157 158 159
 */
BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
{
    return RtlIsTextUnicode( buf, len, flags );
}


160 161 162
/******************************************************************************
 * AbortSystemShutdownA [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
163 164
 * Stop a system shutdown if one is in progress.
 *
165
 * PARAMS
Jon Griffiths's avatar
Jon Griffiths committed
166 167 168 169 170 171 172 173
 *  lpMachineName [I] Name of machine to not shutdown.
 *
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE.
 *
 * NOTES
 *  The Wine implementation of this function is a harmless stub.
174 175 176 177 178 179 180 181 182 183
 */
BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
{
    TRACE("stub %s (harmless)\n", lpMachineName);
    return TRUE;
}

/******************************************************************************
 * AbortSystemShutdownW [ADVAPI32.@]
 *
Jon Griffiths's avatar
Jon Griffiths committed
184
 * See AbortSystemShutdownA.
185
 */
186
BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
187 188 189 190
{
    TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
    return TRUE;
}
191 192 193

/******************************************************************************
 * InitiateSystemShutdownExA [ADVAPI32.@]
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
 *
 * Initiate a shutdown or optionally restart the computer.
 *
 * PARAMS
 *  lpMachineName    [I] Network name of machine to shutdown.
 *  lpMessage        [I] Message displayed in shutdown dialog box.
 *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
 *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
 *                       displayed requesting user to close apps.
 *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
 *                           system flushes all caches to disk and clears
 *                           the screen
 *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
 *               code.
 *
 *  RETURNS
 *   Success: TRUE
 *   Failure: FALSE
 *
 *  NOTES
 *   if lpMachineName is NULL, the local computer is shutdown.
215 216 217 218 219
 */
BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
220
     FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
221 222 223 224 225 226
            debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 

/******************************************************************************
227 228
 * InitiateSystemShutdownExW [ADVAPI32.@]
 *
229
 * See InitiateSystemShutdownExA.
230 231 232 233 234
 */
BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
         DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
         DWORD dwReason)
{
235
     FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
236 237 238 239
            debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
            bRebootAfterShutdown, dwReason);
     return TRUE;
} 
240

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
                                     BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
{
    return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
                                      bForceAppsClosed, bRebootAfterShutdown,
                                      SHTDN_REASON_MAJOR_LEGACY_API );
}

BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
                                     BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
{
    return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
                                      bForceAppsClosed, bRebootAfterShutdown,
                                      SHTDN_REASON_MAJOR_LEGACY_API );
}

BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
260
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
261 262 263 264 265 266 267 268
          debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
                        DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
{
269
    FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
270 271 272 273 274
          debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);

    return TRUE;
}

275 276 277 278
typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);

DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
                    WCHAR *szCommandLine, DWORD *pcchCommandLine )
279
{
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    static const WCHAR szMsi[] = { 'm','s','i',0 };
    fnMsiProvideComponentFromDescriptor mpcfd;
    HMODULE hmsi;
    UINT r = ERROR_CALL_NOT_IMPLEMENTED;

    TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);

    hmsi = LoadLibraryW( szMsi );
    if (!hmsi)
        return r;
    mpcfd = (void*) GetProcAddress( hmsi, "MsiProvideComponentFromDescriptorW" );
    if (mpcfd)
        r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
    FreeLibrary( hmsi );
    return r;
295
}