2 * Mount manager service implementation
4 * Copyright 2008 Alexandre Julliard
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.
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.
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
22 #include "wine/port.h"
25 #include <CoreFoundation/CFString.h>
26 #define LoadResource mac_LoadResource
27 #define GetCurrentThread mac_GetCurrentThread
28 #include <CoreServices/CoreServices.h>
30 #undef GetCurrentThread
35 #ifdef HAVE_SYS_STAT_H
39 #define NONAMELESSUNION
43 #include "wine/list.h"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr
);
53 struct list entry
; /* entry in mount points list */
54 DEVICE_OBJECT
*device
; /* disk device */
55 UNICODE_STRING name
; /* device name */
56 UNICODE_STRING link
; /* DOS device symlink */
57 void *id
; /* device unique id */
61 static struct list mount_points_list
= LIST_INIT(mount_points_list
);
62 static HKEY mount_key
;
64 void set_mount_point_id( struct mount_point
*mount
, const void *id
, unsigned int id_len
)
66 RtlFreeHeap( GetProcessHeap(), 0, mount
->id
);
67 mount
->id_len
= max( MIN_ID_LEN
, id_len
);
68 if ((mount
->id
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, mount
->id_len
)))
70 memcpy( mount
->id
, id
, id_len
);
71 RegSetValueExW( mount_key
, mount
->link
.Buffer
, 0, REG_BINARY
, mount
->id
, mount
->id_len
);
73 else mount
->id_len
= 0;
76 static struct mount_point
*add_mount_point( DEVICE_OBJECT
*device
, UNICODE_STRING
*device_name
,
79 struct mount_point
*mount
;
81 UINT len
= (strlenW(link
) + 1) * sizeof(WCHAR
) + device_name
->Length
+ sizeof(WCHAR
);
83 if (!(mount
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount
) + len
))) return NULL
;
85 str
= (WCHAR
*)(mount
+ 1);
87 RtlInitUnicodeString( &mount
->link
, str
);
88 str
+= strlenW(str
) + 1;
89 memcpy( str
, device_name
->Buffer
, device_name
->Length
);
90 str
[device_name
->Length
/ sizeof(WCHAR
)] = 0;
91 mount
->name
.Buffer
= str
;
92 mount
->name
.Length
= device_name
->Length
;
93 mount
->name
.MaximumLength
= device_name
->Length
+ sizeof(WCHAR
);
94 mount
->device
= device
;
96 list_add_tail( &mount_points_list
, &mount
->entry
);
98 IoCreateSymbolicLink( &mount
->link
, device_name
);
100 TRACE( "created %s id %s for %s\n", debugstr_w(mount
->link
.Buffer
),
101 debugstr_a(mount
->id
), debugstr_w(mount
->name
.Buffer
) );
105 /* create the DosDevices mount point symlink for a new device */
106 struct mount_point
*add_dosdev_mount_point( DEVICE_OBJECT
*device
, UNICODE_STRING
*device_name
, int drive
)
108 static const WCHAR driveW
[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','%','c',':',0};
109 WCHAR link
[sizeof(driveW
)];
111 sprintfW( link
, driveW
, 'A' + drive
);
112 return add_mount_point( device
, device_name
, link
);
115 /* create the Volume mount point symlink for a new device */
116 struct mount_point
*add_volume_mount_point( DEVICE_OBJECT
*device
, UNICODE_STRING
*device_name
,
119 static const WCHAR volumeW
[] = {'\\','?','?','\\','V','o','l','u','m','e','{',
120 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
121 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
122 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
123 WCHAR link
[sizeof(volumeW
)];
125 sprintfW( link
, volumeW
, guid
->Data1
, guid
->Data2
, guid
->Data3
,
126 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
127 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
128 return add_mount_point( device
, device_name
, link
);
131 /* delete the mount point symlinks when a device goes away */
132 void delete_mount_point( struct mount_point
*mount
)
134 TRACE( "deleting %s\n", debugstr_w(mount
->link
.Buffer
) );
135 list_remove( &mount
->entry
);
136 RegDeleteValueW( mount_key
, mount
->link
.Buffer
);
137 IoDeleteSymbolicLink( &mount
->link
);
138 RtlFreeHeap( GetProcessHeap(), 0, mount
->id
);
139 RtlFreeHeap( GetProcessHeap(), 0, mount
);
142 /* check if a given mount point matches the requested specs */
143 static BOOL
matching_mount_point( const struct mount_point
*mount
, const MOUNTMGR_MOUNT_POINT
*spec
)
145 if (spec
->SymbolicLinkNameOffset
)
147 const WCHAR
*name
= (const WCHAR
*)((const char *)spec
+ spec
->SymbolicLinkNameOffset
);
148 if (spec
->SymbolicLinkNameLength
!= mount
->link
.Length
) return FALSE
;
149 if (strncmpiW( name
, mount
->link
.Buffer
, mount
->link
.Length
/sizeof(WCHAR
)))
152 if (spec
->DeviceNameOffset
)
154 const WCHAR
*name
= (const WCHAR
*)((const char *)spec
+ spec
->DeviceNameOffset
);
155 if (spec
->DeviceNameLength
!= mount
->name
.Length
) return FALSE
;
156 if (strncmpiW( name
, mount
->name
.Buffer
, mount
->name
.Length
/sizeof(WCHAR
)))
159 if (spec
->UniqueIdOffset
)
161 const void *id
= ((const char *)spec
+ spec
->UniqueIdOffset
);
162 if (spec
->UniqueIdLength
!= mount
->id_len
) return FALSE
;
163 if (memcmp( id
, mount
->id
, mount
->id_len
)) return FALSE
;
168 /* implementation of IOCTL_MOUNTMGR_QUERY_POINTS */
169 static NTSTATUS
query_mount_points( void *buff
, SIZE_T insize
,
170 SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
172 UINT count
, pos
, size
;
173 MOUNTMGR_MOUNT_POINT
*input
= buff
;
174 MOUNTMGR_MOUNT_POINTS
*info
;
175 struct mount_point
*mount
;
177 if (insize
< sizeof(*input
) ||
178 outsize
< sizeof(*info
) ||
179 input
->SymbolicLinkNameOffset
+ input
->SymbolicLinkNameLength
> insize
||
180 input
->UniqueIdOffset
+ input
->UniqueIdLength
> insize
||
181 input
->DeviceNameOffset
+ input
->DeviceNameLength
> insize
||
182 input
->SymbolicLinkNameOffset
+ input
->SymbolicLinkNameLength
< input
->SymbolicLinkNameOffset
||
183 input
->UniqueIdOffset
+ input
->UniqueIdLength
< input
->UniqueIdOffset
||
184 input
->DeviceNameOffset
+ input
->DeviceNameLength
< input
->DeviceNameOffset
)
185 return STATUS_INVALID_PARAMETER
;
188 LIST_FOR_EACH_ENTRY( mount
, &mount_points_list
, struct mount_point
, entry
)
190 if (!matching_mount_point( mount
, input
)) continue;
191 size
+= mount
->name
.Length
;
192 size
+= mount
->link
.Length
;
193 size
+= mount
->id_len
;
194 size
= (size
+ sizeof(WCHAR
) - 1) & ~(sizeof(WCHAR
) - 1);
197 pos
= FIELD_OFFSET( MOUNTMGR_MOUNT_POINTS
, MountPoints
[count
] );
204 iosb
->Information
= sizeof(info
->Size
);
205 return STATUS_BUFFER_OVERFLOW
;
208 input
= HeapAlloc( GetProcessHeap(), 0, insize
);
210 return STATUS_NO_MEMORY
;
211 memcpy( input
, buff
, insize
);
214 info
->NumberOfMountPoints
= count
;
216 LIST_FOR_EACH_ENTRY( mount
, &mount_points_list
, struct mount_point
, entry
)
218 if (!matching_mount_point( mount
, input
)) continue;
220 info
->MountPoints
[count
].DeviceNameOffset
= pos
;
221 info
->MountPoints
[count
].DeviceNameLength
= mount
->name
.Length
;
222 memcpy( (char *)buff
+ pos
, mount
->name
.Buffer
, mount
->name
.Length
);
223 pos
+= mount
->name
.Length
;
225 info
->MountPoints
[count
].SymbolicLinkNameOffset
= pos
;
226 info
->MountPoints
[count
].SymbolicLinkNameLength
= mount
->link
.Length
;
227 memcpy( (char *)buff
+ pos
, mount
->link
.Buffer
, mount
->link
.Length
);
228 pos
+= mount
->link
.Length
;
230 info
->MountPoints
[count
].UniqueIdOffset
= pos
;
231 info
->MountPoints
[count
].UniqueIdLength
= mount
->id_len
;
232 memcpy( (char *)buff
+ pos
, mount
->id
, mount
->id_len
);
233 pos
+= mount
->id_len
;
234 pos
= (pos
+ sizeof(WCHAR
) - 1) & ~(sizeof(WCHAR
) - 1);
238 iosb
->Information
= pos
;
239 HeapFree( GetProcessHeap(), 0, input
);
240 return STATUS_SUCCESS
;
243 /* implementation of IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE */
244 static NTSTATUS
define_unix_drive( const void *in_buff
, SIZE_T insize
)
246 const struct mountmgr_unix_drive
*input
= in_buff
;
247 const char *mount_point
= NULL
, *device
= NULL
;
249 WCHAR letter
= tolowerW( input
->letter
);
251 if (letter
< 'a' || letter
> 'z') return STATUS_INVALID_PARAMETER
;
252 if (input
->type
> DRIVE_RAMDISK
) return STATUS_INVALID_PARAMETER
;
253 if (input
->mount_point_offset
> insize
|| input
->device_offset
> insize
)
254 return STATUS_INVALID_PARAMETER
;
256 /* make sure string are null-terminated */
257 if (input
->mount_point_offset
)
259 mount_point
= (const char *)in_buff
+ input
->mount_point_offset
;
260 for (i
= input
->mount_point_offset
; i
< insize
; i
++)
261 if (!*((const char *)in_buff
+ i
)) break;
262 if (i
>= insize
) return STATUS_INVALID_PARAMETER
;
264 if (input
->device_offset
)
266 device
= (const char *)in_buff
+ input
->device_offset
;
267 for (i
= input
->device_offset
; i
< insize
; i
++)
268 if (!*((const char *)in_buff
+ i
)) break;
269 if (i
>= insize
) return STATUS_INVALID_PARAMETER
;
272 if (input
->type
!= DRIVE_NO_ROOT_DIR
)
274 enum device_type type
= DEVICE_UNKNOWN
;
276 TRACE( "defining %c: dev %s mount %s type %u\n",
277 letter
, debugstr_a(device
), debugstr_a(mount_point
), input
->type
);
280 case DRIVE_REMOVABLE
: type
= (letter
>= 'c') ? DEVICE_HARDDISK
: DEVICE_FLOPPY
; break;
281 case DRIVE_REMOTE
: type
= DEVICE_NETWORK
; break;
282 case DRIVE_CDROM
: type
= DEVICE_CDROM
; break;
283 case DRIVE_RAMDISK
: type
= DEVICE_RAMDISK
; break;
284 case DRIVE_FIXED
: type
= DEVICE_HARDDISK_VOL
; break;
286 return add_dos_device( letter
- 'a', NULL
, device
, mount_point
, type
, NULL
, NULL
);
290 TRACE( "removing %c:\n", letter
);
291 return remove_dos_device( letter
- 'a', NULL
);
295 /* implementation of IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER */
296 static NTSTATUS
define_shell_folder( const void *in_buff
, SIZE_T insize
)
298 const struct mountmgr_shell_folder
*input
= in_buff
;
299 const char *link
= NULL
;
300 OBJECT_ATTRIBUTES attr
;
304 char *buffer
, *backup
= NULL
;
308 if (input
->folder_offset
>= insize
|| input
->folder_size
> insize
- input
->folder_offset
||
309 input
->symlink_offset
>= insize
)
310 return STATUS_INVALID_PARAMETER
;
312 /* make sure string is null-terminated */
313 if (input
->symlink_offset
)
315 link
= (const char *)in_buff
+ input
->symlink_offset
;
316 for (i
= input
->symlink_offset
; i
< insize
; i
++)
317 if (!*((const char *)in_buff
+ i
)) break;
318 if (i
>= insize
) return STATUS_INVALID_PARAMETER
;
319 if (!link
[0]) link
= NULL
;
322 /* ignore nonexistent link targets */
323 if (link
&& stat( link
, &st
)) return STATUS_OBJECT_NAME_NOT_FOUND
;
325 name
.Buffer
= (WCHAR
*)((char *)in_buff
+ input
->folder_offset
);
326 name
.Length
= input
->folder_size
;
327 InitializeObjectAttributes( &attr
, &name
, 0, 0, NULL
);
331 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
))) return STATUS_NO_MEMORY
;
332 status
= wine_nt_to_unix_file_name( &attr
, buffer
, &size
, FILE_OPEN
);
334 HeapFree( GetProcessHeap(), 0, buffer
);
335 if (status
!= STATUS_BUFFER_TOO_SMALL
) return status
;
338 if (!(backup
= HeapAlloc( GetProcessHeap(), 0, strlen(buffer
) + sizeof(".backup" ) )))
340 status
= STATUS_NO_MEMORY
;
343 strcpy( backup
, buffer
);
344 strcat( backup
, ".backup" );
346 if (!lstat( buffer
, &st
)) /* move old folder/link out of the way */
348 if (S_ISLNK( st
.st_mode
))
352 else if (link
&& S_ISDIR( st
.st_mode
))
354 if (rmdir( buffer
)) /* non-empty dir, try to make a backup */
356 if (!backup
|| rename( buffer
, backup
))
358 status
= STATUS_OBJECT_NAME_COLLISION
;
363 else goto done
; /* nothing to do, folder already exists */
366 if (link
) symlink( link
, buffer
);
369 if (backup
&& !lstat( backup
, &st
) && S_ISDIR( st
.st_mode
)) rename( backup
, buffer
);
370 else mkdir( buffer
, 0777 );
374 HeapFree( GetProcessHeap(), 0, buffer
);
375 HeapFree( GetProcessHeap(), 0, backup
);
379 /* implementation of IOCTL_MOUNTMGR_QUERY_SHELL_FOLDER */
380 static NTSTATUS
query_shell_folder( void *buff
, SIZE_T insize
, SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
383 OBJECT_ATTRIBUTES attr
;
391 name
.Length
= insize
;
392 InitializeObjectAttributes( &attr
, &name
, 0, 0, NULL
);
396 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
))) return STATUS_NO_MEMORY
;
397 status
= wine_nt_to_unix_file_name( &attr
, buffer
, &size
, FILE_OPEN
);
399 HeapFree( GetProcessHeap(), 0, buffer
);
400 if (status
!= STATUS_BUFFER_TOO_SMALL
) return status
;
402 ret
= readlink( buffer
, output
, outsize
- 1 );
406 iosb
->Information
= ret
+ 1;
408 else status
= STATUS_OBJECT_NAME_NOT_FOUND
;
410 HeapFree( GetProcessHeap(), 0, buffer
);
414 /* implementation of IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS */
415 static void WINAPI
query_dhcp_request_params( TP_CALLBACK_INSTANCE
*instance
, void *context
)
418 struct mountmgr_dhcp_request_params
*query
= irp
->AssociatedIrp
.SystemBuffer
;
419 IO_STACK_LOCATION
*irpsp
= IoGetCurrentIrpStackLocation( irp
);
420 SIZE_T insize
= irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
;
421 SIZE_T outsize
= irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
425 if (FIELD_OFFSET(struct mountmgr_dhcp_request_params
, params
[query
->count
]) > insize
)
427 irp
->IoStatus
.u
.Status
= STATUS_INVALID_PARAMETER
;
431 for (i
= 0; i
< query
->count
; i
++)
432 if (query
->params
[i
].offset
+ query
->params
[i
].size
> insize
)
434 irp
->IoStatus
.u
.Status
= STATUS_INVALID_PARAMETER
;
439 offset
= FIELD_OFFSET(struct mountmgr_dhcp_request_params
, params
[query
->count
]);
440 for (i
= 0; i
< query
->count
; i
++)
442 offset
+= get_dhcp_request_param( &query
->adapter
, &query
->params
[i
], (char *)query
, offset
, outsize
- offset
);
443 if (offset
> outsize
)
445 if (offset
>= sizeof(query
->size
)) query
->size
= offset
;
446 offset
= sizeof(query
->size
);
447 irp
->IoStatus
.u
.Status
= STATUS_BUFFER_OVERFLOW
;
451 irp
->IoStatus
.u
.Status
= STATUS_SUCCESS
;
454 irp
->IoStatus
.Information
= offset
;
455 IoCompleteRequest( irp
, IO_NO_INCREMENT
);
458 /* implementation of Wine extension to use host APIs to find symbol file by GUID */
460 static void WINAPI
query_symbol_file( TP_CALLBACK_INSTANCE
*instance
, void *context
)
463 MOUNTMGR_TARGET_NAME
*result
;
464 CFStringRef query_cfstring
;
465 WCHAR
*filename
, *unix_buf
= NULL
;
466 ANSI_STRING unix_path
;
471 NTSTATUS status
= STATUS_NO_MEMORY
;
473 static const WCHAR formatW
[] = { 'c','o','m','_','a','p','p','l','e','_','x','c','o','d','e',
474 '_','d','s','y','m','_','u','u','i','d','s',' ','=','=',' ',
475 '"','%','0','8','X','-','%','0','4','X','-',
476 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
477 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
478 '%','0','2','X','%','0','2','X','"',0 };
479 WCHAR query_string
[ARRAY_SIZE(formatW
)];
481 id
= irp
->AssociatedIrp
.SystemBuffer
;
482 sprintfW( query_string
, formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
483 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
484 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
485 if (!(query_cfstring
= CFStringCreateWithCharacters(NULL
, query_string
, lstrlenW(query_string
)))) goto done
;
487 mdquery
= MDQueryCreate(NULL
, query_cfstring
, NULL
, NULL
);
488 CFRelease(query_cfstring
);
489 if (!mdquery
) goto done
;
491 MDQuerySetMaxCount(mdquery
, 1);
492 TRACE("Executing %s\n", debugstr_w(query_string
));
493 if (MDQueryExecute(mdquery
, kMDQuerySynchronous
))
495 if (MDQueryGetResultCount(mdquery
) >= 1)
497 MDItemRef item
= (MDItemRef
)MDQueryGetResultAtIndex(mdquery
, 0);
498 CFStringRef item_path
= MDItemCopyAttribute(item
, kMDItemPath
);
502 CFIndex item_path_len
= CFStringGetLength(item_path
);
503 if ((unix_buf
= HeapAlloc(GetProcessHeap(), 0, (item_path_len
+ 1) * sizeof(WCHAR
))))
505 CFStringGetCharacters(item_path
, CFRangeMake(0, item_path_len
), unix_buf
);
506 unix_buf
[item_path_len
] = 0;
507 TRACE("found %s\n", debugstr_w(unix_buf
));
509 CFRelease(item_path
);
512 else status
= STATUS_NO_MORE_ENTRIES
;
515 if (!unix_buf
) goto done
;
517 RtlInitUnicodeString( &path
, unix_buf
);
518 status
= RtlUnicodeStringToAnsiString( &unix_path
, &path
, TRUE
);
519 HeapFree( GetProcessHeap(), 0, unix_buf
);
520 if (status
) goto done
;
522 filename
= wine_get_dos_file_name( unix_path
.Buffer
);
523 RtlFreeAnsiString( &unix_path
);
526 status
= STATUS_NO_SUCH_FILE
;
529 result
= irp
->AssociatedIrp
.SystemBuffer
;
530 result
->DeviceNameLength
= lstrlenW(filename
) * sizeof(WCHAR
);
531 size
= FIELD_OFFSET(MOUNTMGR_TARGET_NAME
, DeviceName
[lstrlenW(filename
)]);
532 if (size
<= IoGetCurrentIrpStackLocation(irp
)->Parameters
.DeviceIoControl
.OutputBufferLength
)
534 memcpy( result
->DeviceName
, filename
, lstrlenW(filename
) * sizeof(WCHAR
) );
535 irp
->IoStatus
.Information
= size
;
536 status
= STATUS_SUCCESS
;
540 irp
->IoStatus
.Information
= sizeof(*result
);
541 status
= STATUS_BUFFER_OVERFLOW
;
543 RtlFreeHeap( GetProcessHeap(), 0, filename
);
546 irp
->IoStatus
.u
.Status
= status
;
547 IoCompleteRequest( irp
, IO_NO_INCREMENT
);
550 static inline BOOL
check_credential_string( const void *buf
, SIZE_T buflen
, ULONG size
, ULONG offset
)
552 const WCHAR
*ptr
= buf
;
553 if (!size
|| size
% sizeof(WCHAR
) || offset
+ size
> buflen
|| ptr
[(offset
+ size
) / sizeof(WCHAR
) - 1]) return FALSE
;
557 static SecKeychainItemRef
find_credential( const WCHAR
*name
)
560 SecKeychainSearchRef search
;
561 SecKeychainItemRef item
;
563 status
= SecKeychainSearchCreateFromAttributes( NULL
, kSecGenericPasswordItemClass
, NULL
, &search
);
564 if (status
!= noErr
) return NULL
;
566 while (SecKeychainSearchCopyNext( search
, &item
) == noErr
)
568 SecKeychainAttributeInfo info
;
569 SecKeychainAttributeList
*attr_list
;
570 UInt32 info_tags
[] = { kSecServiceItemAttr
};
574 info
.count
= ARRAY_SIZE(info_tags
);
575 info
.tag
= info_tags
;
577 status
= SecKeychainItemCopyAttributesAndData( item
, &info
, NULL
, &attr_list
, NULL
, NULL
);
580 WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status
);
583 if (attr_list
->count
!= 1 || attr_list
->attr
[0].tag
!= kSecServiceItemAttr
)
588 len
= MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[0].data
, attr_list
->attr
[0].length
, NULL
, 0 );
589 if (!(itemname
= RtlAllocateHeap( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) )))
595 MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[0].data
, attr_list
->attr
[0].length
, itemname
, len
);
597 if (strcmpiW( itemname
, name
))
600 RtlFreeHeap( GetProcessHeap(), 0, itemname
);
603 RtlFreeHeap( GetProcessHeap(), 0, itemname
);
604 SecKeychainItemFreeAttributesAndData( attr_list
, NULL
);
613 static NTSTATUS
fill_credential( SecKeychainItemRef item
, BOOL require_password
, void *buf
, SIZE_T data_offset
,
614 SIZE_T buflen
, SIZE_T
*retlen
)
616 struct mountmgr_credential
*cred
= buf
;
619 UInt32 i
, cred_blob_len
= 0;
622 BOOL user_name_present
= FALSE
;
623 SecKeychainAttributeInfo info
;
624 SecKeychainAttributeList
*attr_list
= NULL
;
625 UInt32 info_tags
[] = { kSecServiceItemAttr
, kSecAccountItemAttr
, kSecCommentItemAttr
, kSecCreationDateItemAttr
};
627 info
.count
= ARRAY_SIZE(info_tags
);
628 info
.tag
= info_tags
;
630 status
= SecKeychainItemCopyAttributesAndData( item
, &info
, NULL
, &attr_list
, &cred_blob_len
, &cred_blob
);
631 if (status
== errSecAuthFailed
&& !require_password
)
635 status
= SecKeychainItemCopyAttributesAndData( item
, &info
, NULL
, &attr_list
, &cred_blob_len
, NULL
);
639 WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status
);
640 return STATUS_NOT_FOUND
;
642 for (i
= 0; i
< attr_list
->count
; i
++)
644 if (attr_list
->attr
[i
].tag
== kSecAccountItemAttr
&& attr_list
->attr
[i
].data
)
646 user_name_present
= TRUE
;
650 if (!user_name_present
)
652 WARN( "no kSecAccountItemAttr for item\n" );
653 SecKeychainItemFreeAttributesAndData( attr_list
, cred_blob
);
654 return STATUS_NOT_FOUND
;
657 *retlen
= sizeof(*cred
);
658 for (i
= 0; i
< attr_list
->count
; i
++)
660 switch (attr_list
->attr
[i
].tag
)
662 case kSecServiceItemAttr
:
663 TRACE( "kSecServiceItemAttr: %.*s\n", (int)attr_list
->attr
[i
].length
, (char *)attr_list
->attr
[i
].data
);
664 if (cred
) cred
->targetname_offset
= cred
->targetname_size
= 0;
665 if (!attr_list
->attr
[i
].data
) continue;
667 len
= MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, NULL
, 0 );
668 size
= (len
+ 1) * sizeof(WCHAR
);
669 if (cred
&& *retlen
+ size
<= buflen
)
671 cred
->targetname_offset
= data_offset
;
672 cred
->targetname_size
= size
;
673 ptr
= (WCHAR
*)((char *)cred
+ cred
->targetname_offset
);
674 MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, ptr
, len
);
680 case kSecAccountItemAttr
:
682 TRACE( "kSecAccountItemAttr: %.*s\n", (int)attr_list
->attr
[i
].length
, (char *)attr_list
->attr
[i
].data
);
683 if (cred
) cred
->username_offset
= cred
->username_size
= 0;
684 if (!attr_list
->attr
[i
].data
) continue;
686 len
= MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, NULL
, 0 );
687 size
= (len
+ 1) * sizeof(WCHAR
);
688 if (cred
&& *retlen
+ size
<= buflen
)
690 cred
->username_offset
= data_offset
;
691 cred
->username_size
= size
;
692 ptr
= (WCHAR
*)((char *)cred
+ cred
->username_offset
);
693 MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, ptr
, len
);
700 case kSecCommentItemAttr
:
701 TRACE( "kSecCommentItemAttr: %.*s\n", (int)attr_list
->attr
[i
].length
, (char *)attr_list
->attr
[i
].data
);
702 if (cred
) cred
->comment_offset
= cred
->comment_size
= 0;
703 if (!attr_list
->attr
[i
].data
) continue;
705 len
= MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, NULL
, 0 );
706 size
= (len
+ 1) * sizeof(WCHAR
);
707 if (cred
&& *retlen
+ size
<= buflen
)
709 cred
->comment_offset
= data_offset
;
710 cred
->comment_size
= size
;
711 ptr
= (WCHAR
*)((char *)cred
+ cred
->comment_offset
);
712 len
= MultiByteToWideChar( CP_UTF8
, 0, attr_list
->attr
[i
].data
, attr_list
->attr
[i
].length
, ptr
, len
);
718 case kSecCreationDateItemAttr
:
720 LARGE_INTEGER wintime
;
724 TRACE( "kSecCreationDateItemAttr: %.*s\n", (int)attr_list
->attr
[i
].length
, (char *)attr_list
->attr
[i
].data
);
725 if (cred
) cred
->last_written
.dwLowDateTime
= cred
->last_written
.dwHighDateTime
= 0;
726 if (!attr_list
->attr
[i
].data
) continue;
730 memset( &tm
, 0, sizeof(tm
) );
731 strptime( attr_list
->attr
[i
].data
, "%Y%m%d%H%M%SZ", &tm
);
732 time
= mktime( &tm
);
733 RtlSecondsSince1970ToTime( time
, &wintime
);
734 cred
->last_written
.dwLowDateTime
= wintime
.u
.LowPart
;
735 cred
->last_written
.dwHighDateTime
= wintime
.u
.HighPart
;
740 FIXME( "unhandled attribute %u\n", (unsigned)attr_list
->attr
[i
].tag
);
747 if (*retlen
+ cred_blob_len
<= buflen
)
749 len
= MultiByteToWideChar( CP_UTF8
, 0, cred_blob
, cred_blob_len
, NULL
, 0 );
750 cred
->blob_offset
= data_offset
;
751 cred
->blob_size
= len
* sizeof(WCHAR
);
752 ptr
= (WCHAR
*)((char *)cred
+ cred
->blob_offset
);
753 MultiByteToWideChar( CP_UTF8
, 0, cred_blob
, cred_blob_len
, ptr
, len
);
755 else cred
->blob_offset
= cred
->blob_size
= 0;
757 *retlen
+= cred_blob_len
;
759 if (attr_list
) SecKeychainItemFreeAttributesAndData( attr_list
, cred_blob
);
760 return STATUS_SUCCESS
;
763 static NTSTATUS
read_credential( void *buff
, SIZE_T insize
, SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
765 struct mountmgr_credential
*cred
= buff
;
766 const WCHAR
*targetname
;
767 SecKeychainItemRef item
;
771 if (!check_credential_string( buff
, insize
, cred
->targetname_size
, cred
->targetname_offset
))
772 return STATUS_INVALID_PARAMETER
;
773 targetname
= (const WCHAR
*)((const char *)cred
+ cred
->targetname_offset
);
775 if (!(item
= find_credential( targetname
))) return STATUS_NOT_FOUND
;
777 status
= fill_credential( item
, TRUE
, cred
, sizeof(*cred
), outsize
, &size
);
779 if (status
!= STATUS_SUCCESS
) return status
;
781 iosb
->Information
= size
;
782 return (size
> outsize
) ? STATUS_BUFFER_OVERFLOW
: STATUS_SUCCESS
;
785 static NTSTATUS
write_credential( void *buff
, SIZE_T insize
, SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
787 const struct mountmgr_credential
*cred
= buff
;
788 int status
, len
, len_password
= 0;
790 SecKeychainItemRef keychain_item
;
791 char *targetname
, *username
= NULL
, *password
= NULL
;
792 SecKeychainAttribute attrs
[1];
793 SecKeychainAttributeList attr_list
;
794 NTSTATUS ret
= STATUS_NO_MEMORY
;
796 if (!check_credential_string( buff
, insize
, cred
->targetname_size
, cred
->targetname_offset
) ||
797 !check_credential_string( buff
, insize
, cred
->username_size
, cred
->username_offset
) ||
798 ((cred
->blob_size
&& cred
->blob_size
% sizeof(WCHAR
)) || cred
->blob_offset
+ cred
->blob_size
> insize
) ||
799 (cred
->comment_size
&& !check_credential_string( buff
, insize
, cred
->comment_size
, cred
->comment_offset
)) ||
800 sizeof(*cred
) + cred
->targetname_size
+ cred
->username_size
+ cred
->blob_size
+ cred
->comment_size
> insize
)
802 return STATUS_INVALID_PARAMETER
;
805 ptr
= (const WCHAR
*)((const char *)cred
+ cred
->targetname_offset
);
806 len
= WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, NULL
, 0, NULL
, NULL
);
807 if (!(targetname
= RtlAllocateHeap( GetProcessHeap(), 0, len
))) goto error
;
808 WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, targetname
, len
, NULL
, NULL
);
810 ptr
= (const WCHAR
*)((const char *)cred
+ cred
->username_offset
);
811 len
= WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, NULL
, 0, NULL
, NULL
);
812 if (!(username
= RtlAllocateHeap( GetProcessHeap(), 0, len
))) goto error
;
813 WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, username
, len
, NULL
, NULL
);
817 ptr
= (const WCHAR
*)((const char *)cred
+ cred
->blob_offset
);
818 len_password
= WideCharToMultiByte( CP_UTF8
, 0, ptr
, cred
->blob_size
/ sizeof(WCHAR
), NULL
, 0, NULL
, NULL
);
819 if (!(password
= RtlAllocateHeap( GetProcessHeap(), 0, len_password
))) goto error
;
820 WideCharToMultiByte( CP_UTF8
, 0, ptr
, cred
->blob_size
/ sizeof(WCHAR
), password
, len_password
, NULL
, NULL
);
823 TRACE("adding target %s, username %s using Keychain\n", targetname
, username
);
824 status
= SecKeychainAddGenericPassword( NULL
, strlen(targetname
), targetname
, strlen(username
), username
,
825 len_password
, password
, &keychain_item
);
826 if (status
!= noErr
) ERR( "SecKeychainAddGenericPassword returned %d\n", status
);
827 if (status
== errSecDuplicateItem
)
829 status
= SecKeychainFindGenericPassword( NULL
, strlen(targetname
), targetname
, strlen(username
), username
, NULL
,
830 NULL
, &keychain_item
);
831 if (status
!= noErr
) ERR( "SecKeychainFindGenericPassword returned %d\n", status
);
833 RtlFreeHeap( GetProcessHeap(), 0, username
);
834 RtlFreeHeap( GetProcessHeap(), 0, targetname
);
837 RtlFreeHeap( GetProcessHeap(), 0, password
);
838 return STATUS_UNSUCCESSFUL
;
840 if (cred
->comment_size
)
843 attr_list
.attr
= attrs
;
844 attrs
[0].tag
= kSecCommentItemAttr
;
845 ptr
= (const WCHAR
*)((const char *)cred
+ cred
->comment_offset
);
846 attrs
[0].length
= WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, NULL
, 0, NULL
, NULL
);
847 if (attrs
[0].length
) attrs
[0].length
--;
848 if (!(attrs
[0].data
= RtlAllocateHeap( GetProcessHeap(), 0, attrs
[0].length
))) goto error
;
849 WideCharToMultiByte( CP_UTF8
, 0, ptr
, -1, attrs
[0].data
, attrs
[0].length
, NULL
, NULL
);
854 attr_list
.attr
= NULL
;
856 status
= SecKeychainItemModifyAttributesAndData( keychain_item
, &attr_list
, cred
->blob_preserve
? 0 : len_password
,
857 cred
->blob_preserve
? NULL
: password
);
859 if (cred
->comment_size
) RtlFreeHeap( GetProcessHeap(), 0, attrs
[0].data
);
860 RtlFreeHeap( GetProcessHeap(), 0, password
);
861 /* FIXME: set TargetAlias attribute */
862 CFRelease( keychain_item
);
863 if (status
!= noErr
) return STATUS_UNSUCCESSFUL
;
864 return STATUS_SUCCESS
;
867 RtlFreeHeap( GetProcessHeap(), 0, username
);
868 RtlFreeHeap( GetProcessHeap(), 0, targetname
);
869 RtlFreeHeap( GetProcessHeap(), 0, password
);
873 static NTSTATUS
delete_credential( void *buff
, SIZE_T insize
, SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
875 const struct mountmgr_credential
*cred
= buff
;
876 const WCHAR
*targetname
;
877 SecKeychainItemRef item
;
879 if (!check_credential_string( buff
, insize
, cred
->targetname_size
, cred
->targetname_offset
))
880 return STATUS_INVALID_PARAMETER
;
881 targetname
= (const WCHAR
*)((const char *)cred
+ cred
->targetname_offset
);
883 if (!(item
= find_credential( targetname
))) return STATUS_NOT_FOUND
;
885 SecKeychainItemDelete( item
);
887 return STATUS_SUCCESS
;
890 static BOOL
match_credential( void *data
, UInt32 data_len
, const WCHAR
*filter
)
897 if (!*filter
) return TRUE
;
899 len
= MultiByteToWideChar( CP_UTF8
, 0, data
, data_len
, NULL
, 0 );
900 if (!(targetname
= RtlAllocateHeap( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return FALSE
;
901 MultiByteToWideChar( CP_UTF8
, 0, data
, data_len
, targetname
, len
);
904 TRACE( "comparing filter %s to target name %s\n", debugstr_w(filter
), debugstr_w(targetname
) );
906 p
= strchrW( filter
, '*' );
907 ret
= CompareStringW( GetThreadLocale(), NORM_IGNORECASE
, filter
,
908 (p
&& !p
[1]) ? p
- filter
: -1, targetname
, (p
&& !p
[1]) ? p
- filter
: -1 ) == CSTR_EQUAL
;
909 RtlFreeHeap( GetProcessHeap(), 0, targetname
);
913 static NTSTATUS
search_credentials( const WCHAR
*filter
, struct mountmgr_credential_list
*list
, SIZE_T
*ret_count
, SIZE_T
*ret_size
)
915 SecKeychainSearchRef search
;
916 SecKeychainItemRef item
;
919 SIZE_T data_offset
, data_size
= 0, size
;
920 NTSTATUS ret
= STATUS_NOT_FOUND
;
922 status
= SecKeychainSearchCreateFromAttributes( NULL
, kSecGenericPasswordItemClass
, NULL
, &search
);
925 ERR( "SecKeychainSearchCreateFromAttributes returned status %d\n", status
);
926 return STATUS_INTERNAL_ERROR
;
929 while (SecKeychainSearchCopyNext( search
, &item
) == noErr
)
931 SecKeychainAttributeInfo info
;
932 SecKeychainAttributeList
*attr_list
;
933 UInt32 info_tags
[] = { kSecServiceItemAttr
};
936 info
.count
= ARRAY_SIZE(info_tags
);
937 info
.tag
= info_tags
;
939 status
= SecKeychainItemCopyAttributesAndData( item
, &info
, NULL
, &attr_list
, NULL
, NULL
);
942 WARN( "SecKeychainItemCopyAttributesAndData returned status %d\n", status
);
946 if (attr_list
->count
!= 1 || attr_list
->attr
[0].tag
!= kSecServiceItemAttr
)
948 SecKeychainItemFreeAttributesAndData( attr_list
, NULL
);
952 TRACE( "service item: %.*s\n", (int)attr_list
->attr
[0].length
, (char *)attr_list
->attr
[0].data
);
954 match
= match_credential( attr_list
->attr
[0].data
, attr_list
->attr
[0].length
, filter
);
955 SecKeychainItemFreeAttributesAndData( attr_list
, NULL
);
962 if (!list
) ret
= fill_credential( item
, FALSE
, NULL
, 0, 0, &size
);
965 data_offset
= FIELD_OFFSET( struct mountmgr_credential_list
, creds
[list
->count
] ) -
966 FIELD_OFFSET( struct mountmgr_credential_list
, creds
[i
] ) + data_size
;
967 ret
= fill_credential( item
, FALSE
, &list
->creds
[i
], data_offset
, list
->size
- data_offset
, &size
);
971 if (ret
== STATUS_NOT_FOUND
) continue;
972 if (ret
!= STATUS_SUCCESS
) break;
973 data_size
+= size
- sizeof(struct mountmgr_credential
);
977 if (ret_count
) *ret_count
= i
;
978 if (ret_size
) *ret_size
= FIELD_OFFSET( struct mountmgr_credential_list
, creds
[i
] ) + data_size
;
984 static NTSTATUS
enumerate_credentials( void *buff
, SIZE_T insize
, SIZE_T outsize
, IO_STATUS_BLOCK
*iosb
)
986 struct mountmgr_credential_list
*list
= buff
;
989 Boolean saved_user_interaction_allowed
;
992 if (!check_credential_string( buff
, insize
, list
->filter_size
, list
->filter_offset
)) return STATUS_INVALID_PARAMETER
;
993 if (!(filter
= strdupW( (const WCHAR
*)((const char *)list
+ list
->filter_offset
) ))) return STATUS_NO_MEMORY
;
995 SecKeychainGetUserInteractionAllowed( &saved_user_interaction_allowed
);
996 SecKeychainSetUserInteractionAllowed( false );
998 if ((status
= search_credentials( filter
, NULL
, &count
, &size
)) == STATUS_SUCCESS
)
1003 if (size
>= sizeof(list
->size
)) list
->size
= size
;
1004 iosb
->Information
= sizeof(list
->size
);
1005 status
= STATUS_BUFFER_OVERFLOW
;
1010 list
->count
= count
;
1011 iosb
->Information
= size
;
1012 status
= search_credentials( filter
, list
, NULL
, NULL
);
1016 SecKeychainSetUserInteractionAllowed( saved_user_interaction_allowed
);
1017 RtlFreeHeap( GetProcessHeap(), 0, filter
);
1020 #endif /* __APPLE__ */
1022 /* handler for ioctls on the mount manager device */
1023 static NTSTATUS WINAPI
mountmgr_ioctl( DEVICE_OBJECT
*device
, IRP
*irp
)
1025 IO_STACK_LOCATION
*irpsp
= IoGetCurrentIrpStackLocation( irp
);
1028 TRACE( "ioctl %x insize %u outsize %u\n",
1029 irpsp
->Parameters
.DeviceIoControl
.IoControlCode
,
1030 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1031 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
);
1033 switch(irpsp
->Parameters
.DeviceIoControl
.IoControlCode
)
1035 case IOCTL_MOUNTMGR_QUERY_POINTS
:
1036 status
= query_mount_points( irp
->AssociatedIrp
.SystemBuffer
,
1037 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1038 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1041 case IOCTL_MOUNTMGR_DEFINE_UNIX_DRIVE
:
1042 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_unix_drive
))
1044 status
= STATUS_INVALID_PARAMETER
;
1047 irp
->IoStatus
.Information
= 0;
1048 status
= define_unix_drive( irp
->AssociatedIrp
.SystemBuffer
,
1049 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
);
1051 case IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE
:
1052 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_unix_drive
))
1054 status
= STATUS_INVALID_PARAMETER
;
1057 status
= query_unix_drive( irp
->AssociatedIrp
.SystemBuffer
,
1058 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1059 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1062 case IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER
:
1063 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_shell_folder
))
1065 status
= STATUS_INVALID_PARAMETER
;
1068 irp
->IoStatus
.Information
= 0;
1069 status
= define_shell_folder( irp
->AssociatedIrp
.SystemBuffer
,
1070 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
);
1072 case IOCTL_MOUNTMGR_QUERY_SHELL_FOLDER
:
1073 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_shell_folder
))
1075 status
= STATUS_INVALID_PARAMETER
;
1078 status
= query_shell_folder( irp
->AssociatedIrp
.SystemBuffer
,
1079 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1080 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1083 case IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS
:
1084 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_dhcp_request_params
))
1086 status
= STATUS_INVALID_PARAMETER
;
1090 if (TrySubmitThreadpoolCallback( query_dhcp_request_params
, irp
, NULL
))
1091 return (irp
->IoStatus
.u
.Status
= STATUS_PENDING
);
1092 status
= STATUS_NO_MEMORY
;
1095 case IOCTL_MOUNTMGR_QUERY_SYMBOL_FILE
:
1096 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
!= sizeof(GUID
)
1097 || irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUNTMGR_TARGET_NAME
))
1099 status
= STATUS_INVALID_PARAMETER
;
1102 if (TrySubmitThreadpoolCallback( query_symbol_file
, irp
, NULL
))
1103 return (irp
->IoStatus
.u
.Status
= STATUS_PENDING
);
1104 status
= STATUS_NO_MEMORY
;
1106 case IOCTL_MOUNTMGR_READ_CREDENTIAL
:
1107 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_credential
))
1109 status
= STATUS_INVALID_PARAMETER
;
1112 status
= read_credential( irp
->AssociatedIrp
.SystemBuffer
,
1113 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1114 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1117 case IOCTL_MOUNTMGR_WRITE_CREDENTIAL
:
1118 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_credential
))
1120 status
= STATUS_INVALID_PARAMETER
;
1123 status
= write_credential( irp
->AssociatedIrp
.SystemBuffer
,
1124 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1125 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1128 case IOCTL_MOUNTMGR_DELETE_CREDENTIAL
:
1129 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_credential
))
1131 status
= STATUS_INVALID_PARAMETER
;
1134 status
= delete_credential( irp
->AssociatedIrp
.SystemBuffer
,
1135 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1136 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1139 case IOCTL_MOUNTMGR_ENUMERATE_CREDENTIALS
:
1140 if (irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(struct mountmgr_credential_list
))
1142 status
= STATUS_INVALID_PARAMETER
;
1145 status
= enumerate_credentials( irp
->AssociatedIrp
.SystemBuffer
,
1146 irpsp
->Parameters
.DeviceIoControl
.InputBufferLength
,
1147 irpsp
->Parameters
.DeviceIoControl
.OutputBufferLength
,
1152 FIXME( "ioctl %x not supported\n", irpsp
->Parameters
.DeviceIoControl
.IoControlCode
);
1153 status
= STATUS_NOT_SUPPORTED
;
1156 irp
->IoStatus
.u
.Status
= status
;
1157 IoCompleteRequest( irp
, IO_NO_INCREMENT
);
1161 /* main entry point for the mount point manager driver */
1162 NTSTATUS WINAPI
DriverEntry( DRIVER_OBJECT
*driver
, UNICODE_STRING
*path
)
1164 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};
1165 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};
1166 static const WCHAR link_mountmgrW
[] = {'\\','?','?','\\','M','o','u','n','t','P','o','i','n','t','M','a','n','a','g','e','r',0};
1167 static const WCHAR harddiskW
[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
1168 static const WCHAR driver_serialW
[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
1169 static const WCHAR driver_parallelW
[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
1170 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};
1173 static const WCHAR qualified_ports_keyW
[] = {'\\','R','E','G','I','S','T','R','Y','\\',
1174 'M','A','C','H','I','N','E','\\','S','o','f','t','w','a','r','e','\\',
1175 'W','i','n','e','\\','P','o','r','t','s'}; /* no null terminator */
1176 static const WCHAR wow64_ports_keyW
[] = {'S','o','f','t','w','a','r','e','\\',
1177 'W','o','w','6','4','3','2','N','o','d','e','\\','W','i','n','e','\\',
1178 'P','o','r','t','s',0};
1179 static const WCHAR symbolic_link_valueW
[] = {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
1180 HKEY wow64_ports_key
= NULL
;
1183 UNICODE_STRING nameW
, linkW
;
1184 DEVICE_OBJECT
*device
;
1188 TRACE( "%s\n", debugstr_w(path
->Buffer
) );
1190 driver
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = mountmgr_ioctl
;
1192 RtlInitUnicodeString( &nameW
, device_mountmgrW
);
1193 RtlInitUnicodeString( &linkW
, link_mountmgrW
);
1194 if (!(status
= IoCreateDevice( driver
, 0, &nameW
, 0, 0, FALSE
, &device
)))
1195 status
= IoCreateSymbolicLink( &linkW
, &nameW
);
1198 FIXME( "failed to create device error %x\n", status
);
1202 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mounted_devicesW
, 0, NULL
,
1203 REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &mount_key
, NULL
);
1205 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, devicemapW
, 0, NULL
, REG_OPTION_VOLATILE
,
1206 KEY_ALL_ACCESS
, NULL
, &devicemap_key
, NULL
))
1207 RegCloseKey( devicemap_key
);
1209 RtlInitUnicodeString( &nameW
, harddiskW
);
1210 status
= IoCreateDriver( &nameW
, harddisk_driver_entry
);
1213 initialize_diskarbitration();
1216 /* create a symlink so that the Wine port overrides key can be edited with 32-bit reg or regedit */
1217 RegCreateKeyExW( HKEY_LOCAL_MACHINE
, wow64_ports_keyW
, 0, NULL
, REG_OPTION_CREATE_LINK
,
1218 KEY_SET_VALUE
, NULL
, &wow64_ports_key
, NULL
);
1219 RegSetValueExW( wow64_ports_key
, symbolic_link_valueW
, 0, REG_LINK
,
1220 (BYTE
*)qualified_ports_keyW
, sizeof(qualified_ports_keyW
) );
1221 RegCloseKey( wow64_ports_key
);
1224 RtlInitUnicodeString( &nameW
, driver_serialW
);
1225 IoCreateDriver( &nameW
, serial_driver_entry
);
1227 RtlInitUnicodeString( &nameW
, driver_parallelW
);
1228 IoCreateDriver( &nameW
, parallel_driver_entry
);