Ejemplo n.º 1
0
class x_mailslot_invalid_use(x_mailslot):
    pass

class x_mailslot_empty(x_mailslot):
    pass

class x_mailslot_message_too_big(x_mailslot):
    pass

class x_mailslot_message_too_complex(x_mailslot):
    pass

WINERROR_MAP = {
    winerror.ERROR_FILE_NOT_FOUND : exc.x_not_found,
}
wrapped = exc.wrapper(WINERROR_MAP, x_ipc)

def _unserialised(data):
    return data

class Mailslot(core._WinSysObject):
    """A mailslot is a mechanism for passing small datasets (up to about
    400 bytes) between machines in the same network. For transport and
    name resolution it uses NetBIOS so you can't, for example, use a
    machine's IP address when specifying the location of a mailslot.
    You can, however, use "*" in order to broadcast your message to
    all listening machines.

    A mailslot is either read-only or write-only. The typical case
    is that one machine starts up a reading mailslot, say for trace
    output, and all other machines write to that mailslot either by
Ejemplo n.º 2
0
PROPERTIES = {
    FMTID.SummaryInformation: PIDSI,
    FMTID.DocSummaryInformation: PIDDSI,
    FMTID.MediaFileSummaryInformation: PIDMSI,
    FMTID.AudioSummaryInformation: PIDASI,
    FMTID.Volume: PID_VOLUME,
}


class x_shell(exc.x_winsys):
    pass


WINERROR_MAP = {}
wrapped = exc.wrapper(WINERROR_MAP, x_shell)


#
# Although this can be done in one call, Win9x didn't
#  support it, so I added this workaround.
#
def get_path(folder_id):
    return shell.SHGetPathFromIDList(
        shell.SHGetSpecialFolderLocation(0, folder_id))


def desktop(common=0):
    u"What folder is equivalent to the current desktop?"
    return get_path((shellcon.CSIDL_DESKTOP,
                     shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common])
Ejemplo n.º 3
0
Archivo: ipc.py Proyecto: hashar/WAPT

class x_mailslot_empty(x_mailslot):
    pass


class x_mailslot_message_too_big(x_mailslot):
    pass


class x_mailslot_message_too_complex(x_mailslot):
    pass


WINERROR_MAP = {winerror.ERROR_FILE_NOT_FOUND: exc.x_not_found}
wrapped = exc.wrapper(WINERROR_MAP, x_ipc)


class Mailslot(core._WinSysObject):
    ur"""A mailslot is a mechanism for passing small datasets (up to about
  400 bytes) between machines in the same network. For transport and
  name resolution it uses NetBIOS so you can't, for example, use a
  machine's IP address when specifying the location of a mailslot.
  You can, however, use "*" in order to broadcast your message to
  all listening machines.
  
  A mailslot is either read-only or write-only. The typical case
  is that one machine starts up a reading mailslot, say for trace
  output, and all other machines write to that mailslot either by
  specifying the machine name directly or by broadcasting. This is
  particularly convenient as the writing machines have no need to
Ejemplo n.º 4
0
import win32security

from winsys import accounts, constants, core, exc, utils

__all__ = ['LogonSession', 'LSA', 'x_lsa']

class x_lsa (exc.x_winsys):
  "Base for all LSA-related exceptions"

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_lsa)

def principal (account):
  try:
    return accounts.principal (account)
  except exc.x_not_found:
    return "<unknown>"

class LogonSession (core._WinSysObject):

  _MAP = {
    u"UserName" : principal,
    u"Sid" : principal,
    u"LogonTime" : utils.from_pytime
  }

  def __init__ (self, session_id):
    core._WinSysObject.__init__ (self)
    self._session_id = session_id
    self._session_info = dict (session_id = self._session_id)
Ejemplo n.º 5
0
    dict(EVENTLOG_SUCCESS=0,
         AUDIT_FAILURE=win32evtlog.EVENTLOG_AUDIT_FAILURE,
         AUDIT_SUCCESS=win32evtlog.EVENTLOG_AUDIT_SUCCESS))
EVENTLOG_TYPE.doc("Types of records in event logs")

PyHANDLE = pywintypes.HANDLEType

DEFAULT_LOG_NAME = "Application"


class x_event_logs(exc.x_winsys):
    "Base exception for eventlog-specific exceptions"


WINERROR_MAP = {winerror.ERROR_ACCESS_DENIED: exc.x_access_denied}
wrapped = exc.wrapper(WINERROR_MAP)


class _EventLogEntry(core._WinSysObject):
    """Internal class for convenient access to attributes of an event log
    record. Attributes are available as lowercase_with_underscore equivalents
    of their TitleCase counterparts and are converted to Python data types
    where appropriate, eg time_written is a datetime value and sid is
    an :class:`accounts.Principal` instance.

    Two _EventLogEntry instances compare equal if they have the same
    record number on the same event log on the same computer.
    """
    def __init__(self, event_log_name, event_log_entry):
        self._event_log_name = event_log_name
        self._event_log_entry = event_log_entry
Ejemplo n.º 6
0
import win32api
import win32profile
import win32gui
import win32con
import winerror

from winsys._compat import *
from winsys import core, exc, utils, registry


class x_environment(exc.x_winsys):
    "Base exception for all env exceptions"


WINERROR_MAP = {winerror.ERROR_ENVVAR_NOT_FOUND: exc.x_not_found}
wrapped = exc.wrapper(WINERROR_MAP, x_environment)


class _DelimitedText(list):
    """Helper class for values such as PATH and PATHEXT which are
    consistently semicolon-delimited text but which can helpfully
    be treated as a list of individual values. Subclasseed from
    list, it keeps track of the delimited list while exposing
    the more familiar Pythonesque list interface.
    """

    def __init__(self, env, key, delimiter=";", initialiser=None):
        super(_DelimitedText, self).__init__(env[key].split(delimiter) if initialiser is None else initialiser)
        self.env = env
        self.key = key
        self.delimiter = unicode(delimiter)
Ejemplo n.º 7
0
CREDUI_FLAGS = constants.Constants.from_pattern("CREDUI_FLAGS_*",
                                                namespace=win32cred)
CREDUI_FLAGS.doc("Options for username prompt UI")
CRED_FLAGS = constants.Constants.from_pattern("CRED_FLAGS_*",
                                              namespace=win32cred)
CRED_TYPE = constants.Constants.from_pattern("CRED_TYPE_*",
                                             namespace=win32cred)
CRED_TI = constants.Constants.from_pattern("CRED_TI_*", namespace=win32cred)


class x_dialogs(exc.x_winsys):
    "Base for dialog-related exceptions"


WINERROR_MAP = {}
wrapped = exc.wrapper(WINERROR_MAP, x_dialogs)

DESKTOP = wrapped(win32gui.GetDesktopWindow)

ENCODING = "UTF-8"


class _DropTarget(win32com.server.policy.DesignatedWrapPolicy):
    """Helper class to implement the IDropTarget interface so that
    files can be drag-dropped onto a text field in a dialog.
    """
    _reg_clsid_ = '{72AA1C07-73BA-4CA8-88B9-7F03FEA173E8}'
    _reg_progid_ = "WinSysDialogs.DropTarget"
    _reg_desc_ = "Drop target handler for WinSys Dialogs"
    _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']
    _com_interfaces_ = [pythoncom.IID_IDropTarget]
Ejemplo n.º 8
0
__all__ = ['PRIVILEGE_ATTRIBUTE', 'PRIVILEGE', 'Privilege', 'privilege', 'x_privilege', 'x_privilege_no_token']

PRIVILEGE_ATTRIBUTE = constants.Constants.from_pattern("SE_PRIVILEGE_*", namespace=win32security)
PRIVILEGE = constants.Constants.from_pattern("SE_*_NAME", namespace=win32security)
PRIVILEGE.doc("Privileges granted through a user's token")

class x_privilege(exc.x_winsys):
    "Base for all privilege-related exceptions"

class x_privilege_no_token(x_privilege):
    "Raised when a token cannot be found"

WINERROR_MAP = {
    winerror.ERROR_NO_TOKEN : x_privilege_no_token
}
wrapped = exc.wrapper(WINERROR_MAP, x_privilege)

#
# Convenience implementation functions
#
def _get_token():
    try:
        return wrapped(
            win32security.OpenThreadToken,
            wrapped(win32api.GetCurrentThread),
            constants.GENERAL.MAXIMUM_ALLOWED,
            True
        )
    except x_privilege_no_token:
        return wrapped(
            win32security.OpenProcessToken,
Ejemplo n.º 9
0
__all__ = ['Token', 'token', 'x_token', 'x_no_token']

class x_token (exc.x_winsys):
  "Base for all token-related exceptions"

class x_no_token (x_token):
  "Raised when a token cannot be retrieved"

PyHANDLE = pywintypes.HANDLEType

WINERROR_MAP = {
  winerror.ERROR_ACCESS_DENIED : exc.x_access_denied,
  winerror.ERROR_NO_TOKEN : x_no_token
}
wrapped = exc.wrapper (WINERROR_MAP, x_token)

def _from_sid_and_attribute (data):
  sid, attributes = data
  #
  # SDK says that no attributes are defined at present,
  # so ignore them!
  #
  return accounts.principal (sid)
  
def _from_sid_and_attributes (data):
  return [_from_sid_and_attribute (d) for d in data]
  
def _from_privileges (data):
  return [_privileges.Privilege (*d) for d in data]
Ejemplo n.º 10
0
UF = constants.Constants.from_pattern (u"UF_*", namespace=win32netcon)
UF.doc ("Flags for creating new users")
SID_NAME_USE = constants.Constants.from_pattern (u"SidType*", namespace=ntsecuritycon)
SID_NAME_USE.doc ("Types of accounts for which SIDs exist")
FILTER = constants.Constants.from_pattern (u"FILTER_*", namespace=win32netcon)
FILTER.doc ("Filters when enumerating users")

PySID = pywintypes.SIDType

class x_accounts (exc.x_winsys):
  "Base for all accounts-related exceptions"

WINERROR_MAP = {
  winerror.ERROR_NONE_MAPPED : exc.x_not_found
}
wrapped = exc.wrapper (WINERROR_MAP, x_accounts)

def _win32net_enum (win32_fn, system_or_domain):
  resume = 0
  while True:
    items, total, resume = wrapped (win32_fn, system_or_domain, 0, resume)
    for item in items:
      yield item
    if resume == 0: break

def principal (principal, cls=core.UNSET):
  ur"""Factory function for the :class:`Principal` class. This is the most
  common way to create a :class:`Principal` object::
  
    from winsys import accounts
    service_account = accounts.principal (accounts.WELL_KNOWN_SID.Service)
Ejemplo n.º 11
0
"""

class x_active_directory(exc.x_winsys):
    "Base for all AD-related exceptions"

SEARCHPREF = constants.Constants.from_pattern("ADS_SEARCHPREF_*", namespace=adsicon)
SEARCHPREF.doc("Preferences for searching AD")
SCOPE = constants.Constants.from_pattern("ADS_SCOPE_*", namespace=adsicon)
SCOPE.doc("Scope for searching AD trees")

WINERROR_MAP = {
    adsicon.E_ADS_COLUMN_NOT_SET : exc.x_not_found,
    0x8000500D : AttributeError
}
wrapped = exc.wrapper(WINERROR_MAP, x_active_directory)

SEARCH_PREFERENCES = {
    SEARCHPREF.PAGESIZE : 1000,
    SEARCHPREF.SEARCH_SCOPE : SCOPE.SUBTREE,
}

class Result(dict):
    def __getattr__(self, attr):
        return self[attr]

ESCAPED_CHARACTERS = dict((special, r"\%02x" % ord(special)) for special in "*()\x00/")
def escaped(s):
    for original, escape in ESCAPED_CHARACTERS.items():
        s = s.replace(original, escape)
    return s
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import win32api
import win32con
import win32process

import pywintypes
from winsys import constants, core, exc, ipc, utils

class x_processes(exc.x_winsys):
    pass

WINERROR_MAP = {
}
wrapped = exc.wrapper(WINERROR_MAP, x_processes)

class Process(core._WinSysObject):

    def __init__(self, command, inherit_handles=True, flags=0, environment=None, current_directory=None, startupinfo=None):
        core._WinSysObject.__init__(self)
        process_info = wrapped(
            win32process.CreateProcess,
            None,
            command,
            None,
            None,
            inherit_handles,
            flags,
            environment,
            current_directory,
Ejemplo n.º 13
0
], pattern=u"SE_*", namespace=win32security)
SD_CONTROL.doc (u"Information held with a security descriptor header")

PyHANDLE = pywintypes.HANDLEType
PySECURITY_ATTRIBUTES = pywintypes.SECURITY_ATTRIBUTESType
PySECURITY_DESCRIPTOR = type (pywintypes.SECURITY_DESCRIPTOR ())

class x_security (exc.x_winsys):
  u"Base for security-related exceptions"

class x_value_not_set (x_security):
  u"Raised if an attempt is made to read a security value which hasn't been set"

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_security)

class Security (core._WinSysObject):
  ur"""The heart of the :mod:`security` module, this class represents the security
  descriptor of a file, kernel object or any other securable object. It's most
  commonly instantiated from an object's security method (eg `fs.File.security`)
  or by means of the :func:`security` function which can take the name or handle
  of an object and return a corresponding :class:`Security` object.
  
  Key attributes are:
  
  * owner - a :class:`Principal` object representing the object owner
  * group - a :class:`Principal` object representing the object group
  * dacl - a :class:`security.DACL` object representing the DACL
  * sacl - an :class:`security.SACL` object representing the SACL
  
Ejemplo n.º 14
0
from winsys._security.core import REVISION
from winsys._security import _aces

__all__ = ['x_acl', 'ACL', 'DACL', 'SACL', 'acl', 'dacl', 'sacl']

PyACL = pywintypes.ACLType

class x_acl (exc.x_winsys):
  "Base for all ACL-related exceptions"
  
class x_value_not_set (x_acl):
  "Raised when iterating over an ACL which has not been set"

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_acl)

class ACL (core._WinSysObject):
  """An ACL maps the Windows security ACL concept, but behaves like
  a Python list. You can append to it, iterate over it, delete from
  it, check its length and test it for membership. A special case is
  made for the so-called NULL ACL. This is different from an empty
  ACL (which is effectively completely restrictive). A NULL ACL is
  completely unrestrictive. This is mapped by holding None and treating
  this specially where needed.
  
  DACL & SACL subclasses are defined to cope with the slightly different
  ways in which the structures are manipulated, but the core functionality
  is in this base class. This class need rarely be instantiated directly;
  normally it will be invoked by the Security class which is accessor
  properties for this purpose.
Ejemplo n.º 15
0
# -*- coding: iso-8859-1 -*-
import win32api
import win32con
import win32file

import pywintypes
from winsys import constants, core, exc, utils

class x_handles (exc.x_winsys):
  pass

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_handles)

class Handle (core._WinSysObject):

  def __init__ (self, handle):
    core._WinSysObject.__init__ (self)
    self._handle = handle
    self.name = str (int (self._handle))

  def __int__ (self):
    return int (self._handle)

  def pyobject (self):
    return self._handle

  def duplicate (self, process=None, inheritable=True):
    target_process = processes.process (process).hProcess
    this_process = wrapped (win32api.GetCurrentProcess)
Ejemplo n.º 16
0
Archivo: shell.py Proyecto: hashar/WAPT
SHGDN = constants.Constants.from_pattern ("SHGDN_*", namespace=shellcon)

PROPERTIES = {
  FMTID.SummaryInformation : PIDSI,
  FMTID.DocSummaryInformation : PIDDSI,
  FMTID.MediaFileSummaryInformation : PIDMSI,
  FMTID.AudioSummaryInformation : PIDASI,
  FMTID.Volume : PID_VOLUME,    
}

class x_shell (exc.x_winsys):
  pass

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_shell)

#
# Although this can be done in one call, Win9x didn't
#  support it, so I added this workaround.
#
def get_path (folder_id):
  return shell.SHGetPathFromIDList (shell.SHGetSpecialFolderLocation (0, folder_id))

def desktop (common=0):
  u"What folder is equivalent to the current desktop?"
  return get_path ((shellcon.CSIDL_DESKTOP, shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common])

def common_desktop ():
#
# Only here because already used in code
Ejemplo n.º 17
0
import os, sys
import win32api
import win32profile
import win32gui
import win32con
import winerror

from winsys import core, exc, utils, registry

class x_environment(exc.x_winsys):
    "Base exception for all env exceptions"

WINERROR_MAP = {
    winerror.ERROR_ENVVAR_NOT_FOUND : exc.x_not_found,
}
wrapped = exc.wrapper(WINERROR_MAP, x_environment)

class _DelimitedText(list):
    """Helper class for values such as PATH and PATHEXT which are
    consistently semicolon-delimited text but which can helpfully
    be treated as a list of individual values. Subclasseed from
    list, it keeps track of the delimited list while exposing
    the more familiar Pythonesque list interface.
    """

    def __init__(self, env, key, delimiter=";", initialiser=None):
        super(_DelimitedText, self).__init__(env[key].split(delimiter) if initialiser is None else initialiser)
        self.env = env
        self.key = key
        self.delimiter = unicode(delimiter)
Ejemplo n.º 18
0
    AUDIT_FAILURE = win32evtlog.EVENTLOG_AUDIT_FAILURE,
    AUDIT_SUCCESS = win32evtlog.EVENTLOG_AUDIT_SUCCESS
))
EVENTLOG_TYPE.doc("Types of records in event logs")

PyHANDLE = pywintypes.HANDLEType

DEFAULT_LOG_NAME = "Application"

class x_event_logs(exc.x_winsys):
    "Base exception for eventlog-specific exceptions"

WINERROR_MAP = {
    winerror.ERROR_ACCESS_DENIED : exc.x_access_denied
}
wrapped = exc.wrapper(WINERROR_MAP)

class _EventLogEntry(core._WinSysObject):
    """Internal class for convenient access to attributes of an event log
    record. Attributes are available as lowercase_with_underscore equivalents
    of their TitleCase counterparts and are converted to Python data types
    where appropriate, eg time_written is a datetime value and sid is
    an :class:`accounts.Principal` instance.

    Two _EventLogEntry instances compare equal if they have the same
    record number on the same event log on the same computer.
    """

    def __init__(self, event_log_name, event_log_entry):
        self._event_log_name = event_log_name
        self._event_log_entry = event_log_entry
Ejemplo n.º 19
0
], pattern=u"SE_*", namespace=win32security)
SD_CONTROL.doc (u"Information held with a security descriptor header")

PyHANDLE = pywintypes.HANDLEType
PySECURITY_ATTRIBUTES = pywintypes.SECURITY_ATTRIBUTESType
PySECURITY_DESCRIPTOR = type (pywintypes.SECURITY_DESCRIPTOR ())

class x_security (exc.x_winsys):
  u"Base for security-related exceptions"

class x_value_not_set (x_security):
  u"Raised if an attempt is made to read a security value which hasn't been set"

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_security)

class Security (core._WinSysObject):
  ur"""The heart of the :mod:`security` module, this class represents the security
  descriptor of a file, kernel object or any other securable object. It's most
  commonly instantiated from an object's security method (eg `fs.File.security`)
  or by means of the :func:`security` function which can take the name or handle
  of an object and return a corresponding :class:`Security` object.

  Key attributes are:

  * owner - a :class:`Principal` object representing the object owner
  * group - a :class:`Principal` object representing the object group
  * dacl - a :class:`security.DACL` object representing the DACL
  * sacl - an :class:`security.SACL` object representing the SACL
Ejemplo n.º 20
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import win32security

from winsys import accounts, constants, core, exc, utils

__all__ = ['LogonSession', 'LSA', 'x_lsa']


class x_lsa(exc.x_winsys):
    "Base for all LSA-related exceptions"


WINERROR_MAP = {}
wrapped = exc.wrapper(WINERROR_MAP, x_lsa)


def principal(account):
    try:
        return accounts.principal(account)
    except exc.x_not_found:
        return "<unknown>"


class LogonSession(core._WinSysObject):

    _MAP = {
        "UserName": principal,
        "Sid": principal,
        "LogonTime": utils.from_pytime
Ejemplo n.º 21
0

class x_moniker_no_root(x_moniker):
    "Raised when a moniker has no Hive in the first or second position"


sep = "\\"

WINERROR_MAP = {
    winerror.ERROR_PATH_NOT_FOUND: exc.x_not_found,
    winerror.ERROR_FILE_NOT_FOUND: exc.x_not_found,
    winerror.ERROR_NO_MORE_ITEMS: StopIteration,
    winerror.ERROR_ACCESS_DENIED: exc.x_access_denied,
    winerror.ERROR_INVALID_HANDLE: exc.x_invalid_handle,
}
wrapped = exc.wrapper(WINERROR_MAP, x_registry)


def _parse_moniker(moniker, accept_value=True):
    r"""Take a registry moniker and return the computer, root key, subkey path and value label.
    NB: neither the computer nor the registry key need exist; they
    need simply to be of the right format. The slashes must be backslashes (since
    registry key names can contain forward slashes). accept_value is mostly used
    internally to indicate that a key search is going on, where a colon is to be
    considered part of the key name; if it is True, then the colon is to be
    considered a value separator.

    The moniker must be of the form:

        [\\computer\]HKEY[\subkey path][:value]
Ejemplo n.º 22
0
class x_active_directory(exc.x_winsys):
    "Base for all AD-related exceptions"


SEARCHPREF = constants.Constants.from_pattern(u"ADS_SEARCHPREF_*",
                                              namespace=adsicon)
SEARCHPREF.doc("Preferences for searching AD")
SCOPE = constants.Constants.from_pattern(u"ADS_SCOPE_*", namespace=adsicon)
SCOPE.doc("Scope for searching AD trees")

WINERROR_MAP = {
    adsicon.E_ADS_COLUMN_NOT_SET: exc.x_not_found,
    0x8000500D: AttributeError
}
wrapped = exc.wrapper(WINERROR_MAP, x_active_directory)

SEARCH_PREFERENCES = {
    SEARCHPREF.PAGESIZE: 1000,
    SEARCHPREF.SEARCH_SCOPE: SCOPE.SUBTREE,
}


class Result(dict):
    def __getattr__(self, attr):
        return self[attr]


ESCAPED_CHARACTERS = dict(
    (special, r"\%02x" % ord(special)) for special in "*()\x00/")
Ejemplo n.º 23
0
__all__ = ['Token', 'token', 'x_token', 'x_no_token']

class x_token(exc.x_winsys):
    "Base for all token-related exceptions"

class x_no_token(x_token):
    "Raised when a token cannot be retrieved"

PyHANDLE = pywintypes.HANDLEType

WINERROR_MAP = {
    winerror.ERROR_ACCESS_DENIED : exc.x_access_denied,
    winerror.ERROR_NO_TOKEN : x_no_token
}
wrapped = exc.wrapper(WINERROR_MAP, x_token)

def _from_sid_and_attribute(data):
    sid, attributes = data
    #
    # SDK says that no attributes are defined at present,
    # so ignore them!
    #
    return accounts.principal(sid)

def _from_sid_and_attributes(data):
    return [_from_sid_and_attribute(d) for d in data]

def _from_privileges(data):
    return [_privileges.Privilege(*d) for d in data]
Ejemplo n.º 24
0
# -*- coding: iso-8859-1 -*-
import win32api
import win32con
import win32file

import pywintypes
from winsys import constants, core, exc, utils


class x_handles(exc.x_winsys):
    pass


WINERROR_MAP = {}
wrapped = exc.wrapper(WINERROR_MAP, x_handles)


class Handle(core._WinSysObject):
    def __init__(self, handle):
        core._WinSysObject.__init__(self)
        self._handle = handle
        self.name = str(int(self._handle))

    def __int__(self):
        return int(self._handle)

    def pyobject(self):
        return self._handle

    def duplicate(self, process=None, inheritable=True):
        target_process = processes.process(process).hProcess
Ejemplo n.º 25
0
# -*- coding: iso-8859-1 -*-
import win32api
import win32con
import win32process

import pywintypes
from winsys import constants, core, exc, ipc, utils

class x_processes (exc.x_winsys):
  pass

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_processes)

class Process (core._WinSysObject):

  def __init__ (self, command, inherit_handles=True, flags=0, environment=None, current_directory=None, startupinfo=None):
    core._WinSysObject.__init__ (self)
    process_info = wrapped (
      win32process.CreateProcess,
      None,
      command,
      None,
      None,
      inherit_handles,
      flags,
      environment,
      current_directory,
      startupinfo
    )
Ejemplo n.º 26
0
UF.doc("Flags for creating new users")
SID_NAME_USE = constants.Constants.from_pattern("SidType*",
                                                namespace=ntsecuritycon)
SID_NAME_USE.doc("Types of accounts for which SIDs exist")
FILTER = constants.Constants.from_pattern("FILTER_*", namespace=win32netcon)
FILTER.doc("Filters when enumerating users")

PySID = pywintypes.SIDType


class x_accounts(exc.x_winsys):
    "Base for all accounts-related exceptions"


WINERROR_MAP = {winerror.ERROR_NONE_MAPPED: exc.x_not_found}
wrapped = exc.wrapper(WINERROR_MAP, x_accounts)


def _win32net_enum(win32_fn, system_or_domain):
    resume = 0
    while True:
        items, total, resume = wrapped(win32_fn, system_or_domain, 0, resume)
        for item in items:
            yield item
        if resume == 0: break


def principal(principal, cls=core.UNSET):
    """Factory function for the :class:`Principal` class. This is the most
    common way to create a :class:`Principal` object::
Ejemplo n.º 27
0
class x_moniker_ill_formed(x_moniker):
    "Raised when a moniker does not match the correct format"

class x_moniker_no_root(x_moniker):
    "Raised when a moniker has no Hive in the first or second position"

sep = "\\"

WINERROR_MAP = {
    winerror.ERROR_PATH_NOT_FOUND : exc.x_not_found,
    winerror.ERROR_FILE_NOT_FOUND : exc.x_not_found,
    winerror.ERROR_NO_MORE_ITEMS : StopIteration,
    winerror.ERROR_ACCESS_DENIED : exc.x_access_denied,
    winerror.ERROR_INVALID_HANDLE : exc.x_invalid_handle,
}
wrapped = exc.wrapper(WINERROR_MAP, x_registry)


def _parse_moniker(moniker, accept_value=True):
    r"""Take a registry moniker and return the computer, root key, subkey path and value label.
    NB: neither the computer nor the registry key need exist; they
    need simply to be of the right format. The slashes must be backslashes (since
    registry key names can contain forward slashes). accept_value is mostly used
    internally to indicate that a key search is going on, where a colon is to be
    considered part of the key name; if it is True, then the colon is to be
    considered a value separator.

    The moniker must be of the form:

        [\\computer\]HKEY[\subkey path][:value]
Ejemplo n.º 28
0
__all__ = ['PRIVILEGE_ATTRIBUTE', 'PRIVILEGE', 'Privilege', 'privilege', 'x_privilege', 'x_privilege_no_token']

PRIVILEGE_ATTRIBUTE = constants.Constants.from_pattern("SE_PRIVILEGE_*", namespace=win32security)
PRIVILEGE = constants.Constants.from_pattern("SE_*_NAME", namespace=win32security)
PRIVILEGE.doc("Privileges granted through a user's token")

class x_privilege(exc.x_winsys):
    "Base for all privilege-related exceptions"

class x_privilege_no_token(x_privilege):
    "Raised when a token cannot be found"

WINERROR_MAP = {
    winerror.ERROR_NO_TOKEN : x_privilege_no_token
}
wrapped = exc.wrapper(WINERROR_MAP, x_privilege)

#
# Convenience implementation functions
#
def _get_token():
    try:
        return wrapped(
            win32security.OpenThreadToken,
            wrapped(win32api.GetCurrentThread),
            constants.GENERAL.MAXIMUM_ALLOWED,
            True
        )
    except x_privilege_no_token:
        return wrapped(
            win32security.OpenProcessToken,
Ejemplo n.º 29
0
BIF.doc ("Styles for browsing for a folder")
BFFM = constants.Constants.from_pattern (u"BFFM_*", namespace=shellcon)
BFFM.doc ("Part of the browse-for-folder shell mechanism")

CREDUI_FLAGS = constants.Constants.from_pattern (u"CREDUI_FLAGS_*", namespace=win32cred)
CREDUI_FLAGS.doc ("Options for username prompt UI")
CRED_FLAGS = constants.Constants.from_pattern (u"CRED_FLAGS_*", namespace=win32cred)
CRED_TYPE = constants.Constants.from_pattern (u"CRED_TYPE_*", namespace=win32cred)
CRED_TI = constants.Constants.from_pattern (u"CRED_TI_*", namespace=win32cred)

class x_dialogs (exc.x_winsys):
  "Base for dialog-related exceptions"

WINERROR_MAP = {
}
wrapped = exc.wrapper (WINERROR_MAP, x_dialogs)

DESKTOP = wrapped (win32gui.GetDesktopWindow)

ENCODING = "UTF-8"

class _DropTarget (win32com.server.policy.DesignatedWrapPolicy):
  ur"""Helper class to implement the IDropTarget interface so that
  files can be drag-dropped onto a text field in a dialog.
  """
  _reg_clsid_ = '{72AA1C07-73BA-4CA8-88B9-7F03FEA173E8}'
  _reg_progid_ = "WinSysDialogs.DropTarget"
  _reg_desc_ = "Drop target handler for WinSys Dialogs"
  _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']
  _com_interfaces_ = [pythoncom.IID_IDropTarget]
Ejemplo n.º 30
0
"""
from __future__ import unicode_literals

import pywintypes
import winerror
import win32event
import win32file

from winsys import constants, core, exc, ipc, utils

class x_asyncio(exc.x_winsys):
    pass

WINERROR_MAP = {
}
wrapped = exc.wrapper(WINERROR_MAP, x_asyncio)

class AsyncIO(core._WinSysObject):

    def __init__(self):
        core._WinSysObject.__init__(self)
        self.event = ipc.event(needs_manual_reset=True)
        self.overlapped = wrapped(win32file.OVERLAPPED)
        self.overlapped.hEvent = self.event.pyobject()

    def pyobject(self):
        """Return the pyobject of the underlying event so that this object can
        be waited on by the :func:`ipc.all` or :func:`ipc.any` functions
        """
        return self.event.pyobject()
Ejemplo n.º 31
0
__all__ = ['x_acl', 'ACL', 'DACL', 'SACL', 'acl', 'dacl', 'sacl']

PyACL = pywintypes.ACLType


class x_acl(exc.x_winsys):
    "Base for all ACL-related exceptions"


class x_value_not_set(x_acl):
    "Raised when iterating over an ACL which has not been set"


WINERROR_MAP = {}
wrapped = exc.wrapper(WINERROR_MAP, x_acl)


class ACL(core._WinSysObject):
    """An ACL maps the Windows security ACL concept, but behaves like
  a Python list. You can append to it, iterate over it, delete from
  it, check its length and test it for membership. A special case is
  made for the so-called NULL ACL. This is different from an empty
  ACL (which is effectively completely restrictive). A NULL ACL is
  completely unrestrictive. This is mapped by holding None and treating
  this specially where needed.
  
  DACL & SACL subclasses are defined to cope with the slightly different
  ways in which the structures are manipulated, but the core functionality
  is in this base class. This class need rarely be instantiated directly;
  normally it will be invoked by the Security class which is accessor