|
| 1 | +from gssapi.raw.cython_types cimport * |
| 2 | +from gssapi.raw.oids cimport OID |
| 3 | +from gssapi.raw.cython_converters cimport c_create_oid_set |
| 4 | +GSSAPI="BASE" # This ensures that a full module is generated by Cython |
| 5 | + |
| 6 | +from gssapi.raw.cython_converters cimport c_get_mech_oid_set |
| 7 | + |
| 8 | +from gssapi.raw.named_tuples import InquireAttrsResult, DisplayAttrResult |
| 9 | +from gssapi.raw.misc import GSSError |
| 10 | + |
| 11 | +cdef extern from "python_gssapi_ext.h": |
| 12 | + OM_uint32 gss_indicate_mechs_by_attrs( |
| 13 | + OM_uint32 *minor_status, |
| 14 | + const gss_OID_set desired_mech_attrs, |
| 15 | + const gss_OID_set except_mech_attrs, |
| 16 | + const gss_OID_set critical_mech_attrs, |
| 17 | + gss_OID_set *mechs) |
| 18 | + |
| 19 | + OM_uint32 gss_inquire_attrs_for_mech( |
| 20 | + OM_uint32 *minor_status, |
| 21 | + const gss_OID mech, |
| 22 | + gss_OID_set *mech_attrs, |
| 23 | + gss_OID_set *known_mech_attrs) |
| 24 | + |
| 25 | + OM_uint32 gss_display_mech_attr( |
| 26 | + OM_uint32 *minor_status, |
| 27 | + const gss_OID mech_attr, |
| 28 | + gss_buffer_t name, |
| 29 | + gss_buffer_t short_desc, |
| 30 | + gss_buffer_t long_desc) |
| 31 | + |
| 32 | + |
| 33 | +def indicate_mechs_by_attrs(desired_mech_attrs=None, except_mech_attrs=None, |
| 34 | + critical_mech_attrs=None): |
| 35 | + cdef OM_uint32 maj_stat, min_stat |
| 36 | + cdef gss_OID_set desired_attrs = GSS_C_NO_OID_SET |
| 37 | + cdef gss_OID_set except_attrs = GSS_C_NO_OID_SET |
| 38 | + cdef gss_OID_set critical_attrs = GSS_C_NO_OID_SET |
| 39 | + cdef gss_OID_set mechs |
| 40 | + |
| 41 | + if desired_mech_attrs is not None: |
| 42 | + desired_attrs = c_get_mech_oid_set(desired_mech_attrs) |
| 43 | + |
| 44 | + if except_mech_attrs is not None: |
| 45 | + except_attrs = c_get_mech_oid_set(except_mech_attrs) |
| 46 | + |
| 47 | + if critical_mech_attrs is not None: |
| 48 | + critical_attrs = c_get_mech_oid_set(critical_mech_attrs) |
| 49 | + |
| 50 | + maj_stat = gss_indicate_mechs_by_attrs(&min_stat, desired_attrs, |
| 51 | + except_attrs, critical_attrs, |
| 52 | + &mechs) |
| 53 | + |
| 54 | + if maj_stat == GSS_S_COMPLETE: |
| 55 | + return c_create_oid_set(mechs) |
| 56 | + else: |
| 57 | + raise GSSError(maj_stat, min_stat) |
| 58 | + |
| 59 | + |
| 60 | +def inquire_attrs_for_mech(OID mech): |
| 61 | + cdef OM_uint32 maj_stat, min_stat |
| 62 | + cdef gss_OID m = GSS_C_NO_OID |
| 63 | + cdef gss_OID_set mech_attrs = GSS_C_NO_OID_SET |
| 64 | + cdef gss_OID_set known_mech_attrs = GSS_C_NO_OID_SET |
| 65 | + |
| 66 | + if mech is not None: |
| 67 | + m = &mech.raw_oid |
| 68 | + |
| 69 | + maj_stat = gss_inquire_attrs_for_mech(&min_stat, m, &mech_attrs, |
| 70 | + &known_mech_attrs) |
| 71 | + |
| 72 | + if maj_stat == GSS_S_COMPLETE: |
| 73 | + return InquireAttrsResult(c_create_oid_set(mech_attrs), |
| 74 | + c_create_oid_set(known_mech_attrs)) |
| 75 | + else: |
| 76 | + raise GSSError(maj_stat, min_stat) |
| 77 | + |
| 78 | + |
| 79 | +def display_mech_attr(OID attr): |
| 80 | + cdef OM_uint32 maj_stat, min_stat |
| 81 | + cdef gss_OID a = GSS_C_NO_OID |
| 82 | + cdef gss_buffer_desc name |
| 83 | + cdef gss_buffer_desc short_desc |
| 84 | + cdef gss_buffer_desc long_desc |
| 85 | + |
| 86 | + if attr is not None: |
| 87 | + a = &attr.raw_oid |
| 88 | + |
| 89 | + maj_stat = gss_display_mech_attr(&min_stat, a, &name, &short_desc, |
| 90 | + &long_desc) |
| 91 | + |
| 92 | + if maj_stat == GSS_S_COMPLETE: |
| 93 | + out_name = name.value[:name.length].decode("UTF-8") |
| 94 | + out_short = short_desc.value[:short_desc.length].decode("UTF-8") |
| 95 | + out_long = long_desc.value[:long_desc.length].decode("UTF-8") |
| 96 | + |
| 97 | + gss_release_buffer(&min_stat, &name) |
| 98 | + gss_release_buffer(&min_stat, &short_desc) |
| 99 | + gss_release_buffer(&min_stat, &long_desc) |
| 100 | + |
| 101 | + return DisplayAttrResult(out_name, out_short, out_long) |
| 102 | + else: |
| 103 | + raise GSSError(maj_stat, min_stat) |
0 commit comments