|
Jakub Jelen |
d8ffa9 |
diff -up openssh-7.2p2/sftp-server.8.sftp-force-mode openssh-7.2p2/sftp-server.8
|
|
Jakub Jelen |
d8ffa9 |
--- openssh-7.2p2/sftp-server.8.sftp-force-mode 2016-03-09 19:04:48.000000000 +0100
|
|
Jakub Jelen |
d8ffa9 |
+++ openssh-7.2p2/sftp-server.8 2016-06-23 16:18:20.463854117 +0200
|
|
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 |
d8ffa9 |
diff -up openssh-7.2p2/sftp-server.c.sftp-force-mode openssh-7.2p2/sftp-server.c
|
|
Jakub Jelen |
d8ffa9 |
--- openssh-7.2p2/sftp-server.c.sftp-force-mode 2016-06-23 16:18:20.446854128 +0200
|
|
Jakub Jelen |
d8ffa9 |
+++ openssh-7.2p2/sftp-server.c 2016-06-23 16:20:37.950766082 +0200
|
|
Jakub Jelen |
d8ffa9 |
@@ -69,6 +69,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 |
d8ffa9 |
@@ -683,6 +687,7 @@ process_open(u_int32_t id)
|
|
Jakub Jelen |
d8ffa9 |
Attrib a;
|
|
Jakub Jelen |
d8ffa9 |
char *name;
|
|
Jakub Jelen |
d8ffa9 |
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
|
Jakub Jelen |
d8ffa9 |
+ mode_t old_umask;
|
|
Jakub Jelen |
d8ffa9 |
|
|
Jakub Jelen |
d8ffa9 |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 ||
|
|
Jakub Jelen |
d8ffa9 |
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
|
|
Jakub Jelen |
d8ffa9 |
@@ -692,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 |
d8ffa9 |
+ old_umask = 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 |
d8ffa9 |
@@ -713,6 +722,8 @@ process_open(u_int32_t id)
|
|
Jakub Jelen |
d8ffa9 |
}
|
|
Jakub Jelen |
d8ffa9 |
}
|
|
Jakub Jelen |
d8ffa9 |
}
|
|
Jakub Jelen |
d8ffa9 |
+ if (permforce == 1)
|
|
Jakub Jelen |
d8ffa9 |
+ (void) umask(old_umask); /* restore umask to something sane */
|
|
Jakub Jelen |
d8ffa9 |
if (status != SSH2_FX_OK)
|
|
Jakub Jelen |
d8ffa9 |
send_status(id, status);
|
|
Jakub Jelen |
d8ffa9 |
free(name);
|
|
Jakub Jelen |
d8ffa9 |
@@ -1494,7 +1505,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 |
d8ffa9 |
@@ -1520,7 +1531,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 |
d8ffa9 |
@@ -1580,6 +1591,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();
|