dhcpcsvc: Pass a luid instead of the adapter name.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2021-07-07 09:05:54 +01:00 committed by Alexandre Julliard
parent e49e79de99
commit e5b90e93b2
7 changed files with 49 additions and 47 deletions

View File

@ -1,4 +1,5 @@
MODULE = dhcpcsvc.dll
DELAYIMPORTS = iphlpapi
IMPORTLIB = dhcpcsvc
EXTRADLLFLAGS = -mno-cygwin -Wb,--prefer-native

View File

@ -22,6 +22,11 @@
#include "winbase.h"
#include "dhcpcsdk.h"
#include "winioctl.h"
#include "winternl.h"
#include "ws2def.h"
#include "ws2ipdef.h"
#include "iphlpapi.h"
#include "netioapi.h"
#define WINE_MOUNTMGR_EXTENSIONS
#include "ddk/mountmgr.h"
@ -42,20 +47,37 @@ DWORD WINAPI DhcpCApiInitialize(LPDWORD version)
return ERROR_SUCCESS;
}
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 );
}
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 )
{
struct mountmgr_dhcp_request_params *query;
DWORD i, size, err = ERROR_OUTOFMEMORY;
DWORD i, size, err;
BYTE *src, *dst;
NET_LUID luid;
HANDLE mgr;
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) );
if (!adapter || lstrlenW(adapter) > IF_MAX_STRING_SIZE || !buflen) return ERROR_INVALID_PARAMETER;
if (!adapter || !buflen) return ERROR_INVALID_PARAMETER;
if (flags != DHCPCAPI_REQUEST_SYNCHRONOUS) FIXME( "unsupported flags %08x\n", flags );
if ((err = get_adapter_luid( adapter, &luid ))) return err;
for (i = 0; i < send_params.nParams; i++)
FIXME( "send option %u not supported\n", send_params.Params->OptionId );
@ -65,11 +87,14 @@ DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHC
if (mgr == INVALID_HANDLE_VALUE) return GetLastError();
size = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[recv_params.nParams]) + *buflen;
if (!(query = heap_alloc_zero( size ))) goto done;
if (!(query = heap_alloc_zero( size )))
{
err = ERROR_OUTOFMEMORY;
goto done;
}
for (i = 0; i < recv_params.nParams; i++) query->params[i].id = recv_params.Params[i].OptionId;
query->count = recv_params.nParams;
lstrcpyW( query->adapter, adapter );
query->adapter = luid;
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS, query, size, query, size, NULL, NULL ))
{

View File

@ -999,25 +999,15 @@ static DBusMessage *device_by_iface_request( const char *iface )
}
#define IF_NAMESIZE 16
static BOOL map_adapter_name( const WCHAR *name, char *unix_name, DWORD len )
static BOOL map_adapter_name( const NET_LUID *luid, char *unix_name, DWORD len )
{
WCHAR unix_nameW[IF_NAMESIZE];
UNICODE_STRING str;
GUID guid;
RtlInitUnicodeString( &str, name );
if (!RtlGUIDFromString( &str, &guid ))
{
NET_LUID luid;
if (ConvertInterfaceGuidToLuid( &guid, &luid ) ||
ConvertInterfaceLuidToNameW( &luid, unix_nameW, ARRAY_SIZE(unix_nameW) )) return FALSE;
name = unix_nameW;
}
return WideCharToMultiByte( CP_UNIXCP, 0, name, -1, unix_name, len, NULL, NULL ) != 0;
if (ConvertInterfaceLuidToNameW( luid, unix_nameW, ARRAY_SIZE(unix_nameW) )) return FALSE;
return WideCharToMultiByte( CP_UNIXCP, 0, unix_nameW, -1, unix_name, len, NULL, NULL ) != 0;
}
static DBusMessage *dhcp4_config_request( const WCHAR *adapter )
static DBusMessage *dhcp4_config_request( const NET_LUID *adapter )
{
static const char *device = "org.freedesktop.NetworkManager.Device";
static const char *dhcp4_config = "Dhcp4Config";
@ -1057,7 +1047,7 @@ static DBusMessage *dhcp4_config_request( const WCHAR *adapter )
return reply;
}
static DBusMessage *dhcp4_config_options_request( const WCHAR *adapter )
static DBusMessage *dhcp4_config_options_request( const NET_LUID *adapter )
{
static const char *dhcp4_config = "org.freedesktop.NetworkManager.DHCP4Config";
static const char *options = "Options";
@ -1116,7 +1106,7 @@ static const char *dhcp4_config_option_next_dict_entry( DBusMessageIter *iter, D
return name;
}
static DBusMessage *dhcp4_config_option_request( const WCHAR *adapter, const char *option, const char **value )
static DBusMessage *dhcp4_config_option_request( const NET_LUID *adapter, const char *option, const char **value )
{
DBusMessage *reply;
DBusMessageIter iter, variant;
@ -1162,7 +1152,7 @@ static const char *map_option( ULONG option )
}
}
ULONG get_dhcp_request_param( const WCHAR *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size )
{
DBusMessage *reply;

View File

@ -258,27 +258,12 @@ static UInt8 map_option( ULONG option )
}
#define IF_NAMESIZE 16
static BOOL map_adapter_name( const WCHAR *name, WCHAR *unix_name, DWORD len )
static BOOL map_adapter_name( const NET_LUID *luid, WCHAR *unix_name, DWORD len )
{
WCHAR buf[IF_NAMESIZE];
UNICODE_STRING str;
GUID guid;
RtlInitUnicodeString( &str, name );
if (!RtlGUIDFromString( &str, &guid ))
{
NET_LUID luid;
if (ConvertInterfaceGuidToLuid( &guid, &luid ) ||
ConvertInterfaceLuidToNameW( &luid, buf, ARRAY_SIZE(buf) )) return FALSE;
name = buf;
}
if (lstrlenW( name ) >= len) return FALSE;
lstrcpyW( unix_name, name );
return TRUE;
return !ConvertInterfaceLuidToNameW( luid, unix_name, len );
}
static CFStringRef find_service_id( const WCHAR *adapter )
static CFStringRef find_service_id( const NET_LUID *adapter )
{
SCPreferencesRef prefs;
SCNetworkSetRef set = NULL;
@ -318,7 +303,7 @@ done:
return ret;
}
ULONG get_dhcp_request_param( const WCHAR *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size )
{
CFStringRef service_id = find_service_id( adapter );
@ -387,7 +372,7 @@ ULONG get_dhcp_request_param( const WCHAR *adapter, struct mountmgr_dhcp_request
#elif !defined(SONAME_LIBDBUS_1)
ULONG get_dhcp_request_param( const WCHAR *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size )
{
FIXME( "support not compiled in\n" );

View File

@ -296,8 +296,7 @@ static void WINAPI query_dhcp_request_params( TP_CALLBACK_INSTANCE *instance, vo
ULONG i, offset = 0;
/* sanity checks */
if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize ||
!memchrW( query->adapter, 0, ARRAY_SIZE(query->adapter) ))
if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize)
{
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
goto err;
@ -314,7 +313,7 @@ static void WINAPI query_dhcp_request_params( TP_CALLBACK_INSTANCE *instance, vo
offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
for (i = 0; i < query->count; i++)
{
offset += get_dhcp_request_param( query->adapter, &query->params[i], (char *)query, offset, outsize - offset );
offset += get_dhcp_request_param( &query->adapter, &query->params[i], (char *)query, offset, outsize - offset );
if (offset > outsize)
{
if (offset >= sizeof(query->size)) query->size = offset;

View File

@ -108,5 +108,5 @@ extern struct mount_point *add_volume_mount_point( DEVICE_OBJECT *device, UNICOD
extern void delete_mount_point( struct mount_point *mount ) DECLSPEC_HIDDEN;
extern void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len ) DECLSPEC_HIDDEN;
extern ULONG get_dhcp_request_param( const WCHAR *adapter, struct mountmgr_dhcp_request_param *param, char *buf,
extern ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf,
ULONG offset, ULONG size ) DECLSPEC_HIDDEN;

View File

@ -21,6 +21,8 @@
#ifndef _MOUNTMGR_
#define _MOUNTMGR_
#include "ifdef.h"
#define MOUNTMGRCONTROLTYPE ((ULONG)'m')
#define MOUNTDEVCONTROLTYPE ((ULONG)'M')
@ -119,7 +121,7 @@ struct mountmgr_dhcp_request_params
{
ULONG size;
ULONG count;
WCHAR adapter[IF_MAX_STRING_SIZE + 1];
NET_LUID adapter;
struct mountmgr_dhcp_request_param params[1];
};