Skip to content

Commit 2359d72

Browse files
committed
Split pname_to_uid into its own module
Not available on Windows. Include it conditionally to prevent build errors on Windows. Signed-off-by: Jacob Henner <code@ventricle.us>
1 parent 39b3677 commit 2359d72

7 files changed

Lines changed: 89 additions & 69 deletions

File tree

gssapi/raw/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,9 @@
156156
from gssapi.raw.ext_localname_attr import * # noqa
157157
except ImportError:
158158
pass
159+
160+
# optional pname_to_uid support (not available on Windows)
161+
try:
162+
from gssapi.raw.ext_pname_to_uid import * # noqa
163+
except ImportError:
164+
pass

gssapi/raw/ext_localname.pyi

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,3 @@ def authorize_localname(
6666
Raises:
6767
~gssapi.exceptions.GSSError
6868
"""
69-
70-
71-
def pname_to_uid(
72-
name: "Name",
73-
mech: t.Optional["OID"] = None,
74-
) -> int:
75-
"""Get the local UID for a GSSAPI name.
76-
77-
This method determines the local UID associated with a GSSAPI
78-
name, optionally for a given mechanism.
79-
80-
Note:
81-
This function is not available on Windows.
82-
83-
Args:
84-
name (Name): the GSSAPI name to map to a local UID
85-
mech (~gssapi.OID): the mechanism to use for the mapping
86-
(or None for the default)
87-
88-
Returns:
89-
int: the local UID
90-
91-
Raises:
92-
~gssapi.exceptions.GSSError
93-
"""

gssapi/raw/ext_localname.pyx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ from gssapi.raw.oids cimport OID
77
from gssapi.raw.misc import GSSError
88
from gssapi import _utils
99

10-
from posix.types cimport uid_t
11-
1210
cdef extern from "python_gssapi_ext.h":
1311
OM_uint32 gss_localname(OM_uint32 *minor,
1412
const gss_name_t name,
@@ -22,11 +20,6 @@ cdef extern from "python_gssapi_ext.h":
2220
const gss_name_t name,
2321
const gss_name_t user) nogil
2422

25-
OM_uint32 gss_pname_to_uid(OM_uint32 *minor,
26-
const gss_name_t name,
27-
const gss_OID mech_type,
28-
uid_t *uid_out) nogil
29-
3023

3124
def localname(Name name not None, OID mech=None):
3225
"""Get the local name for a GSSAPI name.
@@ -118,39 +111,3 @@ def authorize_localname(Name name not None, Name user not None):
118111
return True
119112
else:
120113
raise GSSError(maj_stat, min_stat)
121-
122-
123-
def pname_to_uid(Name name not None, OID mech=None):
124-
"""Get the local UID for a GSSAPI name.
125-
126-
This method determines the local UID associated with a GSSAPI
127-
name, optionally for a given mechanism.
128-
129-
Note:
130-
This function is not available on Windows.
131-
132-
Args:
133-
name (Name): the GSSAPI name to map to a local UID
134-
mech (~gssapi.OID): the mechanism to use for the mapping
135-
(or None for the default)
136-
137-
Returns:
138-
int: the local UID
139-
140-
Raises:
141-
~gssapi.exceptions.GSSError
142-
"""
143-
cdef gss_OID m = GSS_C_NO_OID
144-
if mech is not None:
145-
m = &mech.raw_oid
146-
147-
cdef uid_t uid_out
148-
cdef OM_uint32 maj_stat, min_stat
149-
150-
with nogil:
151-
maj_stat = gss_pname_to_uid(&min_stat, name.raw_name, m, &uid_out)
152-
153-
if maj_stat == GSS_S_COMPLETE:
154-
return uid_out
155-
else:
156-
raise GSSError(maj_stat, min_stat)

gssapi/raw/ext_pname_to_uid.pyi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import typing as t
2+
3+
if t.TYPE_CHECKING:
4+
from gssapi.raw.names import Name
5+
from gssapi.raw.oids import OID
6+
7+
8+
def pname_to_uid(
9+
name: "Name",
10+
mech: t.Optional["OID"] = None,
11+
) -> int:
12+
"""Get the local UID for a GSSAPI name.
13+
14+
This method determines the local UID associated with a GSSAPI
15+
name, optionally for a given mechanism.
16+
17+
Note:
18+
This function is not available on Windows.
19+
20+
Args:
21+
name (Name): the GSSAPI name to map to a local UID
22+
mech (~gssapi.OID): the mechanism to use for the mapping
23+
(or None for the default)
24+
25+
Returns:
26+
int: the local UID
27+
28+
Raises:
29+
~gssapi.exceptions.GSSError
30+
"""

gssapi/raw/ext_pname_to_uid.pyx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
GSSAPI="BASE" # This ensures that a full module is generated by Cython
2+
3+
from posix.types cimport uid_t
4+
5+
from gssapi.raw.cython_types cimport *
6+
from gssapi.raw.names cimport Name
7+
from gssapi.raw.oids cimport OID
8+
9+
from gssapi.raw.misc import GSSError
10+
11+
cdef extern from "python_gssapi_ext.h":
12+
OM_uint32 gss_pname_to_uid(OM_uint32 *minor,
13+
const gss_name_t name,
14+
const gss_OID mech_type,
15+
uid_t *uid_out) nogil
16+
17+
18+
def pname_to_uid(Name name not None, OID mech=None):
19+
"""Get the local UID for a GSSAPI name.
20+
21+
This method determines the local UID associated with a GSSAPI
22+
name, optionally for a given mechanism.
23+
24+
Note:
25+
This function is not available on Windows.
26+
27+
Args:
28+
name (Name): the GSSAPI name to map to a local UID
29+
mech (~gssapi.OID): the mechanism to use for the mapping
30+
(or None for the default)
31+
32+
Returns:
33+
int: the local UID
34+
35+
Raises:
36+
~gssapi.exceptions.GSSError
37+
"""
38+
cdef gss_OID m = GSS_C_NO_OID
39+
if mech is not None:
40+
m = &mech.raw_oid
41+
42+
cdef uid_t uid_out
43+
cdef OM_uint32 maj_stat, min_stat
44+
45+
with nogil:
46+
maj_stat = gss_pname_to_uid(&min_stat, name.raw_name, m, &uid_out)
47+
48+
if maj_stat == GSS_S_COMPLETE:
49+
return uid_out
50+
else:
51+
raise GSSError(maj_stat, min_stat)

gssapi/tests/test_raw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ def test_authorize_localname_fails(self):
13761376
self.assertRaises(gb.GSSError, gb.authorize_localname,
13771377
canon_name, fake_local_name)
13781378

1379-
@ktu.gssapi_extension_test('localname', 'Local Name')
1379+
@ktu.gssapi_extension_test('pname_to_uid', 'pname_to_uid')
13801380
def test_pname_to_uid(self):
13811381
base_name = gb.import_name(self.USER_PRINC,
13821382
gb.NameType.kerberos_principal)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def gssapi_modules(lst):
379379

380380
extension_file('localname', 'gss_localname'),
381381
extension_file('localname_attr', 'GSS_C_ATTR_LOCAL_LOGIN_USER'),
382+
extension_file('pname_to_uid', 'gss_pname_to_uid'),
382383
]),
383384
options=setup_options,
384385
keywords=['gssapi', 'security'],

0 commit comments

Comments
 (0)