auth:creds: Check return code of cli_credentials_guess()
[samba.git] / wscript_configure_system_heimdal
1 import sys
2 from waflib import Logs
3
4 conf.RECURSE('source4/heimdal_build')
5
6 heimdal_includedirs = []
7 heimdal_libdirs = []
8 krb5_config = conf.find_program("krb5-config.heimdal", var="HEIMDAL_KRB5_CONFIG")
9 if not krb5_config:
10     krb5_config = conf.find_program("krb5-config", var="HEIMDAL_KRB5_CONFIG")
11 if krb5_config:
12     # Not ideal, but seems like the best way to get at these paths:
13     f = open(krb5_config[0], 'r')
14     try:
15         for l in f:
16             if l.startswith("libdir="):
17                 heimdal_libdirs.append(l.strip()[len("libdir="):])
18             elif l.startswith("includedir="):
19                 include_path = l.strip()[len("includedir="):]
20                 heimdal_includedirs.append(include_path)
21                 conf.ADD_EXTRA_INCLUDES(include_path)
22                 conf.define('HEIMDAL_KRB5_TYPES_PATH',
23                             include_path + "/krb5-types.h")
24     finally:
25         f.close()
26
27 def check_system_heimdal_lib(name, functions='', headers='', onlyif=None):
28     # Only use system library if the user requested the bundled one not be
29     # used.
30     if conf.LIB_MAY_BE_BUNDLED(name):
31         return False
32     setattr(conf.env, "CPPPATH_%s" % name.upper(), heimdal_includedirs)
33     setattr(conf.env, "LIBPATH_%s" % name.upper(), heimdal_libdirs)
34     if not conf.CHECK_BUNDLED_SYSTEM(name, checkfunctions=functions, headers=headers,
35                                      onlyif=onlyif):
36         return False
37     conf.define('USING_SYSTEM_%s' % name.upper(), 1)
38     return True
39
40 def check_system_heimdal_binary(name):
41     if conf.LIB_MAY_BE_BUNDLED(name):
42         return False
43     if not conf.find_program(name, var=name.upper()):
44         return False
45     conf.define('USING_SYSTEM_%s' % name.upper(), 1)
46     return True
47
48 check_system_heimdal_lib("com_err", "com_right_r com_err", "com_err.h")
49
50 if check_system_heimdal_lib("roken", "rk_socket_set_reuseaddr", "roken.h"):
51     conf.env.CPPPATH_ROKEN_HOSTCC = conf.env.CPPPATH_ROKEN
52     conf.env.LIBPATH_ROKEN_HOSTCC = conf.env.LIBPATH_ROKEN
53     conf.env.LIB_ROKEN_HOSTCC = "roken"
54     conf.SET_TARGET_TYPE("ROKEN_HOSTCC", 'SYSLIB')
55
56 # Make sure HAVE_CONFIG_H is unset, as the system Heimdal headers use it
57 # and include config.h if it is set, resulting in failure (since config.h
58 # doesn't yet exist)
59
60 DEFINES = list(conf.env.DEFINES)
61 conf.undefine("HAVE_CONFIG_H")
62 while "HAVE_CONFIG_H=1" in conf.env.DEFINES:
63     conf.env.DEFINES.remove("HAVE_CONFIG_H=1")
64 try:
65     check_system_heimdal_lib("wind", "wind_stringprep", "wind.h", onlyif="roken")
66     check_system_heimdal_lib("hx509", "hx509_bitstring_print", "hx509.h", onlyif="roken wind")
67     check_system_heimdal_lib("asn1", "initialize_asn1_error_table", "asn1_err.h", onlyif="roken com_err")
68     check_system_heimdal_lib("heimbase", "heim_cmp", "heimbase.h", onlyif="roken")
69     check_system_heimdal_lib("hcrypto", "MD4_Init", "hcrypto/md4.h",
70         onlyif="asn1 roken com_err")
71     if check_system_heimdal_lib("krb5", "krb5_anyaddr", "krb5.h",
72         onlyif="roken wind asn1 hx509 hcrypto com_err heimbase"):
73         conf.CHECK_FUNCS_IN('krb5_free_unparsed_name', 'krb5', headers="krb5.h")
74     check_system_heimdal_lib("gssapi", "gss_oid_to_name", "gssapi.h",
75         onlyif="hcrypto asn1 roken krb5 com_err wind")
76     check_system_heimdal_lib("heimntlm", "heim_ntlm_ntlmv2_key", "heimntlm.h",
77         onlyif="roken hcrypto krb5")
78     if check_system_heimdal_lib("hdb", "hdb_db_dir", "krb5.h hdb.h",
79         onlyif="roken krb5 hcrypto com_err wind"):
80         conf.CHECK_CODE('''
81             #include <hdb.h>
82             int main(void) { hdb_enctype2key(NULL, NULL, NULL, 0, NULL); }
83             ''',
84             define='HDB_ENCTYPE2KEY_TAKES_KEYSET',
85             addmain=False,
86             lib='hdb',
87             msg='Checking whether hdb_enctype2key takes a keyset argument',
88             local_include=False)
89
90     check_system_heimdal_lib("kdc", "kdc_log", "kdc.h",
91         onlyif="roken krb5 hdb asn1 heimntlm hcrypto com_err wind heimbase")
92 finally:
93     conf.env.DEFINES = DEFINES
94
95 # With the proper checks in place we should be able to build against the system libtommath.
96 #if conf.CHECK_BUNDLED_SYSTEM('tommath', checkfunctions='mp_init', headers='tommath.h'):
97 #    conf.define('USING_SYSTEM_TOMMATH', 1)
98
99 check_system_heimdal_binary("compile_et")
100 check_system_heimdal_binary("asn1_compile")
101
102 conf.env.KRB5_VENDOR = 'heimdal'
103 conf.define('USING_SYSTEM_KRB5', 1)
104 conf.define('USING_SYSTEM_HEIMDAL', 1)