]> andersk Git - openssh.git/blob - configure.ac
- (tim) [configure.ac] make some configure options a little more error proof.
[openssh.git] / configure.ac
1 # $Id$
2 #
3 # Copyright (c) 1999-2004 Damien Miller
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 AC_INIT(OpenSSH, Portable)
18 AC_CONFIG_SRCDIR([ssh.c])
19
20 AC_CONFIG_HEADER(config.h)
21 AC_PROG_CC
22 AC_CANONICAL_HOST
23 AC_C_BIGENDIAN
24
25 # Checks for programs.
26 AC_PROG_AWK
27 AC_PROG_CPP
28 AC_PROG_RANLIB
29 AC_PROG_INSTALL
30 AC_PATH_PROG(AR, ar)
31 AC_PATH_PROG(CAT, cat)
32 AC_PATH_PROG(KILL, kill)
33 AC_PATH_PROGS(PERL, perl5 perl)
34 AC_PATH_PROG(SED, sed)
35 AC_SUBST(PERL)
36 AC_PATH_PROG(ENT, ent)
37 AC_SUBST(ENT)
38 AC_PATH_PROG(TEST_MINUS_S_SH, bash)
39 AC_PATH_PROG(TEST_MINUS_S_SH, ksh)
40 AC_PATH_PROG(TEST_MINUS_S_SH, sh)
41 AC_PATH_PROG(SH, sh)
42 AC_SUBST(TEST_SHELL,sh)
43
44 dnl for buildpkg.sh
45 AC_PATH_PROG(PATH_GROUPADD_PROG, groupadd, groupadd,
46         [/usr/sbin${PATH_SEPARATOR}/etc])
47 AC_PATH_PROG(PATH_USERADD_PROG, useradd, useradd,
48         [/usr/sbin${PATH_SEPARATOR}/etc])
49 AC_CHECK_PROG(MAKE_PACKAGE_SUPPORTED, pkgmk, yes, no)
50
51 # System features
52 AC_SYS_LARGEFILE
53
54 if test -z "$AR" ; then
55         AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***])
56 fi
57
58 # Use LOGIN_PROGRAM from environment if possible
59 if test ! -z "$LOGIN_PROGRAM" ; then
60         AC_DEFINE_UNQUOTED(LOGIN_PROGRAM_FALLBACK, "$LOGIN_PROGRAM")
61 else
62         # Search for login
63         AC_PATH_PROG(LOGIN_PROGRAM_FALLBACK, login)
64         if test ! -z "$LOGIN_PROGRAM_FALLBACK" ; then
65                 AC_DEFINE_UNQUOTED(LOGIN_PROGRAM_FALLBACK, "$LOGIN_PROGRAM_FALLBACK")
66         fi
67 fi
68
69 AC_PATH_PROG(PATH_PASSWD_PROG, passwd)
70 if test ! -z "$PATH_PASSWD_PROG" ; then
71         AC_DEFINE_UNQUOTED(_PATH_PASSWD_PROG, "$PATH_PASSWD_PROG")
72 fi
73
74 if test -z "$LD" ; then
75         LD=$CC
76 fi
77 AC_SUBST(LD)
78         
79 AC_C_INLINE
80 if test "$GCC" = "yes" || test "$GCC" = "egcs"; then
81         CFLAGS="$CFLAGS -Wall -Wpointer-arith -Wno-uninitialized"
82 fi
83
84 AC_ARG_WITH(rpath,
85         [  --without-rpath         Disable auto-added -R linker paths],
86         [
87                 if test "x$withval" = "xno" ; then      
88                         need_dash_r=""
89                 fi
90                 if test "x$withval" = "xyes" ; then
91                         need_dash_r=1
92                 fi
93         ]
94 )
95
96 # Check for some target-specific stuff
97 case "$host" in
98 *-*-aix*)
99         AC_MSG_CHECKING([how to specify blibpath for linker ($LD)])
100         if (test -z "$blibpath"); then
101                 blibpath="/usr/lib:/lib"
102         fi
103         saved_LDFLAGS="$LDFLAGS"
104         for tryflags in -blibpath: -Wl,-blibpath: -Wl,-rpath, ;do
105                 if (test -z "$blibflags"); then
106                         LDFLAGS="$saved_LDFLAGS $tryflags$blibpath"
107                         AC_TRY_LINK([], [], [blibflags=$tryflags])
108                 fi
109         done
110         if (test -z "$blibflags"); then
111                 AC_MSG_RESULT(not found)
112                 AC_MSG_ERROR([*** must be able to specify blibpath on AIX - check config.log])
113         else
114                 AC_MSG_RESULT($blibflags)
115         fi
116         LDFLAGS="$saved_LDFLAGS"
117         dnl Check for authenticate.  Might be in libs.a on older AIXes
118         AC_CHECK_FUNC(authenticate, [AC_DEFINE(WITH_AIXAUTHENTICATE)],
119                 [AC_CHECK_LIB(s,authenticate,
120                         [ AC_DEFINE(WITH_AIXAUTHENTICATE)
121                                 LIBS="$LIBS -ls"
122                         ])
123                 ])
124         dnl Check for various auth function declarations in headers.
125         AC_CHECK_DECLS([authenticate, loginrestrictions, loginsuccess,
126             passwdexpired], , , [#include <usersec.h>])
127         dnl Check if loginfailed is declared and takes 4 arguments (AIX >= 5.2)
128         AC_CHECK_DECLS(loginfailed,
129                  [AC_MSG_CHECKING(if loginfailed takes 4 arguments)
130                   AC_TRY_COMPILE(
131                         [#include <usersec.h>],
132                         [(void)loginfailed("user","host","tty",0);],
133                         [AC_MSG_RESULT(yes)
134                          AC_DEFINE(AIX_LOGINFAILED_4ARG)],
135                         [AC_MSG_RESULT(no)]
136                 )],
137                 [],
138                 [#include <usersec.h>]
139         )
140         AC_CHECK_FUNCS(setauthdb)
141         check_for_aix_broken_getaddrinfo=1
142         AC_DEFINE(BROKEN_REALPATH)
143         AC_DEFINE(SETEUID_BREAKS_SETUID)
144         AC_DEFINE(BROKEN_SETREUID)
145         AC_DEFINE(BROKEN_SETREGID)
146         dnl AIX handles lastlog as part of its login message
147         AC_DEFINE(DISABLE_LASTLOG)
148         AC_DEFINE(LOGIN_NEEDS_UTMPX)
149         AC_DEFINE(SPT_TYPE,SPT_REUSEARGV)
150         ;;
151 *-*-cygwin*)
152         check_for_libcrypt_later=1
153         LIBS="$LIBS /usr/lib/textmode.o"
154         AC_DEFINE(HAVE_CYGWIN)
155         AC_DEFINE(USE_PIPES)
156         AC_DEFINE(DISABLE_SHADOW)
157         AC_DEFINE(IP_TOS_IS_BROKEN)
158         AC_DEFINE(NO_X11_UNIX_SOCKETS)
159         AC_DEFINE(NO_IPPORT_RESERVED_CONCEPT)
160         AC_DEFINE(DISABLE_FD_PASSING)
161         ;;
162 *-*-dgux*)
163         AC_DEFINE(IP_TOS_IS_BROKEN)
164         AC_DEFINE(SETEUID_BREAKS_SETUID)
165         AC_DEFINE(BROKEN_SETREUID)
166         AC_DEFINE(BROKEN_SETREGID)
167         ;;
168 *-*-darwin*)
169         AC_MSG_CHECKING(if we have working getaddrinfo)
170         AC_TRY_RUN([#include <mach-o/dyld.h>
171 main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
172                 exit(0);
173         else
174                 exit(1);
175 }], [AC_MSG_RESULT(working)],
176         [AC_MSG_RESULT(buggy)
177         AC_DEFINE(BROKEN_GETADDRINFO)],
178         [AC_MSG_RESULT(assume it is working)])
179         AC_DEFINE(SETEUID_BREAKS_SETUID)
180         AC_DEFINE(BROKEN_SETREUID)
181         AC_DEFINE(BROKEN_SETREGID)
182         AC_DEFINE_UNQUOTED(BIND_8_COMPAT, 1)
183         ;;
184 *-*-hpux10.26)
185         if test -z "$GCC"; then
186                 CFLAGS="$CFLAGS -Ae"
187         fi
188         CPPFLAGS="$CPPFLAGS -D_HPUX_SOURCE -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1"
189         IPADDR_IN_DISPLAY=yes
190         AC_DEFINE(HAVE_SECUREWARE)
191         AC_DEFINE(USE_PIPES)
192         AC_DEFINE(LOGIN_NO_ENDOPT)
193         AC_DEFINE(LOGIN_NEEDS_UTMPX)
194         AC_DEFINE(LOCKED_PASSWD_STRING, "*")
195         AC_DEFINE(SPT_TYPE,SPT_PSTAT)
196         LIBS="$LIBS -lsec -lsecpw"
197         AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
198         disable_ptmx_check=yes
199         ;;
200 *-*-hpux10*)
201         if test -z "$GCC"; then
202                 CFLAGS="$CFLAGS -Ae"
203         fi
204         CPPFLAGS="$CPPFLAGS -D_HPUX_SOURCE -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1"
205         IPADDR_IN_DISPLAY=yes
206         AC_DEFINE(USE_PIPES)
207         AC_DEFINE(LOGIN_NO_ENDOPT)
208         AC_DEFINE(LOGIN_NEEDS_UTMPX)
209         AC_DEFINE(LOCKED_PASSWD_STRING, "*")
210         AC_DEFINE(SPT_TYPE,SPT_PSTAT)
211         LIBS="$LIBS -lsec"
212         AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
213         ;;
214 *-*-hpux11*)
215         CPPFLAGS="$CPPFLAGS -D_HPUX_SOURCE -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1"
216         IPADDR_IN_DISPLAY=yes
217         AC_DEFINE(PAM_SUN_CODEBASE)
218         AC_DEFINE(USE_PIPES)
219         AC_DEFINE(LOGIN_NO_ENDOPT)
220         AC_DEFINE(LOGIN_NEEDS_UTMPX)
221         AC_DEFINE(DISABLE_UTMP)
222         AC_DEFINE(LOCKED_PASSWD_STRING, "*")
223         AC_DEFINE(SPT_TYPE,SPT_PSTAT)
224         AC_DEFINE(USE_BTMP, 1, [Use btmp to log bad logins])
225         check_for_hpux_broken_getaddrinfo=1
226         check_for_conflicting_getspnam=1
227         LIBS="$LIBS -lsec"
228         AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
229         ;;
230 *-*-irix5*)
231         PATH="$PATH:/usr/etc"
232         AC_DEFINE(BROKEN_INET_NTOA)
233         AC_DEFINE(SETEUID_BREAKS_SETUID)
234         AC_DEFINE(BROKEN_SETREUID)
235         AC_DEFINE(BROKEN_SETREGID)
236         AC_DEFINE(WITH_ABBREV_NO_TTY)
237         AC_DEFINE(LOCKED_PASSWD_STRING, "*LK*")
238         ;;
239 *-*-irix6*)
240         PATH="$PATH:/usr/etc"
241         AC_DEFINE(WITH_IRIX_ARRAY)
242         AC_DEFINE(WITH_IRIX_PROJECT)
243         AC_DEFINE(WITH_IRIX_AUDIT)
244         AC_CHECK_FUNC(jlimit_startjob, [AC_DEFINE(WITH_IRIX_JOBS)])
245         AC_DEFINE(BROKEN_INET_NTOA)
246         AC_DEFINE(SETEUID_BREAKS_SETUID)
247         AC_DEFINE(BROKEN_SETREUID)
248         AC_DEFINE(BROKEN_SETREGID)
249         AC_DEFINE(BROKEN_UPDWTMPX)
250         AC_DEFINE(WITH_ABBREV_NO_TTY)
251         AC_DEFINE(LOCKED_PASSWD_STRING, "*LK*")
252         ;;
253 *-*-linux*)
254         no_dev_ptmx=1
255         check_for_libcrypt_later=1
256         check_for_openpty_ctty_bug=1
257         AC_DEFINE(DONT_TRY_OTHER_AF)
258         AC_DEFINE(PAM_TTY_KLUDGE)
259         AC_DEFINE(LOCKED_PASSWD_PREFIX, "!")
260         AC_DEFINE(SPT_TYPE,SPT_REUSEARGV)
261         AC_DEFINE(LINK_OPNOTSUPP_ERRNO, EPERM)
262         AC_DEFINE(_PATH_BTMP, "/var/log/btmp", [log for bad login attempts])
263         AC_DEFINE(USE_BTMP, 1, [Use btmp to log bad logins])
264         inet6_default_4in6=yes
265         case `uname -r` in
266         1.*|2.0.*)
267                 AC_DEFINE(BROKEN_CMSG_TYPE)
268                 ;;
269         esac
270         ;;
271 mips-sony-bsd|mips-sony-newsos4)
272         AC_DEFINE(HAVE_NEWS4)
273         SONY=1
274         ;;
275 *-*-netbsd*)
276         check_for_libcrypt_before=1
277         if test "x$withval" != "xno" ; then     
278                 need_dash_r=1
279         fi
280         ;;
281 *-*-freebsd*)
282         check_for_libcrypt_later=1
283         ;;
284 *-*-bsdi*)
285         AC_DEFINE(SETEUID_BREAKS_SETUID)
286         AC_DEFINE(BROKEN_SETREUID)
287         AC_DEFINE(BROKEN_SETREGID)
288         ;;
289 *-next-*)
290         conf_lastlog_location="/usr/adm/lastlog"
291         conf_utmp_location=/etc/utmp
292         conf_wtmp_location=/usr/adm/wtmp
293         MAIL=/usr/spool/mail
294         AC_DEFINE(HAVE_NEXT)
295         AC_DEFINE(BROKEN_REALPATH)
296         AC_DEFINE(USE_PIPES)
297         AC_DEFINE(BROKEN_SAVED_UIDS)
298         ;;
299 *-*-solaris*)
300         if test "x$withval" != "xno" ; then     
301                 need_dash_r=1
302         fi
303         AC_DEFINE(PAM_SUN_CODEBASE)
304         AC_DEFINE(LOGIN_NEEDS_UTMPX)
305         AC_DEFINE(LOGIN_NEEDS_TERM)
306         AC_DEFINE(PAM_TTY_KLUDGE)
307         AC_DEFINE(SSHPAM_CHAUTHTOK_NEEDS_RUID)
308         AC_DEFINE(LOCKED_PASSWD_STRING, "*LK*")
309         # Pushing STREAMS modules will cause sshd to acquire a controlling tty.
310         AC_DEFINE(SSHD_ACQUIRES_CTTY)
311         external_path_file=/etc/default/login
312         # hardwire lastlog location (can't detect it on some versions)
313         conf_lastlog_location="/var/adm/lastlog"
314         AC_MSG_CHECKING(for obsolete utmp and wtmp in solaris2.x)
315         sol2ver=`echo "$host"| sed -e 's/.*[[0-9]]\.//'`
316         if test "$sol2ver" -ge 8; then
317                 AC_MSG_RESULT(yes)
318                 AC_DEFINE(DISABLE_UTMP)
319                 AC_DEFINE(DISABLE_WTMP)
320         else
321                 AC_MSG_RESULT(no)
322         fi
323         ;;
324 *-*-sunos4*)
325         CPPFLAGS="$CPPFLAGS -DSUNOS4"
326         AC_CHECK_FUNCS(getpwanam)
327         AC_DEFINE(PAM_SUN_CODEBASE)
328         conf_utmp_location=/etc/utmp
329         conf_wtmp_location=/var/adm/wtmp
330         conf_lastlog_location=/var/adm/lastlog
331         AC_DEFINE(USE_PIPES)
332         ;;
333 *-ncr-sysv*)
334         LIBS="$LIBS -lc89"
335         AC_DEFINE(USE_PIPES)
336         AC_DEFINE(SSHD_ACQUIRES_CTTY)
337         AC_DEFINE(SETEUID_BREAKS_SETUID)
338         AC_DEFINE(BROKEN_SETREUID)
339         AC_DEFINE(BROKEN_SETREGID)
340         ;;
341 *-sni-sysv*)
342         # /usr/ucblib MUST NOT be searched on ReliantUNIX
343         AC_CHECK_LIB(dl, dlsym, ,)
344         # -lresolv needs to be at then end of LIBS or DNS lookups break
345         AC_CHECK_LIB(res_query, resolv, [ LIBS="$LIBS -lresolv" ])
346         IPADDR_IN_DISPLAY=yes
347         AC_DEFINE(USE_PIPES)
348         AC_DEFINE(IP_TOS_IS_BROKEN)
349         AC_DEFINE(SETEUID_BREAKS_SETUID)
350         AC_DEFINE(BROKEN_SETREUID)
351         AC_DEFINE(BROKEN_SETREGID)
352         AC_DEFINE(SSHD_ACQUIRES_CTTY)
353         external_path_file=/etc/default/login
354         # /usr/ucblib/libucb.a no longer needed on ReliantUNIX
355         # Attention: always take care to bind libsocket and libnsl before libc,
356         # otherwise you will find lots of "SIOCGPGRP errno 22" on syslog
357         ;;
358 # UnixWare 1.x, UnixWare 2.x, and others based on code from Univel.
359 *-*-sysv4.2*)
360         AC_DEFINE(USE_PIPES)
361         AC_DEFINE(SETEUID_BREAKS_SETUID)
362         AC_DEFINE(BROKEN_SETREUID)
363         AC_DEFINE(BROKEN_SETREGID)
364         ;;
365 # UnixWare 7.x, OpenUNIX 8
366 *-*-sysv5*)
367         AC_DEFINE(USE_PIPES)
368         AC_DEFINE(SETEUID_BREAKS_SETUID)
369         AC_DEFINE(BROKEN_SETREUID)
370         AC_DEFINE(BROKEN_SETREGID)
371         ;;
372 *-*-sysv*)
373         ;;
374 # SCO UNIX and OEM versions of SCO UNIX
375 *-*-sco3.2v4*)
376         AC_MSG_ERROR("This Platform is no longer supported.")
377         ;;
378 # SCO OpenServer 5.x
379 *-*-sco3.2v5*)
380         if test -z "$GCC"; then
381                 CFLAGS="$CFLAGS -belf"
382         fi
383         LIBS="$LIBS -lprot -lx -ltinfo -lm"
384         no_dev_ptmx=1
385         AC_DEFINE(USE_PIPES)
386         AC_DEFINE(HAVE_SECUREWARE)
387         AC_DEFINE(DISABLE_SHADOW)
388         AC_DEFINE(DISABLE_FD_PASSING)
389         AC_DEFINE(SETEUID_BREAKS_SETUID)
390         AC_DEFINE(BROKEN_SETREUID)
391         AC_DEFINE(BROKEN_SETREGID)
392         AC_DEFINE(WITH_ABBREV_NO_TTY)
393         AC_DEFINE(BROKEN_UPDWTMPX)
394         AC_DEFINE(PASSWD_NEEDS_USERNAME, 1, [must supply username to passwd])
395         AC_CHECK_FUNCS(getluid setluid)
396         MANTYPE=man
397         TEST_SHELL=ksh
398         ;;
399 *-*-unicosmk*)
400         AC_DEFINE(NO_SSH_LASTLOG)
401         AC_DEFINE(SETEUID_BREAKS_SETUID)
402         AC_DEFINE(BROKEN_SETREUID)
403         AC_DEFINE(BROKEN_SETREGID)
404         AC_DEFINE(USE_PIPES)
405         AC_DEFINE(DISABLE_FD_PASSING)
406         LDFLAGS="$LDFLAGS"
407         LIBS="$LIBS -lgen -lrsc -lshare -luex -lacm"
408         MANTYPE=cat
409         ;;
410 *-*-unicosmp*)
411         AC_DEFINE(SETEUID_BREAKS_SETUID)
412         AC_DEFINE(BROKEN_SETREUID)
413         AC_DEFINE(BROKEN_SETREGID)
414         AC_DEFINE(WITH_ABBREV_NO_TTY)
415         AC_DEFINE(USE_PIPES)
416         AC_DEFINE(DISABLE_FD_PASSING)
417         LDFLAGS="$LDFLAGS"
418         LIBS="$LIBS -lgen -lacid -ldb"
419         MANTYPE=cat
420         ;;
421 *-*-unicos*)
422         AC_DEFINE(SETEUID_BREAKS_SETUID)
423         AC_DEFINE(BROKEN_SETREUID)
424         AC_DEFINE(BROKEN_SETREGID)
425         AC_DEFINE(USE_PIPES)
426         AC_DEFINE(DISABLE_FD_PASSING)
427         AC_DEFINE(NO_SSH_LASTLOG)
428         LDFLAGS="$LDFLAGS -Wl,-Dmsglevel=334:fatal"
429         LIBS="$LIBS -lgen -lrsc -lshare -luex -lacm"
430         MANTYPE=cat
431         ;;
432 *-dec-osf*)
433         AC_MSG_CHECKING(for Digital Unix SIA)
434         no_osfsia=""
435         AC_ARG_WITH(osfsia,
436                 [  --with-osfsia           Enable Digital Unix SIA],
437                 [
438                         if test "x$withval" = "xno" ; then
439                                 AC_MSG_RESULT(disabled)
440                                 no_osfsia=1
441                         fi
442                 ],
443         )
444         if test -z "$no_osfsia" ; then
445                 if test -f /etc/sia/matrix.conf; then
446                         AC_MSG_RESULT(yes)
447                         AC_DEFINE(HAVE_OSF_SIA)
448                         AC_DEFINE(DISABLE_LOGIN)
449                         AC_DEFINE(DISABLE_FD_PASSING)
450                         LIBS="$LIBS -lsecurity -ldb -lm -laud"
451                 else
452                         AC_MSG_RESULT(no)
453                         AC_DEFINE(LOCKED_PASSWD_SUBSTR, "Nologin")
454                 fi
455         fi
456         AC_DEFINE(BROKEN_GETADDRINFO)
457         AC_DEFINE(SETEUID_BREAKS_SETUID)
458         AC_DEFINE(BROKEN_SETREUID)
459         AC_DEFINE(BROKEN_SETREGID)
460         ;;
461
462 *-*-nto-qnx)
463         AC_DEFINE(USE_PIPES)
464         AC_DEFINE(NO_X11_UNIX_SOCKETS)
465         AC_DEFINE(MISSING_NFDBITS)
466         AC_DEFINE(MISSING_HOWMANY)
467         AC_DEFINE(MISSING_FD_MASK)
468         ;;
469 esac
470
471 # Allow user to specify flags
472 AC_ARG_WITH(cflags,
473         [  --with-cflags           Specify additional flags to pass to compiler],
474         [
475                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
476                     test "x${withval}" != "xyes"; then
477                         CFLAGS="$CFLAGS $withval"
478                 fi
479         ]       
480 )
481 AC_ARG_WITH(cppflags,
482         [  --with-cppflags         Specify additional flags to pass to preprocessor] ,
483         [
484                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
485                     test "x${withval}" != "xyes"; then
486                         CPPFLAGS="$CPPFLAGS $withval"
487                 fi
488         ]
489 )
490 AC_ARG_WITH(ldflags,
491         [  --with-ldflags          Specify additional flags to pass to linker],
492         [
493                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
494                     test "x${withval}" != "xyes"; then
495                         LDFLAGS="$LDFLAGS $withval"
496                 fi
497         ]       
498 )
499 AC_ARG_WITH(libs,
500         [  --with-libs             Specify additional libraries to link with],
501         [
502                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
503                     test "x${withval}" != "xyes"; then
504                         LIBS="$LIBS $withval"
505                 fi
506         ]       
507 )
508
509 AC_MSG_CHECKING(compiler and flags for sanity)
510 AC_RUN_IFELSE(
511         [AC_LANG_SOURCE([
512 #include <stdio.h>
513 int main(){exit(0);}
514         ])],
515         [       AC_MSG_RESULT(yes) ],
516         [
517                 AC_MSG_RESULT(no)
518                 AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***])
519         ],
520         [       AC_MSG_WARN([cross compiling: not checking compiler sanity]) ]
521 )
522
523 # Checks for header files.
524 AC_CHECK_HEADERS(bstring.h crypt.h dirent.h endian.h features.h \
525         floatingpoint.h getopt.h glob.h ia.h lastlog.h limits.h login.h \
526         login_cap.h maillock.h ndir.h netdb.h netgroup.h \
527         netinet/in_systm.h pam/pam_appl.h paths.h pty.h readpassphrase.h \
528         rpc/types.h security/pam_appl.h shadow.h stddef.h stdint.h \
529         strings.h sys/dir.h sys/strtio.h sys/audit.h sys/bitypes.h \
530         sys/bsdtty.h sys/cdefs.h sys/mman.h sys/ndir.h sys/prctl.h \
531         sys/pstat.h sys/select.h sys/stat.h sys/stream.h \
532         sys/stropts.h sys/sysmacros.h sys/time.h sys/timers.h sys/un.h \
533         time.h tmpdir.h ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h)
534
535 # sys/ptms.h requires sys/stream.h to be included first on Solaris
536 AC_CHECK_HEADERS(sys/ptms.h, [], [], [
537 #ifdef HAVE_SYS_STREAM_H
538 # include <sys/stream.h>
539 #endif
540 ])
541
542 # Checks for libraries.
543 AC_CHECK_FUNC(yp_match, , AC_CHECK_LIB(nsl, yp_match))
544 AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
545
546 dnl IRIX and Solaris 2.5.1 have dirname() in libgen
547 AC_CHECK_FUNCS(dirname, [AC_CHECK_HEADERS(libgen.h)] ,[
548         AC_CHECK_LIB(gen, dirname,[
549                 AC_CACHE_CHECK([for broken dirname],
550                         ac_cv_have_broken_dirname, [
551                         save_LIBS="$LIBS"
552                         LIBS="$LIBS -lgen"
553                         AC_TRY_RUN(
554                                 [
555 #include <libgen.h>
556 #include <string.h>
557
558 int main(int argc, char **argv) {
559     char *s, buf[32];
560
561     strncpy(buf,"/etc", 32);
562     s = dirname(buf);
563     if (!s || strncmp(s, "/", 32) != 0) {
564         exit(1);
565     } else {
566         exit(0);
567     }
568 }
569                                 ],
570                                 [ ac_cv_have_broken_dirname="no" ],
571                                 [ ac_cv_have_broken_dirname="yes" ]
572                         )
573                         LIBS="$save_LIBS"
574                 ])
575                 if test "x$ac_cv_have_broken_dirname" = "xno" ; then
576                         LIBS="$LIBS -lgen"
577                         AC_DEFINE(HAVE_DIRNAME)
578                         AC_CHECK_HEADERS(libgen.h)
579                 fi
580         ])
581 ])
582
583 AC_CHECK_FUNC(getspnam, ,
584         AC_CHECK_LIB(gen, getspnam, LIBS="$LIBS -lgen"))
585 AC_SEARCH_LIBS(basename, gen, AC_DEFINE(HAVE_BASENAME))
586
587 dnl zlib is required
588 AC_ARG_WITH(zlib,
589         [  --with-zlib=PATH        Use zlib in PATH],
590         [
591                 if test "x$withval" = "xno" ; then
592                         AC_MSG_ERROR([*** zlib is required ***])
593                 fi
594                 if test -d "$withval/lib"; then
595                         if test -n "${need_dash_r}"; then
596                                 LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
597                         else
598                                 LDFLAGS="-L${withval}/lib ${LDFLAGS}"
599                         fi
600                 else
601                         if test -n "${need_dash_r}"; then
602                                 LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
603                         else
604                                 LDFLAGS="-L${withval} ${LDFLAGS}"
605                         fi
606                 fi
607                 if test -d "$withval/include"; then
608                         CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
609                 else
610                         CPPFLAGS="-I${withval} ${CPPFLAGS}"
611                 fi
612         ]
613 )
614
615 AC_CHECK_LIB(z, deflate, ,
616         [
617                 saved_CPPFLAGS="$CPPFLAGS"
618                 saved_LDFLAGS="$LDFLAGS"
619                 save_LIBS="$LIBS"
620                 dnl Check default zlib install dir
621                 if test -n "${need_dash_r}"; then
622                         LDFLAGS="-L/usr/local/lib -R/usr/local/lib ${saved_LDFLAGS}"
623                 else
624                         LDFLAGS="-L/usr/local/lib ${saved_LDFLAGS}"
625                 fi
626                 CPPFLAGS="-I/usr/local/include ${saved_CPPFLAGS}"
627                 LIBS="$LIBS -lz"
628                 AC_TRY_LINK_FUNC(deflate, AC_DEFINE(HAVE_LIBZ),
629                         [
630                                 AC_MSG_ERROR([*** zlib missing - please install first or check config.log ***])
631                         ]
632                 )
633         ]
634 )
635 AC_CHECK_HEADER([zlib.h], ,AC_MSG_ERROR([*** zlib.h missing - please install first or check config.log ***]))
636
637 AC_ARG_WITH(zlib-version-check,
638         [  --without-zlib-version-check Disable zlib version check],
639         [  if test "x$withval" = "xno" ; then
640                 zlib_check_nonfatal=1
641            fi
642         ]
643 )
644
645 AC_MSG_CHECKING(for zlib 1.1.4 or greater)
646 AC_RUN_IFELSE([AC_LANG_SOURCE([[
647 #include <zlib.h>
648 int main()
649 {
650         int a, b, c, v;
651         if (sscanf(ZLIB_VERSION, "%d.%d.%d", &a, &b, &c) != 3)
652                 exit(1);
653         v = a*1000000 + b*1000 + c;
654         if (v >= 1001004)
655                 exit(0);
656         exit(2);
657 }
658         ]])],
659         AC_MSG_RESULT(yes),
660         [ AC_MSG_RESULT(no)
661           if test -z "$zlib_check_nonfatal" ; then
662                 AC_MSG_ERROR([*** zlib too old - check config.log ***
663 Your reported zlib version has known security problems.  It's possible your
664 vendor has fixed these problems without changing the version number.  If you
665 are sure this is the case, you can disable the check by running
666 "./configure --without-zlib-version-check".
667 If you are in doubt, upgrade zlib to version 1.1.4 or greater.])
668           else
669                 AC_MSG_WARN([zlib version may have security problems])
670           fi
671         ],
672         [       AC_MSG_WARN([cross compiling: not checking zlib version]) ]
673 )
674
675 dnl UnixWare 2.x
676 AC_CHECK_FUNC(strcasecmp,
677         [], [ AC_CHECK_LIB(resolv, strcasecmp, LIBS="$LIBS -lresolv") ]
678 )
679 AC_CHECK_FUNC(utimes,
680         [], [ AC_CHECK_LIB(c89, utimes, [AC_DEFINE(HAVE_UTIMES)
681                                         LIBS="$LIBS -lc89"]) ]
682 )
683
684 dnl    Checks for libutil functions
685 AC_CHECK_HEADERS(libutil.h)
686 AC_SEARCH_LIBS(login, util bsd, [AC_DEFINE(HAVE_LOGIN)])
687 AC_CHECK_FUNCS(logout updwtmp logwtmp)
688
689 AC_FUNC_STRFTIME
690
691 # Check for ALTDIRFUNC glob() extension
692 AC_MSG_CHECKING(for GLOB_ALTDIRFUNC support)
693 AC_EGREP_CPP(FOUNDIT,
694         [
695                 #include <glob.h>
696                 #ifdef GLOB_ALTDIRFUNC
697                 FOUNDIT
698                 #endif
699         ],
700         [
701                 AC_DEFINE(GLOB_HAS_ALTDIRFUNC)
702                 AC_MSG_RESULT(yes)
703         ],
704         [
705                 AC_MSG_RESULT(no)
706         ]
707 )
708
709 # Check for g.gl_matchc glob() extension
710 AC_MSG_CHECKING(for gl_matchc field in glob_t)
711 AC_EGREP_CPP(FOUNDIT,
712         [
713                 #include <glob.h>
714                 int main(void){glob_t g; g.gl_matchc = 1;}
715         ],
716         [
717                 AC_DEFINE(GLOB_HAS_GL_MATCHC)
718                 AC_MSG_RESULT(yes)
719         ],
720         [
721                 AC_MSG_RESULT(no)
722         ]
723 )
724
725 AC_MSG_CHECKING([whether struct dirent allocates space for d_name])
726 AC_RUN_IFELSE(
727         [AC_LANG_SOURCE([[
728 #include <sys/types.h>
729 #include <dirent.h>
730 int main(void){struct dirent d;exit(sizeof(d.d_name)<=sizeof(char));}
731         ]])],
732         [AC_MSG_RESULT(yes)],
733         [
734                 AC_MSG_RESULT(no)
735                 AC_DEFINE(BROKEN_ONE_BYTE_DIRENT_D_NAME)
736         ],
737         [ 
738                 AC_MSG_WARN([cross compiling: assuming BROKEN_ONE_BYTE_DIRENT_D_NAME])
739                 AC_DEFINE(BROKEN_ONE_BYTE_DIRENT_D_NAME)
740         ]
741 )
742
743 AC_MSG_CHECKING([for /proc/pid/fd directory])
744 if test -d "/proc/$$/fd" ; then
745         AC_DEFINE(HAVE_PROC_PID)
746         AC_MSG_RESULT(yes)
747 else
748         AC_MSG_RESULT(no)
749 fi
750
751 # Check whether user wants S/Key support
752 SKEY_MSG="no"
753 AC_ARG_WITH(skey,
754         [  --with-skey[[=PATH]]      Enable S/Key support (optionally in PATH)],
755         [
756                 if test "x$withval" != "xno" ; then
757
758                         if test "x$withval" != "xyes" ; then
759                                 CPPFLAGS="$CPPFLAGS -I${withval}/include"
760                                 LDFLAGS="$LDFLAGS -L${withval}/lib"
761                         fi
762
763                         AC_DEFINE(SKEY)
764                         LIBS="-lskey $LIBS"
765                         SKEY_MSG="yes"
766         
767                         AC_MSG_CHECKING([for s/key support])
768                         AC_TRY_RUN(
769                                 [
770 #include <stdio.h>
771 #include <skey.h>
772 int main() { char *ff = skey_keyinfo(""); ff=""; exit(0); }
773                                 ],
774                                 [AC_MSG_RESULT(yes)],
775                                 [
776                                         AC_MSG_RESULT(no)
777                                         AC_MSG_ERROR([** Incomplete or missing s/key libraries.])
778                                 ])
779                         AC_MSG_CHECKING(if skeychallenge takes 4 arguments)
780                         AC_TRY_COMPILE(
781                                 [#include <stdio.h>
782                                  #include <skey.h>],
783                                 [(void)skeychallenge(NULL,"name","",0);],
784                                 [AC_MSG_RESULT(yes)
785                                  AC_DEFINE(SKEYCHALLENGE_4ARG)],
786                                 [AC_MSG_RESULT(no)]
787                         )
788                 fi
789         ]
790 )
791
792 # Check whether user wants TCP wrappers support
793 TCPW_MSG="no"
794 AC_ARG_WITH(tcp-wrappers,
795         [  --with-tcp-wrappers[[=PATH]] Enable tcpwrappers support (optionally in PATH)],
796         [
797                 if test "x$withval" != "xno" ; then
798                         saved_LIBS="$LIBS"
799                         saved_LDFLAGS="$LDFLAGS"
800                         saved_CPPFLAGS="$CPPFLAGS"
801                         if test -n "${withval}" && \
802                             test "x${withval}" != "xyes"; then
803                                 if test -d "${withval}/lib"; then
804                                         if test -n "${need_dash_r}"; then
805                                                 LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
806                                         else
807                                                 LDFLAGS="-L${withval}/lib ${LDFLAGS}"
808                                         fi
809                                 else
810                                         if test -n "${need_dash_r}"; then
811                                                 LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
812                                         else
813                                                 LDFLAGS="-L${withval} ${LDFLAGS}"
814                                         fi
815                                 fi
816                                 if test -d "${withval}/include"; then
817                                         CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
818                                 else
819                                         CPPFLAGS="-I${withval} ${CPPFLAGS}"
820                                 fi
821                         fi
822                         LIBWRAP="-lwrap"
823                         LIBS="$LIBWRAP $LIBS"
824                         AC_MSG_CHECKING(for libwrap)
825                         AC_TRY_LINK(
826                                 [
827 #include <sys/types.h>
828 #include <sys/socket.h>
829 #include <netinet/in.h>
830 #include <tcpd.h>
831                                         int deny_severity = 0, allow_severity = 0;
832                                 ],
833                                 [hosts_access(0);],
834                                 [
835                                         AC_MSG_RESULT(yes)
836                                         AC_DEFINE(LIBWRAP)
837                                         AC_SUBST(LIBWRAP)
838                                         TCPW_MSG="yes"
839                                 ],
840                                 [
841                                         AC_MSG_ERROR([*** libwrap missing])
842                                 ]
843                         )
844                         LIBS="$saved_LIBS"
845                 fi
846         ]
847 )
848
849 # Check whether user wants libedit support
850 LIBEDIT_MSG="no"
851 AC_ARG_WITH(libedit,
852         [  --with-libedit[[=PATH]]   Enable libedit support for sftp],
853         [ if test "x$withval" != "xno" ; then
854                 AC_CHECK_LIB(edit, el_init,
855                         [ AC_DEFINE(USE_LIBEDIT, [], [Use libedit for sftp])
856                           LIBEDIT="-ledit -lcurses"
857                           LIBEDIT_MSG="yes"
858                           AC_SUBST(LIBEDIT)
859                         ],
860                         [], [-lcurses]
861                 )
862         fi ]
863 )
864
865 AUDIT_MODULE=none
866 AC_ARG_WITH(audit,
867         [  --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm)],
868         [
869           AC_MSG_CHECKING(for supported audit module)
870           case "$withval" in
871           bsm)
872                 AC_MSG_RESULT(bsm)
873                 AUDIT_MODULE=bsm
874                 dnl    Checks for headers, libs and functions
875                 AC_CHECK_HEADERS(bsm/audit.h, [],
876                     [AC_MSG_ERROR(BSM enabled and bsm/audit.h not found)])
877                 AC_CHECK_LIB(bsm, getaudit, [],
878                     [AC_MSG_ERROR(BSM enabled and required library not found)])
879                 AC_CHECK_FUNCS(getaudit, [],
880                     [AC_MSG_ERROR(BSM enabled and required function not found)])
881                 # These are optional
882                 AC_CHECK_FUNCS(getaudit_addr)
883                 AC_DEFINE(USE_BSM_AUDIT, [], [Use BSM audit module])
884                 ;;
885           debug)
886                 AUDIT_MODULE=debug
887                 AC_MSG_RESULT(debug)
888                 AC_DEFINE(SSH_AUDIT_EVENTS, [], Use audit debugging module)
889                 ;;
890           *)
891                 AC_MSG_ERROR([Unknown audit module $withval])
892                 ;;
893         esac ]
894 )
895
896 dnl    Checks for library functions. Please keep in alphabetical order
897 AC_CHECK_FUNCS(\
898         arc4random __b64_ntop b64_ntop __b64_pton b64_pton bcopy \
899         bindresvport_sa clock closefrom dirfd fchdir fchmod fchown \
900         freeaddrinfo futimes getaddrinfo getcwd getgrouplist getnameinfo \
901         getopt getpeereid _getpty getrlimit getttyent glob inet_aton \
902         inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove \
903         mkdtemp mmap ngetaddrinfo nsleep ogetaddrinfo openlog_r openpty \
904         pstat prctl readpassphrase realpath recvmsg rresvport_af sendmsg \
905         setdtablesize setegid setenv seteuid setgroups setlogin setpcred \
906         setproctitle setregid setreuid setrlimit \
907         setsid setvbuf sigaction sigvec snprintf socketpair strerror \
908         strlcat strlcpy strmode strnvis strtoul sysconf tcgetpgrp \
909         truncate unsetenv updwtmpx utimes vhangup vsnprintf waitpid \
910 )
911
912 # IRIX has a const char return value for gai_strerror()
913 AC_CHECK_FUNCS(gai_strerror,[
914         AC_DEFINE(HAVE_GAI_STRERROR)
915         AC_TRY_COMPILE([
916 #include <sys/types.h>
917 #include <sys/socket.h>
918 #include <netdb.h>
919
920 const char *gai_strerror(int);],[
921 char *str;
922
923 str = gai_strerror(0);],[
924                 AC_DEFINE(HAVE_CONST_GAI_STRERROR_PROTO, 1,
925                 [Define if gai_strerror() returns const char *])])])
926
927 AC_SEARCH_LIBS(nanosleep, rt posix4, AC_DEFINE(HAVE_NANOSLEEP))
928
929 dnl Make sure prototypes are defined for these before using them.
930 AC_CHECK_DECL(strsep, [AC_CHECK_FUNCS(strsep)])
931 AC_CHECK_DECL(getrusage, [AC_CHECK_FUNCS(getrusage)])
932
933 dnl tcsendbreak might be a macro
934 AC_CHECK_DECL(tcsendbreak,
935         [AC_DEFINE(HAVE_TCSENDBREAK)],
936         [AC_CHECK_FUNCS(tcsendbreak)],
937         [#include <termios.h>]
938 )
939
940 AC_CHECK_DECLS(h_errno, , ,[#include <netdb.h>])
941
942 AC_CHECK_FUNCS(setresuid, [
943         dnl Some platorms have setresuid that isn't implemented, test for this
944         AC_MSG_CHECKING(if setresuid seems to work)
945         AC_RUN_IFELSE(
946                 [AC_LANG_SOURCE([[
947 #include <stdlib.h>
948 #include <errno.h>
949 int main(){errno=0; setresuid(0,0,0); if (errno==ENOSYS) exit(1); else exit(0);}
950                 ]])],
951                 [AC_MSG_RESULT(yes)],
952                 [AC_DEFINE(BROKEN_SETRESUID)
953                  AC_MSG_RESULT(not implemented)],
954                 [AC_MSG_WARN([cross compiling: not checking setresuid])]
955         )
956 ])
957
958 AC_CHECK_FUNCS(setresgid, [
959         dnl Some platorms have setresgid that isn't implemented, test for this
960         AC_MSG_CHECKING(if setresgid seems to work)
961         AC_RUN_IFELSE(
962                 [AC_LANG_SOURCE([[
963 #include <stdlib.h>
964 #include <errno.h>
965 int main(){errno=0; setresgid(0,0,0); if (errno==ENOSYS) exit(1); else exit(0);}
966                 ]])],
967                 [AC_MSG_RESULT(yes)],
968                 [AC_DEFINE(BROKEN_SETRESGID)
969                  AC_MSG_RESULT(not implemented)],
970                 [AC_MSG_WARN([cross compiling: not checking setresuid])]
971         )
972 ])
973
974 dnl    Checks for time functions
975 AC_CHECK_FUNCS(gettimeofday time)
976 dnl    Checks for utmp functions
977 AC_CHECK_FUNCS(endutent getutent getutid getutline pututline setutent)
978 AC_CHECK_FUNCS(utmpname)
979 dnl    Checks for utmpx functions
980 AC_CHECK_FUNCS(endutxent getutxent getutxid getutxline pututxline )
981 AC_CHECK_FUNCS(setutxent utmpxname)
982
983 AC_CHECK_FUNC(daemon,
984         [AC_DEFINE(HAVE_DAEMON)],
985         [AC_CHECK_LIB(bsd, daemon, [LIBS="$LIBS -lbsd"; AC_DEFINE(HAVE_DAEMON)])]
986 )
987
988 AC_CHECK_FUNC(getpagesize,
989         [AC_DEFINE(HAVE_GETPAGESIZE)],
990         [AC_CHECK_LIB(ucb, getpagesize, [LIBS="$LIBS -lucb"; AC_DEFINE(HAVE_GETPAGESIZE)])]
991 )
992
993 # Check for broken snprintf
994 if test "x$ac_cv_func_snprintf" = "xyes" ; then
995         AC_MSG_CHECKING([whether snprintf correctly terminates long strings])
996         AC_RUN_IFELSE(
997                 [AC_LANG_SOURCE([[
998 #include <stdio.h>
999 int main(void){char b[5];snprintf(b,5,"123456789");exit(b[4]!='\0');}
1000                 ]])],
1001                 [AC_MSG_RESULT(yes)],
1002                 [
1003                         AC_MSG_RESULT(no)
1004                         AC_DEFINE(BROKEN_SNPRINTF)
1005                         AC_MSG_WARN([****** Your snprintf() function is broken, complain to your vendor])
1006                 ],
1007                 [ AC_MSG_WARN([cross compiling: Assuming working snprintf()]) ]
1008         )
1009 fi
1010
1011 # Check for missing getpeereid (or equiv) support
1012 NO_PEERCHECK=""
1013 if test "x$ac_cv_func_getpeereid" != "xyes" ; then
1014         AC_MSG_CHECKING([whether system supports SO_PEERCRED getsockopt])
1015         AC_TRY_COMPILE(
1016                 [#include <sys/types.h>
1017                  #include <sys/socket.h>],
1018                 [int i = SO_PEERCRED;],
1019                 [AC_MSG_RESULT(yes)],
1020                 [AC_MSG_RESULT(no)
1021                 NO_PEERCHECK=1]
1022         )
1023 fi
1024
1025 dnl see whether mkstemp() requires XXXXXX
1026 if test "x$ac_cv_func_mkdtemp" = "xyes" ; then
1027 AC_MSG_CHECKING([for (overly) strict mkstemp])
1028 AC_TRY_RUN(
1029         [
1030 #include <stdlib.h>
1031 main() { char template[]="conftest.mkstemp-test";
1032 if (mkstemp(template) == -1)
1033         exit(1);
1034 unlink(template); exit(0);
1035 }
1036         ],
1037         [
1038                 AC_MSG_RESULT(no)
1039         ],
1040         [
1041                 AC_MSG_RESULT(yes)
1042                 AC_DEFINE(HAVE_STRICT_MKSTEMP)
1043         ],
1044         [
1045                 AC_MSG_RESULT(yes)
1046                 AC_DEFINE(HAVE_STRICT_MKSTEMP)
1047         ]
1048 )
1049 fi
1050
1051 dnl make sure that openpty does not reacquire controlling terminal
1052 if test ! -z "$check_for_openpty_ctty_bug"; then
1053         AC_MSG_CHECKING(if openpty correctly handles controlling tty)
1054         AC_TRY_RUN(
1055                 [
1056 #include <stdio.h>
1057 #include <sys/fcntl.h>
1058 #include <sys/types.h>
1059 #include <sys/wait.h>
1060
1061 int
1062 main()
1063 {
1064         pid_t pid;
1065         int fd, ptyfd, ttyfd, status;
1066
1067         pid = fork();
1068         if (pid < 0) {          /* failed */
1069                 exit(1);
1070         } else if (pid > 0) {   /* parent */
1071                 waitpid(pid, &status, 0);
1072                 if (WIFEXITED(status))
1073                         exit(WEXITSTATUS(status));
1074                 else
1075                         exit(2);
1076         } else {                /* child */
1077                 close(0); close(1); close(2);
1078                 setsid();
1079                 openpty(&ptyfd, &ttyfd, NULL, NULL, NULL);
1080                 fd = open("/dev/tty", O_RDWR | O_NOCTTY);
1081                 if (fd >= 0)
1082                         exit(3);        /* Acquired ctty: broken */
1083                 else
1084                         exit(0);        /* Did not acquire ctty: OK */
1085         }
1086 }
1087                 ],
1088                 [
1089                         AC_MSG_RESULT(yes)
1090                 ],
1091                 [
1092                         AC_MSG_RESULT(no)
1093                         AC_DEFINE(SSHD_ACQUIRES_CTTY)
1094                 ]
1095         )
1096 fi
1097
1098 if test "x$ac_cv_func_getaddrinfo" = "xyes" && \
1099     test "x$check_for_hpux_broken_getaddrinfo" = "x1"; then
1100         AC_MSG_CHECKING(if getaddrinfo seems to work)
1101         AC_TRY_RUN(
1102                 [
1103 #include <stdio.h>
1104 #include <sys/socket.h>
1105 #include <netdb.h>
1106 #include <errno.h>
1107 #include <netinet/in.h>
1108
1109 #define TEST_PORT "2222"
1110
1111 int
1112 main(void)
1113 {
1114         int err, sock;
1115         struct addrinfo *gai_ai, *ai, hints;
1116         char ntop[NI_MAXHOST], strport[NI_MAXSERV], *name = NULL;
1117
1118         memset(&hints, 0, sizeof(hints));
1119         hints.ai_family = PF_UNSPEC;
1120         hints.ai_socktype = SOCK_STREAM;
1121         hints.ai_flags = AI_PASSIVE;
1122
1123         err = getaddrinfo(name, TEST_PORT, &hints, &gai_ai);
1124         if (err != 0) {
1125                 fprintf(stderr, "getaddrinfo failed (%s)", gai_strerror(err));
1126                 exit(1);
1127         }
1128
1129         for (ai = gai_ai; ai != NULL; ai = ai->ai_next) {
1130                 if (ai->ai_family != AF_INET6)
1131                         continue;
1132
1133                 err = getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop,
1134                     sizeof(ntop), strport, sizeof(strport),
1135                     NI_NUMERICHOST|NI_NUMERICSERV);
1136
1137                 if (err != 0) {
1138                         if (err == EAI_SYSTEM)
1139                                 perror("getnameinfo EAI_SYSTEM");
1140                         else
1141                                 fprintf(stderr, "getnameinfo failed: %s\n",
1142                                     gai_strerror(err));
1143                         exit(2);
1144                 }
1145
1146                 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
1147                 if (sock < 0)
1148                         perror("socket");
1149                 if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
1150                         if (errno == EBADF)
1151                                 exit(3);
1152                 }
1153         }
1154         exit(0);
1155 }
1156                 ],
1157                 [
1158                         AC_MSG_RESULT(yes)
1159                 ],
1160                 [
1161                         AC_MSG_RESULT(no)
1162                         AC_DEFINE(BROKEN_GETADDRINFO)
1163                 ]
1164         )
1165 fi
1166
1167 if test "x$ac_cv_func_getaddrinfo" = "xyes" && \
1168     test "x$check_for_aix_broken_getaddrinfo" = "x1"; then
1169         AC_MSG_CHECKING(if getaddrinfo seems to work)
1170         AC_TRY_RUN(
1171                 [
1172 #include <stdio.h>
1173 #include <sys/socket.h>
1174 #include <netdb.h>
1175 #include <errno.h>
1176 #include <netinet/in.h>
1177
1178 #define TEST_PORT "2222"
1179
1180 int
1181 main(void)
1182 {
1183         int err, sock;
1184         struct addrinfo *gai_ai, *ai, hints;
1185         char ntop[NI_MAXHOST], strport[NI_MAXSERV], *name = NULL;
1186
1187         memset(&hints, 0, sizeof(hints));
1188         hints.ai_family = PF_UNSPEC;
1189         hints.ai_socktype = SOCK_STREAM;
1190         hints.ai_flags = AI_PASSIVE;
1191
1192         err = getaddrinfo(name, TEST_PORT, &hints, &gai_ai);
1193         if (err != 0) {
1194                 fprintf(stderr, "getaddrinfo failed (%s)", gai_strerror(err));
1195                 exit(1);
1196         }
1197
1198         for (ai = gai_ai; ai != NULL; ai = ai->ai_next) {
1199                 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
1200                         continue;
1201
1202                 err = getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop,
1203                     sizeof(ntop), strport, sizeof(strport),
1204                     NI_NUMERICHOST|NI_NUMERICSERV);
1205
1206                 if (ai->ai_family == AF_INET && err != 0) {
1207                         perror("getnameinfo");
1208                         exit(2);
1209                 }
1210         }
1211         exit(0);
1212 }
1213                 ],
1214                 [
1215                         AC_MSG_RESULT(yes)
1216                         AC_DEFINE(AIX_GETNAMEINFO_HACK, [],
1217 [Define if you have a getaddrinfo that fails for the all-zeros IPv6 address])
1218                 ],
1219                 [
1220                         AC_MSG_RESULT(no)
1221                         AC_DEFINE(BROKEN_GETADDRINFO)
1222                 ]
1223         )
1224 fi
1225
1226 if test "x$check_for_conflicting_getspnam" = "x1"; then
1227         AC_MSG_CHECKING(for conflicting getspnam in shadow.h)
1228         AC_COMPILE_IFELSE(
1229                 [
1230 #include <shadow.h>
1231 int main(void) {exit(0);}
1232                 ],
1233                 [
1234                         AC_MSG_RESULT(no)
1235                 ],
1236                 [
1237                         AC_MSG_RESULT(yes)
1238                         AC_DEFINE(GETSPNAM_CONFLICTING_DEFS, 1,
1239                             [Conflicting defs for getspnam])
1240                 ]
1241         )
1242 fi
1243
1244 AC_FUNC_GETPGRP
1245
1246 # Check for PAM libs
1247 PAM_MSG="no"
1248 AC_ARG_WITH(pam,
1249         [  --with-pam              Enable PAM support ],
1250         [
1251                 if test "x$withval" != "xno" ; then
1252                         if test "x$ac_cv_header_security_pam_appl_h" != "xyes" && \
1253                            test "x$ac_cv_header_pam_pam_appl_h" != "xyes" ; then
1254                                 AC_MSG_ERROR([PAM headers not found])
1255                         fi
1256
1257                         AC_CHECK_LIB(dl, dlopen, , )
1258                         AC_CHECK_LIB(pam, pam_set_item, , AC_MSG_ERROR([*** libpam missing]))
1259                         AC_CHECK_FUNCS(pam_getenvlist)
1260                         AC_CHECK_FUNCS(pam_putenv)
1261
1262                         PAM_MSG="yes"
1263
1264                         AC_DEFINE(USE_PAM)
1265                         if test $ac_cv_lib_dl_dlopen = yes; then
1266                                 LIBPAM="-lpam -ldl"
1267                         else
1268                                 LIBPAM="-lpam"
1269                         fi
1270                         AC_SUBST(LIBPAM)
1271                 fi
1272         ]
1273 )
1274
1275 # Check for older PAM
1276 if test "x$PAM_MSG" = "xyes" ; then
1277         # Check PAM strerror arguments (old PAM)
1278         AC_MSG_CHECKING([whether pam_strerror takes only one argument])
1279         AC_TRY_COMPILE(
1280                 [
1281 #include <stdlib.h>
1282 #if defined(HAVE_SECURITY_PAM_APPL_H)
1283 #include <security/pam_appl.h>
1284 #elif defined (HAVE_PAM_PAM_APPL_H)
1285 #include <pam/pam_appl.h>
1286 #endif
1287                 ],
1288                 [(void)pam_strerror((pam_handle_t *)NULL, -1);],
1289                 [AC_MSG_RESULT(no)],
1290                 [
1291                         AC_DEFINE(HAVE_OLD_PAM)
1292                         AC_MSG_RESULT(yes)
1293                         PAM_MSG="yes (old library)"
1294                 ]
1295         )
1296 fi
1297
1298 # Search for OpenSSL
1299 saved_CPPFLAGS="$CPPFLAGS"
1300 saved_LDFLAGS="$LDFLAGS"
1301 AC_ARG_WITH(ssl-dir,
1302         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
1303         [
1304                 if test "x$withval" != "xno" ; then
1305                         case "$withval" in
1306                                 # Relative paths
1307                                 ./*|../*)       withval="`pwd`/$withval"
1308                         esac
1309                         if test -d "$withval/lib"; then
1310                                 if test -n "${need_dash_r}"; then
1311                                         LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
1312                                 else
1313                                         LDFLAGS="-L${withval}/lib ${LDFLAGS}"
1314                                 fi
1315                         else
1316                                 if test -n "${need_dash_r}"; then
1317                                         LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
1318                                 else
1319                                         LDFLAGS="-L${withval} ${LDFLAGS}"
1320                                 fi
1321                         fi
1322                         if test -d "$withval/include"; then
1323                                 CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
1324                         else
1325                                 CPPFLAGS="-I${withval} ${CPPFLAGS}"
1326                         fi
1327                 fi
1328         ]
1329 )
1330 LIBS="-lcrypto $LIBS"
1331 AC_TRY_LINK_FUNC(RAND_add, AC_DEFINE(HAVE_OPENSSL),
1332         [
1333                 dnl Check default openssl install dir
1334                 if test -n "${need_dash_r}"; then
1335                         LDFLAGS="-L/usr/local/ssl/lib -R/usr/local/ssl/lib ${saved_LDFLAGS}"
1336                 else
1337                         LDFLAGS="-L/usr/local/ssl/lib ${saved_LDFLAGS}"
1338                 fi
1339                 CPPFLAGS="-I/usr/local/ssl/include ${saved_CPPFLAGS}"
1340                 AC_TRY_LINK_FUNC(RAND_add, AC_DEFINE(HAVE_OPENSSL),
1341                         [
1342                                 AC_MSG_ERROR([*** Can't find recent OpenSSL libcrypto (see config.log for details) ***])
1343                         ]
1344                 )
1345         ]
1346 )
1347
1348 # Determine OpenSSL header version
1349 AC_MSG_CHECKING([OpenSSL header version])
1350 AC_RUN_IFELSE(
1351         [AC_LANG_SOURCE([[
1352 #include <stdio.h>
1353 #include <string.h>
1354 #include <openssl/opensslv.h>
1355 #define DATA "conftest.sslincver"
1356 int main(void) {
1357         FILE *fd;
1358         int rc;
1359
1360         fd = fopen(DATA,"w");
1361         if(fd == NULL)
1362                 exit(1);
1363
1364         if ((rc = fprintf(fd ,"%x (%s)\n", OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT)) <0)
1365                 exit(1);
1366
1367         exit(0);
1368 }
1369         ]])],
1370         [
1371                 ssl_header_ver=`cat conftest.sslincver`
1372                 AC_MSG_RESULT($ssl_header_ver)
1373         ],
1374         [
1375                 AC_MSG_RESULT(not found)
1376                 AC_MSG_ERROR(OpenSSL version header not found.)
1377         ],
1378         [
1379                 AC_MSG_WARN([cross compiling: not checking])
1380         ]
1381 )
1382
1383 # Determine OpenSSL library version
1384 AC_MSG_CHECKING([OpenSSL library version])
1385 AC_RUN_IFELSE(
1386         [AC_LANG_SOURCE([[
1387 #include <stdio.h>
1388 #include <string.h>
1389 #include <openssl/opensslv.h>
1390 #include <openssl/crypto.h>
1391 #define DATA "conftest.ssllibver"
1392 int main(void) {
1393         FILE *fd;
1394         int rc;
1395
1396         fd = fopen(DATA,"w");
1397         if(fd == NULL)
1398                 exit(1);
1399
1400         if ((rc = fprintf(fd ,"%x (%s)\n", SSLeay(), SSLeay_version(SSLEAY_VERSION))) <0)
1401                 exit(1);
1402
1403         exit(0);
1404 }
1405         ]])],
1406         [
1407                 ssl_library_ver=`cat conftest.ssllibver`
1408                 AC_MSG_RESULT($ssl_library_ver)
1409         ],
1410         [
1411                 AC_MSG_RESULT(not found)
1412                 AC_MSG_ERROR(OpenSSL library not found.)
1413         ],
1414         [
1415                 AC_MSG_WARN([cross compiling: not checking])
1416         ]
1417 )
1418
1419 # Sanity check OpenSSL headers
1420 AC_MSG_CHECKING([whether OpenSSL's headers match the library])
1421 AC_RUN_IFELSE(
1422         [AC_LANG_SOURCE([[
1423 #include <string.h>
1424 #include <openssl/opensslv.h>
1425 int main(void) { exit(SSLeay() == OPENSSL_VERSION_NUMBER ? 0 : 1); }
1426         ]])],
1427         [
1428                 AC_MSG_RESULT(yes)
1429         ],
1430         [
1431                 AC_MSG_RESULT(no)
1432                 AC_MSG_ERROR([Your OpenSSL headers do not match your library.
1433 Check config.log for details.
1434 Also see contrib/findssl.sh for help identifying header/library mismatches.])
1435         ],
1436         [
1437                 AC_MSG_WARN([cross compiling: not checking])
1438         ]
1439 )
1440
1441 # Some systems want crypt() from libcrypt, *not* the version in OpenSSL,
1442 # because the system crypt() is more featureful.
1443 if test "x$check_for_libcrypt_before" = "x1"; then
1444         AC_CHECK_LIB(crypt, crypt)
1445 fi
1446
1447 # Some Linux systems (Slackware) need crypt() from libcrypt, *not* the
1448 # version in OpenSSL.
1449 if test "x$check_for_libcrypt_later" = "x1"; then
1450         AC_CHECK_LIB(crypt, crypt, LIBS="$LIBS -lcrypt")
1451 fi
1452
1453
1454 ### Configure cryptographic random number support
1455
1456 # Check wheter OpenSSL seeds itself
1457 AC_MSG_CHECKING([whether OpenSSL's PRNG is internally seeded])
1458 AC_RUN_IFELSE(
1459         [AC_LANG_SOURCE([[
1460 #include <string.h>
1461 #include <openssl/rand.h>
1462 int main(void) { exit(RAND_status() == 1 ? 0 : 1); }
1463         ]])],
1464         [
1465                 OPENSSL_SEEDS_ITSELF=yes
1466                 AC_MSG_RESULT(yes)
1467         ],
1468         [
1469                 AC_MSG_RESULT(no)
1470                 # Default to use of the rand helper if OpenSSL doesn't
1471                 # seed itself
1472                 USE_RAND_HELPER=yes
1473         ],
1474         [
1475                 AC_MSG_WARN([cross compiling: assuming yes])
1476                 # This is safe, since all recent OpenSSL versions will
1477                 # complain at runtime if not seeded correctly. 
1478                 OPENSSL_SEEDS_ITSELF=yes
1479         ]
1480 )
1481
1482
1483 # Do we want to force the use of the rand helper?
1484 AC_ARG_WITH(rand-helper,
1485         [  --with-rand-helper      Use subprocess to gather strong randomness ],
1486         [
1487                 if test "x$withval" = "xno" ; then
1488                         # Force use of OpenSSL's internal RNG, even if
1489                         # the previous test showed it to be unseeded.
1490                         if test -z "$OPENSSL_SEEDS_ITSELF" ; then
1491                                 AC_MSG_WARN([*** Forcing use of OpenSSL's non-self-seeding PRNG])
1492                                 OPENSSL_SEEDS_ITSELF=yes
1493                                 USE_RAND_HELPER=""
1494                         fi
1495                 else
1496                         USE_RAND_HELPER=yes
1497                 fi
1498         ],
1499 )       
1500
1501 # Which randomness source do we use?
1502 if test ! -z "$OPENSSL_SEEDS_ITSELF" && test -z "$USE_RAND_HELPER" ; then
1503         # OpenSSL only
1504         AC_DEFINE(OPENSSL_PRNG_ONLY)
1505         RAND_MSG="OpenSSL internal ONLY"
1506         INSTALL_SSH_RAND_HELPER=""
1507 elif test ! -z "$USE_RAND_HELPER" ; then
1508         # install rand helper
1509         RAND_MSG="ssh-rand-helper"
1510         INSTALL_SSH_RAND_HELPER="yes"
1511 fi
1512 AC_SUBST(INSTALL_SSH_RAND_HELPER)
1513
1514 ### Configuration of ssh-rand-helper
1515
1516 # PRNGD TCP socket
1517 AC_ARG_WITH(prngd-port,
1518         [  --with-prngd-port=PORT  read entropy from PRNGD/EGD TCP localhost:PORT],
1519         [
1520                 case "$withval" in
1521                 no)
1522                         withval=""
1523                         ;;
1524                 [[0-9]]*)
1525                         ;;
1526                 *)
1527                         AC_MSG_ERROR(You must specify a numeric port number for --with-prngd-port)
1528                         ;;
1529                 esac
1530                 if test ! -z "$withval" ; then
1531                         PRNGD_PORT="$withval"
1532                         AC_DEFINE_UNQUOTED(PRNGD_PORT, $PRNGD_PORT)
1533                 fi
1534         ]
1535 )
1536
1537 # PRNGD Unix domain socket
1538 AC_ARG_WITH(prngd-socket,
1539         [  --with-prngd-socket=FILE read entropy from PRNGD/EGD socket FILE (default=/var/run/egd-pool)],
1540         [
1541                 case "$withval" in
1542                 yes)
1543                         withval="/var/run/egd-pool"
1544                         ;;
1545                 no)
1546                         withval=""
1547                         ;;
1548                 /*)
1549                         ;;
1550                 *)
1551                         AC_MSG_ERROR(You must specify an absolute path to the entropy socket)
1552                         ;;
1553                 esac
1554
1555                 if test ! -z "$withval" ; then
1556                         if test ! -z "$PRNGD_PORT" ; then
1557                                 AC_MSG_ERROR(You may not specify both a PRNGD/EGD port and socket)
1558                         fi
1559                         if test ! -r "$withval" ; then
1560                                 AC_MSG_WARN(Entropy socket is not readable)
1561                         fi
1562                         PRNGD_SOCKET="$withval"
1563                         AC_DEFINE_UNQUOTED(PRNGD_SOCKET, "$PRNGD_SOCKET")
1564                 fi
1565         ],
1566         [
1567                 # Check for existing socket only if we don't have a random device already
1568                 if test "$USE_RAND_HELPER" = yes ; then
1569                         AC_MSG_CHECKING(for PRNGD/EGD socket)
1570                         # Insert other locations here
1571                         for sock in /var/run/egd-pool /dev/egd-pool /etc/entropy; do
1572                                 if test -r $sock && $TEST_MINUS_S_SH -c "test -S $sock -o -p $sock" ; then
1573                                         PRNGD_SOCKET="$sock"
1574                                         AC_DEFINE_UNQUOTED(PRNGD_SOCKET, "$PRNGD_SOCKET")
1575                                         break;
1576                                 fi
1577                         done
1578                         if test ! -z "$PRNGD_SOCKET" ; then
1579                                 AC_MSG_RESULT($PRNGD_SOCKET)
1580                         else
1581                                 AC_MSG_RESULT(not found)
1582                         fi
1583                 fi
1584         ]
1585 )
1586
1587 # Change default command timeout for hashing entropy source
1588 entropy_timeout=200
1589 AC_ARG_WITH(entropy-timeout,
1590         [  --with-entropy-timeout  Specify entropy gathering command timeout (msec)],
1591         [
1592                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
1593                     test "x${withval}" != "xyes"; then
1594                         entropy_timeout=$withval
1595                 fi
1596         ]       
1597 )
1598 AC_DEFINE_UNQUOTED(ENTROPY_TIMEOUT_MSEC, $entropy_timeout)
1599
1600 SSH_PRIVSEP_USER=sshd
1601 AC_ARG_WITH(privsep-user,
1602         [  --with-privsep-user=user Specify non-privileged user for privilege separation],
1603         [
1604                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
1605                     test "x${withval}" != "xyes"; then
1606                         SSH_PRIVSEP_USER=$withval
1607                 fi
1608         ]       
1609 )
1610 AC_DEFINE_UNQUOTED(SSH_PRIVSEP_USER, "$SSH_PRIVSEP_USER")
1611 AC_SUBST(SSH_PRIVSEP_USER)
1612
1613 # We do this little dance with the search path to insure
1614 # that programs that we select for use by installed programs
1615 # (which may be run by the super-user) come from trusted
1616 # locations before they come from the user's private area.
1617 # This should help avoid accidentally configuring some
1618 # random version of a program in someone's personal bin.
1619
1620 OPATH=$PATH
1621 PATH=/bin:/usr/bin
1622 test -h /bin 2> /dev/null && PATH=/usr/bin
1623 test -d /sbin && PATH=$PATH:/sbin
1624 test -d /usr/sbin && PATH=$PATH:/usr/sbin
1625 PATH=$PATH:/etc:$OPATH
1626
1627 # These programs are used by the command hashing source to gather entropy
1628 OSSH_PATH_ENTROPY_PROG(PROG_LS, ls)
1629 OSSH_PATH_ENTROPY_PROG(PROG_NETSTAT, netstat)
1630 OSSH_PATH_ENTROPY_PROG(PROG_ARP, arp)
1631 OSSH_PATH_ENTROPY_PROG(PROG_IFCONFIG, ifconfig)
1632 OSSH_PATH_ENTROPY_PROG(PROG_JSTAT, jstat)
1633 OSSH_PATH_ENTROPY_PROG(PROG_PS, ps)
1634 OSSH_PATH_ENTROPY_PROG(PROG_SAR, sar)
1635 OSSH_PATH_ENTROPY_PROG(PROG_W, w)
1636 OSSH_PATH_ENTROPY_PROG(PROG_WHO, who)
1637 OSSH_PATH_ENTROPY_PROG(PROG_LAST, last)
1638 OSSH_PATH_ENTROPY_PROG(PROG_LASTLOG, lastlog)
1639 OSSH_PATH_ENTROPY_PROG(PROG_DF, df)
1640 OSSH_PATH_ENTROPY_PROG(PROG_VMSTAT, vmstat)
1641 OSSH_PATH_ENTROPY_PROG(PROG_UPTIME, uptime)
1642 OSSH_PATH_ENTROPY_PROG(PROG_IPCS, ipcs)
1643 OSSH_PATH_ENTROPY_PROG(PROG_TAIL, tail)
1644 # restore PATH
1645 PATH=$OPATH
1646
1647 # Where does ssh-rand-helper get its randomness from?
1648 INSTALL_SSH_PRNG_CMDS=""
1649 if test ! -z "$INSTALL_SSH_RAND_HELPER" ; then
1650         if test ! -z "$PRNGD_PORT" ; then
1651                 RAND_HELPER_MSG="TCP localhost:$PRNGD_PORT"
1652         elif test ! -z "$PRNGD_SOCKET" ; then
1653                 RAND_HELPER_MSG="Unix domain socket \"$PRNGD_SOCKET\""
1654         else
1655                 RAND_HELPER_MSG="Command hashing (timeout $entropy_timeout)"
1656                 RAND_HELPER_CMDHASH=yes
1657                 INSTALL_SSH_PRNG_CMDS="yes"
1658         fi
1659 fi
1660 AC_SUBST(INSTALL_SSH_PRNG_CMDS)
1661
1662
1663 # Cheap hack to ensure NEWS-OS libraries are arranged right.
1664 if test ! -z "$SONY" ; then
1665   LIBS="$LIBS -liberty";
1666 fi
1667
1668 # Checks for data types
1669 AC_CHECK_SIZEOF(char, 1)
1670 AC_CHECK_SIZEOF(short int, 2)
1671 AC_CHECK_SIZEOF(int, 4)
1672 AC_CHECK_SIZEOF(long int, 4)
1673 AC_CHECK_SIZEOF(long long int, 8)
1674
1675 # Sanity check long long for some platforms (AIX)
1676 if test "x$ac_cv_sizeof_long_long_int" = "x4" ; then
1677         ac_cv_sizeof_long_long_int=0
1678 fi
1679
1680 # More checks for data types
1681 AC_CACHE_CHECK([for u_int type], ac_cv_have_u_int, [
1682         AC_TRY_COMPILE(
1683                 [ #include <sys/types.h> ],
1684                 [ u_int a; a = 1;],
1685                 [ ac_cv_have_u_int="yes" ],
1686                 [ ac_cv_have_u_int="no" ]
1687         )
1688 ])
1689 if test "x$ac_cv_have_u_int" = "xyes" ; then
1690         AC_DEFINE(HAVE_U_INT)
1691         have_u_int=1
1692 fi
1693
1694 AC_CACHE_CHECK([for intXX_t types], ac_cv_have_intxx_t, [
1695         AC_TRY_COMPILE(
1696                 [ #include <sys/types.h> ],
1697                 [ int8_t a; int16_t b; int32_t c; a = b = c = 1;],
1698                 [ ac_cv_have_intxx_t="yes" ],
1699                 [ ac_cv_have_intxx_t="no" ]
1700         )
1701 ])
1702 if test "x$ac_cv_have_intxx_t" = "xyes" ; then
1703         AC_DEFINE(HAVE_INTXX_T)
1704         have_intxx_t=1
1705 fi
1706
1707 if (test -z "$have_intxx_t" && \
1708            test "x$ac_cv_header_stdint_h" = "xyes")
1709 then
1710     AC_MSG_CHECKING([for intXX_t types in stdint.h])
1711         AC_TRY_COMPILE(
1712                 [ #include <stdint.h> ],
1713                 [ int8_t a; int16_t b; int32_t c; a = b = c = 1;],
1714                 [
1715                         AC_DEFINE(HAVE_INTXX_T)
1716                         AC_MSG_RESULT(yes)
1717                 ],
1718                 [ AC_MSG_RESULT(no) ]
1719         )
1720 fi
1721
1722 AC_CACHE_CHECK([for int64_t type], ac_cv_have_int64_t, [
1723         AC_TRY_COMPILE(
1724                 [
1725 #include <sys/types.h>
1726 #ifdef HAVE_STDINT_H
1727 # include <stdint.h>
1728 #endif
1729 #include <sys/socket.h>
1730 #ifdef HAVE_SYS_BITYPES_H
1731 # include <sys/bitypes.h>
1732 #endif
1733                 ],
1734                 [ int64_t a; a = 1;],
1735                 [ ac_cv_have_int64_t="yes" ],
1736                 [ ac_cv_have_int64_t="no" ]
1737         )
1738 ])
1739 if test "x$ac_cv_have_int64_t" = "xyes" ; then
1740         AC_DEFINE(HAVE_INT64_T)
1741 fi
1742
1743 AC_CACHE_CHECK([for u_intXX_t types], ac_cv_have_u_intxx_t, [
1744         AC_TRY_COMPILE(
1745                 [ #include <sys/types.h> ],
1746                 [ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;],
1747                 [ ac_cv_have_u_intxx_t="yes" ],
1748                 [ ac_cv_have_u_intxx_t="no" ]
1749         )
1750 ])
1751 if test "x$ac_cv_have_u_intxx_t" = "xyes" ; then
1752         AC_DEFINE(HAVE_U_INTXX_T)
1753         have_u_intxx_t=1
1754 fi
1755
1756 if test -z "$have_u_intxx_t" ; then
1757     AC_MSG_CHECKING([for u_intXX_t types in sys/socket.h])
1758         AC_TRY_COMPILE(
1759                 [ #include <sys/socket.h> ],
1760                 [ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;],
1761                 [
1762                         AC_DEFINE(HAVE_U_INTXX_T)
1763                         AC_MSG_RESULT(yes)
1764                 ],
1765                 [ AC_MSG_RESULT(no) ]
1766         )
1767 fi
1768
1769 AC_CACHE_CHECK([for u_int64_t types], ac_cv_have_u_int64_t, [
1770         AC_TRY_COMPILE(
1771                 [ #include <sys/types.h> ],
1772                 [ u_int64_t a; a = 1;],
1773                 [ ac_cv_have_u_int64_t="yes" ],
1774                 [ ac_cv_have_u_int64_t="no" ]
1775         )
1776 ])
1777 if test "x$ac_cv_have_u_int64_t" = "xyes" ; then
1778         AC_DEFINE(HAVE_U_INT64_T)
1779         have_u_int64_t=1
1780 fi
1781
1782 if test -z "$have_u_int64_t" ; then
1783     AC_MSG_CHECKING([for u_int64_t type in sys/bitypes.h])
1784         AC_TRY_COMPILE(
1785                 [ #include <sys/bitypes.h> ],
1786                 [ u_int64_t a; a = 1],
1787                 [
1788                         AC_DEFINE(HAVE_U_INT64_T)
1789                         AC_MSG_RESULT(yes)
1790                 ],
1791                 [ AC_MSG_RESULT(no) ]
1792         )
1793 fi
1794
1795 if test -z "$have_u_intxx_t" ; then
1796         AC_CACHE_CHECK([for uintXX_t types], ac_cv_have_uintxx_t, [
1797                 AC_TRY_COMPILE(
1798                         [
1799 #include <sys/types.h>
1800                         ],
1801                         [ uint8_t a; uint16_t b; uint32_t c; a = b = c = 1; ],
1802                         [ ac_cv_have_uintxx_t="yes" ],
1803                         [ ac_cv_have_uintxx_t="no" ]
1804                 )
1805         ])
1806         if test "x$ac_cv_have_uintxx_t" = "xyes" ; then
1807                 AC_DEFINE(HAVE_UINTXX_T)
1808         fi
1809 fi
1810
1811 if test -z "$have_uintxx_t" ; then
1812     AC_MSG_CHECKING([for uintXX_t types in stdint.h])
1813         AC_TRY_COMPILE(
1814                 [ #include <stdint.h> ],
1815                 [ uint8_t a; uint16_t b; uint32_t c; a = b = c = 1;],
1816                 [
1817                         AC_DEFINE(HAVE_UINTXX_T)
1818                         AC_MSG_RESULT(yes)
1819                 ],
1820                 [ AC_MSG_RESULT(no) ]
1821         )
1822 fi
1823
1824 if (test -z "$have_u_intxx_t" || test -z "$have_intxx_t" && \
1825            test "x$ac_cv_header_sys_bitypes_h" = "xyes")
1826 then
1827         AC_MSG_CHECKING([for intXX_t and u_intXX_t types in sys/bitypes.h])
1828         AC_TRY_COMPILE(
1829                 [
1830 #include <sys/bitypes.h>
1831                 ],
1832                 [
1833                         int8_t a; int16_t b; int32_t c;
1834                         u_int8_t e; u_int16_t f; u_int32_t g;
1835                         a = b = c = e = f = g = 1;
1836                 ],
1837                 [
1838                         AC_DEFINE(HAVE_U_INTXX_T)
1839                         AC_DEFINE(HAVE_INTXX_T)
1840                         AC_MSG_RESULT(yes)
1841                 ],
1842                 [AC_MSG_RESULT(no)]
1843         )
1844 fi
1845
1846
1847 AC_CACHE_CHECK([for u_char], ac_cv_have_u_char, [
1848         AC_TRY_COMPILE(
1849                 [
1850 #include <sys/types.h>
1851                 ],
1852                 [ u_char foo; foo = 125; ],
1853                 [ ac_cv_have_u_char="yes" ],
1854                 [ ac_cv_have_u_char="no" ]
1855         )
1856 ])
1857 if test "x$ac_cv_have_u_char" = "xyes" ; then
1858         AC_DEFINE(HAVE_U_CHAR)
1859 fi
1860
1861 TYPE_SOCKLEN_T
1862
1863 AC_CHECK_TYPES(sig_atomic_t,,,[#include <signal.h>])
1864
1865 AC_CHECK_TYPES(in_addr_t,,,
1866 [#include <sys/types.h>
1867 #include <netinet/in.h>])
1868
1869 AC_CACHE_CHECK([for size_t], ac_cv_have_size_t, [
1870         AC_TRY_COMPILE(
1871                 [
1872 #include <sys/types.h>
1873                 ],
1874                 [ size_t foo; foo = 1235; ],
1875                 [ ac_cv_have_size_t="yes" ],
1876                 [ ac_cv_have_size_t="no" ]
1877         )
1878 ])
1879 if test "x$ac_cv_have_size_t" = "xyes" ; then
1880         AC_DEFINE(HAVE_SIZE_T)
1881 fi
1882
1883 AC_CACHE_CHECK([for ssize_t], ac_cv_have_ssize_t, [
1884         AC_TRY_COMPILE(
1885                 [
1886 #include <sys/types.h>
1887                 ],
1888                 [ ssize_t foo; foo = 1235; ],
1889                 [ ac_cv_have_ssize_t="yes" ],
1890                 [ ac_cv_have_ssize_t="no" ]
1891         )
1892 ])
1893 if test "x$ac_cv_have_ssize_t" = "xyes" ; then
1894         AC_DEFINE(HAVE_SSIZE_T)
1895 fi
1896
1897 AC_CACHE_CHECK([for clock_t], ac_cv_have_clock_t, [
1898         AC_TRY_COMPILE(
1899                 [
1900 #include <time.h>
1901                 ],
1902                 [ clock_t foo; foo = 1235; ],
1903                 [ ac_cv_have_clock_t="yes" ],
1904                 [ ac_cv_have_clock_t="no" ]
1905         )
1906 ])
1907 if test "x$ac_cv_have_clock_t" = "xyes" ; then
1908         AC_DEFINE(HAVE_CLOCK_T)
1909 fi
1910
1911 AC_CACHE_CHECK([for sa_family_t], ac_cv_have_sa_family_t, [
1912         AC_TRY_COMPILE(
1913                 [
1914 #include <sys/types.h>
1915 #include <sys/socket.h>
1916                 ],
1917                 [ sa_family_t foo; foo = 1235; ],
1918                 [ ac_cv_have_sa_family_t="yes" ],
1919                 [ AC_TRY_COMPILE(
1920                   [
1921 #include <sys/types.h>
1922 #include <sys/socket.h>
1923 #include <netinet/in.h>
1924                 ],
1925                 [ sa_family_t foo; foo = 1235; ],
1926                 [ ac_cv_have_sa_family_t="yes" ],
1927
1928                 [ ac_cv_have_sa_family_t="no" ]
1929         )]
1930         )
1931 ])
1932 if test "x$ac_cv_have_sa_family_t" = "xyes" ; then
1933         AC_DEFINE(HAVE_SA_FAMILY_T)
1934 fi
1935
1936 AC_CACHE_CHECK([for pid_t], ac_cv_have_pid_t, [
1937         AC_TRY_COMPILE(
1938                 [
1939 #include <sys/types.h>
1940                 ],
1941                 [ pid_t foo; foo = 1235; ],
1942                 [ ac_cv_have_pid_t="yes" ],
1943                 [ ac_cv_have_pid_t="no" ]
1944         )
1945 ])
1946 if test "x$ac_cv_have_pid_t" = "xyes" ; then
1947         AC_DEFINE(HAVE_PID_T)
1948 fi
1949
1950 AC_CACHE_CHECK([for mode_t], ac_cv_have_mode_t, [
1951         AC_TRY_COMPILE(
1952                 [
1953 #include <sys/types.h>
1954                 ],
1955                 [ mode_t foo; foo = 1235; ],
1956                 [ ac_cv_have_mode_t="yes" ],
1957                 [ ac_cv_have_mode_t="no" ]
1958         )
1959 ])
1960 if test "x$ac_cv_have_mode_t" = "xyes" ; then
1961         AC_DEFINE(HAVE_MODE_T)
1962 fi
1963
1964
1965 AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
1966         AC_TRY_COMPILE(
1967                 [
1968 #include <sys/types.h>
1969 #include <sys/socket.h>
1970                 ],
1971                 [ struct sockaddr_storage s; ],
1972                 [ ac_cv_have_struct_sockaddr_storage="yes" ],
1973                 [ ac_cv_have_struct_sockaddr_storage="no" ]
1974         )
1975 ])
1976 if test "x$ac_cv_have_struct_sockaddr_storage" = "xyes" ; then
1977         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE)
1978 fi
1979
1980 AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
1981         AC_TRY_COMPILE(
1982                 [
1983 #include <sys/types.h>
1984 #include <netinet/in.h>
1985                 ],
1986                 [ struct sockaddr_in6 s; s.sin6_family = 0; ],
1987                 [ ac_cv_have_struct_sockaddr_in6="yes" ],
1988                 [ ac_cv_have_struct_sockaddr_in6="no" ]
1989         )
1990 ])
1991 if test "x$ac_cv_have_struct_sockaddr_in6" = "xyes" ; then
1992         AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6)
1993 fi
1994
1995 AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
1996         AC_TRY_COMPILE(
1997                 [
1998 #include <sys/types.h>
1999 #include <netinet/in.h>
2000                 ],
2001                 [ struct in6_addr s; s.s6_addr[0] = 0; ],
2002                 [ ac_cv_have_struct_in6_addr="yes" ],
2003                 [ ac_cv_have_struct_in6_addr="no" ]
2004         )
2005 ])
2006 if test "x$ac_cv_have_struct_in6_addr" = "xyes" ; then
2007         AC_DEFINE(HAVE_STRUCT_IN6_ADDR)
2008 fi
2009
2010 AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
2011         AC_TRY_COMPILE(
2012                 [
2013 #include <sys/types.h>
2014 #include <sys/socket.h>
2015 #include <netdb.h>
2016                 ],
2017                 [ struct addrinfo s; s.ai_flags = AI_PASSIVE; ],
2018                 [ ac_cv_have_struct_addrinfo="yes" ],
2019                 [ ac_cv_have_struct_addrinfo="no" ]
2020         )
2021 ])
2022 if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then
2023         AC_DEFINE(HAVE_STRUCT_ADDRINFO)
2024 fi
2025
2026 AC_CACHE_CHECK([for struct timeval], ac_cv_have_struct_timeval, [
2027         AC_TRY_COMPILE(
2028                 [ #include <sys/time.h> ],
2029                 [ struct timeval tv; tv.tv_sec = 1;],
2030                 [ ac_cv_have_struct_timeval="yes" ],
2031                 [ ac_cv_have_struct_timeval="no" ]
2032         )
2033 ])
2034 if test "x$ac_cv_have_struct_timeval" = "xyes" ; then
2035         AC_DEFINE(HAVE_STRUCT_TIMEVAL)
2036         have_struct_timeval=1
2037 fi
2038
2039 AC_CHECK_TYPES(struct timespec)
2040
2041 # We need int64_t or else certian parts of the compile will fail.
2042 if test "x$ac_cv_have_int64_t" = "xno" && \
2043         test "x$ac_cv_sizeof_long_int" != "x8" && \
2044         test "x$ac_cv_sizeof_long_long_int" = "x0" ; then
2045         echo "OpenSSH requires int64_t support.  Contact your vendor or install"
2046         echo "an alternative compiler (I.E., GCC) before continuing."
2047         echo ""
2048         exit 1;
2049 else
2050 dnl test snprintf (broken on SCO w/gcc)
2051         AC_RUN_IFELSE(
2052                 [AC_LANG_SOURCE([[
2053 #include <stdio.h>
2054 #include <string.h>
2055 #ifdef HAVE_SNPRINTF
2056 main()
2057 {
2058         char buf[50];
2059         char expected_out[50];
2060         int mazsize = 50 ;
2061 #if (SIZEOF_LONG_INT == 8)
2062         long int num = 0x7fffffffffffffff;
2063 #else
2064         long long num = 0x7fffffffffffffffll;
2065 #endif
2066         strcpy(expected_out, "9223372036854775807");
2067         snprintf(buf, mazsize, "%lld", num);
2068         if(strcmp(buf, expected_out) != 0)
2069                 exit(1);
2070         exit(0);
2071 }
2072 #else
2073 main() { exit(0); }
2074 #endif
2075                 ]])], [ true ], [ AC_DEFINE(BROKEN_SNPRINTF) ],
2076                 AC_MSG_WARN([cross compiling: Assuming working snprintf()])
2077         )
2078 fi
2079
2080 dnl Checks for structure members
2081 OSSH_CHECK_HEADER_FOR_FIELD(ut_host, utmp.h, HAVE_HOST_IN_UTMP)
2082 OSSH_CHECK_HEADER_FOR_FIELD(ut_host, utmpx.h, HAVE_HOST_IN_UTMPX)
2083 OSSH_CHECK_HEADER_FOR_FIELD(syslen, utmpx.h, HAVE_SYSLEN_IN_UTMPX)
2084 OSSH_CHECK_HEADER_FOR_FIELD(ut_pid, utmp.h, HAVE_PID_IN_UTMP)
2085 OSSH_CHECK_HEADER_FOR_FIELD(ut_type, utmp.h, HAVE_TYPE_IN_UTMP)
2086 OSSH_CHECK_HEADER_FOR_FIELD(ut_type, utmpx.h, HAVE_TYPE_IN_UTMPX)
2087 OSSH_CHECK_HEADER_FOR_FIELD(ut_tv, utmp.h, HAVE_TV_IN_UTMP)
2088 OSSH_CHECK_HEADER_FOR_FIELD(ut_id, utmp.h, HAVE_ID_IN_UTMP)
2089 OSSH_CHECK_HEADER_FOR_FIELD(ut_id, utmpx.h, HAVE_ID_IN_UTMPX)
2090 OSSH_CHECK_HEADER_FOR_FIELD(ut_addr, utmp.h, HAVE_ADDR_IN_UTMP)
2091 OSSH_CHECK_HEADER_FOR_FIELD(ut_addr, utmpx.h, HAVE_ADDR_IN_UTMPX)
2092 OSSH_CHECK_HEADER_FOR_FIELD(ut_addr_v6, utmp.h, HAVE_ADDR_V6_IN_UTMP)
2093 OSSH_CHECK_HEADER_FOR_FIELD(ut_addr_v6, utmpx.h, HAVE_ADDR_V6_IN_UTMPX)
2094 OSSH_CHECK_HEADER_FOR_FIELD(ut_exit, utmp.h, HAVE_EXIT_IN_UTMP)
2095 OSSH_CHECK_HEADER_FOR_FIELD(ut_time, utmp.h, HAVE_TIME_IN_UTMP)
2096 OSSH_CHECK_HEADER_FOR_FIELD(ut_time, utmpx.h, HAVE_TIME_IN_UTMPX)
2097 OSSH_CHECK_HEADER_FOR_FIELD(ut_tv, utmpx.h, HAVE_TV_IN_UTMPX)
2098
2099 AC_CHECK_MEMBERS([struct stat.st_blksize])
2100
2101 AC_CACHE_CHECK([for ss_family field in struct sockaddr_storage],
2102                 ac_cv_have_ss_family_in_struct_ss, [
2103         AC_TRY_COMPILE(
2104                 [
2105 #include <sys/types.h>
2106 #include <sys/socket.h>
2107                 ],
2108                 [ struct sockaddr_storage s; s.ss_family = 1; ],
2109                 [ ac_cv_have_ss_family_in_struct_ss="yes" ],
2110                 [ ac_cv_have_ss_family_in_struct_ss="no" ],
2111         )
2112 ])
2113 if test "x$ac_cv_have_ss_family_in_struct_ss" = "xyes" ; then
2114         AC_DEFINE(HAVE_SS_FAMILY_IN_SS)
2115 fi
2116
2117 AC_CACHE_CHECK([for __ss_family field in struct sockaddr_storage],
2118                 ac_cv_have___ss_family_in_struct_ss, [
2119         AC_TRY_COMPILE(
2120                 [
2121 #include <sys/types.h>
2122 #include <sys/socket.h>
2123                 ],
2124                 [ struct sockaddr_storage s; s.__ss_family = 1; ],
2125                 [ ac_cv_have___ss_family_in_struct_ss="yes" ],
2126                 [ ac_cv_have___ss_family_in_struct_ss="no" ]
2127         )
2128 ])
2129 if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then
2130         AC_DEFINE(HAVE___SS_FAMILY_IN_SS)
2131 fi
2132
2133 AC_CACHE_CHECK([for pw_class field in struct passwd],
2134                 ac_cv_have_pw_class_in_struct_passwd, [
2135         AC_TRY_COMPILE(
2136                 [
2137 #include <pwd.h>
2138                 ],
2139                 [ struct passwd p; p.pw_class = 0; ],
2140                 [ ac_cv_have_pw_class_in_struct_passwd="yes" ],
2141                 [ ac_cv_have_pw_class_in_struct_passwd="no" ]
2142         )
2143 ])
2144 if test "x$ac_cv_have_pw_class_in_struct_passwd" = "xyes" ; then
2145         AC_DEFINE(HAVE_PW_CLASS_IN_PASSWD)
2146 fi
2147
2148 AC_CACHE_CHECK([for pw_expire field in struct passwd],
2149                 ac_cv_have_pw_expire_in_struct_passwd, [
2150         AC_TRY_COMPILE(
2151                 [
2152 #include <pwd.h>
2153                 ],
2154                 [ struct passwd p; p.pw_expire = 0; ],
2155                 [ ac_cv_have_pw_expire_in_struct_passwd="yes" ],
2156                 [ ac_cv_have_pw_expire_in_struct_passwd="no" ]
2157         )
2158 ])
2159 if test "x$ac_cv_have_pw_expire_in_struct_passwd" = "xyes" ; then
2160         AC_DEFINE(HAVE_PW_EXPIRE_IN_PASSWD)
2161 fi
2162
2163 AC_CACHE_CHECK([for pw_change field in struct passwd],
2164                 ac_cv_have_pw_change_in_struct_passwd, [
2165         AC_TRY_COMPILE(
2166                 [
2167 #include <pwd.h>
2168                 ],
2169                 [ struct passwd p; p.pw_change = 0; ],
2170                 [ ac_cv_have_pw_change_in_struct_passwd="yes" ],
2171                 [ ac_cv_have_pw_change_in_struct_passwd="no" ]
2172         )
2173 ])
2174 if test "x$ac_cv_have_pw_change_in_struct_passwd" = "xyes" ; then
2175         AC_DEFINE(HAVE_PW_CHANGE_IN_PASSWD)
2176 fi
2177
2178 dnl make sure we're using the real structure members and not defines
2179 AC_CACHE_CHECK([for msg_accrights field in struct msghdr],
2180                 ac_cv_have_accrights_in_msghdr, [
2181         AC_COMPILE_IFELSE(
2182                 [
2183 #include <sys/types.h>
2184 #include <sys/socket.h>
2185 #include <sys/uio.h>
2186 int main() {
2187 #ifdef msg_accrights
2188 #error "msg_accrights is a macro"
2189 exit(1);
2190 #endif
2191 struct msghdr m;
2192 m.msg_accrights = 0;
2193 exit(0);
2194 }
2195                 ],
2196                 [ ac_cv_have_accrights_in_msghdr="yes" ],
2197                 [ ac_cv_have_accrights_in_msghdr="no" ]
2198         )
2199 ])
2200 if test "x$ac_cv_have_accrights_in_msghdr" = "xyes" ; then
2201         AC_DEFINE(HAVE_ACCRIGHTS_IN_MSGHDR)
2202 fi
2203
2204 AC_CACHE_CHECK([for msg_control field in struct msghdr],
2205                 ac_cv_have_control_in_msghdr, [
2206         AC_COMPILE_IFELSE(
2207                 [
2208 #include <sys/types.h>
2209 #include <sys/socket.h>
2210 #include <sys/uio.h>
2211 int main() {
2212 #ifdef msg_control
2213 #error "msg_control is a macro"
2214 exit(1);
2215 #endif
2216 struct msghdr m;
2217 m.msg_control = 0;
2218 exit(0);
2219 }
2220                 ],
2221                 [ ac_cv_have_control_in_msghdr="yes" ],
2222                 [ ac_cv_have_control_in_msghdr="no" ]
2223         )
2224 ])
2225 if test "x$ac_cv_have_control_in_msghdr" = "xyes" ; then
2226         AC_DEFINE(HAVE_CONTROL_IN_MSGHDR)
2227 fi
2228
2229 AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
2230         AC_TRY_LINK([],
2231                 [ extern char *__progname; printf("%s", __progname); ],
2232                 [ ac_cv_libc_defines___progname="yes" ],
2233                 [ ac_cv_libc_defines___progname="no" ]
2234         )
2235 ])
2236 if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
2237         AC_DEFINE(HAVE___PROGNAME)
2238 fi
2239
2240 AC_CACHE_CHECK([whether $CC implements __FUNCTION__], ac_cv_cc_implements___FUNCTION__, [
2241         AC_TRY_LINK([
2242 #include <stdio.h>
2243 ],
2244                 [ printf("%s", __FUNCTION__); ],
2245                 [ ac_cv_cc_implements___FUNCTION__="yes" ],
2246                 [ ac_cv_cc_implements___FUNCTION__="no" ]
2247         )
2248 ])
2249 if test "x$ac_cv_cc_implements___FUNCTION__" = "xyes" ; then
2250         AC_DEFINE(HAVE___FUNCTION__)
2251 fi
2252
2253 AC_CACHE_CHECK([whether $CC implements __func__], ac_cv_cc_implements___func__, [
2254         AC_TRY_LINK([
2255 #include <stdio.h>
2256 ],
2257                 [ printf("%s", __func__); ],
2258                 [ ac_cv_cc_implements___func__="yes" ],
2259                 [ ac_cv_cc_implements___func__="no" ]
2260         )
2261 ])
2262 if test "x$ac_cv_cc_implements___func__" = "xyes" ; then
2263         AC_DEFINE(HAVE___func__)
2264 fi
2265
2266 AC_CACHE_CHECK([whether getopt has optreset support],
2267                 ac_cv_have_getopt_optreset, [
2268         AC_TRY_LINK(
2269                 [
2270 #include <getopt.h>
2271                 ],
2272                 [ extern int optreset; optreset = 0; ],
2273                 [ ac_cv_have_getopt_optreset="yes" ],
2274                 [ ac_cv_have_getopt_optreset="no" ]
2275         )
2276 ])
2277 if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
2278         AC_DEFINE(HAVE_GETOPT_OPTRESET)
2279 fi
2280
2281 AC_CACHE_CHECK([if libc defines sys_errlist], ac_cv_libc_defines_sys_errlist, [
2282         AC_TRY_LINK([],
2283                 [ extern const char *const sys_errlist[]; printf("%s", sys_errlist[0]);],
2284                 [ ac_cv_libc_defines_sys_errlist="yes" ],
2285                 [ ac_cv_libc_defines_sys_errlist="no" ]
2286         )
2287 ])
2288 if test "x$ac_cv_libc_defines_sys_errlist" = "xyes" ; then
2289         AC_DEFINE(HAVE_SYS_ERRLIST)
2290 fi
2291
2292
2293 AC_CACHE_CHECK([if libc defines sys_nerr], ac_cv_libc_defines_sys_nerr, [
2294         AC_TRY_LINK([],
2295                 [ extern int sys_nerr; printf("%i", sys_nerr);],
2296                 [ ac_cv_libc_defines_sys_nerr="yes" ],
2297                 [ ac_cv_libc_defines_sys_nerr="no" ]
2298         )
2299 ])
2300 if test "x$ac_cv_libc_defines_sys_nerr" = "xyes" ; then
2301         AC_DEFINE(HAVE_SYS_NERR)
2302 fi
2303
2304 SCARD_MSG="no"
2305 # Check whether user wants sectok support
2306 AC_ARG_WITH(sectok,
2307         [  --with-sectok           Enable smartcard support using libsectok],
2308         [
2309                 if test "x$withval" != "xno" ; then
2310                         if test "x$withval" != "xyes" ; then
2311                                 CPPFLAGS="$CPPFLAGS -I${withval}"
2312                                 LDFLAGS="$LDFLAGS -L${withval}"
2313                                 if test ! -z "$need_dash_r" ; then
2314                                         LDFLAGS="$LDFLAGS -R${withval}"
2315                                 fi
2316                                 if test ! -z "$blibpath" ; then
2317                                         blibpath="$blibpath:${withval}"
2318                                 fi
2319                         fi
2320                         AC_CHECK_HEADERS(sectok.h)
2321                         if test "$ac_cv_header_sectok_h" != yes; then
2322                                 AC_MSG_ERROR(Can't find sectok.h)
2323                         fi
2324                         AC_CHECK_LIB(sectok, sectok_open)
2325                         if test "$ac_cv_lib_sectok_sectok_open" != yes; then
2326                                 AC_MSG_ERROR(Can't find libsectok)
2327                         fi
2328                         AC_DEFINE(SMARTCARD)
2329                         AC_DEFINE(USE_SECTOK)
2330                         SCARD_MSG="yes, using sectok"
2331                 fi
2332         ]
2333 )
2334
2335 # Check whether user wants OpenSC support
2336 OPENSC_CONFIG="no"
2337 AC_ARG_WITH(opensc,
2338         [--with-opensc[[=PFX]]       Enable smartcard support using OpenSC (optionally in PATH)],
2339         [
2340             if test "x$withval" != "xno" ; then
2341                 if test "x$withval" != "xyes" ; then
2342                         OPENSC_CONFIG=$withval/bin/opensc-config
2343                 else
2344                         AC_PATH_PROG(OPENSC_CONFIG, opensc-config, no)
2345                 fi
2346                 if test "$OPENSC_CONFIG" != "no"; then
2347                         LIBOPENSC_CFLAGS=`$OPENSC_CONFIG --cflags`
2348                         LIBOPENSC_LIBS=`$OPENSC_CONFIG --libs`
2349                         CPPFLAGS="$CPPFLAGS $LIBOPENSC_CFLAGS"
2350                         LDFLAGS="$LDFLAGS $LIBOPENSC_LIBS"
2351                         AC_DEFINE(SMARTCARD)
2352                         AC_DEFINE(USE_OPENSC)
2353                         SCARD_MSG="yes, using OpenSC"
2354                 fi
2355             fi
2356         ]
2357 )
2358
2359 # Check libraries needed by DNS fingerprint support
2360 AC_SEARCH_LIBS(getrrsetbyname, resolv,
2361         [AC_DEFINE(HAVE_GETRRSETBYNAME)],
2362         [
2363                 # Needed by our getrrsetbyname()
2364                 AC_SEARCH_LIBS(res_query, resolv)
2365                 AC_SEARCH_LIBS(dn_expand, resolv)
2366                 AC_MSG_CHECKING(if res_query will link)
2367                 AC_TRY_LINK_FUNC(res_query, AC_MSG_RESULT(yes),
2368                    [AC_MSG_RESULT(no)
2369                     saved_LIBS="$LIBS"
2370                     LIBS="$LIBS -lresolv"
2371                     AC_MSG_CHECKING(for res_query in -lresolv)
2372                     AC_LINK_IFELSE([
2373 #include <resolv.h>
2374 int main()
2375 {
2376         res_query (0, 0, 0, 0, 0);
2377         return 0;
2378 }
2379                         ],
2380                         [LIBS="$LIBS -lresolv"
2381                          AC_MSG_RESULT(yes)],
2382                         [LIBS="$saved_LIBS"
2383                          AC_MSG_RESULT(no)])
2384                     ])
2385                 AC_CHECK_FUNCS(_getshort _getlong)
2386                 AC_CHECK_MEMBER(HEADER.ad,
2387                         [AC_DEFINE(HAVE_HEADER_AD)],,
2388                         [#include <arpa/nameser.h>])
2389         ])
2390
2391 # Check whether user wants Kerberos 5 support
2392 KRB5_MSG="no"
2393 AC_ARG_WITH(kerberos5,
2394         [  --with-kerberos5=PATH   Enable Kerberos 5 support],
2395         [ if test "x$withval" != "xno" ; then
2396                 if test "x$withval" = "xyes" ; then
2397                         KRB5ROOT="/usr/local"
2398                 else
2399                         KRB5ROOT=${withval}
2400                 fi
2401
2402                 AC_DEFINE(KRB5)
2403                 KRB5_MSG="yes"
2404
2405                 AC_MSG_CHECKING(for krb5-config)
2406                 if test -x  $KRB5ROOT/bin/krb5-config ; then
2407                         KRB5CONF=$KRB5ROOT/bin/krb5-config
2408                         AC_MSG_RESULT($KRB5CONF)
2409
2410                         AC_MSG_CHECKING(for gssapi support)
2411                         if $KRB5CONF | grep gssapi >/dev/null ; then
2412                                 AC_MSG_RESULT(yes)
2413                                 AC_DEFINE(GSSAPI)
2414                                 k5confopts=gssapi
2415                         else
2416                                 AC_MSG_RESULT(no)
2417                                 k5confopts=""
2418                         fi
2419                         K5CFLAGS="`$KRB5CONF --cflags $k5confopts`"
2420                         K5LIBS="`$KRB5CONF --libs $k5confopts`"
2421                         CPPFLAGS="$CPPFLAGS $K5CFLAGS"
2422                         AC_MSG_CHECKING(whether we are using Heimdal)
2423                         AC_TRY_COMPILE([ #include <krb5.h> ],
2424                                        [ char *tmp = heimdal_version; ],
2425                                        [ AC_MSG_RESULT(yes)
2426                                          AC_DEFINE(HEIMDAL) ],
2427                                          AC_MSG_RESULT(no)
2428                         )
2429                 else
2430                         AC_MSG_RESULT(no)
2431                         CPPFLAGS="$CPPFLAGS -I${KRB5ROOT}/include"
2432                         LDFLAGS="$LDFLAGS -L${KRB5ROOT}/lib"
2433                         AC_MSG_CHECKING(whether we are using Heimdal)
2434                         AC_TRY_COMPILE([ #include <krb5.h> ],
2435                                        [ char *tmp = heimdal_version; ],
2436                                        [ AC_MSG_RESULT(yes)
2437                                          AC_DEFINE(HEIMDAL)
2438                                          K5LIBS="-lkrb5 -ldes"
2439                                          K5LIBS="$K5LIBS -lcom_err -lasn1"
2440                                          AC_CHECK_LIB(roken, net_write, 
2441                                            [K5LIBS="$K5LIBS -lroken"])
2442                                        ],
2443                                        [ AC_MSG_RESULT(no)
2444                                          K5LIBS="-lkrb5 -lk5crypto -lcom_err"
2445                                        ]
2446                         )
2447                         AC_SEARCH_LIBS(dn_expand, resolv)
2448
2449                         AC_CHECK_LIB(gssapi,gss_init_sec_context,
2450                                 [ AC_DEFINE(GSSAPI)
2451                                   K5LIBS="-lgssapi $K5LIBS" ],
2452                                 [ AC_CHECK_LIB(gssapi_krb5,gss_init_sec_context,
2453                                         [ AC_DEFINE(GSSAPI)
2454                                           K5LIBS="-lgssapi_krb5 $K5LIBS" ],
2455                                         AC_MSG_WARN([Cannot find any suitable gss-api library - build may fail]),
2456                                         $K5LIBS)
2457                                 ],
2458                                 $K5LIBS)
2459                         
2460                         AC_CHECK_HEADER(gssapi.h, ,
2461                                 [ unset ac_cv_header_gssapi_h
2462                                   CPPFLAGS="$CPPFLAGS -I${KRB5ROOT}/include/gssapi"
2463                                   AC_CHECK_HEADERS(gssapi.h, ,
2464                                         AC_MSG_WARN([Cannot find any suitable gss-api header - build may fail])
2465                                   )
2466                                 ]
2467                         )
2468
2469                         oldCPP="$CPPFLAGS"
2470                         CPPFLAGS="$CPPFLAGS -I${KRB5ROOT}/include/gssapi"
2471                         AC_CHECK_HEADER(gssapi_krb5.h, ,
2472                                         [ CPPFLAGS="$oldCPP" ])
2473
2474                 fi
2475                 if test ! -z "$need_dash_r" ; then
2476                         LDFLAGS="$LDFLAGS -R${KRB5ROOT}/lib"
2477                 fi
2478                 if test ! -z "$blibpath" ; then
2479                         blibpath="$blibpath:${KRB5ROOT}/lib"
2480                 fi
2481         fi
2482
2483         AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h)
2484         AC_CHECK_HEADERS(gssapi_krb5.h gssapi/gssapi_krb5.h)
2485         AC_CHECK_HEADERS(gssapi_generic.h gssapi/gssapi_generic.h)
2486
2487         LIBS="$LIBS $K5LIBS"
2488         AC_SEARCH_LIBS(k_hasafs, kafs, AC_DEFINE(USE_AFS))
2489         AC_SEARCH_LIBS(krb5_init_ets, $K5LIBS, AC_DEFINE(KRB5_INIT_ETS))
2490         ]
2491 )
2492
2493 # Looking for programs, paths and files
2494
2495 PRIVSEP_PATH=/var/empty
2496 AC_ARG_WITH(privsep-path,
2497         [  --with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)],
2498         [
2499                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
2500                     test "x${withval}" != "xyes"; then
2501                         PRIVSEP_PATH=$withval
2502                 fi
2503         ]
2504 )
2505 AC_SUBST(PRIVSEP_PATH)
2506
2507 AC_ARG_WITH(xauth,
2508         [  --with-xauth=PATH       Specify path to xauth program ],
2509         [
2510                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
2511                     test "x${withval}" != "xyes"; then
2512                         xauth_path=$withval
2513                 fi
2514         ],
2515         [
2516                 TestPath="$PATH"
2517                 TestPath="${TestPath}${PATH_SEPARATOR}/usr/X/bin"
2518                 TestPath="${TestPath}${PATH_SEPARATOR}/usr/bin/X11"
2519                 TestPath="${TestPath}${PATH_SEPARATOR}/usr/X11R6/bin"
2520                 TestPath="${TestPath}${PATH_SEPARATOR}/usr/openwin/bin"
2521                 AC_PATH_PROG(xauth_path, xauth, , $TestPath)
2522                 if (test ! -z "$xauth_path" && test -x "/usr/openwin/bin/xauth") ; then
2523                         xauth_path="/usr/openwin/bin/xauth"
2524                 fi
2525         ]
2526 )
2527
2528 STRIP_OPT=-s
2529 AC_ARG_ENABLE(strip,
2530         [  --disable-strip         Disable calling strip(1) on install],
2531         [
2532                 if test "x$enableval" = "xno" ; then
2533                         STRIP_OPT=
2534                 fi
2535         ]
2536 )
2537 AC_SUBST(STRIP_OPT)
2538
2539 if test -z "$xauth_path" ; then
2540         XAUTH_PATH="undefined"
2541         AC_SUBST(XAUTH_PATH)
2542 else
2543         AC_DEFINE_UNQUOTED(XAUTH_PATH, "$xauth_path")
2544         XAUTH_PATH=$xauth_path
2545         AC_SUBST(XAUTH_PATH)
2546 fi
2547
2548 # Check for mail directory (last resort if we cannot get it from headers)
2549 if test ! -z "$MAIL" ; then
2550         maildir=`dirname $MAIL`
2551         AC_DEFINE_UNQUOTED(MAIL_DIRECTORY, "$maildir")
2552 fi
2553
2554 if test ! -z "$cross_compiling" && test "x$cross_compiling" = "xyes"; then
2555         AC_MSG_WARN([cross compiling: Disabling /dev/ptmx test])
2556         disable_ptmx_check=yes
2557 fi
2558 if test -z "$no_dev_ptmx" ; then
2559         if test "x$disable_ptmx_check" != "xyes" ; then
2560                 AC_CHECK_FILE("/dev/ptmx",
2561                         [
2562                                 AC_DEFINE_UNQUOTED(HAVE_DEV_PTMX)
2563                                 have_dev_ptmx=1
2564                         ]
2565                 )
2566         fi
2567 fi
2568
2569 if test ! -z "$cross_compiling" && test "x$cross_compiling" != "xyes"; then
2570         AC_CHECK_FILE("/dev/ptc",
2571                 [
2572                         AC_DEFINE_UNQUOTED(HAVE_DEV_PTS_AND_PTC)
2573                         have_dev_ptc=1
2574                 ]
2575         )
2576 else
2577         AC_MSG_WARN([cross compiling: Disabling /dev/ptc test])
2578 fi
2579
2580 # Options from here on. Some of these are preset by platform above
2581 AC_ARG_WITH(mantype,
2582         [  --with-mantype=man|cat|doc  Set man page type],
2583         [
2584                 case "$withval" in
2585                 man|cat|doc)
2586                         MANTYPE=$withval
2587                         ;;
2588                 *)
2589                         AC_MSG_ERROR(invalid man type: $withval)
2590                         ;;
2591                 esac
2592         ]
2593 )
2594 if test -z "$MANTYPE"; then
2595         TestPath="/usr/bin${PATH_SEPARATOR}/usr/ucb"
2596         AC_PATH_PROGS(NROFF, nroff awf, /bin/false, $TestPath)
2597         if ${NROFF} -mdoc ${srcdir}/ssh.1 >/dev/null 2>&1; then
2598                 MANTYPE=doc
2599         elif ${NROFF} -man ${srcdir}/ssh.1 >/dev/null 2>&1; then
2600                 MANTYPE=man
2601         else
2602                 MANTYPE=cat
2603         fi
2604 fi
2605 AC_SUBST(MANTYPE)
2606 if test "$MANTYPE" = "doc"; then
2607         mansubdir=man;
2608 else
2609         mansubdir=$MANTYPE;
2610 fi
2611 AC_SUBST(mansubdir)
2612
2613 # Check whether to enable MD5 passwords
2614 MD5_MSG="no"
2615 AC_ARG_WITH(md5-passwords,
2616         [  --with-md5-passwords    Enable use of MD5 passwords],
2617         [
2618                 if test "x$withval" != "xno" ; then
2619                         AC_DEFINE(HAVE_MD5_PASSWORDS)
2620                         MD5_MSG="yes"
2621                 fi
2622         ]
2623 )
2624
2625 # Whether to disable shadow password support
2626 AC_ARG_WITH(shadow,
2627         [  --without-shadow        Disable shadow password support],
2628         [
2629                 if test "x$withval" = "xno" ; then      
2630                         AC_DEFINE(DISABLE_SHADOW)
2631                         disable_shadow=yes
2632                 fi
2633         ]
2634 )
2635
2636 if test -z "$disable_shadow" ; then
2637         AC_MSG_CHECKING([if the systems has expire shadow information])
2638         AC_TRY_COMPILE(
2639         [
2640 #include <sys/types.h>
2641 #include <shadow.h>
2642         struct spwd sp;
2643         ],[ sp.sp_expire = sp.sp_lstchg = sp.sp_inact = 0; ],
2644         [ sp_expire_available=yes ], []
2645         )
2646
2647         if test "x$sp_expire_available" = "xyes" ; then
2648                 AC_MSG_RESULT(yes)
2649                 AC_DEFINE(HAS_SHADOW_EXPIRE)
2650         else
2651                 AC_MSG_RESULT(no)
2652         fi
2653 fi
2654
2655 # Use ip address instead of hostname in $DISPLAY
2656 if test ! -z "$IPADDR_IN_DISPLAY" ; then
2657         DISPLAY_HACK_MSG="yes"
2658         AC_DEFINE(IPADDR_IN_DISPLAY)
2659 else
2660         DISPLAY_HACK_MSG="no"
2661         AC_ARG_WITH(ipaddr-display,
2662                 [  --with-ipaddr-display   Use ip address instead of hostname in \$DISPLAY],
2663                 [
2664                         if test "x$withval" != "xno" ; then     
2665                                 AC_DEFINE(IPADDR_IN_DISPLAY)
2666                                 DISPLAY_HACK_MSG="yes"
2667                         fi
2668                 ]
2669         )
2670 fi
2671
2672 # check for /etc/default/login and use it if present.
2673 AC_ARG_ENABLE(etc-default-login,
2674         [  --disable-etc-default-login Disable using PATH from /etc/default/login [no]],
2675         [ if test "x$enableval" = "xno"; then
2676                 AC_MSG_NOTICE([/etc/default/login handling disabled])
2677                 etc_default_login=no
2678           else
2679                 etc_default_login=yes
2680           fi ],
2681         [ etc_default_login=yes ]
2682 )
2683
2684 if test "x$etc_default_login" != "xno"; then
2685         AC_CHECK_FILE("/etc/default/login",
2686             [ external_path_file=/etc/default/login ])
2687         if test ! -z "$cross_compiling" && test "x$cross_compiling" = "xyes";
2688         then
2689                 AC_MSG_WARN([cross compiling: Disabling /etc/default/login test])
2690         elif test "x$external_path_file" = "x/etc/default/login"; then
2691                 AC_DEFINE(HAVE_ETC_DEFAULT_LOGIN)
2692         fi
2693 fi
2694
2695 dnl BSD systems use /etc/login.conf so --with-default-path= has no effect
2696 if test $ac_cv_func_login_getcapbool = "yes" && \
2697         test $ac_cv_header_login_cap_h = "yes" ; then
2698         external_path_file=/etc/login.conf
2699 fi
2700
2701 # Whether to mess with the default path
2702 SERVER_PATH_MSG="(default)"
2703 AC_ARG_WITH(default-path,
2704         [  --with-default-path=    Specify default \$PATH environment for server],
2705         [
2706                 if test "x$external_path_file" = "x/etc/login.conf" ; then
2707                         AC_MSG_WARN([
2708 --with-default-path=PATH has no effect on this system.
2709 Edit /etc/login.conf instead.])
2710                 elif test "x$withval" != "xno" ; then   
2711                         if test ! -z "$external_path_file" ; then
2712                                 AC_MSG_WARN([
2713 --with-default-path=PATH will only be used if PATH is not defined in
2714 $external_path_file .])
2715                         fi
2716                         user_path="$withval"
2717                         SERVER_PATH_MSG="$withval"
2718                 fi
2719         ],
2720         [ if test "x$external_path_file" = "x/etc/login.conf" ; then
2721                 AC_MSG_WARN([Make sure the path to scp is in /etc/login.conf])
2722         else
2723                 if test ! -z "$external_path_file" ; then
2724                         AC_MSG_WARN([
2725 If PATH is defined in $external_path_file, ensure the path to scp is included,
2726 otherwise scp will not work.])
2727                 fi
2728                 AC_TRY_RUN(
2729                         [
2730 /* find out what STDPATH is */
2731 #include <stdio.h>
2732 #ifdef HAVE_PATHS_H
2733 # include <paths.h>
2734 #endif
2735 #ifndef _PATH_STDPATH
2736 # ifdef _PATH_USERPATH  /* Irix */
2737 #  define _PATH_STDPATH _PATH_USERPATH
2738 # else
2739 #  define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
2740 # endif
2741 #endif
2742 #include <sys/types.h>
2743 #include <sys/stat.h>
2744 #include <fcntl.h>
2745 #define DATA "conftest.stdpath"
2746
2747 main()
2748 {
2749         FILE *fd;
2750         int rc;
2751         
2752         fd = fopen(DATA,"w");
2753         if(fd == NULL)
2754                 exit(1);
2755         
2756         if ((rc = fprintf(fd,"%s", _PATH_STDPATH)) < 0)
2757                 exit(1);
2758
2759         exit(0);
2760 }
2761                 ], [ user_path=`cat conftest.stdpath` ],
2762                 [ user_path="/usr/bin:/bin:/usr/sbin:/sbin" ],
2763                 [ user_path="/usr/bin:/bin:/usr/sbin:/sbin" ]
2764         )
2765 # make sure $bindir is in USER_PATH so scp will work
2766                 t_bindir=`eval echo ${bindir}`
2767                 case $t_bindir in
2768                         NONE/*) t_bindir=`echo $t_bindir | sed "s~NONE~$prefix~"` ;;
2769                 esac
2770                 case $t_bindir in
2771                         NONE/*) t_bindir=`echo $t_bindir | sed "s~NONE~$ac_default_prefix~"` ;;
2772                 esac
2773                 echo $user_path | grep ":$t_bindir"  > /dev/null 2>&1
2774                 if test $? -ne 0  ; then
2775                         echo $user_path | grep "^$t_bindir"  > /dev/null 2>&1
2776                         if test $? -ne 0  ; then
2777                                 user_path=$user_path:$t_bindir
2778                                 AC_MSG_RESULT(Adding $t_bindir to USER_PATH so scp will work)
2779                         fi
2780                 fi
2781         fi ]
2782 )
2783 if test "x$external_path_file" != "x/etc/login.conf" ; then
2784         AC_DEFINE_UNQUOTED(USER_PATH, "$user_path")
2785         AC_SUBST(user_path)
2786 fi
2787
2788 # Set superuser path separately to user path
2789 AC_ARG_WITH(superuser-path,
2790         [  --with-superuser-path=  Specify different path for super-user],
2791         [
2792                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
2793                     test "x${withval}" != "xyes"; then
2794                         AC_DEFINE_UNQUOTED(SUPERUSER_PATH, "$withval")
2795                         superuser_path=$withval
2796                 fi
2797         ]
2798 )
2799
2800
2801 AC_MSG_CHECKING([if we need to convert IPv4 in IPv6-mapped addresses])
2802 IPV4_IN6_HACK_MSG="no"
2803 AC_ARG_WITH(4in6,
2804         [  --with-4in6             Check for and convert IPv4 in IPv6 mapped addresses],
2805         [
2806                 if test "x$withval" != "xno" ; then
2807                         AC_MSG_RESULT(yes)
2808                         AC_DEFINE(IPV4_IN_IPV6)
2809                         IPV4_IN6_HACK_MSG="yes"
2810                 else
2811                         AC_MSG_RESULT(no)
2812                 fi
2813         ],[
2814                 if test "x$inet6_default_4in6" = "xyes"; then
2815                         AC_MSG_RESULT([yes (default)])
2816                         AC_DEFINE(IPV4_IN_IPV6)
2817                         IPV4_IN6_HACK_MSG="yes"
2818                 else
2819                         AC_MSG_RESULT([no (default)])
2820                 fi
2821         ]
2822 )
2823
2824 # Whether to enable BSD auth support
2825 BSD_AUTH_MSG=no
2826 AC_ARG_WITH(bsd-auth,
2827         [  --with-bsd-auth         Enable BSD auth support],
2828         [
2829                 if test "x$withval" != "xno" ; then     
2830                         AC_DEFINE(BSD_AUTH)
2831                         BSD_AUTH_MSG=yes
2832                 fi
2833         ]
2834 )
2835
2836 # Where to place sshd.pid
2837 piddir=/var/run
2838 # make sure the directory exists
2839 if test ! -d $piddir ; then     
2840         piddir=`eval echo ${sysconfdir}`
2841         case $piddir in
2842                 NONE/*) piddir=`echo $piddir | sed "s~NONE~$ac_default_prefix~"` ;;
2843         esac
2844 fi
2845
2846 AC_ARG_WITH(pid-dir,
2847         [  --with-pid-dir=PATH     Specify location of ssh.pid file],
2848         [
2849                 if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
2850                     test "x${withval}" != "xyes"; then
2851                         piddir=$withval
2852                         if test ! -d $piddir ; then     
2853                         AC_MSG_WARN([** no $piddir directory on this system **])
2854                         fi
2855                 fi
2856         ]
2857 )
2858
2859 AC_DEFINE_UNQUOTED(_PATH_SSH_PIDDIR, "$piddir")
2860 AC_SUBST(piddir)
2861
2862 dnl allow user to disable some login recording features
2863 AC_ARG_ENABLE(lastlog,
2864         [  --disable-lastlog       disable use of lastlog even if detected [no]],
2865         [
2866                 if test "x$enableval" = "xno" ; then
2867                         AC_DEFINE(DISABLE_LASTLOG)
2868                 fi
2869         ]
2870 )
2871 AC_ARG_ENABLE(utmp,
2872         [  --disable-utmp          disable use of utmp even if detected [no]],
2873         [
2874                 if test "x$enableval" = "xno" ; then
2875                         AC_DEFINE(DISABLE_UTMP)
2876                 fi
2877         ]
2878 )
2879 AC_ARG_ENABLE(utmpx,
2880         [  --disable-utmpx         disable use of utmpx even if detected [no]],
2881         [
2882                 if test "x$enableval" = "xno" ; then
2883                         AC_DEFINE(DISABLE_UTMPX)
2884                 fi
2885         ]
2886 )
2887 AC_ARG_ENABLE(wtmp,
2888         [  --disable-wtmp          disable use of wtmp even if detected [no]],
2889         [
2890                 if test "x$enableval" = "xno" ; then
2891                         AC_DEFINE(DISABLE_WTMP)
2892                 fi
2893         ]
2894 )
2895 AC_ARG_ENABLE(wtmpx,
2896         [  --disable-wtmpx         disable use of wtmpx even if detected [no]],
2897         [
2898                 if test "x$enableval" = "xno" ; then
2899                         AC_DEFINE(DISABLE_WTMPX)
2900                 fi
2901         ]
2902 )
2903 AC_ARG_ENABLE(libutil,
2904         [  --disable-libutil       disable use of libutil (login() etc.) [no]],
2905         [
2906                 if test "x$enableval" = "xno" ; then
2907                         AC_DEFINE(DISABLE_LOGIN)
2908                 fi
2909         ]
2910 )
2911 AC_ARG_ENABLE(pututline,
2912         [  --disable-pututline     disable use of pututline() etc. ([uw]tmp) [no]],
2913         [
2914                 if test "x$enableval" = "xno" ; then
2915                         AC_DEFINE(DISABLE_PUTUTLINE)
2916                 fi
2917         ]
2918 )
2919 AC_ARG_ENABLE(pututxline,
2920         [  --disable-pututxline    disable use of pututxline() etc. ([uw]tmpx) [no]],
2921         [
2922                 if test "x$enableval" = "xno" ; then
2923                         AC_DEFINE(DISABLE_PUTUTXLINE)
2924                 fi
2925         ]
2926 )
2927 AC_ARG_WITH(lastlog,
2928   [  --with-lastlog=FILE|DIR specify lastlog location [common locations]],
2929         [
2930                 if test "x$withval" = "xno" ; then      
2931                         AC_DEFINE(DISABLE_LASTLOG)
2932                 elif test -n "$withval"  &&  test "x${withval}" != "xyes"; then
2933                         conf_lastlog_location=$withval
2934                 fi
2935         ]
2936 )
2937
2938 dnl lastlog, [uw]tmpx? detection
2939 dnl  NOTE: set the paths in the platform section to avoid the
2940 dnl   need for command-line parameters
2941 dnl lastlog and [uw]tmp are subject to a file search if all else fails
2942
2943 dnl lastlog detection
2944 dnl  NOTE: the code itself will detect if lastlog is a directory
2945 AC_MSG_CHECKING([if your system defines LASTLOG_FILE])
2946 AC_TRY_COMPILE([
2947 #include <sys/types.h>
2948 #include <utmp.h>
2949 #ifdef HAVE_LASTLOG_H
2950 #  include <lastlog.h>
2951 #endif
2952 #ifdef HAVE_PATHS_H
2953 #  include <paths.h>
2954 #endif
2955 #ifdef HAVE_LOGIN_H
2956 # include <login.h>
2957 #endif
2958         ],
2959         [ char *lastlog = LASTLOG_FILE; ],
2960         [ AC_MSG_RESULT(yes) ],
2961         [
2962                 AC_MSG_RESULT(no)
2963                 AC_MSG_CHECKING([if your system defines _PATH_LASTLOG])
2964                 AC_TRY_COMPILE([
2965 #include <sys/types.h>
2966 #include <utmp.h>
2967 #ifdef HAVE_LASTLOG_H
2968 #  include <lastlog.h>
2969 #endif
2970 #ifdef HAVE_PATHS_H
2971 #  include <paths.h>
2972 #endif
2973                 ],
2974                 [ char *lastlog = _PATH_LASTLOG; ],
2975                 [ AC_MSG_RESULT(yes) ],
2976                 [
2977                         AC_MSG_RESULT(no)
2978                         system_lastlog_path=no
2979                 ])
2980         ]
2981 )
2982
2983 if test -z "$conf_lastlog_location"; then
2984         if test x"$system_lastlog_path" = x"no" ; then
2985                 for f in /var/log/lastlog /usr/adm/lastlog /var/adm/lastlog /etc/security/lastlog ; do
2986                                 if (test -d "$f" || test -f "$f") ; then
2987                                         conf_lastlog_location=$f
2988                                 fi
2989                 done
2990                 if test -z "$conf_lastlog_location"; then
2991                         AC_MSG_WARN([** Cannot find lastlog **])
2992                         dnl Don't define DISABLE_LASTLOG - that means we don't try wtmp/wtmpx
2993                 fi
2994         fi
2995 fi
2996
2997 if test -n "$conf_lastlog_location"; then
2998         AC_DEFINE_UNQUOTED(CONF_LASTLOG_FILE, "$conf_lastlog_location")
2999 fi      
3000
3001 dnl utmp detection
3002 AC_MSG_CHECKING([if your system defines UTMP_FILE])
3003 AC_TRY_COMPILE([
3004 #include <sys/types.h>
3005 #include <utmp.h>
3006 #ifdef HAVE_PATHS_H
3007 #  include <paths.h>
3008 #endif
3009         ],
3010         [ char *utmp = UTMP_FILE; ],
3011         [ AC_MSG_RESULT(yes) ],
3012         [ AC_MSG_RESULT(no)
3013           system_utmp_path=no ]
3014 )
3015 if test -z "$conf_utmp_location"; then
3016         if test x"$system_utmp_path" = x"no" ; then
3017                 for f in /etc/utmp /usr/adm/utmp /var/run/utmp; do
3018                         if test -f $f ; then
3019                                 conf_utmp_location=$f
3020                         fi
3021                 done
3022                 if test -z "$conf_utmp_location"; then
3023                         AC_DEFINE(DISABLE_UTMP)
3024                 fi
3025         fi
3026 fi
3027 if test -n "$conf_utmp_location"; then
3028         AC_DEFINE_UNQUOTED(CONF_UTMP_FILE, "$conf_utmp_location")
3029 fi      
3030
3031 dnl wtmp detection
3032 AC_MSG_CHECKING([if your system defines WTMP_FILE])
3033 AC_TRY_COMPILE([
3034 #include <sys/types.h>
3035 #include <utmp.h>
3036 #ifdef HAVE_PATHS_H
3037 #  include <paths.h>
3038 #endif
3039         ],
3040         [ char *wtmp = WTMP_FILE; ],
3041         [ AC_MSG_RESULT(yes) ],
3042         [ AC_MSG_RESULT(no)
3043           system_wtmp_path=no ]
3044 )
3045 if test -z "$conf_wtmp_location"; then
3046         if test x"$system_wtmp_path" = x"no" ; then
3047                 for f in /usr/adm/wtmp /var/log/wtmp; do
3048                         if test -f $f ; then
3049                                 conf_wtmp_location=$f
3050                         fi
3051                 done
3052                 if test -z "$conf_wtmp_location"; then
3053                         AC_DEFINE(DISABLE_WTMP)
3054                 fi
3055         fi
3056 fi
3057 if test -n "$conf_wtmp_location"; then
3058         AC_DEFINE_UNQUOTED(CONF_WTMP_FILE, "$conf_wtmp_location")
3059 fi      
3060
3061
3062 dnl utmpx detection - I don't know any system so perverse as to require
3063 dnl  utmpx, but not define UTMPX_FILE (ditto wtmpx.) No doubt it's out
3064 dnl  there, though.
3065 AC_MSG_CHECKING([if your system defines UTMPX_FILE])
3066 AC_TRY_COMPILE([
3067 #include <sys/types.h>
3068 #include <utmp.h>
3069 #ifdef HAVE_UTMPX_H
3070 #include <utmpx.h>
3071 #endif
3072 #ifdef HAVE_PATHS_H
3073 #  include <paths.h>
3074 #endif
3075         ],
3076         [ char *utmpx = UTMPX_FILE; ],
3077         [ AC_MSG_RESULT(yes) ],
3078         [ AC_MSG_RESULT(no)
3079           system_utmpx_path=no ]
3080 )
3081 if test -z "$conf_utmpx_location"; then
3082         if test x"$system_utmpx_path" = x"no" ; then
3083                 AC_DEFINE(DISABLE_UTMPX)
3084         fi
3085 else
3086         AC_DEFINE_UNQUOTED(CONF_UTMPX_FILE, "$conf_utmpx_location")
3087 fi      
3088
3089 dnl wtmpx detection
3090 AC_MSG_CHECKING([if your system defines WTMPX_FILE])
3091 AC_TRY_COMPILE([
3092 #include <sys/types.h>
3093 #include <utmp.h>
3094 #ifdef HAVE_UTMPX_H
3095 #include <utmpx.h>
3096 #endif
3097 #ifdef HAVE_PATHS_H
3098 #  include <paths.h>
3099 #endif
3100         ],
3101         [ char *wtmpx = WTMPX_FILE; ],
3102         [ AC_MSG_RESULT(yes) ],
3103         [ AC_MSG_RESULT(no)
3104           system_wtmpx_path=no ]
3105 )
3106 if test -z "$conf_wtmpx_location"; then
3107         if test x"$system_wtmpx_path" = x"no" ; then
3108                 AC_DEFINE(DISABLE_WTMPX)
3109         fi
3110 else
3111         AC_DEFINE_UNQUOTED(CONF_WTMPX_FILE, "$conf_wtmpx_location")
3112 fi      
3113
3114
3115 if test ! -z "$blibpath" ; then
3116         LDFLAGS="$LDFLAGS $blibflags$blibpath"
3117         AC_MSG_WARN([Please check and edit blibpath in LDFLAGS in Makefile])
3118 fi
3119
3120 dnl remove pam and dl because they are in $LIBPAM
3121 if test "$PAM_MSG" = yes ; then
3122         LIBS=`echo $LIBS | sed 's/-lpam //'`
3123 fi
3124 if test "$ac_cv_lib_pam_pam_set_item" = yes ; then
3125         LIBS=`echo $LIBS | sed 's/-ldl //'`
3126 fi
3127
3128 AC_EXEEXT
3129 AC_CONFIG_FILES([Makefile buildpkg.sh opensshd.init openbsd-compat/Makefile \
3130         scard/Makefile ssh_prng_cmds survey.sh])
3131 AC_OUTPUT
3132
3133 # Print summary of options
3134
3135 # Someone please show me a better way :)
3136 A=`eval echo ${prefix}` ; A=`eval echo ${A}`
3137 B=`eval echo ${bindir}` ; B=`eval echo ${B}`
3138 C=`eval echo ${sbindir}` ; C=`eval echo ${C}`
3139 D=`eval echo ${sysconfdir}` ; D=`eval echo ${D}`
3140 E=`eval echo ${libexecdir}/ssh-askpass` ; E=`eval echo ${E}`
3141 F=`eval echo ${mandir}/${mansubdir}X` ; F=`eval echo ${F}`
3142 G=`eval echo ${piddir}` ; G=`eval echo ${G}`
3143 H=`eval echo ${PRIVSEP_PATH}` ; H=`eval echo ${H}`
3144 I=`eval echo ${user_path}` ; I=`eval echo ${I}`
3145 J=`eval echo ${superuser_path}` ; J=`eval echo ${J}`
3146
3147 echo ""
3148 echo "OpenSSH has been configured with the following options:"
3149 echo "                     User binaries: $B"
3150 echo "                   System binaries: $C"
3151 echo "               Configuration files: $D"
3152 echo "                   Askpass program: $E"
3153 echo "                      Manual pages: $F"
3154 echo "                          PID file: $G"
3155 echo "  Privilege separation chroot path: $H"
3156 if test "x$external_path_file" = "x/etc/login.conf" ; then
3157 echo "   At runtime, sshd will use the path defined in $external_path_file"
3158 echo "   Make sure the path to scp is present, otherwise scp will not work"
3159 else
3160 echo "            sshd default user PATH: $I"
3161         if test ! -z "$external_path_file"; then
3162 echo "   (If PATH is set in $external_path_file it will be used instead. If"
3163 echo "   used, ensure the path to scp is present, otherwise scp will not work.)"
3164         fi
3165 fi
3166 if test ! -z "$superuser_path" ; then
3167 echo "          sshd superuser user PATH: $J"
3168 fi
3169 echo "                    Manpage format: $MANTYPE"
3170 echo "                       PAM support: $PAM_MSG"
3171 echo "                 KerberosV support: $KRB5_MSG"
3172 echo "                 Smartcard support: $SCARD_MSG"
3173 echo "                     S/KEY support: $SKEY_MSG"
3174 echo "              TCP Wrappers support: $TCPW_MSG"
3175 echo "              MD5 password support: $MD5_MSG"
3176 echo "                   libedit support: $LIBEDIT_MSG"
3177 echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
3178 echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
3179 echo "                  BSD Auth support: $BSD_AUTH_MSG"
3180 echo "              Random number source: $RAND_MSG"
3181 if test ! -z "$USE_RAND_HELPER" ; then
3182 echo "     ssh-rand-helper collects from: $RAND_HELPER_MSG"
3183 fi
3184
3185 echo ""
3186
3187 echo "              Host: ${host}"
3188 echo "          Compiler: ${CC}"
3189 echo "    Compiler flags: ${CFLAGS}"
3190 echo "Preprocessor flags: ${CPPFLAGS}"
3191 echo "      Linker flags: ${LDFLAGS}"
3192 echo "         Libraries: ${LIBWRAP} ${LIBPAM} ${LIBS}"
3193
3194 echo ""
3195
3196 if test "x$MAKE_PACKAGE_SUPPORTED" = "xyes" ; then
3197         echo "SVR4 style packages are supported with \"make package\""
3198         echo ""
3199 fi
3200
3201 if test "x$PAM_MSG" = "xyes" ; then
3202         echo "PAM is enabled. You may need to install a PAM control file "
3203         echo "for sshd, otherwise password authentication may fail. "
3204         echo "Example PAM control files can be found in the contrib/ "
3205         echo "subdirectory"
3206         echo ""
3207 fi
3208
3209 if test ! -z "$RAND_HELPER_CMDHASH" ; then
3210         echo "WARNING: you are using the builtin random number collection "
3211         echo "service. Please read WARNING.RNG and request that your OS "
3212         echo "vendor includes kernel-based random number collection in "
3213         echo "future versions of your OS."
3214         echo ""
3215 fi
3216
3217 if test ! -z "$NO_PEERCHECK" ; then
3218         echo "WARNING: the operating system that you are using does not "
3219         echo "appear to support either the getpeereid() API nor the "
3220         echo "SO_PEERCRED getsockopt() option. These facilities are used to "
3221         echo "enforce security checks to prevent unauthorised connections to "
3222         echo "ssh-agent. Their absence increases the risk that a malicious "
3223         echo "user can connect to your agent. "
3224         echo ""
3225 fi
3226
3227 if test "$AUDIT_MODULE" = "bsm" ; then
3228         echo "WARNING: BSM audit support is currently considered EXPERIMENTAL."
3229         echo "See the Solaris section in README.platform for details."
3230 fi
This page took 0.493791 seconds and 5 git commands to generate.