wine  6.0.1
About: Wine is an Open Source implementation of the MS Windows API on top of X, OpenGL, and Unix. Think of Wine as a compatibility layer for running Windows programs.
  Fossies Dox: wine-6.0.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mountmgr.c
Go to the documentation of this file.
1 /*
2  * Mount manager service implementation
3  *
4  * Copyright 2008 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #ifdef __APPLE__
22 #include <CoreFoundation/CFString.h>
23 #define LoadResource mac_LoadResource
24 #define GetCurrentThread mac_GetCurrentThread
25 #include <CoreServices/CoreServices.h>
26 #undef LoadResource
27 #undef GetCurrentThread
28 #endif
29 
30 #include <stdarg.h>
31 #include <unistd.h>
32 
33 #define NONAMELESSUNION
34 
35 #include "mountmgr.h"
36 #include "winreg.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40 
42 
43 #define MIN_ID_LEN 4
44 
46 {
47  struct list entry; /* entry in mount points list */
48  DEVICE_OBJECT *device; /* disk device */
49  UNICODE_STRING name; /* device name */
50  UNICODE_STRING link; /* DOS device symlink */
51  void *id; /* device unique id */
52  unsigned int id_len;
53 };
54 
56 static HKEY mount_key;
57 
58 void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len )
59 {
60  RtlFreeHeap( GetProcessHeap(), 0, mount->id );
61  mount->id_len = max( MIN_ID_LEN, id_len );
62  if ((mount->id = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, mount->id_len )))
63  {
64  memcpy( mount->id, id, id_len );
65  RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len );
66  }
67  else mount->id_len = 0;
68 }
69 
71  const WCHAR *link )
72 {
73  struct mount_point *mount;
74  WCHAR *str;
75  UINT len = (strlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR);
76 
77  if (!(mount = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount) + len ))) return NULL;
78 
79  str = (WCHAR *)(mount + 1);
80  strcpyW( str, link );
81  RtlInitUnicodeString( &mount->link, str );
82  str += strlenW(str) + 1;
83  memcpy( str, device_name->Buffer, device_name->Length );
84  str[device_name->Length / sizeof(WCHAR)] = 0;
85  mount->name.Buffer = str;
86  mount->name.Length = device_name->Length;
87  mount->name.MaximumLength = device_name->Length + sizeof(WCHAR);
88  mount->device = device;
89  mount->id = NULL;
91 
92  IoCreateSymbolicLink( &mount->link, device_name );
93 
94  TRACE( "created %s id %s for %s\n", debugstr_w(mount->link.Buffer),
95  debugstr_a(mount->id), debugstr_w(mount->name.Buffer) );
96  return mount;
97 }
98 
99 /* create the DosDevices mount point symlink for a new device */
101 {
102  static const WCHAR driveW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','%','c',':',0};
103  WCHAR link[sizeof(driveW)];
104 
105  sprintfW( link, driveW, 'A' + drive );
106  return add_mount_point( device, device_name, link );
107 }
108 
109 /* create the Volume mount point symlink for a new device */
111  const GUID *guid )
112 {
113  static const WCHAR volumeW[] = {'\\','?','?','\\','V','o','l','u','m','e','{',
114  '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
115  '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
116  '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
117  WCHAR link[sizeof(volumeW)];
118 
119  sprintfW( link, volumeW, guid->Data1, guid->Data2, guid->Data3,
120  guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
121  guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
122  return add_mount_point( device, device_name, link );
123 }
124 
125 /* delete the mount point symlinks when a device goes away */
126 void delete_mount_point( struct mount_point *mount )
127 {
128  TRACE( "deleting %s\n", debugstr_w(mount->link.Buffer) );
129  list_remove( &mount->entry );
131  IoDeleteSymbolicLink( &mount->link );
132  RtlFreeHeap( GetProcessHeap(), 0, mount->id );
133  RtlFreeHeap( GetProcessHeap(), 0, mount );
134 }
135 
136 /* check if a given mount point matches the requested specs */
137 static BOOL matching_mount_point( const struct mount_point *mount, const MOUNTMGR_MOUNT_POINT *spec )
138 {
139  if (spec->SymbolicLinkNameOffset)
140  {
141  const WCHAR *name = (const WCHAR *)((const char *)spec + spec->SymbolicLinkNameOffset);
142  if (spec->SymbolicLinkNameLength != mount->link.Length) return FALSE;
143  if (strncmpiW( name, mount->link.Buffer, mount->link.Length/sizeof(WCHAR)))
144  return FALSE;
145  }
146  if (spec->DeviceNameOffset)
147  {
148  const WCHAR *name = (const WCHAR *)((const char *)spec + spec->DeviceNameOffset);
149  if (spec->DeviceNameLength != mount->name.Length) return FALSE;
150  if (strncmpiW( name, mount->name.Buffer, mount->name.Length/sizeof(WCHAR)))
151  return FALSE;
152  }
153  if (spec->UniqueIdOffset)
154  {
155  const void *id = ((const char *)spec + spec->UniqueIdOffset);
156  if (spec->UniqueIdLength != mount->id_len) return FALSE;
157  if (memcmp( id, mount->id, mount->id_len )) return FALSE;
158  }
159  return TRUE;
160 }
161 
162 /* implementation of IOCTL_MOUNTMGR_QUERY_POINTS */
163 static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
164  SIZE_T outsize, IO_STATUS_BLOCK *iosb )
165 {
166  UINT count, pos, size;
167  MOUNTMGR_MOUNT_POINT *input = buff;
169  struct mount_point *mount;
170 
171  /* sanity checks */
172  if (input->SymbolicLinkNameOffset + input->SymbolicLinkNameLength > insize ||
173  input->UniqueIdOffset + input->UniqueIdLength > insize ||
174  input->DeviceNameOffset + input->DeviceNameLength > insize ||
176  input->UniqueIdOffset + input->UniqueIdLength < input->UniqueIdOffset ||
177  input->DeviceNameOffset + input->DeviceNameLength < input->DeviceNameOffset)
179 
180  count = size = 0;
182  {
183  if (!matching_mount_point( mount, input )) continue;
184  size += mount->name.Length;
185  size += mount->link.Length;
186  size += mount->id_len;
187  size = (size + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
188  count++;
189  }
190  pos = FIELD_OFFSET( MOUNTMGR_MOUNT_POINTS, MountPoints[count] );
191  size += pos;
192 
193  if (size > outsize)
194  {
195  info = buff;
196  if (size >= sizeof(info->Size)) info->Size = size;
197  iosb->Information = sizeof(info->Size);
198  return STATUS_MORE_ENTRIES;
199  }
200 
201  input = HeapAlloc( GetProcessHeap(), 0, insize );
202  if (!input)
203  return STATUS_NO_MEMORY;
204  memcpy( input, buff, insize );
205  info = buff;
206 
207  info->NumberOfMountPoints = count;
208  count = 0;
210  {
211  if (!matching_mount_point( mount, input )) continue;
212 
213  info->MountPoints[count].DeviceNameOffset = pos;
214  info->MountPoints[count].DeviceNameLength = mount->name.Length;
215  memcpy( (char *)buff + pos, mount->name.Buffer, mount->name.Length );
216  pos += mount->name.Length;
217 
218  info->MountPoints[count].SymbolicLinkNameOffset = pos;
219  info->MountPoints[count].SymbolicLinkNameLength = mount->link.Length;
220  memcpy( (char *)buff + pos, mount->link.Buffer, mount->link.Length );
221  pos += mount->link.Length;
222 
223  info->MountPoints[count].UniqueIdOffset = pos;
224  info->MountPoints[count].UniqueIdLength = mount->id_len;
225  memcpy( (char *)buff + pos, mount->id, mount->id_len );
226  pos += mount->id_len;
227  pos = (pos + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
228  count++;
229  }
230  info->Size = pos;
231  iosb->Information = pos;
232  HeapFree( GetProcessHeap(), 0, input );
233  return STATUS_SUCCESS;
234 }
235 
236 /* implementation of IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE */
237 static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
238 {
239  const struct mountmgr_unix_drive *input = in_buff;
240  const char *mount_point = NULL, *device = NULL;
241  unsigned int i;
242  WCHAR letter = tolowerW( input->letter );
243 
244  if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
245  if (input->type > DRIVE_RAMDISK) return STATUS_INVALID_PARAMETER;
246  if (input->mount_point_offset > insize || input->device_offset > insize)
248 
249  /* make sure string are null-terminated */
250  if (input->mount_point_offset)
251  {
252  mount_point = (const char *)in_buff + input->mount_point_offset;
253  for (i = input->mount_point_offset; i < insize; i++)
254  if (!*((const char *)in_buff + i)) break;
255  if (i >= insize) return STATUS_INVALID_PARAMETER;
256  }
257  if (input->device_offset)
258  {
259  device = (const char *)in_buff + input->device_offset;
260  for (i = input->device_offset; i < insize; i++)
261  if (!*((const char *)in_buff + i)) break;
262  if (i >= insize) return STATUS_INVALID_PARAMETER;
263  }
264 
265  if (input->type != DRIVE_NO_ROOT_DIR)
266  {
268 
269  TRACE( "defining %c: dev %s mount %s type %u\n",
270  letter, debugstr_a(device), debugstr_a(mount_point), input->type );
271  switch (input->type)
272  {
273  case DRIVE_REMOVABLE: type = (letter >= 'c') ? DEVICE_HARDDISK : DEVICE_FLOPPY; break;
274  case DRIVE_REMOTE: type = DEVICE_NETWORK; break;
275  case DRIVE_CDROM: type = DEVICE_CDROM; break;
276  case DRIVE_RAMDISK: type = DEVICE_RAMDISK; break;
277  case DRIVE_FIXED: type = DEVICE_HARDDISK_VOL; break;
278  }
279  return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL, NULL );
280  }
281  else
282  {
283  TRACE( "removing %c:\n", letter );
284  return remove_dos_device( letter - 'a', NULL );
285  }
286 }
287 
288 /* implementation of IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE */
289 static NTSTATUS query_unix_drive( void *buff, SIZE_T insize,
290  SIZE_T outsize, IO_STATUS_BLOCK *iosb )
291 {
292  const struct mountmgr_unix_drive *input = buff;
293  struct mountmgr_unix_drive *output = NULL;
294  char *device, *mount_point;
295  int letter = tolowerW( input->letter );
298  enum mountmgr_fs_type fs_type;
300  char *ptr;
301  WCHAR *label;
302 
303  if (!letter)
304  {
305  if ((status = query_unix_device( input->unix_dev, &device_type, &fs_type,
306  &serial, &device, &mount_point, &label )))
307  return status;
308  }
309  else
310  {
311  if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
312 
313  if ((status = query_dos_device( letter - 'a', &device_type, &fs_type, &serial, &device,
314  &mount_point, &label )))
315  return status;
316  }
317 
318  switch (device_type)
319  {
320  case DEVICE_UNKNOWN: type = DRIVE_UNKNOWN; break;
321  case DEVICE_HARDDISK: type = DRIVE_REMOVABLE; break;
322  case DEVICE_HARDDISK_VOL: type = DRIVE_FIXED; break;
323  case DEVICE_FLOPPY: type = DRIVE_REMOVABLE; break;
324  case DEVICE_CDROM: type = DRIVE_CDROM; break;
325  case DEVICE_DVD: type = DRIVE_CDROM; break;
326  case DEVICE_NETWORK: type = DRIVE_REMOTE; break;
327  case DEVICE_RAMDISK: type = DRIVE_RAMDISK; break;
328  }
329 
330  size = sizeof(*output);
331  if (label) size += (strlenW(label) + 1) * sizeof(WCHAR);
332  if (device) size += strlen(device) + 1;
333  if (mount_point) size += strlen(mount_point) + 1;
334 
335  input = NULL;
336  output = buff;
337  output->size = size;
338  output->letter = letter;
339  output->type = type;
340  output->fs_type = fs_type;
341  output->serial = serial;
342  output->mount_point_offset = 0;
343  output->device_offset = 0;
344  output->label_offset = 0;
345 
346  ptr = (char *)(output + 1);
347 
348  if (label && ptr + (strlenW(label) + 1) * sizeof(WCHAR) - (char *)output <= outsize)
349  {
350  output->label_offset = ptr - (char *)output;
351  strcpyW( (WCHAR *)ptr, label );
352  ptr += (strlenW(label) + 1) * sizeof(WCHAR);
353  }
354  if (mount_point && ptr + strlen(mount_point) + 1 - (char *)output <= outsize)
355  {
356  output->mount_point_offset = ptr - (char *)output;
357  strcpy( ptr, mount_point );
358  ptr += strlen(ptr) + 1;
359  }
360  if (device && ptr + strlen(device) + 1 - (char *)output <= outsize)
361  {
362  output->device_offset = ptr - (char *)output;
363  strcpy( ptr, device );
364  ptr += strlen(ptr) + 1;
365  }
366 
367  TRACE( "returning %c: dev %s mount %s type %u\n",
368  letter, debugstr_a(device), debugstr_a(mount_point), type );
369 
370  iosb->Information = ptr - (char *)output;
371  if (size > outsize) status = STATUS_BUFFER_OVERFLOW;
372 
375  RtlFreeHeap( GetProcessHeap(), 0, label );
376  return status;
377 }
378 
379 /* implementation of IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS */
380 static NTSTATUS query_dhcp_request_params( void *buff, SIZE_T insize,
381  SIZE_T outsize, IO_STATUS_BLOCK *iosb )
382 {
383  struct mountmgr_dhcp_request_params *query = buff;
384  ULONG i, offset;
385 
386  /* sanity checks */
387  if (FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]) > insize ||
388  !memchrW( query->adapter, 0, ARRAY_SIZE(query->adapter) )) return STATUS_INVALID_PARAMETER;
389  for (i = 0; i < query->count; i++)
390  if (query->params[i].offset + query->params[i].size > insize) return STATUS_INVALID_PARAMETER;
391 
392  offset = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[query->count]);
393  for (i = 0; i < query->count; i++)
394  {
395  offset += get_dhcp_request_param( query->adapter, &query->params[i], buff, offset, outsize - offset );
396  if (offset > outsize)
397  {
398  if (offset >= sizeof(query->size)) query->size = offset;
399  iosb->Information = sizeof(query->size);
400  return STATUS_MORE_ENTRIES;
401  }
402  }
403 
404  iosb->Information = offset;
405  return STATUS_SUCCESS;
406 }
407 
408 /* implementation of Wine extension to use host APIs to find symbol file by GUID */
409 #ifdef __APPLE__
410 static void WINAPI query_symbol_file( TP_CALLBACK_INSTANCE *instance, void *context )
411 {
412  IRP *irp = context;
413  MOUNTMGR_TARGET_NAME *result;
414  CFStringRef query_cfstring;
415  WCHAR *filename, *unix_buf = NULL;
416  ANSI_STRING unix_path;
418  MDQueryRef mdquery;
419  const GUID *id;
420  size_t size;
422 
423  static const WCHAR formatW[] = { 'c','o','m','_','a','p','p','l','e','_','x','c','o','d','e',
424  '_','d','s','y','m','_','u','u','i','d','s',' ','=','=',' ',
425  '"','%','0','8','X','-','%','0','4','X','-',
426  '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
427  '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
428  '%','0','2','X','%','0','2','X','"',0 };
429  WCHAR query_string[ARRAY_SIZE(formatW)];
430 
431  id = irp->AssociatedIrp.SystemBuffer;
432  sprintfW( query_string, formatW, id->Data1, id->Data2, id->Data3,
433  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
434  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
435  if (!(query_cfstring = CFStringCreateWithCharacters(NULL, query_string, lstrlenW(query_string)))) goto done;
436 
437  mdquery = MDQueryCreate(NULL, query_cfstring, NULL, NULL);
438  CFRelease(query_cfstring);
439  if (!mdquery) goto done;
440 
441  MDQuerySetMaxCount(mdquery, 1);
442  TRACE("Executing %s\n", debugstr_w(query_string));
443  if (MDQueryExecute(mdquery, kMDQuerySynchronous))
444  {
445  if (MDQueryGetResultCount(mdquery) >= 1)
446  {
447  MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(mdquery, 0);
448  CFStringRef item_path = MDItemCopyAttribute(item, kMDItemPath);
449 
450  if (item_path)
451  {
452  CFIndex item_path_len = CFStringGetLength(item_path);
453  if ((unix_buf = HeapAlloc(GetProcessHeap(), 0, (item_path_len + 1) * sizeof(WCHAR))))
454  {
455  CFStringGetCharacters(item_path, CFRangeMake(0, item_path_len), unix_buf);
456  unix_buf[item_path_len] = 0;
457  TRACE("found %s\n", debugstr_w(unix_buf));
458  }
459  CFRelease(item_path);
460  }
461  }
463  }
464  CFRelease(mdquery);
465  if (!unix_buf) goto done;
466 
467  RtlInitUnicodeString( &path, unix_buf );
468  status = RtlUnicodeStringToAnsiString( &unix_path, &path, TRUE );
469  HeapFree( GetProcessHeap(), 0, unix_buf );
470  if (status) goto done;
471 
472  filename = wine_get_dos_file_name( unix_path.Buffer );
473  RtlFreeAnsiString( &unix_path );
474  if (!filename)
475  {
477  goto done;
478  }
479  result = irp->AssociatedIrp.SystemBuffer;
480  result->DeviceNameLength = lstrlenW(filename) * sizeof(WCHAR);
482  if (size <= IoGetCurrentIrpStackLocation(irp)->Parameters.DeviceIoControl.OutputBufferLength)
483  {
484  memcpy( result->DeviceName, filename, lstrlenW(filename) * sizeof(WCHAR) );
485  irp->IoStatus.Information = size;
487  }
488  else
489  {
490  irp->IoStatus.Information = sizeof(*result);
492  }
494 
495 done:
496  irp->IoStatus.u.Status = status;
498 }
499 
500 static inline BOOL check_credential_string( const void *buf, SIZE_T buflen, ULONG size, ULONG offset )
501 {
502  const WCHAR *ptr = buf;
503  if (!size || size % sizeof(WCHAR) || offset + size > buflen || ptr[(offset + size) / sizeof(WCHAR) - 1]) return FALSE;
504  return TRUE;
505 }
506 
507 static SecKeychainItemRef find_credential( const WCHAR *name )
508 {
509  int status;
510  SecKeychainSearchRef search;
511  SecKeychainItemRef item;
512 
513  status = SecKeychainSearchCreateFromAttributes( NULL, kSecGenericPasswordItemClass, NULL, &search );
514  if (status != noErr) return NULL;
515 
516  while (SecKeychainSearchCopyNext( search, &item ) == noErr)
517  {
518  SecKeychainAttributeInfo info;
519  SecKeychainAttributeList *attr_list;
520  UInt32 info_tags[] = { kSecServiceItemAttr };
521  WCHAR *itemname;
522  int len;
523 
524  info.count = ARRAY_SIZE(info_tags);
525  info.tag = info_tags;
526  info.format = NULL;
527  status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, NULL, NULL );
528  if (status != noErr)
529  {
530  WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
531  continue;
532  }
533  if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)
534  {
535  CFRelease( item );
536  continue;
537  }
538  len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[0].data, attr_list->attr[0].length, NULL, 0 );
539  if (!(itemname = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
540  {
541  CFRelease( item );
542  CFRelease( search );
543  return NULL;
544  }
545  MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[0].data, attr_list->attr[0].length, itemname, len );
546  itemname[len] = 0;
547  if (strcmpiW( itemname, name ))
548  {
549  CFRelease( item );
550  RtlFreeHeap( GetProcessHeap(), 0, itemname );
551  continue;
552  }
553  RtlFreeHeap( GetProcessHeap(), 0, itemname );
554  SecKeychainItemFreeAttributesAndData( attr_list, NULL );
555  CFRelease( search );
556  return item;
557  }
558 
559  CFRelease( search );
560  return NULL;
561 }
562 
563 static NTSTATUS fill_credential( SecKeychainItemRef item, BOOL require_password, void *buf, SIZE_T data_offset,
564  SIZE_T buflen, SIZE_T *retlen )
565 {
566  struct mountmgr_credential *cred = buf;
567  int status, len;
568  SIZE_T size;
569  UInt32 i, cred_blob_len = 0;
570  void *cred_blob;
571  WCHAR *ptr;
572  BOOL user_name_present = FALSE;
573  SecKeychainAttributeInfo info;
574  SecKeychainAttributeList *attr_list = NULL;
575  UInt32 info_tags[] = { kSecServiceItemAttr, kSecAccountItemAttr, kSecCommentItemAttr, kSecCreationDateItemAttr };
576 
577  info.count = ARRAY_SIZE(info_tags);
578  info.tag = info_tags;
579  info.format = NULL;
580  status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, &cred_blob_len, &cred_blob );
581  if (status == errSecAuthFailed && !require_password)
582  {
583  cred_blob_len = 0;
584  cred_blob = NULL;
585  status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, &cred_blob_len, NULL );
586  }
587  if (status != noErr)
588  {
589  WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
590  return STATUS_NOT_FOUND;
591  }
592  for (i = 0; i < attr_list->count; i++)
593  {
594  if (attr_list->attr[i].tag == kSecAccountItemAttr && attr_list->attr[i].data)
595  {
596  user_name_present = TRUE;
597  break;
598  }
599  }
600  if (!user_name_present)
601  {
602  WARN( "no kSecAccountItemAttr for item\n" );
603  SecKeychainItemFreeAttributesAndData( attr_list, cred_blob );
604  return STATUS_NOT_FOUND;
605  }
606 
607  *retlen = sizeof(*cred);
608  for (i = 0; i < attr_list->count; i++)
609  {
610  switch (attr_list->attr[i].tag)
611  {
612  case kSecServiceItemAttr:
613  TRACE( "kSecServiceItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
614  if (cred) cred->targetname_offset = cred->targetname_size = 0;
615  if (!attr_list->attr[i].data) continue;
616 
617  len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
618  size = (len + 1) * sizeof(WCHAR);
619  if (cred && *retlen + size <= buflen)
620  {
621  cred->targetname_offset = data_offset;
622  cred->targetname_size = size;
623  ptr = (WCHAR *)((char *)cred + cred->targetname_offset);
624  MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
625  ptr[len] = 0;
626  data_offset += size;
627  }
628  *retlen += size;
629  break;
630  case kSecAccountItemAttr:
631  {
632  TRACE( "kSecAccountItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
633  if (cred) cred->username_offset = cred->username_size = 0;
634  if (!attr_list->attr[i].data) continue;
635 
636  len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
637  size = (len + 1) * sizeof(WCHAR);
638  if (cred && *retlen + size <= buflen)
639  {
640  cred->username_offset = data_offset;
641  cred->username_size = size;
642  ptr = (WCHAR *)((char *)cred + cred->username_offset);
643  MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
644  ptr[len] = 0;
645  data_offset += size;
646  }
647  *retlen += size;
648  break;
649  }
650  case kSecCommentItemAttr:
651  TRACE( "kSecCommentItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
652  if (cred) cred->comment_offset = cred->comment_size = 0;
653  if (!attr_list->attr[i].data) continue;
654 
655  len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, NULL, 0 );
656  size = (len + 1) * sizeof(WCHAR);
657  if (cred && *retlen + size <= buflen)
658  {
659  cred->comment_offset = data_offset;
660  cred->comment_size = size;
661  ptr = (WCHAR *)((char *)cred + cred->comment_offset);
662  len = MultiByteToWideChar( CP_UTF8, 0, attr_list->attr[i].data, attr_list->attr[i].length, ptr, len );
663  ptr[len] = 0;
664  data_offset += size;
665  }
666  *retlen += size;
667  break;
668  case kSecCreationDateItemAttr:
669  {
670  LARGE_INTEGER wintime;
671  struct tm tm;
672  time_t time;
673 
674  TRACE( "kSecCreationDateItemAttr: %.*s\n", (int)attr_list->attr[i].length, (char *)attr_list->attr[i].data );
675  if (cred) cred->last_written.dwLowDateTime = cred->last_written.dwHighDateTime = 0;
676  if (!attr_list->attr[i].data) continue;
677 
678  if (cred)
679  {
680  memset( &tm, 0, sizeof(tm) );
681  strptime( attr_list->attr[i].data, "%Y%m%d%H%M%SZ", &tm );
682  time = mktime( &tm );
683  RtlSecondsSince1970ToTime( time, &wintime );
684  cred->last_written.dwLowDateTime = wintime.u.LowPart;
685  cred->last_written.dwHighDateTime = wintime.u.HighPart;
686  }
687  break;
688  }
689  default:
690  FIXME( "unhandled attribute %u\n", (unsigned)attr_list->attr[i].tag );
691  break;
692  }
693  }
694 
695  if (cred)
696  {
697  if (*retlen + cred_blob_len <= buflen)
698  {
699  len = MultiByteToWideChar( CP_UTF8, 0, cred_blob, cred_blob_len, NULL, 0 );
700  cred->blob_offset = data_offset;
701  cred->blob_size = len * sizeof(WCHAR);
702  ptr = (WCHAR *)((char *)cred + cred->blob_offset);
703  MultiByteToWideChar( CP_UTF8, 0, cred_blob, cred_blob_len, ptr, len );
704  }
705  else cred->blob_offset = cred->blob_size = 0;
706  }
707  *retlen += cred_blob_len;
708 
709  if (attr_list) SecKeychainItemFreeAttributesAndData( attr_list, cred_blob );
710  return STATUS_SUCCESS;
711 }
712 
713 static NTSTATUS read_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
714 {
715  struct mountmgr_credential *cred = buff;
716  const WCHAR *targetname;
717  SecKeychainItemRef item;
718  SIZE_T size;
720 
721  if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ))
723  targetname = (const WCHAR *)((const char *)cred + cred->targetname_offset);
724 
725  if (!(item = find_credential( targetname ))) return STATUS_NOT_FOUND;
726 
727  status = fill_credential( item, TRUE, cred, sizeof(*cred), outsize, &size );
728  CFRelease( item );
729  if (status != STATUS_SUCCESS) return status;
730 
731  iosb->Information = size;
732  return (size > outsize) ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
733 }
734 
735 static NTSTATUS write_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
736 {
737  const struct mountmgr_credential *cred = buff;
738  int status, len, len_password = 0;
739  const WCHAR *ptr;
740  SecKeychainItemRef keychain_item;
741  char *targetname, *username = NULL, *password = NULL;
742  SecKeychainAttribute attrs[1];
743  SecKeychainAttributeList attr_list;
745 
746  if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ) ||
747  !check_credential_string( buff, insize, cred->username_size, cred->username_offset ) ||
748  ((cred->blob_size && cred->blob_size % sizeof(WCHAR)) || cred->blob_offset + cred->blob_size > insize) ||
749  (cred->comment_size && !check_credential_string( buff, insize, cred->comment_size, cred->comment_offset )) ||
750  sizeof(*cred) + cred->targetname_size + cred->username_size + cred->blob_size + cred->comment_size > insize)
751  {
753  }
754 
755  ptr = (const WCHAR *)((const char *)cred + cred->targetname_offset);
756  len = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
757  if (!(targetname = RtlAllocateHeap( GetProcessHeap(), 0, len ))) goto error;
758  WideCharToMultiByte( CP_UTF8, 0, ptr, -1, targetname, len, NULL, NULL );
759 
760  ptr = (const WCHAR *)((const char *)cred + cred->username_offset);
761  len = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
762  if (!(username = RtlAllocateHeap( GetProcessHeap(), 0, len ))) goto error;
763  WideCharToMultiByte( CP_UTF8, 0, ptr, -1, username, len, NULL, NULL );
764 
765  if (cred->blob_size)
766  {
767  ptr = (const WCHAR *)((const char *)cred + cred->blob_offset);
768  len_password = WideCharToMultiByte( CP_UTF8, 0, ptr, cred->blob_size / sizeof(WCHAR), NULL, 0, NULL, NULL );
769  if (!(password = RtlAllocateHeap( GetProcessHeap(), 0, len_password ))) goto error;
770  WideCharToMultiByte( CP_UTF8, 0, ptr, cred->blob_size / sizeof(WCHAR), password, len_password, NULL, NULL );
771  }
772 
773  TRACE("adding target %s, username %s using Keychain\n", targetname, username );
774  status = SecKeychainAddGenericPassword( NULL, strlen(targetname), targetname, strlen(username), username,
775  len_password, password, &keychain_item );
776  if (status != noErr) ERR( "SecKeychainAddGenericPassword returned %d\n", status );
777  if (status == errSecDuplicateItem)
778  {
779  status = SecKeychainFindGenericPassword( NULL, strlen(targetname), targetname, strlen(username), username, NULL,
780  NULL, &keychain_item );
781  if (status != noErr) ERR( "SecKeychainFindGenericPassword returned %d\n", status );
782  }
783  RtlFreeHeap( GetProcessHeap(), 0, username );
784  RtlFreeHeap( GetProcessHeap(), 0, targetname );
785  if (status != noErr)
786  {
787  RtlFreeHeap( GetProcessHeap(), 0, password );
788  return STATUS_UNSUCCESSFUL;
789  }
790  if (cred->comment_size)
791  {
792  attr_list.count = 1;
793  attr_list.attr = attrs;
794  attrs[0].tag = kSecCommentItemAttr;
795  ptr = (const WCHAR *)((const char *)cred + cred->comment_offset);
796  attrs[0].length = WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
797  if (attrs[0].length) attrs[0].length--;
798  if (!(attrs[0].data = RtlAllocateHeap( GetProcessHeap(), 0, attrs[0].length ))) goto error;
799  WideCharToMultiByte( CP_UTF8, 0, ptr, -1, attrs[0].data, attrs[0].length, NULL, NULL );
800  }
801  else
802  {
803  attr_list.count = 0;
804  attr_list.attr = NULL;
805  }
806  status = SecKeychainItemModifyAttributesAndData( keychain_item, &attr_list, cred->blob_preserve ? 0 : len_password,
807  cred->blob_preserve ? NULL : password );
808 
809  if (cred->comment_size) RtlFreeHeap( GetProcessHeap(), 0, attrs[0].data );
810  RtlFreeHeap( GetProcessHeap(), 0, password );
811  /* FIXME: set TargetAlias attribute */
812  CFRelease( keychain_item );
813  if (status != noErr) return STATUS_UNSUCCESSFUL;
814  return STATUS_SUCCESS;
815 
816 error:
817  RtlFreeHeap( GetProcessHeap(), 0, username );
818  RtlFreeHeap( GetProcessHeap(), 0, targetname );
819  RtlFreeHeap( GetProcessHeap(), 0, password );
820  return ret;
821 }
822 
823 static NTSTATUS delete_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
824 {
825  const struct mountmgr_credential *cred = buff;
826  const WCHAR *targetname;
827  SecKeychainItemRef item;
828 
829  if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset ))
831  targetname = (const WCHAR *)((const char *)cred + cred->targetname_offset);
832 
833  if (!(item = find_credential( targetname ))) return STATUS_NOT_FOUND;
834 
835  SecKeychainItemDelete( item );
836  CFRelease( item );
837  return STATUS_SUCCESS;
838 }
839 
840 static BOOL match_credential( void *data, UInt32 data_len, const WCHAR *filter )
841 {
842  int len;
843  WCHAR *targetname;
844  const WCHAR *p;
845  BOOL ret;
846 
847  if (!*filter) return TRUE;
848 
849  len = MultiByteToWideChar( CP_UTF8, 0, data, data_len, NULL, 0 );
850  if (!(targetname = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return FALSE;
851  MultiByteToWideChar( CP_UTF8, 0, data, data_len, targetname, len );
852  targetname[len] = 0;
853 
854  TRACE( "comparing filter %s to target name %s\n", debugstr_w(filter), debugstr_w(targetname) );
855 
856  p = strchrW( filter, '*' );
858  (p && !p[1]) ? p - filter : -1, targetname, (p && !p[1]) ? p - filter : -1 ) == CSTR_EQUAL;
859  RtlFreeHeap( GetProcessHeap(), 0, targetname );
860  return ret;
861 }
862 
863 static NTSTATUS search_credentials( const WCHAR *filter, struct mountmgr_credential_list *list, SIZE_T *ret_count, SIZE_T *ret_size )
864 {
865  SecKeychainSearchRef search;
866  SecKeychainItemRef item;
867  int status;
868  ULONG i = 0;
869  SIZE_T data_offset, data_size = 0, size;
871 
872  status = SecKeychainSearchCreateFromAttributes( NULL, kSecGenericPasswordItemClass, NULL, &search );
873  if (status != noErr)
874  {
875  ERR( "SecKeychainSearchCreateFromAttributes returned status %d\n", status );
876  return STATUS_INTERNAL_ERROR;
877  }
878 
879  while (SecKeychainSearchCopyNext( search, &item ) == noErr)
880  {
881  SecKeychainAttributeInfo info;
882  SecKeychainAttributeList *attr_list;
883  UInt32 info_tags[] = { kSecServiceItemAttr };
884  BOOL match;
885 
886  info.count = ARRAY_SIZE(info_tags);
887  info.tag = info_tags;
888  info.format = NULL;
889  status = SecKeychainItemCopyAttributesAndData( item, &info, NULL, &attr_list, NULL, NULL );
890  if (status != noErr)
891  {
892  WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status );
893  CFRelease( item );
894  continue;
895  }
896  if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)
897  {
898  SecKeychainItemFreeAttributesAndData( attr_list, NULL );
899  CFRelease( item );
900  continue;
901  }
902  TRACE( "service item: %.*s\n", (int)attr_list->attr[0].length, (char *)attr_list->attr[0].data );
903 
904  match = match_credential( attr_list->attr[0].data, attr_list->attr[0].length, filter );
905  SecKeychainItemFreeAttributesAndData( attr_list, NULL );
906  if (!match)
907  {
908  CFRelease( item );
909  continue;
910  }
911 
912  if (!list) ret = fill_credential( item, FALSE, NULL, 0, 0, &size );
913  else
914  {
915  data_offset = FIELD_OFFSET( struct mountmgr_credential_list, creds[list->count] ) -
916  FIELD_OFFSET( struct mountmgr_credential_list, creds[i] ) + data_size;
917  ret = fill_credential( item, FALSE, &list->creds[i], data_offset, list->size - data_offset, &size );
918  }
919 
920  CFRelease( item );
921  if (ret == STATUS_NOT_FOUND) continue;
922  if (ret != STATUS_SUCCESS) break;
923  data_size += size - sizeof(struct mountmgr_credential);
924  i++;
925  }
926 
927  if (ret_count) *ret_count = i;
928  if (ret_size) *ret_size = FIELD_OFFSET( struct mountmgr_credential_list, creds[i] ) + data_size;
929 
930  CFRelease( search );
931  return ret;
932 }
933 
934 static NTSTATUS enumerate_credentials( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb )
935 {
936  struct mountmgr_credential_list *list = buff;
937  WCHAR *filter;
938  SIZE_T size, count;
939  Boolean saved_user_interaction_allowed;
941 
942  if (!check_credential_string( buff, insize, list->filter_size, list->filter_offset )) return STATUS_INVALID_PARAMETER;
943  if (!(filter = strdupW( (const WCHAR *)((const char *)list + list->filter_offset) ))) return STATUS_NO_MEMORY;
944 
945  SecKeychainGetUserInteractionAllowed( &saved_user_interaction_allowed );
946  SecKeychainSetUserInteractionAllowed( false );
947 
948  if ((status = search_credentials( filter, NULL, &count, &size )) == STATUS_SUCCESS)
949  {
950 
951  if (size > outsize)
952  {
953  if (size >= sizeof(list->size)) list->size = size;
954  iosb->Information = sizeof(list->size);
956  }
957  else
958  {
959  list->size = size;
960  list->count = count;
961  iosb->Information = size;
962  status = search_credentials( filter, list, NULL, NULL );
963  }
964  }
965 
966  SecKeychainSetUserInteractionAllowed( saved_user_interaction_allowed );
968  return status;
969 }
970 #endif /* __APPLE__ */
971 
972 /* handler for ioctls on the mount manager device */
974 {
976 
977  TRACE( "ioctl %x insize %u outsize %u\n",
978  irpsp->Parameters.DeviceIoControl.IoControlCode,
979  irpsp->Parameters.DeviceIoControl.InputBufferLength,
980  irpsp->Parameters.DeviceIoControl.OutputBufferLength );
981 
982  switch(irpsp->Parameters.DeviceIoControl.IoControlCode)
983  {
985  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(MOUNTMGR_MOUNT_POINT))
986  {
988  break;
989  }
991  irpsp->Parameters.DeviceIoControl.InputBufferLength,
992  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
993  &irp->IoStatus );
994  break;
995  case IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE:
996  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
997  {
999  break;
1000  }
1001  irp->IoStatus.Information = 0;
1003  irpsp->Parameters.DeviceIoControl.InputBufferLength );
1004  break;
1005  case IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE:
1006  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_unix_drive))
1007  {
1009  break;
1010  }
1012  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1013  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1014  &irp->IoStatus );
1015  break;
1016  case IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS:
1017  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_dhcp_request_params))
1018  {
1020  break;
1021  }
1023  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1024  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1025  &irp->IoStatus );
1026  break;
1027 #ifdef __APPLE__
1028  case IOCTL_MOUNTMGR_QUERY_SYMBOL_FILE:
1029  if (irpsp->Parameters.DeviceIoControl.InputBufferLength != sizeof(GUID)
1030  || irpsp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUNTMGR_TARGET_NAME))
1031  {
1033  break;
1034  }
1035  if (TrySubmitThreadpoolCallback( query_symbol_file, irp, NULL )) return STATUS_PENDING;
1036  irp->IoStatus.u.Status = STATUS_NO_MEMORY;
1037  break;
1038  case IOCTL_MOUNTMGR_READ_CREDENTIAL:
1039  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
1040  {
1042  break;
1043  }
1044  irp->IoStatus.u.Status = read_credential( irp->AssociatedIrp.SystemBuffer,
1045  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1046  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1047  &irp->IoStatus );
1048  break;
1049  case IOCTL_MOUNTMGR_WRITE_CREDENTIAL:
1050  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
1051  {
1053  break;
1054  }
1055  irp->IoStatus.u.Status = write_credential( irp->AssociatedIrp.SystemBuffer,
1056  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1057  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1058  &irp->IoStatus );
1059  break;
1060  case IOCTL_MOUNTMGR_DELETE_CREDENTIAL:
1061  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential))
1062  {
1064  break;
1065  }
1066  irp->IoStatus.u.Status = delete_credential( irp->AssociatedIrp.SystemBuffer,
1067  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1068  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1069  &irp->IoStatus );
1070  break;
1071  case IOCTL_MOUNTMGR_ENUMERATE_CREDENTIALS:
1072  if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential_list))
1073  {
1075  break;
1076  }
1077  irp->IoStatus.u.Status = enumerate_credentials( irp->AssociatedIrp.SystemBuffer,
1078  irpsp->Parameters.DeviceIoControl.InputBufferLength,
1079  irpsp->Parameters.DeviceIoControl.OutputBufferLength,
1080  &irp->IoStatus );
1081  break;
1082 #endif
1083  default:
1084  FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
1086  break;
1087  }
1089  return STATUS_SUCCESS;
1090 }
1091 
1092 /* main entry point for the mount point manager driver */
1094 {
1095  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};
1096  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};
1097  static const WCHAR link_mountmgrW[] = {'\\','?','?','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
1098  static const WCHAR harddiskW[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
1099  static const WCHAR driver_serialW[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
1100  static const WCHAR driver_parallelW[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
1101  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};
1102 
1103 #ifdef _WIN64
1104  static const WCHAR qualified_ports_keyW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
1105  'M','A','C','H','I','N','E','\\','S','o','f','t','w','a','r','e','\\',
1106  'W','i','n','e','\\','P','o','r','t','s'}; /* no null terminator */
1107  static const WCHAR wow64_ports_keyW[] = {'S','o','f','t','w','a','r','e','\\',
1108  'W','o','w','6','4','3','2','N','o','d','e','\\','W','i','n','e','\\',
1109  'P','o','r','t','s',0};
1110  static const WCHAR symbolic_link_valueW[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
1111  HKEY wow64_ports_key = NULL;
1112 #endif
1113 
1114  UNICODE_STRING nameW, linkW;
1116  HKEY devicemap_key;
1117  NTSTATUS status;
1118 
1119  TRACE( "%s\n", debugstr_w(path->Buffer) );
1120 
1121  driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = mountmgr_ioctl;
1122 
1123  RtlInitUnicodeString( &nameW, device_mountmgrW );
1124  RtlInitUnicodeString( &linkW, link_mountmgrW );
1125  if (!(status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device )))
1126  status = IoCreateSymbolicLink( &linkW, &nameW );
1127  if (status)
1128  {
1129  FIXME( "failed to create device error %x\n", status );
1130  return status;
1131  }
1132 
1133  RegCreateKeyExW( HKEY_LOCAL_MACHINE, mounted_devicesW, 0, NULL,
1135 
1137  KEY_ALL_ACCESS, NULL, &devicemap_key, NULL ))
1138  RegCloseKey( devicemap_key );
1139 
1140  RtlInitUnicodeString( &nameW, harddiskW );
1142 
1143  initialize_dbus();
1145 
1146 #ifdef _WIN64
1147  /* create a symlink so that the Wine port overrides key can be edited with 32-bit reg or regedit */
1149  KEY_SET_VALUE, NULL, &wow64_ports_key, NULL );
1150  RegSetValueExW( wow64_ports_key, symbolic_link_valueW, 0, REG_LINK,
1151  (BYTE *)qualified_ports_keyW, sizeof(qualified_ports_keyW) );
1152  RegCloseKey( wow64_ports_key );
1153 #endif
1154 
1155  RtlInitUnicodeString( &nameW, driver_serialW );
1157 
1158  RtlInitUnicodeString( &nameW, driver_parallelW );
1160 
1161  return status;
1162 }
static WCHAR * strdupW(const WCHAR *src)
ULONG_PTR SIZE_T
Definition: basetsd.h:264
LONG NTSTATUS
Definition: bcrypt.h:40
#define WINAPI
Definition: bcrypt.h:23
enum shader_type type
DWORD UInt32
Definition: chm_lib.c:104
Definition: output.pm:7
Definition: type.pm:7
#define ERR(...)
Definition: cocoa_app.h:61
__time32_t time_t
Definition: corecrt.h:233
void initialize_dbus(void)
Definition: dbus.c:1220
device_type
void initialize_diskarbitration(void)
Definition: diskarb.c:235
ULONG get_dhcp_request_param(const WCHAR *adapter, struct mountmgr_dhcp_request_param *param, char *buf, ULONG offset, ULONG size)
Definition: diskarb.c:390
static HINSTANCE instance
Definition: main.c:40
int id
Definition: main.c:4907
LPCWSTR filter
Definition: main.c:4909
LSTATUS RegSetValueExW(HKEY hkey, LPCWSTR name, DWORD reserved, DWORD type, const BYTE *data, DWORD count)
Definition: registry.c:1044
LSTATUS RegCreateKeyExW(HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class, DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa, PHKEY retkey, LPDWORD dispos)
Definition: registry.c:373
LSTATUS RegDeleteValueW(HKEY hkey, LPCWSTR name)
Definition: registry.c:2089
LSTATUS RegCloseKey(HKEY hkey)
Definition: registry.c:964
LCID GetThreadLocale(void)
Definition: thread.c:262
BOOL TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK callback, PVOID userdata, TP_CALLBACK_ENVIRON *environment)
Definition: thread.c:1206
NTSTATUS parallel_driver_entry(DRIVER_OBJECT *driver, UNICODE_STRING *path)
Definition: device.c:2137
NTSTATUS query_dos_device(int letter, enum device_type *type, enum mountmgr_fs_type *fs_type, DWORD *serial, char **device, char **mount_point, WCHAR **label)
Definition: device.c:1697
NTSTATUS query_unix_device(ULONGLONG unix_dev, enum device_type *type, enum mountmgr_fs_type *fs_type, DWORD *serial, char **device, char **mount_point, WCHAR **label)
Definition: device.c:1723
NTSTATUS harddisk_driver_entry(DRIVER_OBJECT *driver, UNICODE_STRING *path)
Definition: device.c:1920
NTSTATUS serial_driver_entry(DRIVER_OBJECT *driver, UNICODE_STRING *path)
Definition: device.c:2126
NTSTATUS remove_dos_device(int letter, const char *udi)
Definition: device.c:1637
NTSTATUS add_dos_device(int letter, const char *udi, const char *device, const char *mount_point, enum device_type type, const GUID *guid, UNICODE_STRING *devname)
Definition: device.c:1548
@ DEVICE_NETWORK
Definition: mountmgr.h:51
@ DEVICE_CDROM
Definition: mountmgr.h:49
@ DEVICE_HARDDISK
Definition: mountmgr.h:46
@ DEVICE_DVD
Definition: mountmgr.h:50
@ DEVICE_FLOPPY
Definition: mountmgr.h:48
@ DEVICE_HARDDISK_VOL
Definition: mountmgr.h:47
@ DEVICE_UNKNOWN
Definition: mountmgr.h:45
@ DEVICE_RAMDISK
Definition: mountmgr.h:52
size_t strlen(const char *str)
Definition: string.c:1502
void * memcpy(void *dst, const void *src, size_t n)
Definition: string.c:2580
char * strcpy(char *dst, const char *src)
Definition: string.c:1263
void * memset(void *dst, int c, size_t n)
Definition: string.c:2588
int memcmp(const void *ptr1, const void *ptr2, size_t n)
Definition: string.c:2461
static const WCHAR symbolic_link_valueW[]
Definition: display.c:71
unsigned int UINT
Definition: dxgicommon.idl:20
long BOOL
Definition: dxgitype.idl:24
NTSTATUS status
Definition: except.c:81
const char * str
Definition: glu.c:32
#define IOCTL_MOUNTMGR_QUERY_POINTS
Definition: mountmgr.h:38
#define WINE_DEFAULT_DEBUG_CHANNEL(ch)
Definition: debug.h:499
static WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:89
static int sprintfW(WCHAR *str, const WCHAR *format,...)
Definition: unicode.h:263
static WCHAR * memchrW(const WCHAR *ptr, WCHAR ch, size_t n)
Definition: unicode.h:115
static int strcmpiW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:122
static WCHAR tolowerW(WCHAR ch)
Definition: unicode.h:39
static unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:56
static WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:63
static int strncmpiW(const WCHAR *str1, const WCHAR *str2, int n)
Definition: unicode.h:133
WCHAR * wine_get_dos_file_name(LPCSTR str)
Definition: path.c:311
fs_type
Definition: volume.c:50
INT CompareStringW(LCID lcid, DWORD flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2)
Definition: locale.c:3144
INT WideCharToMultiByte(UINT codepage, DWORD flags, LPCWSTR src, INT srclen, LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used)
Definition: locale.c:5806
INT MultiByteToWideChar(UINT codepage, DWORD flags, const char *src, INT srclen, WCHAR *dst, INT dstlen)
Definition: locale.c:5510
GUID guid
Definition: version.c:141
struct version_info info
Definition: version.c:140
const char * filename
Definition: loader.c:74
static void list_remove(struct list *elem)
Definition: list.h:98
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:188
#define LIST_INIT(list)
Definition: list.h:227
static void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:92
#define max(a, b)
Definition: minmax.h:25
#define MIN_ID_LEN
Definition: mountmgr.c:43
static NTSTATUS query_dhcp_request_params(void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb)
Definition: mountmgr.c:380
static struct mount_point * add_mount_point(DEVICE_OBJECT *device, UNICODE_STRING *device_name, const WCHAR *link)
Definition: mountmgr.c:70
NTSTATUS DriverEntry(DRIVER_OBJECT *driver, UNICODE_STRING *path)
Definition: mountmgr.c:1093
static HKEY mount_key
Definition: mountmgr.c:56
static BOOL matching_mount_point(const struct mount_point *mount, const MOUNTMGR_MOUNT_POINT *spec)
Definition: mountmgr.c:137
struct mount_point * add_dosdev_mount_point(DEVICE_OBJECT *device, UNICODE_STRING *device_name, int drive)
Definition: mountmgr.c:100
void delete_mount_point(struct mount_point *mount)
Definition: mountmgr.c:126
static struct list mount_points_list
Definition: mountmgr.c:55
static NTSTATUS query_unix_drive(void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb)
Definition: mountmgr.c:289
void set_mount_point_id(struct mount_point *mount, const void *id, unsigned int id_len)
Definition: mountmgr.c:58
static NTSTATUS mountmgr_ioctl(DEVICE_OBJECT *device, IRP *irp)
Definition: mountmgr.c:973
static NTSTATUS query_mount_points(void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb)
Definition: mountmgr.c:163
struct mount_point * add_volume_mount_point(DEVICE_OBJECT *device, UNICODE_STRING *device_name, const GUID *guid)
Definition: mountmgr.c:110
static NTSTATUS define_unix_drive(const void *in_buff, SIZE_T insize)
Definition: mountmgr.c:237
static short search(int val, const short *table, int size)
Definition: msg711.c:255
static void size_t len
ULONG offset
Definition: error.c:1729
void * RtlAllocateHeap(HANDLE heap, ULONG flags, SIZE_T size)
Definition: heap.c:1652
BOOLEAN RtlFreeHeap(HANDLE heap, ULONG flags, void *ptr)
Definition: heap.c:1737
void RtlSecondsSince1970ToTime(DWORD Seconds, LARGE_INTEGER *Time)
Definition: time.c:310
USHORT * data
Definition: env.c:81
void IoCompleteRequest(IRP *irp, UCHAR priority_boost)
Definition: ntoskrnl.c:1901
NTSTATUS IoCreateDevice(DRIVER_OBJECT *driver, ULONG ext_size, UNICODE_STRING *name, DWORD type, ULONG characteristics, BOOLEAN exclusive, DEVICE_OBJECT **ret_device)
Definition: ntoskrnl.c:1490
NTSTATUS IoCreateDriver(UNICODE_STRING *name, PDRIVER_INITIALIZE init)
Definition: ntoskrnl.c:1415
NTSTATUS IoDeleteSymbolicLink(UNICODE_STRING *name)
Definition: ntoskrnl.c:1636
NTSTATUS IoCreateSymbolicLink(UNICODE_STRING *name, UNICODE_STRING *target)
Definition: ntoskrnl.c:1590
PSecurityUserData *typedef PSECPKG_EXTENDED_INFORMATION *typedef ULONG
Definition: ntsecpkg.h:377
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:439
#define STATUS_INVALID_PARAMETER
Definition: ntstatus.h:223
#define STATUS_PENDING
Definition: ntstatus.h:48
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:176
#define STATUS_NO_MEMORY
Definition: ntstatus.h:233
#define STATUS_UNSUCCESSFUL
Definition: ntstatus.h:211
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:397
#define STATUS_NO_SUCH_FILE
Definition: ntstatus.h:225
#define STATUS_MORE_ENTRIES
Definition: ntstatus.h:50
#define STATUS_NOT_FOUND
Definition: ntstatus.h:675
#define STATUS_BUFFER_OVERFLOW
Definition: ntstatus.h:157
#define STATUS_SUCCESS
Definition: ntstatus.h:30
static void size_t size
Definition: oledb_private.h:32
NTSTATUS RtlUnicodeStringToAnsiString(STRING *ansi, const UNICODE_STRING *uni, BOOLEAN doalloc)
Definition: rtlstr.c:635
void RtlInitUnicodeString(PUNICODE_STRING target, PCWSTR source)
Definition: rtlstr.c:171
void RtlFreeAnsiString(PSTRING str)
Definition: rtlstr.c:124
Definition: windef.h:320
union _IO_STACK_LOCATION::@1029 Parameters
struct _IO_STACK_LOCATION::@1029::@1036 DeviceIoControl
NTSTATUS Status
Definition: winternl.h:1470
ULONG_PTR Information
Definition: winternl.h:1474
Definition: wdm.h:511
PVOID SystemBuffer
Definition: wdm.h:519
union _IRP::@1001 AssociatedIrp
IO_STATUS_BLOCK IoStatus
Definition: wdm.h:522
USHORT SymbolicLinkNameLength
Definition: mountmgr.h:141
ULONG SymbolicLinkNameOffset
Definition: mountmgr.h:140
PCHAR Buffer
Definition: ntsecapi.h:147
USHORT Length
Definition: ntsecapi.h:154
USHORT MaximumLength
Definition: ntsecapi.h:155
Definition: filter.c:165
Definition: file.h:35
Definition: list.h:27
UNICODE_STRING link
Definition: mountmgr.c:50
DEVICE_OBJECT * device
Definition: mountmgr.c:48
UNICODE_STRING name
Definition: mountmgr.c:49
struct list entry
Definition: mountmgr.c:47
unsigned int id_len
Definition: mountmgr.c:52
void * id
Definition: mountmgr.c:51
Definition: name.c:36
Definition: serial.c:71
Definition: ticket.c:41
static time_t time(time_t *t)
Definition: time.h:105
static time_t mktime(struct tm *tm)
Definition: time.h:104
static int match(const char *n, const char *m)
Definition: typelib.c:115
void error(const char *s,...)
Definition: utils.c:104
#define NULL
Definition: ungif.h:66
#define TRUE
Definition: ungif.h:59
#define FALSE
Definition: ungif.h:62
struct _LARGE_INTEGER::@1824 u
BATCH_CONTEXT * context
Definition: wcmdmain.c:38
#define IO_NO_INCREMENT
Definition: wdm.h:305
#define IoGetCurrentIrpStackLocation(_Irp)
Definition: wdm.h:1586
#define IRP_MJ_DEVICE_CONTROL
Definition: wdm.h:336
#define ARRAY_SIZE(x)
Definition: utils.h:37
#define DRIVE_UNKNOWN
Definition: winbase.h:224
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:225
#define DRIVE_REMOTE
Definition: winbase.h:228
DECLSPEC_IMPORT BOOL WINAPI HeapFree(HANDLE, DWORD, LPVOID)
DECLSPEC_IMPORT HANDLE WINAPI GetProcessHeap(void)
DECLSPEC_IMPORT INT WINAPI lstrlenW(LPCWSTR)
#define DRIVE_RAMDISK
Definition: winbase.h:231
#define DRIVE_CDROM
Definition: winbase.h:230
#define DRIVE_FIXED
Definition: winbase.h:227
DECLSPEC_IMPORT LPVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T) __WINE_ALLOC_SIZE(3)
#define DRIVE_REMOVABLE
Definition: winbase.h:226
unsigned char BYTE
Definition: windef.h:250
unsigned int DWORD
Definition: windef.h:261
#define NORM_IGNORECASE
Definition: winnls.h:343
#define CSTR_EQUAL
Definition: winnls.h:562
#define CP_UTF8
Definition: winnls.h:364
#define REG_BINARY
Definition: winnt.h:5631
#define KEY_ALL_ACCESS
Definition: winnt.h:6068
#define REG_OPTION_CREATE_LINK
Definition: winnt.h:6019
unsigned short WCHAR
Definition: winnt.h:468
#define FIELD_OFFSET(type, field)
Definition: winnt.h:822
#define REG_LINK
Definition: winnt.h:5636
#define REG_OPTION_VOLATILE
Definition: winnt.h:6018
struct _TP_CALLBACK_INSTANCE TP_CALLBACK_INSTANCE
Definition: winnt.h:6716
#define HEAP_ZERO_MEMORY
Definition: winnt.h:906
#define KEY_SET_VALUE
Definition: winnt.h:6041
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:30