@@ -3691,34 +3691,43 @@ def test_modes(self):
3691
3691
arc .add ('read_group_only' , mode = '?---r-----' )
3692
3692
arc .add ('no_bits' , mode = '?---------' )
3693
3693
arc .add ('dir/' , mode = '?---rwsrwt' )
3694
+ arc .add ('dir_all_bits/' , mode = '?rwsrwsrwt' )
3694
3695
3695
- # On some systems, setting the sticky bit is a no-op.
3696
- # Check if that's the case.
3696
+ # On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
3697
+ # Check which bits we can set, so we can compare tarfile machinery to
3698
+ # a simple chmod.
3697
3699
tmp_filename = os .path .join (TEMPDIR , "tmp.file" )
3698
3700
with open (tmp_filename , 'w' ):
3699
3701
pass
3700
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3701
- have_sticky_files = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3702
+ new_mode = (os .stat (tmp_filename ).st_mode
3703
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3704
+ os .chmod (tmp_filename , new_mode )
3705
+ got_mode = os .stat (tmp_filename ).st_mode
3706
+ _t_file = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3707
+ _suid_file = 's' if (got_mode & stat .S_ISUID ) else 'x'
3708
+ _sgid_file = 's' if (got_mode & stat .S_ISGID ) else 'x'
3702
3709
os .unlink (tmp_filename )
3703
3710
3704
3711
os .mkdir (tmp_filename )
3705
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3706
- have_sticky_dirs = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3712
+ new_mode = (os .stat (tmp_filename ).st_mode
3713
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3714
+ os .chmod (tmp_filename , new_mode )
3715
+ got_mode = os .stat (tmp_filename ).st_mode
3716
+ _t_dir = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3717
+ _suid_dir = 's' if (got_mode & stat .S_ISUID ) else 'x'
3718
+ _sgid_dir = 's' if (got_mode & stat .S_ISGID ) else 'x'
3707
3719
os .rmdir (tmp_filename )
3708
3720
3709
3721
with self .check_context (arc .open (), 'fully_trusted' ):
3710
- if have_sticky_files :
3711
- self .expect_file ('all_bits' , mode = '?rwsrwsrwt' )
3712
- else :
3713
- self .expect_file ('all_bits' , mode = '?rwsrwsrwx' )
3722
+ self .expect_file ('all_bits' ,
3723
+ mode = f'?rw{ _suid_file } rw{ _sgid_file } rw{ _t_file } ' )
3714
3724
self .expect_file ('perm_bits' , mode = '?rwxrwxrwx' )
3715
3725
self .expect_file ('exec_group_other' , mode = '?rw-rwxrwx' )
3716
3726
self .expect_file ('read_group_only' , mode = '?---r-----' )
3717
3727
self .expect_file ('no_bits' , mode = '?---------' )
3718
- if have_sticky_dirs :
3719
- self .expect_file ('dir/' , mode = '?---rwsrwt' )
3720
- else :
3721
- self .expect_file ('dir/' , mode = '?---rwsrwx' )
3728
+ self .expect_file ('dir/' , mode = f'?---rw{ _sgid_dir } rw{ _t_dir } ' )
3729
+ self .expect_file ('dir_all_bits/' ,
3730
+ mode = f'?rw{ _suid_dir } rw{ _sgid_dir } rw{ _t_dir } ' )
3722
3731
3723
3732
with self .check_context (arc .open (), 'tar' ):
3724
3733
self .expect_file ('all_bits' , mode = '?rwxr-xr-x' )
@@ -3727,6 +3736,7 @@ def test_modes(self):
3727
3736
self .expect_file ('read_group_only' , mode = '?---r-----' )
3728
3737
self .expect_file ('no_bits' , mode = '?---------' )
3729
3738
self .expect_file ('dir/' , mode = '?---r-xr-x' )
3739
+ self .expect_file ('dir_all_bits/' , mode = '?rwxr-xr-x' )
3730
3740
3731
3741
with self .check_context (arc .open (), 'data' ):
3732
3742
normal_dir_mode = stat .filemode (stat .S_IMODE (
@@ -3737,6 +3747,7 @@ def test_modes(self):
3737
3747
self .expect_file ('read_group_only' , mode = '?rw-r-----' )
3738
3748
self .expect_file ('no_bits' , mode = '?rw-------' )
3739
3749
self .expect_file ('dir/' , mode = normal_dir_mode )
3750
+ self .expect_file ('dir_all_bits/' , mode = normal_dir_mode )
3740
3751
3741
3752
def test_pipe (self ):
3742
3753
# Test handling of a special file
0 commit comments