|
Jakub Jelen |
132f8f |
diff -up openssh-6.8p1/sftp-server.8.sftp-force-mode openssh-6.8p1/sftp-server.8
|
|
Jakub Jelen |
132f8f |
--- openssh-6.8p1/sftp-server.8.sftp-force-mode 2015-03-17 06:49:20.000000000 +0100
|
|
Jakub Jelen |
132f8f |
+++ openssh-6.8p1/sftp-server.8 2015-03-18 13:18:05.898306477 +0100
|
|
Jakub Jelen |
132f8f |
@@ -38,6 +38,7 @@
|
|
Jakub Jelen |
558fb7 |
.Op Fl P Ar blacklisted_requests
|
|
Jakub Jelen |
558fb7 |
.Op Fl p Ar whitelisted_requests
|
|
Jakub Jelen |
558fb7 |
.Op Fl u Ar umask
|
|
Jakub Jelen |
558fb7 |
+.Op Fl m Ar force_file_perms
|
|
Jakub Jelen |
558fb7 |
.Ek
|
|
Jakub Jelen |
558fb7 |
.Nm
|
|
Jakub Jelen |
558fb7 |
.Fl Q Ar protocol_feature
|
|
Jakub Jelen |
132f8f |
@@ -138,6 +139,10 @@ Sets an explicit
|
|
Jakub Jelen |
558fb7 |
.Xr umask 2
|
|
Jakub Jelen |
558fb7 |
to be applied to newly-created files and directories, instead of the
|
|
Jakub Jelen |
558fb7 |
user's default mask.
|
|
Jakub Jelen |
558fb7 |
+.It Fl m Ar force_file_perms
|
|
Jakub Jelen |
558fb7 |
+Sets explicit file permissions to be applied to newly-created files instead
|
|
Jakub Jelen |
558fb7 |
+of the default or client requested mode. Numeric values include:
|
|
Jakub Jelen |
558fb7 |
+777, 755, 750, 666, 644, 640, etc. Option -u is ineffective if -m is set.
|
|
Jakub Jelen |
558fb7 |
.El
|
|
Jakub Jelen |
558fb7 |
.Pp
|
|
Jakub Jelen |
558fb7 |
On some systems,
|
|
Jakub Jelen |
132f8f |
diff -up openssh-6.8p1/sftp-server.c.sftp-force-mode openssh-6.8p1/sftp-server.c
|
|
Jakub Jelen |
132f8f |
--- openssh-6.8p1/sftp-server.c.sftp-force-mode 2015-03-18 13:18:05.883306513 +0100
|
|
Jakub Jelen |
132f8f |
+++ openssh-6.8p1/sftp-server.c 2015-03-18 13:18:36.697232193 +0100
|
|
Jakub Jelen |
132f8f |
@@ -70,6 +70,10 @@ struct sshbuf *oqueue;
|
|
Jakub Jelen |
558fb7 |
/* Version of client */
|
|
Jakub Jelen |
558fb7 |
static u_int version;
|
|
Jakub Jelen |
558fb7 |
|
|
Jakub Jelen |
558fb7 |
+/* Force file permissions */
|
|
Jakub Jelen |
558fb7 |
+int permforce = 0;
|
|
Jakub Jelen |
558fb7 |
+long permforcemode;
|
|
Jakub Jelen |
558fb7 |
+
|
|
Jakub Jelen |
558fb7 |
/* SSH2_FXP_INIT received */
|
|
Jakub Jelen |
558fb7 |
static int init_done;
|
|
Jakub Jelen |
558fb7 |
|
|
Jakub Jelen |
132f8f |
@@ -693,6 +697,10 @@ process_open(u_int32_t id)
|
|
Jakub Jelen |
132f8f |
debug3("request %u: open flags %d", id, pflags);
|
|
Jakub Jelen |
558fb7 |
flags = flags_from_portable(pflags);
|
|
Jakub Jelen |
132f8f |
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
|
|
Jakub Jelen |
558fb7 |
+ if (permforce == 1) { /* Force perm if -m is set */
|
|
Jakub Jelen |
558fb7 |
+ mode = permforcemode;
|
|
Jakub Jelen |
558fb7 |
+ (void)umask(0); /* so umask does not interfere */
|
|
Jakub Jelen |
558fb7 |
+ }
|
|
Jakub Jelen |
558fb7 |
logit("open \"%s\" flags %s mode 0%o",
|
|
Jakub Jelen |
558fb7 |
name, string_from_portable(pflags), mode);
|
|
Jakub Jelen |
558fb7 |
if (readonly &&
|
|
Jakub Jelen |
132f8f |
@@ -1495,7 +1503,7 @@ sftp_server_usage(void)
|
|
Jakub Jelen |
558fb7 |
fprintf(stderr,
|
|
Jakub Jelen |
558fb7 |
"usage: %s [-ehR] [-d start_directory] [-f log_facility] "
|
|
Jakub Jelen |
558fb7 |
"[-l log_level]\n\t[-P blacklisted_requests] "
|
|
Jakub Jelen |
558fb7 |
- "[-p whitelisted_requests] [-u umask]\n"
|
|
Jakub Jelen |
558fb7 |
+ "[-p whitelisted_requests] [-u umask] [-m force_file_perms]\n"
|
|
Jakub Jelen |
558fb7 |
" %s -Q protocol_feature\n",
|
|
Jakub Jelen |
558fb7 |
__progname, __progname);
|
|
Jakub Jelen |
558fb7 |
exit(1);
|
|
Jakub Jelen |
132f8f |
@@ -1520,7 +1528,7 @@ sftp_server_main(int argc, char **argv,
|
|
Jakub Jelen |
558fb7 |
pw = pwcopy(user_pw);
|
|
Jakub Jelen |
558fb7 |
|
|
Jakub Jelen |
558fb7 |
while (!skipargs && (ch = getopt(argc, argv,
|
|
Jakub Jelen |
558fb7 |
- "d:f:l:P:p:Q:u:cehR")) != -1) {
|
|
Jakub Jelen |
558fb7 |
+ "d:f:l:P:p:Q:u:m:cehR")) != -1) {
|
|
Jakub Jelen |
558fb7 |
switch (ch) {
|
|
Jakub Jelen |
558fb7 |
case 'Q':
|
|
Jakub Jelen |
558fb7 |
if (strcasecmp(optarg, "requests") != 0) {
|
|
Jakub Jelen |
132f8f |
@@ -1580,6 +1588,15 @@ sftp_server_main(int argc, char **argv,
|
|
Jakub Jelen |
558fb7 |
fatal("Invalid umask \"%s\"", optarg);
|
|
Jakub Jelen |
558fb7 |
(void)umask((mode_t)mask);
|
|
Jakub Jelen |
558fb7 |
break;
|
|
Jakub Jelen |
558fb7 |
+ case 'm':
|
|
Jakub Jelen |
558fb7 |
+ /* Force permissions on file received via sftp */
|
|
Jakub Jelen |
558fb7 |
+ permforce = 1;
|
|
Jakub Jelen |
558fb7 |
+ permforcemode = strtol(optarg, &cp, 8);
|
|
Jakub Jelen |
558fb7 |
+ if (permforcemode < 0 || permforcemode > 0777 ||
|
|
Jakub Jelen |
558fb7 |
+ *cp != '\0' || (permforcemode == 0 &&
|
|
Jakub Jelen |
558fb7 |
+ errno != 0))
|
|
Jakub Jelen |
558fb7 |
+ fatal("Invalid file mode \"%s\"", optarg);
|
|
Jakub Jelen |
558fb7 |
+ break;
|
|
Jakub Jelen |
558fb7 |
case 'h':
|
|
Jakub Jelen |
558fb7 |
default:
|
|
Jakub Jelen |
558fb7 |
sftp_server_usage();
|