Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions osquery/TPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def close(self):
in the same way
"""
if self._handle is not None:
win32pipe.DisconnectNamedPipe(self._handle)
win32file.CloseHandle(self._handle)
self._handle = None


Expand Down Expand Up @@ -67,13 +67,10 @@ def open(self):
while conns < self._max_conn_attempts:
try:
h = win32file.CreateFile(
self._pipe_name,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0,
None,
win32file.OPEN_EXISTING,
win32file.FILE_FLAG_OVERLAPPED,
None)
self._pipe_name,
win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None,
win32file.OPEN_EXISTING, win32file.FILE_FLAG_OVERLAPPED,
None)
except pywintypes.error as e:
if e.winerror != winerror.ERROR_PIPE_BUSY:
raise TTransportException(
Expand Down Expand Up @@ -198,8 +195,8 @@ def create_named_pipe(self):

self._handle = win32pipe.CreateNamedPipe(
self._pipe_name, openMode, pipeMode,
win32pipe.PIPE_UNLIMITED_INSTANCES, self._buff_size, self._buff_size,
win32pipe.NMPWAIT_WAIT_FOREVER, saAttr)
win32pipe.PIPE_UNLIMITED_INSTANCES, self._buff_size,
self._buff_size, win32pipe.NMPWAIT_WAIT_FOREVER, saAttr)

err = win32api.GetLastError()
if self._handle.handle == winerror.ERROR_INVALID_HANDLE:
Expand All @@ -223,3 +220,13 @@ def initiate_named_connect(self):
if ret == winerror.ERROR_PIPE_CONNECTED:
win32event.SetEvent(self._overlapped.hEvent)
break

def close(self):
"""
The server must ensure to disconnect so that subsequent reconnect
attempts are successful
"""
if self._handle is not None:
win32pipe.DisconnectNamedPipe(self._handle)
win32file.CloseHandle(self._handle)
self._handle = None