vsftpd/vsftpd-2.2.2-nfs-fail.patch

145 lines
3.8 KiB
Diff
Raw Normal View History

2016-03-17 13:58:25 +00:00
From 1be2ebccc0a5e1040fa9bb5f1cac8040070830df Mon Sep 17 00:00:00 2001
2016-03-17 13:10:03 +00:00
From: Martin Sehnoutka <msehnout@redhat.com>
2016-03-17 13:58:25 +00:00
Date: Thu, 17 Mar 2016 14:51:29 +0100
2016-03-17 13:10:03 +00:00
Subject: [PATCH 25/26] Applied vsftpd-2.2.2-nfs-fail.patch
---
2016-03-17 13:58:25 +00:00
ftpcodes.h | 1 +
postlogin.c | 32 ++++++++++++++++++++++++++++++--
sysutil.c | 21 +++++++++++++++++++++
sysutil.h | 1 +
4 files changed, 53 insertions(+), 2 deletions(-)
2016-03-17 13:10:03 +00:00
diff --git a/ftpcodes.h b/ftpcodes.h
index 81e25c5..3950f92 100644
--- a/ftpcodes.h
+++ b/ftpcodes.h
@@ -73,6 +73,7 @@
#define FTP_NOHANDLEPROT 536
#define FTP_FILEFAIL 550
#define FTP_NOPERM 550
+#define FTP_DISKQUOTA 552
#define FTP_UPLOADFAIL 553
#endif /* VSF_FTPCODES_H */
diff --git a/postlogin.c b/postlogin.c
index 29958c0..154c16a 100644
--- a/postlogin.c
+++ b/postlogin.c
@@ -28,6 +28,8 @@
#include "vsftpver.h"
#include "opts.h"
+#include <errno.h>
+
/* Private local functions */
static void handle_pwd(struct vsf_session* p_sess);
static void handle_cwd(struct vsf_session* p_sess);
@@ -1028,8 +1030,10 @@ handle_upload_common(struct vsf_session* p_sess, int is_append, int is_unique)
struct vsf_transfer_ret trans_ret;
int new_file_fd;
int remote_fd;
+ int close_errno;
int success = 0;
int created = 0;
+ int closed = 0;
int do_truncate = 0;
filesize_t offset = p_sess->restart_pos;
p_sess->restart_pos = 0;
@@ -1142,6 +1146,18 @@ handle_upload_common(struct vsf_session* p_sess, int is_append, int is_unique)
trans_ret = vsf_ftpdataio_transfer_file(p_sess, remote_fd,
new_file_fd, 1, 0);
}
+
+ /* Need to check close operation here because some errors
+ * like EIO, EDQUOT, ENOSPC can be detected only on close
+ * when using NFS
+ */
+ close_errno = vsf_sysutil_close_errno(new_file_fd);
+ closed = 1;
+ if (close_errno != 0)
+ {
+ trans_ret.retval = -1;
+ }
+
if (vsf_ftpdataio_dispose_transfer_fd(p_sess) != 1 && trans_ret.retval == 0)
{
trans_ret.retval = -2;
@@ -1154,7 +1170,16 @@ handle_upload_common(struct vsf_session* p_sess, int is_append, int is_unique)
}
if (trans_ret.retval == -1)
{
- vsf_cmdio_write(p_sess, FTP_BADSENDFILE, "Failure writing to local file.");
+ /* Disk quota exceeded */
+ if (close_errno == EDQUOT)
+ {
+ vsf_cmdio_write(p_sess, FTP_DISKQUOTA, "Disk quota exceeded.");
+ }
+ /* any other local error */
+ else
+ {
+ vsf_cmdio_write(p_sess, FTP_BADSENDFILE, "Failure writing to local file.");
+ }
}
else if (trans_ret.retval == -2)
{
@@ -1176,7 +1201,10 @@ port_pasv_cleanup_out:
{
str_unlink(p_filename);
}
- vsf_sysutil_close(new_file_fd);
+ if (!closed)
+ {
+ vsf_sysutil_close(new_file_fd);
+ }
}
static void
diff --git a/sysutil.c b/sysutil.c
index a924edf..6dfe350 100644
--- a/sysutil.c
+++ b/sysutil.c
@@ -1259,6 +1259,27 @@ vsf_sysutil_close(int fd)
}
int
+vsf_sysutil_close_errno(int fd)
+{
+ while (1)
+ {
+ int retval = close(fd);
+ if (retval != 0)
+ {
+ if (errno == EINTR)
+ {
+ vsf_sysutil_check_pending_actions(kVSFSysUtilUnknown, 0, 0);
+ continue;
+ }
+ else {
+ return errno;
+ }
+ }
+ return 0;
+ }
+}
+
+int
vsf_sysutil_close_failok(int fd)
{
return close(fd);
diff --git a/sysutil.h b/sysutil.h
index c145bdf..26698cd 100644
--- a/sysutil.h
+++ b/sysutil.h
@@ -92,6 +92,7 @@ int vsf_sysutil_create_or_open_file_append(const char* p_filename,
int vsf_sysutil_create_or_open_file(const char* p_filename, unsigned int mode);
void vsf_sysutil_dupfd2(int old_fd, int new_fd);
void vsf_sysutil_close(int fd);
+int vsf_sysutil_close_errno(int fd);
int vsf_sysutil_close_failok(int fd);
int vsf_sysutil_unlink(const char* p_dead);
int vsf_sysutil_write_access(const char* p_filename);
--
2.5.0