Skip to content

Commit d3b83e8

Browse files
sigmarisDirectXMan12
authored andcommitted
Use GSS.framework on Mac OS X
On Mac OS X, Apple wants us to use the GSS.framework to compile against GSSAPI, instead of <gssapi/gssapi.h>. With this change we can choose headers to link against at compile time, without changing our source and header files.
1 parent 416d20c commit d3b83e8

19 files changed

+59
-39
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ include *.txt
22
recursive-include docs *.txt
33
recursive-include gssapi *.pxd
44
recursive-include gssapi *.c
5+
recursive-include gssapi *.h

gssapi/raw/creds.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from gssapi.raw.named_tuples import AcquireCredResult, AddCredResult
1313
from gssapi.raw.named_tuples import InquireCredResult, InquireCredByMechResult
1414

1515

16-
cdef extern from "gssapi.h":
16+
cdef extern from "python_gssapi.h":
1717
OM_uint32 gss_acquire_cred(OM_uint32 *min_stat,
1818
const gss_name_t name,
1919
OM_uint32 ttl,

gssapi/raw/cython_types.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from libc.stdint cimport uint32_t
22

33

4-
cdef extern from "gssapi.h":
4+
cdef extern from "python_gssapi.h":
55
# basic types
66
ctypedef uint32_t OM_uint32
77

gssapi/raw/exceptions.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from gssapi.raw.misc import GSSError
55
"""Specific exceptions for GSSAPI errors"""
66

77

8-
cdef extern from "gssapi.h":
8+
cdef extern from "python_gssapi.h":
99
# calling errors
1010
OM_uint32 GSS_S_CALL_INACCESSIBLE_READ
1111
OM_uint32 GSS_S_CALL_INACCESSIBLE_WRITE

gssapi/raw/ext_cred_imp_exp.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from gssapi.raw.misc import GSSError
1212
from gssapi.raw.named_tuples import AcquireCredResult, AddCredResult
1313

1414

15-
cdef extern from "gssapi/gssapi_ext.h":
15+
cdef extern from "python_gssapi_ext.h":
1616
OM_uint32 gss_export_cred(OM_uint32 *min_stat, gss_cred_id_t cred_handle,
1717
gss_buffer_t token) nogil
1818

gssapi/raw/ext_cred_store.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from gssapi.raw.named_tuples import StoreCredResult
1818
from gssapi.raw.misc import GSSError
1919

2020

21-
cdef extern from "gssapi/gssapi_ext.h":
21+
cdef extern from "python_gssapi_ext.h":
2222
ctypedef struct gss_key_value_element_desc:
2323
const char *key
2424
const char *value

gssapi/raw/ext_password.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from gssapi.raw.names cimport Name
1515
from gssapi.raw.misc import GSSError
1616
from gssapi.raw.named_tuples import AcquireCredResult
1717

18-
cdef extern from "gssapi/gssapi_ext.h":
18+
cdef extern from "python_gssapi_ext.h":
1919
OM_uint32 gss_acquire_cred_with_password(OM_uint32 *min_stat,
2020
const gss_name_t desired_name,
2121
const gss_buffer_t password,

gssapi/raw/ext_password_add.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from gssapi.raw.oids cimport OID
1616
from gssapi.raw.misc import GSSError
1717
from gssapi.raw.named_tuples import AddCredResult
1818

19-
cdef extern from "gssapi/gssapi_ext.h":
19+
cdef extern from "python_gssapi_ext.h":
2020
OM_uint32 gss_add_cred_with_password(OM_uint32 *min_stat,
2121
const gss_cred_id_t input_cred_handle,
2222
const gss_name_t desired_name,

gssapi/raw/ext_rfc5588.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from gssapi.raw.cython_converters cimport c_c_ttl_to_py, c_py_ttl_to_c
1111
from gssapi.raw.named_tuples import StoreCredResult
1212
from gssapi.raw.misc import GSSError
1313

14-
cdef extern from "gssapi.h":
14+
cdef extern from "python_gssapi.h":
1515
OM_uint32 gss_store_cred(OM_uint32 *min_stat,
1616
gss_cred_id_t input_creds,
1717
gss_cred_usage_t cred_usage,

gssapi/raw/ext_s4u.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from gssapi.raw.misc import GSSError
1212
from gssapi.raw.named_tuples import AcquireCredResult, AddCredResult
1313

1414

15-
cdef extern from "gssapi/gssapi_ext.h":
15+
cdef extern from "python_gssapi_ext.h":
1616
OM_uint32 gss_acquire_cred_impersonate_name(OM_uint32 *min_stat,
1717
const gss_cred_id_t imp_creds,
1818
const gss_name_t name,

gssapi/raw/mech_krb5.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and MechType.
1313
"""
1414

1515

16-
cdef extern from "gssapi/gssapi_krb5.h":
16+
cdef extern from "python_gssapi_krb5.h":
1717
gss_OID gss_mech_krb5
1818
gss_OID GSS_KRB5_NT_PRINCIPAL_NAME
1919

gssapi/raw/message.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from gssapi.raw.misc import GSSError
77
from gssapi.raw.named_tuples import VerifyMICResult, WrapResult, UnwrapResult
88

99

10-
cdef extern from "gssapi.h":
10+
cdef extern from "python_gssapi.h":
1111
OM_uint32 gss_get_mic(OM_uint32 *min_stat,
1212
const gss_ctx_id_t context,
1313
gss_qop_t qop,

gssapi/raw/misc.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from gssapi.raw.oids cimport OID
1212
from gssapi.raw.types import MechType
1313

1414

15-
cdef extern from "gssapi.h":
15+
cdef extern from "python_gssapi.h":
1616
OM_uint32 gss_display_status(OM_uint32 *minor_status,
1717
OM_uint32 status_value,
1818
int status_type,

gssapi/raw/names.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from gssapi.raw.misc import GSSError
77
from gssapi.raw.named_tuples import DisplayNameResult
88

99

10-
cdef extern from "gssapi.h":
10+
cdef extern from "python_gssapi.h":
1111
OM_uint32 gss_import_name(OM_uint32 *min_stat,
1212
const gss_buffer_t input_buffer,
1313
const gss_OID name_type,

gssapi/raw/python_gssapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifdef OSX_HAS_GSS_FRAMEWORK
2+
#include <GSS/GSS.h>
3+
#else
4+
#include <gssapi/gssapi.h>
5+
#endif

gssapi/raw/python_gssapi_ext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifdef OSX_HAS_GSS_FRAMEWORK
2+
#include <GSS/GSS.h>
3+
#else
4+
#ifdef HAS_GSSAPI_EXT_H
5+
#include <gssapi/gssapi_ext.h>
6+
#else
7+
#include <gssapi/gssapi.h>
8+
#endif
9+
#endif

gssapi/raw/python_gssapi_krb5.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifdef OSX_HAS_GSS_FRAMEWORK
2+
#include <GSS/gssapi_krb5.h>
3+
#else
4+
#include <gssapi/gssapi_krb5.h>
5+
#endif

gssapi/raw/sec_contexts.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from gssapi.raw.named_tuples import InitSecContextResult
1616
from gssapi.raw.named_tuples import InquireContextResult
1717

1818

19-
cdef extern from "gssapi.h":
19+
cdef extern from "python_gssapi.h":
2020
OM_uint32 gss_init_sec_context(OM_uint32 *min_stat,
2121
const gss_cred_id_t initiator_creds,
2222
gss_ctx_id_t *context,

setup.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from setuptools.command.build_ext import build_ext
66
from setuptools.command.sdist import sdist
77
from setuptools.extension import Extension
8+
import platform
89
import re
910
import sys
1011
import os
@@ -21,7 +22,7 @@
2122
print("Building from Cython files...", file=sys.stderr)
2223
SOURCE_EXT = 'pyx'
2324
except ImportError:
24-
print("Cython not found, building from Cython files...",
25+
print("Cython not found, building from C files...",
2526
file=sys.stderr)
2627
SOURCE_EXT = 'c'
2728

@@ -43,12 +44,22 @@ def _get_output(*args, **kwargs):
4344
# get the compile and link args
4445
link_args = os.environ.get('GSSAPI_LINKER_ARGS', None)
4546
compile_args = os.environ.get('GSSAPI_COMPILER_ARGS', None)
47+
osx_has_gss_framework = False
48+
if sys.platform == 'darwin':
49+
mac_ver = [int(v) for v in platform.mac_ver()[0].split('.')]
50+
osx_has_gss_framework = (mac_ver >= [10, 7, 0])
4651

4752
if link_args is None:
48-
link_args = get_output('krb5-config --libs gssapi')
53+
if osx_has_gss_framework:
54+
link_args = '-framework GSS'
55+
else:
56+
link_args = get_output('krb5-config --libs gssapi')
4957

5058
if compile_args is None:
51-
compile_args = get_output('krb5-config --cflags gssapi')
59+
if osx_has_gss_framework:
60+
compile_args = '-framework GSS -DOSX_HAS_GSS_FRAMEWORK'
61+
else:
62+
compile_args = get_output('krb5-config --cflags gssapi')
5263

5364
link_args = link_args.split()
5465
compile_args = compile_args.split()
@@ -57,42 +68,31 @@ def _get_output(*args, **kwargs):
5768
(os.environ.get('GSSAPI_SUPPORT_DETECT', 'true').lower() == 'true')
5869

5970
if ENABLE_SUPPORT_DETECTION:
71+
import ctypes.util
72+
6073
main_lib = os.environ.get('GSSAPI_MAIN_LIB', None)
61-
if main_lib is None:
74+
if main_lib is None and osx_has_gss_framework:
75+
main_lib = ctypes.util.find_library('GSS')
76+
elif main_lib is None:
6277
for opt in link_args:
6378
if opt.startswith('-lgssapi'):
6479
main_lib = 'lib%s.so' % opt[2:]
6580

6681
if main_lib is None:
67-
raise Exception("Could not find main GSSAPI shared libary. Please "
82+
raise Exception("Could not find main GSSAPI shared library. Please "
6883
"try setting GSSAPI_MAIN_LIB yourself or setting "
6984
"ENABLE_SUPPORT_DETECTION to 'false'")
7085

71-
import ctypes
7286
GSSAPI_LIB = ctypes.CDLL(main_lib)
7387

7488

7589
class build_gssapi_ext(build_ext):
7690
def run(self):
77-
if not self.dry_run:
78-
# optionally fake gssapi_ext.h using gssapi.h
79-
prefix = get_output('krb5-config gssapi --prefix')
80-
gssapi_ext_h = os.path.join(prefix, 'include/gssapi/gssapi_ext.h')
81-
82-
if not os.path.exists(gssapi_ext_h):
83-
target_dir = os.path.join(self.build_temp, 'c_include')
84-
gssapi_dir = os.path.join(target_dir, 'gssapi')
85-
if not os.path.exists(gssapi_dir):
86-
os.makedirs(gssapi_dir)
87-
88-
target_file = os.path.join(target_dir, 'gssapi/gssapi_ext.h')
89-
if not os.path.exists(target_file):
90-
with open(target_file, 'w') as header:
91-
header.write('#include "gssapi.h"')
92-
93-
for ext in self.extensions:
94-
ext.extra_compile_args.append("-I%s" %
95-
os.path.abspath(target_dir))
91+
prefix = get_output('krb5-config gssapi --prefix')
92+
gssapi_ext_h = os.path.join(prefix, 'include/gssapi/gssapi_ext.h')
93+
if os.path.exists(gssapi_ext_h):
94+
for ext in self.extensions:
95+
ext.extra_compile_args.append("-DHAS_GSSAPI_EXT_H")
9696

9797
build_ext.run(self)
9898

0 commit comments

Comments
 (0)