From 26daece790988d1cdaed9af4e0ec550f968cd1c8 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 3 Sep 2020 14:59:06 +0200 Subject: [PATCH] mountmgr: Add ioctl to delete host credentials on macOS. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/mountmgr.sys/mountmgr.c | 28 ++++++++++++++++++++++++++++ include/ddk/mountmgr.h | 1 + 2 files changed, 29 insertions(+) diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c index c3b9135ce10..95b11d864ab 100644 --- a/dlls/mountmgr.sys/mountmgr.c +++ b/dlls/mountmgr.sys/mountmgr.c @@ -819,6 +819,23 @@ error: RtlFreeHeap( GetProcessHeap(), 0, password ); return ret; } + +static NTSTATUS delete_credential( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_BLOCK *iosb ) +{ + const struct mountmgr_credential *cred = buff; + const WCHAR *targetname; + SecKeychainItemRef item; + + if (!check_credential_string( buff, insize, cred->targetname_size, cred->targetname_offset )) + return STATUS_INVALID_PARAMETER; + targetname = (const WCHAR *)((const char *)cred + cred->targetname_offset); + + if (!(item = find_credential( targetname ))) return STATUS_NOT_FOUND; + + SecKeychainItemDelete( item ); + CFRelease( item ); + return STATUS_SUCCESS; +} #endif /* __APPLE__ */ /* handler for ioctls on the mount manager device */ @@ -909,6 +926,17 @@ static NTSTATUS WINAPI mountmgr_ioctl( DEVICE_OBJECT *device, IRP *irp ) irpsp->Parameters.DeviceIoControl.OutputBufferLength, &irp->IoStatus ); break; + case IOCTL_MOUNTMGR_DELETE_CREDENTIAL: + if (irpsp->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct mountmgr_credential)) + { + irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER; + break; + } + irp->IoStatus.u.Status = delete_credential( irp->AssociatedIrp.SystemBuffer, + irpsp->Parameters.DeviceIoControl.InputBufferLength, + irpsp->Parameters.DeviceIoControl.OutputBufferLength, + &irp->IoStatus ); + break; #endif default: FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode ); diff --git a/include/ddk/mountmgr.h b/include/ddk/mountmgr.h index 162bbf71076..a5aae2a0851 100644 --- a/include/ddk/mountmgr.h +++ b/include/ddk/mountmgr.h @@ -76,6 +76,7 @@ struct mountmgr_unix_drive #define IOCTL_MOUNTMGR_READ_CREDENTIAL CTL_CODE(MOUNTMGRCONTROLTYPE, 48, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_MOUNTMGR_WRITE_CREDENTIAL CTL_CODE(MOUNTMGRCONTROLTYPE, 49, METHOD_BUFFERED, FILE_WRITE_ACCESS) +#define IOCTL_MOUNTMGR_DELETE_CREDENTIAL CTL_CODE(MOUNTMGRCONTROLTYPE, 50, METHOD_BUFFERED, FILE_WRITE_ACCESS) struct mountmgr_credential {