summaryrefslogtreecommitdiff
path: root/paramiko/_winapi.py
diff options
context:
space:
mode:
authorDorian Pula <dorian.pula@amber-penguin-software.ca>2017-05-23 17:49:28 -0700
committerJeff Forcier <jeff@bitprophet.org>2017-05-31 17:14:40 -0700
commitc960e2281a567314e80d46e77e79e05e6b2dc83e (patch)
treeea40ceecf201a121dd6d69545659edc7e394b0f9 /paramiko/_winapi.py
parentc1a0974d8886c6a2d46fb69a4a7df382875374c2 (diff)
downloadparamiko-c960e2281a567314e80d46e77e79e05e6b2dc83e.tar.gz
Lots of flake8 fix.
Diffstat (limited to 'paramiko/_winapi.py')
-rw-r--r--paramiko/_winapi.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/paramiko/_winapi.py b/paramiko/_winapi.py
index c9797d23..a13d7e87 100644
--- a/paramiko/_winapi.py
+++ b/paramiko/_winapi.py
@@ -41,7 +41,7 @@ def format_system_message(errno):
ctypes.byref(result_buffer),
buffer_size,
arguments,
- )
+ )
# note the following will cause an infinite loop if GetLastError
# repeatedly returns an error that cannot be formatted, although
# this should not happen.
@@ -52,13 +52,14 @@ def format_system_message(errno):
class WindowsError(builtins.WindowsError):
- "more info about errors at http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx"
+ """more info about errors at
+ http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx"""
def __init__(self, value=None):
if value is None:
value = ctypes.windll.kernel32.GetLastError()
strerror = format_system_message(value)
- if sys.version_info > (3,3):
+ if sys.version_info > (3, 3):
args = 0, strerror, None, value
else:
args = value, strerror
@@ -78,6 +79,7 @@ class WindowsError(builtins.WindowsError):
def __repr__(self):
return '{self.__class__.__name__}({self.winerror})'.format(**vars())
+
def handle_nonzero_success(result):
if result == 0:
raise WindowsError()
@@ -133,6 +135,7 @@ ctypes.windll.kernel32.LocalFree.argtypes = ctypes.wintypes.HLOCAL,
#####################
# jaraco.windows.mmap
+
class MemoryMap(object):
"""
A memory map object which can have security attributes overridden.
@@ -189,6 +192,7 @@ class MemoryMap(object):
ctypes.windll.kernel32.UnmapViewOfFile(self.view)
ctypes.windll.kernel32.CloseHandle(self.filemap)
+
#############################
# jaraco.windows.api.security
@@ -252,12 +256,15 @@ POLICY_EXECUTE = (
POLICY_VIEW_LOCAL_INFORMATION |
POLICY_LOOKUP_NAMES)
+
class TokenAccess:
TOKEN_QUERY = 0x8
+
class TokenInformationClass:
TokenUser = 1
+
class TOKEN_USER(ctypes.Structure):
num = 1
_fields_ = [
@@ -292,6 +299,7 @@ class SECURITY_DESCRIPTOR(ctypes.Structure):
('Dacl', ctypes.c_void_p),
]
+
class SECURITY_ATTRIBUTES(ctypes.Structure):
"""
typedef struct _SECURITY_ATTRIBUTES {
@@ -329,6 +337,7 @@ ctypes.windll.advapi32.SetSecurityDescriptorOwner.argtypes = (
#########################
# jaraco.windows.security
+
def GetTokenInformation(token, information_class):
"""
Given a token, get the token information for it.
@@ -343,6 +352,7 @@ def GetTokenInformation(token, information_class):
ctypes.byref(data_size)))
return ctypes.cast(data, ctypes.POINTER(TOKEN_USER)).contents
+
def OpenProcessToken(proc_handle, access):
result = ctypes.wintypes.HANDLE()
proc_handle = ctypes.wintypes.HANDLE(proc_handle)
@@ -350,6 +360,7 @@ def OpenProcessToken(proc_handle, access):
proc_handle, access, ctypes.byref(result)))
return result
+
def get_current_user():
"""
Return a TOKEN_USER for the owner of this process.
@@ -360,6 +371,7 @@ def get_current_user():
)
return GetTokenInformation(process, TOKEN_USER)
+
def get_security_attributes_for_user(user=None):
"""
Return a SECURITY_ATTRIBUTES structure with the SID set to the