|
Lines 66-71
struct sshbuf *oqueue;
Link Here
|
| 66 |
/* Version of client */ |
66 |
/* Version of client */ |
| 67 |
static u_int version; |
67 |
static u_int version; |
| 68 |
|
68 |
|
|
|
69 |
/* Force file permissions */ |
| 70 |
int permforce = 0; |
| 71 |
long permforcemode; |
| 72 |
|
| 69 |
/* SSH2_FXP_INIT received */ |
73 |
/* SSH2_FXP_INIT received */ |
| 70 |
static int init_done; |
74 |
static int init_done; |
| 71 |
|
75 |
|
|
Lines 680-685
process_open(u_int32_t id)
Link Here
|
| 680 |
Attrib a; |
684 |
Attrib a; |
| 681 |
char *name; |
685 |
char *name; |
| 682 |
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE; |
686 |
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE; |
|
|
687 |
mode_t old_umask = 0; |
| 683 |
|
688 |
|
| 684 |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
689 |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
| 685 |
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */ |
690 |
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */ |
|
Lines 689-694
process_open(u_int32_t id)
Link Here
|
| 689 |
debug3("request %u: open flags %d", id, pflags); |
694 |
debug3("request %u: open flags %d", id, pflags); |
| 690 |
flags = flags_from_portable(pflags); |
695 |
flags = flags_from_portable(pflags); |
| 691 |
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666; |
696 |
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666; |
|
|
697 |
if (permforce == 1) { /* Force perm if -m is set */ |
| 698 |
mode = permforcemode; |
| 699 |
old_umask = umask(0); /* so umask does not interfere */ |
| 700 |
} |
| 692 |
logit("open \"%s\" flags %s mode 0%o", |
701 |
logit("open \"%s\" flags %s mode 0%o", |
| 693 |
name, string_from_portable(pflags), mode); |
702 |
name, string_from_portable(pflags), mode); |
| 694 |
if (readonly && |
703 |
if (readonly && |
|
Lines 710-715
process_open(u_int32_t id)
Link Here
|
| 710 |
} |
719 |
} |
| 711 |
} |
720 |
} |
| 712 |
} |
721 |
} |
|
|
722 |
if (permforce == 1) |
| 723 |
(void) umask(old_umask); /* restore umask to something sane */ |
| 713 |
if (status != SSH2_FX_OK) |
724 |
if (status != SSH2_FX_OK) |
| 714 |
send_status(id, status); |
725 |
send_status(id, status); |
| 715 |
free(name); |
726 |
free(name); |
|
Lines 1491-1497
sftp_server_usage(void)
Link Here
|
| 1491 |
fprintf(stderr, |
1502 |
fprintf(stderr, |
| 1492 |
"usage: %s [-ehR] [-d start_directory] [-f log_facility] " |
1503 |
"usage: %s [-ehR] [-d start_directory] [-f log_facility] " |
| 1493 |
"[-l log_level]\n\t[-P blacklisted_requests] " |
1504 |
"[-l log_level]\n\t[-P blacklisted_requests] " |
| 1494 |
"[-p whitelisted_requests] [-u umask]\n" |
1505 |
"[-p whitelisted_requests] [-u umask] [-m force_file_perms]\n" |
| 1495 |
" %s -Q protocol_feature\n", |
1506 |
" %s -Q protocol_feature\n", |
| 1496 |
__progname, __progname); |
1507 |
__progname, __progname); |
| 1497 |
exit(1); |
1508 |
exit(1); |
|
Lines 1517-1523
sftp_server_main(int argc, char **argv, struct passwd *user_pw)
Link Here
|
| 1517 |
pw = pwcopy(user_pw); |
1528 |
pw = pwcopy(user_pw); |
| 1518 |
|
1529 |
|
| 1519 |
while (!skipargs && (ch = getopt(argc, argv, |
1530 |
while (!skipargs && (ch = getopt(argc, argv, |
| 1520 |
"d:f:l:P:p:Q:u:cehR")) != -1) { |
1531 |
"d:f:l:P:p:Q:u:m:cehR")) != -1) { |
| 1521 |
switch (ch) { |
1532 |
switch (ch) { |
| 1522 |
case 'Q': |
1533 |
case 'Q': |
| 1523 |
if (strcasecmp(optarg, "requests") != 0) { |
1534 |
if (strcasecmp(optarg, "requests") != 0) { |
|
Lines 1577-1582
sftp_server_main(int argc, char **argv, struct passwd *user_pw)
Link Here
|
| 1577 |
fatal("Invalid umask \"%s\"", optarg); |
1588 |
fatal("Invalid umask \"%s\"", optarg); |
| 1578 |
(void)umask((mode_t)mask); |
1589 |
(void)umask((mode_t)mask); |
| 1579 |
break; |
1590 |
break; |
|
|
1591 |
case 'm': |
| 1592 |
/* Force permissions on file received via sftp */ |
| 1593 |
permforce = 1; |
| 1594 |
permforcemode = strtol(optarg, &cp, 8); |
| 1595 |
if (permforcemode < 0 || permforcemode > 0777 || |
| 1596 |
*cp != '\0' || (permforcemode == 0 && |
| 1597 |
errno != 0)) |
| 1598 |
fatal("Invalid file mode \"%s\"", optarg); |
| 1599 |
break; |
| 1580 |
case 'h': |
1600 |
case 'h': |
| 1581 |
default: |
1601 |
default: |
| 1582 |
sftp_server_usage(); |
1602 |
sftp_server_usage(); |