22
22
$LOAD_PATH <<( ENV [ 'srcdir' ] ||'.' )
23
23
24
24
require 'common.rb'
25
+ require 'etc'
25
26
26
27
include Errno
27
28
@@ -49,6 +50,7 @@ def chown(user, group, list)
49
50
$nobody_uid= nobody_uid = Etc . getpwnam ( 'nobody' ) . uid
50
51
$nobody_gid= nobody_gid = Etc . getpwnam ( 'nobody' ) . gid
51
52
$nobody_group= nobody_group = Etc . getgrgid ( nobody_gid ) . name
53
+ $root_group= root_group = Etc . getgrgid ( 0 ) . name
52
54
53
55
$tests_dir= File . realpath ( '.' )
54
56
@@ -247,18 +249,20 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
247
249
assert { File . stat ( 'mnt/file' ) . gid == $nobody_gid}
248
250
end
249
251
250
- testenv ( "--chmod-allow-x --chmod-ignore" ) do
251
- touch ( 'src/file' )
252
+ if `uname` . strip !='FreeBSD' # FreeBSD doesn't let us set the sticky bit on files
253
+ testenv ( "--chmod-allow-x --chmod-ignore" ) do
254
+ touch ( 'src/file' )
252
255
253
- chmod ( 01700 , 'src/file' ) # sticky bit set
256
+ chmod ( 01700 , 'src/file' ) # sticky bit set
254
257
255
- chmod ( 00077 , 'mnt/file' ) # should change x bits; should not unset sticky bit
256
- assert { File . stat ( 'src/file' ) . mode &07777 ==01611 }
258
+ chmod ( 00077 , 'mnt/file' ) # should change x bits; should not unset sticky bit
259
+ assert { File . stat ( 'src/file' ) . mode &07777 ==01611 }
257
260
258
- mkdir ( 'src/dir' )
259
- chmod ( 0700 , 'src/dir' )
260
- chmod ( 0077 , 'mnt/dir' ) # bits on dir should not change
261
- assert { File . stat ( 'src/dir' ) . mode &0777 ==0700 }
261
+ mkdir ( 'src/dir' )
262
+ chmod ( 0700 , 'src/dir' )
263
+ chmod ( 0077 , 'mnt/dir' ) # bits on dir should not change
264
+ assert { File . stat ( 'src/dir' ) . mode &0777 ==0700 }
265
+ end
262
266
end
263
267
264
268
testenv ( "--chmod-deny --chmod-allow-x" ) do
@@ -289,7 +293,7 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
289
293
assert { File . stat ( 'src/file' ) . mode &0777 ==0640 }
290
294
end
291
295
292
- root_testenv ( "--map=nobody/root:@#{ nobody_group } /@root " ) do
296
+ root_testenv ( "--map=nobody/root:@#{ nobody_group } /@#{ root_group } " ) do
293
297
touch ( 'src/file' )
294
298
chown ( 'nobody' , nobody_group , 'src/file' )
295
299
@@ -310,7 +314,7 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
310
314
assert { File . stat ( 'mnt/newdir' ) . gid ==0 }
311
315
end
312
316
313
- root_testenv ( "--map=@#{ nobody_group } /@root " ) do
317
+ root_testenv ( "--map=@#{ nobody_group } /@#{ root_group } " ) do
314
318
touch ( 'src/file' )
315
319
chown ( 'nobody' , nobody_group , 'src/file' )
316
320
@@ -377,20 +381,21 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
377
381
root_testenv ( "--uid-offset=2 --gid-offset=20" , :title => "file creation with --uid-offset and --gid-offset" ) do
378
382
touch ( 'mnt/file' )
379
383
380
- assert { File . stat ( 'mnt/file' ) . uid ==2 }
381
- assert { File . stat ( 'mnt/file' ) . gid ==20 }
382
384
assert { File . stat ( 'src/file' ) . uid ==0 }
383
- assert { File . stat ( 'src/file' ) . gid ==0 }
385
+ assert { File . stat ( 'mnt/file' ) . uid ==2 }
386
+ # Note: BSDs tend to inherit group from parent dir while Linux uses the effective GID.
387
+ # This check works for both.
388
+ assert { File . stat ( 'mnt/file' ) . gid ==File . stat ( 'src/file' ) . gid +20 }
384
389
end
385
390
386
391
root_testenv ( "--uid-offset=2 --gid-offset=20" , :title => "chown/chgrp with --uid-offset and --gid-offset" ) do
387
392
touch ( 'src/file' )
388
393
chown ( 6 , 25 , 'mnt/file' )
389
394
390
- assert { File . stat ( 'mnt/file' ) . uid ==6 }
391
- assert { File . stat ( 'mnt/file' ) . gid ==25 }
392
395
assert { File . stat ( 'src/file' ) . uid ==4 }
393
396
assert { File . stat ( 'src/file' ) . gid ==5 }
397
+ assert { File . stat ( 'mnt/file' ) . uid ==6 }
398
+ assert { File . stat ( 'mnt/file' ) . gid ==25 }
394
399
end
395
400
396
401
testenv ( "" , :title => "preserves inode numbers" ) do
@@ -400,7 +405,7 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
400
405
assert { File . stat ( 'mnt/dir' ) . ino ==File . stat ( 'src/dir' ) . ino }
401
406
end
402
407
403
- testenv ( "" , :title => "has readdir inode numbers" ) do
408
+ testenv ( "" , :title => "preserves readdir inode numbers" ) do
404
409
touch ( 'src/file' )
405
410
mkdir ( 'src/dir' )
406
411
@@ -744,7 +749,8 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
744
749
745
750
# FIXME: this stuff around testenv is a hax, and testenv may also exit(), which defeats the 'ensure' below.
746
751
# the test setup ought to be refactored. It might well use MiniTest or something.
747
- if Process . uid ==0
752
+ # TODO: support FreeBSD in this test (different group management commands)
753
+ if Process . uid ==0 &&`uname` . strip =='Linux'
748
754
begin
749
755
`groupdel bindfs_test_group 2>&1`
750
756
`groupadd -f bindfs_test_group`