|
|
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 |
|
|
|
f8987c |
@@ -668,6 +672,7 @@ process_open(u_int32_t id)
|
|
|
f8987c |
Attrib *a;
|
|
|
f8987c |
char *name;
|
|
|
f8987c |
int handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
|
|
f8987c |
+ mode_t old_umask;
|
|
|
f8987c |
|
|
|
f8987c |
name = get_string(NULL);
|
|
|
f8987c |
pflags = get_int(); /* portable flags */
|
|
|
f8987c |
@@ -675,6 +680,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;
|
|
|
f8987c |
+ old_umask = umask(0); /* so umask does not interfere */
|
|
|
f8987c |
+ }
|
|
|
674526 |
logit("open \"%s\" flags %s mode 0%o",
|
|
|
674526 |
name, string_from_portable(pflags), mode);
|
|
|
674526 |
if (readonly &&
|
|
|
f8987c |
@@ -696,6 +705,8 @@ process_open(u_int32_t id)
|
|
|
f8987c |
}
|
|
|
f8987c |
}
|
|
|
f8987c |
}
|
|
|
f8987c |
+ if (permforce == 1)
|
|
|
f8987c |
+ (void) umask(old_umask); /* restore umask to something sane */
|
|
|
f8987c |
if (status != SSH2_FX_OK)
|
|
|
f8987c |
send_status(id, status);
|
|
|
f8987c |
free(name);
|
|
|
f8987c |
@@ -1430,7 +1441,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();
|