dnl Process this file with autoconf to produce a configure script
AC_PREREQ(2.5)
AC_INIT(cgiwrap.h)
AC_CONFIG_AUX_DIR(.)
AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)

VERSION="3.9"
AC_SUBST(VERSION)

AC_PROG_CC
AC_PROG_MAKE_SET


dnl
dnl Path to perl for unsupported stuff
dnl
AC_ARG_WITH( perl, 
	[  --with-perl=PATH]
	[  path to perl executable to use], 
	[
		AC_MSG_CHECKING(for perl)
		if test "x$withval" != x; then
			PATH_PROG_PERL="$withval"
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT(not found)
		fi
	],
	[
		AC_PATH_PROG(PATH_PROG_PERL, perl, no)
	])

dnl
dnl Check for REDIRECT_URL when building SCRIPT_NAME
dnl
AC_MSG_CHECKING(for use-redirect-url)
AC_ARG_WITH( use-redirect-url,
	[  --with-use-redirect-url]
	[  use REDIRECT_URL in building SCRIPT_NAME if available],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_USE_REDIRECT_URL, [], [use REDIRECT_URL in building SCRIPT_NAME if available])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])


dnl
dnl Set SCRIPT_NAME to SCRIPT_URL
dnl
AC_MSG_CHECKING(for whether to use SCRIPT_URL to build SCRIPT_NAME)
AC_ARG_WITH( use-script-url,
        [  --with-use-script-url]
        [  use SCRIPT_URL to build SCRIPT_NAME],
        [
                if test "x$withval" != xno; then
                        AC_DEFINE(CONF_USE_SCRIPT_URL, [], [use SCRIPT_URL to build SCRIPT_NAME])
                        AC_MSG_RESULT([enabled])
                else
                        AC_MSG_RESULT([disabled])
                fi
        ],
        [
                AC_MSG_RESULT([disabled])
        ])


AC_MSG_CHECKING(for require-redirect-url)
AC_ARG_WITH( require-redirect-url,
	[  --with-require-redirect-url]
	[  require REDIRECT_URL in environment, to force use of Action/Handlers],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_REQUIRE_REDIRECT_URL, [], [require REDIRECT_URL in environment])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

dnl
dnl Avoid information disclosure in error messages
dnl
AC_MSG_CHECKING(for quiet-errors)
AC_ARG_WITH( quiet-errors,
	[  --with-quiet-errors]
	[  avoid releasing internal information in error messages],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_QUIET_ERRORS, [], [avoid release of information])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

dnl
dnl Allow cgiwrap specific vhost override - for use with wildcard vhosts
dnl
AC_MSG_CHECKING(for vhost-override)
AC_ARG_WITH( vhost-override,
	[  --with-vhost-override]
	[  allow overriding HTTP_HOST with CGIWRAP_AUTH_VHOST],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_VHOST_OVERRIDE, [], [CGIWRAP_AUTH_VHOST overrides HTTP_HOST])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

dnl
dnl Allow specifying CGIWRAP_REQUIRE_USER=userid in environment
dnl
AC_MSG_CHECKING(for env-require-user)
AC_ARG_WITH( env-require-user,
	[  --with-env-require-user]
	[  allow specifying CGIWRAP_REQUIRE_USER in env to restrict to specific userid],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_ENV_REQUIRE_USER, [], [CGIWRAP_REQUIRE_USER in env to restrict user])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])
	
dnl
dnl Path to php for interpreter support
dnl
AC_ARG_WITH( php, 
	[  --with-php=PATH]
	[  path to php executable to use], 
	[
		AC_MSG_CHECKING(for php)
		if test "x$withval" != x; then
			PATH_PROG_PHP="$withval"
			AC_DEFINE_UNQUOTED(PATH_PROG_PHP,"$withval", [php path])
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT(not found)
		fi
	],
	[
		AC_PATH_PROG(PATH_PROG_PHP, php, no)
		if test "x${PATH_PROG_PHP}" != "xno"; then
			AC_DEFINE_UNQUOTED(PATH_PROG_PHP,"${PATH_PROG_PHP}", [path to php executable to use])
		fi
	])


dnl
dnl Path to asp for interpreter support
dnl
AC_ARG_WITH( asp, 
	[  --with-asp=PATH]
	[  path to asp interpreter to use], 
	[
		AC_MSG_CHECKING(for asp interpreter)
		if test "x$withval" != x; then
			PATH_PROG_ASP="$withval"
			AC_DEFINE_UNQUOTED(PATH_PROG_ASP,"$withval", [asp interpreter path])
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT(not found)
		fi
	],
	[
		AC_PATH_PROG(PATH_PROG_ASP, asp-perl, no)
		if test "x${PATH_PROG_ASP}" != "xno"; then
			AC_DEFINE_UNQUOTED(PATH_PROG_ASP,"${PATH_PROG_ASP}", [path to asp executable to use])
		fi
	])



dnl
dnl Check needed library functions
dnl
AC_CHECK_FUNC(sigset,		[AC_DEFINE(HAS_SIGSET, 		[], [has sigset library function])])
AC_CHECK_FUNC(initgroups, 	[AC_DEFINE(HAS_INITGROUPS, 	[], [has initgroups library function])])
AC_CHECK_FUNC(setgroups, 	[AC_DEFINE(HAS_SETGROUPS, 	[], [has setgroups library function])])
AC_CHECK_FUNC(getgroups, 	[AC_DEFINE(HAS_GETGROUPS, 	[], [has getgroups library function])])
AC_CHECK_FUNC(setgid, 		[AC_DEFINE(HAS_SETGID, 		[], [has setgid library function])])
AC_CHECK_FUNC(setuid, 		[AC_DEFINE(HAS_SETUID, 		[], [has setuid library function])])
AC_CHECK_FUNC(setegid, 		[AC_DEFINE(HAS_SETEGID, 	[], [has setegid library function])])
AC_CHECK_FUNC(seteuid, 		[AC_DEFINE(HAS_SETEUID, 	[], [has seteuid library function])])
AC_CHECK_FUNC(setrgid, 		[AC_DEFINE(HAS_SETRGID, 	[], [has setrgid library function])])
AC_CHECK_FUNC(setruid, 		[AC_DEFINE(HAS_SETRUID, 	[], [has setruid library function])])
AC_CHECK_FUNC(setregid, 	[AC_DEFINE(HAS_SETREGID, 	[], [has setregid library function])])
AC_CHECK_FUNC(setreuid, 	[AC_DEFINE(HAS_SETREUID, 	[], [has setreuid library function])])
AC_CHECK_FUNC(setresgid, 	[AC_DEFINE(HAS_SETRESGID, 	[], [has setresgid library function])])
AC_CHECK_FUNC(setresuid, 	[AC_DEFINE(HAS_SETRESUID, 	[], [has setresuid library function])])
AC_CHECK_FUNC(perror, 		[AC_DEFINE(HAS_PERROR, 		[], [has perror library function])])
AC_CHECK_FUNC(strerror, 	[AC_DEFINE(HAS_STRERROR, 	[], [has strerror library function])])
AC_CHECK_FUNC(strdup, 		[AC_DEFINE(HAS_STRDUP, 		[], [has strdup library function])])
AC_CHECK_FUNC(syslog, 		[AC_DEFINE(HAS_SYSLOG, 		[], [has syslog library function])])
AC_CHECK_FUNC(setrlimit, 	[AC_DEFINE(HAS_SETRLIMIT, 	[], [has setrlimit library function])])
AC_CHECK_FUNC(putenv, 		[AC_DEFINE(HAS_PUTENV, 		[], [has putenv library function])])
AC_CHECK_FUNC(unsetenv, 	[AC_DEFINE(HAS_UNSETENV, 	[], [has unsetenv library function])])
AC_CHECK_FUNC(wait3, 		[AC_DEFINE(HAS_WAIT3, 		[], [has wait3 library function])])
AC_CHECK_FUNC(innetgr, 		[AC_DEFINE(HAS_INNETGR, 	[], [has innetgr library function])])

dnl
dnl Information options
dnl
AC_MSG_CHECKING(for chroot prefix)
AC_ARG_WITH( chroot,
        [  --with-chroot=PATH]
        [  define prefix to chroot to before execution ]
        [  DO NOT USE THIS unless you have read the cgiwrap chroot ]
	[  documentation and have set up the requisite structure ],
        [
                if test "x$withval" = xyes; then
                        AC_MSG_RESULT([disabled, must specify value])
                elif test "x$withval" = xno; then
                        AC_MSG_RESULT([disabled, must specify value])
                elif test "x$withval" = x; then
                        AC_MSG_RESULT([disabled, must specify value])
                else
                        AC_MSG_RESULT($withval)
                        AC_DEFINE_UNQUOTED(CONF_CHROOT_PREFIX,"$withval", [chroot prefix])
                fi
        ],
        [
                AC_MSG_RESULT([disabled])
        ])

dnl
dnl Information options
dnl
AC_MSG_CHECKING(for local contact name)
AC_ARG_WITH( local-contact-name, 
	[  --with-local-contact-name=NAME]
	[  define name of local contact], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_CONTACT_NAME,"$withval", [local contact])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for local contact email)
AC_ARG_WITH( local-contact-email, 
	[  --with-local-contact-email=ADDRESS]
	[  define email address of local contact], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_CONTACT_EMAIL,"$withval", [local contact email])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for local contact phone)
AC_ARG_WITH( local-contact-phone, 
	[  --with-local-contact-phone=PHONE]
	[  define phone number of local contact], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_CONTACT_PHONE,"$withval", [local contact phone])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for local contact url)
AC_ARG_WITH( local-contact-url, 
	[  --with-local-contact-url=URL]
	[  define url of local contact], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_CONTACT_URL,"$withval", [local contact url])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for local site url)
AC_ARG_WITH( local-site-url, 
	[  --with-local-site-url=URL]
	[  define url of local site], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_SITE_URL,"$withval", [local site url])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for local cgiwrap docs)
AC_ARG_WITH( local-doc-url, 
	[  --with-local-doc-url=URL]
	[  define url of local cgiwrap documentation], 
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled, must specify value])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([disabled, must specify value])
		else
			AC_MSG_RESULT($withval)
			AC_DEFINE_UNQUOTED(CONF_LOCAL_DOC_URL,"$withval", [local doc url])
			AC_DEFINE(CONF_LOCAL_INFO_ENABLED, [], [local info enabled])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled])
	])


dnl
dnl Debugging option
dnl
AC_MSG_CHECKING(for with-wall)
AC_ARG_WITH( wall, 
	[  --with-wall]
	[  enable -Wall option on compile],
	[
		if test "x$withval" = xno; then
			AC_MSG_RESULT(disabled)
			withval=
		else
			AC_MSG_RESULT(enabled)
			withval="-Wall"
		fi

		GCC_WALL_OPT="$withval"	
	],
	[
		AC_MSG_RESULT(disabled)
		GCC_WALL_OPT=""
	])
AC_SUBST(GCC_WALL_OPT)

dnl
dnl Installation group
dnl
AC_MSG_CHECKING(for installation group)
AC_ARG_WITH( install-group, 
	[  --with-install-group=GROUP  (root)]
	[  group to install cgiwrap as],
	[
		if test "x$withval" = xyes; then
			withval=root
		fi
		if test "x$withval" = xno; then
			withval=root
		fi
		if test "x$withval" = x; then
			withval=root
		fi

		INSTALLGROUP="$withval"
	],
	[
		withval=root
		INSTALLGROUP="$withval"
	])
AC_MSG_RESULT($withval)
AC_SUBST(INSTALLGROUP)

AC_MSG_CHECKING(for installation directory)
AC_ARG_WITH( install-dir, 
	[  --with-install-dir=PATH]
	[  path to installation directory],
	[
		if test "x$withval" != x; then
			INSTALLDIR="$withval"
			DOINSTALL=""
			if test "x${PATH_PROG_PHP}" != "xno"; then
				DOINSTALLPHP=""
			else
				DOINSTALLPHP="#"
			fi
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT(not found)
			DOINSTALL="#"
			DOINSTALLPHP="#"
		fi
	],
	[
		AC_MSG_RESULT([not found])
		DOINSTALL="#"
		DOINSTALLPHP="#"
	])
AC_SUBST(INSTALLDIR)
AC_SUBST(DOINSTALL)
AC_SUBST(DOINSTALLPHP)

AC_MSG_CHECKING(for whether to disable cgiwrapd)
AC_ARG_WITH( cgiwrapd,
	[ --without-cgiwrapd]
	[ disable installation of cgiwrapd ],
	[
		AC_MSG_RESULT([disabled])
		DOINSTALLCGIWRAPD="#"
	],
	[
		AC_MSG_RESULT([enabled])
		DOINSTALLCGIWRAPD=""
	])
AC_SUBST(DOINSTALLCGIWRAPD)

AC_MSG_CHECKING(for whether to disable nph-cgiwrap)
AC_ARG_WITH( nph,
	[ --without-nph]
	[ disable installation of nph-cgiwrap ],
	[
		AC_MSG_RESULT([disabled])
		DOINSTALLNPH="#"
	],
	[
		AC_MSG_RESULT([enabled])
		DOINSTALLNPH=""
	])
AC_SUBST(DOINSTALLNPH)


AC_MSG_CHECKING(for path to cgi scripts)
AC_ARG_WITH( cgi-dir, 
	[  --with-cgi-dir=PATH  (public_html/cgi-bin)]
	[  path relative to home dir for cgi scripts], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_CGIDIR, "$withval", [cgi dir relative to user home dir])
			AC_MSG_RESULT($withval)
		else
			AC_MSG_ERROR([must be defined])
		fi
	],
	[
		AC_MSG_RESULT([public_html/cgi-bin])
		AC_DEFINE_UNQUOTED(CONF_CGIDIR,"public_html/cgi-bin", [cgi dir relative to user home dir])
	])


dnl
dnl Checking for what server userid cgiwrap will run as
dnl
AC_MSG_CHECKING(for httpd-user)
AC_ARG_WITH( httpd-user, 
	[  --with-httpd-user=USER  (http)]
	[  define what userid the web server is running as], 
	[ 
		if test "x$withval" = xyes; then
			withval=http
		fi
		if test "x$withval" = xno; then
			withval=http
		fi
		if test "x$withval" = x; then
			withval=http
		fi
	],
	[ 
		withval=http
	])
AC_DEFINE_UNQUOTED(CONF_HTTPD_USER, "$withval", [user httpd executing as])
AC_MSG_RESULT([server running as "$withval"])

dnl
dnl Checking for whether to have a multiuser cgi dir
dnl
AC_MSG_CHECKING(for multiuser-cgi-dir)
AC_ARG_WITH( multiuser-cgi-dir, 
	[  --with-multiuser-cgi-dir=PATH  (disabled)]
	[  define a central shared cgi directory that acts as a fallback ]
	[  directory to search if the cgi script is not found in the user's ]
	[  own cgi directory. This can be dangerous if not used properly. ],
	[ 
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([must specify path, disabled.])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([must specify path, disabled.])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([must specify path, disabled.])
		else
			AC_MSG_RESULT([$withval])
			AC_DEFINE_UNQUOTED(CONF_MULTIUSER_CGI_DIR, "$withval", [support a shared multi-user cgi directory])
		fi
	],
	[ 
		AC_MSG_RESULT([disabled.])
	])

dnl
dnl Checking for what server userid cgiwrap will run as
dnl
AC_MSG_CHECKING(for check-httpd-user)
AC_ARG_WITH( check-httpd-user, 
	[  --without-check-httpd-user]
	[  don't check to make sure cgiwrap is being run by server userid], 
	[
		AC_MSG_RESULT([disabled, server userid will be checked])
		INSTALLMODE=4750
	],
	[
		AC_DEFINE(CONF_CHECK_HTTPD_USER, [], [check executing user - very important])
		AC_MSG_RESULT([enabled, be sure to restrict permissions])
		INSTALLMODE=4755
	])
AC_SUBST(INSTALLMODE)

dnl
dnl Use fork/wait3 to get rusage info 
dnl
dnl AC_FUNC_WAIT3
dnl don't use the above, it fails on sol26
AC_MSG_CHECKING(for report-rusage)
AC_ARG_WITH( report-rusage, 
	[  --with-report-rusage]
	[  report rusage and return status of cgi script after execution], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_REPORT_RUSAGE, [], [report rusage after script terminates])
			AC_MSG_RESULT([enabled, rusage and return code will be logged])
		else
			AC_MSG_RESULT([disabled, rusage and return code will not be logged])
		fi
	],
	[
		AC_MSG_RESULT([disabled, rusage and return code will not be logged])
	])

dnl
dnl Check for php filename, and pass to php interpreter directly
dnl
AC_MSG_CHECKING(for php-interpreter support)
AC_ARG_WITH( php-interpreter, 
	[  --with-php-interpreter]
	[  pass script to php interpreter if filename matches], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_PHP_INTERPRETER, [], [pass script to php interpreter if suffix])
			AC_MSG_RESULT([enabled, php will be handled specially])
		else
			AC_MSG_RESULT([disabled, no special handling for php scripts])
		fi
	],
	[
		AC_MSG_RESULT([disabled, no special handling for php scripts])
	])

AC_MSG_CHECKING(for whether to enable special support on non-executable files only)
AC_ARG_WITH( php-nonexec-only, 
	[  --with-php-nonexec-only]
	[  pass script to php interpreter only if not executable, otherwise use #! line ], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_PHP_NONEXEC_ONLY, [], [pass script to php interpreter only if nonexecutable file])
			AC_MSG_RESULT([enabled if php enabled, php will be handled specially only for nonexecutable files])
		else
			AC_MSG_RESULT([disabled, all php scripts handled the same if php enabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled, all php scripts handled the same if php enabled])
	])

AC_MSG_CHECKING(for whether to install separate php-cgiwrap wrapper)
AC_ARG_WITH( php-cgiwrap, 
	[  --with-php-cgiwrap]
	[  install separate php-cgiwrap executable ], 
	[
		if test "x$withval" != xno; then
			AC_MSG_RESULT([enabled])
		else
			DOINSTALLPHP="#"
			AC_MSG_RESULT([disabled]);
		fi
	],
	[
		DOINSTALLPHP="#"
		AC_MSG_RESULT([disabled]);
	])
AC_SUBST(DOINSTALLPHP)



dnl
dnl Check for asp filename, and pass to php interpreter directly
dnl
AC_MSG_CHECKING(for asp-interpreter support)
AC_ARG_WITH( asp-interpreter, 
	[  --with-asp-interpreter]
	[  pass script to asp interpreter if filename matches], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_ASP_INTERPRETER, [], [pass script to asp interpreter if suffix])
			AC_MSG_RESULT([enabled, asp will be handled specially])
		else
			AC_MSG_RESULT([disabled, no special handling for asp scripts])
		fi
	],
	[
		AC_MSG_RESULT([disabled, no special handling for asp scripts])
	])

AC_MSG_CHECKING(for whether to enable special support on non-executable files only)
AC_ARG_WITH( asp-nonexec-only, 
	[  --with-asp-nonexec-only]
	[  pass script to asp interpreter only if not executable, otherwise use #! line ], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_ASP_NONEXEC_ONLY, [], [pass script to asp interpreter only if nonexecutable file])
			AC_MSG_RESULT([enabled if asp enabled, asp will be handled specially only for nonexecutable files])
		else
			AC_MSG_RESULT([disabled, all asp scripts handled the same if asp enabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled, all asp scripts handled the same if asp enabled])
	])



dnl
dnl Enable/disable check for special characters in the script path
dnl Disabling this turns off the !isprint and isspace checks in the
dnl CheckPath routine. Thanks to Cobalt for pointing out that this
dnl would break japanese compatability. 
dnl
AC_MSG_CHECKING(for strict-names)
AC_ARG_WITH( strict-names,
	[  --without-strict-names]
	[  disable check for !isprint() and isspace() in script path],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_STRICT_NAMES, [], [check for nonprintables in script path])
			AC_MSG_RESULT([enabled, script must be all alphanumeric])
		else
			AC_MSG_RESULT([disabled, script name not checked])
		fi
	],
	[
		AC_DEFINE(CONF_STRICT_NAMES, [], [check for nonprintables in script path])
		AC_MSG_RESULT([enabled, script name must be all alphanumeric])
	])

dnl
dnl Various cgi-script permission checks
dnl The DEFINE is in the 'not-found' section of the macro
dnl
AC_MSG_CHECKING(for check-owner)
AC_ARG_WITH( check-owner, 
	[  --without-check-owner]
	[  disable check for matching owner],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCRUID, [], [check script uid])
			AC_MSG_RESULT([enabled, owner of script must match])
		else
			AC_MSG_RESULT([disabled, owner of script can be different])
		fi
	],
	[
		AC_DEFINE(CONF_CHECK_SCRUID, [], [check script uid])
		AC_MSG_RESULT([enabled, owner of script must match])
	])

AC_MSG_CHECKING(for check-group)
AC_ARG_WITH( check-group, 
	[  --without-check-group]
	[  disable check for matching group],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCRGID, [], [check script gid])
			AC_MSG_RESULT([enabled, group of script must match])
		else
			AC_MSG_RESULT([disabled, group of script can be different])
		fi
	],
	[
		AC_DEFINE(CONF_CHECK_SCRGID, [], [check script gid])
		AC_MSG_RESULT([enabled, group of script must match])
	])

AC_MSG_CHECKING(for check-setuid)
AC_ARG_WITH( check-setuid, 
	[  --without-check-setuid]
	[  disable check for setuid script],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCRSUID, [], [check script is suid])
			AC_MSG_RESULT([enabled, script cannot be setuid])
		else
			AC_MSG_RESULT([disabled, script can be setuid])
		fi
	],
	[
		AC_MSG_RESULT([enabled, script cannot be setuid])
		AC_DEFINE(CONF_CHECK_SCRSUID, [], [check script is suid])		
	])

AC_MSG_CHECKING(for check-setgid)
AC_ARG_WITH( check-setgid, 
	[  --without-check-setgid]
	[  disable check for setgid script],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCRSGID, [], [check script is sgid])
			AC_MSG_RESULT([enabled, script cannot be setuid])
		else
			AC_MSG_RESULT([disabled, script can be setgid])
		fi
	],
	[
		AC_MSG_RESULT([enabled, script cannot be setgid])
		AC_DEFINE(CONF_CHECK_SCRSGID, [], [check script is sgid])		
	])

AC_MSG_CHECKING(for check-group-writable)
AC_ARG_WITH( check-group-writable, 
	[  --without-check-group-writable]
	[  disable check for group writable script],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCRGWRITE, [], [check script is group writable])
			AC_MSG_RESULT([enabled, script cannot be group writable])
		else
			AC_MSG_RESULT([disabled, script can be group writable])
		fi
	],
	[
		AC_DEFINE(CONF_CHECK_SCRGWRITE, [], [check script is group writable])
		AC_MSG_RESULT([enabled, script cannot be group writable])
	])

AC_MSG_CHECKING(for check-world-writable)
AC_ARG_WITH( check-world-writable, 
	[  --without-check-world-writable]
	[  disable check for world writable script],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SCROWRITE, [], [check script is world writable])
			AC_MSG_RESULT([enabled, script cannot be world writable])
		else
			AC_MSG_RESULT([disabled, script can be world writable])
		fi
	],
	[
		AC_DEFINE(CONF_CHECK_SCROWRITE, [], [check script is world writable])
		AC_MSG_RESULT([enabled, script cannot be world writable])
	])

AC_MSG_CHECKING(for check-symlink)
AC_ARG_WITH( check-symlink,
	[  --without-check-symlink]
	[  disable check for symlinked script],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECK_SYMLINK, [], [check if script is symlink])
			AC_MSG_RESULT([enabled, script cannot be a symlink])
		else
			AC_MSG_RESULT([disabled, script can be a symlink])
		fi
	],
	[
		AC_MSG_RESULT([enabled, script cannot be a symlink])
		AC_DEFINE(CONF_CHECK_SYMLINK, [], [check if script is symlink])
	])

dnl
dnl Check for minimum uid
dnl
AC_MSG_CHECKING(for minimum uid)
AC_ARG_WITH( minimum-uid, 
	[  --with-minimum-uid=UID  (10)]
	[  minimum uid to allow script execution], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_MINIMUM_UID, $withval, [check for minimum script uid])
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([10])
		AC_DEFINE_UNQUOTED(CONF_MINIMUM_UID,10,[check for minimum script uid])
	])

dnl
dnl Check for minimum gid
dnl
AC_MSG_CHECKING([for minimum gid (primary and auxilliary)])
AC_ARG_WITH( minimum-gid, 
	[  --with-minimum-gid=GID  (not checked)]
	[  minimum gid to allow script execution], 
	[
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_MINIMUM_GID, $withval, [check for minimum script gid])
			AC_MSG_RESULT($withval)
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])


dnl
dnl Options for logging script execution
dnl
AC_MSG_CHECKING(for logging-syslog)
AC_ARG_WITH( logging-syslog,
	[  --with-logging-syslog=LABEL]
	[  enable logging script execution to syslog],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_LOG_USESYSLOG, [], [use syslog for logging])
			AC_DEFINE_UNQUOTED(CONF_LOG_LABEL, "$withval", [syslog log label])
			AC_MSG_RESULT([enabled, label is '${withval}'])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for logging-file)
AC_ARG_WITH( logging-file,
	[  --with-logging-file=FILE  (/usr/adm/cgiwrap.log)]
	[  enable logging script execution to file],
	[
		if test "x$withval" = x; then
			withval="/usr/adm/cgiwrap.log"
		fi

		if test "x$withval" != xno; then
			AC_DEFINE(CONF_LOG_USEFILE, [], [use logfile for logging])
			AC_DEFINE_UNQUOTED(CONF_LOG_LOGFILE, "$withval", [logfile path])
			AC_MSG_RESULT([enabled, logging to file '${withval}'])
		else
			AC_MSG_RESULT(disabled)
		fi
	],
	[
		AC_MSG_RESULT(disabled)
	])


dnl
dnl Option to not allow scripts in subdirectories
dnl
AC_MSG_CHECKING(for script-subdirs)
AC_ARG_WITH( script-subdirs,
	[  --without-script-subdirs]
	[  prevent users from storing scripts in subdirs],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_SUBDIRS, [], [allow scripts in subdirs])
			AC_MSG_RESULT([enabled, scripts allowed in subdirectories])
		else
			AC_MSG_RESULT([disabled, scripts not allowed in subdirectories])
		fi
	],
	[
		AC_DEFINE(CONF_SUBDIRS, [], [allow scripts in subdirs])
		AC_MSG_RESULT([enabled, scripts allowed in subdirectories])
	])


dnl
dnl Option to not redirect the stderr output
dnl
AC_MSG_CHECKING(for redirect-stderr)
AC_ARG_WITH( redirect-stderr,
	[  --without-redirect-stderr]
	[  don't redirect stderr to stdout in scripts],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_REDIR_STDERR, [], [redirect stderr on script execution])
			AC_MSG_RESULT([enabled, stderr output will go to stdout])
		else
			AC_MSG_RESULT([disabled, server will get stderr output])
		fi
	],
	[
		AC_DEFINE(CONF_REDIR_STDERR, [], [redirect stderr on script execution])
		AC_MSG_RESULT([enabled, stderr output will go to stdout])
	])


dnl
dnl Options for clearing/setting a user's auxilliary (/etc/groups) groups
dnl
AC_MSG_CHECKING(for initgroups)
AC_ARG_WITH( initgroups,
	[  --without-initgroups]
	[  disable use of initgroups() to clear non-userid auxilliary groups],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_INITGROUPS, [], [call initgroups])
			AC_MSG_RESULT([enabled, aux groups will be cleared])
		else
			AC_MSG_RESULT([disabled, aux groups will not be cleared])
		fi
	],
	[
		AC_DEFINE(CONF_INITGROUPS, [], [call initgroups])
		AC_MSG_RESULT([enabled, aux groups will be cleared])
	])

AC_MSG_CHECKING(for setgroups)
AC_ARG_WITH( setgroups,
	[  --without-setgroups]
	[  disable use of setgroups() to add userid's auxilliary groups],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_SETGROUPS, [], [call setgroups])
			AC_MSG_RESULT([enabled, aux groups will be set])
		else
			AC_MSG_RESULT([disabled, aux groups will not be set])
		fi
	],
	[
		AC_DEFINE(CONF_SETGROUPS, [], [call setgroups])
		AC_MSG_RESULT([enabled, aux groups will be set])
	])


dnl
dnl Option for enabling and specifying the user dir rewrite file
dnl
AC_MSG_CHECKING(for user directory rewrite)
AC_ARG_WITH( rewrite,
	[  --with-rewrite=FILE]
	[  use a file to rewrite user directories],
	[
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_USERDIRFILE, "$withval", [check user homedir rewrite file])
			AC_MSG_RESULT([enabled, rewrite file is "$withval"])
		else
			AC_MSG_RESULT([disabled, no rewrite file will be used])
		fi
	],
	[
		AC_MSG_RESULT([disabled, no rewrite file will be used])
	])

dnl
dnl Environment variable definitions
dnl
dnl CGIWRAP_SETENV(path,PATH,STRING,[search path])

AC_DEFUN(CGIWRAP_SETENV,[
	AC_MSG_CHECKING(for setenv-$1)
	AC_ARG_WITH( setenv-$1,
	[  --with-setenv-$1=$3]
        [  set $2 environment variable to $3],
	[
		if test "x$withval" = xyes; then
			AC_MSG_RESULT([no value specified])
		elif test "x$withval" = x; then
			AC_MSG_RESULT([no value specified])
		elif test "x$withval" = xno; then
			AC_MSG_RESULT([disabled])
		else
			AC_DEFINE(CONF_SETENV_ANY, [], [some setenvs are defined])
			AC_DEFINE_UNQUOTED(CONF_SETENV_$2, "$withval", [setenv for $2 to $withval])
			AC_MSG_RESULT([enabled, set to ("$withval")])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])
])

CGIWRAP_SETENV(ld_library_path,LD_LIBRARY_PATH,STRING,[lib search path])
CGIWRAP_SETENV(path,PATH,STRING,[search path])
CGIWRAP_SETENV(tz,TZ,STRING,[time zone])


dnl
dnl Resource limits for those who want to use them
dnl
dnl CGIWRAP_RLIMIT(cpu,CPU,SECONDS,[cpu seconds],10,[cpu usage])

AC_DEFUN(CGIWRAP_RLIMIT,[
	AC_MSG_CHECKING(for limit rlimit-$1)
	AC_ARG_WITH( rlimit-$1,
	[  --with-rlimit-$1=$3  ($5)]
        [  limit $6 with setrlimit],
	[
		if test "x$withval" = xyes; then
			withval=$5
		fi
		if test "x$withval" = x; then
			withval=$5
		fi
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_USE_RLIMIT_ANY, [], [any rlimits are set])
			AC_DEFINE_UNQUOTED(CONF_USE_RLIMIT_$2, $withval, [set rlimit for $2 to $4])
			AC_MSG_RESULT(["$withval" $4])
		else
			AC_MSG_RESULT([none])
		fi
	],
	[
		AC_MSG_RESULT([none])
	])
])

CGIWRAP_RLIMIT(cpu,CPU,SECONDS,[cpu seconds],10,[cpu time])
CGIWRAP_RLIMIT(vmem,VMEM,BYTES,[bytes],2500000,[total virtual memory])
CGIWRAP_RLIMIT(as,AS,BYTES,[bytes],2500000,[total available memory])
CGIWRAP_RLIMIT(fsize,FSIZE,BYTES,[bytes],2500000,[writable file size])
CGIWRAP_RLIMIT(data,DATA,BYTES,[bytes],2500000,[data segment size])
CGIWRAP_RLIMIT(stack,STACK,BYTES,[bytes],2500000,[stack segment size])
CGIWRAP_RLIMIT(core,CORE,BYTES,[bytes],2500000,[core file size])
CGIWRAP_RLIMIT(rss,RSS,BYTES,[bytes],2500000,[resident set size])
CGIWRAP_RLIMIT(nproc,NPROC,COUNT,[processes],32,[number of processes])
CGIWRAP_RLIMIT(nofile,NOFILE,COUNT,[files],32,[number of open files])
CGIWRAP_RLIMIT(memlock,MEMLOCK,BYTES,[bytes],2500000,[lockable memory])




dnl
dnl Options for access control files
dnl

AC_MSG_CHECKING(for allow-file)
AC_ARG_WITH( allow-file,
	[  --with-allow-file=FILE  (/usr/adm/cgiwrap.allow)]
	[  limit cgiwrap usage],
	[
		if test "x$withval" = x; then
			withval="/usr/adm/cgiwrap.allow"
		fi
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_ALLOWFILE, "$withval", [user allow config file])
			AC_MSG_RESULT([enabled, file is "$withval"])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for deny-file)
AC_ARG_WITH( deny-file,
	[  --with-deny-file=FILE  (/usr/adm/cgiwrap.deny)]
	[  limit cgiwrap usage],
	[
		if test "x$withval" = x; then
			withval="/usr/adm/cgiwrap.deny"
		fi
		if test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_DENYFILE, "$withval", [user deny config file])
			AC_MSG_RESULT([enabled, file is "$withval"])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])


dnl
dnl Options for access control files
dnl

AC_MSG_CHECKING(for allow-deny-netgroups)
AC_ARG_WITH( allow-deny-netgroups,
	[  --with-allow-deny-netgroups  (disabled)]
	[  limit cgiwrap usage based on netgroup membership],
	[
		if test "x$withval" = x; then
			AC_MSG_RESULT([disabled])
		elif test "x$withval" != xno; then
			AC_DEFINE(CONF_ALLOWDENY_NETGROUPS, [], [enabled checking netgroup syntax in allow/deny files])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for vhost-allow-dir)
AC_ARG_WITH( vhost-allow-dir,
	[  --with-vhost-allow-dir=FILE  (disabled)]
	[  limit cgiwrap usage on vhosts],
	[
		if test "x$withval" = x; then
			AC_MSG_RESULT([disabled])
		elif test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_VHOST_ALLOWDIR, "$withval", [dir for vhost allow files])
			AC_MSG_RESULT([enabled, dir is "$withval"])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for vhost-deny-dir)
AC_ARG_WITH( vhost-deny-dir,
	[  --with-vhost-deny-dir=FILE  (disabled)]
	[  limit cgiwrap usage on vhosts],
	[
		if test "x$withval" = x; then
			AC_MSG_RESULT([disabled])
		elif test "x$withval" != xno; then
			AC_DEFINE_UNQUOTED(CONF_VHOST_DENYDIR, "$withval", [dir for vhost deny files])
			AC_MSG_RESULT([enabled, dir is "$withval"])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for host checking)
AC_ARG_WITH( host-checking,
	[  --with-host-checking]
	[  allow specifying hosts in allow/deny files],
	[
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECKHOST, [], [check host in allow/deny files])
			AC_MSG_RESULT([enabled])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

AC_MSG_CHECKING(for shell checking)
AC_ARG_WITH( check-shell,
	[  --with-check-shell]
	[  user shell must be in system shells list ],
	[
		GETUSERSHELL=""
		if test "x$withval" != xno; then
			AC_DEFINE(CONF_CHECKSHELL, [], [check shell against /etc/shells])
			AC_MSG_RESULT([enabled])
			AC_CHECK_FUNC(getusershell, , [GETUSERSHELL="getusershell.o"])
			AC_MSG_CHECKING(for OS specific getusershell support)
			os_specific_msg="none needed"
			case $target_os in
			aix* )	
				LIBS="$LIBS -ls"
				os_specific_msg="-ls"
				;;
			esac
			AC_MSG_RESULT([$os_specific_msg])
		else
			AC_MSG_RESULT([disabled])
		fi
	],
	[
		GETUSERSHELL=""
		AC_MSG_RESULT([disabled])
	])
AC_SUBST(GETUSERSHELL)

dnl
dnl Options for AFS PAG support
dnl
AC_MSG_CHECKING([for afs setpag() support])
AC_ARG_WITH( afs,
	[  --with-afs=DIR  (/usr/afsws)]
	[  enable afs setpag() support],
	[
		if test "x$withval" = xno; then
			AC_MSG_RESULT([disabled])
		else
			if test "x$withval" = x; then
				withval="/usr/afsws"
			fi
			if test "x$withval" = xyes; then
				withval="/usr/afsws"
			fi
			AFSDIR="$withval"
			AFSLDFLAGS="-L${AFSDIR}/lib -L${AFSDIR}/lib/afs"
			AFSLIBS="-lsys -lrx -llwp ${AFSDIR}/lib/afs/util.a"
			AC_DEFINE(CONF_AFS_SETPAG, [], [set AFS pag])
			AC_MSG_RESULT([enabled, afs dir is "$withval"])
		fi
	],
	[
		AC_MSG_RESULT([disabled])
	])

dnl
dnl Special lib requirements for AFS
dnl
if test "x$AFSDIR" != x; then
	AC_MSG_CHECKING(for extra requirements for AFS support)
	os_specific_msg="none needed"
	case $target_os in
		hpux* )	
			EXTRA_AFS_LIBS="-lBSD"
			AFSLIBS="$AFSLIBS $EXTRA_AFS_LIBS"
			os_specific_msg="$EXTRA_AFS_LIBS"
		;;
		*solaris*)
			EXTRA_AFS_LIBS="-lnsl -lsocket -L/usr/ucblib -lucb"
			AFSLIBS="$AFSLIBS $EXTRA_AFS_LIBS"
			os_specific_msg="$EXTRA_AFS_LIBS"
		;;
	esac
	AC_MSG_RESULT([$os_specific_msg])
fi

AC_SUBST(AFSDIR)
AC_SUBST(AFSLDFLAGS)
AC_SUBST(AFSLIBS)

AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h stdlib.h pwd.h string.h strings.h)
AC_CHECK_HEADERS(sys/resource.h sys/types.h sys/time.h unistd.h)
AC_CHECK_HEADERS(syslog.h fcntl.h sys/stat.h signal.h ctype.h grp.h)
AC_CHECK_HEADERS(errno.h sys/errno.h sys/wait.h time.h sys/signal.h)

AC_OUTPUT(Makefile unsup/loganalyze.pl)
