]> git.sesse.net Git - betaftpd/blobdiff - configure.in
Fixed a security problem where the custom snprintf() would always be used. Thanks...
[betaftpd] / configure.in
index 763e05dd6b83a3d2ac4cdb9a9becf3e44014ff07..6767a1328fd20f1aa7a8cb775db286350d113a0f 100644 (file)
@@ -92,7 +92,7 @@ else
 fi
 
 if test "$nonroot_support" = "yes"; then
-       ARG_ENABLE_BETAFTPD(nonroot,[  --enable-nonroot        Do not need root access (implies --disable-shadow)],AC_DEFINE(WANT_NONROOT))
+       ARG_ENABLE_BETAFTPD(nonroot,[  --enable-nonroot        Do not need root access (EXPERIMENTAL)],AC_DEFINE(WANT_NONROOT))
 else
        enableval=no
 fi
@@ -167,7 +167,7 @@ if test "$result" = "yes"; then
 fi
 
 if test "$result" = "no"; then
-       AC_CHECK_HEADER(linux/socket.h)
+       AC_CHECK_HEADERS(linux/socket.h linux/tcp.h)
 fi
 
 AC_CHECK_HEADERS(sys/poll.h)
@@ -194,6 +194,9 @@ dnl
 dnl sendfile() is not standard -- we'll have to check the different
 dnl versions one by one :-)
 dnl
+dnl Unfortunately, we'll have to run the program too -- this is a
+dnl problem with newer libc's and not-so-new kernels :-)
+dnl
 AC_CHECK_HEADERS(sys/sendfile.h,result=yes,result=no)
 
 if test "$result" = "yes"; then
@@ -219,9 +222,14 @@ if test "$result" = "yes"; then
 #include <sys/types.h>
 #endif
 
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 #if HAVE_SYS_UIO_H
 #include <sys/uio.h>
-#endif],[
+#endif
+],[
        int out_fd = 1, in_fd = 0;
        off_t offset = 0;
        size_t size = 1024;
@@ -231,7 +239,71 @@ if test "$result" = "yes"; then
        AC_MSG_RESULT($enableval)
 
        if test "$enableval" = "yes"; then
-               AC_DEFINE(HAVE_LINUX_SENDFILE, 1, [Define if you have sendfile() with the Linux semantics.])
+               dnl
+               dnl If the compile fails now, we assume sendfile() exists (since this
+               dnl is by far the most common case)
+               dnl
+               AC_MSG_CHECKING([that sendfile() really is implemented])
+
+               AC_TRY_RUN([
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#if HAVE_SYS_LIMITS_H
+#include <sys/limits.h>
+#endif
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#if HAVE_SYS_SENDFILE_H
+#include <sys/sendfile.h>
+#endif
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#if HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+
+int main() {
+        int out_fd = 1, in_fd = 0;
+        off_t offset = 0;
+        size_t size = 1024;
+
+       errno = 0;
+       sendfile(out_fd, in_fd, &offset, size);
+       if (errno == ENOSYS)
+               return 0;
+       else
+               return 1;
+}],
+               enableval=no,enableval=yes,[enableval="cross-compiling, not checked"])
+               AC_MSG_RESULT($enableval)
+
+               has_sendfile=$enableval
+
+               dnl
+               dnl Force sendfile() `state' if the user tells us to
+               dnl
+               AC_ARG_WITH(linux-sendfile,[  --with-linux-sendfile   Force sendfile() support],has_sendfile=$withval)
+
+               if test $has_sendfile != "no"; then
+                       AC_DEFINE(HAVE_LINUX_SENDFILE, 1, [Define if you have sendfile() with the Linux semantics.])
+                       has_sendfile=enabled
+               else
+                       has_sendfile=disabled
+               fi
+               AC_MSG_CHECKING([final status of Linux sendfile() support])
+               AC_MSG_RESULT($has_sendfile)
        fi
 fi