Commit dbe3269c authored by Alexandre Julliard's avatar Alexandre Julliard

mountmgr: Pass a Unix interface name in the dhcp_request_params ioctl.

parent 5e42498e
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winnls.h"
#include "dhcpcsdk.h" #include "dhcpcsdk.h"
#include "winioctl.h" #include "winioctl.h"
#include "winternl.h" #include "winternl.h"
...@@ -62,6 +63,20 @@ static DWORD get_adapter_luid( const WCHAR *adapter, NET_LUID *luid ) ...@@ -62,6 +63,20 @@ static DWORD get_adapter_luid( const WCHAR *adapter, NET_LUID *luid )
return ConvertInterfaceNameToLuidW( adapter, luid ); return ConvertInterfaceNameToLuidW( adapter, luid );
} }
#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;
}
DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHCPCAPI_CLASSID *class_id, 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, DHCPCAPI_PARAMS_ARRAY send_params, DHCPCAPI_PARAMS_ARRAY recv_params, BYTE *buf,
DWORD *buflen, WCHAR *request_id ) DWORD *buflen, WCHAR *request_id )
...@@ -69,15 +84,15 @@ DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHC ...@@ -69,15 +84,15 @@ DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHC
struct mountmgr_dhcp_request_params *query; struct mountmgr_dhcp_request_params *query;
DWORD i, size, err; DWORD i, size, err;
BYTE *src, *dst; BYTE *src, *dst;
NET_LUID luid;
HANDLE mgr; HANDLE mgr;
char unix_name[IF_NAMESIZE];
TRACE( "(%08x, %p, %s, %p, %u, %u, %p, %p, %s)\n", flags, reserved, debugstr_w(adapter), class_id, 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) ); send_params.nParams, recv_params.nParams, buf, buflen, debugstr_w(request_id) );
if (!adapter || !buflen) return ERROR_INVALID_PARAMETER; if (!adapter || !buflen) return ERROR_INVALID_PARAMETER;
if (flags != DHCPCAPI_REQUEST_SYNCHRONOUS) FIXME( "unsupported flags %08x\n", flags ); if (flags != DHCPCAPI_REQUEST_SYNCHRONOUS) FIXME( "unsupported flags %08x\n", flags );
if ((err = get_adapter_luid( adapter, &luid ))) return err; if ((err = get_adapter_name( adapter, unix_name, sizeof(unix_name) ))) return err;
for (i = 0; i < send_params.nParams; i++) for (i = 0; i < send_params.nParams; i++)
FIXME( "send option %u not supported\n", send_params.Params->OptionId ); FIXME( "send option %u not supported\n", send_params.Params->OptionId );
...@@ -94,7 +109,7 @@ DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHC ...@@ -94,7 +109,7 @@ DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHC
} }
for (i = 0; i < recv_params.nParams; i++) query->params[i].id = recv_params.Params[i].OptionId; for (i = 0; i < recv_params.nParams; i++) query->params[i].id = recv_params.Params[i].OptionId;
query->count = recv_params.nParams; query->count = recv_params.nParams;
query->adapter = luid; strcpy( query->unix_name, unix_name );
if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS, query, size, query, size, NULL, NULL )) if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS, query, size, query, size, NULL, NULL ))
{ {
......
MODULE = mountmgr.sys MODULE = mountmgr.sys
IMPORTS = uuid advapi32 ntoskrnl IMPORTS = uuid advapi32 ntoskrnl
DELAYIMPORTS = user32 iphlpapi DELAYIMPORTS = user32
EXTRAINCL = $(DBUS_CFLAGS) $(HAL_CFLAGS) EXTRAINCL = $(DBUS_CFLAGS) $(HAL_CFLAGS)
EXTRALIBS = $(DISKARBITRATION_LIBS) $(SYSTEMCONFIGURATION_LIBS) $(CORESERVICES_LIBS) $(SECURITY_LIBS) EXTRALIBS = $(DISKARBITRATION_LIBS) $(SYSTEMCONFIGURATION_LIBS) $(CORESERVICES_LIBS) $(SECURITY_LIBS)
......
...@@ -38,9 +38,6 @@ ...@@ -38,9 +38,6 @@
#define USE_WS_PREFIX #define USE_WS_PREFIX
#include "winsock2.h" #include "winsock2.h"
#include "ws2ipdef.h" #include "ws2ipdef.h"
#include "nldef.h"
#include "netioapi.h"
#include "inaddr.h"
#include "ip2string.h" #include "ip2string.h"
#include "dhcpcsdk.h" #include "dhcpcsdk.h"
...@@ -998,26 +995,15 @@ static DBusMessage *device_by_iface_request( const char *iface ) ...@@ -998,26 +995,15 @@ static DBusMessage *device_by_iface_request( const char *iface )
return reply; return reply;
} }
#define IF_NAMESIZE 16 static DBusMessage *dhcp4_config_request( const char *iface )
static BOOL map_adapter_name( const NET_LUID *luid, char *unix_name, DWORD len )
{
WCHAR unix_nameW[IF_NAMESIZE];
if (ConvertInterfaceLuidToAlias( 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 NET_LUID *adapter )
{ {
static const char *device = "org.freedesktop.NetworkManager.Device"; static const char *device = "org.freedesktop.NetworkManager.Device";
static const char *dhcp4_config = "Dhcp4Config"; static const char *dhcp4_config = "Dhcp4Config";
char iface[IF_NAMESIZE];
DBusMessage *request, *reply; DBusMessage *request, *reply;
DBusMessageIter iter; DBusMessageIter iter;
DBusError error; DBusError error;
const char *path = NULL; const char *path = NULL;
if (!map_adapter_name( adapter, iface, sizeof(iface) )) return NULL;
if (!(reply = device_by_iface_request( iface ))) return NULL; if (!(reply = device_by_iface_request( iface ))) return NULL;
p_dbus_message_iter_init( reply, &iter ); p_dbus_message_iter_init( reply, &iter );
...@@ -1047,7 +1033,7 @@ static DBusMessage *dhcp4_config_request( const NET_LUID *adapter ) ...@@ -1047,7 +1033,7 @@ static DBusMessage *dhcp4_config_request( const NET_LUID *adapter )
return reply; return reply;
} }
static DBusMessage *dhcp4_config_options_request( const NET_LUID *adapter ) static DBusMessage *dhcp4_config_options_request( const char *unix_name )
{ {
static const char *dhcp4_config = "org.freedesktop.NetworkManager.DHCP4Config"; static const char *dhcp4_config = "org.freedesktop.NetworkManager.DHCP4Config";
static const char *options = "Options"; static const char *options = "Options";
...@@ -1056,7 +1042,7 @@ static DBusMessage *dhcp4_config_options_request( const NET_LUID *adapter ) ...@@ -1056,7 +1042,7 @@ static DBusMessage *dhcp4_config_options_request( const NET_LUID *adapter )
DBusError error; DBusError error;
const char *path = NULL; const char *path = NULL;
if (!(reply = dhcp4_config_request( adapter ))) return NULL; if (!(reply = dhcp4_config_request( unix_name ))) return NULL;
p_dbus_message_iter_init( reply, &iter ); p_dbus_message_iter_init( reply, &iter );
if (p_dbus_message_iter_get_arg_type( &iter ) == DBUS_TYPE_VARIANT) if (p_dbus_message_iter_get_arg_type( &iter ) == DBUS_TYPE_VARIANT)
...@@ -1106,13 +1092,13 @@ static const char *dhcp4_config_option_next_dict_entry( DBusMessageIter *iter, D ...@@ -1106,13 +1092,13 @@ static const char *dhcp4_config_option_next_dict_entry( DBusMessageIter *iter, D
return name; return name;
} }
static DBusMessage *dhcp4_config_option_request( const NET_LUID *adapter, const char *option, const char **value ) static DBusMessage *dhcp4_config_option_request( const char *unix_name, const char *option, const char **value )
{ {
DBusMessage *reply; DBusMessage *reply;
DBusMessageIter iter, variant; DBusMessageIter iter, variant;
const char *name; const char *name;
if (!(reply = dhcp4_config_options_request( adapter ))) return NULL; if (!(reply = dhcp4_config_options_request( unix_name ))) return NULL;
*value = NULL; *value = NULL;
p_dbus_message_iter_init( reply, &iter ); p_dbus_message_iter_init( reply, &iter );
...@@ -1152,7 +1138,7 @@ static const char *map_option( ULONG option ) ...@@ -1152,7 +1138,7 @@ static const char *map_option( ULONG option )
} }
} }
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset, ULONG get_dhcp_request_param( const char *unix_name, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size ) ULONG size )
{ {
DBusMessage *reply; DBusMessage *reply;
...@@ -1161,7 +1147,7 @@ ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_requ ...@@ -1161,7 +1147,7 @@ ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_requ
param->offset = param->size = 0; param->offset = param->size = 0;
if (!(reply = dhcp4_config_option_request( adapter, map_option(param->id), &value ))) return 0; if (!(reply = dhcp4_config_option_request( unix_name, map_option(param->id), &value ))) return 0;
switch (param->id) switch (param->id)
{ {
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
#define USE_WS_PREFIX #define USE_WS_PREFIX
#include "winsock2.h" #include "winsock2.h"
#include "ws2ipdef.h" #include "ws2ipdef.h"
#include "nldef.h"
#include "netioapi.h"
#include "dhcpcsdk.h" #include "dhcpcsdk.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -258,22 +256,14 @@ static UInt8 map_option( ULONG option ) ...@@ -258,22 +256,14 @@ static UInt8 map_option( ULONG option )
} }
} }
#define IF_NAMESIZE 16 static CFStringRef find_service_id( const char *unix_name )
static BOOL map_adapter_name( const NET_LUID *luid, WCHAR *unix_name, DWORD len )
{
return !ConvertInterfaceLuidToAlias( luid, unix_name, len );
}
static CFStringRef find_service_id( const NET_LUID *adapter )
{ {
SCPreferencesRef prefs; SCPreferencesRef prefs;
SCNetworkSetRef set = NULL; SCNetworkSetRef set = NULL;
CFArrayRef services = NULL; CFArrayRef services = NULL;
CFStringRef id, ret = NULL; CFStringRef id, ret = NULL;
WCHAR unix_name[IF_NAMESIZE];
CFIndex i; CFIndex i;
if (!map_adapter_name( adapter, unix_name, ARRAY_SIZE(unix_name) )) return NULL;
if (!(prefs = SCPreferencesCreate( NULL, CFSTR("mountmgr.sys"), NULL ))) return NULL; if (!(prefs = SCPreferencesCreate( NULL, CFSTR("mountmgr.sys"), NULL ))) return NULL;
if (!(set = SCNetworkSetCopyCurrent( prefs ))) goto done; if (!(set = SCNetworkSetCopyCurrent( prefs ))) goto done;
if (!(services = SCNetworkSetCopyServices( set ))) goto done; if (!(services = SCNetworkSetCopyServices( set ))) goto done;
...@@ -281,15 +271,14 @@ static CFStringRef find_service_id( const NET_LUID *adapter ) ...@@ -281,15 +271,14 @@ static CFStringRef find_service_id( const NET_LUID *adapter )
for (i = 0; i < CFArrayGetCount( services ); i++) for (i = 0; i < CFArrayGetCount( services ); i++)
{ {
SCNetworkServiceRef service; SCNetworkServiceRef service;
UniChar buf[IF_NAMESIZE] = {0}; char buf[16];
CFStringRef name; CFStringRef name;
service = CFArrayGetValueAtIndex( services, i ); service = CFArrayGetValueAtIndex( services, i );
name = SCNetworkInterfaceGetBSDName( SCNetworkServiceGetInterface(service) ); name = SCNetworkInterfaceGetBSDName( SCNetworkServiceGetInterface(service) );
if (name && CFStringGetLength( name ) < ARRAY_SIZE( buf )) if (name && CFStringGetCString( name, buf, sizeof(buf), kCFStringEncodingUTF8 ))
{ {
CFStringGetCharacters( name, CFRangeMake(0, CFStringGetLength(name)), buf ); if (!strcmp( buf, unix_name ) && (id = SCNetworkServiceGetServiceID( service )))
if (!lstrcmpW( buf, unix_name ) && (id = SCNetworkServiceGetServiceID( service )))
{ {
ret = CFStringCreateCopy( NULL, id ); ret = CFStringCreateCopy( NULL, id );
break; break;
...@@ -304,10 +293,10 @@ done: ...@@ -304,10 +293,10 @@ done:
return ret; return ret;
} }
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset, ULONG get_dhcp_request_param( const char *unix_name, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size ) ULONG size )
{ {
CFStringRef service_id = find_service_id( adapter ); CFStringRef service_id = find_service_id( unix_name );
CFDictionaryRef dict; CFDictionaryRef dict;
CFDataRef value; CFDataRef value;
DWORD ret = 0; DWORD ret = 0;
...@@ -373,7 +362,7 @@ ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_requ ...@@ -373,7 +362,7 @@ ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_requ
#elif !defined(SONAME_LIBDBUS_1) #elif !defined(SONAME_LIBDBUS_1)
ULONG get_dhcp_request_param( const NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset, ULONG get_dhcp_request_param( const char *unix_name, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset,
ULONG size ) ULONG size )
{ {
FIXME( "support not compiled in\n" ); FIXME( "support not compiled in\n" );
......
...@@ -246,7 +246,6 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize ) ...@@ -246,7 +246,6 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
{ {
const struct mountmgr_unix_drive *input = in_buff; const struct mountmgr_unix_drive *input = in_buff;
const char *mount_point = NULL, *device = NULL; const char *mount_point = NULL, *device = NULL;
unsigned int i;
WCHAR letter = tolowerW( input->letter ); WCHAR letter = tolowerW( input->letter );
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER; if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
...@@ -258,16 +257,12 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize ) ...@@ -258,16 +257,12 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
if (input->mount_point_offset) if (input->mount_point_offset)
{ {
mount_point = (const char *)in_buff + input->mount_point_offset; mount_point = (const char *)in_buff + input->mount_point_offset;
for (i = input->mount_point_offset; i < insize; i++) if (!memchr( mount_point, 0, insize - input->mount_point_offset )) return STATUS_INVALID_PARAMETER;
if (!*((const char *)in_buff + i)) break;
if (i >= insize) return STATUS_INVALID_PARAMETER;
} }
if (input->device_offset) if (input->device_offset)
{ {
device = (const char *)in_buff + input->device_offset; device = (const char *)in_buff + input->device_offset;
for (i = input->device_offset; i < insize; i++) if (!memchr( device, 0, insize - input->device_offset )) return STATUS_INVALID_PARAMETER;
if (!*((const char *)in_buff + i)) break;
if (i >= insize) return STATUS_INVALID_PARAMETER;
} }
if (input->type != DRIVE_NO_ROOT_DIR) if (input->type != DRIVE_NO_ROOT_DIR)
...@@ -305,7 +300,6 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) ...@@ -305,7 +300,6 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
const char *home; const char *home;
char *buffer = NULL, *backup = NULL, *homelink = NULL; char *buffer = NULL, *backup = NULL, *homelink = NULL;
struct stat st; struct stat st;
unsigned int i;
if (input->folder_offset >= insize || input->folder_size > insize - input->folder_offset || if (input->folder_offset >= insize || input->folder_size > insize - input->folder_offset ||
input->symlink_offset >= insize) input->symlink_offset >= insize)
...@@ -315,9 +309,7 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) ...@@ -315,9 +309,7 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
if (input->symlink_offset) if (input->symlink_offset)
{ {
link = (const char *)in_buff + input->symlink_offset; link = (const char *)in_buff + input->symlink_offset;
for (i = input->symlink_offset; i < insize; i++) if (!memchr( link, 0, insize - input->symlink_offset )) return STATUS_INVALID_PARAMETER;
if (!*((const char *)in_buff + i)) break;
if (i >= insize) return STATUS_INVALID_PARAMETER;
if (!link[0]) link = NULL; if (!link[0]) link = NULL;
} }
...@@ -459,11 +451,16 @@ static void WINAPI query_dhcp_request_params( TP_CALLBACK_INSTANCE *instance, vo ...@@ -459,11 +451,16 @@ static void WINAPI query_dhcp_request_params( TP_CALLBACK_INSTANCE *instance, vo
goto err; goto err;
} }
if (!memchr( query->unix_name, 0, sizeof(query->unix_name) ))
{
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
goto err;
}
offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]); offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
for (i = 0; i < query->count; i++) 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->unix_name, &query->params[i], (char *)query, offset, outsize - offset );
if (offset > outsize) if (offset > outsize)
{ {
if (offset >= sizeof(query->size)) query->size = offset; if (offset >= sizeof(query->size)) query->size = offset;
......
...@@ -108,5 +108,5 @@ extern struct mount_point *add_volume_mount_point( DEVICE_OBJECT *device, UNICOD ...@@ -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 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 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 NET_LUID *adapter, struct mountmgr_dhcp_request_param *param, char *buf, extern ULONG get_dhcp_request_param( const char *unix_name, struct mountmgr_dhcp_request_param *param,
ULONG offset, ULONG size ) DECLSPEC_HIDDEN; char *buf, ULONG offset, ULONG size ) DECLSPEC_HIDDEN;
...@@ -131,7 +131,7 @@ struct mountmgr_dhcp_request_params ...@@ -131,7 +131,7 @@ struct mountmgr_dhcp_request_params
{ {
ULONG size; ULONG size;
ULONG count; ULONG count;
NET_LUID adapter; char unix_name[16];
struct mountmgr_dhcp_request_param params[1]; struct mountmgr_dhcp_request_param params[1];
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment