git: sbin/hammer: Detect possible relinking of pfs by user
Tomohiro Kusumi
tkusumi at crater.dragonflybsd.org
Wed Apr 1 14:32:37 PDT 2015
commit a7c8cfeffaecd107a8cfd45efa25e459b45327f2
Author: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
Date: Wed Apr 1 05:26:19 2015 +0900
sbin/hammer: Detect possible relinking of pfs by user
- It is possible that a user rm pfs symlink and then relink the pfs.
If the user happens to make the symlink to, for example,
"./@@-1:00001" (has "./" before "@@-1:00001"), then getpfs() fails
to properly parse the pfs id as it fails to sscanf the string.
This commit checks if the symlink has "/" in the path, and if yes
use a basename of it to get rid of unnecessary prefix to make it
work properly.
==========
example1 - using existing /sbin/hammer
# mount | grep TEST
TEST on /HAMMER (hammer, local)
# pwd
/HAMMER
# hammer pfs-master test1 > /dev/null
# ls -l ./test1
lrwxr-xr-x 1 root wheel 10 Apr 2 04:27 ./test1 -> @@-1:00001
# ln -s ./@@-1:00001 test2
# ls -l ./test2
lrwxr-xr-x 1 root wheel 12 Apr 2 04:28 ./test2 -> ./@@-1:00001
# hammer pfs-destroy ./test2
You have requested that PFS#1 () be destroyed
<snip>
Destroying PFS #1 () in 5 4 3 2 1.. starting destruction pass
pfs-destroy of PFS#1 failed: Directory not empty
==========
example2 - using this commit
# mount | grep TEST
TEST on /HAMMER (hammer, local)
# pwd
/HAMMER
# hammer pfs-master test1 > /dev/null
# ls -l ./test1
lrwxr-xr-x 1 root wheel 10 Apr 2 04:31 ./test1 -> @@-1:00001
# ln -s ./@@-1:00001 test2
# ls -l ./test2
lrwxr-xr-x 1 root wheel 12 Apr 2 04:31 ./test2 -> ./@@-1:00001
# hammer pfs-destroy ./test2
You have requested that PFS#1 () be destroyed
<snip>
Destroying PFS #1 () in 5 4 3 2 1.. starting destruction pass
pfs-destroy of PFS#1 succeeded!
# ls -l ./test*
lrwxr-xr-x 1 root wheel 10 Apr 2 04:31 ./test1 -> @@PFS00001
# hammer pfs-status ./test1
Cannot access PFS ./test1: No such file or directory
Summary of changes:
sbin/hammer/cmd_pseudofs.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/a7c8cfeffaecd107a8cfd45efa25e459b45327f2
--
DragonFly BSD source repository
More information about the Commits
mailing list