2011-12-22 00:04:05 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Stefan Leichter
|
2019-11-19 14:45:00 +01:00
|
|
|
* Copyright 2019 Hans Leidekker for CodeWeavers
|
2011-12-22 00:04:05 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2021-11-25 11:07:37 +01:00
|
|
|
#include "winnls.h"
|
2017-02-02 07:53:30 +01:00
|
|
|
#include "dhcpcsdk.h"
|
2019-11-19 14:45:00 +01:00
|
|
|
#include "winioctl.h"
|
2021-07-07 10:05:54 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "ws2def.h"
|
|
|
|
#include "ws2ipdef.h"
|
|
|
|
#include "iphlpapi.h"
|
|
|
|
#include "netioapi.h"
|
2019-11-19 14:45:00 +01:00
|
|
|
#define WINE_MOUNTMGR_EXTENSIONS
|
|
|
|
#include "ddk/mountmgr.h"
|
|
|
|
|
2011-12-22 00:04:05 +01:00
|
|
|
#include "wine/debug.h"
|
2019-11-19 14:45:00 +01:00
|
|
|
#include "wine/heap.h"
|
2011-12-22 00:04:05 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dhcpcsvc);
|
|
|
|
|
2017-03-17 00:59:49 +01:00
|
|
|
void WINAPI DhcpCApiCleanup(void)
|
|
|
|
{
|
|
|
|
FIXME(": stub\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI DhcpCApiInitialize(LPDWORD version)
|
|
|
|
{
|
|
|
|
*version = 2; /* 98, XP, and 8 */
|
|
|
|
FIXME(": stub\n");
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-07-07 10:05:54 +02:00
|
|
|
static DWORD get_adapter_luid( const WCHAR *adapter, NET_LUID *luid )
|
|
|
|
{
|
|
|
|
UNICODE_STRING ustr;
|
|
|
|
NTSTATUS status;
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
if (adapter[0] == '{')
|
|
|
|
{
|
|
|
|
RtlInitUnicodeString( &ustr, adapter );
|
|
|
|
status = RtlGUIDFromString( &ustr, &guid );
|
|
|
|
if (!status) return ConvertInterfaceGuidToLuid( &guid, luid );
|
|
|
|
}
|
|
|
|
return ConvertInterfaceNameToLuidW( adapter, luid );
|
|
|
|
}
|
|
|
|
|
2021-11-25 11:07:37 +01:00
|
|
|
#define IF_NAMESIZE 16
|
|
|
|
static DWORD get_adapter_name( const WCHAR *adapter, char *unix_name, DWORD len )
|
|
|
|
{
|
|
|
|
WCHAR unix_nameW[IF_NAMESIZE];
|
|
|
|
NET_LUID luid;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
if ((ret = get_adapter_luid( adapter, &luid ))) return ret;
|
|
|
|
if ((ret = ConvertInterfaceLuidToAlias( &luid, unix_nameW, ARRAY_SIZE(unix_nameW) ))) return ret;
|
|
|
|
if (!WideCharToMultiByte( CP_UNIXCP, 0, unix_nameW, -1, unix_name, len, NULL, NULL ))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-11-19 14:45:00 +01:00
|
|
|
DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHCPCAPI_CLASSID *class_id,
|
|
|
|
DHCPCAPI_PARAMS_ARRAY send_params, DHCPCAPI_PARAMS_ARRAY recv_params, BYTE *buf,
|
|
|
|
DWORD *buflen, WCHAR *request_id )
|
2017-02-02 07:53:30 +01:00
|
|
|
{
|
2019-11-19 14:45:00 +01:00
|
|
|
struct mountmgr_dhcp_request_params *query;
|
2021-07-07 10:05:54 +02:00
|
|
|
DWORD i, size, err;
|
2019-11-19 14:45:00 +01:00
|
|
|
BYTE *src, *dst;
|
|
|
|
HANDLE mgr;
|
2021-11-25 11:07:37 +01:00
|
|
|
char unix_name[IF_NAMESIZE];
|
2019-11-19 14:45:00 +01:00
|
|
|
|
|
|
|
TRACE( "(%08x, %p, %s, %p, %u, %u, %p, %p, %s)\n", flags, reserved, debugstr_w(adapter), class_id,
|
|
|
|
send_params.nParams, recv_params.nParams, buf, buflen, debugstr_w(request_id) );
|
|
|
|
|
2021-07-07 10:05:54 +02:00
|
|
|
if (!adapter || !buflen) return ERROR_INVALID_PARAMETER;
|
2019-11-19 14:45:00 +01:00
|
|
|
if (flags != DHCPCAPI_REQUEST_SYNCHRONOUS) FIXME( "unsupported flags %08x\n", flags );
|
2021-11-25 11:07:37 +01:00
|
|
|
if ((err = get_adapter_name( adapter, unix_name, sizeof(unix_name) ))) return err;
|
2019-11-19 14:45:00 +01:00
|
|
|
|
|
|
|
for (i = 0; i < send_params.nParams; i++)
|
|
|
|
FIXME( "send option %u not supported\n", send_params.Params->OptionId );
|
|
|
|
|
|
|
|
mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, 0, 0 );
|
|
|
|
if (mgr == INVALID_HANDLE_VALUE) return GetLastError();
|
|
|
|
|
|
|
|
size = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[recv_params.nParams]) + *buflen;
|
2021-07-07 10:05:54 +02:00
|
|
|
if (!(query = heap_alloc_zero( size )))
|
|
|
|
{
|
|
|
|
err = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2019-11-19 14:45:00 +01:00
|
|
|
for (i = 0; i < recv_params.nParams; i++) query->params[i].id = recv_params.Params[i].OptionId;
|
|
|
|
query->count = recv_params.nParams;
|
2021-11-25 11:07:37 +01:00
|
|
|
strcpy( query->unix_name, unix_name );
|
2019-11-19 14:45:00 +01:00
|
|
|
|
|
|
|
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS, query, size, query, size, NULL, NULL ))
|
|
|
|
{
|
|
|
|
err = GetLastError();
|
|
|
|
if (err == ERROR_MORE_DATA) *buflen = query->size - (size - *buflen);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = buf;
|
|
|
|
for (i = 0; i < query->count; i++)
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
recv_params.Params[i].OptionId = query->params[i].id;
|
|
|
|
recv_params.Params[i].IsVendor = FALSE; /* FIXME */
|
|
|
|
if (query->params[i].size)
|
|
|
|
{
|
|
|
|
src = (BYTE *)query + query->params[i].offset;
|
|
|
|
memcpy( dst, src, query->params[i].size );
|
|
|
|
|
|
|
|
recv_params.Params[i].Data = dst;
|
|
|
|
recv_params.Params[i].nBytesData = query->params[i].size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
recv_params.Params[i].Data = NULL;
|
|
|
|
recv_params.Params[i].nBytesData = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += query->params[i].size;
|
|
|
|
}
|
|
|
|
|
|
|
|
*buflen = dst - buf;
|
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
done:
|
|
|
|
heap_free( query );
|
|
|
|
CloseHandle( mgr );
|
|
|
|
return err;
|
2017-02-02 07:53:30 +01:00
|
|
|
}
|