From: Denis Ovsienko Date: Sat, 11 Feb 2023 22:17:33 +0000 (+0000) Subject: Autoconf: Fix --with-user and --with-chroot. [skip appveyor] X-Git-Tag: tcpdump-4.99.5~182 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/46e3bdae96a220f0407a7bad2c3c15710c7d07ad Autoconf: Fix --with-user and --with-chroot. [skip appveyor] Refine two blocks in configure.ac such that each option correctly handles both of the Autoconf-supplied values ("yes" and "no") and, when the option is properly enabled, the message is easier to understand. See also commit 9aca99a. While at it, use $withval more to unify the code and squelch the following warnings from Autoconf 2.71: configure.ac:188: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: result: to \"$withval\" configure.ac:188: warning: back quotes and double quotes must not be escaped in: to \"$withval\" configure.ac:198: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: result: to \"$withval\" configure.ac:198: warning: back quotes and double quotes must not be escaped in: to \"$withval\" User experience before: ./configure checking whether to drop root privileges by default... no checking whether to chroot... no ./configure --with-user=someuser --with-chroot=/some/dir/ checking whether to drop root privileges by default... to "someuser" checking whether to chroot... to "/some/dir/" ./configure --without-user --without-chroot checking whether to drop root privileges by default... to "no" checking whether to chroot... no ./configure --with-user checking whether to drop root privileges by default... to "yes" ./configure --with-chroot checking whether to chroot... to "yes" User experience after: ./configure checking whether to drop root privileges by default... no checking whether to chroot... no ./configure --with-user=someuser --with-chroot=/some/dir/ checking whether to drop root privileges by default... yes, to user "someuser" checking whether to chroot... yes, to directory "/some/dir/" ./configure --without-user --without-chroot checking whether to drop root privileges by default... no checking whether to chroot... no ./configure --with-user configure: error: --with-user requires a username ./configure --with-chroot configure: error: --with-chroot requires a directory (cherry picked from commit 3aa65743dde584106c3b5b13a67ae45bcfd7c16c) --- diff --git a/configure.ac b/configure.ac index b36492a7..21a0f701 100644 --- a/configure.ac +++ b/configure.ac @@ -155,20 +155,26 @@ esac AC_ARG_WITH(user, [ --with-user=USERNAME drop privileges by default to USERNAME]) AC_MSG_CHECKING([whether to drop root privileges by default]) -if test ! -z "$with_user" ; then +if test ! -z "$withval" && test "$withval" != "no" ; then + if test "$withval" = "yes" ; then + AC_MSG_ERROR([--with-user requires a username]) + fi AC_DEFINE_UNQUOTED(WITH_USER, "$withval", [define if should drop privileges by default]) - AC_MSG_RESULT(to \"$withval\") + AC_MSG_RESULT([yes, to user "$withval"]) else AC_MSG_RESULT(no) fi AC_ARG_WITH(chroot, [ --with-chroot=DIRECTORY when dropping privileges, chroot to DIRECTORY]) AC_MSG_CHECKING([whether to chroot]) -if test ! -z "$with_chroot" && test "$with_chroot" != "no" ; then +if test ! -z "$withval" && test "$withval" != "no" ; then + if test "$withval" = "yes" ; then + AC_MSG_ERROR([--with-chroot requires a directory]) + fi AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval", [define if should chroot when dropping privileges]) - AC_MSG_RESULT(to \"$withval\") + AC_MSG_RESULT([yes, to directory "$withval"]) else AC_MSG_RESULT(no) fi