From 94f955fa909b0d3bb216b9c6ddaf365c9d7c861d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 26 Mar 2019 18:39:40 +0000 Subject: [PATCH] Add an autoconf test and workaround for futimes(3). Not every system provides it (e.g. uClibc-ng); if one does not, the Uppity SFTP server should now degrade sensibly to refusing attempts to set the utimes on an already-open file. --- configure.ac | 2 +- unix/uxsftpserver.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 35552ed2..38b3e8b9 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,7 @@ AC_CHECK_LIB(X11, XOpenDisplay, [GTK_LIBS="-lX11 $GTK_LIBS" AC_DEFINE([HAVE_LIBX11],[],[Define if libX11.a is available])]) -AC_CHECK_FUNCS([getaddrinfo posix_openpt ptsname setresuid strsignal updwtmpx fstatat dirfd]) +AC_CHECK_FUNCS([getaddrinfo posix_openpt ptsname setresuid strsignal updwtmpx fstatat dirfd futimes]) AC_CHECK_DECLS([CLOCK_MONOTONIC], [], [], [[#include ]]) AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE([HAVE_CLOCK_GETTIME],[],[Define if clock_gettime() is available])]) diff --git a/unix/uxsftpserver.c b/unix/uxsftpserver.c index 6fab0ba0..a90344e0 100644 --- a/unix/uxsftpserver.c +++ b/unix/uxsftpserver.c @@ -412,6 +412,16 @@ static void uss_fstat(SftpServer *srv, SftpReplyBuilder *reply, } } +#if !HAVE_FUTIMES +static inline int futimes(int fd, const struct timeval tv[2]) +{ + /* If the OS doesn't support futimes(3) then we have to pretend it + * always returns failure */ + errno = EINVAL; + return -1; +} +#endif + /* * The guts of setstat and fsetstat, macroised so that they can call * fchown(fd,...) or chown(path,...) depending on parameters.