2016-06-23 14:23:32 +00:00
|
|
|
diff -up openssh-7.2p2/sftp-server.8.sftp-force-mode openssh-7.2p2/sftp-server.8
|
|
|
|
--- openssh-7.2p2/sftp-server.8.sftp-force-mode 2016-03-09 19:04:48.000000000 +0100
|
|
|
|
+++ openssh-7.2p2/sftp-server.8 2016-06-23 16:18:20.463854117 +0200
|
2015-03-20 13:56:04 +00:00
|
|
|
@@ -38,6 +38,7 @@
|
2015-03-11 16:16:54 +00:00
|
|
|
.Op Fl P Ar blacklisted_requests
|
|
|
|
.Op Fl p Ar whitelisted_requests
|
|
|
|
.Op Fl u Ar umask
|
|
|
|
+.Op Fl m Ar force_file_perms
|
|
|
|
.Ek
|
|
|
|
.Nm
|
|
|
|
.Fl Q Ar protocol_feature
|
2020-08-28 18:14:29 +00:00
|
|
|
@@ -138,6 +139,12 @@ Sets an explicit
|
2015-03-11 16:16:54 +00:00
|
|
|
.Xr umask 2
|
|
|
|
to be applied to newly-created files and directories, instead of the
|
|
|
|
user's default mask.
|
|
|
|
+.It Fl m Ar force_file_perms
|
|
|
|
+Sets explicit file permissions to be applied to newly-created files instead
|
|
|
|
+of the default or client requested mode. Numeric values include:
|
2020-08-28 18:14:29 +00:00
|
|
|
+777, 755, 750, 666, 644, 640, etc. Using both -m and -u switches makes the
|
|
|
|
+umask (-u) effective only for newly created directories and explicit mode (-m)
|
|
|
|
+for newly created files.
|
2015-03-11 16:16:54 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
On some systems,
|
2016-06-23 14:23:32 +00:00
|
|
|
diff -up openssh-7.2p2/sftp-server.c.sftp-force-mode openssh-7.2p2/sftp-server.c
|
|
|
|
--- openssh-7.2p2/sftp-server.c.sftp-force-mode 2016-06-23 16:18:20.446854128 +0200
|
|
|
|
+++ openssh-7.2p2/sftp-server.c 2016-06-23 16:20:37.950766082 +0200
|
|
|
|
@@ -69,6 +69,10 @@ struct sshbuf *oqueue;
|
2015-03-11 16:16:54 +00:00
|
|
|
/* Version of client */
|
|
|
|
static u_int version;
|
|
|
|
|
|
|
|
+/* Force file permissions */
|
|
|
|
+int permforce = 0;
|
|
|
|
+long permforcemode;
|
|
|
|
+
|
|
|
|
/* SSH2_FXP_INIT received */
|
|
|
|
static int init_done;
|
|
|
|
|
2016-06-23 14:23:32 +00:00
|
|
|
@@ -683,6 +687,7 @@ process_open(u_int32_t id)
|
|
|
|
Attrib a;
|
|
|
|
char *name;
|
|
|
|
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
2017-11-24 14:48:45 +00:00
|
|
|
+ mode_t old_umask = 0;
|
2016-06-23 14:23:32 +00:00
|
|
|
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 ||
|
|
|
|
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
|
|
|
|
@@ -692,6 +697,10 @@ process_open(u_int32_t id)
|
2015-03-20 13:56:04 +00:00
|
|
|
debug3("request %u: open flags %d", id, pflags);
|
2015-03-11 16:16:54 +00:00
|
|
|
flags = flags_from_portable(pflags);
|
2015-03-20 13:56:04 +00:00
|
|
|
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
|
2015-03-11 16:16:54 +00:00
|
|
|
+ if (permforce == 1) { /* Force perm if -m is set */
|
|
|
|
+ mode = permforcemode;
|
2016-06-23 14:23:32 +00:00
|
|
|
+ old_umask = umask(0); /* so umask does not interfere */
|
2015-03-11 16:16:54 +00:00
|
|
|
+ }
|
|
|
|
logit("open \"%s\" flags %s mode 0%o",
|
|
|
|
name, string_from_portable(pflags), mode);
|
|
|
|
if (readonly &&
|
2016-06-23 14:23:32 +00:00
|
|
|
@@ -713,6 +722,8 @@ process_open(u_int32_t id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ if (permforce == 1)
|
|
|
|
+ (void) umask(old_umask); /* restore umask to something sane */
|
|
|
|
if (status != SSH2_FX_OK)
|
|
|
|
send_status(id, status);
|
|
|
|
free(name);
|
|
|
|
@@ -1494,7 +1505,7 @@ sftp_server_usage(void)
|
2015-03-11 16:16:54 +00: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"
|
|
|
|
+ "[-p whitelisted_requests] [-u umask] [-m force_file_perms]\n"
|
|
|
|
" %s -Q protocol_feature\n",
|
|
|
|
__progname, __progname);
|
|
|
|
exit(1);
|
2016-06-23 14:23:32 +00:00
|
|
|
@@ -1520,7 +1531,7 @@ sftp_server_main(int argc, char **argv,
|
2015-03-11 16:16:54 +00: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) {
|
2016-06-23 14:23:32 +00:00
|
|
|
@@ -1580,6 +1591,15 @@ sftp_server_main(int argc, char **argv,
|
2015-03-11 16:16:54 +00:00
|
|
|
fatal("Invalid umask \"%s\"", optarg);
|
|
|
|
(void)umask((mode_t)mask);
|
|
|
|
break;
|
|
|
|
+ case 'm':
|
|
|
|
+ /* Force permissions on file received via sftp */
|
|
|
|
+ permforce = 1;
|
|
|
|
+ permforcemode = strtol(optarg, &cp, 8);
|
|
|
|
+ if (permforcemode < 0 || permforcemode > 0777 ||
|
|
|
|
+ *cp != '\0' || (permforcemode == 0 &&
|
|
|
|
+ errno != 0))
|
|
|
|
+ fatal("Invalid file mode \"%s\"", optarg);
|
|
|
|
+ break;
|
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
sftp_server_usage();
|