]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Autoconf: Fix --with-user and --with-chroot. [skip appveyor]
authorDenis Ovsienko <[email protected]>
Sat, 11 Feb 2023 22:17:33 +0000 (22:17 +0000)
committerDenis Ovsienko <[email protected]>
Sat, 11 Feb 2023 22:17:33 +0000 (22:17 +0000)
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

configure.ac

index f5b28fcc978b40c0f0c7552ee8de3140afdd51f4..6d6936f2c57e0cf7f8fabd2c1e8d1e811713fd26 100644 (file)
@@ -182,20 +182,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