wmi-1.3.16 from opsview.com

This commit is contained in:
Are Casilla
2019-02-16 00:16:52 +01:00
parent 163fdd3d1b
commit 17b3af2911
2146 changed files with 678824 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
+69
View File
@@ -0,0 +1,69 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from pysamba.library import *
from pysamba.rpc.credentials import CRED_SPECIFIED
import logging
log = logging.getLogger('p.composite_context')
( COMPOSITE_STATE_INIT, COMPOSITE_STATE_IN_PROGRESS,
COMPOSITE_STATE_DONE, COMPOSITE_STATE_ERROR ) = range(4)
class composite_context(Structure): pass
composite_context_callback = CFUNCTYPE(None, POINTER(composite_context))
class async(Structure):
_fields_ = [
('fn', composite_context_callback),
('private_data', c_void_p),
]
composite_context._fields_ = [
('state', enum),
('private_data', c_void_p),
('status', NTSTATUS),
('event_ctx', c_void_p), # struct event_context *
('async', async),
('used_wait', BOOL),
]
# _PUBLIC_ struct composite_context *composite_create(TALLOC_CTX *mem_ctx,
# struct event_context *ev);
library.composite_create.restype = POINTER(composite_context)
library.composite_create.argtypes = [c_void_p, c_void_p]
library.composite_create = logFuncCall(library.composite_create)
def composite_create(memctx, eventContext):
result = library.composite_create(memctx, eventContext)
if not result:
raise RuntimeError("Unable to allocate a composite_context")
return result
# _PUBLIC_ BOOL composite_nomem(const void *p, struct composite_context *ctx);
library.composite_nomem.restype = BOOL
library.composite_nomem.argtypes = [c_void_p, POINTER(composite_context)]
library.composite_nomem = logFuncCall(library.composite_nomem)
library.composite_wait.restype = NTSTATUS
library.composite_wait.argtypes = [POINTER(composite_context)]
library.composite_wait = logFuncCall(library.composite_wait)
library.composite_is_ok.restype = BOOL
library.composite_is_ok.argtypes = [POINTER(composite_context)]
library.composite_is_ok = logFuncCall(library.composite_is_ok)
library.composite_error.restype = None
library.composite_error.argtypes = [POINTER(composite_context), NTSTATUS]
library.composite_error = logFuncCall(library.composite_error)
library.composite_done.restype = None
library.composite_done.argtypes = [POINTER(composite_context)]
library.composite_done = logFuncCall(library.composite_done)
+442
View File
@@ -0,0 +1,442 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__ = "Provide basic access to the Samba library"
import os
import sys
from ctypes import *
from ctypes.util import find_library
import logging
logging.basicConfig()
log = logging.getLogger('zen.pysamba')
def samba_find_library(library_name):
# normal look-up
import glob
library_location = find_library(library_name)
# go hunting for it
if not library_location:
# along the elements of the dynamic library load path
path = os.environ.get('LD_LIBRARY_PATH', '')
for directory in path.split(":") + sys.path:
# with various endings, depending on platform
for prefix in 'lib','':
for ending in ".so", ".dylib":
pattern = os.path.join(directory,
prefix + library_name + ending) + '*'
for filename in sorted(glob.glob(pattern)):
return filename
if "DEBUG_LIB" in os.environ:
library = CDLL(os.environ["DEBUG_LIB"])
else:
library = CDLL(samba_find_library('async_wmi_lib'))
if not library:
raise ImportError("Unable to load initial pysamba library")
DEBUGLEVEL = c_int.in_dll(library, 'DEBUGLEVEL')
DEBUG_LOGGING = ("PYSAMBA_DEBUG" in os.environ)
if DEBUG_LOGGING:
internalLog = logging.getLogger('zen.pysamba.internal')
DEBUGLEVEL.value = 9
def logFuncCall(f):
def wrapper(*args, **kw):
retstat = "FAIL"
try:
internalLog.debug("called %s" % f.__name__)
res = f(*args, **kw)
retstat = "PASS"
return res
finally:
internalLog.debug("leaving %s (%s)" % (f.__name__, retstat))
return wrapper
else:
# define do-nothing decorator
logFuncCall = lambda f : f
DEBUGLEVEL.value = 0
# definitions common to most samba structures
enum = c_uint
BOOL = c_int
class NTSTATUS(Structure):
_fields_ = [
('v', c_uint)
]
class WERROR(Structure):
_fields_ = [
('v', c_uint)
]
if sizeof(c_uint32) == sizeof(c_void_p):
size_t = c_uint32
else:
size_t = c_uint64
int64_t = c_int64
uint64_t = c_uint64
uint32_t = c_uint32
int32_t = c_int32
uint8_t = c_uint8
int8_t = c_int8
uint16_t = c_uint16
int16_t = c_int16
#const char *nt_errstr(NTSTATUS nt_code);
library.nt_errstr.restype = c_char_p
library.nt_errstr.argtypes = [NTSTATUS]
library.nt_errstr = logFuncCall(library.nt_errstr)
#const char *win_errstr(WERROR werror);
library.win_errstr.restype = c_char_p
library.win_errstr.argtypes = [WERROR]
library.win_errstr = logFuncCall(library.win_errstr)
#NTSTATUS dcerpc_init(void);
library.dcerpc_init.restype = NTSTATUS
library.dcerpc_init.argtypes = []
library.dcerpc_init = logFuncCall(library.dcerpc_init)
#NTSTATUS dcerpc_table_init(void);
library.dcerpc_table_init.restype = NTSTATUS
library.dcerpc_table_init.argtypes = []
library.dcerpc_table_init = logFuncCall(library.dcerpc_table_init)
library.cli_credentials_init.restype = c_void_p
library.cli_credentials_init.argtypes = [c_void_p]
library.cli_credentials_init = logFuncCall(library.cli_credentials_init)
library.cli_credentials_set_conf.restype = None
library.cli_credentials_set_conf.argtypes = [c_void_p]
library.cli_credentials_set_conf = logFuncCall(library.cli_credentials_set_conf)
library.cli_credentials_parse_string.restype = None
library.cli_credentials_parse_string.argtypes = [c_void_p, c_void_p, enum]
library.cli_credentials_parse_string = logFuncCall(library.cli_credentials_parse_string)
library._talloc.restype = c_void_p
library._talloc.argtypes = [c_void_p, c_size_t]
library._talloc = logFuncCall(library._talloc)
library.talloc_increase_ref_count.restype = c_int
library.talloc_increase_ref_count.argtypes = [c_void_p]
library.talloc_increase_ref_count = logFuncCall(library.talloc_increase_ref_count)
library.talloc_reference_count.restype = c_size_t
library.talloc_reference_count.argtypes = [c_void_p]
library.talloc_reference_count = logFuncCall(library.talloc_reference_count)
library._talloc_reference.restype = c_void_p
library._talloc_reference.argtypes = [c_void_p, c_void_p]
library._talloc_reference = logFuncCall(library._talloc_reference)
library.talloc_unlink.restype = c_int
library.talloc_unlink.argtypes = [c_void_p, c_void_p]
library.talloc_unlink = logFuncCall(library.talloc_unlink)
library.talloc_set_name_const.restype = None
library.talloc_set_name_const.argtypes = [c_void_p, c_char_p]
library.talloc_set_name_const = logFuncCall(library.talloc_set_name_const)
library.talloc_named_const.restype = c_void_p
library.talloc_named_const.argtypes = [c_void_p, c_size_t, c_char_p]
library.talloc_named_const = logFuncCall(library.talloc_named_const)
library.talloc_get_name.restype = c_char_p
library.talloc_get_name.argtypes = [c_void_p]
library.talloc_get_name = logFuncCall(library.talloc_get_name)
library.talloc_check_name.restype = c_void_p
library.talloc_check_name.argtypes = [c_void_p, c_char_p]
library.talloc_check_name = logFuncCall(library.talloc_check_name)
library.talloc_parent.restype = c_void_p
library.talloc_parent.argtypes = [c_void_p]
library.talloc_parent = logFuncCall(library.talloc_parent)
library.talloc_free.restype = c_int
library.talloc_free.argtypes = [c_void_p]
library.talloc_free = logFuncCall(library.talloc_free)
library.talloc_free_children.restype = None
library.talloc_free_children.argtypes = [c_void_p]
library.talloc_free_children = logFuncCall(library.talloc_free_children)
library._talloc_realloc.restype = c_void_p
library._talloc_realloc.argtypes = [c_void_p, c_void_p, c_size_t, c_char_p]
library._talloc_realloc = logFuncCall(library._talloc_realloc)
library._talloc_steal.restype = c_void_p
library._talloc_steal.argtypes = [c_void_p, c_void_p]
library._talloc_steal = logFuncCall(library._talloc_steal)
library._talloc_move.restype = c_void_p
library._talloc_move.argtypes = [c_void_p, c_void_p]
library._talloc_move = logFuncCall(library._talloc_move)
library.talloc_total_size.restype = c_size_t
library.talloc_total_size.argtypes = [c_void_p]
library.talloc_total_size = logFuncCall(library.talloc_total_size)
library.talloc_total_blocks.restype = c_size_t
library.talloc_total_blocks.argtypes = [c_void_p]
library.talloc_total_blocks = logFuncCall(library.talloc_total_blocks)
library.talloc_report_depth_file.restype = None
library.talloc_report_depth_file.argtypes = [c_void_p, c_int, c_int, c_void_p]
library.talloc_report_depth_file = logFuncCall(library.talloc_report_depth_file)
library.talloc_report_full.restype = None
library.talloc_report_full.argtypes = [c_void_p, c_void_p]
library.talloc_report_full = logFuncCall(library.talloc_report_full)
library.talloc_report.restype = None
library.talloc_report.argtypes = [c_void_p, c_void_p]
library.talloc_report = logFuncCall(library.talloc_report)
library.talloc_enable_null_tracking.restype = None
library.talloc_enable_null_tracking.argtypes = []
library.talloc_enable_null_tracking = logFuncCall(library.talloc_enable_null_tracking)
library.talloc_disable_null_tracking.restype = None
library.talloc_disable_null_tracking.argtypes = []
library.talloc_disable_null_tracking = logFuncCall(library.talloc_disable_null_tracking)
library.talloc_enable_leak_report.restype = None
library.talloc_enable_leak_report.argtypes = []
library.talloc_enable_leak_report = logFuncCall(library.talloc_enable_leak_report)
library.talloc_enable_leak_report_full.restype = None
library.talloc_enable_leak_report_full.argtypes = []
library.talloc_enable_leak_report_full = logFuncCall(library.talloc_enable_leak_report_full)
library._talloc_zero.restype = c_void_p
library._talloc_zero.argtypes = [c_void_p, c_size_t, c_char_p]
library._talloc_zero = logFuncCall(library._talloc_zero)
library._talloc_memdup.restype = c_void_p
library._talloc_memdup.argtypes = [c_void_p, c_void_p, c_size_t, c_char_p]
library._talloc_memdup = logFuncCall(library._talloc_memdup)
library.talloc_strdup.restype = c_char_p
library.talloc_strdup.argtypes = [c_void_p, c_char_p]
library.talloc_strdup = logFuncCall(library.talloc_strdup)
library.talloc_strndup.restype = c_char_p
library.talloc_strndup.argtypes = [c_void_p, c_char_p, c_size_t]
library.talloc_strndup = logFuncCall(library.talloc_strndup)
library.talloc_append_string.restype = c_char_p
library.talloc_append_string.argtypes = [c_void_p, c_char_p, c_char_p]
library.talloc_append_string = logFuncCall(library.talloc_append_string)
library._talloc_array.restype = c_void_p
library._talloc_array.argtypes = [c_void_p, c_size_t, c_uint, c_char_p]
library._talloc_array = logFuncCall(library._talloc_array)
library._talloc_zero_array.restype = c_void_p
library._talloc_zero_array.argtypes = [c_void_p, c_size_t, c_uint, c_char_p]
library._talloc_zero_array = logFuncCall(library._talloc_zero_array)
library._talloc_realloc_array.restype = c_void_p
library._talloc_realloc_array.argtypes = [c_void_p, c_void_p, c_size_t, c_uint, c_char_p]
library._talloc_realloc_array = logFuncCall(library._talloc_realloc_array)
library.talloc_realloc_fn.restype = c_void_p
library.talloc_realloc_fn.argtypes = [c_void_p, c_void_p, c_size_t]
library.talloc_realloc_fn = logFuncCall(library.talloc_realloc_fn)
library.talloc_autofree_context.restype = c_void_p
library.talloc_autofree_context.argtypes = []
library.talloc_autofree_context = logFuncCall(library.talloc_autofree_context)
library.talloc_get_size.restype = c_size_t
library.talloc_get_size.argtypes = [c_void_p]
library.talloc_get_size = logFuncCall(library.talloc_get_size)
library.strlen_m_term.restype = c_size_t
library.strlen_m_term.argtypes = [c_char_p]
library.strlen_m_term = logFuncCall(library.strlen_m_term)
library.talloc_find_parent_byname.restype = c_void_p
library.talloc_find_parent_byname.argtypes = [c_void_p, c_char_p]
library.talloc_find_parent_byname = logFuncCall(library.talloc_find_parent_byname)
library.talloc_show_parents.restype = None
library.talloc_show_parents.argtypes = [c_void_p, c_void_p]
library.talloc_show_parents = logFuncCall(library.talloc_show_parents)
library.talloc_is_parent.restype = c_int
library.talloc_is_parent.argtypes = [c_void_p, c_void_p]
library.talloc_is_parent = logFuncCall(library.talloc_is_parent)
class event_context(Structure): pass
library.watch_fd_callback = CFUNCTYPE(c_int, c_int, c_uint16)
library.loop_callback = CFUNCTYPE(c_int)
class reactor_functions(Structure):
_fields_ = [
('fd_callback', library.watch_fd_callback),
('loop_callback', library.loop_callback)
]
#struct event_context* async_create_context(struct reactor_functions *funcs)
library.async_create_context.restype = POINTER(event_context)
library.async_create_context.argtypes = [POINTER(reactor_functions)]
library.async_create_context = logFuncCall(library.async_create_context)
def W_ERROR_IS_OK(err):
return err.v == 0
class WError(Exception):
def __init__(self, werror, deviceId, action):
# error code from samba/windows
self.werror = werror
# what device was this for?
self.deviceId = deviceId
# what were we doing at the time?
self._action = action
def __str__(self):
return '%s on %s (%s)' % (self._action, self.deviceId, self.why())
def action(self):
return self._action
def why(self):
return DCOM_ERROR_CONSTANTS.get(self.werror.v,
library.win_errstr(self.werror))
def WERR_CHECK(result, deviceId, action):
if not W_ERROR_IS_OK(result):
log.debug("ERROR: %s - %s", deviceId, action)
raise WError(result, deviceId, action)
log.debug("OK: %s - %s", deviceId, action)
def W_ERROR_EQUAL(a, b):
return a.v == b
DCOM_ERROR_CONSTANTS = {
1726:'RPC_S_CALL_FAILED',
0:'WBEM_NO_ERROR',
0x40001:'WBEM_S_ALREADY_EXISTS',
0x40002:'WBEM_S_RESET_TO_DEFAULT',
0x40003:'WBEM_S_DIFFERENT',
0x40004:'WBEM_S_TIMEDOUT',
0x40005:'WBEM_S_NO_MORE_DATA',
0x40006:'WBEM_S_OPERATION_CANCELLED',
0x40007:'WBEM_S_PENDING',
0x40008:'WBEM_S_DUPLICATE_OBJECTS',
0x40009:'WBEM_S_ACCESS_DENIED',
0x40010:'WBEM_S_PARTIAL_RESULTS',
0x40011:'WBEM_S_NO_POSTHOOK',
0x40012:'WBEM_S_POSTHOOK_WITH_BOTH',
0x40013:'WBEM_S_POSTHOOK_WITH_NEW',
0x40014:'WBEM_S_POSTHOOK_WITH_STATUS',
0x40015:'WBEM_S_POSTHOOK_WITH_OLD',
0x40016:'WBEM_S_REDO_PREHOOK_WITH_ORIGINAL_OBJECT',
0x40017:'WBEM_S_SOURCE_NOT_AVAILABLE',
0x80041001:'WBEM_E_FAILED',
0x80041002:'WBEM_E_NOT_FOUND',
0x80041003:'WBEM_E_ACCESS_DENIED',
0x80041004:'WBEM_E_PROVIDER_FAILURE',
0x80041005:'WBEM_E_TYPE_MISMATCH',
0x80041006:'WBEM_E_OUT_OF_MEMORY',
0x80041007:'WBEM_E_INVALID_CONTEXT',
0x80041008:'WBEM_E_INVALID_PARAMETER',
0x80041009:'WBEM_E_NOT_AVAILABLE',
0x8004100A:'WBEM_E_CRITICAL_ERROR',
0x8004100B:'WBEM_E_INVALID_STREAM',
0x8004100C:'WBEM_E_NOT_SUPPORTED',
0x8004100D:'WBEM_E_INVALID_SUPERCLASS',
0x8004100E:'WBEM_E_INVALID_NAMESPACE',
0x8004100F:'WBEM_E_INVALID_OBJECT',
0x80041010:'WBEM_E_INVALID_CLASS',
0x80041011:'WBEM_E_PROVIDER_NOT_FOUND',
0x80041012:'WBEM_E_INVALID_PROVIDER_REGISTRATION',
0x80041013:'WBEM_E_PROVIDER_LOAD_FAILURE',
0x80041014:'WBEM_E_INITIALIZATION_FAILURE',
0x80041015:'WBEM_E_TRANSPORT_FAILURE',
0x80041016:'WBEM_E_INVALID_OPERATION',
0x80041017:'WBEM_E_INVALID_QUERY',
0x80041018:'WBEM_E_INVALID_QUERY_TYPE',
0x80041019:'WBEM_E_ALREADY_EXISTS',
0x8004101A:'WBEM_E_OVERRIDE_NOT_ALLOWED',
0x8004101B:'WBEM_E_PROPAGATED_QUALIFIER',
0x8004101C:'WBEM_E_PROPAGATED_PROPERTY',
0x8004101D:'WBEM_E_UNEXPECTED',
0x8004101E:'WBEM_E_ILLEGAL_OPERATION',
0x8004101F:'WBEM_E_CANNOT_BE_KEY',
0x80041020:'WBEM_E_INCOMPLETE_CLASS',
0x80041021:'WBEM_E_INVALID_SYNTAX',
0x80041022:'WBEM_E_NONDECORATED_OBJECT',
0x80041023:'WBEM_E_READ_ONLY',
0x80041024:'WBEM_E_PROVIDER_NOT_CAPABLE',
0x80041025:'WBEM_E_CLASS_HAS_CHILDREN',
0x80041026:'WBEM_E_CLASS_HAS_INSTANCES',
0x80041027:'WBEM_E_QUERY_NOT_IMPLEMENTED',
0x80041028:'WBEM_E_ILLEGAL_NULL',
0x80041029:'WBEM_E_INVALID_QUALIFIER_TYPE',
0x8004102A:'WBEM_E_INVALID_PROPERTY_TYPE',
0x8004102B:'WBEM_E_VALUE_OUT_OF_RANGE',
0x8004102C:'WBEM_E_CANNOT_BE_SINGLETON',
0x8004102D:'WBEM_E_INVALID_CIM_TYPE',
0x8004102E:'WBEM_E_INVALID_METHOD',
0x8004102F:'WBEM_E_INVALID_METHOD_PARAMETERS',
0x80041030:'WBEM_E_SYSTEM_PROPERTY',
0x80041031:'WBEM_E_INVALID_PROPERTY',
0x80041032:'WBEM_E_CALL_CANCELLED',
0x80041033:'WBEM_E_SHUTTING_DOWN',
0x80041034:'WBEM_E_PROPAGATED_METHOD',
0x80041035:'WBEM_E_UNSUPPORTED_PARAMETER',
0x80041036:'WBEM_E_MISSING_PARAMETER_ID',
0x80041037:'WBEM_E_INVALID_PARAMETER_ID',
0x80041038:'WBEM_E_NONCONSECUTIVE_PARAMETER_IDS',
0x80041039:'WBEM_E_PARAMETER_ID_ON_RETVAL',
0x8004103A:'WBEM_E_INVALID_OBJECT_PATH',
0x8004103B:'WBEM_E_OUT_OF_DISK_SPACE',
0x8004103C:'WBEM_E_BUFFER_TOO_SMALL',
0x8004103D:'WBEM_E_UNSUPPORTED_PUT_EXTENSION',
0x8004103E:'WBEM_E_UNKNOWN_OBJECT_TYPE',
0x8004103F:'WBEM_E_UNKNOWN_PACKET_TYPE',
0x80041040:'WBEM_E_MARSHAL_VERSION_MISMATCH',
0x80041041:'WBEM_E_MARSHAL_INVALID_SIGNATURE',
0x80041042:'WBEM_E_INVALID_QUALIFIER',
0x80041043:'WBEM_E_INVALID_DUPLICATE_PARAMETER',
0x80041044:'WBEM_E_TOO_MUCH_DATA',
0x80041045:'WBEM_E_SERVER_TOO_BUSY',
0x80041046:'WBEM_E_INVALID_FLAVOR',
0x80041047:'WBEM_E_CIRCULAR_REFERENCE',
0x80041048:'WBEM_E_UNSUPPORTED_CLASS_UPDATE',
0x80041049:'WBEM_E_CANNOT_CHANGE_KEY_INHERITANCE',
0x80041050:'WBEM_E_CANNOT_CHANGE_INDEX_INHERITANCE',
0x80041051:'WBEM_E_TOO_MANY_PROPERTIES',
0x80041052:'WBEM_E_UPDATE_TYPE_MISMATCH',
0x80041053:'WBEM_E_UPDATE_OVERRIDE_NOT_ALLOWED',
0x80041054:'WBEM_E_UPDATE_PROPAGATED_METHOD',
0x80041055:'WBEM_E_METHOD_NOT_IMPLEMENTED',
0x80041056:'WBEM_E_METHOD_DISABLED',
0x80041057:'WBEM_E_REFRESHER_BUSY',
0x80041058:'WBEM_E_UNPARSABLE_QUERY',
0x80041059:'WBEM_E_NOT_EVENT_CLASS',
0x8004105A:'WBEM_E_MISSING_GROUP_WITHIN',
0x8004105B:'WBEM_E_MISSING_AGGREGATION_LIST',
0x8004105C:'WBEM_E_PROPERTY_NOT_AN_OBJECT',
0x8004105D:'WBEM_E_AGGREGATING_BY_OBJECT',
0x8004105F:'WBEM_E_UNINTERPRETABLE_PROVIDER_QUERY',
0x80041060:'WBEM_E_BACKUP_RESTORE_WINMGMT_RUNNING',
0x80041061:'WBEM_E_QUEUE_OVERFLOW',
0x80041062:'WBEM_E_PRIVILEGE_NOT_HELD',
0x80041063:'WBEM_E_INVALID_OPERATOR',
0x80041064:'WBEM_E_LOCAL_CREDENTIALS',
0x80041065:'WBEM_E_CANNOT_BE_ABSTRACT',
0x80041066:'WBEM_E_AMENDED_OBJECT',
0x80041067:'WBEM_E_CLIENT_TOO_SLOW',
0x80041068:'WBEM_E_NULL_SECURITY_DESCRIPTOR',
0x80041069:'WBEM_E_TIMED_OUT',
0x8004106A:'WBEM_E_INVALID_ASSOCIATION',
0x8004106B:'WBEM_E_AMBIGUOUS_OPERATION',
0x8004106C:'WBEM_E_QUOTA_VIOLATION',
0x8004106D:'WBEM_E_RESERVED_001',
0x8004106E:'WBEM_E_RESERVED_002',
0x8004106F:'WBEM_E_UNSUPPORTED_LOCALE',
0x80041070:'WBEM_E_HANDLE_OUT_OF_DATE',
0x80041071:'WBEM_E_CONNECTION_FAILED',
0x80041072:'WBEM_E_INVALID_HANDLE_REQUEST',
0x80041073:'WBEM_E_PROPERTY_NAME_TOO_WIDE',
0x80041074:'WBEM_E_CLASS_NAME_TOO_WIDE',
0x80041075:'WBEM_E_METHOD_NAME_TOO_WIDE',
0x80041076:'WBEM_E_QUALIFIER_NAME_TOO_WIDE',
0x80041077:'WBEM_E_RERUN_COMMAND',
0x80041078:'WBEM_E_DATABASE_VER_MISMATCH',
0x80041079:'WBEM_E_VETO_DELETE',
0x8004107A:'WBEM_E_VETO_PUT',
0x80041080:'WBEM_E_INVALID_LOCALE',
0x80041081:'WBEM_E_PROVIDER_SUSPENDED',
0x80041082:'WBEM_E_SYNCHRONIZATION_REQUIRED',
0x80041083:'WBEM_E_NO_SCHEMA',
0x80041084:'WBEM_E_PROVIDER_ALREADY_REGISTERED',
0x80041085:'WBEM_E_PROVIDER_NOT_REGISTERED',
0x80041086:'WBEM_E_FATAL_TRANSPORT_ERROR',
0x80041087:'WBEM_E_ENCRYPTED_CONNECTION_REQUIRED',
0x80041088:'WBEM_E_PROVIDER_TIMED_OUT',
0x80041089:'WBEM_E_NO_KEY',
0x8004108a:'WBEM_E_PROVIDER_DISABLED',
# not dcom, but frequently seen
0x000006be: 'OPERATION_COULD_NOT_BE_COMPLETED',
}
+21
View File
@@ -0,0 +1,21 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__ = "Provide access to generic NDR routines"
from pysamba.library import library
NDR_OUT = 2
def debugPrint(text, printFunct, obj):
"Print an NDR structure to debug output"
library.ndr_print_function_debug(printFunct, text, NDR_OUT, obj)
+176
View File
@@ -0,0 +1,176 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__="""
Define a simple API for performing a sequence of RPC calls to a
single host in an asynchronous fashion
"""
from pysamba.twisted.reactor import eventContext
from pysamba.library import library, logFuncCall
from pysamba.twisted.callback import Callback
from pysamba.composite_context import *
from pysamba.talloc import *
from pysamba.rpc.rpc_request import rpc_request
class dcerpc_pipe(Structure): pass
class dcerpc_interface_table(Structure): pass
# struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
# const char *binding,
# const struct dcerpc_interface_table *table,
# struct cli_credentials *credentials,
# struct event_context *ev);
library.dcerpc_pipe_connect_send.restype = POINTER(composite_context)
library.dcerpc_pipe_connect_send.argtypes = [c_void_p, c_char_p, c_void_p, c_void_p, c_void_p]
library.dcerpc_pipe_connect_send = logFuncCall(library.dcerpc_pipe_connect_send)
# NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
# TALLOC_CTX *mem_ctx,
# struct dcerpc_pipe **pp);
library.dcerpc_pipe_connect_recv.restype = NTSTATUS
library.dcerpc_pipe_connect_recv.argtypes = [POINTER(composite_context), c_void_p, c_void_p]
library.dcerpc_pipe_connect_recv = logFuncCall(library.dcerpc_pipe_connect_recv)
# _PUBLIC_ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req);
library.dcerpc_ndr_request_recv.restype = NTSTATUS
library.dcerpc_ndr_request_recv.argtypes = [c_void_p]
library.dcerpc_ndr_request_recv = logFuncCall(library.dcerpc_ndr_request_recv)
#_PUBLIC_ void composite_continue_rpc(struct composite_context *ctx,
# struct rpc_request *new_req,
# void (*continuation)(struct rpc_request *),
# void *private_data)
library.composite_continue_rpc.restype = None
library.composite_continue_rpc.argtypes = [POINTER(composite_context),
POINTER(rpc_request), c_void_p, c_void_p]
library.composite_continue_rpc = logFuncCall(library.composite_continue_rpc)
#
# Continue the RPC connect after a successful socket open to the server by
# receiving the results.
#
@logFuncCall
def rpc_connect_continue(ctx):
c = talloc_get_type(ctx.contents.async.private_data, composite_context)
if not library.composite_is_ok(c):
return
# complete the pipe connect and receive a pointer to the
# dcerpc_pipe structure
pipe = POINTER(dcerpc_pipe)()
import time
c.contents.status = library.dcerpc_pipe_connect_recv(ctx, c, byref(pipe));
c.contents.async.private_data = cast(pipe, c_void_p)
if not library.composite_is_ok(c):
return
library.composite_done(c)
continue_callback = CFUNCTYPE(None, POINTER(composite_context))
rpc_connect_continue = continue_callback(rpc_connect_continue)
#
# Open an RPC connection to the specified server
#
@logFuncCall
def async_rpc_open(event_ctx, server, cred, binding, arg, callback):
# create a composite context for this sequence of asynchronous calls
c = composite_create(None, event_ctx)
c.contents.async.fn = callback
c.contents.async.private_data = None
# build a binding string using the only protocol we care about...
binding = library.talloc_strdup(c, "%s:%s" % (binding, server))
# create a set of credentials
creds = library.cli_credentials_init(c)
if library.composite_nomem(creds, c):
return c
library.cli_credentials_set_conf(creds);
if cred:
library.cli_credentials_parse_string(creds, cred, CRED_SPECIFIED);
# issue the asynchronous rpc pipe connect request
rpc_ctx = library.dcerpc_pipe_connect_send(c,
binding,
arg,
creds,
event_ctx)
if library.composite_nomem(rpc_ctx, c):
return c
# setup the next stage of the connect process
library.composite_continue(c, rpc_ctx, rpc_connect_continue, c)
return c
# Fetch the return result after an RPC call completes
@logFuncCall
def continue_rpc(rpc_ctx):
c = talloc_get_type(rpc_ctx.contents.async.private, composite_context)
c.contents.async.private_data = rpc_ctx.contents.ndr.struct_ptr
c.contents.status = library.dcerpc_ndr_request_recv(rpc_ctx)
if not library.composite_is_ok(c):
return
library.composite_done(c)
continue_rpc_callback = CFUNCTYPE(None, POINTER(rpc_request))
continue_rpc = continue_rpc_callback(continue_rpc)
class Rpc(object):
def __init__(self):
self.ctx = self.rpc_pipe = None
def __del__(self):
self.close()
def close(self):
if self.ctx:
talloc_free(self.ctx)
self.ctx = self.rpc_pipe = None
def connect(self, host, credentials, object, binding='ncacn_np'):
table = dcerpc_interface_table.in_dll(library, 'dcerpc_table_' + object)
cb = Callback()
ctx = async_rpc_open(eventContext,
host,
credentials,
binding,
byref(table),
cb.callback)
cb.deferred.addCallback(self._store_rpc_pipe, ctx)
cb.deferred.addErrback(self._errback_cleanup, ctx)
return cb.deferred
def _errback_cleanup(self, result, ctx):
talloc_free(ctx)
return result
def _store_rpc_pipe(self, rpc_pipe, ctx):
self.ctx = ctx
self.rpc_pipe = rpc_pipe
return rpc_pipe
# ctx is the memory context to use to make the call, if not the one that
# started the original open call
@logFuncCall
def call(self, send_func, arg, ctx = None):
cb = Callback()
if ctx is None:
ctx = self.ctx
ctx.contents.async.fn = cb.callback
ctx.contents.async.private_data = None
rpc_ctx = cast(send_func(self.rpc_pipe, ctx, arg), POINTER(rpc_request))
if library.composite_nomem(rpc_ctx, ctx):
return
library.composite_continue_rpc(ctx, rpc_ctx, continue_rpc, ctx)
return cb.deferred
+13
View File
@@ -0,0 +1,13 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
+21
View File
@@ -0,0 +1,21 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__ = "Define constants needed for the cli_credentials structure"
( CRED_UNINITIALISED,
CRED_GUESS_ENV,
CRED_CALLBACK,
CRED_GUESS_FILE,
CRED_CALLBACK_RESULT,
CRED_SPECIFIED ) = range(6)
+50
View File
@@ -0,0 +1,50 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__ = "Define common structures used to perform DCE-RPC calls"
from pysamba.library import *
class GUID(Structure):
_fields_ = [
('time_low', uint32_t),
('time_mid', uint16_t),
('time_hi_and_version', uint16_t),
('clock_seq', uint8_t*2),
('node', uint8_t*6),
]
class policy_handle(Structure):
_fields_ = [
('handle_type', uint32_t),
('uuid', GUID),
]
class dcerpc_syntax_id(Structure):
_fields_ = [
('uuid', GUID),
('if_version', uint32_t),
]
class dcerpc_pipe(Structure):
_fields_ = [
('context_id', uint32_t),
('syntax', dcerpc_syntax_id),
('transfer_syntax', dcerpc_syntax_id),
('conn', c_void_p), # lie: struct dcerpc_connection *
('binding', c_void_p), # lie: struct dcerpc_binding *
('last_fault_code', uint32_t),
('request_timeout', uint32_t),
]
+46
View File
@@ -0,0 +1,46 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__="Define structure for the ServerAlive2 RPC call"
from pysamba.library import *
class COMVERSION(Structure):
_fields_ = [
('MajorVersion', uint16_t),
('MinorVersion', uint16_t),
]
class COMINFO(Structure):
_fields_ = [
('version', COMVERSION),
('unknown1', uint32_t),
]
class DUALSTRINGARRAY(Structure):
_fields_ = [
('stringbindings', c_void_p), # POINTER(POINTER(STRINGBINDING))),
('securitybindings', c_void_p), # POINTER(PIONTER(SECURITYBINDING))),
]
uint_t = c_uint
class ServerAlive2_out(Structure):
_fields_ = [
('info', POINTER(COMINFO)),
('dualstring', POINTER(DUALSTRINGARRAY)),
('unknown2', uint8_t*3),
('result', WERROR),
]
class ServerAlive2(Structure):
_fields_ = [('out', ServerAlive2_out)]
+59
View File
@@ -0,0 +1,59 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__="Define the rpc_request structure."
from pysamba.library import *
class rpc_request(Structure): pass
class dcerpc_pipe(Structure): pass
class GUID(Structure):
_fields_ = [
]
class DATA_BLOB(Structure):
_fields_ = [
('data', POINTER(uint8_t)),
('length', size_t),
]
class ndr(Structure):
_fields_ = [
('table', c_void_p), # lie: POINTER(dcerpc_interface_table)
('opnum', uint32_t),
('struct_ptr', c_void_p),
('mem_ctx', c_void_p), # lie: POINTER(TALLOC_CTX)
]
class async(Structure):
_fields_ = [
('callback', CFUNCTYPE(None, POINTER(rpc_request))),
('private', c_void_p),
]
rpc_request._fields_ = [
('next', POINTER(rpc_request)),
('prev', POINTER(rpc_request)),
('p', POINTER(dcerpc_pipe)),
('status', NTSTATUS),
('call_id', uint32_t),
('state', enum),
('payload', DATA_BLOB),
('flags', uint32_t),
('fault_code', uint32_t),
('recv_handler', c_void_p), # lie
('object', POINTER(GUID)),
('opnum', uint16_t),
('request_data', DATA_BLOB),
('async_call', BOOL),
('ndr', ndr),
('async', async),
]
+71
View File
@@ -0,0 +1,71 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__= "Re-implement the talloc macros in a python-compatible way"
from pysamba.library import library, logFuncCall
from ctypes import *
class TallocError(Exception): pass
# function wrapper to check for out-of-memory and turn it into an exception
def check(f):
def inner(*args, **kw):
res = f(*args, **kw)
if not res:
raise TallocError("Out of memory - %08x" % res)
return res
inner.__name__ = f.__name__
return inner
@logFuncCall
@check
def talloc_zero(ctx, type):
typename = 'struct ' + type.__name__
return cast(library._talloc_zero(ctx,
sizeof(type),
typename),
POINTER(type))
#char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
library.talloc_asprintf.restype = c_char_p
library.talloc_asprintf = logFuncCall(library.talloc_asprintf)
@logFuncCall
@check
def talloc_asprintf(*args):
ctx = args[0]
fmt = args[1]
s = fmt % args[2:]
ret = library.talloc_strdup(ctx, s)
return ret
def talloc_get_type(obj, type):
result = library.talloc_check_name(obj, 'struct ' + type.__name__)
if not result:
raise TallocError("Probable mis-interpretation of memory block: "
"Have %s, wanted %s" % (talloc_get_name(obj),
'struct ' + type.__name__))
return cast(result, POINTER(type))
@logFuncCall
@check
def talloc_array(ctx, type, count):
obj = library._talloc_array(ctx,
sizeof(type),
count,
'struct ' + type.__name__)
return cast(obj, POINTER(type))
talloc_free = library.talloc_free
talloc_increase_ref_count = library.talloc_increase_ref_count
talloc_get_name = library.talloc_get_name
+61
View File
@@ -0,0 +1,61 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from ctypes import *
from pysamba.twisted.reactor import reactor, eventContext
from pysamba.library import *
from pysamba.rpc.Rpc import Rpc
from pysamba.twisted.callback import WMIFailure
import sys
import pysamba.wbem.Query
from pysamba.twisted.callback import WMIFailure
import logging
log = logging.getLogger('p.t.connect')
import Globals
from Products.ZenUtils.Driver import drive, driveLater
from twisted.internet import defer
def doOneDevice(creds, hostname):
def inner(driver):
while 1:
try:
q = Rpc()
yield q.connect(hostname, creds, 'winreg')
driver.next()
q.close()
except Exception, ex:
log.exception(ex)
return drive(inner)
def main():
logging.basicConfig()
log = logging.getLogger()
log.setLevel(10)
DEBUGLEVEL.value = 99
creds = sys.argv[1]
hosts = sys.argv[2:]
defs = []
for host in hosts:
defs.append(doOneDevice(creds, host))
d = defer.DeferredList(defs)
d.addBoth(lambda x : reactor.stop())
reactor.run()
sys.exit(main())
+103
View File
@@ -0,0 +1,103 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from ctypes import *
from pysamba.twisted.reactor import reactor, eventContext
from pysamba.library import *
from pysamba.wbem.wbem import *
from pysamba.wbem.Query import Query
from pysamba.twisted.callback import WMIFailure
import sys
import logging
log = logging.getLogger('p.t.watcher')
import Globals
from Products.ZenUtils.Driver import drive
from twisted.internet import defer
wql = """SELECT * FROM __InstanceCreationEvent where """\
"""TargetInstance ISA 'Win32_NTLogEvent' """\
"""and TargetInstance.EventType <= 5"""
def async_sleep(secs):
d = defer.Deferred()
reactor.callLater(secs, d.callback, None)
return d
def printSize():
"Monitor this process' memory usage"
import gc
gc.collect()
sz = open('/proc/%d/statm' % os.getpid()).read().split()[0]
log.info('*'*40)
log.info("Current size: %s" % (sz,) )
def doOneDevice(creds, hostname):
def inner(driver):
try:
q = Query()
yield q.connect(eventContext, hostname, creds)
driver.next()
yield q.notificationQuery(wql)
result = driver.next()
log.info("Query sent")
while 1:
printSize()
try:
class_name = ''
while 1:
yield result.fetchSome(500)
if not driver.next(): break
log.info("Got %d items", len(driver.next()))
for obj in driver.next():
obj = obj.targetinstance
props = [p for p in obj.__dict__.keys()
if not p.startswith('_')]
if obj._class_name != class_name:
class_name = obj._class_name
print obj._class_name
print repr(props)
print repr([getattr(obj, p) for p in props])
except WError, ex:
log.exception(ex)
yield async_sleep(1)
driver.next()
q.close()
except Exception, ex:
log.exception(ex)
return drive(inner)
def main():
logging.basicConfig()
log = logging.getLogger()
log.setLevel(20)
# DEBUGLEVEL.value = 99
creds = sys.argv[1]
hosts = sys.argv[2:]
def stop(result):
print result
reactor.stop()
def later():
d = defer.DeferredList(
[doOneDevice(creds, h) for h in hosts]
)
d.addBoth(stop)
reactor.callLater(1, later)
reactor.run()
sys.exit(main())
+78
View File
@@ -0,0 +1,78 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from ctypes import *
from pysamba.twisted.reactor import reactor, eventContext
from pysamba.library import *
from pysamba.wbem.wbem import *
from pysamba.wbem.Query import Query
from pysamba.twisted.callback import WMIFailure
import sys
import logging
log = logging.getLogger('p.t.wmic')
import Globals
from Products.ZenUtils.Driver import drive, driveLater
from twisted.internet import defer
def doOneDevice(creds, query, hostname):
def inner(driver):
try:
q = Query()
yield q.connect(eventContext, hostname, creds)
driver.next()
log.info("Query sent")
yield q.query(query)
result = driver.next()
class_name = ''
while 1:
yield result.fetchSome()
if not driver.next(): break
for obj in driver.next():
props = [p for p in obj.__dict__.keys()
if not p.startswith('_')]
if obj._class_name != class_name:
class_name = obj._class_name
print obj._class_name
print repr(props)
print repr([getattr(obj, p) for p in props])
q.close()
except Exception, ex:
log.exception(ex)
return driveLater(0.25, inner)
def main():
logging.basicConfig()
log = logging.getLogger()
log.setLevel(10)
DEBUGLEVEL.value = 99
creds, query = sys.argv[1:3]
hosts = sys.argv[3:]
def stop(result):
print result
reactor.stop()
def later():
d = defer.DeferredList(
[doOneDevice(creds, query, h) for h in hosts]
)
d.addBoth(stop)
reactor.callLater(1, later)
reactor.run()
sys.exit(main())
+13
View File
@@ -0,0 +1,13 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
+53
View File
@@ -0,0 +1,53 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__="""
Support classes for integrating deferreds into the Samba asynchronous framework
"""
from pysamba.library import logFuncCall
from pysamba.composite_context import *
from twisted.internet import defer
DEFERS = {}
COUNTER = 0L
class WMIFailure(Exception):
"Exception that represents a composite_context failure"
def __str__(self):
return library.nt_errstr(self.args[1])
class Callback(object):
"Turn a composite_context callback into a deferred callback"
def __init__(self):
# keep a reference to this object as long as it lives in the C code
global COUNTER
COUNTER += 1
self.which = COUNTER
DEFERS[self.which] = self
self.callback = composite_context_callback(self.callback)
self.deferred = defer.Deferred()
@logFuncCall
def callback(self, ctx):
# remove the reference to the object now that we're out of C code
try:
DEFERS.pop(self.which)
except KeyError, ex:
log.error("Encountered error in pysamba.Callback.callback: " + ex)
d = self.deferred
if ctx.contents.state == COMPOSITE_STATE_DONE:
d.callback(ctx.contents.async.private_data)
else:
d.errback(WMIFailure(ctx.contents.state,
ctx.contents.status))
+232
View File
@@ -0,0 +1,232 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
__doc__="python classes to integrate the twisted and Samba event loops"
from pysamba.library import *
from ctypes import *
import os
import sys
import errno
import sys
import logging
logging.basicConfig()
log = logging.getLogger("zen.pysamba")
EVENT_FD_READ = 1
EVENT_FD_WRITE = 2
class Timer(object):
callLater = None
timer = Timer()
class timeval(Structure):
_fields_ = [
('tv_sec', c_long),
('tv_usec', c_long),
]
#void zenoss_get_next_timeout(struct event_context* event_ctx, struct timeval* timeout)
library.zenoss_get_next_timeout.restype = None
library.zenoss_get_next_timeout.argtypes = [c_void_p, POINTER(timeval)]
#logging will occur within this C function - avoid python logging for verbosity
#library.zenoss_get_next_timeout = logFuncCall(library.zenoss_get_next_timeout)
library.zenoss_read_ready.restype = None
library.zenoss_read_ready.argtypes = [c_void_p, c_int]
library.zenoss_read_ready = logFuncCall(library.zenoss_read_ready)
library.zenoss_write_ready.restype = None
library.zenoss_write_ready.argtypes = [c_void_p, c_int]
library.zenoss_write_ready = logFuncCall(library.zenoss_write_ready)
library.lp_do_parameter.restype = None
library.lp_do_parameter.argtypes = [c_int, c_char_p, c_char_p]
library.lp_do_parameter = logFuncCall(library.lp_do_parameter)
from twisted.internet.selectreactor import SelectReactor
from select import select
class WmiReactorMixin:
def __init__(self):
self.readFdMap = {}
self.writeFdMap = {}
def callTimeouts(self, delay):
"""
Perform a single iteration of the reactor. Here we make sure that
all of our file descriptors that we need to watch are and then delegate
the actual watching back to the twisted reactor.
"""
#
# determine the next timeout interval based upon any queued events
#
timeout = timeval()
while True:
library.zenoss_get_next_timeout(eventContext, byref(timeout))
t = timeout.tv_sec + timeout.tv_usec / 1e6
if t > 0.0: break
if timer.callLater:
timer.callLater.cancel()
timer.callLater = None
timer.callLater = self.callLater(t, self.__checkTimeouts)
def removeFileDescriptor(self, fd):
self.watchFileDescriptor(fd, 0)
def watchFileDescriptor(self, fd, flags):
log.debug("Callback from c: watchFileDescriptor: fd: %s flags: %s" % (fd, flags))
if (flags & EVENT_FD_READ) != 0:
if fd not in self.readFdMap:
reader = ActivityHook('Reader', fd)
self.readFdMap[fd] = reader
self.addReader(self.readFdMap[fd])
elif fd in self.readFdMap:
self.removeReader(self.readFdMap[fd])
del self.readFdMap[fd]
if (flags & EVENT_FD_WRITE) != 0:
if fd not in self.writeFdMap:
writer = ActivityHook('Writer', fd)
self.writeFdMap[fd] = writer
self.addWriter(self.writeFdMap[fd])
elif fd in self.writeFdMap:
self.removeWriter(self.writeFdMap[fd])
del self.writeFdMap[fd]
return 0
def __checkTimeouts(self):
timer.callLater = None
def doOnce(self):
self.doIteration(0.1)
return 0
class WmiReactor(WmiReactorMixin, SelectReactor):
def __init__(self):
SelectReactor.__init__(self)
WmiReactorMixin.__init__(self)
def _preenDescriptors(self):
for fdMap, lst in (
(self.readFdMap, self.readFdMap.keys()),
(self.writeFdMap.keys(), self.writeFdMap.keys())
):
for fd in lst:
try:
select(fd + 1, [fd], [fd], [fd], 0)
except:
try:
fdMap.pop(fd)
except IndexError:
pass
SelectReactor._preenDescriptors(self)
def doIteration(self, delay):
"""
Perform a single iteration of the reactor. Here we make sure that
all of our file descriptors that we need to watch are and then delegate
the actual watching back to the twisted reactor.
"""
self.callTimeouts(delay)
return SelectReactor.doIteration(self, delay)
#
# Install the WmiReactor instead of the default twisted one. See the following
# ticket for the history of using an epoll vs. select reactor.
# http://dev.zenoss.org/trac/ticket/4640
#
if os.uname()[0] == 'Linux':
from twisted.internet.epollreactor import EPollReactor
class WmiEPollReactor(WmiReactorMixin, EPollReactor):
def __init__(self):
EPollReactor.__init__(self)
WmiReactorMixin.__init__(self)
def _remove(self, xer, primary, other, selectables, event, antievent):
try:
return EPollReactor._remove(self,
xer, primary, other, selectables,
event, antievent)
except IOError, err:
# huh, wha? oh, we weren't listening for that fileno anyhow
if err.errno != errno.EBADF:
raise
def doPoll(self, delay):
self.callTimeouts(delay)
return EPollReactor.doPoll(self, delay)
doIteration = doPoll
wmiReactor = WmiEPollReactor()
else:
wmiReactor = WmiReactor()
callback = reactor_functions()
callback.fd_callback = library.watch_fd_callback(logFuncCall(wmiReactor.watchFileDescriptor))
callback.loop_callback = library.loop_callback(logFuncCall(wmiReactor.doOnce))
eventContext = library.async_create_context(byref(callback))
from twisted.internet.main import installReactor
try:
installReactor(wmiReactor)
except Exception, e:
log.critical("Unable to install the WMI reactor. %s" % e)
sys.exit(1) # TODO: pick a better error code?
class ActivityHook:
"Notify the Samba event loop of file descriptor activity"
def __init__(self, prefix, fd):
self.prefix = prefix
self.fd = fd
def logPrefix(self):
return self.prefix
def doRead(self):
library.zenoss_read_ready(eventContext, self.fd)
def doWrite(self):
library.zenoss_write_ready(eventContext, self.fd)
def fileno(self):
return self.fd
def connectionLost(self, why):
wmiReactor.removeFileDescriptor(self.fd)
# allow users to write:
# from pysamba.twisted import reactor
# instead of
# from twisted.internet import reactor
from twisted.internet import reactor
def setNTLMv2Authentication(enabled = False):
"""
Enables or disables the NTLMv2 authentication feature.
@param enabled: True if NTLMv2 is supported
@type enabled: boolean
"""
flag = "no"
if enabled:
flag = "yes"
library.lp_do_parameter(-1, "client ntlmv2 auth", flag)
log.debug("client ntlmv2 auth is now %s", flag)
+13
View File
@@ -0,0 +1,13 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
VERSION='1.3.16'
+256
View File
@@ -0,0 +1,256 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from pysamba.library import *
from pysamba.wbem.wbem import *
from twisted.internet import defer
from pysamba.talloc import *
from pysamba.rpc.credentials import *
from pysamba.twisted.callback import Callback, WMIFailure
import Globals
from Products.ZenUtils.Driver import drive
import logging
logging.basicConfig()
log = logging.getLogger('zen.pysamba')
WBEM_S_TIMEDOUT = 0x40004L
WERR_BADFUNC = 1
# struct dcom_client_context *dcom_client_init(struct com_context *ctx,
# struct cli_credentials *credentials)
library.dcom_client_init.restype = c_void_p
library.dcom_client_init.argtypes = [POINTER(com_context), c_void_p]
library.dcom_client_init = logFuncCall(library.dcom_client_init)
#WERROR com_init_ctx(struct com_context **ctx, struct event_context *event_ctx);
library.com_init_ctx.restype = WERROR
library.com_init_ctx.argtypes = [POINTER(POINTER(com_context)), POINTER(event_context)]
library.com_init_ctx = logFuncCall(library.com_init_ctx)
class _WbemObject:
def __getattr__(self, name):
try:
return self.__dict__[name.lower()]
except Exception, ex:
raise AttributeError(name)
def convertArray(arr):
if not arr:
return None
result = []
arr = arr.contents
for i in range(arr.count):
result.append(arr.item[i])
return result
def convert(v, typeval):
if typeval == CIM_SINT8: return v.v_sint8
if typeval == CIM_UINT8: return v.v_uint8
if typeval == CIM_SINT16: return v.v_sint16
if typeval == CIM_UINT16: return v.v_uint16
if typeval == CIM_SINT32: return v.v_sint32
if typeval == CIM_UINT32: return v.v_uint32
if typeval == CIM_SINT64: return v.v_sint64
if typeval == CIM_UINT64: return v.v_sint64
if typeval == CIM_REAL32: return float(v.v_uint32)
if typeval == CIM_REAL64: return float(v.v_uint64)
if typeval == CIM_BOOLEAN: return bool(v.v_boolean)
if typeval in (CIM_STRING, CIM_DATETIME, CIM_REFERENCE):
return v.v_string
if typeval == CIM_CHAR16:
return v.v_string.decode('utf16')
if typeval == CIM_OBJECT:
return wbemInstanceToPython(v.v_object)
if typeval == CIM_ARR_SINT8: return convertArray(v.a_sint8)
if typeval == CIM_ARR_UINT8: return convertArray(v.a_uint8)
if typeval == CIM_ARR_SINT16: return convertArray(v.a_sint16)
if typeval == CIM_ARR_UINT16: return convertArray(v.a_uint16)
if typeval == CIM_ARR_SINT32: return convertArray(v.a_sint32)
if typeval == CIM_ARR_UINT32: return convertArray(v.a_uint32)
if typeval == CIM_ARR_SINT64: return convertArray(v.a_sint64)
if typeval == CIM_ARR_UINT64: return convertArray(v.a_uint64)
if typeval == CIM_ARR_REAL32: return convertArray(v.a_real32)
if typeval == CIM_ARR_REAL64: return convertArray(v.a_real64)
if typeval == CIM_ARR_BOOLEAN: return convertArray(v.a_boolean)
if typeval == CIM_ARR_STRING: return convertArray(v.a_string)
if typeval == CIM_ARR_DATETIME:
return convertArray(v.contents.a_datetime)
if typeval == CIM_ARR_REFERENCE:
return convertArray(v.contents.a_reference)
return "Unsupported"
def wbemInstanceToPython(obj):
klass = obj.contents.obj_class.contents
inst = obj.contents.instance.contents
result = _WbemObject()
result._class_name = klass.__CLASS
for j in range(klass.__PROPERTY_COUNT):
prop = klass.properties[j]
value = convert(inst.data[j], prop.desc.contents.cimtype & CIM_TYPEMASK)
if prop.name:
setattr(result, prop.name.lower(), value)
return result
def deferred(ctx):
cback = Callback()
ctx.contents.async.fn = cback.callback
return cback.deferred
wbemTimeoutInfinite = -1
class QueryResult(object):
def __init__(self, deviceId, ctx, pEnum):
self._deviceId = deviceId
self.ctx = ctx
talloc_increase_ref_count(self.ctx)
self.pEnum = pEnum
def close(self):
if self.ctx:
talloc_free(self.ctx)
self.ctx = None
def __del__(self):
self.close()
def fetchSome(self, timeoutMs=wbemTimeoutInfinite, chunkSize=10):
assert self.pEnum
def inner(driver):
count = uint32_t()
objs = (POINTER(WbemClassObject)*chunkSize)()
ctx = library.IEnumWbemClassObject_SmartNext_send(
self.pEnum, None, timeoutMs, chunkSize
)
yield deferred(ctx); driver.next()
result = library.IEnumWbemClassObject_SmartNext_recv(
ctx, self.ctx, objs, byref(count)
)
WERR_CHECK(result, self._deviceId, "Retrieve result data.")
result = []
for i in range(count.value):
result.append(wbemInstanceToPython(objs[i]))
talloc_free(objs[i])
driver.finish(result)
return drive(inner)
class Query(object):
def __init__(self):
self.ctx = POINTER(com_context)()
self.pWS = POINTER(IWbemServices)()
self._deviceId = None
def connect(self, eventContext, deviceId, hostname, creds, namespace="root\\cimv2"):
self._deviceId = deviceId
library.com_init_ctx(byref(self.ctx), eventContext)
cred = library.cli_credentials_init(self.ctx)
library.cli_credentials_set_conf(cred)
library.cli_credentials_parse_string(cred, creds, CRED_SPECIFIED)
library.dcom_client_init(self.ctx, cred)
def inner(driver):
flags = uint32_t()
flags.value = 0
ctx = library.WBEM_ConnectServer_send(
self.ctx, # com_ctx
None, # parent_ctx
hostname, # server
namespace, # namespace
None, # username
None, # password
None, # locale
flags.value, # flags
None, # authority
None) # wbem_ctx
yield deferred(ctx); driver.next()
result = library.WBEM_ConnectServer_recv(ctx, None, byref(self.pWS))
WERR_CHECK(result, self._deviceId, "Connect")
driver.finish(None)
return drive(inner)
def query(self, query):
assert self.pWS
def inner(driver):
qctx = None
try:
qctx = library.IWbemServices_ExecQuery_send_f(
self.pWS,
self.ctx,
"WQL",
query,
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_ENSURE_LOCATABLE,
None)
yield deferred(qctx); driver.next()
pEnum = POINTER(IEnumWbemClassObject)()
result = library.IWbemServices_ExecQuery_recv(qctx,
byref(pEnum))
WERR_CHECK(result, self._deviceId, "ExecQuery")
ctx = library.IEnumWbemClassObject_Reset_send_f(pEnum, self.ctx)
yield deferred(ctx); driver.next()
result = library.IEnumWbemClassObject_Reset_recv(ctx);
WERR_CHECK(result, self._deviceId, "Reset result of WMI query.");
driver.finish(QueryResult(self._deviceId, self.ctx, pEnum))
except Exception, ex:
log.exception(ex)
raise
return drive(inner)
def notificationQuery(self, query):
assert self.pWS
def inner(driver):
qctx = None
pEnum = None
try:
qctx = library.IWbemServices_ExecNotificationQuery_send_f(
self.pWS,
self.ctx,
"WQL",
query,
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
None)
yield deferred(qctx); driver.next()
pEnum = POINTER(IEnumWbemClassObject)()
result = library.IWbemServices_ExecNotificationQuery_recv(
qctx, byref(pEnum))
WERR_CHECK(result, self._deviceId, "ExecNotificationQuery")
driver.finish(QueryResult(self._deviceId, self.ctx, pEnum))
except Exception, ex:
if pEnum:
c = library.IUnknown_Release_send_f(pEnum, self.ctx)
yield deferred(c); driver.next()
result = library.IUnknown_Release_recv(self.ctx)
WERR_CHECK(result, self._deviceId, "Release")
log.exception(ex)
raise
return drive(inner)
def __del__(self):
self.close()
def close(self):
if self.ctx:
talloc_free(self.ctx)
self.ctx = None
+13
View File
@@ -0,0 +1,13 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
+309
View File
@@ -0,0 +1,309 @@
###########################################################################
#
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2008-2010, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#
###########################################################################
from pysamba.library import *
from pysamba.composite_context import composite_context
class com_context(Structure): pass
CIMSTRING = c_char_p
CIM_EMPTY=0
CIM_SINT8=16
CIM_UINT8=17
CIM_SINT16=2
CIM_UINT16=18
CIM_SINT32=3
CIM_UINT32=19
CIM_SINT64=20
CIM_UINT64=21
CIM_REAL32=4
CIM_REAL64=5
CIM_BOOLEAN=11
CIM_STRING=8
CIM_DATETIME=101
CIM_REFERENCE=102
CIM_CHAR16=103
CIM_OBJECT=13
CIM_FLAG_ARRAY=0x2000
CIM_ARR_SINT8=CIM_FLAG_ARRAY|CIM_SINT8
CIM_ARR_UINT8=CIM_FLAG_ARRAY|CIM_UINT8
CIM_ARR_SINT16=CIM_FLAG_ARRAY|CIM_SINT16
CIM_ARR_UINT16=CIM_FLAG_ARRAY|CIM_UINT16
CIM_ARR_SINT32=CIM_FLAG_ARRAY|CIM_SINT32
CIM_ARR_UINT32=CIM_FLAG_ARRAY|CIM_UINT32
CIM_ARR_SINT64=CIM_FLAG_ARRAY|CIM_SINT64
CIM_ARR_UINT64=CIM_FLAG_ARRAY|CIM_UINT64
CIM_ARR_REAL32=CIM_FLAG_ARRAY|CIM_REAL32
CIM_ARR_REAL64=CIM_FLAG_ARRAY|CIM_REAL64
CIM_ARR_BOOLEAN=CIM_FLAG_ARRAY|CIM_BOOLEAN
CIM_ARR_STRING=CIM_FLAG_ARRAY|CIM_STRING
CIM_ARR_DATETIME=CIM_FLAG_ARRAY|CIM_DATETIME
CIM_ARR_REFERENCE=CIM_FLAG_ARRAY|CIM_REFERENCE
CIM_ARR_CHAR16=CIM_FLAG_ARRAY|CIM_CHAR16
CIM_ARR_OBJECT=CIM_FLAG_ARRAY|CIM_OBJECT
CIM_ILLEGAL=0xfff
CIM_TYPEMASK=0x2FFF
class CIMSTRINGS(Structure):
_fields_ = [
('count', uint32_t),
('item', POINTER(CIMSTRING))
]
class WbemClassObject(Structure): pass
class arr_int8(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(int8_t))
]
class arr_uint8(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(uint8_t))
]
class arr_int16(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(int16_t))
]
class uarr_uint16(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(uint16_t))
]
class arr_int32(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(int32_t))
]
class arr_uint32(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(uint32_t))
]
dlong_t = int64_t
class arr_dlong(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(dlong_t))
]
class arr_uint32(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(uint32_t))
]
udlong_t = uint64_t
class arr_udlong(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(udlong_t))
]
class arr_uint16(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(uint16_t))
]
class arr_CIMSTRING(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(CIMSTRING))
]
class arr_WbemClassObject(Structure):
_fields_= [
('count', uint32_t),
('item', POINTER(WbemClassObject))
]
class CIMVAR(Union):
_fields_ = [
('v_sint8', int8_t), # case (CIM_SINT8)
('v_uint8', uint8_t), # case (CIM_UINT8)
('v_sint16', int16_t), # case (CIM_SINT16)
('v_uint16', uint16_t), # case (CIM_UINT16)
('v_sint32', int32_t), # case (CIM_SINT32)
('v_uint32', uint32_t), # case (CIM_UINT32)
('v_sint64', int64_t), # case (CIM_SINT64)
('v_uint64', uint64_t), # case (CIM_UINT64)
('v_real32', uint32_t), # case (CIM_REAL32)
('v_real64', uint64_t), # case (CIM_REAL64)
('v_boolean', uint16_t), # case (CIM_BOOLEAN)
('v_string', CIMSTRING), # relative,string,charset(UTF16),case(CIM_STRING)]
('v_datetime', CIMSTRING), # relative,string,charset(UTF16),case(CIM_DATETIME)]
('v_reference', CIMSTRING), # relative,string,charset(UTF16),case(CIM_REFERENCE)]
('v_object', POINTER(WbemClassObject)), # [relative,subcontext(4),case(CIM_OBJECT)]
('a_sint8', POINTER(arr_int8)), # [relative,case(CIM_ARR_SINT8)]
('a_uint8', POINTER(arr_uint8)), # [relative,case(CIM_ARR_UINT8)]
('a_sint16', POINTER(arr_int16)), # [relative,case(CIM_ARR_SINT16)]
('a_uint16', POINTER(arr_uint16)), # [relative,case(CIM_ARR_UINT16)]
('a_sint32', POINTER(arr_int32)), # [relative,case(CIM_ARR_SINT32)]
('a_uint32', POINTER(arr_uint32)), # [relative,case(CIM_ARR_UINT32)]
('a_sint64', POINTER(arr_dlong)), # [relative,case(CIM_ARR_SINT64)]
('a_uint64', POINTER(arr_udlong)), # [relative,case(CIM_ARR_UINT64)]
('a_real32', POINTER(arr_uint32)), # [relative,case(CIM_ARR_REAL32)]
('a_real64', POINTER(arr_udlong)), # [relative,case(CIM_ARR_REAL64)]
('a_boolean', POINTER(arr_uint16)), # [relative,case(CIM_ARR_BOOLEAN)]
('a_string', POINTER(arr_CIMSTRING)), # [relative,case(CIM_ARR_STRING)]
('a_datetime', POINTER(arr_CIMSTRING)), # [relative,case(CIM_ARR_DATETIME)]
('a_reference', POINTER(arr_CIMSTRING)), # [relative,case(CIM_ARR_REFERENCE)]
('a_object', POINTER(arr_WbemClassObject)), # [relative,case(CIM_ARR_OBJECT)]
]
class WbemQualifier(Structure): pass
class WbemQualifiers(Structure):
_fields_ = [
('count', uint32_t),
('item', POINTER(POINTER(WbemQualifier))),
]
class WbemPropertyDesc(Structure):
_fields_ = [
('cimtype', uint32_t),
('nr', uint16_t),
('offset', uint32_t),
('depth', uint32_t),
('qualifiers', WbemQualifiers),
]
class WbemProperty(Structure):
_fields_ = [
('name', CIMSTRING), # [relative,string,charset(UTF16)]
('desc', POINTER(WbemPropertyDesc)), # [relative]
]
class WbemMethods(Structure): pass
class WbemClass(Structure):
_fields_ = [
('u_0', uint8_t),
('__CLASS', CIMSTRING),
('data_size', uint32_t),
('__DERIVATION', CIMSTRINGS),
('qualifiers', WbemQualifiers),
('__PROPERTY_COUNT', uint32_t),
('properties', POINTER(WbemProperty)),
('default_flags', POINTER(uint8_t)),
('default_values', POINTER(CIMVAR)),
]
class WbemInstance(Structure):
_fields_ = [
('u1_0', uint8_t),
('__CLASS', CIMSTRING),
('default_flags', POINTER(uint8_t)),
('data', POINTER(CIMVAR)),
('u2_4', uint32_t),
('u3_1', uint8_t),
]
WbemClassObject._fields_ = [
('flags', uint8_t),
('__SERVER', CIMSTRING),
('__NAMESPACE', CIMSTRING),
('sup_class', POINTER(WbemClass)),
('sup_methods', POINTER(WbemMethods)),
('obj_class', POINTER(WbemClass)),
('obj_methods', POINTER(WbemMethods)),
('instance', POINTER(WbemInstance)),
]
class IWbemServices(Structure): pass
class IEnumWbemClassObject(Structure): pass
class IWbemClassObject(Structure): pass
class IWbemContext(Structure): pass
class IUnknown(Structure): pass
# hack definition of BSTR, needs more complete structure definition
BSTR = c_char_p
WBEM_FLAG_RETURN_IMMEDIATELY = 0x10
WBEM_FLAG_ENSURE_LOCATABLE = 0x100
WBEM_FLAG_FORWARD_ONLY = 0x20
WBEM_S_TIMEDOUT=0x40004
#WERROR IWbemServices_ExecQuery_recv(struct composite_context *c, struct IEnumWbemClassObject **ppEnum);
library.IWbemServices_ExecQuery_recv.restype = WERROR
library.IWbemServices_ExecQuery_recv.argtypes = [POINTER(composite_context), POINTER(POINTER(IEnumWbemClassObject))]
library.IWbemServices_ExecQuery_recv = logFuncCall(library.IWbemServices_ExecQuery_recv)
#WERROR IEnumWbemClassObject_Reset_recv(struct composite_context *c);
library.IEnumWbemClassObject_Reset_recv.restype = WERROR
library.IEnumWbemClassObject_Reset_recv.argtypes = [POINTER(composite_context)]
library.IEnumWbemClassObject_Reset_recv = logFuncCall(library.IEnumWbemClassObject_Reset_recv)
#uint32_t IUnknown_Release_recv(struct composite_context *c);
library.IUnknown_Release_recv.restype = WERROR
library.IUnknown_Release_recv.argtypes = [POINTER(composite_context)]
library.IUnknown_Release_recv = logFuncCall(library.IUnknown_Release_recv)
library.WBEM_ConnectServer.restype = WERROR
library.WBEM_ConnectServer.argtypes = [POINTER(com_context), c_char_p, c_char_p, c_char_p, c_char_p, c_char_p, c_uint32, c_char_p, POINTER(IWbemContext), c_void_p]
library.WBEM_ConnectServer = logFuncCall(library.WBEM_ConnectServer)
library.WBEM_ConnectServer_recv.restype = WERROR
library.WBEM_ConnectServer_recv.argtypes = [POINTER(composite_context), c_void_p, c_void_p]
library.WBEM_ConnectServer_recv = logFuncCall(library.WBEM_ConnectServer_recv)
#extern struct composite_context *WBEM_ConnectServer_send(struct com_context *ctx,
# TALLOC_CTX *parent_ctx, const char *server, const char *nspace,
# const char *user, const char *password, const char *locale,
# uint32_t flags, const char *authority, struct IWbemContext* wbem_ctx);
library.WBEM_ConnectServer_send.restype = POINTER(composite_context)
library.WBEM_ConnectServer_send.argtypes = [POINTER(com_context), c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_char_p, c_uint32, c_char_p, POINTER(IWbemContext)]
library.WBEM_ConnectServer_send = logFuncCall(library.WBEM_ConnectServer_send)
library.IEnumWbemClassObject_SmartNext_send.restype = POINTER(composite_context)
library.IEnumWbemClassObject_SmartNext_send.argtypes = [POINTER(IEnumWbemClassObject), c_void_p, c_int32, c_uint32]
library.IEnumWbemClassObject_SmartNext_send = logFuncCall(library.IEnumWbemClassObject_SmartNext_send)
library.IEnumWbemClassObject_SmartNext_recv.restype = WERROR
library.IEnumWbemClassObject_SmartNext_recv.argtypes = [POINTER(composite_context), c_void_p, c_void_p, c_void_p]
library.IEnumWbemClassObject_SmartNext_recv = logFuncCall(library.IEnumWbemClassObject_SmartNext_recv)
library.IEnumWbemClassObject_SmartNext.restype = WERROR
library.IEnumWbemClassObject_SmartNext.argtypes = [POINTER(IEnumWbemClassObject), c_void_p, c_int32, c_uint32, c_void_p, c_void_p]
library.IEnumWbemClassObject_SmartNext = logFuncCall(library.IEnumWbemClassObject_SmartNext)
library.wmi_errstr.restype = c_char_p
library.wmi_errstr.argtypes = [WERROR]
library.wmi_errstr = logFuncCall(library.wmi_errstr)
library.IWbemClassObject_GetMethod.restype = WERROR
library.IWbemClassObject_GetMethod.argtypes = [POINTER(IWbemClassObject), c_void_p, c_char_p, c_uint32, c_void_p, c_void_p]
library.IWbemClassObject_GetMethod = logFuncCall(library.IWbemClassObject_GetMethod)
library.IWbemClassObject_SpawnInstance.restype = WERROR
library.IWbemClassObject_SpawnInstance.argtypes = [POINTER(IWbemClassObject), c_void_p, c_uint32, c_void_p]
library.IWbemClassObject_SpawnInstance = logFuncCall(library.IWbemClassObject_SpawnInstance)
library.IWbemClassObject_Put.restype = WERROR
library.IWbemClassObject_Put.argtypes = [POINTER(IWbemClassObject), c_void_p, c_char_p, c_uint32, POINTER(CIMVAR), enum]
library.IWbemClassObject_Put = logFuncCall(library.IWbemClassObject_Put)
library.WbemClassObject_Get.restype = WERROR
library.WbemClassObject_Get.argtypes = [POINTER(WbemClassObject), c_void_p, c_char_p, c_uint32, POINTER(CIMVAR), enum, c_void_p]
library.WbemClassObject_Get = logFuncCall(library.WbemClassObject_Get)
library.ConnectAndQuery.restype = WERROR
library.ConnectAndQuery.argtypes = [POINTER(com_context), c_char_p, c_char_p, c_void_p]
library.ConnectAndQuery = logFuncCall(library.ConnectAndQuery)
library.IWbemServices_ExecQuery_send_f.restype = POINTER(composite_context)
library.IWbemServices_ExecQuery_send_f.argtypes = [POINTER(IWbemServices), c_void_p, BSTR, BSTR, c_int32, POINTER(IWbemContext)]
library.IWbemServices_ExecQuery_send_f = logFuncCall(library.IWbemServices_ExecQuery_send_f)
library.IWbemServices_ExecNotificationQuery_send_f.restype = POINTER(composite_context)
library.IWbemServices_ExecNotificationQuery_send_f.argtypes = [POINTER(IWbemServices), c_void_p, BSTR, BSTR, c_int32, POINTER(IWbemContext)]
library.IWbemServices_ExecNotificationQuery_send_f = logFuncCall(library.IWbemServices_ExecNotificationQuery_send_f)
library.IWbemServices_ExecNotificationQuery_recv.restype = WERROR
library.IWbemServices_ExecNotificationQuery_recv.argtypes = [POINTER(composite_context), POINTER(POINTER(IEnumWbemClassObject))]
library.IWbemServices_ExecNotificationQuery_recv = logFuncCall(library.IWbemServices_ExecNotificationQuery_recv)
library.IEnumWbemClassObject_Reset_send_f.restype = POINTER(composite_context)
library.IEnumWbemClassObject_Reset_send_f.argtypes = [POINTER(IEnumWbemClassObject), c_void_p]
library.IEnumWbemClassObject_Reset_send_f = logFuncCall(library.IEnumWbemClassObject_Reset_send_f)
library.IUnknown_Release_send_f.restype = POINTER(composite_context)
library.IUnknown_Release_send_f.argtypes = [POINTER(IUnknown), c_void_p]
library.IUnknown_Release_send_f = logFuncCall(library.IUnknown_Release_send_f)