@@ -3808,34 +3808,43 @@ def test_modes(self):
3808
3808
arc .add ('read_group_only' , mode = '?---r-----' )
3809
3809
arc .add ('no_bits' , mode = '?---------' )
3810
3810
arc .add ('dir/' , mode = '?---rwsrwt' )
3811
+ arc .add ('dir_all_bits/' , mode = '?rwsrwsrwt' )
3811
3812
3812
- # On some systems, setting the sticky bit is a no-op.
3813
- # Check if that's the case.
3813
+ # On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
3814
+ # Check which bits we can set, so we can compare tarfile machinery to
3815
+ # a simple chmod.
3814
3816
tmp_filename = os .path .join (TEMPDIR , "tmp.file" )
3815
3817
with open (tmp_filename , 'w' ):
3816
3818
pass
3817
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3818
- have_sticky_files = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3819
+ new_mode = (os .stat (tmp_filename ).st_mode
3820
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3821
+ os .chmod (tmp_filename , new_mode )
3822
+ got_mode = os .stat (tmp_filename ).st_mode
3823
+ _t_file = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3824
+ _suid_file = 's' if (got_mode & stat .S_ISUID ) else 'x'
3825
+ _sgid_file = 's' if (got_mode & stat .S_ISGID ) else 'x'
3819
3826
os .unlink (tmp_filename )
3820
3827
3821
3828
os .mkdir (tmp_filename )
3822
- os .chmod (tmp_filename , os .stat (tmp_filename ).st_mode | stat .S_ISVTX )
3823
- have_sticky_dirs = (os .stat (tmp_filename ).st_mode & stat .S_ISVTX )
3829
+ new_mode = (os .stat (tmp_filename ).st_mode
3830
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3831
+ os .chmod (tmp_filename , new_mode )
3832
+ got_mode = os .stat (tmp_filename ).st_mode
3833
+ _t_dir = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3834
+ _suid_dir = 's' if (got_mode & stat .S_ISUID ) else 'x'
3835
+ _sgid_dir = 's' if (got_mode & stat .S_ISGID ) else 'x'
3824
3836
os .rmdir (tmp_filename )
3825
3837
3826
3838
with self .check_context (arc .open (), 'fully_trusted' ):
3827
- if have_sticky_files :
3828
- self .expect_file ('all_bits' , mode = '?rwsrwsrwt' )
3829
- else :
3830
- self .expect_file ('all_bits' , mode = '?rwsrwsrwx' )
3839
+ self .expect_file ('all_bits' ,
3840
+ mode = f'?rw{ _suid_file } rw{ _sgid_file } rw{ _t_file } ' )
3831
3841
self .expect_file ('perm_bits' , mode = '?rwxrwxrwx' )
3832
3842
self .expect_file ('exec_group_other' , mode = '?rw-rwxrwx' )
3833
3843
self .expect_file ('read_group_only' , mode = '?---r-----' )
3834
3844
self .expect_file ('no_bits' , mode = '?---------' )
3835
- if have_sticky_dirs :
3836
- self .expect_file ('dir/' , mode = '?---rwsrwt' )
3837
- else :
3838
- self .expect_file ('dir/' , mode = '?---rwsrwx' )
3845
+ self .expect_file ('dir/' , mode = f'?---rw{ _sgid_dir } rw{ _t_dir } ' )
3846
+ self .expect_file ('dir_all_bits/' ,
3847
+ mode = f'?rw{ _suid_dir } rw{ _sgid_dir } rw{ _t_dir } ' )
3839
3848
3840
3849
with self .check_context (arc .open (), 'tar' ):
3841
3850
self .expect_file ('all_bits' , mode = '?rwxr-xr-x' )
@@ -3844,6 +3853,7 @@ def test_modes(self):
3844
3853
self .expect_file ('read_group_only' , mode = '?---r-----' )
3845
3854
self .expect_file ('no_bits' , mode = '?---------' )
3846
3855
self .expect_file ('dir/' , mode = '?---r-xr-x' )
3856
+ self .expect_file ('dir_all_bits/' , mode = '?rwxr-xr-x' )
3847
3857
3848
3858
with self .check_context (arc .open (), 'data' ):
3849
3859
normal_dir_mode = stat .filemode (stat .S_IMODE (
@@ -3854,6 +3864,7 @@ def test_modes(self):
3854
3864
self .expect_file ('read_group_only' , mode = '?rw-r-----' )
3855
3865
self .expect_file ('no_bits' , mode = '?rw-------' )
3856
3866
self .expect_file ('dir/' , mode = normal_dir_mode )
3867
+ self .expect_file ('dir_all_bits/' , mode = normal_dir_mode )
3857
3868
3858
3869
def test_pipe (self ):
3859
3870
# Test handling of a special file
0 commit comments