@@ -3651,34 +3651,43 @@ def test_modes(self):
3651
3651
arc .add ('read_group_only' , mode = '?---r-----' )
3652
3652
arc .add ('no_bits' , mode = '?---------' )
3653
3653
arc .add ('dir/' , mode = '?---rwsrwt' )
3654
+ arc .add ('dir_all_bits/' , mode = '?rwsrwsrwt' )
3654
3655
3655
- # On some systems, setting the sticky bit is a no-op.
3656
- # Check if that's the case.
3656
+ # On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
3657
+ # Check which bits we can set, so we can compare tarfile machinery to
3658
+ # a simple chmod.
3657
3659
tmp_filename = os .path .join (TEMPDIR , "tmp.file" )
3658
3660
with open (tmp_filename , 'w' ):
3659
3661
pass
3660
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3661
- have_sticky_files = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3662
+ new_mode = (os .stat (tmp_filename ).st_mode
3663
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3664
+ os .chmod (tmp_filename , new_mode )
3665
+ got_mode = os .stat (tmp_filename ).st_mode
3666
+ _t_file = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3667
+ _suid_file = 's' if (got_mode & stat .S_ISUID ) else 'x'
3668
+ _sgid_file = 's' if (got_mode & stat .S_ISGID ) else 'x'
3662
3669
os .unlink (tmp_filename )
3663
3670
3664
3671
os .mkdir (tmp_filename )
3665
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3666
- have_sticky_dirs = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3672
+ new_mode = (os .stat (tmp_filename ).st_mode
3673
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3674
+ os .chmod (tmp_filename , new_mode )
3675
+ got_mode = os .stat (tmp_filename ).st_mode
3676
+ _t_dir = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3677
+ _suid_dir = 's' if (got_mode & stat .S_ISUID ) else 'x'
3678
+ _sgid_dir = 's' if (got_mode & stat .S_ISGID ) else 'x'
3667
3679
os .rmdir (tmp_filename )
3668
3680
3669
3681
with self .check_context (arc .open (), 'fully_trusted' ):
3670
- if have_sticky_files :
3671
- self .expect_file ('all_bits' , mode = '?rwsrwsrwt' )
3672
- else :
3673
- self .expect_file ('all_bits' , mode = '?rwsrwsrwx' )
3682
+ self .expect_file ('all_bits' ,
3683
+ mode = f'?rw{ _suid_file } rw{ _sgid_file } rw{ _t_file } ' )
3674
3684
self .expect_file ('perm_bits' , mode = '?rwxrwxrwx' )
3675
3685
self .expect_file ('exec_group_other' , mode = '?rw-rwxrwx' )
3676
3686
self .expect_file ('read_group_only' , mode = '?---r-----' )
3677
3687
self .expect_file ('no_bits' , mode = '?---------' )
3678
- if have_sticky_dirs :
3679
- self .expect_file ('dir/' , mode = '?---rwsrwt' )
3680
- else :
3681
- self .expect_file ('dir/' , mode = '?---rwsrwx' )
3688
+ self .expect_file ('dir/' , mode = f'?---rw{ _sgid_dir } rw{ _t_dir } ' )
3689
+ self .expect_file ('dir_all_bits/' ,
3690
+ mode = f'?rw{ _suid_dir } rw{ _sgid_dir } rw{ _t_dir } ' )
3682
3691
3683
3692
with self .check_context (arc .open (), 'tar' ):
3684
3693
self .expect_file ('all_bits' , mode = '?rwxr-xr-x' )
@@ -3687,6 +3696,7 @@ def test_modes(self):
3687
3696
self .expect_file ('read_group_only' , mode = '?---r-----' )
3688
3697
self .expect_file ('no_bits' , mode = '?---------' )
3689
3698
self .expect_file ('dir/' , mode = '?---r-xr-x' )
3699
+ self .expect_file ('dir_all_bits/' , mode = '?rwxr-xr-x' )
3690
3700
3691
3701
with self .check_context (arc .open (), 'data' ):
3692
3702
normal_dir_mode = stat .filemode (stat .S_IMODE (
@@ -3697,6 +3707,7 @@ def test_modes(self):
3697
3707
self .expect_file ('read_group_only' , mode = '?rw-r-----' )
3698
3708
self .expect_file ('no_bits' , mode = '?rw-------' )
3699
3709
self .expect_file ('dir/' , mode = normal_dir_mode )
3710
+ self .expect_file ('dir_all_bits/' , mode = normal_dir_mode )
3700
3711
3701
3712
def test_pipe (self ):
3702
3713
# Test handling of a special file
0 commit comments