dll: np: NPAddConnection3, NPCancelConnection implementation

This commit is contained in:
Bill Zissimopoulos
2016-05-16 15:48:27 -07:00
parent 67c6cd453a
commit 1c3fc530f6
6 changed files with 250 additions and 49 deletions

View File

@ -65,14 +65,14 @@ static int call_pipe_and_report(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize)
{
DWORD LastError, BytesTransferred;
LastError = CallNamedPipeW(L"" PIPE_NAME, PipeBuf, SendSize, PipeBuf, RecvSize,
LastError = CallNamedPipeW(L"" LAUNCHER_PIPE_NAME, PipeBuf, SendSize, PipeBuf, RecvSize,
&BytesTransferred, NMPWAIT_USE_DEFAULT_WAIT) ? 0 : GetLastError();
if (0 != LastError)
warn("KO CallNamedPipeW = %ld", LastError);
else if (0 == BytesTransferred)
else if (sizeof(WCHAR) > BytesTransferred)
warn("KO launcher: empty buffer");
else if (L'$' == PipeBuf[0])
else if (LauncherSuccess == PipeBuf[0])
{
if (sizeof(WCHAR) == BytesTransferred)
info("OK");
@ -97,7 +97,7 @@ static int call_pipe_and_report(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize)
info("OK\n%S", PipeBuf + 1);
}
}
else if (L'!' == PipeBuf[0])
else if (LauncherFailure == PipeBuf[0])
{
if (BytesTransferred < RecvSize)
PipeBuf[BytesTransferred / sizeof(WCHAR)] = L'\0';
@ -213,7 +213,7 @@ int wmain(int argc, wchar_t **argv)
PWSTR PipeBuf = 0;
/* allocate our PipeBuf early on; freed on process exit by the system */
PipeBuf = MemAlloc(PIPE_BUFFER_SIZE);
PipeBuf = MemAlloc(LAUNCHER_PIPE_BUFFER_SIZE);
if (0 == PipeBuf)
return ERROR_NO_SYSTEM_RESOURCES;
@ -228,7 +228,7 @@ int wmain(int argc, wchar_t **argv)
if (3 > argc || argc > 12)
usage();
return start(PipeBuf, PIPE_BUFFER_SIZE, argv[1], argv[2], argc - 3, argv + 3);
return start(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2], argc - 3, argv + 3);
}
else
if (0 == lstrcmpW(L"stop", argv[0]))
@ -236,7 +236,7 @@ int wmain(int argc, wchar_t **argv)
if (3 != argc)
usage();
return stop(PipeBuf, PIPE_BUFFER_SIZE, argv[1], argv[2]);
return stop(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
}
else
if (0 == lstrcmpW(L"info", argv[0]))
@ -244,7 +244,7 @@ int wmain(int argc, wchar_t **argv)
if (3 != argc)
usage();
return getinfo(PipeBuf, PIPE_BUFFER_SIZE, argv[1], argv[2]);
return getinfo(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
}
else
if (0 == lstrcmpW(L"list", argv[0]))
@ -252,7 +252,7 @@ int wmain(int argc, wchar_t **argv)
if (1 != argc)
usage();
return list(PipeBuf, PIPE_BUFFER_SIZE);
return list(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE);
}
else
if (0 == lstrcmpW(L"quit", argv[0]))
@ -261,7 +261,7 @@ int wmain(int argc, wchar_t **argv)
usage();
/* works only against DEBUG version of launcher */
return quit(PipeBuf, PIPE_BUFFER_SIZE);
return quit(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE);
}
else
usage();

View File

@ -487,7 +487,7 @@ NTSTATUS SvcInstanceStop(HANDLE ClientToken,
if (!NT_SUCCESS(Result))
goto exit;
KillProcess(SvcInstance->ProcessId, SvcInstance->Process, KILL_TIMEOUT);
KillProcess(SvcInstance->ProcessId, SvcInstance->Process, LAUNCHER_KILL_TIMEOUT);
Result = STATUS_SUCCESS;
@ -588,12 +588,12 @@ NTSTATUS SvcInstanceStopAndWaitAll(VOID)
{
SvcInstance = CONTAINING_RECORD(ListEntry, SVC_INSTANCE, ListEntry);
KillProcess(SvcInstance->ProcessId, SvcInstance->Process, KILL_TIMEOUT);
KillProcess(SvcInstance->ProcessId, SvcInstance->Process, LAUNCHER_KILL_TIMEOUT);
}
LeaveCriticalSection(&SvcInstanceLock);
WaitForSingleObject(SvcInstanceEvent, STOP_TIMEOUT);
WaitForSingleObject(SvcInstanceEvent, LAUNCHER_STOP_TIMEOUT);
return STATUS_SUCCESS;
}
@ -621,7 +621,7 @@ static NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
SecurityAttributes.nLength = sizeof SecurityAttributes;
SecurityAttributes.bInheritHandle = FALSE;
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(L"" PIPE_SDDL, SDDL_REVISION_1,
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(L"" LAUNCHER_PIPE_SDDL, SDDL_REVISION_1,
&SecurityAttributes.lpSecurityDescriptor, 0))
goto fail;
@ -654,11 +654,12 @@ static NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
if (0 == SvcOverlapped.hEvent)
goto fail;
SvcPipe = CreateNamedPipeW(L"" PIPE_NAME,
SvcPipe = CreateNamedPipeW(L"" LAUNCHER_PIPE_NAME,
PIPE_ACCESS_DUPLEX |
FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
1, PIPE_BUFFER_SIZE, PIPE_BUFFER_SIZE, PIPE_DEFAULT_TIMEOUT, &SecurityAttributes);
1, LAUNCHER_PIPE_BUFFER_SIZE, LAUNCHER_PIPE_BUFFER_SIZE, LAUNCHER_PIPE_DEFAULT_TIMEOUT,
&SecurityAttributes);
if (INVALID_HANDLE_VALUE == SvcPipe)
goto fail;
@ -708,8 +709,8 @@ static NTSTATUS SvcStop(FSP_SERVICE *Service)
if (GetCurrentThreadId() != SvcThreadId)
{
SetEvent(SvcEvent);
FspServiceRequestTime(Service, STOP_TIMEOUT);
WaitForSingleObject(SvcThread, STOP_TIMEOUT);
FspServiceRequestTime(Service, LAUNCHER_STOP_TIMEOUT);
WaitForSingleObject(SvcThread, LAUNCHER_STOP_TIMEOUT);
}
/*
@ -779,7 +780,7 @@ static DWORD WINAPI SvcPipeServer(PVOID Context)
HANDLE ClientToken;
DWORD LastError, BytesTransferred;
PipeBuf = MemAlloc(PIPE_BUFFER_SIZE);
PipeBuf = MemAlloc(LAUNCHER_PIPE_BUFFER_SIZE);
if (0 == PipeBuf)
{
FspServiceSetExitCode(Service, ERROR_NO_SYSTEM_RESOURCES);
@ -802,7 +803,7 @@ static DWORD WINAPI SvcPipeServer(PVOID Context)
}
LastError = SvcPipeWaitResult(
ReadFile(SvcPipe, PipeBuf, PIPE_BUFFER_SIZE, &BytesTransferred, &SvcOverlapped),
ReadFile(SvcPipe, PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, &BytesTransferred, &SvcOverlapped),
SvcEvent, SvcPipe, &SvcOverlapped, &BytesTransferred);
if (-1 == LastError)
break;
@ -892,11 +893,12 @@ static inline VOID SvcPipeTransactResult(NTSTATUS Result, PWSTR PipeBuf, PULONG
{
if (NT_SUCCESS(Result))
{
*PipeBuf = L'$';
*PipeBuf = LauncherSuccess;
*PSize += sizeof(WCHAR);
}
else
*PSize = (wsprintfW(PipeBuf, L"!%ld", FspWin32FromNtStatus(Result)) + 1) * sizeof(WCHAR);
*PSize = (wsprintfW(PipeBuf, L"%c%ld", LauncherFailure, FspWin32FromNtStatus(Result)) + 1) *
sizeof(WCHAR);
}
static VOID SvcPipeTransact(HANDLE ClientToken, PWSTR PipeBuf, PULONG PSize)
@ -945,7 +947,7 @@ static VOID SvcPipeTransact(HANDLE ClientToken, PWSTR PipeBuf, PULONG PSize)
Result = STATUS_INVALID_PARAMETER;
if (0 != ClassName && 0 != InstanceName)
{
*PSize = PIPE_BUFFER_SIZE - 1;
*PSize = LAUNCHER_PIPE_BUFFER_SIZE - 1;
Result = SvcInstanceGetInfo(ClientToken, ClassName, InstanceName, PipeBuf + 1, PSize);
}
@ -953,7 +955,7 @@ static VOID SvcPipeTransact(HANDLE ClientToken, PWSTR PipeBuf, PULONG PSize)
break;
case LauncherSvcInstanceList:
*PSize = PIPE_BUFFER_SIZE - 1;
*PSize = LAUNCHER_PIPE_BUFFER_SIZE - 1;
Result = SvcInstanceGetNameList(ClientToken, PipeBuf + 1, PSize);
SvcPipeTransactResult(Result, PipeBuf, PSize);

View File

@ -21,12 +21,12 @@
#include <winfsp/winfsp.h>
#include <shared/minimal.h>
#define STOP_TIMEOUT 5500
#define KILL_TIMEOUT 5000
#define LAUNCHER_STOP_TIMEOUT 5500
#define LAUNCHER_KILL_TIMEOUT 5000
#define PIPE_NAME "\\\\.\\pipe\\WinFsp.{14E7137D-22B4-437A-B0C1-D21D1BDF3767}"
#define PIPE_BUFFER_SIZE 2048
#define PIPE_DEFAULT_TIMEOUT 3000
#define LAUNCHER_PIPE_NAME "\\\\.\\pipe\\WinFsp.{14E7137D-22B4-437A-B0C1-D21D1BDF3767}"
#define LAUNCHER_PIPE_BUFFER_SIZE 2048
#define LAUNCHER_PIPE_DEFAULT_TIMEOUT 3000
/*
* The launcher named pipe SDDL gives full access to LocalSystem and Administrators.
@ -38,7 +38,7 @@
* the FILE_CREATE_PIPE_INSTANCE right is that the server creates the named pipe with
* MaxInstances == 1 (and therefore no client can create additional instances).
*/
#define PIPE_SDDL "D:P(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;WD)"
#define LAUNCHER_PIPE_SDDL "D:P(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;WD)"
/*
* The default service instance SDDL gives full access to LocalSystem and Administrators.
@ -60,6 +60,9 @@ enum
LauncherSvcInstanceInfo = 'I', /* requires: SERVICE_QUERY_STATUS */
LauncherSvcInstanceList = 'L', /* requires: none*/
LauncherQuit = 'Q', /* DEBUG version only */
LauncherSuccess = '$',
LauncherFailure = '!',
};
#endif