1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
Description: Restrict upload and download of files to certain name patterns.
Author: Thomas B. Preußer <thomas.preusser@utexas.edu>
Last-Update: 2015-12-21
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
===================================================================
Index: access.c
access.h
parseconf.c
postlogin.c
tunables.c
tunables.h
vsftpd.conf.5
Index: vsftpd-3.0.5/access.c
===================================================================
--- vsftpd-3.0.5.orig/access.c
+++ vsftpd-3.0.5/access.c
@@ -12,11 +12,27 @@
#include "tunables.h"
#include "str.h"
+static int
+vsf_match_filter(struct mystr const *const p_filename_str,
+ struct mystr const *const p_access_str) {
+
+ unsigned iters = 0;
+ if (vsf_filename_passes_filter(p_filename_str, p_access_str, &iters))
+ {
+ return 1;
+ }
+ else
+ {
+ struct str_locate_result const loc_res =
+ str_locate_str(p_filename_str, p_access_str);
+ return loc_res.found;
+ }
+}
+
int
vsf_access_check_file(const struct mystr* p_filename_str)
{
static struct mystr s_access_str;
- unsigned int iters = 0;
if (!tunable_deny_file)
{
@@ -26,27 +42,21 @@ vsf_access_check_file(const struct mystr
{
str_alloc_text(&s_access_str, tunable_deny_file);
}
- if (vsf_filename_passes_filter(p_filename_str, &s_access_str, &iters))
+
+ if (vsf_match_filter(p_filename_str, &s_access_str))
{
return 0;
}
else
{
- struct str_locate_result loc_res =
- str_locate_str(p_filename_str, &s_access_str);
- if (loc_res.found)
- {
- return 0;
- }
+ return 1;
}
- return 1;
}
int
vsf_access_check_file_visible(const struct mystr* p_filename_str)
{
static struct mystr s_access_str;
- unsigned int iters = 0;
if (!tunable_hide_file)
{
@@ -56,19 +66,47 @@ vsf_access_check_file_visible(const stru
{
str_alloc_text(&s_access_str, tunable_hide_file);
}
- if (vsf_filename_passes_filter(p_filename_str, &s_access_str, &iters))
+
+ if (vsf_match_filter(p_filename_str, &s_access_str))
{
return 0;
}
else
{
- struct str_locate_result loc_res =
- str_locate_str(p_filename_str, &s_access_str);
- if (loc_res.found)
- {
- return 0;
- }
+ return 1;
+ }
+}
+
+int
+vsf_access_check_file_upload(const struct mystr* p_filename_str)
+{
+ static struct mystr s_access_str;
+
+ if (!tunable_upload_file)
+ {
+ return 1;
+ }
+ if (str_isempty(&s_access_str))
+ {
+ str_alloc_text(&s_access_str, tunable_upload_file);
}
- return 1;
+
+ return vsf_match_filter(p_filename_str, &s_access_str);
}
+int
+vsf_access_check_file_download(const struct mystr* p_filename_str)
+{
+ static struct mystr s_access_str;
+
+ if (!tunable_download_file)
+ {
+ return 1;
+ }
+ if (str_isempty(&s_access_str))
+ {
+ str_alloc_text(&s_access_str, tunable_download_file);
+ }
+
+ return vsf_match_filter(p_filename_str, &s_access_str);
+}
Index: vsftpd-3.0.5/access.h
===================================================================
--- vsftpd-3.0.5.orig/access.h
+++ vsftpd-3.0.5/access.h
@@ -25,5 +25,27 @@ int vsf_access_check_file(const struct m
*/
int vsf_access_check_file_visible(const struct mystr* p_filename_str);
+/* vsf_access_check_file_upload()
+ * PURPOSE
+ * Check whether the current session has permission to upload a file
+ * using the given filename.
+ * PARAMETERS
+ * p_filename_str - the filename to check upload permission for
+ * RETURNS
+ * Returns 1 if the file may be uploaded, otherwise 0.
+ */
+int vsf_access_check_file_upload(const struct mystr* p_filename_str);
+
+/* vsf_access_check_file_download()
+ * PURPOSE
+ * Check whether the current session has permission to download a file
+ * with the given filename.
+ * PARAMETERS
+ * p_filename_str - the filename to check download permission for
+ * RETURNS
+ * Returns 1 if the file may be downloaded, otherwise 0.
+ */
+int vsf_access_check_file_download(const struct mystr* p_filename_str);
+
#endif /* VSF_ACCESS_H */
Index: vsftpd-3.0.5/parseconf.c
===================================================================
--- vsftpd-3.0.5.orig/parseconf.c
+++ vsftpd-3.0.5/parseconf.c
@@ -174,6 +174,8 @@ parseconf_str_array[] =
{ "cmds_allowed", &tunable_cmds_allowed },
{ "hide_file", &tunable_hide_file },
{ "deny_file", &tunable_deny_file },
+ { "upload_file", &tunable_upload_file },
+ { "download_file", &tunable_download_file },
{ "user_sub_token", &tunable_user_sub_token },
{ "email_password_file", &tunable_email_password_file },
{ "rsa_cert_file", &tunable_rsa_cert_file },
Index: vsftpd-3.0.5/postlogin.c
===================================================================
--- vsftpd-3.0.5.orig/postlogin.c
+++ vsftpd-3.0.5/postlogin.c
@@ -671,7 +671,8 @@ handle_retr(struct vsf_session* p_sess,
vsf_log_start_entry(p_sess, kVSFLogEntryDownload);
str_copy(&p_sess->log_str, &p_sess->ftp_arg_str);
prepend_path_to_filename(&p_sess->log_str);
- if (!vsf_access_check_file(&p_sess->ftp_arg_str))
+ if (!vsf_access_check_file(&p_sess->ftp_arg_str) ||
+ !vsf_access_check_file_download(&p_sess->ftp_arg_str))
{
vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
return;
@@ -1040,7 +1041,8 @@ handle_upload_common(struct vsf_session*
vsf_log_start_entry(p_sess, kVSFLogEntryUpload);
str_copy(&p_sess->log_str, &p_sess->ftp_arg_str);
prepend_path_to_filename(&p_sess->log_str);
- if (!vsf_access_check_file(p_filename))
+ if (!vsf_access_check_file(p_filename) ||
+ !vsf_access_check_file_upload(p_filename))
{
vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
return;
Index: vsftpd-3.0.5/tunables.c
===================================================================
--- vsftpd-3.0.5.orig/tunables.c
+++ vsftpd-3.0.5/tunables.c
@@ -138,6 +138,8 @@ const char* tunable_cmds_allowed;
const char* tunable_cmds_denied;
const char* tunable_hide_file;
const char* tunable_deny_file;
+const char* tunable_upload_file;
+const char* tunable_download_file;
const char* tunable_user_sub_token;
const char* tunable_email_password_file;
const char* tunable_rsa_cert_file;
@@ -287,6 +289,8 @@ tunables_load_defaults()
install_str_setting(0, &tunable_cmds_denied);
install_str_setting(0, &tunable_hide_file);
install_str_setting(0, &tunable_deny_file);
+ install_str_setting(0, &tunable_upload_file);
+ install_str_setting(0, &tunable_download_file);
install_str_setting(0, &tunable_user_sub_token);
install_str_setting("/etc/vsftpd.email_passwords",
&tunable_email_password_file);
Index: vsftpd-3.0.5/tunables.h
===================================================================
--- vsftpd-3.0.5.orig/tunables.h
+++ vsftpd-3.0.5/tunables.h
@@ -140,6 +140,8 @@ extern const char* tunable_listen_addres
extern const char* tunable_cmds_allowed;
extern const char* tunable_hide_file;
extern const char* tunable_deny_file;
+extern const char* tunable_upload_file;
+extern const char* tunable_download_file;
extern const char* tunable_user_sub_token;
extern const char* tunable_email_password_file;
extern const char* tunable_rsa_cert_file;
Index: vsftpd-3.0.5/vsftpd.conf.5
===================================================================
--- vsftpd-3.0.5.orig/vsftpd.conf.5
+++ vsftpd-3.0.5/vsftpd.conf.5
@@ -871,6 +871,16 @@ Example: deny_file={*.mp3,*.mov,.private
Default: (none)
.TP
+.B download_file
+This option may be set to restrict downloads to files with names matching the
+specified pattern. If a filename also matches the
+.BR deny_file
+pattern, the denial takes precedence. For usage and pattern details, see the
+.BR deny_file
+option.
+
+Default: (none)
+.TP
.B dsa_cert_file
This option specifies the location of the DSA certificate to use for SSL
encrypted connections.
@@ -1012,6 +1022,16 @@ incoming handshakes matches this value.
Default: (none)
.TP
+.B upload_file
+This option may be set to restrict uploads to files with names matching the
+specified pattern. If a filename also matches the
+.BR deny_file
+pattern, the denial takes precedence. For usage and pattern details, see the
+.BR deny_file
+option.
+
+Default: (none)
+.TP
.B user_config_dir
This powerful option allows the override of any config option specified in
the manual page, on a per-user basis. Usage is simple, and is best illustrated
|