2008-01-04 12:07:05 +00:00
|
|
|
/*
|
|
|
|
* Mount manager service implementation
|
|
|
|
*
|
|
|
|
* Copyright 2008 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-09-07 11:18:17 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2020-04-03 13:23:27 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <CoreFoundation/CFString.h>
|
|
|
|
#define LoadResource mac_LoadResource
|
|
|
|
#define GetCurrentThread mac_GetCurrentThread
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#undef LoadResource
|
|
|
|
#undef GetCurrentThread
|
|
|
|
#endif
|
|
|
|
|
2008-01-04 12:07:05 +00:00
|
|
|
#include <stdarg.h>
|
2021-11-03 09:43:13 +00:00
|
|
|
#include <stdlib.h>
|
2008-01-04 12:07:05 +00:00
|
|
|
#include <unistd.h>
|
2021-09-07 11:18:17 +00:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2008-01-04 12:07:05 +00:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2008-10-21 13:01:52 +00:00
|
|
|
#include "mountmgr.h"
|
2008-01-04 13:27:53 +00:00
|
|
|
#include "winreg.h"
|
2008-10-17 18:09:31 +00:00
|
|
|
#include "wine/list.h"
|
2008-10-21 13:01:52 +00:00
|
|
|
#include "wine/unicode.h"
|
2008-01-04 12:07:05 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
|
|
|
|
|
2008-10-17 17:57:43 +00:00
|
|
|
#define MIN_ID_LEN 4
|
2008-01-04 13:24:59 +00:00
|
|
|
|
|
|
|
struct mount_point
|
|
|
|
{
|
2008-10-17 18:09:31 +00:00
|
|
|
struct list entry; /* entry in mount points list */
|
|
|
|
DEVICE_OBJECT *device; /* disk device */
|
2008-10-17 18:01:23 +00:00
|
|
|
UNICODE_STRING name; /* device name */
|
2008-01-04 13:24:59 +00:00
|
|
|
UNICODE_STRING link; /* DOS device symlink */
|
|
|
|
void *id; /* device unique id */
|
|
|
|
unsigned int id_len;
|
|
|
|
};
|
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
static struct list mount_points_list = LIST_INIT(mount_points_list);
|
2008-01-04 13:27:53 +00:00
|
|
|
static HKEY mount_key;
|
2008-01-04 13:24:59 +00:00
|
|
|
|
2008-10-21 13:02:10 +00:00
|
|
|
void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len )
|
2008-10-17 17:57:43 +00:00
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount->id );
|
|
|
|
mount->id_len = max( MIN_ID_LEN, id_len );
|
|
|
|
if ((mount->id = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, mount->id_len )))
|
|
|
|
{
|
|
|
|
memcpy( mount->id, id, id_len );
|
|
|
|
RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len );
|
|
|
|
}
|
|
|
|
else mount->id_len = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
static struct mount_point *add_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
|
2009-07-20 19:00:33 +00:00
|
|
|
const WCHAR *link )
|
2008-10-17 18:09:31 +00:00
|
|
|
{
|
|
|
|
struct mount_point *mount;
|
|
|
|
WCHAR *str;
|
2008-10-17 18:01:23 +00:00
|
|
|
UINT len = (strlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR);
|
2008-10-17 18:09:31 +00:00
|
|
|
|
|
|
|
if (!(mount = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount) + len ))) return NULL;
|
|
|
|
|
|
|
|
str = (WCHAR *)(mount + 1);
|
|
|
|
strcpyW( str, link );
|
|
|
|
RtlInitUnicodeString( &mount->link, str );
|
2008-10-17 18:01:23 +00:00
|
|
|
str += strlenW(str) + 1;
|
|
|
|
memcpy( str, device_name->Buffer, device_name->Length );
|
|
|
|
str[device_name->Length / sizeof(WCHAR)] = 0;
|
|
|
|
mount->name.Buffer = str;
|
|
|
|
mount->name.Length = device_name->Length;
|
|
|
|
mount->name.MaximumLength = device_name->Length + sizeof(WCHAR);
|
2008-10-17 18:09:31 +00:00
|
|
|
mount->device = device;
|
|
|
|
mount->id = NULL;
|
|
|
|
list_add_tail( &mount_points_list, &mount->entry );
|
|
|
|
|
|
|
|
IoCreateSymbolicLink( &mount->link, device_name );
|
|
|
|
|
|
|
|
TRACE( "created %s id %s for %s\n", debugstr_w(mount->link.Buffer),
|
2008-10-17 18:01:23 +00:00
|
|
|
debugstr_a(mount->id), debugstr_w(mount->name.Buffer) );
|
2008-10-17 18:09:31 +00:00
|
|
|
return mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the DosDevices mount point symlink for a new device */
|
2009-07-20 19:00:33 +00:00
|
|
|
struct mount_point *add_dosdev_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name, int drive )
|
2008-01-04 13:24:59 +00:00
|
|
|
{
|
|
|
|
static const WCHAR driveW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','%','c',':',0};
|
2008-10-17 18:09:31 +00:00
|
|
|
WCHAR link[sizeof(driveW)];
|
|
|
|
|
|
|
|
sprintfW( link, driveW, 'A' + drive );
|
2009-07-20 19:00:33 +00:00
|
|
|
return add_mount_point( device, device_name, link );
|
2008-10-17 18:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create the Volume mount point symlink for a new device */
|
2008-10-21 13:02:10 +00:00
|
|
|
struct mount_point *add_volume_mount_point( DEVICE_OBJECT *device, UNICODE_STRING *device_name,
|
2009-07-20 19:00:33 +00:00
|
|
|
const GUID *guid )
|
2008-10-17 18:09:31 +00:00
|
|
|
{
|
2008-01-04 13:24:59 +00:00
|
|
|
static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{',
|
|
|
|
'%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
|
|
|
|
'%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
|
|
|
|
'%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
|
2008-10-17 18:09:31 +00:00
|
|
|
WCHAR link[sizeof(volumeW)];
|
2008-01-04 13:24:59 +00:00
|
|
|
|
2009-07-20 14:05:04 +00:00
|
|
|
sprintfW( link, volumeW, guid->Data1, guid->Data2, guid->Data3,
|
|
|
|
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
|
|
|
|
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
|
2009-07-20 19:00:33 +00:00
|
|
|
return add_mount_point( device, device_name, link );
|
2008-01-04 13:24:59 +00:00
|
|
|
}
|
|
|
|
|
2008-10-21 13:20:09 +00:00
|
|
|
/* delete the mount point symlinks when a device goes away */
|
|
|
|
void delete_mount_point( struct mount_point *mount )
|
|
|
|
{
|
|
|
|
TRACE( "deleting %s\n", debugstr_w(mount->link.Buffer) );
|
|
|
|
list_remove( &mount->entry );
|
|
|
|
RegDeleteValueW( mount_key, mount->link.Buffer );
|
|
|
|
IoDeleteSymbolicLink( &mount->link );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount->id );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, mount );
|
|
|
|
}
|
|
|
|
|
2008-01-04 13:28:47 +00:00
|
|
|
/* check if a given mount point matches the requested specs */
|
|
|
|
static BOOL matching_mount_point( const struct mount_point *mount, const MOUNTMGR_MOUNT_POINT *spec )
|
|
|
|
{
|
|
|
|
if (spec->SymbolicLinkNameOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *name = (const WCHAR *)((const char *)spec + spec->SymbolicLinkNameOffset);
|
|
|
|
if (spec->SymbolicLinkNameLength != mount->link.Length) return FALSE;
|
2019-05-07 16:31:21 +00:00
|
|
|
if (strncmpiW( name, mount->link.Buffer, mount->link.Length/sizeof(WCHAR)))
|
2008-01-04 13:28:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (spec->DeviceNameOffset)
|
|
|
|
{
|
|
|
|
const WCHAR *name = (const WCHAR *)((const char *)spec + spec->DeviceNameOffset);
|
2008-10-17 18:01:23 +00:00
|
|
|
if (spec->DeviceNameLength != mount->name.Length) return FALSE;
|
2019-05-07 16:31:21 +00:00
|
|
|
if (strncmpiW( name, mount->name.Buffer, mount->name.Length/sizeof(WCHAR)))
|
2008-01-04 13:28:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (spec->UniqueIdOffset)
|
|
|
|
{
|
|
|
|
const void *id = ((const char *)spec + spec->UniqueIdOffset);
|
|
|
|
if (spec->UniqueIdLength != mount->id_len) return FALSE;
|
|
|
|
if (memcmp( id, mount->id, mount->id_len )) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_POINTS */
|
2011-11-01 12:03:12 +00:00
|
|
|
static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
|
|
|
|
SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
2008-01-04 13:28:47 +00:00
|
|
|
{
|
2008-10-17 18:09:31 +00:00
|
|
|
UINT count, pos, size;
|
2011-11-01 12:03:12 +00:00
|
|
|
MOUNTMGR_MOUNT_POINT *input = buff;
|
|
|
|
MOUNTMGR_MOUNT_POINTS *info;
|
2008-10-17 18:09:31 +00:00
|
|
|
struct mount_point *mount;
|
2008-01-04 13:28:47 +00:00
|
|
|
|
2021-08-31 03:25:57 +00:00
|
|
|
if (insize < sizeof(*input) ||
|
|
|
|
outsize < sizeof(*info) ||
|
|
|
|
input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength > insize ||
|
2008-01-04 13:28:47 +00:00
|
|
|
input->UniqueIdOffset + input->UniqueIdLength > insize ||
|
|
|
|
input->DeviceNameOffset + input->DeviceNameLength > insize ||
|
|
|
|
input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength < input->SymbolicLinkNameOffset ||
|
|
|
|
input->UniqueIdOffset + input->UniqueIdLength < input->UniqueIdOffset ||
|
|
|
|
input->DeviceNameOffset + input->DeviceNameLength < input->DeviceNameOffset)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
count = size = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
|
2008-01-04 13:28:47 +00:00
|
|
|
{
|
2008-10-17 18:09:31 +00:00
|
|
|
if (!matching_mount_point( mount, input )) continue;
|
2008-10-17 18:01:23 +00:00
|
|
|
size += mount->name.Length;
|
2008-10-17 18:09:31 +00:00
|
|
|
size += mount->link.Length;
|
|
|
|
size += mount->id_len;
|
2008-10-15 18:12:49 +00:00
|
|
|
size = (size + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
2008-10-17 18:09:31 +00:00
|
|
|
count++;
|
2008-01-04 13:28:47 +00:00
|
|
|
}
|
2008-10-17 18:09:31 +00:00
|
|
|
pos = FIELD_OFFSET( MOUNTMGR_MOUNT_POINTS, MountPoints[count] );
|
2008-01-04 13:28:47 +00:00
|
|
|
size += pos;
|
|
|
|
|
|
|
|
if (size > outsize)
|
|
|
|
{
|
2011-11-01 12:03:12 +00:00
|
|
|
info = buff;
|
2021-08-31 03:25:57 +00:00
|
|
|
info->Size = size;
|
2008-01-04 13:28:47 +00:00
|
|
|
iosb->Information = sizeof(info->Size);
|
2021-08-31 03:25:58 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
2008-01-04 13:28:47 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 12:03:12 +00:00
|
|
|
input = HeapAlloc( GetProcessHeap(), 0, insize );
|
|
|
|
if (!input)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
memcpy( input, buff, insize );
|
|
|
|
info = buff;
|
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
info->NumberOfMountPoints = count;
|
|
|
|
count = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( mount, &mount_points_list, struct mount_point, entry )
|
2008-01-04 13:28:47 +00:00
|
|
|
{
|
2008-10-17 18:09:31 +00:00
|
|
|
if (!matching_mount_point( mount, input )) continue;
|
2008-01-04 13:28:47 +00:00
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
info->MountPoints[count].DeviceNameOffset = pos;
|
2008-10-17 18:01:23 +00:00
|
|
|
info->MountPoints[count].DeviceNameLength = mount->name.Length;
|
2011-11-01 12:03:12 +00:00
|
|
|
memcpy( (char *)buff + pos, mount->name.Buffer, mount->name.Length );
|
2008-10-17 18:01:23 +00:00
|
|
|
pos += mount->name.Length;
|
2008-01-04 13:28:47 +00:00
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
info->MountPoints[count].SymbolicLinkNameOffset = pos;
|
|
|
|
info->MountPoints[count].SymbolicLinkNameLength = mount->link.Length;
|
2011-11-01 12:03:12 +00:00
|
|
|
memcpy( (char *)buff + pos, mount->link.Buffer, mount->link.Length );
|
2008-10-17 18:09:31 +00:00
|
|
|
pos += mount->link.Length;
|
2008-10-15 18:12:49 +00:00
|
|
|
|
2008-10-17 18:09:31 +00:00
|
|
|
info->MountPoints[count].UniqueIdOffset = pos;
|
|
|
|
info->MountPoints[count].UniqueIdLength = mount->id_len;
|
2011-11-01 12:03:12 +00:00
|
|
|
memcpy( (char *)buff + pos, mount->id, mount->id_len );
|
2008-10-17 18:09:31 +00:00
|
|
|
pos += mount->id_len;
|
2008-10-15 18:12:49 +00:00
|
|
|
pos = (pos + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
2008-10-17 18:09:31 +00:00
|
|
|
count++;
|
2008-01-04 13:28:47 +00:00
|
|
|
}
|
|
|
|
info->Size = pos;
|
|
|
|
iosb->Information = pos;
|
2011-11-01 12:03:12 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, input );
|
2008-01-04 13:28:47 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-10-23 13:48:08 +00:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE */
|
|
|
|
static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
|
|
|
|
{
|
|
|
|
const struct mountmgr_unix_drive *input = in_buff;
|
|
|
|
const char *mount_point = NULL, *device = NULL;
|
|
|
|
WCHAR letter = tolowerW( input->letter );
|
|
|
|
|
|
|
|
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
|
|
|
|
if (input->type > DRIVE_RAMDISK) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (input->mount_point_offset > insize || input->device_offset > insize)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* make sure string are null-terminated */
|
|
|
|
if (input->mount_point_offset)
|
|
|
|
{
|
|
|
|
mount_point = (const char *)in_buff + input->mount_point_offset;
|
2021-11-25 10:07:37 +00:00
|
|
|
if (!memchr( mount_point, 0, insize - input->mount_point_offset )) return STATUS_INVALID_PARAMETER;
|
2008-10-23 13:48:08 +00:00
|
|
|
}
|
|
|
|
if (input->device_offset)
|
|
|
|
{
|
|
|
|
device = (const char *)in_buff + input->device_offset;
|
2021-11-25 10:07:37 +00:00
|
|
|
if (!memchr( device, 0, insize - input->device_offset )) return STATUS_INVALID_PARAMETER;
|
2008-10-23 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (input->type != DRIVE_NO_ROOT_DIR)
|
|
|
|
{
|
2008-11-12 09:47:49 +00:00
|
|
|
enum device_type type = DEVICE_UNKNOWN;
|
|
|
|
|
2008-10-23 13:48:08 +00:00
|
|
|
TRACE( "defining %c: dev %s mount %s type %u\n",
|
|
|
|
letter, debugstr_a(device), debugstr_a(mount_point), input->type );
|
2008-11-12 09:47:49 +00:00
|
|
|
switch (input->type)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE: type = (letter >= 'c') ? DEVICE_HARDDISK : DEVICE_FLOPPY; break;
|
|
|
|
case DRIVE_REMOTE: type = DEVICE_NETWORK; break;
|
|
|
|
case DRIVE_CDROM: type = DEVICE_CDROM; break;
|
|
|
|
case DRIVE_RAMDISK: type = DEVICE_RAMDISK; break;
|
2009-06-04 08:14:56 +00:00
|
|
|
case DRIVE_FIXED: type = DEVICE_HARDDISK_VOL; break;
|
2008-11-12 09:47:49 +00:00
|
|
|
}
|
2019-11-25 17:40:34 +00:00
|
|
|
return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL, NULL );
|
2008-10-23 13:48:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "removing %c:\n", letter );
|
|
|
|
return remove_dos_device( letter - 'a', NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:18:17 +00:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER */
|
|
|
|
static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
|
|
|
|
{
|
|
|
|
const struct mountmgr_shell_folder *input = in_buff;
|
|
|
|
const char *link = NULL;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING name;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size = 256;
|
2021-09-17 14:50:00 +00:00
|
|
|
const char *home;
|
|
|
|
char *buffer = NULL, *backup = NULL, *homelink = NULL;
|
2021-09-07 11:18:17 +00:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (input->folder_offset >= insize || input->folder_size > insize - input->folder_offset ||
|
|
|
|
input->symlink_offset >= insize)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* make sure string is null-terminated */
|
|
|
|
if (input->symlink_offset)
|
|
|
|
{
|
|
|
|
link = (const char *)in_buff + input->symlink_offset;
|
2021-11-25 10:07:37 +00:00
|
|
|
if (!memchr( link, 0, insize - input->symlink_offset )) return STATUS_INVALID_PARAMETER;
|
2021-09-07 11:18:17 +00:00
|
|
|
if (!link[0]) link = NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-17 14:50:00 +00:00
|
|
|
if (link && (!strcmp( link, "$HOME" ) || !strncmp( link, "$HOME/", 6 )) && (home = getenv( "HOME" )))
|
|
|
|
{
|
|
|
|
link += 5;
|
|
|
|
homelink = HeapAlloc( GetProcessHeap(), 0, strlen(home) + strlen(link) + 1 );
|
|
|
|
strcpy( homelink, home );
|
|
|
|
strcat( homelink, link );
|
|
|
|
link = homelink;
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:18:17 +00:00
|
|
|
/* ignore nonexistent link targets */
|
2021-09-17 14:50:00 +00:00
|
|
|
if (link && (stat( link, &st ) || !S_ISDIR( st.st_mode )))
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
goto done;
|
|
|
|
}
|
2021-09-07 11:18:17 +00:00
|
|
|
|
|
|
|
name.Buffer = (WCHAR *)((char *)in_buff + input->folder_offset);
|
|
|
|
name.Length = input->folder_size;
|
|
|
|
InitializeObjectAttributes( &attr, &name, 0, 0, NULL );
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2021-09-17 14:50:00 +00:00
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN_IF );
|
|
|
|
if (status == STATUS_NO_SUCH_FILE) status = STATUS_SUCCESS;
|
|
|
|
if (status == STATUS_SUCCESS) break;
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) goto done;
|
2021-09-07 11:18:17 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
}
|
|
|
|
|
2021-09-17 14:49:30 +00:00
|
|
|
if (input->create_backup)
|
2021-09-07 11:18:17 +00:00
|
|
|
{
|
2021-09-17 14:49:30 +00:00
|
|
|
if (!(backup = HeapAlloc( GetProcessHeap(), 0, strlen(buffer) + sizeof(".backup" ) )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
strcpy( backup, buffer );
|
|
|
|
strcat( backup, ".backup" );
|
2021-09-07 11:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!lstat( buffer, &st )) /* move old folder/link out of the way */
|
|
|
|
{
|
|
|
|
if (S_ISLNK( st.st_mode ))
|
|
|
|
{
|
|
|
|
unlink( buffer );
|
|
|
|
}
|
|
|
|
else if (link && S_ISDIR( st.st_mode ))
|
|
|
|
{
|
|
|
|
if (rmdir( buffer )) /* non-empty dir, try to make a backup */
|
|
|
|
{
|
|
|
|
if (!backup || rename( buffer, backup ))
|
|
|
|
{
|
|
|
|
status = STATUS_OBJECT_NAME_COLLISION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else goto done; /* nothing to do, folder already exists */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (link) symlink( link, buffer );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (backup && !lstat( backup, &st ) && S_ISDIR( st.st_mode )) rename( backup, buffer );
|
|
|
|
else mkdir( buffer, 0777 );
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
HeapFree( GetProcessHeap(), 0, backup );
|
2021-09-17 14:50:00 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, homelink );
|
2021-09-07 11:18:17 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_SHELL_FOLDER */
|
|
|
|
static NTSTATUS query_shell_folder( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
char *output = buff;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING name;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size = 256;
|
|
|
|
char *buffer;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
name.Buffer = buff;
|
|
|
|
name.Length = insize;
|
|
|
|
InitializeObjectAttributes( &attr, &name, 0, 0, NULL );
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) return STATUS_NO_MEMORY;
|
|
|
|
status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN );
|
|
|
|
if (!status) break;
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) return status;
|
|
|
|
}
|
|
|
|
ret = readlink( buffer, output, outsize - 1 );
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
output[ret] = 0;
|
|
|
|
iosb->Information = ret + 1;
|
|
|
|
}
|
|
|
|
else status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-19 13:44:58 +00:00
|
|
|
/* implementation of IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS */
|
2021-07-06 09:11:47 +00:00
|
|
|
static void WINAPI query_dhcp_request_params( TP_CALLBACK_INSTANCE *instance, void *context )
|
2019-11-19 13:44:58 +00:00
|
|
|
{
|
2021-07-06 09:11:47 +00:00
|
|
|
IRP *irp = context;
|
|
|
|
struct mountmgr_dhcp_request_params *query = irp->AssociatedIrp.SystemBuffer;
|
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
|
|
|
SIZE_T insize = irpsp->Parameters.DeviceIoControl.InputBufferLength;
|
|
|
|
SIZE_T outsize = irpsp->Parameters.DeviceIoControl.OutputBufferLength;
|
|
|
|
ULONG i, offset = 0;
|
2019-11-19 13:44:58 +00:00
|
|
|
|
|
|
|
/* sanity checks */
|
2021-07-07 08:05:54 +00:00
|
|
|
if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize)
|
2021-07-06 09:11:47 +00:00
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2019-11-19 13:44:58 +00:00
|
|
|
for (i = 0; i < query->count; i++)
|
2021-07-06 09:11:47 +00:00
|
|
|
if (query->params[i].offset + query->params[i].size > insize)
|
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-11-25 10:07:37 +00:00
|
|
|
if (!memchr( query->unix_name, 0, sizeof(query->unix_name) ))
|
|
|
|
{
|
|
|
|
irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto err;
|
|
|
|
}
|
2019-11-19 13:44:58 +00:00
|
|
|
|
|
|
|
offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
|
|
|
|
for (i = 0; i < query->count; i++)
|
|
|
|
{
|
2021-11-25 10:07:37 +00:00
|
|
|
offset += get_dhcp_request_param( query->unix_name, &query->params[i], (char *)query, offset, outsize - offset );
|
2019-11-19 13:44:58 +00:00
|
|
|
if (offset > outsize)
|
|
|
|
{
|
|
|
|
if (offset >= sizeof(query->size)) query->size = offset;
|
2021-07-06 09:11:47 +00:00
|
|
|
offset = sizeof(query->size);
|
2021-08-31 03:25:59 +00:00
|
|
|
irp->IoStatus.u.Status = STATUS_BUFFER_OVERFLOW;
|
2021-07-06 09:11:47 +00:00
|
|
|
goto err;
|
2019-11-19 13:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-06 09:11:47 +00:00
|
|
|
irp->IoStatus.u.Status = STATUS_SUCCESS;
|
2019-11-19 13:44:58 +00:00
|
|
|
|
2021-07-06 09:11:47 +00:00
|
|
|
err:
|
|
|
|
irp->IoStatus.Information = offset;
|
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2019-11-19 13:44:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 13:23:27 +00:00
|
|
|
/* implementation of Wine extension to use host APIs to find symbol file by GUID */
|
|
|
|
#ifdef __APPLE__
|
|
|
|
static void WINAPI query_symbol_file( TP_CALLBACK_INSTANCE *instance, void *context )
|
|
|
|
{
|
|
|
|
IRP *irp = context;
|
|
|
|
MOUNTMGR_TARGET_NAME *result;
|
|
|
|
CFStringRef query_cfstring;
|
2020-07-08 12:16:21 +00:00
|
|
|
WCHAR *filename, *unix_buf = NULL;
|
2020-04-03 13:23:27 +00:00
|
|
|
ANSI_STRING unix_path;
|
|
|
|
UNICODE_STRING path;
|
|
|
|
MDQueryRef mdquery;
|
|
|
|
const GUID *id;
|
|
|
|
size_t size;
|
|
|
|
NTSTATUS status = STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
static const WCHAR formatW[] = { 'c','o','m','_','a','p','p','l','e','_','x','c','o','d','e',
|
|
|
|
'_','d','s','y','m','_','u','u','i','d','s',' ','=','=',' ',
|
|
|
|
'"','%','0','8','X','-','%','0','4','X','-',
|
|
|
|
'%','0','4','X','-','%','0','2','X','%','0','2','X','-',
|
|
|
|
'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
|
|
|
|
'%','0','2','X','%','0','2','X','"',0 };
|
|
|
|
WCHAR query_string[ARRAY_SIZE(formatW)];
|
|
|
|
|
|
|
|
id = irp->AssociatedIrp.SystemBuffer;
|
|
|
|
sprintfW( query_string, formatW, id->Data1, id->Data2, id->Data3,
|
|
|
|
id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
|
|
|
|
id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
|
|
|
|
if (!(query_cfstring = CFStringCreateWithCharacters(NULL, query_string, lstrlenW(query_string)))) goto done;
|
|
|
|
|
|
|
|
mdquery = MDQueryCreate(NULL, query_cfstring, NULL, NULL);
|
|
|
|
CFRelease(query_cfstring);
|
|
|
|
if (!mdquery) goto done;
|
|
|
|
|
|
|
|
MDQuerySetMaxCount(mdquery, 1);
|
|
|
|
TRACE("Executing %s\n", debugstr_w(query_string));
|
|
|
|
if (MDQueryExecute(mdquery, kMDQuerySynchronous))
|
|
|
|
{
|
|
|
|
if (MDQueryGetResultCount(mdquery) >= 1)
|
|
|
|
{
|
|
|
|
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(mdquery, 0);
|
|
|
|
CFStringRef item_path = MDItemCopyAttribute(item, kMDItemPath);
|
|
|
|
|
|
|
|
if (item_path)
|
|
|
|
{
|
|
|
|
CFIndex item_path_len = CFStringGetLength(item_path);
|
|
|
|
if ((unix_buf = HeapAlloc(GetProcessHeap(), 0, (item_path_len + 1) * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
CFStringGetCharacters(item_path, CFRangeMake(0, item_path_len), unix_buf);
|
|
|
|
unix_buf[item_path_len] = 0;
|
|
|
|
TRACE("found %s\n", debugstr_w(unix_buf));
|
|
|
|
}
|
|
|
|
CFRelease(item_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else status = STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
CFRelease(mdquery);
|
|
|
|
if (!unix_buf) goto done;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &path, unix_buf );
|
|
|
|
status = RtlUnicodeStringToAnsiString( &unix_path, &path, TRUE );
|
|
|
|
HeapFree( GetProcessHeap(), 0, unix_buf );
|
|
|
|
if (status) goto done;
|
|
|
|
|
2020-07-08 12:16:21 +00:00
|
|
|
filename = wine_get_dos_file_name( unix_path.Buffer );
|
2020-04-03 13:23:27 +00:00
|
|
|
RtlFreeAnsiString( &unix_path );
|
2020-07-08 12:16:21 +00:00
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
status = STATUS_NO_SUCH_FILE;
|
|
|
|
goto done;
|
|
|
|
}
|
2020-04-03 13:23:27 +00:00
|
|
|
result = irp->AssociatedIrp.SystemBuffer;
|
2020-07-08 12:16:21 +00:00
|
|
|
result->DeviceNameLength = lstrlenW(filename) * sizeof(WCHAR);
|
|
|
|
size = FIELD_OFFSET(MOUNTMGR_TARGET_NAME, DeviceName[lstrlenW(filename)]);
|
2020-04-03 13:23:27 +00:00
|
|
|
if (size <= IoGetCurrentIrpStackLocation(irp)->Parameters.DeviceIoControl.OutputBufferLength)
|
|
|
|
{
|
2020-07-08 12:16:21 +00:00
|
|
|
memcpy( result->DeviceName, filename, lstrlenW(filename) * sizeof(WCHAR) );
|
2020-04-03 13:23:27 +00:00
|
|
|
irp->IoStatus.Information = size;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
irp->IoStatus.Information = sizeof(*result);
|
|
|
|
status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2020-07-08 12:16:21 +00:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, filename );
|
2020-04-03 13:23:27 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
irp->IoStatus.u.Status = status;
|
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
|
|
|
}
|
2020-09-02 13:07:59 +00:00
|
|
|
|
|
|
|
static inline BOOL check_credential_string( const void *buf, SIZE_T buflen, ULONG size, ULONG offset )
|
|
|
|
{
|
|
|
|
const WCHAR *ptr = buf;
|
|
|
|
if (!size || size % sizeof(WCHAR) || offset + size > buflen || ptr[(offset + size) / sizeof(WCHAR) - 1]) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SecKeychainItemRef find_credential( const WCHAR *name )
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
SecKeychainSearchRef search;
|
|
|
|
SecKeychainItemRef item;
|
|
|
|
|
|
|
|
status = SecKeychainSearchCreateFromAttributes( NULL, kSecGenericPasswordItemClass, NULL, &search );
|
|
|
|
if (status != noErr) return NULL;
|
|
|
|
|
|
|
|
while (SecKeychainSearchCopyNext( search, &item ) == noErr)
|
|
|
|
{
|
|
|
|
SecKeychainAttributeInfo info;
|
|
|
|
SecKeychainAttributeList *attr_list;
|
|
|
|
UInt32 info_tags[] = { kSecServiceItemAttr };
|
|
|
|
WCHAR *itemname;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
info.count = ARRAY_SIZE(info_tags);
|
|
|
|
info.tag = info_tags;
|
|
|
|
info.format = NULL;
|
|
|
|
status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, NULL, NULL );
|
|
|
|
if (status != noErr)
|
|
|
|
{
|
|
|
|
WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)
|
|
|
|
{
|
|
|
|
CFRelease( item );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[0].data, attr_list->attr[0].length, NULL, 0 );
|
|
|
|
if (!(itemname = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
CFRelease( item );
|
|
|
|
CFRelease( search );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[0].data, attr_list->attr[0].length, itemname, len );
|
|
|
|
itemname[len] = 0;
|
|
|
|
if (strcmpiW( itemname, name ))
|
|
|
|
{
|
|
|
|
CFRelease( item );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, itemname );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, itemname );
|
|
|
|
SecKeychainItemFreeAttributesAndData( attr_list, NULL );
|
|
|
|
CFRelease( search );
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease( search );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fill_credential( SecKeychainItemRef item, BOOL require_password, void *buf, SIZE_T data_offset,
|
|
|
|
SIZE_T buflen, SIZE_T *retlen )
|
|
|
|
{
|
|
|
|
struct mountmgr_credential *cred = buf;
|
|
|
|
int status, len;
|
|
|
|
SIZE_T size;
|
|
|
|
UInt32 i, cred_blob_len = 0;
|
|
|
|
void *cred_blob;
|
|
|
|
WCHAR *ptr;
|
|
|
|
BOOL user_name_present = FALSE;
|
|
|
|
SecKeychainAttributeInfo info;
|
|
|
|
SecKeychainAttributeList *attr_list = NULL;
|
|
|
|
UInt32 info_tags[] = { kSecServiceItemAttr, kSecAccountItemAttr, kSecCommentItemAttr, kSecCreationDateItemAttr };
|
|
|
|
|
|
|
|
info.count = ARRAY_SIZE(info_tags);
|
|
|
|
info.tag = info_tags;
|
|
|
|
info.format = NULL;
|
|
|
|
status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, &cred_blob_len, &cred_blob );
|
|
|
|
if (status == errSecAuthFailed && !require_password)
|
|
|
|
{
|
|
|
|
cred_blob_len = 0;
|
|
|
|
cred_blob = NULL;
|
|
|
|
status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, &cred_blob_len, NULL );
|
|
|
|
}
|
|
|
|
if (status != noErr)
|
|
|
|
{
|
|
|
|
WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
|
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
for (i = 0; i < attr_list->count; i++)
|
|
|
|
{
|
|
|
|
if (attr_list->attr[i].tag == kSecAccountItemAttr && attr_list->attr[i].data)
|
|
|
|
{
|
|
|
|
user_name_present = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!user_name_present)
|
|
|
|
{
|
|
|
|
WARN( "no kSecAccountItemAttr for item\n" );
|
|
|
|
SecKeychainItemFreeAttributesAndData( attr_list, cred_blob );
|
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
*retlen = sizeof(*cred);
|
|
|
|
for (i = 0; i < attr_list->count; i++)
|
|
|
|
{
|
|
|
|
switch (attr_list->attr[i].tag)
|
|
|
|
{
|
|
|
|
case kSecServiceItemAttr:
|
|
|
|
TRACE( "kSecServiceItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
|
|
|
|
if (cred) cred->targetname_offset = cred->targetname_size = 0;
|
|
|
|
if (!attr_list->attr[i].data) continue;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
|
|
|
|
size = (len + 1) * sizeof(WCHAR);
|
|
|
|
if (cred && *retlen + size <= buflen)
|
|
|
|
{
|
|
|
|
cred->targetname_offset = data_offset;
|
|
|
|
cred->targetname_size = size;
|
|
|
|
ptr = (WCHAR *)((char *)cred + cred->targetname_offset);
|
|
|
|
MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
|
|
|
|
ptr[len] = 0;
|
|
|
|
data_offset += size;
|
|
|
|
}
|
|
|
|
*retlen += size;
|
|
|
|
break;
|
|
|
|
case kSecAccountItemAttr:
|
|
|
|
{
|
|
|
|
TRACE( "kSecAccountItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
|
|
|
|
if (cred) cred->username_offset = cred->username_size = 0;
|
|
|
|
if (!attr_list->attr[i].data) continue;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
|
|
|
|
size = (len + 1) * sizeof(WCHAR);
|
|
|
|
if (cred && *retlen + size <= buflen)
|
|
|
|
{
|
|
|
|
cred->username_offset = data_offset;
|
|
|
|
cred->username_size = size;
|
|
|
|
ptr = (WCHAR *)((char *)cred + cred->username_offset);
|
|
|
|
MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
|
|
|
|
ptr[len] = 0;
|
|
|
|
data_offset += size;
|
|
|
|
}
|
|
|
|
*retlen += size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kSecCommentItemAttr:
|
|
|
|
TRACE( "kSecCommentItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
|
|
|
|
if (cred) cred->comment_offset = cred->comment_size = 0;
|
|
|
|
if (!attr_list->attr[i].data) continue;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
|
|
|
|
size = (len + 1) * sizeof(WCHAR);
|
|
|
|
if (cred && *retlen + size <= buflen)
|
|
|
|
{
|
|
|
|
cred->comment_offset = data_offset;
|
|
|
|
cred->comment_size = size;
|
|
|
|
ptr = (WCHAR *)((char *)cred + cred->comment_offset);
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
|
|
|
|
ptr[len] = 0;
|
|
|
|
data_offset += size;
|
|
|
|
}
|
|
|
|
*retlen += size;
|
|
|
|
break;
|
|
|
|
case kSecCreationDateItemAttr:
|
|
|
|
{
|
|
|
|
LARGE_INTEGER wintime;
|
|
|
|
struct tm tm;
|
|
|
|
time_t time;
|
|
|
|
|
|
|
|
TRACE( "kSecCreationDateItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
|
|
|
|
if (cred) cred->last_written.dwLowDateTime = cred->last_written.dwHighDateTime = 0;
|
|
|
|
if (!attr_list->attr[i].data) continue;
|
|
|
|
|
|
|
|
if (cred)
|
|
|
|
{
|
|
|
|
memset( &tm, 0, sizeof(tm) );
|
|
|
|
strptime( attr_list->attr[i].data, "%Y%m%d%H%M%SZ", &tm );
|
|
|
|
time = mktime( &tm );
|
|
|
|
RtlSecondsSince1970ToTime( time, &wintime );
|
|
|
|
cred->last_written.dwLowDateTime = wintime.u.LowPart;
|
|
|
|
cred->last_written.dwHighDateTime = wintime.u.HighPart;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "unhandled attribute %u\n", (unsigned)attr_list->attr[i].tag );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cred)
|
|
|
|
{
|
|
|
|
if (*retlen + cred_blob_len <= buflen)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, cred_blob, cred_blob_len, NULL, 0 );
|
|
|
|
cred->blob_offset = data_offset;
|
|
|
|
cred->blob_size = len * sizeof(WCHAR);
|
|
|
|
ptr = (WCHAR *)((char *)cred + cred->blob_offset);
|
|
|
|
MultiByteToWideChar( CP_UTF8, 0, cred_blob, cred_blob_len, ptr, len );
|
|
|
|
}
|
|
|
|
else cred->blob_offset = cred->blob_size = 0;
|
|
|
|
}
|
|
|
|
*retlen += cred_blob_len;
|
|
|
|
|
|
|
|
if (attr_list) SecKeychainItemFreeAttributesAndData( attr_list, cred_blob );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS read_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
struct mountmgr_credential *cred = buff;
|
|
|
|
const WCHAR *targetname;
|
|
|
|
SecKeychainItemRef item;
|
|
|
|
SIZE_T size;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
targetname = (const WCHAR *)((const char *)cred + cred->targetname_offset);
|
|
|
|
|
|
|
|
if (!(item = find_credential( targetname ))) return STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
status = fill_credential( item, TRUE, cred, sizeof(*cred), outsize, &size );
|
|
|
|
CFRelease( item );
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
|
|
|
iosb->Information = size;
|
|
|
|
return (size > outsize) ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
|
|
|
|
}
|
2020-09-03 12:59:04 +00:00
|
|
|
|
|
|
|
static NTSTATUS write_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
const struct mountmgr_credential *cred = buff;
|
|
|
|
int status, len, len_password = 0;
|
|
|
|
const WCHAR *ptr;
|
|
|
|
SecKeychainItemRef keychain_item;
|
|
|
|
char *targetname, *username = NULL, *password = NULL;
|
|
|
|
SecKeychainAttribute attrs[1];
|
|
|
|
SecKeychainAttributeList attr_list;
|
|
|
|
NTSTATUS ret = STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ) ||
|
|
|
|
!check_credential_string( buff, insize, cred->username_size, cred->username_offset ) ||
|
|
|
|
((cred->blob_size && cred->blob_size % sizeof(WCHAR)) || cred->blob_offset + cred->blob_size > insize) ||
|
|
|
|
(cred->comment_size && !check_credential_string( buff, insize, cred->comment_size, cred->comment_offset )) ||
|
|
|
|
sizeof(*cred) + cred->targetname_size + cred->username_size + cred->blob_size + cred->comment_size > insize)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (const WCHAR *)((const char *)cred + cred->targetname_offset);
|
|
|
|
len = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
|
|
|
|
if (!(targetname = RtlAllocateHeap( GetProcessHeap(), 0, len ))) goto error;
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, ptr, -1, targetname, len, NULL, NULL );
|
|
|
|
|
|
|
|
ptr = (const WCHAR *)((const char *)cred + cred->username_offset);
|
|
|
|
len = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
|
|
|
|
if (!(username = RtlAllocateHeap( GetProcessHeap(), 0, len ))) goto error;
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, ptr, -1, username, len, NULL, NULL );
|
|
|
|
|
|
|
|
if (cred->blob_size)
|
|
|
|
{
|
|
|
|
ptr = (const WCHAR *)((const char *)cred + cred->blob_offset);
|
|
|
|
len_password = WideCharToMultiByte( CP_UTF8, 0, ptr, cred->blob_size / sizeof(WCHAR), NULL, 0, NULL, NULL );
|
|
|
|
if (!(password = RtlAllocateHeap( GetProcessHeap(), 0, len_password ))) goto error;
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, ptr, cred->blob_size / sizeof(WCHAR), password, len_password, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("adding target %s, username %s using Keychain\n", targetname, username );
|
|
|
|
status = SecKeychainAddGenericPassword( NULL, strlen(targetname), targetname, strlen(username), username,
|
|
|
|
len_password, password, &keychain_item );
|
|
|
|
if (status != noErr) ERR( "SecKeychainAddGenericPassword returned %d\n", status );
|
|
|
|
if (status == errSecDuplicateItem)
|
|
|
|
{
|
|
|
|
status = SecKeychainFindGenericPassword( NULL, strlen(targetname), targetname, strlen(username), username, NULL,
|
|
|
|
NULL, &keychain_item );
|
|
|
|
if (status != noErr) ERR( "SecKeychainFindGenericPassword returned %d\n", status );
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, username );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, targetname );
|
|
|
|
if (status != noErr)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, password );
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
if (cred->comment_size)
|
|
|
|
{
|
|
|
|
attr_list.count = 1;
|
|
|
|
attr_list.attr = attrs;
|
|
|
|
attrs[0].tag = kSecCommentItemAttr;
|
|
|
|
ptr = (const WCHAR *)((const char *)cred + cred->comment_offset);
|
|
|
|
attrs[0].length = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
|
|
|
|
if (attrs[0].length) attrs[0].length--;
|
|
|
|
if (!(attrs[0].data = RtlAllocateHeap( GetProcessHeap(), 0, attrs[0].length ))) goto error;
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, ptr, -1, attrs[0].data, attrs[0].length, NULL, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attr_list.count = 0;
|
|
|
|
attr_list.attr = NULL;
|
|
|
|
}
|
|
|
|
status = SecKeychainItemModifyAttributesAndData( keychain_item, &attr_list, cred->blob_preserve ? 0 : len_password,
|
|
|
|
cred->blob_preserve ? NULL : password );
|
|
|
|
|
|
|
|
if (cred->comment_size) RtlFreeHeap( GetProcessHeap(), 0, attrs[0].data );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, password );
|
|
|
|
/* FIXME: set TargetAlias attribute */
|
|
|
|
CFRelease( keychain_item );
|
|
|
|
if (status != noErr) return STATUS_UNSUCCESSFUL;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, username );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, targetname );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, password );
|
|
|
|
return ret;
|
|
|
|
}
|
2020-09-03 12:59:06 +00:00
|
|
|
|
|
|
|
static NTSTATUS delete_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
const struct mountmgr_credential *cred = buff;
|
|
|
|
const WCHAR *targetname;
|
|
|
|
SecKeychainItemRef item;
|
|
|
|
|
|
|
|
if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
targetname = (const WCHAR *)((const char *)cred + cred->targetname_offset);
|
|
|
|
|
|
|
|
if (!(item = find_credential( targetname ))) return STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
SecKeychainItemDelete( item );
|
|
|
|
CFRelease( item );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2020-09-03 12:59:08 +00:00
|
|
|
|
|
|
|
static BOOL match_credential( void *data, UInt32 data_len, const WCHAR *filter )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
WCHAR *targetname;
|
|
|
|
const WCHAR *p;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!*filter) return TRUE;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, data, data_len, NULL, 0 );
|
|
|
|
if (!(targetname = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
MultiByteToWideChar( CP_UTF8, 0, data, data_len, targetname, len );
|
|
|
|
targetname[len] = 0;
|
|
|
|
|
|
|
|
TRACE( "comparing filter %s to target name %s\n", debugstr_w(filter), debugstr_w(targetname) );
|
|
|
|
|
|
|
|
p = strchrW( filter, '*' );
|
|
|
|
ret = CompareStringW( GetThreadLocale(), NORM_IGNORECASE, filter,
|
|
|
|
(p && !p[1]) ? p - filter : -1, targetname, (p && !p[1]) ? p - filter : -1 ) == CSTR_EQUAL;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, targetname );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS search_credentials( const WCHAR *filter, struct mountmgr_credential_list *list, SIZE_T *ret_count, SIZE_T *ret_size )
|
|
|
|
{
|
|
|
|
SecKeychainSearchRef search;
|
|
|
|
SecKeychainItemRef item;
|
|
|
|
int status;
|
|
|
|
ULONG i = 0;
|
|
|
|
SIZE_T data_offset, data_size = 0, size;
|
|
|
|
NTSTATUS ret = STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
status = SecKeychainSearchCreateFromAttributes( NULL, kSecGenericPasswordItemClass, NULL, &search );
|
|
|
|
if (status != noErr)
|
|
|
|
{
|
|
|
|
ERR( "SecKeychainSearchCreateFromAttributes returned status %d\n", status );
|
|
|
|
return STATUS_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (SecKeychainSearchCopyNext( search, &item ) == noErr)
|
|
|
|
{
|
|
|
|
SecKeychainAttributeInfo info;
|
|
|
|
SecKeychainAttributeList *attr_list;
|
|
|
|
UInt32 info_tags[] = { kSecServiceItemAttr };
|
|
|
|
BOOL match;
|
|
|
|
|
|
|
|
info.count = ARRAY_SIZE(info_tags);
|
|
|
|
info.tag = info_tags;
|
|
|
|
info.format = NULL;
|
|
|
|
status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, NULL, NULL );
|
|
|
|
if (status != noErr)
|
|
|
|
{
|
|
|
|
WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
|
|
|
|
CFRelease( item );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)
|
|
|
|
{
|
|
|
|
SecKeychainItemFreeAttributesAndData( attr_list, NULL );
|
|
|
|
CFRelease( item );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
TRACE( "service item: %.*s\n", (int)attr_list->attr[0].length, (char *)attr_list->attr[0].data );
|
|
|
|
|
|
|
|
match = match_credential( attr_list->attr[0].data, attr_list->attr[0].length, filter );
|
|
|
|
SecKeychainItemFreeAttributesAndData( attr_list, NULL );
|
|
|
|
if (!match)
|
|
|
|
{
|
|
|
|
CFRelease( item );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!list) ret = fill_credential( item, FALSE, NULL, 0, 0, &size );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data_offset = FIELD_OFFSET( struct mountmgr_credential_list, creds[list->count] ) -
|
|
|
|
FIELD_OFFSET( struct mountmgr_credential_list, creds[i] ) + data_size;
|
|
|
|
ret = fill_credential( item, FALSE, &list->creds[i], data_offset, list->size - data_offset, &size );
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease( item );
|
|
|
|
if (ret == STATUS_NOT_FOUND) continue;
|
|
|
|
if (ret != STATUS_SUCCESS) break;
|
|
|
|
data_size += size - sizeof(struct mountmgr_credential);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_count) *ret_count = i;
|
|
|
|
if (ret_size) *ret_size = FIELD_OFFSET( struct mountmgr_credential_list, creds[i] ) + data_size;
|
|
|
|
|
|
|
|
CFRelease( search );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS enumerate_credentials( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
|
|
|
|
{
|
|
|
|
struct mountmgr_credential_list *list = buff;
|
|
|
|
WCHAR *filter;
|
|
|
|
SIZE_T size, count;
|
|
|
|
Boolean saved_user_interaction_allowed;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!check_credential_string( buff, insize, list->filter_size, list->filter_offset )) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (!(filter = strdupW( (const WCHAR *)((const char *)list + list->filter_offset) ))) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
SecKeychainGetUserInteractionAllowed( &saved_user_interaction_allowed );
|
|
|
|
SecKeychainSetUserInteractionAllowed( false );
|
|
|
|
|
|
|
|
if ((status = search_credentials( filter, NULL, &count, &size )) == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (size > outsize)
|
|
|
|
{
|
|
|
|
if (size >= sizeof(list->size)) list->size = size;
|
|
|
|
iosb->Information = sizeof(list->size);
|
2021-08-31 03:26:00 +00:00
|
|
|
status = STATUS_BUFFER_OVERFLOW;
|
2020-09-03 12:59:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list->size = size;
|
|
|
|
list->count = count;
|
|
|
|
iosb->Information = size;
|
|
|
|
status = search_credentials( filter, list, NULL, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SecKeychainSetUserInteractionAllowed( saved_user_interaction_allowed );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, filter );
|
|
|
|
return status;
|
|
|
|
}
|
2020-04-03 13:23:27 +00:00
|
|
|
#endif /* __APPLE__ */
|
|
|
|
|
2008-01-04 12:07:05 +00:00
|
|
|
/* handler for ioctls on the mount manager device */
|
|
|
|
static NTSTATUS WINAPI mountmgr_ioctl( DEVICE_OBJECT *device, IRP *irp )
|
|
|
|
{
|
2010-03-23 16:08:03 +00:00
|
|
|
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp );
|
2021-02-05 06:00:45 +00:00
|
|
|
NTSTATUS status;
|
2008-01-04 12:07:05 +00:00
|
|
|
|
|
|
|
TRACE( "ioctl %x insize %u outsize %u\n",
|
|
|
|
irpsp->Parameters.DeviceIoControl.IoControlCode,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength );
|
|
|
|
|
|
|
|
switch(irpsp->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
{
|
2008-01-04 13:28:47 +00:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_POINTS:
|
2021-02-05 06:00:45 +00:00
|
|
|
status = query_mount_points( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2008-01-04 13:28:47 +00:00
|
|
|
break;
|
2008-10-23 13:48:08 +00:00
|
|
|
case IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
|
2011-11-01 12:03:22 +00:00
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2011-11-01 12:03:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-23 13:48:08 +00:00
|
|
|
irp->IoStatus.Information = 0;
|
2021-02-05 06:00:45 +00:00
|
|
|
status = define_unix_drive( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength );
|
2008-10-23 13:48:08 +00:00
|
|
|
break;
|
2008-10-23 13:52:39 +00:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
|
2011-11-01 12:03:22 +00:00
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2011-11-01 12:03:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
status = query_unix_drive( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2008-10-23 13:52:39 +00:00
|
|
|
break;
|
2021-09-07 11:18:17 +00:00
|
|
|
case IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_shell_folder))
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
irp->IoStatus.Information = 0;
|
|
|
|
status = define_shell_folder( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength );
|
|
|
|
break;
|
|
|
|
case IOCTL_MOUNTMGR_QUERY_SHELL_FOLDER:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_shell_folder))
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
status = query_shell_folder( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
|
|
|
break;
|
2019-11-19 13:44:58 +00:00
|
|
|
case IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_dhcp_request_params))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2019-11-19 13:44:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-06 09:11:47 +00:00
|
|
|
|
|
|
|
if (TrySubmitThreadpoolCallback( query_dhcp_request_params, irp, NULL ))
|
|
|
|
return (irp->IoStatus.u.Status = STATUS_PENDING);
|
|
|
|
status = STATUS_NO_MEMORY;
|
2019-11-19 13:44:58 +00:00
|
|
|
break;
|
2020-04-03 13:23:27 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
case IOCTL_MOUNTMGR_QUERY_SYMBOL_FILE:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength != sizeof(GUID)
|
|
|
|
|| irpsp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUNTMGR_TARGET_NAME))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2020-04-03 13:23:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
if (TrySubmitThreadpoolCallback( query_symbol_file, irp, NULL ))
|
|
|
|
return (irp->IoStatus.u.Status = STATUS_PENDING);
|
|
|
|
status = STATUS_NO_MEMORY;
|
2020-04-03 13:23:27 +00:00
|
|
|
break;
|
2020-09-02 13:07:59 +00:00
|
|
|
case IOCTL_MOUNTMGR_READ_CREDENTIAL:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2020-09-02 13:07:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
status = read_credential( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2020-09-02 13:07:59 +00:00
|
|
|
break;
|
2020-09-03 12:59:04 +00:00
|
|
|
case IOCTL_MOUNTMGR_WRITE_CREDENTIAL:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2020-09-03 12:59:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
status = write_credential( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2020-09-03 12:59:04 +00:00
|
|
|
break;
|
2020-09-03 12:59:06 +00:00
|
|
|
case IOCTL_MOUNTMGR_DELETE_CREDENTIAL:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2020-09-03 12:59:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
status = delete_credential( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2020-09-03 12:59:06 +00:00
|
|
|
break;
|
2020-09-03 12:59:08 +00:00
|
|
|
case IOCTL_MOUNTMGR_ENUMERATE_CREDENTIALS:
|
|
|
|
if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential_list))
|
|
|
|
{
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2020-09-03 12:59:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
status = enumerate_credentials( irp->AssociatedIrp.SystemBuffer,
|
|
|
|
irpsp->Parameters.DeviceIoControl.InputBufferLength,
|
|
|
|
irpsp->Parameters.DeviceIoControl.OutputBufferLength,
|
|
|
|
&irp->IoStatus );
|
2020-09-03 12:59:08 +00:00
|
|
|
break;
|
2020-04-03 13:23:27 +00:00
|
|
|
#endif
|
2008-01-04 12:07:05 +00:00
|
|
|
default:
|
|
|
|
FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
|
2021-02-05 06:00:45 +00:00
|
|
|
status = STATUS_NOT_SUPPORTED;
|
2008-01-04 12:07:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-05 06:00:45 +00:00
|
|
|
irp->IoStatus.u.Status = status;
|
2010-03-23 16:08:03 +00:00
|
|
|
IoCompleteRequest( irp, IO_NO_INCREMENT );
|
2021-02-05 06:00:45 +00:00
|
|
|
return status;
|
2008-01-04 12:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* main entry point for the mount point manager driver */
|
|
|
|
NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
|
|
|
|
{
|
2008-10-21 13:02:10 +00:00
|
|
|
static const WCHAR mounted_devicesW[] = {'S','y','s','t','e','m','\\','M','o','u','n','t','e','d','D','e','v','i','c','e','s',0};
|
2008-01-04 12:07:05 +00:00
|
|
|
static const WCHAR device_mountmgrW[] = {'\\','D','e','v','i','c','e','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
|
|
|
|
static const WCHAR link_mountmgrW[] = {'\\','?','?','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
|
2008-01-04 13:21:27 +00:00
|
|
|
static const WCHAR harddiskW[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
|
2017-04-26 03:18:35 +00:00
|
|
|
static const WCHAR driver_serialW[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
|
2017-04-26 03:18:36 +00:00
|
|
|
static const WCHAR driver_parallelW[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
|
2019-11-25 17:40:34 +00:00
|
|
|
static const WCHAR devicemapW[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
|
2008-01-04 12:07:05 +00:00
|
|
|
|
2017-10-29 20:58:52 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
static const WCHAR qualified_ports_keyW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
|
|
|
|
'M','A','C','H','I','N','E','\\','S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','i','n','e','\\','P','o','r','t','s'}; /* no null terminator */
|
|
|
|
static const WCHAR wow64_ports_keyW[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'W','o','w','6','4','3','2','N','o','d','e','\\','W','i','n','e','\\',
|
|
|
|
'P','o','r','t','s',0};
|
|
|
|
static const WCHAR symbolic_link_valueW[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
|
|
|
|
HKEY wow64_ports_key = NULL;
|
|
|
|
#endif
|
|
|
|
|
2008-01-04 12:07:05 +00:00
|
|
|
UNICODE_STRING nameW, linkW;
|
|
|
|
DEVICE_OBJECT *device;
|
2019-11-25 17:40:34 +00:00
|
|
|
HKEY devicemap_key;
|
2008-01-04 12:07:05 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "%s\n", debugstr_w(path->Buffer) );
|
|
|
|
|
|
|
|
driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = mountmgr_ioctl;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, device_mountmgrW );
|
|
|
|
RtlInitUnicodeString( &linkW, link_mountmgrW );
|
|
|
|
if (!(status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device )))
|
|
|
|
status = IoCreateSymbolicLink( &linkW, &nameW );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
FIXME( "failed to create device error %x\n", status );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-10-21 13:02:10 +00:00
|
|
|
RegCreateKeyExW( HKEY_LOCAL_MACHINE, mounted_devicesW, 0, NULL,
|
|
|
|
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &mount_key, NULL );
|
2008-03-04 06:58:32 +00:00
|
|
|
|
2019-11-25 17:40:34 +00:00
|
|
|
if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, devicemapW, 0, NULL, REG_OPTION_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS, NULL, &devicemap_key, NULL ))
|
|
|
|
RegCloseKey( devicemap_key );
|
|
|
|
|
2008-01-04 13:21:27 +00:00
|
|
|
RtlInitUnicodeString( &nameW, harddiskW );
|
|
|
|
status = IoCreateDriver( &nameW, harddisk_driver_entry );
|
|
|
|
|
2011-12-20 10:04:18 +00:00
|
|
|
initialize_dbus();
|
2008-10-21 13:02:10 +00:00
|
|
|
initialize_diskarbitration();
|
|
|
|
|
2017-10-29 20:58:52 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
/* create a symlink so that the Wine port overrides key can be edited with 32-bit reg or regedit */
|
|
|
|
RegCreateKeyExW( HKEY_LOCAL_MACHINE, wow64_ports_keyW, 0, NULL, REG_OPTION_CREATE_LINK,
|
|
|
|
KEY_SET_VALUE, NULL, &wow64_ports_key, NULL );
|
|
|
|
RegSetValueExW( wow64_ports_key, symbolic_link_valueW, 0, REG_LINK,
|
|
|
|
(BYTE *)qualified_ports_keyW, sizeof(qualified_ports_keyW) );
|
|
|
|
RegCloseKey( wow64_ports_key );
|
|
|
|
#endif
|
|
|
|
|
2017-04-26 03:18:35 +00:00
|
|
|
RtlInitUnicodeString( &nameW, driver_serialW );
|
|
|
|
IoCreateDriver( &nameW, serial_driver_entry );
|
|
|
|
|
2017-04-26 03:18:36 +00:00
|
|
|
RtlInitUnicodeString( &nameW, driver_parallelW );
|
|
|
|
IoCreateDriver( &nameW, parallel_driver_entry );
|
|
|
|
|
2008-01-04 12:07:05 +00:00
|
|
|
return status;
|
|
|
|
}
|