|
| 1 | +from gssapi.raw.cython_types cimport * |
| 2 | +from gssapi.raw.oids cimport OID |
| 3 | +GSSAPI="BASE" # This ensures that a full module is generated by Cython |
| 4 | + |
| 5 | +from gssapi.raw.cython_converters cimport c_make_oid |
| 6 | + |
| 7 | +from gssapi.raw.named_tuples import InquireSASLNameResult |
| 8 | +from gssapi.raw.misc import GSSError |
| 9 | + |
| 10 | +cdef extern from "python_gssapi_ext.h": |
| 11 | + OM_uint32 gss_inquire_saslname_for_mech( |
| 12 | + OM_uint32 *min_stat, |
| 13 | + const gss_OID desired_mech, |
| 14 | + gss_buffer_t sasl_mech_name, |
| 15 | + gss_buffer_t mech_name, |
| 16 | + gss_buffer_t mech_description) nogil |
| 17 | + |
| 18 | + OM_uint32 gss_inquire_mech_for_saslname( |
| 19 | + OM_uint32 *min_stat, |
| 20 | + const gss_buffer_t sasl_mech_name, |
| 21 | + gss_OID *mech_type) nogil |
| 22 | + |
| 23 | + |
| 24 | +def inquire_saslname_for_mech(OID mech): |
| 25 | + """ |
| 26 | + inquire_saslname_for_mech(mech) |
| 27 | + Gets information about a specified mech, including the SASL name, |
| 28 | + the mech name, and the mech description. |
| 29 | +
|
| 30 | + Args: |
| 31 | + mech (OID): Mechanism to inquire about |
| 32 | +
|
| 33 | + Returns: |
| 34 | + InquireSASLNameResult: the results of inquiry; a mech's SASL name, |
| 35 | + name, and description. |
| 36 | + """ |
| 37 | + cdef OM_uint32 maj_stat, min_stat |
| 38 | + cdef gss_buffer_desc sasl_mech_name |
| 39 | + cdef gss_buffer_desc mech_name |
| 40 | + cdef gss_buffer_desc mech_desc |
| 41 | + cdef gss_OID m = GSS_C_NO_OID |
| 42 | + |
| 43 | + if mech is not None: |
| 44 | + m = &mech.raw_oid |
| 45 | + |
| 46 | + with nogil: |
| 47 | + maj_stat = gss_inquire_saslname_for_mech(&min_stat, m, &sasl_mech_name, |
| 48 | + &mech_name, &mech_desc) |
| 49 | + |
| 50 | + if maj_stat == GSS_S_COMPLETE: |
| 51 | + out_smn = sasl_mech_name.value[:sasl_mech_name.length] |
| 52 | + out_mn = mech_name.value[:mech_name.length] |
| 53 | + out_md = mech_desc.value[:mech_desc.length] |
| 54 | + |
| 55 | + gss_release_buffer(&min_stat, &sasl_mech_name) |
| 56 | + gss_release_buffer(&min_stat, &mech_name) |
| 57 | + gss_release_buffer(&min_stat, &mech_desc) |
| 58 | + |
| 59 | + return InquireSASLNameResult(out_smn, out_mn, out_md) |
| 60 | + else: |
| 61 | + raise GSSError(maj_stat, min_stat) |
| 62 | + |
| 63 | + |
| 64 | +def inquire_mech_for_saslname(bytes sasl_name): |
| 65 | + """ |
| 66 | + inquire_mech_for_saslname(sasl_name) |
| 67 | + Gets the OID for the mech specified by SASL name. |
| 68 | +
|
| 69 | + Args: |
| 70 | + sasl_name (bytes): SASL name of the mechanism |
| 71 | +
|
| 72 | + Returns: |
| 73 | + OID: the mechanism with corresponding SASL name. |
| 74 | + """ |
| 75 | + cdef OM_uint32 maj_stat, min_stat |
| 76 | + cdef gss_buffer_desc sn |
| 77 | + cdef gss_OID m |
| 78 | + |
| 79 | + sn.length = len(sasl_name) |
| 80 | + sn.value = sasl_name |
| 81 | + |
| 82 | + with nogil: |
| 83 | + maj_stat = gss_inquire_mech_for_saslname(&min_stat, &sn, &m) |
| 84 | + |
| 85 | + if maj_stat == GSS_S_COMPLETE: |
| 86 | + return c_make_oid(m) |
| 87 | + else: |
| 88 | + raise GSSError(maj_stat, min_stat) |
0 commit comments