Debian Codegraph @

m4/sudo.m4

raw
1 dnl Local m4 macros for autoconf (used by sudo)
2 dnl
3 dnl SPDX-License-Identifier: ISC
4 dnl
5 dnl Copyright (c) 1994-1996, 1998-2005, 2007-2023
6 dnl Todd C. Miller <[email protected]>
7 dnl
8 dnl Permission to use, copy, modify, and distribute this software for any
9 dnl purpose with or without fee is hereby granted, provided that the above
10 dnl copyright notice and this permission notice appear in all copies.
11 dnl
12 dnl THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 dnl WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 dnl MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 dnl ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 dnl
20
21 dnl
22 dnl check for sendmail in well-known locations
23 dnl
24 AC_ARG_VAR([SENDMAILPROG], [The fully-qualified path to the sendmail program to use.])
25 AC_DEFUN([SUDO_PROG_SENDMAIL], [
26 AC_PATH_PROG([SENDMAILPROG], [sendmail], [], [/usr/sbin$PATH_SEPARATOR/usr/lib$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/usr/ucblib$PATH_SEPARATOR/usr/local/lib$PATH_SEPARATOR/usr/local/bin])
27 test -n "${ac_cv_path_SENDMAILPROG}" && SUDO_DEFINE_UNQUOTED(_PATH_SUDO_SENDMAIL, "${ac_cv_path_SENDMAILPROG}")
28 ])dnl
29
30 dnl
31 dnl check for vi in well-known locations
32 dnl
33 AC_ARG_VAR([VIPROG], [The fully-qualified path to the vi program to use.])
34 AC_DEFUN([SUDO_PROG_VI], [
35 AC_PATH_PROG([VIPROG], [vi], [], [/usr/bin$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/ucb$PATH_SEPARATOR/usr/bsd$PATH_SEPARATOR/usr/local/bin])
36 test -n "${ac_cv_path_VIPROG}" && SUDO_DEFINE_UNQUOTED(_PATH_VI, "${ac_cv_path_VIPROG}")
37 ])dnl
38
39 dnl
40 dnl check for mv in well-known locations
41 dnl
42 AC_ARG_VAR([MVPROG], [The fully-qualified path to the mv program to use.])
43 AC_DEFUN([SUDO_PROG_MV], [
44 AC_PATH_PROG([MVPROG], [mv], [], [/usr/bin$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/ucb$PATH_SEPARATOR/usr/local/bin])
45 test -n "${ac_cv_path_MVPROG}" && SUDO_DEFINE_UNQUOTED(_PATH_MV, "${ac_cv_path_MVPROG}")
46 ])dnl
47
48 dnl
49 dnl check for bourne shell in well-known locations
50 dnl
51 AC_ARG_VAR([BSHELLPROG], [The fully-qualified path to the Bourne shell to use.])
52 AC_DEFUN([SUDO_PROG_BSHELL], [
53 AC_PATH_PROG([BSHELLPROG], [sh], [/usr/bin$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
54 test -n "${ac_cv_path_BSHELLPROG}" && SUDO_DEFINE_UNQUOTED(_PATH_BSHELL, "${ac_cv_path_BSHELLPROG}")
55 ])dnl
56
57 dnl
58 dnl Check for path to utmp file if not using getutid(), etc.
59 dnl
60 AC_DEFUN([SUDO_PATH_UTMP], [
61 AC_CACHE_CHECK([for utmp file path], [sudo_cv_path_UTMP], [
62 sudo_cv_path_UTMP=no
63 for p in "/var/run/utmp" "/var/adm/utmp" "/etc/utmp"; do
64 if test -r "$p"; then
65 sudo_cv_path_UTMP="$p"
66 break
67 fi
68 done
69 ])
70 if test X"$sudo_cv_path_UTMP" != X"no"; then
71 SUDO_DEFINE_UNQUOTED(_PATH_UTMP, "$sudo_cv_path_UTMP")
72 fi
73 ])
74
75 dnl
76 dnl Where the log file goes, use /var/log if it exists, else /{var,usr}/adm
77 dnl
78 AC_DEFUN([SUDO_LOGFILE], [
79 if test -n "$with_logpath"; then
80 logpath="$with_logpath"
81 else
82 AC_CACHE_CHECK([for log file location], [sudo_cv_log_path], [
83 # Default value of logpath set in configure.ac
84 sudo_cv_log_path="$logpath"
85 for d in /var/log /var/adm /usr/adm; do
86 if test -d "$d"; then
87 sudo_cv_log_path="$d/sudo.log"
88 break
89 fi
90 done
91 ])
92 logpath="$sudo_cv_log_path"
93 fi
94 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGFILE, "$logpath")
95 ])
96
97 dnl
98 dnl Detect time zone file directory, if any.
99 dnl
100 AC_DEFUN([SUDO_TZDIR], [
101 if test -n "$with_tzdir"; then
102 tzdir="$with_tzdir"
103 else
104 AC_CACHE_CHECK([time zone data directory], [sudo_cv_tz_dir], [
105 sudo_cv_tz_dir=no
106 for d in /usr/share /usr/share/lib /usr/lib /etc; do
107 if test -d "$d/zoneinfo"; then
108 sudo_cv_tz_dir="$d/zoneinfo"
109 break
110 fi
111 done
112 ])
113 tzdir="$sudo_cv_tz_dir"
114 fi
115 if test X"$tzdir" != X"no"; then
116 SUDO_DEFINE_UNQUOTED(_PATH_ZONEINFO, "$tzdir")
117 fi
118 ])
119
120 dnl
121 dnl Parent directory for time stamp dir.
122 dnl
123 AC_DEFUN([SUDO_RUNDIR], [
124 if test -n "$with_rundir"; then
125 rundir="$with_rundir"
126 elif test -n "$runstatedir" && test "$runstatedir" != '${localstatedir}/run'; then
127 rundir="$runstatedir/sudo"
128 else
129 # No --with-rundir or --runstatedir specified
130 AC_CACHE_CHECK([for sudo run dir location], [sudo_cv_run_dir], [
131 sudo_cv_run_dir=no
132 for d in /run /var/run /var/db /var/lib /var/adm /usr/adm; do
133 if test -d "$d"; then
134 sudo_cv_run_dir="$d/sudo"
135 break
136 fi
137 done
138 ])
139 rundir="$sudo_cv_run_dir"
140 fi
141 if test X"$rundir" != X"no"; then
142 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_TIMEDIR, "$rundir/ts")
143 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGSRVD_PID, "$rundir/sudo_logsrvd.pid")
144 fi
145 ])
146
147 dnl
148 dnl Parent directory for the lecture status dir.
149 dnl
150 AC_DEFUN([SUDO_VARDIR], [
151 if test -n "$with_vardir"; then
152 vardir="$with_vardir"
153 else
154 AC_CACHE_CHECK([for sudo var dir location], [sudo_cv_var_dir], [
155 sudo_cv_var_dir=no
156 for d in /var/db /var/lib /var/adm /usr/adm; do
157 if test -d "$d"; then
158 sudo_cv_var_dir="$d/sudo"
159 break
160 fi
161 done
162 ])
163 vardir="$sudo_cv_var_dir"
164 fi
165 if test X"$vardir" != X"no"; then
166 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LECTURE_DIR, "$vardir/lectured")
167 fi
168 ])
169
170 dnl
171 dnl Where the sudo_logsrvd relay temporary log files go, use
172 dnl /var/log/sudo_logsrvd if /var/log exists, else
173 dnl /{var,usr}/adm/sudo_logsrvd
174 dnl
175 AC_DEFUN([SUDO_RELAY_DIR], [
176 if test "${with_relaydir-yes}" != "yes"; then
177 relay_dir="$with_relaydir"
178 else
179 AC_CACHE_CHECK([for sudo_logsrvd relay dir location], [sudo_cv_relay_dir], [
180 # Default value of relay_dir set in configure.ac
181 sudo_cv_relay_dir="$relay_dir"
182 for d in /var/log /var/adm /usr/adm; do
183 if test -d "$d"; then
184 sudo_cv_relay_dir="$d/sudo_logsrvd"
185 break
186 fi
187 done
188 ])
189 relay_dir="$sudo_cv_relay_dir"
190 fi
191 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_RELAY_DIR, "$relay_dir")
192 ])
193
194 dnl
195 dnl Where the I/O log files go, use /var/log/sudo-io if
196 dnl /var/log exists, else /{var,usr}/adm/sudo-io
197 dnl
198 AC_DEFUN([SUDO_IO_LOGDIR], [
199 if test "${with_iologdir-yes}" != "yes"; then
200 iolog_dir="$with_iologdir"
201 else
202 AC_CACHE_CHECK([for I/O log dir location], [sudo_cv_iolog_dir], [
203 # Default value of iolog_dir set in configure.ac
204 sudo_cv_iolog_dir="$iolog_dir"
205 for d in /var/log /var/adm /usr/adm; do
206 if test -d "$d"; then
207 sudo_cv_iolog_dir="$d/sudo-io"
208 break
209 fi
210 done
211 ])
212 iolog_dir="$sudo_cv_iolog_dir"
213 fi
214 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_IO_LOGDIR, "$iolog_dir")
215 ])
216
217 dnl
218 dnl Where the log files go, use /var/log if it exists, else /{var,usr}/adm
219 dnl
220 AC_DEFUN([SUDO_LOGDIR], [
221 if test "${with_logdir-yes}" != "yes"; then
222 log_dir="$with_logdir"
223 else
224 AC_CACHE_CHECK([for log dir location], [sudo_cv_log_dir], [
225 # Default value of log_dir set in configure.ac
226 sudo_cv_log_dir="$log_dir"
227 for d in /var/log /var/adm /usr/adm; do
228 if test -d "$d"; then
229 sudo_cv_log_dir="$d"
230 break
231 fi
232 done
233 ])
234 log_dir="$sudo_cv_log_dir"
235 fi
236 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGDIR, "$log_dir")
237 ])
238
239 dnl
240 dnl check for working fnmatch(3)
241 dnl
242 AC_DEFUN([SUDO_FUNC_FNMATCH], [
243 AC_CACHE_CHECK([for working fnmatch with FNM_CASEFOLD],
244 sudo_cv_func_fnmatch, [
245 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <fnmatch.h>
246 int main() { return(fnmatch("/*/bin/echo *", "/usr/bin/echo just a test", FNM_CASEFOLD)); }]])], [sudo_cv_func_fnmatch=yes], [sudo_cv_func_fnmatch=no], [sudo_cv_func_fnmatch=no])
247 ])
248 AS_IF([test $sudo_cv_func_fnmatch = yes], [$1], [$2])
249 ])
250
251 dnl
252 dnl Attempt to check for working PIE support.
253 dnl This is a bit of a hack but on Solaris 10 with GNU ld and GNU as
254 dnl we can end up with strange values from malloc().
255 dnl A better check would be to verify that ASLR works with PIE.
256 dnl
257 AC_DEFUN([SUDO_WORKING_PIE], [
258 AC_CACHE_CHECK([for working PIE support], sudo_cv_working_pie, [
259 AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT
260 int main() { char *p = malloc(1024); if (p == NULL) return 1; memset(p, 0, 1024); return 0; }])], [sudo_cv_working_pie=yes], [sudo_cv_working_pie=no], [sudo_cv_working_pie=no])
261 ])
262 AS_IF([test $sudo_cv_working_pie = yes], [$1], [$2])
263 ])
264
265 dnl
266 dnl check for isblank(3)
267 dnl
268 AC_DEFUN([SUDO_FUNC_ISBLANK],
269 [AC_CACHE_CHECK([for isblank], [sudo_cv_func_isblank],
270 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ctype.h>]], [[return (isblank('a'));]])],
271 [sudo_cv_func_isblank=yes], [sudo_cv_func_isblank=no])])
272 ] [
273 if test "$sudo_cv_func_isblank" = "yes"; then
274 AC_DEFINE(HAVE_ISBLANK, 1, [Define if you have isblank(3).])
275 else
276 AC_LIBOBJ(isblank)
277 SUDO_APPEND_COMPAT_EXP(isblank)
278 fi
279 ])
280
281 AC_DEFUN([SUDO_CHECK_LIB], [
282 _sudo_check_lib_extras=`echo "$5"|sed -e 's/[ ]*//g' -e 's/-l/_/g'`
283 AC_MSG_CHECKING([for $2 in -l$1${5+ }$5])
284 AC_CACHE_VAL([sudo_cv_lib_$1''_$2$_sudo_check_lib_extras], [
285 SUDO_CHECK_LIB_OLIBS="$LIBS"
286 LIBS="$LIBS -l$1${5+ }$5"
287 AC_LINK_IFELSE(
288 [AC_LANG_CALL([], [$2])],
289 [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=yes],
290 [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=no]
291 )
292 LIBS="$SUDO_CHECK_LIB_OLIBS"
293 ])
294 if eval test \$sudo_cv_lib_$1''_$2$_sudo_check_lib_extras = "yes"; then
295 AC_MSG_RESULT([yes])
296 $3
297 else
298 AC_MSG_RESULT([no])
299 $4
300 fi
301 ])
302
303 AC_DEFUN([SUDO_CHECK_NET_FUNC], [
304 _LIBS="$LIBS"
305 LIBS="${LIBS} ${NET_LIBS}"
306 found=true
307 AC_CHECK_FUNC([$1], [$2], [
308 # Look for $1 in network libraries appending to NET_LIBS as needed.
309 # May need to link with -lnsl and -lsocket due to unresolved symbols
310 found=false
311 for libs in "-lsocket" "-linet" "-lsocket -lnsl" "-lresolv"; do
312 _libs=
313 for lib in $libs; do
314 case "$NET_LIBS" in
315 *"$lib"*) ;;
316 *) _libs="$_libs $lib";;
317 esac
318 done
319 libs="${_libs# }"
320 test -z "$libs" && continue
321 lib="`echo \"$libs\"|sed -e 's/^-l//' -e 's/ .*$//'`"
322 extralibs="`echo \"$libs\"|sed 's/^-l[[^ ]]*//'`"
323 SUDO_CHECK_LIB($lib, $1, [
324 found=true
325 NET_LIBS="${NET_LIBS}${NET_LIBS+ }$libs"
326 INET_PTON_LIBS="$libs"
327 case "$libs" in
328 *-lresolv*)
329 AC_DEFINE(NEED_RESOLV_H)
330 ;;
331 esac
332 break
333 ], [], [$extralibs])
334 done
335 ])
336 LIBS="$_LIBS"
337 AS_IF([test $found = true], [$2], [$3])
338 ])
339
340 dnl
341 dnl check unsetenv() return value
342 dnl
343 AC_DEFUN([SUDO_FUNC_UNSETENV_VOID],
344 [AC_CACHE_CHECK([whether unsetenv returns void], [sudo_cv_func_unsetenv_void],
345 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [
346 [return unsetenv("FOO");]
347 ])
348 ],
349 [sudo_cv_func_unsetenv_void=no],
350 [sudo_cv_func_unsetenv_void=yes])])
351 if test $sudo_cv_func_unsetenv_void = yes; then
352 AC_DEFINE(UNSETENV_VOID, 1,
353 [Define to 1 if the 'unsetenv' function returns void instead of 'int'.])
354 fi
355 ])
356
357 dnl
358 dnl check putenv() argument for const
359 dnl
360 AC_DEFUN([SUDO_FUNC_PUTENV_CONST],
361 [AC_CACHE_CHECK([whether putenv takes a const argument], [sudo_cv_func_putenv_const],
362 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
363 int putenv(const char *string) {return 0;}
364 ], [])],
365 [sudo_cv_func_putenv_const=yes],
366 [sudo_cv_func_putenv_const=no])
367 ])
368 if test $sudo_cv_func_putenv_const = yes; then
369 AC_DEFINE(PUTENV_CONST, const, [Define to const if the 'putenv' function takes a const argument.])
370 else
371 AC_DEFINE(PUTENV_CONST, [])
372 fi
373 ])
374
375 dnl
376 dnl check if ioctl() request argument is int.
377 dnl
378 AC_DEFUN([SUDO_FUNC_IOCTL_REQ_INT],
379 [AC_CACHE_CHECK([whether ioctl() takes an int request argument], [sudo_cv_func_ioctl_req_int],
380 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
381 #include <sys/ioctl.h>
382 #include <unistd.h>
383 int ioctl(int fd, int req, ...) {return 0;}
384 ], [])],
385 [sudo_cv_func_ioctl_req_int=yes],
386 [sudo_cv_func_ioctl_req_int=no])
387 ])
388 if test $sudo_cv_func_ioctl_req_int = yes; then
389 AC_DEFINE(IOCTL_REQ_CAST, [(int)], [Define to (int) if the 'ioctl' function request takes an int request argument.])
390 else
391 AC_DEFINE(IOCTL_REQ_CAST, [])
392 fi
393 ])
394
395 dnl
396 dnl check whether au_close() takes 3 or 4 arguments
397 dnl
398 AC_DEFUN([SUDO_FUNC_AU_CLOSE_SOLARIS11],
399 [AC_CACHE_CHECK([whether au_close() takes 4 arguments],
400 sudo_cv_func_au_close_solaris11,
401 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
402 #include <bsm/audit.h>
403 #include <bsm/libbsm.h>
404 #include <bsm/audit_uevents.h>
405
406 int au_close(int d, int keep, au_event_t event, au_emod_t emod) {return 0;}], [])],
407 [sudo_cv_func_au_close_solaris11=yes],
408 [sudo_cv_func_au_close_solaris11=no])
409 ])
410 if test $sudo_cv_func_au_close_solaris11 = yes; then
411 AC_DEFINE(HAVE_AU_CLOSE_SOLARIS11, 1, [Define to 1 if the 'au_close' functions takes 4 arguments like Solaris 11.])
412 fi
413 ])
414
415 dnl
416 dnl Check if the data argument for the sha2 functions is void * or u_char *
417 dnl
418 AC_DEFUN([SUDO_FUNC_SHA2_VOID_PTR],
419 [AC_CACHE_CHECK([whether the data argument of SHA224Update() is void *],
420 sudo_cv_func_sha2_void_ptr,
421 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
422 #include <sha2.h>
423 void SHA224Update(SHA2_CTX *context, const void *data, size_t len) {return;}], [])],
424 [sudo_cv_func_sha2_void_ptr=yes],
425 [sudo_cv_func_sha2_void_ptr=no])
426 ])
427 if test $sudo_cv_func_sha2_void_ptr = yes; then
428 AC_DEFINE(SHA2_VOID_PTR, 1,
429 [Define to 1 if the sha2 functions use 'const void *' instead of 'const unsigned char'.])
430 fi
431 ])
432
433 dnl
434 dnl check for sa_len field in struct sockaddr
435 dnl
436 AC_DEFUN([SUDO_SOCK_SA_LEN], [
437 AC_CHECK_MEMBER([struct sockaddr.sa_len],
438 [AC_DEFINE(HAVE_STRUCT_SOCKADDR_SA_LEN, 1, [Define if your struct sockaddr has an sa_len field.])],
439 [], [
440 # include <sys/types.h>
441 # include <sys/socket.h>]
442 )]
443 )
444
445 dnl
446 dnl check for sin_len field in struct sockaddr_in
447 dnl
448 AC_DEFUN([SUDO_SOCK_SIN_LEN], [
449 AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
450 [AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN, 1, [Define if your struct sockaddr_in has a sin_len field.])],
451 [], [
452 # include <sys/types.h>
453 # include <sys/socket.h>]
454 )]
455 )
456
457 dnl
458 dnl There are three different utmp variants we need to check for.
459 dnl SUDO_CHECK_UTMP_MEMBERS(utmp_type)
460 dnl
461 AC_DEFUN([SUDO_CHECK_UTMP_MEMBERS], [
462 dnl
463 dnl Check for utmp/utmpx/utmps struct members.
464 dnl
465 AC_CHECK_MEMBER([struct $1.ut_id], [
466 AC_DEFINE(HAVE_STRUCT_UTMP_UT_ID, 1, [Define to 1 if 'ut_id' is a member of 'struct utmp'.])
467 ], [], [
468 # include <sys/types.h>
469 # include <$1.h>
470 ])
471 AC_CHECK_MEMBER([struct $1.ut_pid], [
472 AC_DEFINE(HAVE_STRUCT_UTMP_UT_PID, 1, [Define to 1 if 'ut_pid' is a member of 'struct utmp'.])
473 ], [], [
474 # include <sys/types.h>
475 # include <$1.h>
476 ])
477 AC_CHECK_MEMBER([struct $1.ut_tv], [
478 AC_DEFINE(HAVE_STRUCT_UTMP_UT_TV, 1, [Define to 1 if 'ut_tv' is a member of 'struct utmp'.])
479 ], [], [
480 # include <sys/types.h>
481 # include <$1.h>
482 ])
483 AC_CHECK_MEMBER([struct $1.ut_type], [
484 AC_DEFINE(HAVE_STRUCT_UTMP_UT_TYPE, 1, [Define to 1 if 'ut_type' is a member of 'struct utmp'.])
485 ], [], [
486 # include <sys/types.h>
487 # include <$1.h>
488 ])
489 dnl
490 dnl Older struct utmp has ut_name instead of ut_user
491 dnl
492 if test "$1" = "utmp"; then
493 AC_CHECK_MEMBERS([struct utmp.ut_user], [], [], [
494 # include <sys/types.h>
495 # include <$1.h>
496 ])
497 fi
498 dnl
499 dnl Check for ut_exit.__e_termination first, then ut_exit.e_termination
500 dnl We need to have already defined _GNU_SOURCE on glibc which only has
501 dnl __e_termination visible when _GNU_SOURCE is *not* defined.
502 dnl
503 AC_CHECK_MEMBER([struct $1.ut_exit.__e_termination], [
504 AC_DEFINE(HAVE_STRUCT_UTMP_UT_EXIT, 1, [Define to 1 if 'ut_exit' is a member of 'struct utmp'.])
505 AC_DEFINE(HAVE_STRUCT_UTMP_UT_EXIT___E_TERMINATION, 1, [Define to 1 if 'ut_exit.__e_termination' is a member of 'struct utmp'.])
506 ], [
507 AC_CHECK_MEMBER([struct $1.ut_exit.e_termination], [
508 AC_DEFINE(HAVE_STRUCT_UTMP_UT_EXIT, 1, [Define to 1 if 'ut_exit' is a member of 'struct utmp'.])
509 AC_DEFINE(HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION, 1, [Define to 1 if 'ut_exit.e_termination' is a member of 'struct utmp'.])
510 ], [], [
511 # include <sys/types.h>
512 # include <$1.h>
513 ])
514 ], [
515 # include <sys/types.h>
516 # include <$1.h>
517 ])
518 ])
519
520 dnl
521 dnl Append a libpath to an LDFLAGS style variable if not already present.
522 dnl Also appends to the _R version unless rpath is disabled.
523 dnl
524 AC_DEFUN([SUDO_APPEND_LIBPATH], [
525 AX_APPEND_FLAG([-L$2], [$1])
526 if test X"$enable_rpath" = X"yes"; then
527 AX_APPEND_FLAG([-R$2], [$1_R])
528 fi
529 ])
530
531 dnl
532 dnl Append one or more symbols to COMPAT_EXP
533 dnl
534 AC_DEFUN([SUDO_APPEND_COMPAT_EXP], [
535 for _sym in $1; do
536 COMPAT_EXP="${COMPAT_EXP}${_sym}
537 "
538 done
539 ])
540
541 dnl
542 dnl Append one or more symbols to INTERCEPT_EXP
543 dnl
544 AC_DEFUN([SUDO_APPEND_INTERCEPT_EXP], [
545 for _sym in $1; do
546 INTERCEPT_EXP="${INTERCEPT_EXP}${_sym}
547 "
548 done
549 ])
550
551 dnl
552 dnl Determine the mail spool location
553 dnl NOTE: must be run *after* check for paths.h
554 dnl
555 AC_DEFUN([SUDO_MAILDIR], [
556 AC_CACHE_CHECK([for the user mail spool directory], [sudo_cv_mail_dir], [
557 sudo_cv_mail_dir=no
558 if test X"$ac_cv_header_paths_h" = X"yes"; then
559 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
560 #include <paths.h>],
561 [char *p = _PATH_MAILDIR;])], [sudo_cv_mail_dir="paths.h"], [])
562 fi
563 if test $sudo_cv_mail_dir = no; then
564 # Solaris has maillock.h which defines MAILDIR
565 AC_CHECK_HEADERS(maillock.h, [
566 sudo_cv_mail_dir=maillock.h
567 ], [
568 sudo_cv_mail_dir=/var/mail
569 for d in /var/mail /var/spool/mail /usr/spool/mail; do
570 if test -d "$d"; then
571 sudo_cv_mail_dir="$d"
572 break
573 fi
574 done
575 ])
576 fi
577 ])
578 case "$sudo_cv_mail_dir" in
579 paths.h)
580 # _PATH_MAILDIR already present in paths.h.
581 ;;
582 maillock.h)
583 # Use MAILDIR from maillock.h
584 SUDO_DEFINE(_PATH_MAILDIR, MAILDIR)
585 AC_DEFINE(HAVE_MAILLOCK_H)
586 ;;
587 *)
588 SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "$sudo_cv_mail_dir")
589 ;;
590 esac
591 ])
592
593 dnl
594 dnl Create PVS-Studio.cfg for supported platforms or throw an error.
595 dnl
596 AC_DEFUN([SUDO_PVS_STUDIO_CFG], [
597 if test X"$enable_pvs_studio" = X"yes"; then
598 # Determine preprocessor type
599 case "$CC" in
600 *clang*) preprocessor=clang;;
601 *gcc*) preprocessor=gcc;;
602 *) case `$CC --version 2>&1` in
603 *clang*) preprocessor=clang;;
604 *gcc*) preprocessor=gcc;;
605 *) AC_MSG_ERROR([Compiler must be gcc or clang for PVS-Studio.]);;
606 esac
607 ;;
608 esac
609
610 # Determine platform (currently linux or macos)
611 case "$host" in
612 x86_64-*-linux*) pvs_platform=linux64;;
613 *86-*-linux*) pvs_platform=linux32;;
614 *-*-darwin*) pvs_platform=macos;;
615 *) AC_MSG_ERROR([PVS-Studio does not support $host.]);;
616 esac
617
618 # Create a basic PVS-Studio.cfg file
619 cat > PVS-Studio.cfg <<-EOF
620 preprocessor = $preprocessor
621 platform = $pvs_platform
622 analysis-mode = 4
623 language = C
624 EOF
625
626 # Check for a license file in the default location
627 if test -f "$HOME/.config/PVS-Studio/PVS-Studio.lic"; then
628 echo "lic-file = $HOME/.config/PVS-Studio/PVS-Studio.lic" >> PVS-Studio.cfg
629 fi
630 fi
631 ])
632
633 AC_DEFUN([SUDO_CPP_VARIADIC_MACROS],
634 [AC_CACHE_CHECK([for variadic macro support in cpp],
635 [sudo_cv_cpp_variadic_macros], [
636 sudo_cv_cpp_variadic_macros=yes
637 if test X"$ac_cv_prog_cc_c99" = X"no"; then
638 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
639 #if defined(__GNUC__) && __GNUC__ == 2
640 # define sudo_fprintf(fp, fmt...) fprintf((fp), (fmt))
641 #else
642 # define sudo_fprintf(fp, ...) fprintf((fp), __VA_ARGS__)
643 #endif], [sudo_fprintf(stderr, "a %s", "test");
644 ])], [], [sudo_cv_cpp_variadic_macros=no])
645 fi
646 ])
647 if test X"$sudo_cv_cpp_variadic_macros" = X"no"; then
648 AC_DEFINE([NO_VARIADIC_MACROS], [1], [Define if your C preprocessor does not support variadic macros.])
649 AC_MSG_WARN([your C preprocessor doesn't support variadic macros, debugging support will be limited])
650 SUDO_APPEND_COMPAT_EXP(sudo_debug_printf_nvm_v1)
651 fi
652 ])
653
654 dnl
655 dnl private versions of AC_DEFINE and AC_DEFINE_UNQUOTED that don't support
656 dnl tracing that we use to define paths for pathnames.h so autoheader doesn't
657 dnl put them in config.h.in. An awful hack.
658 dnl
659 m4_define([SUDO_DEFINE],
660 [cat >>confdefs.h <<\EOF
661 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
662 EOF
663 ])
664
665 m4_define([SUDO_DEFINE_UNQUOTED],
666 [cat >>confdefs.h <<EOF
667 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
668 EOF
669 ])
670
671 dnl
672 dnl Expand Makefile-style variables in $1 and store the result in $2.
673 dnl Used to expand file paths for use in man pages and pathnames.h.
674 dnl
675 AC_DEFUN([SUDO_EXPAND_PATH], [
676 $2="$1"
677 while :; do
678 $2="`echo \"$$2\" | sed -e 's/(/{/g' -e 's/)/}/g'`"
679 case "$$2" in
680 *\${[[A-Za-z]]*}*)
681 eval $2="$$2"
682 ;;
683 *)
684 break
685 ;;
686 esac
687 done
688 case "$$2" in
689 NONE/*)
690 $2="${ac_default_prefix}${$2#NONE}"
691 ;;
692 esac
693 ])
694
695 dnl
696 dnl Expand Makefile-style variables in $1, a colon-separated list of paths,
697 dnl and define the result as a string using the name $2.
698 dnl
699 AC_DEFUN([SUDO_DEFINE_PATH], [
700 as_save_IFS=$IFS
701 IFS=:
702 _sudo_define_path_res=
703 for as_dir in $1; do
704 SUDO_EXPAND_PATH([$as_dir], [_sudo_define_path_exp])
705 if test -z "${_sudo_define_path_res}"; then
706 _sudo_define_path_res="${_sudo_define_path_exp}"
707 else
708 _sudo_define_path_res="${_sudo_define_path_res}:${_sudo_define_path_exp}"
709 fi
710 done
711 IFS=$as_save_IFS
712 SUDO_DEFINE_UNQUOTED($2, "${_sudo_define_path_res}")
713 ])