8

I have a Windows 7 host, with a CentOS 6 guest under VirtualBox.

I have a Windows directory shared with the Linux guest using CIFS.

Everything worked fine so far, until I realized that all chmod operations yield:

chmod: changing permissions of `x': Operation not permitted

This is understandable, but my problem is that some tools I have no control on, attempt to chmod files for me, and fail as a result.

Is it possible to allow but ignore all chmod() calls on a CIFS mount? Please note than these calls are made from a programming language and not from the command-line chmod utility.

Edit: the manual for mount.cifs says (emphasize mine):

The core CIFS protocol does not provide unix ownership information or mode for files and directories. Because of this, files and directories will generally appear to be owned by whatever values the uid= or gid= options are set, and will have permissions set to the default file_mode and dir_mode for the mount. Attempting to change these values via chmod/chown will return success but have no effect.

That's exactly the behaviour I'm after then, so why is it not working for me?

BenMorel
  • 905
  • 4
  • 13
  • 33
  • Please could you clarify **what** programming language, and what you are actually trying to achieve with the *programming* language. *Allow* but *ignore* on the face of it seems to be contradictory. With further background will help us provide insight into your problem. – David Apr 21 '14 at 21:55
  • I don't think you can get all permissions modifications to be ignored . . . does the script actually bail out when the file permissions are modified, or does it bail out later as the permissions are not sufficient? If they're not sufficient, you could use mount options (file_mode and dir_mode) to set all the files to have the permissions you need . . . – ernie Apr 22 '14 at 00:21
  • @David Again I don't have control over the tool, which I believe is programmed in C, and makes calls to the system's `chmod()` function. @ernie It bails out when the file permissions are (trying to be) modified, and does not complete. – BenMorel Apr 22 '14 at 06:31
  • For information, I'm trying to install a [PEAR](http://pear.php.net/) package for PHP over [Composer](https://getcomposer.org/), and the script fails because its [PHAR](http://www.php.net/manual/en/book.phar.php) package installer tries to `chmod()` some files. The exact error is: *Extraction from phar "..." failed: Cannot extract "package.xml" to "...", setting file permissions failed*. – BenMorel Apr 22 '14 at 06:35
  • Thanks, this was the background that we where looking for. Can you add additional permissions on your Windows system to permit what is happening in the install script? It sounds almost as though the script is trying to set something to executable, which just may not work on a windows share. – David Apr 22 '14 at 09:17
  • @David I don't know what to try or how to do this, that's precisely why I'm asking the question :) – BenMorel Apr 22 '14 at 11:30
  • What is your mount command? – David Apr 22 '14 at 22:25
  • @David here is the `fstab` entry: `//192.168.56.1/www /mnt/www cifs username=www,password=xxx,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0` – BenMorel Apr 22 '14 at 22:52

2 Answers2

14

Found it: the noperm mount parameter does exactly this:

//192.168.56.1/www /mnt/www cifs noperm,username=www,password=xxx, ...

Note that mount -a does not apply the parameter, you have to reboot to make it work.
It took me a lot of trial and error to figure this out.

Now chmod works fine, the command does not yield any error, and is just ignored.

BenMorel
  • 905
  • 4
  • 13
  • 33
  • 2
    Why reboot when you can just unmount and mount again? Maybe CIFS can even remount. – Daniel B Apr 25 '14 at 11:44
  • Shouldn't `mount -a` unmount and remount as well? – BenMorel Apr 25 '14 at 11:50
  • No. That would be fatal. It only mounts currently unmounted filesystems from `/etc/fstab` – Daniel B Apr 25 '14 at 12:41
  • This fixed the problem I was having using python's `shutil.copytree(src,dst)` where `dst` is on a CIFS mount. Internally, `shutil`'s low-level copy function does a `chmod` on `dst` after the copy. The solution here is much preferred to catching and ignoring the `[Errno 1] Operation not permitted` that python was producing. – Arthur Hebert-Ryan Dec 18 '19 at 18:35
  • Thanks this worked great for a program that was out of my control trying to change permissions on a CIFS mount – rwarner Sep 22 '21 at 21:46
0

Try adding exec option. I believe mounting as a non-root user will turn off exec.

https://unix.stackexchange.com/questions/34822/is-it-possible-to-enable-execution-of-files-from-a-cifs-mount-in-bash

David
  • 2,302
  • 13
  • 26
  • Same thing I'm afraid with `exec`: *operation not permitted*. – BenMorel Apr 24 '14 at 13:02
  • try mounting as root? – David Apr 24 '14 at 22:17
  • Well, looking at a couple further articles, you can not chmod +x to a file on a windows share. You have marked all the files as executable by using using the option `file_mode=0777` anyway. I would suggest installing the pear module on a folder in the linux file system, then copy it over. – David Apr 24 '14 at 22:24
  • http://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition http://superuser.com/questions/624368/how-to-chmod-x-a-file-in-windows-for-use-in-linux – David Apr 24 '14 at 22:25