| 1 |
#------------------------------------------------------------------------- |
| 2 |
# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 |
# Licensed under the MIT License. See License.txt in the project root for |
| 4 |
# license information. |
| 5 |
#-------------------------------------------------------------------------- |
| 6 |
|
| 7 |
# Python imports |
| 8 |
import logging |
| 9 |
|
| 10 |
# C imports |
| 11 |
cimport c_xio |
| 12 |
cimport c_sasl_mechanism |
| 13 |
|
| 14 |
|
| 15 |
_logger = logging.getLogger(__name__) |
| 16 |
|
| 17 |
|
| 18 |
cpdef _get_sasl_mechanism_interface(): |
| 19 |
cdef const c_sasl_mechanism.SASL_MECHANISM_INTERFACE_DESCRIPTION* interface |
| 20 |
interface = c_sasl_mechanism.saslmssbcbs_get_interface() |
| 21 |
if <void*>interface == NULL: |
| 22 |
raise ValueError("Failed to create SASL CBS Interface description") |
| 23 |
desc = SASLMechanismInterfaceDescription() |
| 24 |
desc.wrap(interface) |
| 25 |
return desc |
| 26 |
|
| 27 |
|
| 28 |
cpdef saslanonymous_get_interface(): |
| 29 |
cdef c_sasl_mechanism.SASL_MECHANISM_INTERFACE_DESCRIPTION* io_desc |
| 30 |
io_desc = c_sasl_mechanism.saslanonymous_get_interface() |
| 31 |
if <void*>io_desc == NULL: |
| 32 |
raise ValueError("Failed to create SASL Anonymous Interface description") |
| 33 |
|
| 34 |
interface = SASLMechanismInterfaceDescription() |
| 35 |
interface.wrap(io_desc) |
| 36 |
return interface |
| 37 |
|
| 38 |
|
| 39 |
cpdef saslplain_get_interface(): |
| 40 |
cdef c_sasl_mechanism.SASL_MECHANISM_INTERFACE_DESCRIPTION* io_desc |
| 41 |
io_desc = c_sasl_mechanism.saslplain_get_interface() |
| 42 |
if <void*>io_desc == NULL: |
| 43 |
raise ValueError("Failed to create SASL plain Interface description") |
| 44 |
|
| 45 |
interface = SASLMechanismInterfaceDescription() |
| 46 |
interface.wrap(io_desc) |
| 47 |
return interface |
| 48 |
|
| 49 |
|
| 50 |
cpdef get_sasl_mechanism(SASLMechanismInterfaceDescription interface=None): |
| 51 |
if interface is None: |
| 52 |
interface = _get_sasl_mechanism_interface() |
| 53 |
sasl_mechanism = SASLMechanism() |
| 54 |
sasl_mechanism.create(interface) |
| 55 |
return sasl_mechanism |
| 56 |
|
| 57 |
|
| 58 |
cpdef get_plain_sasl_mechanism(SASLMechanismInterfaceDescription interface, SASLPlainConfig parameters): |
| 59 |
_logger.debug("Creating SASL Mechanism") |
| 60 |
sasl_mechanism = SASLMechanism() |
| 61 |
sasl_mechanism.create_with_parameters(interface, ¶meters._c_value) |
| 62 |
return sasl_mechanism |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
cdef class SASLMechanism(StructBase): |
| 67 |
|
| 68 |
cdef c_sasl_mechanism.SASL_MECHANISM_HANDLE _c_value |
| 69 |
|
| 70 |
def __cinit__(self): |
| 71 |
pass |
| 72 |
|
| 73 |
def __dealloc__(self): |
| 74 |
_logger.debug("Deallocating SASLMechanism") |
| 75 |
self.destroy() |
| 76 |
|
| 77 |
cdef _create(self): |
| 78 |
if <void*>self._c_value is NULL: |
| 79 |
self._memory_error() |
| 80 |
|
| 81 |
cpdef destroy(self): |
| 82 |
if <void*>self._c_value is not NULL: |
| 83 |
_logger.debug("Destroying SASLMechanism") |
| 84 |
c_sasl_mechanism.saslmechanism_destroy(self._c_value) |
| 85 |
self._c_value = <c_sasl_mechanism.SASL_MECHANISM_HANDLE>NULL |
| 86 |
|
| 87 |
cdef wrap(self, c_sasl_mechanism.SASL_MECHANISM_HANDLE value): |
| 88 |
self.destroy() |
| 89 |
self._c_value = value |
| 90 |
self._create() |
| 91 |
|
| 92 |
cdef create(self, SASLMechanismInterfaceDescription sasl_mechanism_interface_description): |
| 93 |
self.destroy() |
| 94 |
self._c_value = c_sasl_mechanism.saslmechanism_create(sasl_mechanism_interface_description._c_value, NULL) |
| 95 |
self._create() |
| 96 |
|
| 97 |
cdef create_with_parameters(self, SASLMechanismInterfaceDescription sasl_mechanism_interface_description, void *parameters): |
| 98 |
self.destroy() |
| 99 |
self._c_value = c_sasl_mechanism.saslmechanism_create(sasl_mechanism_interface_description._c_value, parameters) |
| 100 |
self._create() |
| 101 |
|
| 102 |
|
| 103 |
cdef class SASLMechanismInterfaceDescription(object): |
| 104 |
|
| 105 |
cdef c_sasl_mechanism.SASL_MECHANISM_INTERFACE_DESCRIPTION* _c_value |
| 106 |
|
| 107 |
def __cinit__(self): |
| 108 |
pass |
| 109 |
|
| 110 |
cdef wrap(self, c_sasl_mechanism.SASL_MECHANISM_INTERFACE_DESCRIPTION* value): |
| 111 |
self._c_value = value |
| 112 |
|
| 113 |
|
| 114 |
cdef class SASLClientIOConfig(object): |
| 115 |
|
| 116 |
cdef c_sasl_mechanism.SASLCLIENTIO_CONFIG _c_value |
| 117 |
cdef XIO _underlying_io |
| 118 |
|
| 119 |
def __cinit__(self, XIO underlying_io, SASLMechanism sasl_mechanism): |
| 120 |
if <void*>underlying_io._c_value is NULL: |
| 121 |
raise ValueError("UnderLying IO must not be NULL") |
| 122 |
if <void*>sasl_mechanism._c_value is NULL: |
| 123 |
raise ValueError("SASL Mechanism must not be NULL") |
| 124 |
|
| 125 |
self._underlying_io = underlying_io |
| 126 |
self._c_value = c_sasl_mechanism.SASLCLIENTIO_CONFIG( |
| 127 |
<c_xio.XIO_HANDLE>underlying_io._c_value, |
| 128 |
<c_sasl_mechanism.SASL_MECHANISM_HANDLE>sasl_mechanism._c_value |
| 129 |
) |
| 130 |
|
| 131 |
|
| 132 |
cdef class SASLPlainConfig(object): |
| 133 |
|
| 134 |
cdef c_sasl_mechanism.SASL_PLAIN_CONFIG _c_value |
| 135 |
|
| 136 |
def __cinit__(self): |
| 137 |
self._c_value = c_sasl_mechanism.SASL_PLAIN_CONFIG(NULL, NULL, NULL) |
| 138 |
self._c_value.authcid = NULL |
| 139 |
self._c_value.passwd = NULL |
| 140 |
self._c_value.authzid = NULL |
| 141 |
|
| 142 |
@property |
| 143 |
def authcid(self): |
| 144 |
return self._c_value.authcid |
| 145 |
|
| 146 |
@authcid.setter |
| 147 |
def authcid(self, const char* value): |
| 148 |
self._c_value.authcid = value |
| 149 |
|
| 150 |
@property |
| 151 |
def passwd(self): |
| 152 |
return self._c_value.passwd |
| 153 |
|
| 154 |
@passwd.setter |
| 155 |
def passwd(self, const char* value): |
| 156 |
self._c_value.passwd = value |
| 157 |
|
| 158 |
@property |
| 159 |
def authzid(self): |
| 160 |
return self._c_value.authzid |
| 161 |
|
| 162 |
@authzid.setter |
| 163 |
def authzid(self, const char* value): |
| 164 |
self._c_value.authzid = value |