2017-09-08 08:02:43 +00:00
|
|
|
/* Copyright (c) Mark Harmstone 2016-17
|
|
|
|
*
|
2016-09-04 15:27:46 +00:00
|
|
|
* This file is part of WinBtrfs.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-09-04 15:27:46 +00:00
|
|
|
* WinBtrfs is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public Licence as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the Licence, or
|
|
|
|
* (at your option) any later version.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-09-04 15:27:46 +00:00
|
|
|
* WinBtrfs is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public Licence for more details.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-09-04 15:27:46 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public Licence
|
|
|
|
* along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
#include "btrfs_drv.h"
|
|
|
|
|
|
|
|
extern UNICODE_STRING log_device, log_file, registry_path;
|
2017-09-08 08:02:43 +00:00
|
|
|
extern LIST_ENTRY uid_map_list, gid_map_list;
|
|
|
|
extern ERESOURCE mapping_lock;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
extern HANDLE log_handle;
|
|
|
|
extern ERESOURCE log_lock;
|
|
|
|
extern PFILE_OBJECT comfo;
|
|
|
|
extern PDEVICE_OBJECT comdo;
|
|
|
|
#endif
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
WORK_QUEUE_ITEM wqi;
|
|
|
|
|
|
|
|
static WCHAR option_mounted[] = L"Mounted";
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
NTSTATUS registry_load_volume_options(device_extension* Vcb) {
|
|
|
|
BTRFS_UUID* uuid = &Vcb->superblock.uuid;
|
|
|
|
mount_options* options = &Vcb->options;
|
|
|
|
UNICODE_STRING path, ignoreus, compressus, compressforceus, compresstypeus, readonlyus, zliblevelus, flushintervalus,
|
2017-09-08 08:02:43 +00:00
|
|
|
maxinlineus, subvolidus, skipbalanceus, nobarrierus, notrimus, clearcacheus, allowdegradedus;
|
2016-07-27 19:24:26 +00:00
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG i, j, kvfilen, index, retlen;
|
|
|
|
KEY_VALUE_FULL_INFORMATION* kvfi = NULL;
|
|
|
|
HANDLE h;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->compress = mount_compress;
|
|
|
|
options->compress_force = mount_compress_force;
|
|
|
|
options->compress_type = mount_compress_type > BTRFS_COMPRESSION_LZO ? 0 : mount_compress_type;
|
2017-09-08 08:02:43 +00:00
|
|
|
options->readonly = mount_readonly;
|
2016-09-04 15:27:46 +00:00
|
|
|
options->zlib_level = mount_zlib_level;
|
|
|
|
options->flush_interval = mount_flush_interval;
|
|
|
|
options->max_inline = min(mount_max_inline, Vcb->superblock.node_size - sizeof(tree_header) - sizeof(leaf_node) - sizeof(EXTENT_DATA) + 1);
|
2017-01-01 17:12:12 +00:00
|
|
|
options->skip_balance = mount_skip_balance;
|
2017-09-08 08:02:43 +00:00
|
|
|
options->no_barrier = mount_no_barrier;
|
|
|
|
options->no_trim = mount_no_trim;
|
|
|
|
options->clear_cache = mount_clear_cache;
|
|
|
|
options->allow_degraded = mount_allow_degraded;
|
2016-09-04 15:27:46 +00:00
|
|
|
options->subvol_id = 0;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Length = path.MaximumLength = registry_path.Length + (37 * sizeof(WCHAR));
|
|
|
|
path.Buffer = ExAllocatePoolWithTag(PagedPool, path.Length, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!path.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(path.Buffer, registry_path.Buffer, registry_path.Length);
|
|
|
|
i = registry_path.Length / sizeof(WCHAR);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Buffer[i] = '\\';
|
|
|
|
i++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
path.Buffer[i] = hex_digit((uuid->uuid[j] & 0xF0) >> 4);
|
|
|
|
path.Buffer[i+1] = hex_digit(uuid->uuid[j] & 0xF);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
i += 2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (j == 3 || j == 5 || j == 7 || j == 9) {
|
|
|
|
path.Buffer[i] = '-';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvfilen = sizeof(KEY_VALUE_FULL_INFORMATION) - sizeof(WCHAR) + (255 * sizeof(WCHAR));
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
InitializeObjectAttributes(&oa, &path, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwOpenKey(&h, KEY_QUERY_VALUE, &oa);
|
|
|
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
goto end;
|
|
|
|
} else if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwOpenKey returned %08x\n", Status);
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
index = 0;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
RtlInitUnicodeString(&ignoreus, L"Ignore");
|
|
|
|
RtlInitUnicodeString(&compressus, L"Compress");
|
|
|
|
RtlInitUnicodeString(&compressforceus, L"CompressForce");
|
|
|
|
RtlInitUnicodeString(&compresstypeus, L"CompressType");
|
|
|
|
RtlInitUnicodeString(&readonlyus, L"Readonly");
|
|
|
|
RtlInitUnicodeString(&zliblevelus, L"ZlibLevel");
|
|
|
|
RtlInitUnicodeString(&flushintervalus, L"FlushInterval");
|
|
|
|
RtlInitUnicodeString(&maxinlineus, L"MaxInline");
|
|
|
|
RtlInitUnicodeString(&subvolidus, L"SubvolId");
|
2017-01-01 17:12:12 +00:00
|
|
|
RtlInitUnicodeString(&skipbalanceus, L"SkipBalance");
|
2017-09-08 08:02:43 +00:00
|
|
|
RtlInitUnicodeString(&nobarrierus, L"NoBarrier");
|
|
|
|
RtlInitUnicodeString(¬rimus, L"NoTrim");
|
|
|
|
RtlInitUnicodeString(&clearcacheus, L"ClearCache");
|
|
|
|
RtlInitUnicodeString(&allowdegradedus, L"AllowDegraded");
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
do {
|
|
|
|
Status = ZwEnumerateValueKey(h, index, KeyValueFullInformation, kvfi, kvfilen, &retlen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
index++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
|
|
|
UNICODE_STRING us;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
us.Length = us.MaximumLength = (USHORT)kvfi->NameLength;
|
2016-07-27 19:24:26 +00:00
|
|
|
us.Buffer = kvfi->Name;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (FsRtlAreNamesEqual(&ignoreus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
options->ignore = *val != 0 ? TRUE : FALSE;
|
2016-09-04 15:27:46 +00:00
|
|
|
} else if (FsRtlAreNamesEqual(&compressus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->compress = *val != 0 ? TRUE : FALSE;
|
|
|
|
} else if (FsRtlAreNamesEqual(&compressforceus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->compress_force = *val != 0 ? TRUE : FALSE;
|
|
|
|
} else if (FsRtlAreNamesEqual(&compresstypeus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
options->compress_type = (UINT8)(*val > BTRFS_COMPRESSION_LZO ? 0 : *val);
|
2016-09-04 15:27:46 +00:00
|
|
|
} else if (FsRtlAreNamesEqual(&readonlyus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->readonly = *val != 0 ? TRUE : FALSE;
|
|
|
|
} else if (FsRtlAreNamesEqual(&zliblevelus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->zlib_level = *val;
|
|
|
|
} else if (FsRtlAreNamesEqual(&flushintervalus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->flush_interval = *val;
|
|
|
|
} else if (FsRtlAreNamesEqual(&maxinlineus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->max_inline = min(*val, Vcb->superblock.node_size - sizeof(tree_header) - sizeof(leaf_node) - sizeof(EXTENT_DATA) + 1);
|
|
|
|
} else if (FsRtlAreNamesEqual(&subvolidus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_QWORD) {
|
|
|
|
UINT64* val = (UINT64*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
options->subvol_id = *val;
|
2017-01-01 17:12:12 +00:00
|
|
|
} else if (FsRtlAreNamesEqual(&skipbalanceus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
options->skip_balance = *val;
|
2017-09-08 08:02:43 +00:00
|
|
|
} else if (FsRtlAreNamesEqual(&nobarrierus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
|
|
|
|
|
|
|
options->no_barrier = *val;
|
|
|
|
} else if (FsRtlAreNamesEqual(¬rimus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
|
|
|
|
|
|
|
options->no_trim = *val;
|
|
|
|
} else if (FsRtlAreNamesEqual(&clearcacheus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
|
|
|
|
|
|
|
options->clear_cache = *val;
|
|
|
|
} else if (FsRtlAreNamesEqual(&allowdegradedus, &us, TRUE, NULL) && kvfi->DataOffset > 0 && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
DWORD* val = (DWORD*)((UINT8*)kvfi + kvfi->DataOffset);
|
|
|
|
|
|
|
|
options->allow_degraded = *val;
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
|
|
|
} else if (Status != STATUS_NO_MORE_ENTRIES) {
|
|
|
|
ERR("ZwEnumerateValueKey returned %08x\n", Status);
|
|
|
|
goto end2;
|
|
|
|
}
|
|
|
|
} while (NT_SUCCESS(Status));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (!options->compress && options->compress_force)
|
|
|
|
options->compress = TRUE;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (options->zlib_level > 9)
|
|
|
|
options->zlib_level = 9;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (options->flush_interval == 0)
|
|
|
|
options->flush_interval = mount_flush_interval;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
end2:
|
|
|
|
ZwClose(h);
|
|
|
|
|
|
|
|
end:
|
|
|
|
ExFreePool(path.Buffer);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (kvfi)
|
|
|
|
ExFreePool(kvfi);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS registry_mark_volume_mounted(BTRFS_UUID* uuid) {
|
|
|
|
UNICODE_STRING path, mountedus;
|
|
|
|
ULONG i, j;
|
|
|
|
NTSTATUS Status;
|
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
HANDLE h;
|
|
|
|
DWORD data;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Length = path.MaximumLength = registry_path.Length + (37 * sizeof(WCHAR));
|
|
|
|
path.Buffer = ExAllocatePoolWithTag(PagedPool, path.Length, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!path.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(path.Buffer, registry_path.Buffer, registry_path.Length);
|
|
|
|
i = registry_path.Length / sizeof(WCHAR);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Buffer[i] = '\\';
|
|
|
|
i++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
path.Buffer[i] = hex_digit((uuid->uuid[j] & 0xF0) >> 4);
|
|
|
|
path.Buffer[i+1] = hex_digit(uuid->uuid[j] & 0xF);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
i += 2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (j == 3 || j == 5 || j == 7 || j == 9) {
|
|
|
|
path.Buffer[i] = '-';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&oa, &path, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwCreateKey(&h, KEY_SET_VALUE, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwCreateKey returned %08x\n", Status);
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
mountedus.Buffer = option_mounted;
|
2017-09-08 08:02:43 +00:00
|
|
|
mountedus.Length = mountedus.MaximumLength = (USHORT)wcslen(option_mounted) * sizeof(WCHAR);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
data = 1;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwSetValueKey(h, &mountedus, 0, REG_DWORD, &data, sizeof(DWORD));
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
|
|
|
goto end2;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
end2:
|
|
|
|
ZwClose(h);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
end:
|
|
|
|
ExFreePool(path.Buffer);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS registry_mark_volume_unmounted_path(PUNICODE_STRING path) {
|
|
|
|
HANDLE h;
|
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG index, kvbilen = sizeof(KEY_VALUE_BASIC_INFORMATION) - sizeof(WCHAR) + (255 * sizeof(WCHAR)), retlen;
|
|
|
|
KEY_VALUE_BASIC_INFORMATION* kvbi;
|
|
|
|
BOOL has_options = FALSE;
|
|
|
|
UNICODE_STRING mountedus;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
// If a volume key has any options in it, we set Mounted to 0 and return. Otherwise,
|
|
|
|
// we delete the whole thing.
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvbi = ExAllocatePoolWithTag(PagedPool, kvbilen, ALLOC_TAG);
|
|
|
|
if (!kvbi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
InitializeObjectAttributes(&oa, path, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwOpenKey(&h, KEY_QUERY_VALUE | KEY_SET_VALUE | DELETE, &oa);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwOpenKey returned %08x\n", Status);
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
index = 0;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
mountedus.Buffer = option_mounted;
|
2017-09-08 08:02:43 +00:00
|
|
|
mountedus.Length = mountedus.MaximumLength = (USHORT)wcslen(option_mounted) * sizeof(WCHAR);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
do {
|
|
|
|
Status = ZwEnumerateValueKey(h, index, KeyValueBasicInformation, kvbi, kvbilen, &retlen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
index++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
|
|
|
UNICODE_STRING us;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
us.Length = us.MaximumLength = (USHORT)kvbi->NameLength;
|
2016-07-27 19:24:26 +00:00
|
|
|
us.Buffer = kvbi->Name;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!FsRtlAreNamesEqual(&mountedus, &us, TRUE, NULL)) {
|
|
|
|
has_options = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (Status != STATUS_NO_MORE_ENTRIES) {
|
|
|
|
ERR("ZwEnumerateValueKey returned %08x\n", Status);
|
|
|
|
goto end2;
|
|
|
|
}
|
|
|
|
} while (NT_SUCCESS(Status));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (has_options) {
|
|
|
|
DWORD data = 0;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwSetValueKey(h, &mountedus, 0, REG_DWORD, &data, sizeof(DWORD));
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
|
|
|
goto end2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Status = ZwDeleteKey(h);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwDeleteKey returned %08x\n", Status);
|
|
|
|
goto end2;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
end2:
|
|
|
|
ZwClose(h);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
end:
|
|
|
|
ExFreePool(kvbi);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS registry_mark_volume_unmounted(BTRFS_UUID* uuid) {
|
|
|
|
UNICODE_STRING path;
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG i, j;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Length = path.MaximumLength = registry_path.Length + (37 * sizeof(WCHAR));
|
|
|
|
path.Buffer = ExAllocatePoolWithTag(PagedPool, path.Length, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!path.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(path.Buffer, registry_path.Buffer, registry_path.Length);
|
|
|
|
i = registry_path.Length / sizeof(WCHAR);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Buffer[i] = '\\';
|
|
|
|
i++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
path.Buffer[i] = hex_digit((uuid->uuid[j] & 0xF0) >> 4);
|
|
|
|
path.Buffer[i+1] = hex_digit(uuid->uuid[j] & 0xF);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
i += 2;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (j == 3 || j == 5 || j == 7 || j == 9) {
|
|
|
|
path.Buffer[i] = '-';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = registry_mark_volume_unmounted_path(&path);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("registry_mark_volume_unmounted_path returned %08x\n", Status);
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
end:
|
|
|
|
ExFreePool(path.Buffer);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define is_hex(c) ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
|
|
|
|
|
|
|
|
static BOOL is_uuid(ULONG namelen, WCHAR* name) {
|
|
|
|
ULONG i;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (namelen != 36 * sizeof(WCHAR))
|
|
|
|
return FALSE;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
for (i = 0; i < 36; i++) {
|
|
|
|
if (i == 8 || i == 13 || i == 18 || i == 23) {
|
|
|
|
if (name[i] != '-')
|
|
|
|
return FALSE;
|
|
|
|
} else if (!is_hex(name[i]))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UNICODE_STRING name;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} key_name;
|
|
|
|
|
|
|
|
static void reset_subkeys(HANDLE h, PUNICODE_STRING reg_path) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
KEY_BASIC_INFORMATION* kbi;
|
|
|
|
ULONG kbilen = sizeof(KEY_BASIC_INFORMATION) - sizeof(WCHAR) + (255 * sizeof(WCHAR)), retlen, index = 0;
|
|
|
|
LIST_ENTRY key_names, *le;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
InitializeListHead(&key_names);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kbi = ExAllocatePoolWithTag(PagedPool, kbilen, ALLOC_TAG);
|
|
|
|
if (!kbi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
do {
|
|
|
|
Status = ZwEnumerateKey(h, index, KeyBasicInformation, kbi, kbilen, &retlen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
index++;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
|
|
|
key_name* kn;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
TRACE("key: %.*S\n", kbi->NameLength / sizeof(WCHAR), kbi->Name);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (is_uuid(kbi->NameLength, kbi->Name)) {
|
|
|
|
kn = ExAllocatePoolWithTag(PagedPool, sizeof(key_name), ALLOC_TAG);
|
|
|
|
if (!kn) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
kn->name.Length = kn->name.MaximumLength = (USHORT)min(0xffff, kbi->NameLength);
|
|
|
|
kn->name.Buffer = ExAllocatePoolWithTag(PagedPool, kn->name.MaximumLength, ALLOC_TAG);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!kn->name.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ExFreePool(kn);
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
RtlCopyMemory(kn->name.Buffer, kbi->Name, kn->name.Length);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
InsertTailList(&key_names, &kn->list_entry);
|
|
|
|
}
|
|
|
|
} else if (Status != STATUS_NO_MORE_ENTRIES)
|
|
|
|
ERR("ZwEnumerateKey returned %08x\n", Status);
|
|
|
|
} while (NT_SUCCESS(Status));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
le = key_names.Flink;
|
|
|
|
while (le != &key_names) {
|
|
|
|
key_name* kn = CONTAINING_RECORD(le, key_name, list_entry);
|
|
|
|
UNICODE_STRING path;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path.Length = path.MaximumLength = reg_path->Length + sizeof(WCHAR) + kn->name.Length;
|
|
|
|
path.Buffer = ExAllocatePoolWithTag(PagedPool, path.Length, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!path.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(path.Buffer, reg_path->Buffer, reg_path->Length);
|
|
|
|
path.Buffer[reg_path->Length / sizeof(WCHAR)] = '\\';
|
|
|
|
RtlCopyMemory(&path.Buffer[(reg_path->Length / sizeof(WCHAR)) + 1], kn->name.Buffer, kn->name.Length);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = registry_mark_volume_unmounted_path(&path);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
WARN("registry_mark_volume_unmounted_path returned %08x\n", Status);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExFreePool(path.Buffer);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
le = le->Flink;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
end:
|
|
|
|
while (!IsListEmpty(&key_names)) {
|
|
|
|
key_name* kn;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
le = RemoveHeadList(&key_names);
|
|
|
|
kn = CONTAINING_RECORD(le, key_name, list_entry);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (kn->name.Buffer)
|
|
|
|
ExFreePool(kn->name.Buffer);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExFreePool(kn);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool(kbi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_mappings(PUNICODE_STRING regpath) {
|
|
|
|
WCHAR* path;
|
|
|
|
UNICODE_STRING us;
|
|
|
|
HANDLE h;
|
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
ULONG dispos;
|
|
|
|
NTSTATUS Status;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
const WCHAR mappings[] = L"\\Mappings";
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
while (!IsListEmpty(&uid_map_list)) {
|
|
|
|
uid_map* um = CONTAINING_RECORD(RemoveHeadList(&uid_map_list), uid_map, listentry);
|
|
|
|
|
|
|
|
if (um->sid) ExFreePool(um->sid);
|
|
|
|
ExFreePool(um);
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
path = ExAllocatePoolWithTag(PagedPool, regpath->Length + (wcslen(mappings) * sizeof(WCHAR)), ALLOC_TAG);
|
|
|
|
if (!path) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(path, regpath->Buffer, regpath->Length);
|
|
|
|
RtlCopyMemory((UINT8*)path + regpath->Length, mappings, wcslen(mappings) * sizeof(WCHAR));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
us.Buffer = path;
|
|
|
|
us.Length = us.MaximumLength = regpath->Length + ((USHORT)wcslen(mappings) * sizeof(WCHAR));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
InitializeObjectAttributes(&oa, &us, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwCreateKey(&h, KEY_QUERY_VALUE, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, &dispos);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwCreateKey returned %08x\n", Status);
|
|
|
|
ExFreePool(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dispos == REG_OPENED_EXISTING_KEY) {
|
2017-09-08 08:02:43 +00:00
|
|
|
KEY_VALUE_FULL_INFORMATION* kvfi;
|
|
|
|
ULONG kvfilen, retlen, i;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvfilen = sizeof(KEY_VALUE_FULL_INFORMATION) + 256;
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ExFreePool(path);
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
Status = ZwEnumerateValueKey(h, i, KeyValueFullInformation, kvfi, kvfilen, &retlen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (NT_SUCCESS(Status) && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
2016-07-27 19:24:26 +00:00
|
|
|
UINT32 val = 0;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(&val, (UINT8*)kvfi + kvfi->DataOffset, min(kvfi->DataLength, sizeof(UINT32)));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
TRACE("entry %u = %.*S = %u\n", i, kvfi->NameLength / sizeof(WCHAR), kvfi->Name, val);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
add_user_mapping(kvfi->Name, kvfi->NameLength / sizeof(WCHAR), val);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
i = i + 1;
|
|
|
|
} while (Status != STATUS_NO_MORE_ENTRIES);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
ExFreePool(kvfi);
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ZwClose(h);
|
|
|
|
|
|
|
|
ExFreePool(path);
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
static void read_group_mappings(PUNICODE_STRING regpath) {
|
|
|
|
WCHAR* path;
|
|
|
|
UNICODE_STRING us;
|
|
|
|
HANDLE h;
|
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
ULONG dispos;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
const WCHAR mappings[] = L"\\GroupMappings";
|
|
|
|
|
|
|
|
while (!IsListEmpty(&gid_map_list)) {
|
|
|
|
gid_map* gm = CONTAINING_RECORD(RemoveHeadList(&gid_map_list), gid_map, listentry);
|
|
|
|
|
|
|
|
if (gm->sid) ExFreePool(gm->sid);
|
|
|
|
ExFreePool(gm);
|
|
|
|
}
|
|
|
|
|
|
|
|
path = ExAllocatePoolWithTag(PagedPool, regpath->Length + (wcslen(mappings) * sizeof(WCHAR)), ALLOC_TAG);
|
|
|
|
if (!path) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory(path, regpath->Buffer, regpath->Length);
|
|
|
|
RtlCopyMemory((UINT8*)path + regpath->Length, mappings, wcslen(mappings) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
us.Buffer = path;
|
|
|
|
us.Length = us.MaximumLength = regpath->Length + ((USHORT)wcslen(mappings) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&oa, &us, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
|
|
|
|
|
|
|
Status = ZwCreateKey(&h, KEY_QUERY_VALUE, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, &dispos);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwCreateKey returned %08x\n", Status);
|
|
|
|
ExFreePool(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool(path);
|
|
|
|
|
|
|
|
if (dispos == REG_OPENED_EXISTING_KEY) {
|
|
|
|
KEY_VALUE_FULL_INFORMATION* kvfi;
|
|
|
|
ULONG kvfilen, retlen, i;
|
|
|
|
|
|
|
|
kvfilen = sizeof(KEY_VALUE_FULL_INFORMATION) + 256;
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
|
|
|
|
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
Status = ZwEnumerateValueKey(h, i, KeyValueFullInformation, kvfi, kvfilen, &retlen);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status) && kvfi->DataLength > 0 && kvfi->Type == REG_DWORD) {
|
|
|
|
UINT32 val = 0;
|
|
|
|
|
|
|
|
RtlCopyMemory(&val, (UINT8*)kvfi + kvfi->DataOffset, min(kvfi->DataLength, sizeof(UINT32)));
|
|
|
|
|
|
|
|
TRACE("entry %u = %.*S = %u\n", i, kvfi->NameLength / sizeof(WCHAR), kvfi->Name, val);
|
|
|
|
|
|
|
|
add_group_mapping(kvfi->Name, kvfi->NameLength / sizeof(WCHAR), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = i + 1;
|
|
|
|
} while (Status != STATUS_NO_MORE_ENTRIES);
|
|
|
|
|
|
|
|
ExFreePool(kvfi);
|
|
|
|
} else if (dispos == REG_CREATED_NEW_KEY) {
|
|
|
|
WCHAR* builtin_users = L"S-1-5-32-545";
|
|
|
|
UNICODE_STRING us2;
|
|
|
|
DWORD val;
|
|
|
|
|
|
|
|
// If we're creating the key for the first time, we add a default mapping of
|
|
|
|
// BUILTIN\Users to gid 100, which ought to correspond to the "users" group on Linux.
|
|
|
|
|
|
|
|
us2.Length = us2.MaximumLength = (USHORT)wcslen(builtin_users) * sizeof(WCHAR);
|
|
|
|
us2.Buffer = ExAllocatePoolWithTag(PagedPool, us2.MaximumLength, ALLOC_TAG);
|
|
|
|
|
|
|
|
if (us2.Buffer) {
|
|
|
|
RtlCopyMemory(us2.Buffer, builtin_users, us2.Length);
|
|
|
|
|
|
|
|
val = 100;
|
|
|
|
Status = ZwSetValueKey(h, &us2, 0, REG_DWORD, &val, sizeof(DWORD));
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_group_mapping(us2.Buffer, us2.Length / sizeof(WCHAR), val);
|
|
|
|
|
|
|
|
ExFreePool(us2.Buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZwClose(h);
|
|
|
|
}
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
static void get_registry_value(HANDLE h, WCHAR* string, ULONG type, void* val, ULONG size) {
|
2016-07-27 19:24:26 +00:00
|
|
|
ULONG kvfilen;
|
|
|
|
KEY_VALUE_FULL_INFORMATION* kvfi;
|
2016-09-04 15:27:46 +00:00
|
|
|
UNICODE_STRING us;
|
|
|
|
NTSTATUS Status;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
RtlInitUnicodeString(&us, string);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvfi = NULL;
|
|
|
|
kvfilen = 0;
|
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if ((Status == STATUS_BUFFER_TOO_SMALL || Status == STATUS_BUFFER_OVERFLOW) && kvfilen > 0) {
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
2016-09-04 15:27:46 +00:00
|
|
|
if (kvfi->Type == type && kvfi->DataLength >= size) {
|
|
|
|
RtlCopyMemory(val, ((UINT8*)kvfi) + kvfi->DataOffset, size);
|
2016-07-27 19:24:26 +00:00
|
|
|
} else {
|
|
|
|
Status = ZwDeleteValueKey(h, &us);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwDeleteValueKey returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
Status = ZwSetValueKey(h, &us, 0, type, val, size);
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
2016-09-04 15:27:46 +00:00
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExFreePool(kvfi);
|
|
|
|
} else if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
|
2016-09-04 15:27:46 +00:00
|
|
|
Status = ZwSetValueKey(h, &us, 0, type, val, size);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
2016-09-04 15:27:46 +00:00
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
2016-07-27 19:24:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("ZwQueryValueKey returned %08x\n", Status);
|
|
|
|
}
|
2016-09-04 15:27:46 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
void read_registry(PUNICODE_STRING regpath, BOOL refresh) {
|
2016-09-04 15:27:46 +00:00
|
|
|
OBJECT_ATTRIBUTES oa;
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE h;
|
|
|
|
ULONG dispos;
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifdef _DEBUG
|
2016-09-04 15:27:46 +00:00
|
|
|
KEY_VALUE_FULL_INFORMATION* kvfi;
|
2017-09-08 08:02:43 +00:00
|
|
|
ULONG kvfilen, old_debug_log_level = debug_log_level;
|
|
|
|
UNICODE_STRING us, old_log_file, old_log_device;
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
static WCHAR def_log_file[] = L"\\??\\C:\\btrfs.log";
|
|
|
|
#endif
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
ExAcquireResourceExclusiveLite(&mapping_lock, TRUE);
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
read_mappings(regpath);
|
2017-09-08 08:02:43 +00:00
|
|
|
read_group_mappings(regpath);
|
|
|
|
|
|
|
|
ExReleaseResourceLite(&mapping_lock);
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
InitializeObjectAttributes(&oa, regpath, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
Status = ZwCreateKey(&h, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, &dispos);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwCreateKey returned %08x\n", Status);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!refresh)
|
|
|
|
reset_subkeys(h, regpath);
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
get_registry_value(h, L"Compress", REG_DWORD, &mount_compress, sizeof(mount_compress));
|
|
|
|
get_registry_value(h, L"CompressForce", REG_DWORD, &mount_compress_force, sizeof(mount_compress_force));
|
|
|
|
get_registry_value(h, L"CompressType", REG_DWORD, &mount_compress_type, sizeof(mount_compress_type));
|
|
|
|
get_registry_value(h, L"ZlibLevel", REG_DWORD, &mount_zlib_level, sizeof(mount_zlib_level));
|
|
|
|
get_registry_value(h, L"FlushInterval", REG_DWORD, &mount_flush_interval, sizeof(mount_flush_interval));
|
|
|
|
get_registry_value(h, L"MaxInline", REG_DWORD, &mount_max_inline, sizeof(mount_max_inline));
|
2017-01-01 17:12:12 +00:00
|
|
|
get_registry_value(h, L"SkipBalance", REG_DWORD, &mount_skip_balance, sizeof(mount_skip_balance));
|
2017-09-08 08:02:43 +00:00
|
|
|
get_registry_value(h, L"NoBarrier", REG_DWORD, &mount_no_barrier, sizeof(mount_no_barrier));
|
|
|
|
get_registry_value(h, L"NoTrim", REG_DWORD, &mount_no_trim, sizeof(mount_no_trim));
|
|
|
|
get_registry_value(h, L"ClearCache", REG_DWORD, &mount_clear_cache, sizeof(mount_clear_cache));
|
|
|
|
get_registry_value(h, L"AllowDegraded", REG_DWORD, &mount_allow_degraded, sizeof(mount_allow_degraded));
|
|
|
|
get_registry_value(h, L"Readonly", REG_DWORD, &mount_readonly, sizeof(mount_readonly));
|
|
|
|
|
|
|
|
if (!refresh)
|
|
|
|
get_registry_value(h, L"NoPNP", REG_DWORD, &no_pnp, sizeof(no_pnp));
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (mount_flush_interval == 0)
|
|
|
|
mount_flush_interval = 1;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
get_registry_value(h, L"DebugLogLevel", REG_DWORD, &debug_log_level, sizeof(debug_log_level));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlInitUnicodeString(&us, L"LogDevice");
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvfi = NULL;
|
|
|
|
kvfilen = 0;
|
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
old_log_device = log_device;
|
|
|
|
|
|
|
|
log_device.Length = log_device.MaximumLength = 0;
|
|
|
|
log_device.Buffer = NULL;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if ((Status == STATUS_BUFFER_TOO_SMALL || Status == STATUS_BUFFER_OVERFLOW) && kvfilen > 0) {
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
|
|
|
if ((kvfi->Type == REG_SZ || kvfi->Type == REG_EXPAND_SZ) && kvfi->DataLength >= sizeof(WCHAR)) {
|
2017-09-08 08:02:43 +00:00
|
|
|
log_device.Length = log_device.MaximumLength = (USHORT)min(0xffff, kvfi->DataLength);
|
|
|
|
log_device.Buffer = ExAllocatePoolWithTag(PagedPool, log_device.MaximumLength, ALLOC_TAG);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!log_device.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ExFreePool(kvfi);
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
RtlCopyMemory(log_device.Buffer, ((UINT8*)kvfi) + kvfi->DataOffset, log_device.Length);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (log_device.Buffer[(log_device.Length / sizeof(WCHAR)) - 1] == 0)
|
|
|
|
log_device.Length -= sizeof(WCHAR);
|
|
|
|
} else {
|
|
|
|
ERR("LogDevice was type %u, length %u\n", kvfi->Type, kvfi->DataLength);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwDeleteValueKey(h, &us);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwDeleteValueKey returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExFreePool(kvfi);
|
|
|
|
} else if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
|
|
|
|
ERR("ZwQueryValueKey returned %08x\n", Status);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
ExAcquireResourceExclusiveLite(&log_lock, TRUE);
|
|
|
|
|
|
|
|
if (refresh && (log_device.Length != old_log_device.Length || RtlCompareMemory(log_device.Buffer, old_log_device.Buffer, log_device.Length) != log_device.Length ||
|
|
|
|
(!comfo && log_device.Length > 0) || (old_debug_log_level == 0 && debug_log_level > 0) || (old_debug_log_level > 0 && debug_log_level == 0))) {
|
|
|
|
if (comfo)
|
|
|
|
ObDereferenceObject(comfo);
|
|
|
|
|
|
|
|
if (log_handle) {
|
|
|
|
ZwClose(log_handle);
|
|
|
|
log_handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
comfo = NULL;
|
|
|
|
comdo = NULL;
|
|
|
|
|
|
|
|
if (log_device.Length > 0 && debug_log_level > 0) {
|
|
|
|
Status = IoGetDeviceObjectPointer(&log_device, FILE_WRITE_DATA, &comfo, &comdo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
DbgPrint("IoGetDeviceObjectPointer returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExReleaseResourceLite(&log_lock);
|
|
|
|
|
|
|
|
if (old_log_device.Buffer)
|
|
|
|
ExFreePool(old_log_device.Buffer);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlInitUnicodeString(&us, L"LogFile");
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
kvfi = NULL;
|
|
|
|
kvfilen = 0;
|
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
old_log_file = log_file;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if ((Status == STATUS_BUFFER_TOO_SMALL || Status == STATUS_BUFFER_OVERFLOW) && kvfilen > 0) {
|
|
|
|
kvfi = ExAllocatePoolWithTag(PagedPool, kvfilen, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!kvfi) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwQueryValueKey(h, &us, KeyValueFullInformation, kvfi, kvfilen, &kvfilen);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (NT_SUCCESS(Status)) {
|
|
|
|
if ((kvfi->Type == REG_SZ || kvfi->Type == REG_EXPAND_SZ) && kvfi->DataLength >= sizeof(WCHAR)) {
|
2017-09-08 08:02:43 +00:00
|
|
|
log_file.Length = log_file.MaximumLength = (USHORT)min(0xffff, kvfi->DataLength);
|
|
|
|
log_file.Buffer = ExAllocatePoolWithTag(PagedPool, log_file.MaximumLength, ALLOC_TAG);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!log_file.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ExFreePool(kvfi);
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
RtlCopyMemory(log_file.Buffer, ((UINT8*)kvfi) + kvfi->DataOffset, log_file.Length);
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (log_file.Buffer[(log_file.Length / sizeof(WCHAR)) - 1] == 0)
|
|
|
|
log_file.Length -= sizeof(WCHAR);
|
|
|
|
} else {
|
|
|
|
ERR("LogFile was type %u, length %u\n", kvfi->Type, kvfi->DataLength);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
Status = ZwDeleteValueKey(h, &us);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwDeleteValueKey returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ExFreePool(kvfi);
|
|
|
|
} else if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
|
2017-09-08 08:02:43 +00:00
|
|
|
Status = ZwSetValueKey(h, &us, 0, REG_SZ, def_log_file, (ULONG)(wcslen(def_log_file) + 1) * sizeof(WCHAR));
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
ERR("ZwSetValueKey returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("ZwQueryValueKey returned %08x\n", Status);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (log_file.Length == 0) {
|
2017-09-08 08:02:43 +00:00
|
|
|
log_file.Length = log_file.MaximumLength = (UINT16)wcslen(def_log_file) * sizeof(WCHAR);
|
2016-07-27 19:24:26 +00:00
|
|
|
log_file.Buffer = ExAllocatePoolWithTag(PagedPool, log_file.MaximumLength, ALLOC_TAG);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
if (!log_file.Buffer) {
|
|
|
|
ERR("out of memory\n");
|
|
|
|
ZwClose(h);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
RtlCopyMemory(log_file.Buffer, def_log_file, log_file.Length);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
ExAcquireResourceExclusiveLite(&log_lock, TRUE);
|
|
|
|
|
|
|
|
if (refresh && (log_file.Length != old_log_file.Length || RtlCompareMemory(log_file.Buffer, old_log_file.Buffer, log_file.Length) != log_file.Length ||
|
|
|
|
(!log_handle && log_file.Length > 0) || (old_debug_log_level == 0 && debug_log_level > 0) || (old_debug_log_level > 0 && debug_log_level == 0))) {
|
|
|
|
if (log_handle) {
|
|
|
|
ZwClose(log_handle);
|
|
|
|
log_handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!comfo && log_file.Length > 0 && refresh && debug_log_level > 0) {
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&oa, &log_file, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
|
|
|
|
|
|
|
Status = ZwCreateFile(&log_handle, FILE_WRITE_DATA, &oa, &iosb, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
|
|
|
|
FILE_OPEN_IF, FILE_NON_DIRECTORY_FILE | FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_ALERT, NULL, 0);
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
DbgPrint("ZwCreateFile returned %08x\n", Status);
|
|
|
|
log_handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExReleaseResourceLite(&log_lock);
|
|
|
|
|
|
|
|
if (old_log_file.Buffer)
|
|
|
|
ExFreePool(old_log_file.Buffer);
|
2016-07-27 19:24:26 +00:00
|
|
|
#endif
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
ZwClose(h);
|
|
|
|
}
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Function_class_(WORKER_THREAD_ROUTINE)
|
|
|
|
#ifdef __REACTOS__
|
|
|
|
static void NTAPI registry_work_item(PVOID Parameter) {
|
|
|
|
#else
|
|
|
|
static void registry_work_item(PVOID Parameter) {
|
|
|
|
#endif
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE regh = (HANDLE)Parameter;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
|
|
|
TRACE("registry changed\n");
|
|
|
|
|
|
|
|
read_registry(®istry_path, TRUE);
|
|
|
|
|
|
|
|
Status = ZwNotifyChangeKey(regh, NULL, (PVOID)&wqi, (PVOID)DelayedWorkQueue, &iosb, REG_NOTIFY_CHANGE_LAST_SET, TRUE, NULL, 0, TRUE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
ERR("ZwNotifyChangeKey returned %08x\n", Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void watch_registry(HANDLE regh) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
|
|
|
ExInitializeWorkItem(&wqi, registry_work_item, regh);
|
|
|
|
|
|
|
|
Status = ZwNotifyChangeKey(regh, NULL, (PVOID)&wqi, (PVOID)DelayedWorkQueue, &iosb, REG_NOTIFY_CHANGE_LAST_SET, TRUE, NULL, 0, TRUE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
ERR("ZwNotifyChangeKey returned %08x\n", Status);
|
|
|
|
}
|