Skip to content

Commit

Permalink
Implement inquire_mechs_for_name in low-level API
Browse files Browse the repository at this point in the history
This commit implements the inquire_mechs_for_name method
from RFC 2744, and adds a simple test as well.

Closes #10
  • Loading branch information
DirectXMan12 committed Dec 18, 2014
1 parent 6b4a24d commit 4ffaaa0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gssapi/raw/misc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
9 changes: 9 additions & 0 deletions gssapi/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4ffaaa0

Please sign in to comment.