July 30, 2008

permission weirdness ....

If underlying permissions are not correct, they might create some unwanted permission issues.

Please see below example:

# chmod 700 /test_mount
# mount /dev/dsk/c0t0d0s5 /test_mount
# cd /test_mount
# ls -ld .
drwxr-xr-x 5 root root 512 Jul 30 15:14 .

At this time non-root users, will have problems, deleting directories recursively.

$ id
uid=30583(cherukve) gid=30454(u30583)
$ ls -ld cv1
drwxr-xr-x 2 cherukve root 512 Jul 30 15:20 cv1
$ cd cv1
$ mkdir 123 ( create a dir and touch some files )
$ cd 123
$ touch 1 2 3
$ ls -l
total 0
-rw-rw-r-- 1 cherukve u30583 0 Jul 30 15:21 1
-rw-rw-r-- 1 cherukve u30583 0 Jul 30 15:21 2
-rw-rw-r-- 1 cherukve u30583 0 Jul 30 15:21 3

$ pwd
/test_mount/cv1/123
$ cd ..
$ rm -r 123

rm: cannot determine if this is an ancestor of the current working directory

Hmmm... this deletes all files under "123", but it cant delete the directory it self. ( rm -rf doesnt complain - but it cant delete the directory either )
There is a SUN bug ID 4677347 - which says its fixed, but the problem seem to exist still.
To see the underlying mount perms .. lets do some mdb

root# mdb -k
Loading modules: [ unix krtld genunix specfs dtrace ufs pcipsy ip sctp usba fctl nca zfs random nfs audiosup sd sppp ipc ptm crypto ]

> ::fsinfo !grep test_mount
0000030003897b00 ufs /test_mount
> 0000030003897b00::print struct vfs vfs_vnodecovered|::print struct vnode v_data |::print struct inode i_ic.ic_smode

i_ic.ic_smode = 0x41c0

This mode is in hex and need to be converted to octal
> 0x41c0=O
040700


i.e 700 - we need to change it to 755 - so that others can have execute/search permision

For changing permission of underlying mount, you can

1. unmount FS , change permision and mount it back
2. share it via NFS - mount it on another box and change perms

so, i fixed it via NFS

root# share -o root=sm1p9316swk,rw /
root# mount sm1p9316swk:/ /a
root# cd /a
root# ls -ld test_mount
drwx------ 2 root root 512 Jul 30 15:13 test_mount
root# chmod 755 test_mount
root# cd /
root# umount /a


Now "rm" works like charm !!!