当我在linux中创建文件时,组所有者变成创建文件的进程的gid。如果我将SGID添加到父目录文件中,则将继承父目录所有者组。此外,我还可以更改fs挂载选项,使其行为类似于sys5或BSD。
如果我想选择这个选项而不管目录权限和fs挂载选项如何?是否有c函数选项或syscall参数允许您选择组所有者?
$ find . -ls
262 4 drwxrwxr-x 4 devops devops 4096 Apr 24 18:01 .
999 4 drwxrwxr-x 2 devops root 4096 Apr 24 18:03 ./dir1
6093 4 drwxrwsr-x 2 devops root 4096 Apr 24 18:03 ./dir2
$ touch dir1/file dir2/file
$ find . -ls
262 4 drwxrwxr-x 4 devops devops 4096 Apr 24 18:01 .
999 4 drwxrwxr-x 2 devops root 4096 Apr 24 18:04 ./dir1
5576 0 -rw-rw-r-- 1 devops devops 0 Apr 24 18:04 ./dir1/file
6093 4 drwxrwsr-x 2 devops root 4096 Apr 24 18:04 ./dir2
6094 0 -rw-rw-r-- 1 devops root 0 Apr 24 18:04 ./dir2/file
$
我希望有这样的东西:
$ mytouch -s BSD dir1/file1
$ mytouch -s sys5 dir1/file2
$ find dir1 -ls
999 4 drwxrwxr-x 2 devops root 4096 Apr 24 18:10 dir1
6213 0 -rw-rw-r-- 1 devops root 0 Apr 24 18:10 dir1/file1
6214 0 -rw-rw-r-- 1 devops devops 0 Apr 24 18:10 dir1/file2
$
发布于 2017-04-24 23:22:20
很有可能,你不能。
粘性位的实现完全存在于内核中,并且没有open()
或creat()
的选项来控制它的操作方式。
您的程序可以在创建文件后调用chown()
手动重置文件组。但是,只有当进程以root用户身份运行,或者作为拥有父目录的组的成员运行时,这才能可靠地工作。
https://stackoverflow.com/questions/43598280
复制相似问题