diff --git a/gssapi/raw/misc.pyx b/gssapi/raw/misc.pyx index 8f3e9ca8..de343942 100644 --- a/gssapi/raw/misc.pyx +++ b/gssapi/raw/misc.pyx @@ -6,6 +6,7 @@ import six from gssapi.raw.cython_types cimport * from gssapi.raw.cython_converters cimport c_create_oid_list +from gssapi.raw.names cimport Name from gssapi.raw.oids cimport OID from gssapi.raw.types import MechType @@ -26,6 +27,10 @@ cdef extern from "gssapi.h": const gss_OID mech_type, gss_OID_set *name_types) + OM_uint32 gss_inquire_mechs_for_name(OM_uint32 *minor_status, + const gss_name_t input_name, + gss_OID_set *mech_types) + def indicate_mechs(): """ @@ -76,6 +81,35 @@ def inquire_names_for_mech(OID mech_type not None): raise GSSError(maj_stat, min_stat) +def inquire_mechs_for_name(Name name not None): + """List the mechanisms which can process a name. + + This method lists the mechanisms which may be able to + process the given name. + + Args: + name (Name): the name in question + + Returns: + list: the mechanism OIDs able to process the given name + + Raises: + GSSError + """ + + cdef gss_OID_set mech_types + + cdef OM_uint32 maj_stat, min_stat + + maj_stat = gss_inquire_mechs_for_name(&min_stat, name.raw_name, + &mech_types) + + if maj_stat == GSS_S_COMPLETE: + return c_create_oid_list(mech_types) + else: + raise GSSError(maj_stat, min_stat) + + def _display_status(unsigned int error_code, bint is_major_code, OID mech_type=None, unsigned int message_context=0): """ diff --git a/gssapi/tests/test_raw.py b/gssapi/tests/test_raw.py index e51ff2bc..fa831c18 100644 --- a/gssapi/tests/test_raw.py +++ b/gssapi/tests/test_raw.py @@ -371,6 +371,15 @@ def test_inquire_names_for_mech(self): res.shouldnt_be_none() res.should_include(gb.NameType.kerberos_principal) + def test_inquire_mechs_for_name(self): + name = gb.import_name(self.USER_PRINC, + gb.NameType.kerberos_principal) + + res = gb.inquire_mechs_for_name(name) + + res.shouldnt_be_none() + res.should_include(gb.MechType.kerberos) + class TestIntEnumFlagSet(unittest.TestCase): def test_create_from_int(self):