aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2012-03-26 19:27:18 +0300
committerMartin Pärtel <martin.partel@gmail.com>2012-03-26 19:27:18 +0300
commit9bcae813af89d445a4d269e83c371847075f1008 (patch)
tree4b54d7d3c56ce93910635e2d306a84a7b322b1ba
parent6d96d673fa3977364a9cb3c8c9d3c82ced521bb6 (diff)
downloadbindfs-9bcae813af89d445a4d269e83c371847075f1008.tar.gz
Made --map affect chown/chgrp results.
-rw-r--r--ChangeLog4
-rw-r--r--src/bindfs.110
-rw-r--r--src/bindfs.c2
-rwxr-xr-xtests/common.rb4
-rwxr-xr-xtests/test_bindfs.rb14
5 files changed, 28 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 23787c4..8fed29e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-03-26 Martin Pärtel <martin dot partel at gmail dot com>
+
+ * Made --map affect chown/chgrp results.
+
2012-03-13 Martin Pärtel <martin dot partel at gmail dot com>
* Added --map.
diff --git a/src/bindfs.1 b/src/bindfs.1
index b45b79d..9a03199 100644
--- a/src/bindfs.1
+++ b/src/bindfs.1
@@ -55,13 +55,15 @@ Like \fB\-\-mirror\fP but disallows access for all other users (except root).
.TP
.B \-\-map=\fIuser1/user2:@group1/@group2:...\fP, \-o map=...
Given a mapping \fIuser1/user2\fP, all files owned by user1 are shown
-as owned by user2. Additionally, when user2 creates files, they are chowned
-to user1 in the underlying directory. Works similarly for groups.
+as owned by user2. When user2 creates files, they are chowned
+to user1 in the underlying directory. When files are chowned to user2,
+they are chowned to user1 in the underlying directory. Works similarly for groups.
A single user or group may appear no more than once on the left and once on the
right of a slash in the list of mappings.
-Currently, the options \fB--user\fP, \fB--group\fP, \fB--mirror\fP and
-\fB--create-for-*\fP override the corresponding behavior of this option.
+Currently, the options \fB--user\fP, \fB--group\fP, \fB--mirror\fP,
+\fB--create-for-*\fP, \fB--chown-*\fP and \fB--chgrp-*\fP override
+the corresponding behavior of this option.
Requires mounting as root.
diff --git a/src/bindfs.c b/src/bindfs.c
index 2cebf41..35b1b48 100644
--- a/src/bindfs.c
+++ b/src/bindfs.c
@@ -615,6 +615,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid)
if (uid != -1) {
switch (settings.chown_policy) {
case CHOWN_NORMAL:
+ uid = usermap_get_uid(settings.usermap_reverse, uid);
break;
case CHOWN_IGNORE:
uid = -1;
@@ -627,6 +628,7 @@ static int bindfs_chown(const char *path, uid_t uid, gid_t gid)
if (gid != -1) {
switch (settings.chgrp_policy) {
case CHGRP_NORMAL:
+ gid = usermap_get_gid(settings.usermap_reverse, gid);
break;
case CHGRP_IGNORE:
gid = -1;
diff --git a/tests/common.rb b/tests/common.rb
index d030972..ac1ef43 100755
--- a/tests/common.rb
+++ b/tests/common.rb
@@ -142,9 +142,9 @@ def testenv(bindfs_args, options = {}, &block)
end
# Like testenv but skips the test if not running as root
-def root_testenv(bindfs_args, &block)
+def root_testenv(bindfs_args, options = {}, &block)
if Process.uid == 0
- testenv(bindfs_args, &block)
+ testenv(bindfs_args, options, &block)
else
puts "--- #{bindfs_args} ---"
puts "[ #{bindfs_args} ]"
diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb
index 30899ed..ef732ff 100755
--- a/tests/test_bindfs.rb
+++ b/tests/test_bindfs.rb
@@ -293,3 +293,17 @@ root_testenv("-u 1 --map=1/2:3/4") do
assert { File.stat('mnt/file1').uid == 1 }
assert { File.stat('mnt/file2').uid == 1 }
end
+
+root_testenv("--map=0/1:@0/@1", :title => "--map and chown/chgrp") do
+ touch('src/file1')
+ chown(2, 2, 'src/file1')
+ assert { File.stat('mnt/file1').uid == 2 }
+ assert { File.stat('mnt/file1').gid == 2 }
+
+ chown(1, 1, 'mnt/file1')
+
+ assert { File.stat('src/file1').uid == 0 }
+ assert { File.stat('src/file1').gid == 0 }
+ assert { File.stat('mnt/file1').uid == 1 }
+ assert { File.stat('mnt/file1').gid == 1 }
+end