memfs: MemfsCreate: RootSddl

This commit is contained in:
Bill Zissimopoulos 2016-04-09 12:02:18 -07:00
parent 25911a808c
commit d1b004dc29
4 changed files with 51 additions and 7 deletions

View File

@ -55,6 +55,7 @@ static void usage(void)
" -t FileInfoTimeout\n" " -t FileInfoTimeout\n"
" -n MaxFileNodes\n" " -n MaxFileNodes\n"
" -s MaxFileSize\n" " -s MaxFileSize\n"
" -S RootSddl"
" -u \\\\Volume\\Prefix\n" " -u \\\\Volume\\Prefix\n"
" -m MountPoint\n"; " -m MountPoint\n";
@ -99,6 +100,7 @@ int wmain(int argc, wchar_t **argv)
ULONG MaxFileSize = 1024 * 1024; ULONG MaxFileSize = 1024 * 1024;
PWSTR MountPoint = 0; PWSTR MountPoint = 0;
PWSTR VolumePrefix = 0; PWSTR VolumePrefix = 0;
PWSTR RootSddl = 0;
for (argp = argv + 1; 0 != argp[0]; argp++) for (argp = argv + 1; 0 != argp[0]; argp++)
{ {
@ -112,6 +114,9 @@ int wmain(int argc, wchar_t **argv)
case L'n': case L'n':
MaxFileNodes = argtol(++argp, MaxFileNodes); MaxFileNodes = argtol(++argp, MaxFileNodes);
break; break;
case L'S':
RootSddl = argtos(++argp);
break;
case L's': case L's':
MaxFileSize = argtol(++argp, MaxFileSize); MaxFileSize = argtol(++argp, MaxFileSize);
break; break;
@ -135,7 +140,8 @@ int wmain(int argc, wchar_t **argv)
if (0 == MainEvent) if (0 == MainEvent)
fail("error: cannot create MainEvent"); fail("error: cannot create MainEvent");
Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, &Memfs); Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, RootSddl,
&Memfs);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
fail("error: cannot create MEMFS"); fail("error: cannot create MEMFS");
Result = MemfsStart(Memfs); Result = MemfsStart(Memfs);
@ -146,8 +152,9 @@ int wmain(int argc, wchar_t **argv)
fail("error: cannot mount MEMFS"); fail("error: cannot mount MEMFS");
MountPoint = FspFileSystemMountPoint(MemfsFileSystem(Memfs)); MountPoint = FspFileSystemMountPoint(MemfsFileSystem(Memfs));
warn("%s -t %ld -n %ld -s %ld%s%S -m %S", warn("%s -t %ld -n %ld -s %ld%s%S%s%S -m %S",
PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize, PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize,
RootSddl ? " -S " : "", RootSddl ? RootSddl : L"",
VolumePrefix ? " -u " : "", VolumePrefix ? VolumePrefix : L"", VolumePrefix ? " -u " : "", VolumePrefix ? VolumePrefix : L"",
MountPoint); MountPoint);
SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);

View File

@ -6,6 +6,7 @@
#undef _DEBUG #undef _DEBUG
#include "memfs.h" #include "memfs.h"
#include <sddl.h>
#include <map> #include <map>
#include <cassert> #include <cassert>
@ -836,9 +837,13 @@ static VOID MemfsLeaveOperation(FSP_FILE_SYSTEM *FileSystem,
LeaveCriticalSection(&Memfs->Lock); LeaveCriticalSection(&Memfs->Lock);
} }
NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout, NTSTATUS MemfsCreate(
ULONG MaxFileNodes, ULONG MaxFileSize, ULONG Flags,
ULONG FileInfoTimeout,
ULONG MaxFileNodes,
ULONG MaxFileSize,
PWSTR VolumePrefix, PWSTR VolumePrefix,
PWSTR RootSddl,
MEMFS **PMemfs) MEMFS **PMemfs)
{ {
NTSTATUS Result; NTSTATUS Result;
@ -848,13 +853,24 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
UINT64 AllocationUnit; UINT64 AllocationUnit;
MEMFS *Memfs; MEMFS *Memfs;
MEMFS_FILE_NODE *RootNode; MEMFS_FILE_NODE *RootNode;
PSECURITY_DESCRIPTOR RootSecurity;
ULONG RootSecuritySize;
BOOLEAN Inserted; BOOLEAN Inserted;
*PMemfs = 0; *PMemfs = 0;
if (0 == RootSddl)
RootSddl = L"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)";
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(RootSddl, SDDL_REVISION_1,
&RootSecurity, &RootSecuritySize))
return FspNtStatusFromWin32(GetLastError());
Memfs = (MEMFS *)malloc(sizeof *Memfs); Memfs = (MEMFS *)malloc(sizeof *Memfs);
if (0 == Memfs) if (0 == Memfs)
{
LocalFree(RootSecurity);
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
}
memset(Memfs, 0, sizeof *Memfs); memset(Memfs, 0, sizeof *Memfs);
Memfs->MaxFileNodes = MaxFileNodes; Memfs->MaxFileNodes = MaxFileNodes;
@ -865,6 +881,7 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
free(Memfs); free(Memfs);
LocalFree(RootSecurity);
return Result; return Result;
} }
@ -886,6 +903,7 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
{ {
MemfsFileNodeMapDelete(Memfs->FileNodeMap); MemfsFileNodeMapDelete(Memfs->FileNodeMap);
free(Memfs); free(Memfs);
LocalFree(RootSecurity);
return Result; return Result;
} }
@ -907,19 +925,34 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
MemfsDelete(Memfs); MemfsDelete(Memfs);
LocalFree(RootSecurity);
return Result; return Result;
} }
RootNode->FileInfo.FileAttributes = FILE_ATTRIBUTE_DIRECTORY; RootNode->FileInfo.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
RootNode->FileSecurity = malloc(RootSecuritySize);
if (0 == RootNode->FileSecurity)
{
MemfsFileNodeDelete(RootNode);
MemfsDelete(Memfs);
LocalFree(RootSecurity);
return STATUS_INSUFFICIENT_RESOURCES;
}
RootNode->FileSecuritySize = RootSecuritySize;
memcpy(RootNode->FileSecurity, RootSecurity, RootSecuritySize);
Result = MemfsFileNodeMapInsert(Memfs->FileNodeMap, RootNode, &Inserted); Result = MemfsFileNodeMapInsert(Memfs->FileNodeMap, RootNode, &Inserted);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
MemfsFileNodeDelete(RootNode); MemfsFileNodeDelete(RootNode);
MemfsDelete(Memfs); MemfsDelete(Memfs);
LocalFree(RootSecurity);
return Result; return Result;
} }
LocalFree(RootSecurity);
*PMemfs = Memfs; *PMemfs = Memfs;
return STATUS_SUCCESS; return STATUS_SUCCESS;

View File

@ -21,9 +21,13 @@ enum
MemfsNet = 0x01, MemfsNet = 0x01,
}; };
NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout, NTSTATUS MemfsCreate(
ULONG MaxFileNodes, ULONG MaxFileSize, ULONG Flags,
ULONG FileInfoTimeout,
ULONG MaxFileNodes,
ULONG MaxFileSize,
PWSTR VolumePrefix, PWSTR VolumePrefix,
PWSTR RootSddl,
MEMFS **PMemfs); MEMFS **PMemfs);
VOID MemfsDelete(MEMFS *Memfs); VOID MemfsDelete(MEMFS *Memfs);
NTSTATUS MemfsStart(MEMFS *Memfs); NTSTATUS MemfsStart(MEMFS *Memfs);

View File

@ -15,7 +15,7 @@ void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout)
NTSTATUS Result; NTSTATUS Result;
Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024, Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024,
MemfsNet == Flags ? L"\\memfs\\share" : 0, &Memfs); MemfsNet == Flags ? L"\\memfs\\share" : 0, 0, &Memfs);
ASSERT(NT_SUCCESS(Result)); ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs); ASSERT(0 != Memfs);