Package: sshfs
Version: 2.2-1

I ran into this problem when testing if sshfs could be used to mount
the home directory of users.

The problem is simply that the client umask is not used as is, but
seem to be combined with the ssh server umask.  This give unexpected
results.

Here is a program demonstrating the problem.


#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

mode_t touch_get_mode(const char *name, mode_t mode) {
  mode_t retval = 0;
  int fd = open(name, O_RDWR|O_CREAT|O_LARGEFILE, mode);
  if (-1 != fd) {
    unlink(name);
    struct stat statbuf;
    if (-1 != fstat(fd, &statbuf)) {
      retval = statbuf.st_mode & 0x1ff;
    }
    close(fd);
  }
  return retval;
}

/* Try to detect problem discovered using sshfs */
int test_umask(void) {
  printf("info: testing umask effect on file creation\n");

  mode_t orig_umask = umask(000);
  mode_t newmode;
  if (0666 != (newmode = touch_get_mode("foobar", 0666))) {
    printf("  error: Wrong file mode %o when creating using mode 666 and umask 
000\n",
           newmode);
  }
  umask(007);
  if (0660 != (newmode = touch_get_mode("foobar", 0666))) {
    printf("  error: Wrong file mode %o when creating using mode 666 and umask 
007\n",
           newmode);
  }

  umask (orig_umask);
  return 0;
}

int main(int argc, char **argv) {
  test_umask();
  return 0;
}


On a system where everything is OK, this is printed:

  info: testing umask effect on file creation

When working on a sshfs file system, this is printed:

  info: testing umask effect on file creation
    error: Wrong file mode 644 when creating using mode 666 and umask 000
    error: Wrong file mode 640 when creating using mode 666 and umask 007

I suspect this can be solved by using umask(0) on the server before
handling any file system requests.

Happy hacking,
-- 
Petter Reinholdtsen



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to