@@ -3809,33 +3809,38 @@ def test_modes(self):
3809
3809
arc .add ('no_bits' , mode = '?---------' )
3810
3810
arc .add ('dir/' , mode = '?---rwsrwt' )
3811
3811
3812
- # On some systems, setting the sticky bit is a no-op.
3813
- # Check if that's the case.
3812
+ # On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
3813
+ # Check which bits we can set, so we can compare tarfile machinery to
3814
+ # a simple chmod.
3814
3815
tmp_filename = os .path .join (TEMPDIR , "tmp.file" )
3815
3816
with open (tmp_filename , 'w' ):
3816
3817
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 )
3818
+ new_mode = (os .stat (tmp_filename ).st_mode
3819
+ | stat .S_ISVTX | stat .S_ISGID | stat .S_ISUID )
3820
+ os .chmod (tmp_filename , new_mode )
3821
+ got_mode = os .stat (tmp_filename ).st_mode
3822
+ _t_file = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3823
+ _suid_file = 's' if (got_mode & stat .S_ISUID ) else 'x'
3824
+ _sgid_file = 's' if (got_mode & stat .S_ISGID ) else 'x'
3819
3825
os .unlink (tmp_filename )
3820
3826
3821
3827
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 )
3828
+ new_mode = os .stat (tmp_filename ).st_mode | stat .S_ISVTX | stat .S_ISGID
3829
+ os .chmod (tmp_filename , new_mode )
3830
+ got_mode = os .stat (tmp_filename ).st_mode
3831
+ _t_dir = 't' if (got_mode & stat .S_ISVTX ) else 'x'
3832
+ _suid_dir = 's' if (got_mode & stat .S_ISUID ) else 'x'
3833
+ _sgid_dir = 's' if (got_mode & stat .S_ISGID ) else 'x'
3824
3834
os .rmdir (tmp_filename )
3825
3835
3826
3836
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' )
3837
+ self .expect_file ('all_bits' ,
3838
+ mode = f'?rw{ _suid_file } rw{ _sgid_file } rw{ _t_file } ' )
3831
3839
self .expect_file ('perm_bits' , mode = '?rwxrwxrwx' )
3832
3840
self .expect_file ('exec_group_other' , mode = '?rw-rwxrwx' )
3833
3841
self .expect_file ('read_group_only' , mode = '?---r-----' )
3834
3842
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' )
3843
+ self .expect_file ('dir/' , mode = f'?---rw{ _sgid_dir } rw{ _t_dir } ' )
3839
3844
3840
3845
with self .check_context (arc .open (), 'tar' ):
3841
3846
self .expect_file ('all_bits' , mode = '?rwxr-xr-x' )
0 commit comments