2018-10-19 15:12:48 +02:00
|
|
|
--- original/sftp-server.8 2016-12-19 04:59:41.000000000 +0000
|
|
|
|
+++ original/sftp-server.8 2017-11-23 08:47:01.267239186 +0000
|
|
|
|
@@ -38,6 +38,7 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
.Op Fl P Ar blacklisted_requests
|
|
|
|
.Op Fl p Ar whitelisted_requests
|
|
|
|
.Op Fl u Ar umask
|
2018-10-19 15:12:48 +02:00
|
|
|
+.Op Fl m Ar force_file_dir_perms
|
2018-10-17 10:57:56 +02:00
|
|
|
.Ek
|
|
|
|
.Nm
|
|
|
|
.Fl Q Ar protocol_feature
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -138,6 +139,10 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
.Xr umask 2
|
|
|
|
to be applied to newly-created files and directories, instead of the
|
|
|
|
user's default mask.
|
2018-10-19 15:12:48 +02:00
|
|
|
+.It Fl m Ar force_file_dir_perms
|
|
|
|
+Sets explicit permissions to be applied to newly-created files and directories
|
|
|
|
+instead of the default or client requested mode. Numeric values include:
|
2018-10-17 10:57:56 +02:00
|
|
|
+777, 755, 750, 666, 644, 640, etc. Option -u is ineffective if -m is set.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
On some systems,
|
2018-10-19 15:12:48 +02:00
|
|
|
--- original/sftp-server.c 2016-12-19 04:59:41.000000000 +0000
|
|
|
|
+++ original/sftp-server.c 2017-11-23 13:07:08.481765581 +0000
|
|
|
|
@@ -65,6 +65,10 @@
|
|
|
|
/* Version of client */
|
|
|
|
static u_int version;
|
2018-10-17 10:57:56 +02:00
|
|
|
|
2018-10-19 15:12:48 +02:00
|
|
|
+/* Force file and directory permissions */
|
2018-10-17 10:57:56 +02:00
|
|
|
+int permforce = 0;
|
|
|
|
+long permforcemode;
|
|
|
|
+
|
2018-10-19 15:12:48 +02:00
|
|
|
/* SSH2_FXP_INIT received */
|
|
|
|
static int init_done;
|
2018-10-17 10:57:56 +02:00
|
|
|
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -679,6 +683,7 @@
|
|
|
|
Attrib a;
|
2018-10-17 10:57:56 +02:00
|
|
|
char *name;
|
2018-10-19 15:12:48 +02:00
|
|
|
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
|
|
|
+ mode_t old_umask = 0;
|
|
|
|
|
2018-10-17 10:57:56 +02:00
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 ||
|
|
|
|
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -688,6 +693,10 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
debug3("request %u: open flags %d", id, pflags);
|
|
|
|
flags = flags_from_portable(pflags);
|
|
|
|
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
|
2018-10-19 15:12:48 +02:00
|
|
|
+ if (permforce == 1) { /* Force perm if -m is set */
|
2018-10-17 10:57:56 +02:00
|
|
|
+ mode = permforcemode;
|
2018-10-19 15:12:48 +02:00
|
|
|
+ old_umask = umask(0); /* so umask does not interfere */
|
2018-10-17 10:57:56 +02:00
|
|
|
+ }
|
|
|
|
logit("open \"%s\" flags %s mode 0%o",
|
|
|
|
name, string_from_portable(pflags), mode);
|
|
|
|
if (readonly &&
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -709,6 +718,8 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ if (permforce == 1)
|
|
|
|
+ (void) umask(old_umask); /* restore umask to something sane */
|
|
|
|
if (status != SSH2_FX_OK)
|
|
|
|
send_status(id, status);
|
|
|
|
free(name);
|
|
|
|
@@ -1110,6 +1121,7 @@
|
|
|
|
Attrib a;
|
|
|
|
char *name;
|
|
|
|
int r, mode, status = SSH2_FX_FAILURE;
|
|
|
|
+ mode_t old_umask = 0;
|
2018-10-17 10:57:56 +02:00
|
|
|
|
2018-10-19 15:12:48 +02:00
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 ||
|
|
|
|
(r = decode_attrib(iqueue, &a)) != 0)
|
|
|
|
@@ -1117,9 +1129,16 @@
|
|
|
|
|
|
|
|
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
|
|
|
|
a.perm & 07777 : 0777;
|
|
|
|
+ if (permforce == 1) { /* Force perm if -m is set */
|
|
|
|
+ mode = permforcemode;
|
|
|
|
+ old_umask = umask(0); /* so umask does not interfere */
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
debug3("request %u: mkdir", id);
|
|
|
|
logit("mkdir name \"%s\" mode 0%o", name, mode);
|
|
|
|
r = mkdir(name, mode);
|
|
|
|
+ if (permforce == 1)
|
|
|
|
+ (void) umask(old_umask); /* restore umask to something sane */
|
|
|
|
status = (r == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
|
|
|
|
send_status(id, status);
|
|
|
|
free(name);
|
|
|
|
@@ -1490,7 +1509,7 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s [-ehR] [-d start_directory] [-f log_facility] "
|
|
|
|
"[-l log_level]\n\t[-P blacklisted_requests] "
|
|
|
|
- "[-p whitelisted_requests] [-u umask]\n"
|
2018-10-19 15:12:48 +02:00
|
|
|
+ "[-p whitelisted_requests] [-u umask] [-m force_file_dir_perms]\n"
|
2018-10-17 10:57:56 +02:00
|
|
|
" %s -Q protocol_feature\n",
|
|
|
|
__progname, __progname);
|
|
|
|
exit(1);
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -1516,7 +1535,7 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
pw = pwcopy(user_pw);
|
|
|
|
|
|
|
|
while (!skipargs && (ch = getopt(argc, argv,
|
|
|
|
- "d:f:l:P:p:Q:u:cehR")) != -1) {
|
|
|
|
+ "d:f:l:P:p:Q:u:m:cehR")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'Q':
|
|
|
|
if (strcasecmp(optarg, "requests") != 0) {
|
2018-10-19 15:12:48 +02:00
|
|
|
@@ -1576,6 +1595,15 @@
|
2018-10-17 10:57:56 +02:00
|
|
|
fatal("Invalid umask \"%s\"", optarg);
|
|
|
|
(void)umask((mode_t)mask);
|
|
|
|
break;
|
|
|
|
+ case 'm':
|
2018-10-19 15:12:48 +02:00
|
|
|
+ /* Force permissions on file and directory received via sftp */
|
2018-10-17 10:57:56 +02:00
|
|
|
+ permforce = 1;
|
|
|
|
+ permforcemode = strtol(optarg, &cp, 8);
|
2018-10-19 15:12:48 +02:00
|
|
|
+ if (permforcemode < 0 || permforcemode > 0777 ||
|
|
|
|
+ *cp != '\0' || (permforcemode == 0 &&
|
|
|
|
+ errno != 0))
|
|
|
|
+ fatal("Invalid file mode \"%s\"", optarg);
|
2018-10-17 10:57:56 +02:00
|
|
|
+ break;
|
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
sftp_server_usage();
|