From adeed2b79d8f1a8fa92be09305f0fe8b64f0f2c5 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 21 Aug 2022 07:59:28 +0100 Subject: [PATCH] fsptool: ver, unload commands --- inc/winfsp/winfsp.h | 1 + src/dll/library.h | 1 - src/dll/sxs.c | 2 +- src/fsptool/fsptool.c | 49 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h index 4cb599f1..bf117260 100644 --- a/inc/winfsp/winfsp.h +++ b/inc/winfsp/winfsp.h @@ -2124,6 +2124,7 @@ FSP_API NTSTATUS FspCallNamedPipeSecurelyEx(PWSTR PipeName, PULONG PBytesTransferred, ULONG Timeout, BOOLEAN AllowImpersonation, PSID Sid); FSP_API NTSTATUS FspVersion(PUINT32 PVersion); +FSP_API PWSTR FspSxsIdent(VOID); /* * Delay load diff --git a/src/dll/library.h b/src/dll/library.h index 7eea06c6..da524098 100644 --- a/src/dll/library.h +++ b/src/dll/library.h @@ -70,7 +70,6 @@ NTSTATUS FspNpUnregister(VOID); NTSTATUS FspEventLogRegister(VOID); NTSTATUS FspEventLogUnregister(VOID); -PWSTR FspSxsIdent(VOID); PWSTR FspSxsSuffix(VOID); PWSTR FspSxsAppendSuffix(PWCHAR Buffer, SIZE_T Size, PWSTR Ident); diff --git a/src/dll/sxs.c b/src/dll/sxs.c index 93352cb7..874dad71 100644 --- a/src/dll/sxs.c +++ b/src/dll/sxs.c @@ -183,7 +183,7 @@ exit: return TRUE; } -PWSTR FspSxsIdent(VOID) +FSP_API PWSTR FspSxsIdent(VOID) { InitOnceExecuteOnce(&FspSxsIdentInitOnce, FspSxsIdentInitialize, 0, 0); return FspSxsIdentBuf + 1; diff --git a/src/fsptool/fsptool.c b/src/fsptool/fsptool.c index 68e61ab3..2ce083b1 100644 --- a/src/fsptool/fsptool.c +++ b/src/fsptool/fsptool.c @@ -61,11 +61,11 @@ static void usage(void) "usage: %s COMMAND ARGS\n" "\n" "commands:\n" + " ver print version\n" " lsvol list file system devices (volumes)\n" - //" list list running file system processes\n" - //" kill kill file system process\n" " id [NAME|SID|UID] print user id\n" - " perm [PATH|SDDL|UID:GID:MODE] print permissions\n", + " perm [PATH|SDDL|UID:GID:MODE] print permissions\n" + " unload unload driver (requires load driver priv)\n", PROGNAME); } @@ -237,6 +237,29 @@ NTSTATUS FspToolGetSidFromName(PWSTR Name, PSID *PSid) return STATUS_SUCCESS; } +static int ver(int argc, wchar_t **argv) +{ + if (1 != argc) + usage(); + + NTSTATUS Result; + UINT32 Version; + PWSTR SxsIdent; + + Result = FspVersion(&Version); + if (!NT_SUCCESS(Result)) + return FspWin32FromNtStatus(Result); + + SxsIdent = FspSxsIdent(); + + if (L'\0' == SxsIdent[0]) + info("%u.%u", Version >> 16, Version & 0xFFFF); + else + info("%u.%u (SxS=%S)", Version >> 16, Version & 0xFFFF, SxsIdent); + + return 0; +} + static NTSTATUS lsvol_dev(PWSTR DeviceName) { NTSTATUS Result; @@ -541,6 +564,20 @@ static int perm(int argc, wchar_t **argv) return FspWin32FromNtStatus(Result); } +static int unload(int argc, wchar_t **argv) +{ + if (1 != argc) + usage(); + + NTSTATUS Result; + + Result = FspFsctlStopService(); + if (!NT_SUCCESS(Result)) + return FspWin32FromNtStatus(Result); + + return 0; +} + int wmain(int argc, wchar_t **argv) { argc--; @@ -549,6 +586,9 @@ int wmain(int argc, wchar_t **argv) if (0 == argc) usage(); + if (0 == invariant_wcscmp(L"ver", argv[0])) + return ver(argc, argv); + else if (0 == invariant_wcscmp(L"lsvol", argv[0])) return lsvol(argc, argv); else @@ -557,6 +597,9 @@ int wmain(int argc, wchar_t **argv) else if (0 == invariant_wcscmp(L"perm", argv[0])) return perm(argc, argv); + else + if (0 == invariant_wcscmp(L"unload", argv[0])) + return unload(argc, argv); else usage();