third_party: Fix a typo in the option name
[samba.git] / third_party / uid_wrapper / wscript
1 #!/usr/bin/env python
2
3 import Options
4 import os, sys
5
6 VERSION="1.2.4"
7
8 def configure(conf):
9     if conf.CHECK_UID_WRAPPER():
10         conf.DEFINE('USING_SYSTEM_UID_WRAPPER', 1)
11         libuid_wrapper_so_path = 'libuid_wrapper.so'
12     else:
13         # check HAVE_GCC_ATOMIC_BUILTINS
14         conf.CHECK_CODE('''
15             #include <stdbool.h>
16             int main(void) {
17                 bool x;
18                 bool *p_x = &x;
19                 __atomic_load(p_x, &x, __ATOMIC_RELAXED);
20                 return 0;
21             ''',
22             'HAVE_GCC_ATOMIC_BUILTINS',
23             addmain=False,
24             msg='Checking for atomic builtins')
25
26         # check HAVE_GCC_THREAD_LOCAL_STORAGE
27         conf.CHECK_CODE('''
28             __thread int tls;
29
30             int main(void) {
31                 return 0;
32             }
33             ''',
34             'HAVE_GCC_THREAD_LOCAL_STORAGE',
35             addmain=False,
36             msg='Checking for thread local storage')
37
38         if Options.options.address_sanitizer:
39             # check HAVE_ADDRESS_SANITIZER_ATTRIBUTE
40             conf.CHECK_CODE('''
41                 void test_address_sanitizer_attribute(void) __attribute__((no_sanitize_address));
42
43                 void test_address_sanitizer_attribute(void)
44                 {
45                     return;
46                 }
47
48                 int main(void) {
49                     return 0;
50                 }
51                 ''',
52                 'HAVE_ADDRESS_SANITIZER_ATTRIBUTE',
53                 addmain=False,
54                 cflags='-Wall -Wextra -Werror',
55                 msg='Checking for address sanitizer attribute')
56
57         # check HAVE_FUNCTION_ATTRIBUTE_FORMAT
58         conf.CHECK_CODE('''
59             void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
60
61             int main(void) {
62                 return 0;
63             }
64             ''',
65             'HAVE_FUNCTION_ATTRIBUTE_FORMAT',
66             addmain=False,
67             msg='Checking for printf format validation support')
68         # Prototype checks
69         conf.CHECK_C_PROTOTYPE('setgroups',
70                         'int setgroups(int ngroups, const gid_t *grouplist)',
71                         define='HAVE_SETGROUPS_INT', headers='unistd.h sys/types.h')
72         conf.CHECK_C_PROTOTYPE('syscall',
73                         'int syscall(int number, ...)',
74                         define='HAVE_SYSCALL_INT', headers='unistd.h sys/syscall.h')
75
76         if (sys.platform.rfind('linux') > -1):
77             conf.CHECK_CODE('''
78 #if defined(HAVE_UNISTD_H)
79 #include <unistd.h>
80 #endif
81 #include <stdlib.h>
82 #include <stdio.h>
83 #include <sys/types.h>
84 #include <errno.h>
85
86 #ifdef HAVE_SYS_PRIV_H
87 #include <sys/priv.h>
88 #endif
89 #ifdef HAVE_SYS_ID_H
90 #include <sys/id.h>
91 #endif
92
93 #if defined(HAVE_SYSCALL_H)
94 #include <syscall.h>
95 #endif
96
97 #if defined(HAVE_SYS_SYSCALL_H)
98 #include <sys/syscall.h>
99 #endif
100
101 syscall(SYS_setresuid32, -1, -1, -1);
102 syscall(SYS_setresgid32, -1, -1, -1);
103 syscall(SYS_setreuid32, -1, -1);
104 syscall(SYS_setregid32, -1, -1);
105 syscall(SYS_setuid32, -1);
106 syscall(SYS_setgid32, -1);
107 syscall(SYS_setgroups32, 0, NULL);
108 ''',
109                 'HAVE_LINUX_32BIT_SYSCALLS',
110                 msg="Checking whether Linux has 32-bit credential calls");
111
112         conf.CHECK_FUNCS('getresuid getresgid')
113
114         # Create full path to uid_wrapper
115         blddir = os.path.realpath(conf.blddir)
116         libuid_wrapper_so_path = blddir + '/default/third_party/uid_wrapper/libuid-wrapper.so'
117
118     conf.DEFINE('LIBUID_WRAPPER_SO_PATH', libuid_wrapper_so_path)
119     conf.DEFINE('UID_WRAPPER', 1)
120
121 def build(bld):
122     if not bld.CONFIG_SET("USING_SYSTEM_UID_WRAPPER"):
123         # We need to do it this way or the library wont work.
124         # Using private_library=True will add symbol version which
125         # breaks preloading!
126         bld.SAMBA_LIBRARY('uid_wrapper',
127                           source='uid_wrapper.c',
128                           deps='dl',
129                           install=False,
130                           realname='libuid-wrapper.so')