autoconf: enable full RELRO in cifs-utils binaries
[jlayton/cifs-utils.git] / configure.ac
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_INIT([cifs-utils], [5.8.1], [linux-cifs@vger.kernel.org], [cifs-utils], [https://wiki.samba.org/index.php/LinuxCIFS_utils])
5 AC_CONFIG_SRCDIR([replace.h])
6 AC_CONFIG_HEADERS([config.h])
7 AC_CONFIG_FILES([Makefile contrib/Makefile contrib/request-key.d/Makefile])
8 AC_CONFIG_MACRO_DIR(aclocal)
9
10 AM_INIT_AUTOMAKE
11
12 # "enable" options
13 AC_ARG_ENABLE(pie,
14         [AC_HELP_STRING([--enable-pie],
15                         [Produce position independent executables @<:@default=yes@:>@])],
16         enable_pie=$enableval,
17         enable_pie="maybe")
18
19 AC_ARG_ENABLE(relro,
20         [AC_HELP_STRING([--enable-relro],
21                         [Enable relocations read-only support @<:@default=yes@:>@])],
22         enable_relro=$enableval,
23         enable_relro="maybe")
24
25 AC_ARG_ENABLE(cifsupcall,
26         [AC_HELP_STRING([--enable-cifsupcall],
27                         [Create cifs.upcall binary @<:@default=yes@:>@])],
28         enable_cifsupcall=$enableval,
29         enable_cifsupcall="maybe")
30
31 AC_ARG_ENABLE(cifscreds,
32         [AC_HELP_STRING([--enable-cifscreds],
33                         [Create cifscreds utility @<:@default=yes@:>@])],
34         enable_cifscreds=$enableval,
35         enable_cifscreds="maybe")
36
37 AC_ARG_ENABLE(cifsidmap,
38         [AC_HELP_STRING([--enable-cifsidmap],
39                         [Create cifs.idmap binary @<:@default=yes@:>@])],
40         enable_cifsidmap=$enableval,
41         enable_cifsidmap="maybe")
42
43 AC_ARG_ENABLE(cifsacl,
44         [AC_HELP_STRING([--enable-cifsacl],
45                         [Create get/set cifsacl binary @<:@default=yes@:>@])],
46         enable_cifsacl=$enableval,
47         enable_cifsacl="maybe")
48
49 AC_ARG_ENABLE(systemd,
50         [AC_HELP_STRING([--enable-systemd],
51                         [Enable systemd specific behavior for mount.cifs @<:@default=yes@:>@])],
52         enable_systemd=$enableval,
53         enable_systemd="maybe")
54
55 # check for ROOTSBINDIR environment var
56 if test -z $ROOTSBINDIR; then
57         ROOTSBINDIR="/sbin"
58         export ROOTSBINDIR
59 fi
60
61 AC_ARG_VAR(ROOTSBINDIR, [Location where files ordinarily under /sbin should be installed. Note: unaffected by --prefix. @<:@default=/sbin@:>@])
62
63 # Checks for programs.
64 AC_PROG_CC
65 AC_GNU_SOURCE
66 AM_PROG_CC_C_O
67
68 # AC_PROG_SED is only avaliable in recent autoconf versions.
69 # Use AC_CHECK_PROG instead if AC_PROG_SED is not present.
70 ifdef([AC_PROG_SED],
71       [AC_PROG_SED],
72       [AC_CHECK_PROG(SED, sed, sed)])
73
74 # Checks for typedefs, structures, and compiler characteristics.
75 AC_HEADER_STDBOOL
76 AC_TYPE_UID_T
77 AC_TYPE_OFF_T
78 AC_TYPE_PID_T
79 AC_TYPE_SIZE_T
80 AC_CHECK_TYPES([ptrdiff_t, ssize_t, uint32_t, uint8_t])
81
82 # Checks for library functions.
83 AC_FUNC_GETMNTENT
84 AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
85 AC_FUNC_MALLOC
86 AC_FUNC_REALLOC
87 AC_FUNC_STRNLEN
88
89 # check for required functions
90 AC_CHECK_FUNCS([alarm atexit endpwent getmntent getpass gettimeofday inet_ntop memset realpath setenv strchr strcmp strdup strerror strncasecmp strndup strpbrk strrchr strstr strtol strtoul tolower uname], , [AC_MSG_ERROR([necessary functions(s) not found])])
91
92 AC_CHECK_FUNCS(clock_gettime, [], [
93   AC_CHECK_LIB(rt, clock_gettime, [
94       AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
95         AC_DEFINE(HAVE_CLOCK_GETTIME,1,
96                 [Whether the clock_gettime func is there])
97       LIBS="$LIBS -lrt"
98         ])
99   ])
100
101 # Checks for header files.
102 AC_CHECK_HEADERS([arpa/inet.h ctype.h fcntl.h inttypes.h limits.h mntent.h netdb.h stddef.h stdint.h stdbool.h stdlib.h stdio.h errno.h string.h strings.h sys/mount.h sys/param.h sys/socket.h sys/time.h syslog.h unistd.h], , [AC_MSG_ERROR([necessary header(s) not found])])
103
104 # do we have sys/fsuid.h and setfsuid()?
105 AC_CHECK_HEADERS([sys/fsuid.h])
106 AC_CHECK_FUNC(setfsuid, , [AC_MSG_ERROR([System does not support setfsuid()])])
107
108 # FIXME: add test(s) to autodisable these flags when compiler/linker don't support it
109 if test $enable_pie != "no"; then
110         PIE_CFLAGS="-fpie -pie"
111 else
112         PIE_CFLAGS=""
113 fi
114 AC_SUBST([PIE_CFLAGS])
115
116 if test $enable_relro != "no"; then
117         RELRO_CFLAGS="-Wl,-z,relro,-z,now"
118 else
119         RELRO_CFLAGS=""
120 fi
121 AC_SUBST([RELRO_CFLAGS])
122
123 if test $enable_cifsupcall != "no"; then
124         AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
125         if test x$ac_cv_header_krb5_krb5_h != xyes ; then
126                 if test x$ac_cv_header_krb5_h != xyes ; then
127                         if test "$enable_cifsupcall" = "yes"; then
128                                 AC_MSG_ERROR([krb5.h not found, consider installing krb5-libs-devel.])
129                         else
130                                 AC_MSG_WARN([krb5.h not found, consider installing krb5-libs-devel. Disabling cifs.upcall.])
131                                 enable_cifsupcall="no"
132                         fi
133                 fi
134         fi
135 fi
136 if test $enable_cifsupcall != "no"; then
137         if test x$ac_cv_header_krb5_krb5_h = xyes ; then
138                 krb5_include="#include <krb5/krb5.h>"
139         fi
140         if test x$ac_cv_header_krb5_h = xyes ; then
141                 krb5_include="#include <krb5.h>"
142         fi
143
144         AC_CACHE_CHECK([for keyvalue in krb5_keyblock],
145                 [ac_cv_have_krb5_keyblock_keyvalue],[
146                         AC_TRY_COMPILE([$krb5_include],
147                         [krb5_keyblock key; key.keyvalue.data = NULL;],
148                         ac_cv_have_krb5_keyblock_keyvalue=yes,
149                         ac_cv_have_krb5_keyblock_keyvalue=no)])
150         if test x"$ac_cv_have_krb5_keyblock_keyvalue" = x"yes" ; then
151                 AC_DEFINE(HAVE_KRB5_KEYBLOCK_KEYVALUE,1,
152                         [Whether the krb5_keyblock struct has a keyvalue property])
153         fi
154 fi
155 if test $enable_cifsupcall != "no"; then
156         AC_CHECK_HEADERS([talloc.h], , [
157                                 if test "$enable_cifsupcall" = "yes"; then
158                                         AC_MSG_ERROR([talloc.h not found, consider installing libtalloc-devel.])
159                                 else
160                                         AC_MSG_WARN([talloc.h not found, consider installing libtalloc-devel. Disabling cifs.upcall.])
161                                         enable_cifsupcall="no"
162                                 fi
163                         ])
164 fi
165 if test $enable_cifsupcall != "no" -o $enable_cifsidmap != "no"; then
166         AC_CHECK_HEADERS([keyutils.h], , [
167                                 if test "$enable_cifsupcall" = "yes"; then
168                                         AC_MSG_ERROR([keyutils.h not found, consider installing keyutils-libs-devel.])
169                                 else
170                                         AC_MSG_WARN([keyutils.h not found, consider installing keyutils-libs-devel. Disabling cifs.upcall.])
171                                         enable_cifsupcall="no"
172                                 fi
173                                 if test "$enable_cifsidmap" = "yes"; then
174                                         AC_MSG_ERROR([keyutils.h not found, consider installing keyutils-libs-devel.])
175                                 else
176                                         AC_MSG_WARN([keyutils.h not found, consider installing keyutils-libs-devel. Disabling cifs.idmap.])
177                                         enable_cifsidmap="no"
178                                 fi
179                         ])
180 fi
181 if test $enable_cifsupcall != "no"; then
182         AC_CHECK_LIB([krb5], [krb5_init_context],
183                         [ KRB5_LDADD='-lkrb5' ],
184                         AC_MSG_ERROR([no functioning krb5 library found!]))
185         AC_SUBST(KRB5_LDADD)
186 fi
187
188 # checks for wbclient.h and libwbclient.so library
189 AC_TEST_WBCHL
190
191 if test $enable_cifscreds != "no"; then
192         AC_CHECK_HEADERS([keyutils.h], , [
193
194                                 if test $enable_cifscreds = "yes"; then
195                                         AC_MSG_ERROR([keyutils.h not found, consider installing keyutils-libs-devel.])
196                                 else
197                                         AC_MSG_WARN([keyutils.h not found, consider installing keyutils-libs-devel. Disabling cifscreds.])
198                                         enable_cifscreds="no"
199                                 fi
200                         ])
201 fi
202
203
204 # ugly, but I'm not sure how to check for functions in a library that's not in $LIBS
205 cu_saved_libs=$LIBS
206 LIBS="$LIBS $KRB5_LDADD"
207
208 # determine whether we can use MIT's new 'krb5_auth_con_getsendsubkey' to extract the signing key
209 if test $enable_cifsupcall != "no"; then
210         AC_CHECK_FUNCS([krb5_auth_con_getsendsubkey])
211 fi
212
213 # non-critical functions (we have workarounds for these)
214 if test $enable_cifsupcall != "no"; then
215         AC_CHECK_FUNCS([krb5_principal_get_realm krb5_free_unparsed_name])
216         AC_CHECK_FUNCS([krb5_auth_con_setaddrs krb5_auth_con_set_req_cksumtype])
217 fi
218
219 if test $enable_systemd != "no"; then
220         AC_DEFINE(ENABLE_SYSTEMD, 1, [Enable systemd specific behavior for mount.cifs])
221 fi
222
223 # MIT krb5 < 1.7 does not have this declaration but does have the symbol
224 AC_CHECK_DECLS(krb5_auth_con_set_req_cksumtype, [], [], [#include <krb5.h>])
225
226 LIBS=$cu_saved_libs
227
228 AM_CONDITIONAL(CONFIG_CIFSUPCALL, [test "$enable_cifsupcall" != "no"])
229 AM_CONDITIONAL(CONFIG_CIFSCREDS, [test "$enable_cifscreds" != "no"])
230 AM_CONDITIONAL(CONFIG_CIFSIDMAP, [test "$enable_cifsidmap" != "no"])
231 AM_CONDITIONAL(CONFIG_CIFSACL, [test "$enable_cifsacl" != "no"])
232
233 LIBCAP_NG_PATH
234
235 if test "x$CAPNG_LDADD" = "x"; then
236         AC_LIBCAP
237 fi
238 AC_OUTPUT