Skip to content

Commit c439330

Browse files
committed
Implement inquire_mechs_for_name in low-level API
This commit implements the inquire_mechs_for_name method from RFC 2744, and adds a simple test as well. Closes #10
1 parent 44dcf22 commit c439330

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

gssapi/raw/misc.pyx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import six
66

77
from gssapi.raw.cython_types cimport *
88
from gssapi.raw.cython_converters cimport c_create_oid_set
9+
from gssapi.raw.names cimport Name
910
from gssapi.raw.oids cimport OID
1011

1112
from gssapi.raw.types import MechType
@@ -26,6 +27,10 @@ cdef extern from "gssapi.h":
2627
const gss_OID mech_type,
2728
gss_OID_set *name_types)
2829

30+
OM_uint32 gss_inquire_mechs_for_name(OM_uint32 *minor_status,
31+
const gss_name_t input_name,
32+
gss_OID_set *mech_types)
33+
2934

3035
def indicate_mechs():
3136
"""
@@ -76,6 +81,35 @@ def inquire_names_for_mech(OID mech_type not None):
7681
raise GSSError(maj_stat, min_stat)
7782

7883

84+
def inquire_mechs_for_name(Name name not None):
85+
"""List the mechanisms which can process a name.
86+
87+
This method lists the mechanisms which may be able to
88+
process the given name.
89+
90+
Args:
91+
name (Name): the name in question
92+
93+
Returns:
94+
list: the mechanism OIDs able to process the given name
95+
96+
Raises:
97+
GSSError
98+
"""
99+
100+
cdef gss_OID_set mech_types
101+
102+
cdef OM_uint32 maj_stat, min_stat
103+
104+
maj_stat = gss_inquire_mechs_for_name(&min_stat, name.raw_name,
105+
&mech_types)
106+
107+
if maj_stat == GSS_S_COMPLETE:
108+
return c_create_oid_set(mech_types)
109+
else:
110+
raise GSSError(maj_stat, min_stat)
111+
112+
79113
def _display_status(unsigned int error_code, bint is_major_code,
80114
OID mech_type=None, unsigned int message_context=0):
81115
"""

gssapi/tests/test_raw.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ def test_inquire_names_for_mech(self):
371371
res.shouldnt_be_none()
372372
res.should_include(gb.NameType.kerberos_principal)
373373

374+
def test_inquire_mechs_for_name(self):
375+
name = gb.import_name(self.USER_PRINC,
376+
gb.NameType.kerberos_principal)
377+
378+
res = gb.inquire_mechs_for_name(name)
379+
380+
res.shouldnt_be_none()
381+
res.should_include(gb.MechType.kerberos)
382+
374383

375384
class TestIntEnumFlagSet(unittest.TestCase):
376385
def test_create_from_int(self):

0 commit comments

Comments
 (0)