uid_wrapper: Be strict when checking __attribute__ features
[metze/samba/wip.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',
55                 strict=True,
56                 msg='Checking for address sanitizer attribute')
57
58         # check HAVE_FUNCTION_ATTRIBUTE_FORMAT
59         conf.CHECK_CODE('''
60             void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
61
62             int main(void) {
63                 return 0;
64             }
65             ''',
66             'HAVE_FUNCTION_ATTRIBUTE_FORMAT',
67             addmain=False,
68             strict=True,
69             msg='Checking for printf format validation support')
70         # Prototype checks
71         conf.CHECK_C_PROTOTYPE('setgroups',
72                         'int setgroups(int ngroups, const gid_t *grouplist)',
73                         define='HAVE_SETGROUPS_INT', headers='unistd.h sys/types.h')
74         conf.CHECK_C_PROTOTYPE('syscall',
75                         'int syscall(int number, ...)',
76                         define='HAVE_SYSCALL_INT', headers='unistd.h sys/syscall.h')
77
78         if (sys.platform.rfind('linux') > -1):
79             conf.CHECK_CODE('''
80 #if defined(HAVE_UNISTD_H)
81 #include <unistd.h>
82 #endif
83 #include <stdlib.h>
84 #include <stdio.h>
85 #include <sys/types.h>
86 #include <errno.h>
87
88 #ifdef HAVE_SYS_PRIV_H
89 #include <sys/priv.h>
90 #endif
91 #ifdef HAVE_SYS_ID_H
92 #include <sys/id.h>
93 #endif
94
95 #if defined(HAVE_SYSCALL_H)
96 #include <syscall.h>
97 #endif
98
99 #if defined(HAVE_SYS_SYSCALL_H)
100 #include <sys/syscall.h>
101 #endif
102
103 syscall(SYS_setresuid32, -1, -1, -1);
104 syscall(SYS_setresgid32, -1, -1, -1);
105 syscall(SYS_setreuid32, -1, -1);
106 syscall(SYS_setregid32, -1, -1);
107 syscall(SYS_setuid32, -1);
108 syscall(SYS_setgid32, -1);
109 syscall(SYS_setgroups32, 0, NULL);
110 ''',
111                 'HAVE_LINUX_32BIT_SYSCALLS',
112                 msg="Checking whether Linux has 32-bit credential calls");
113
114         conf.CHECK_FUNCS('getresuid getresgid')
115
116         # Create full path to uid_wrapper
117         blddir = os.path.realpath(conf.blddir)
118         libuid_wrapper_so_path = blddir + '/default/third_party/uid_wrapper/libuid-wrapper.so'
119
120     conf.DEFINE('LIBUID_WRAPPER_SO_PATH', libuid_wrapper_so_path)
121     conf.DEFINE('UID_WRAPPER', 1)
122
123 def build(bld):
124     if not bld.CONFIG_SET("USING_SYSTEM_UID_WRAPPER"):
125         # We need to do it this way or the library wont work.
126         # Using private_library=True will add symbol version which
127         # breaks preloading!
128         bld.SAMBA_LIBRARY('uid_wrapper',
129                           source='uid_wrapper.c',
130                           deps='dl',
131                           install=False,
132                           realname='libuid-wrapper.so')