Skip to content

Commit df376cd

Browse files
committed
Autoconf: Get --with-user and --with-chroot right. [skip appveyor]
As Francois-Xavier points it out, my commit 3aa6574 fixed one bug, but introduced another: running "./configure --with-gcc" also erroneously takes the --with-user code path because withval is set to "yes" after the --with-gcc block: ./configure --with-gcc [...] checking whether to drop root privileges by default... configure: error: --with-user requires a username The matter is, in Autoconf AC_ARG_WITH() without ation-if-not-given assigns withval only if with_xxxx is set to any value (including an empty string), so make sure withval is always set in AC_ARG_WITH() and spell all possible withval values in AS_CASE(), this way regardless of any other options the behaviour is correct. Rejected: --with-user --with-user= --with-user=yes --with-chroot --with-chroot= --with-chroot=yes Accepted: --without-user --with-user=no --with-user=someuser --without-chroot --with-chroot=no --with-chroot=/somedir
1 parent b200ed9 commit df376cd

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

configure.ac

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,42 @@ yes) AC_MSG_RESULT(yes)
179179
;;
180180
esac
181181

182-
AC_ARG_WITH(user, [ --with-user=USERNAME drop privileges by default to USERNAME])
183182
AC_MSG_CHECKING([whether to drop root privileges by default])
184-
if test ! -z "$withval" && test "$withval" != "no" ; then
185-
if test "$withval" = "yes" ; then
186-
AC_MSG_ERROR([--with-user requires a username])
187-
fi
188-
AC_DEFINE_UNQUOTED(WITH_USER, "$withval",
189-
[define if should drop privileges by default])
190-
AC_MSG_RESULT([yes, to user "$withval"])
191-
else
192-
AC_MSG_RESULT(no)
193-
fi
183+
AC_ARG_WITH(
184+
[user],
185+
[AS_HELP_STRING([--with-user=USERNAME],
186+
[drop privileges by default to USERNAME]
187+
)],
188+
[],
189+
[withval=no])
190+
AS_CASE(["$withval"],
191+
[no], [AC_MSG_RESULT(no)],
192+
[''|yes], [AC_MSG_ERROR([--with-user requires a username])],
193+
[
194+
AC_DEFINE_UNQUOTED(WITH_USER, "$withval",
195+
[define if should drop privileges by default])
196+
AC_MSG_RESULT([yes, to user "$withval"])
197+
]
198+
)
194199

195-
AC_ARG_WITH(chroot, [ --with-chroot=DIRECTORY when dropping privileges, chroot to DIRECTORY])
196200
AC_MSG_CHECKING([whether to chroot])
197-
if test ! -z "$withval" && test "$withval" != "no" ; then
198-
if test "$withval" = "yes" ; then
199-
AC_MSG_ERROR([--with-chroot requires a directory])
200-
fi
201-
AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval",
202-
[define if should chroot when dropping privileges])
203-
AC_MSG_RESULT([yes, to directory "$withval"])
204-
else
205-
AC_MSG_RESULT(no)
206-
fi
201+
AC_ARG_WITH(
202+
[chroot],
203+
[AS_HELP_STRING([--with-chroot=DIRECTORY],
204+
[when dropping privileges, chroot to DIRECTORY]
205+
)],
206+
[],
207+
[withval=no]
208+
)
209+
AS_CASE(["$withval"],
210+
[no], [AC_MSG_RESULT(no)],
211+
[''|yes], [AC_MSG_ERROR([--with-chroot requires a directory])],
212+
[
213+
AC_DEFINE_UNQUOTED(WITH_CHROOT, "$withval",
214+
[define if should chroot when dropping privileges])
215+
AC_MSG_RESULT([yes, to directory "$withval"])
216+
]
217+
)
207218

208219
AC_ARG_WITH(sandbox-capsicum,
209220
AS_HELP_STRING([--with-sandbox-capsicum],

0 commit comments

Comments
 (0)