2 Nov 2010 16:21
SFTP subsystem and umask
Rob C <candland <at> xmission.com>
2010-11-02 15:21:18 GMT
2010-11-02 15:21:18 GMT
Hello,
I have noticed that the -u parameter to the sftp-server or internal-sftp subsystem is not working
correctly. For openssh-5.6p1 I believe that the problem lies in this code, starting at line 1414 in sftp-server.c:
----------------------------------------------------------
case 'u':
mask = (mode_t)strtonum(optarg, 0, 0777, &errmsg);
if (errmsg != NULL)
fatal("Invalid umask \"%s\": %s",
optarg, errmsg);
(void)umask(mask);
break;
----------------------------------------------------------
I think that adherence to strtonum() in this instance causes unexpected results due to "mask" being set to
decimal/base 10.
For example, say you had the following in sshd_config:
Subsystem sftp /usr/local/libexec/sftp-server -u 022
Then say you upload a file with permissions of 777 via sftp -p, you would expect the uploaded file to end up
with permission of 755, right? In this case you get a file with permissions of 751 or -rwxr-x--x. Why?
I believe it is because decimal 22 == octal 026. Further compounding the problem is that sftp-server
doggedly insists upon accepting permissions from the sftp client before it applies umask.
To test, set the following in your sshd_config:
Subsystem sftp /your/path/to/sftp-server -u 18
Then kill -HUP sshd and create a file on the client with permissions of 777. Upload the file via sftp -p and
(Continue reading)
RSS Feed