Skip to content

Commit 44dcf22

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

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

gssapi/raw/misc.pyx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ cdef extern from "gssapi.h":
2222
OM_uint32 gss_indicate_mechs(OM_uint32 *minor_status,
2323
gss_OID_set *mech_set)
2424

25+
OM_uint32 gss_inquire_names_for_mech(OM_uint32 *minor_status,
26+
const gss_OID mech_type,
27+
gss_OID_set *name_types)
28+
2529

2630
def indicate_mechs():
2731
"""
@@ -43,6 +47,35 @@ def indicate_mechs():
4347
raise GSSError(maj_stat, min_stat)
4448

4549

50+
def inquire_names_for_mech(OID mech_type not None):
51+
"""Get the name types supported by a mechanism.
52+
53+
This method retrives the different name types supported by
54+
the given mechanism.
55+
56+
Args:
57+
mech_type (OID): the mechanism in question
58+
59+
Returns:
60+
list: the name type OIDs supported by the given mechanism
61+
62+
Raises:
63+
GSSError
64+
"""
65+
66+
cdef gss_OID_set name_types
67+
68+
cdef OM_uint32 maj_stat, min_stat
69+
70+
maj_stat = gss_inquire_names_for_mech(&min_stat, &mech_type.raw_oid,
71+
&name_types)
72+
73+
if maj_stat == GSS_S_COMPLETE:
74+
return c_create_oid_set(name_types)
75+
else:
76+
raise GSSError(maj_stat, min_stat)
77+
78+
4679
def _display_status(unsigned int error_code, bint is_major_code,
4780
OID mech_type=None, unsigned int message_context=0):
4881
"""

gssapi/tests/test_raw.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ def test_error_dispatch(self):
365365
err.should_be_a(gb.NameReadError)
366366
err.maj_code.should_be(err_code1 | err_code2)
367367

368+
def test_inquire_names_for_mech(self):
369+
res = gb.inquire_names_for_mech(gb.MechType.kerberos)
370+
371+
res.shouldnt_be_none()
372+
res.should_include(gb.NameType.kerberos_principal)
373+
368374

369375
class TestIntEnumFlagSet(unittest.TestCase):
370376
def test_create_from_int(self):

0 commit comments

Comments
 (0)