|
|
674526 |
diff -up openssh-6.6p1/sftp-server.8.sftp-force-mode openssh-6.6p1/sftp-server.8
|
|
|
674526 |
--- openssh-6.6p1/sftp-server.8.sftp-force-mode 2013-10-15 03:07:05.000000000 +0200
|
|
|
674526 |
+++ openssh-6.6p1/sftp-server.8 2015-04-20 14:04:47.427562510 +0200
|
|
|
674526 |
@@ -38,6 +38,7 @@
|
|
|
674526 |
.Op Fl P Ar blacklisted_requests
|
|
|
674526 |
.Op Fl p Ar whitelisted_requests
|
|
|
674526 |
.Op Fl u Ar umask
|
|
|
674526 |
+.Op Fl m Ar force_file_perms
|
|
|
674526 |
.Ek
|
|
|
674526 |
.Nm
|
|
|
674526 |
.Fl Q Ar protocol_feature
|
|
|
674526 |
@@ -138,6 +139,10 @@ Sets an explicit
|
|
|
674526 |
.Xr umask 2
|
|
|
674526 |
to be applied to newly-created files and directories, instead of the
|
|
|
674526 |
user's default mask.
|
|
|
674526 |
+.It Fl m Ar force_file_perms
|
|
|
674526 |
+Sets explicit file permissions to be applied to newly-created files instead
|
|
|
674526 |
+of the default or client requested mode. Numeric values include:
|
|
|
674526 |
+777, 755, 750, 666, 644, 640, etc. Option -u is ineffective if -m is set.
|
|
|
674526 |
.El
|
|
|
674526 |
.Pp
|
|
|
674526 |
For logging to work,
|
|
|
674526 |
diff -up openssh-6.6p1/sftp-server.c.sftp-force-mode openssh-6.6p1/sftp-server.c
|
|
|
674526 |
--- openssh-6.6p1/sftp-server.c.sftp-force-mode 2015-04-20 14:04:47.420562526 +0200
|
|
|
674526 |
+++ openssh-6.6p1/sftp-server.c 2015-04-20 14:07:13.799231025 +0200
|
|
|
674526 |
@@ -71,6 +71,10 @@ static Buffer oqueue;
|
|
|
674526 |
/* Version of client */
|
|
|
674526 |
static u_int version;
|
|
|
674526 |
|
|
|
674526 |
+/* Force file permissions */
|
|
|
674526 |
+int permforce = 0;
|
|
|
674526 |
+long permforcemode;
|
|
|
674526 |
+
|
|
|
674526 |
/* SSH2_FXP_INIT received */
|
|
|
674526 |
static int init_done;
|
|
|
674526 |
|
|
|
674526 |
@@ -675,6 +679,10 @@ process_open(u_int32_t id)
|
|
|
674526 |
a = get_attrib();
|
|
|
674526 |
flags = flags_from_portable(pflags);
|
|
|
674526 |
mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
|
|
|
674526 |
+ if (permforce == 1) { /* Force perm if -m is set */
|
|
|
674526 |
+ mode = permforcemode;
|
|
|
674526 |
+ (void)umask(0); /* so umask does not interfere */
|
|
|
674526 |
+ }
|
|
|
674526 |
logit("open \"%s\" flags %s mode 0%o",
|
|
|
674526 |
name, string_from_portable(pflags), mode);
|
|
|
674526 |
if (readonly &&
|
|
|
674526 |
@@ -1430,7 +1438,7 @@ sftp_server_usage(void)
|
|
|
674526 |
fprintf(stderr,
|
|
|
674526 |
"usage: %s [-ehR] [-d start_directory] [-f log_facility] "
|
|
|
674526 |
"[-l log_level]\n\t[-P blacklisted_requests] "
|
|
|
674526 |
- "[-p whitelisted_requests] [-u umask]\n"
|
|
|
674526 |
+ "[-p whitelisted_requests] [-u umask] [-m force_file_perms]\n"
|
|
|
674526 |
" %s -Q protocol_feature\n",
|
|
|
674526 |
__progname, __progname);
|
|
|
674526 |
exit(1);
|
|
|
674526 |
@@ -1455,7 +1463,7 @@ sftp_server_main(int argc, char **argv,
|
|
|
674526 |
pw = pwcopy(user_pw);
|
|
|
674526 |
|
|
|
674526 |
while (!skipargs && (ch = getopt(argc, argv,
|
|
|
674526 |
- "d:f:l:P:p:Q:u:cehR")) != -1) {
|
|
|
674526 |
+ "d:f:l:P:p:Q:u:m:cehR")) != -1) {
|
|
|
674526 |
switch (ch) {
|
|
|
674526 |
case 'Q':
|
|
|
674526 |
if (strcasecmp(optarg, "requests") != 0) {
|
|
|
674526 |
@@ -1515,6 +1523,15 @@ sftp_server_main(int argc, char **argv,
|
|
|
674526 |
fatal("Invalid umask \"%s\"", optarg);
|
|
|
674526 |
(void)umask((mode_t)mask);
|
|
|
674526 |
break;
|
|
|
674526 |
+ case 'm':
|
|
|
674526 |
+ /* Force permissions on file received via sftp */
|
|
|
674526 |
+ permforce = 1;
|
|
|
674526 |
+ permforcemode = strtol(optarg, &cp, 8);
|
|
|
674526 |
+ if (permforcemode < 0 || permforcemode > 0777 ||
|
|
|
674526 |
+ *cp != '\0' || (permforcemode == 0 &&
|
|
|
674526 |
+ errno != 0))
|
|
|
674526 |
+ fatal("Invalid file mode \"%s\"", optarg);
|
|
|
674526 |
+ break;
|
|
|
674526 |
case 'h':
|
|
|
674526 |
default:
|
|
|
674526 |
sftp_server_usage();
|