Python stat.S_ISVTX Examples
The following are 18
code examples of stat.S_ISVTX().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stat
, or try the search function
.
Example #1
Source File: plat_other.py From pipeline with MIT License | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, str(uid)) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #2
Source File: lib.py From marsnake with GNU General Public License v3.0 | 6 votes |
def special_to_letter(mode): l = '' ALL_R = (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) ALL_W = (stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) if mode & stat.S_ISGID: l += 'G' if mode & stat.S_ISUID: l += 'U' if mode & stat.S_ISVTX: l += 'T' if mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH): l += 'E' if ( mode & ALL_R ) == ALL_R: l += 'R' if ( mode & ALL_W ) == ALL_W: l += 'W' return l
Example #3
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testStatDirectory_filePermissions(self): should_have = ( ('some_file', stat.S_IWUSR), # Owner can write. ('tmp', stat.S_IXOTH), # Others can execute. ('tmp', stat.S_ISVTX), # Has sticky bit. ('my_cmd', stat.S_ISGID), # Has set-group-ID bit. ('silly', stat.S_ISUID), # Has set UID bit. ) should_not_have = ( ('some_file', stat.S_IWOTH), # Others can't write. ('block_dev', stat.S_IRGRP), # Group can't read. ('silly', stat.S_IXUSR), # Owner can't execute. ) entries = self.getStatEntries() for filename, bit in should_have: self.assertTrue(entries[filename]['st_mode'] & bit) for filename, bit in should_not_have: self.assertFalse(entries[filename]['st_mode'] & bit)
Example #4
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testStatDirectory_filePermissions(self): should_have = ( ('some_file', stat.S_IWUSR), # Owner can write. ('tmp', stat.S_IXOTH), # Others can execute. ('tmp', stat.S_ISVTX), # Has sticky bit. ('my_cmd', stat.S_ISGID), # Has set-group-ID bit. ('silly', stat.S_ISUID), # Has set UID bit. ) should_not_have = ( ('some_file', stat.S_IWOTH), # Others can't write. ('block_dev', stat.S_IRGRP), # Group can't read. ('silly', stat.S_IXUSR), # Owner can't execute. ) entries = self.getStatEntries() for filename, bit in should_have: self.assertTrue(entries[filename]['st_mode'] & bit) for filename, bit in should_not_have: self.assertFalse(entries[filename]['st_mode'] & bit)
Example #5
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testStatDirectory_filePermissions(self): should_have = ( ('some_file', stat.S_IWUSR), # Owner can write. ('tmp', stat.S_IXOTH), # Others can execute. ('tmp', stat.S_ISVTX), # Has sticky bit. ('my_cmd', stat.S_ISGID), # Has set-group-ID bit. ('silly', stat.S_ISUID), # Has set UID bit. ) should_not_have = ( ('some_file', stat.S_IWOTH), # Others can't write. ('block_dev', stat.S_IRGRP), # Group can't read. ('silly', stat.S_IXUSR), # Owner can't execute. ) entries = self.getStatEntries() for filename, bit in should_have: self.assertTrue(entries[filename]['st_mode'] & bit) for filename, bit in should_not_have: self.assertFalse(entries[filename]['st_mode'] & bit)
Example #6
Source File: plat_other.py From Snu-Photo-Manager with GNU Lesser General Public License v3.0 | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, text_type(uid).encode('ascii')) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #7
Source File: plat_other.py From FileManager with MIT License | 6 votes |
def find_ext_volume_global_trash(volume_root): # from [2] Trash directories (1) check for a .Trash dir with the right # permissions set. trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX): return None trash_dir = op.join(trash_dir, text_type(uid).encode('ascii')) try: check_create(trash_dir) except OSError: return None return trash_dir
Example #8
Source File: aactivator.py From aactivator with MIT License | 5 votes |
def insecure_inode(path): """This particular inode can be altered by someone other than the owner""" pathstat = os.stat(path).st_mode # Directories with a sticky bit are always acceptable. if os.path.isdir(path) and pathstat & stat.S_ISVTX: return False # The path is writable by someone who is not us. elif pathstat & (stat.S_IWGRP | stat.S_IWOTH): return True else: return False
Example #9
Source File: __init__.py From ALF with Apache License 2.0 | 5 votes |
def rm_full_dir(path, ignore_errors=False): """ This function is used to remove a directory and all files and directories within it (like `rm -rf`). """ if os.path.isdir(path): try: os.chmod(path, os.stat(path).st_mode | stat.S_IRWXU & ~stat.S_ISVTX) except OSError: pass f_last = 0 while True: f_count = 0 for root, d_names, f_names in os.walk(path): try: os.chmod(root, os.stat(root).st_mode | stat.S_IRWXU & ~stat.S_ISVTX) except OSError: pass for fs_name in f_names + d_names: target = os.path.join(root, fs_name) try: os.chmod(target, os.stat(target).st_mode | stat.S_IRWXU & ~stat.S_ISVTX) except OSError: pass f_count += 1 f_count += 1 # do this until we get the same count twice, ie. all files we can # chmod our way into have been found if f_last == f_count: break f_last = f_count shutil.rmtree(path, ignore_errors)
Example #10
Source File: native.py From treadmill with Apache License 2.0 | 5 votes |
def make_fsroot(root_dir, emptydirs, stickydirs, mounts): """Initializes directory structure for the container in a new root. """ _LOGGER.info('Creating fs root in: %s', root_dir) for directory in sorted(emptydirs): fs.mkdir_safe(root_dir + directory) for directory in sorted(stickydirs): os.chmod(root_dir + directory, 0o777 | stat.S_ISVTX) # Make shared directories/files readonly to container reserved = {'/run', '/sys/fs', '/var/spool/tickets', '/var/spool/keytabs', '/var/spool/tokens'} for mount, args in mounts.items(): # These are reserved, mounted on memory in make_osroot. if mount in reserved: continue if not args: fs_linux.mount_bind( root_dir, mount, recursive=True, read_only=True ) else: fs_linux.mount_bind(root_dir, mount, **args)
Example #11
Source File: filesystem.py From oswatcher with GNU General Public License v3.0 | 5 votes |
def is_sticky(self): return True if self.status['st_mode'] & stat.S_ISVTX else False
Example #12
Source File: tools.py From EasY_HaCk with Apache License 2.0 | 4 votes |
def humanUnixAttributes(mode): """ Convert a Unix file attributes (or "file mode") to an unicode string. Original source code: http://cvs.savannah.gnu.org/viewcvs/coreutils/lib/filemode.c?root=coreutils >>> humanUnixAttributes(0644) u'-rw-r--r-- (644)' >>> humanUnixAttributes(02755) u'-rwxr-sr-x (2755)' """ def ftypelet(mode): if stat.S_ISREG (mode) or not stat.S_IFMT(mode): return '-' if stat.S_ISBLK (mode): return 'b' if stat.S_ISCHR (mode): return 'c' if stat.S_ISDIR (mode): return 'd' if stat.S_ISFIFO(mode): return 'p' if stat.S_ISLNK (mode): return 'l' if stat.S_ISSOCK(mode): return 's' return '?' chars = [ ftypelet(mode), 'r', 'w', 'x', 'r', 'w', 'x', 'r', 'w', 'x' ] for i in xrange(1, 10): if not mode & 1 << 9 - i: chars[i] = '-' if mode & stat.S_ISUID: if chars[3] != 'x': chars[3] = 'S' else: chars[3] = 's' if mode & stat.S_ISGID: if chars[6] != 'x': chars[6] = 'S' else: chars[6] = 's' if mode & stat.S_ISVTX: if chars[9] != 'x': chars[9] = 'T' else: chars[9] = 't' return u"%s (%o)" % (''.join(chars), mode)
Example #13
Source File: sftp_attr.py From imoocc with GNU General Public License v2.0 | 4 votes |
def __str__(self): """create a unix-style long description of the file (like ls -l)""" if self.st_mode is not None: kind = stat.S_IFMT(self.st_mode) if kind == stat.S_IFIFO: ks = 'p' elif kind == stat.S_IFCHR: ks = 'c' elif kind == stat.S_IFDIR: ks = 'd' elif kind == stat.S_IFBLK: ks = 'b' elif kind == stat.S_IFREG: ks = '-' elif kind == stat.S_IFLNK: ks = 'l' elif kind == stat.S_IFSOCK: ks = 's' else: ks = '?' ks += self._rwx((self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID) ks += self._rwx((self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID) ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' # compute display date if (self.st_mtime is None) or (self.st_mtime == xffffffff): # shouldn't really happen datestr = '(unknown date)' else: if abs(time.time() - self.st_mtime) > 15552000: # (15552000 = 6 months) datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime)) else: datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime)) filename = getattr(self, 'filename', '?') # not all servers support uid/gid uid = self.st_uid gid = self.st_gid size = self.st_size if uid is None: uid = 0 if gid is None: gid = 0 if size is None: size = 0 return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, size, datestr, filename)
Example #14
Source File: sftp_attr.py From imoocc with GNU General Public License v2.0 | 4 votes |
def __str__(self): "create a unix-style long description of the file (like ls -l)" if self.st_mode is not None: kind = stat.S_IFMT(self.st_mode) if kind == stat.S_IFIFO: ks = 'p' elif kind == stat.S_IFCHR: ks = 'c' elif kind == stat.S_IFDIR: ks = 'd' elif kind == stat.S_IFBLK: ks = 'b' elif kind == stat.S_IFREG: ks = '-' elif kind == stat.S_IFLNK: ks = 'l' elif kind == stat.S_IFSOCK: ks = 's' else: ks = '?' ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID) ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID) ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' # compute display date if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL): # shouldn't really happen datestr = '(unknown date)' else: if abs(time.time() - self.st_mtime) > 15552000: # (15552000 = 6 months) datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime)) else: datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime)) filename = getattr(self, 'filename', '?') # not all servers support uid/gid uid = self.st_uid gid = self.st_gid if uid is None: uid = 0 if gid is None: gid = 0 return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, self.st_size, datestr, filename)
Example #15
Source File: sftp_attr.py From imoocc with GNU General Public License v2.0 | 4 votes |
def __str__(self): "create a unix-style long description of the file (like ls -l)" if self.st_mode is not None: kind = stat.S_IFMT(self.st_mode) if kind == stat.S_IFIFO: ks = 'p' elif kind == stat.S_IFCHR: ks = 'c' elif kind == stat.S_IFDIR: ks = 'd' elif kind == stat.S_IFBLK: ks = 'b' elif kind == stat.S_IFREG: ks = '-' elif kind == stat.S_IFLNK: ks = 'l' elif kind == stat.S_IFSOCK: ks = 's' else: ks = '?' ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID) ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID) ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' # compute display date if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL): # shouldn't really happen datestr = '(unknown date)' else: if abs(time.time() - self.st_mtime) > 15552000: # (15552000 = 6 months) datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime)) else: datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime)) filename = getattr(self, 'filename', '?') # not all servers support uid/gid uid = self.st_uid gid = self.st_gid if uid is None: uid = 0 if gid is None: gid = 0 return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, self.st_size, datestr, filename)
Example #16
Source File: base.py From stash with MIT License | 4 votes |
def calc_mode( sticky=False, isuid=True, isgid=True, type=stat.S_IFREG, owner_read=True, owner_write=True, owner_exec=True, group_read=True, group_write=True, group_exec=True, other_read=True, other_write=True, other_exec=True, ): """helper function to calculate the mode bits of a file.""" mode = 0 if owner_read: mode |= stat.S_IRUSR if owner_write: mode |= stat.S_IWUSR if owner_exec: mode |= stat.S_IXUSR if group_read: mode |= stat.S_IRGRP if group_write: mode |= stat.S_IWGRP if group_exec: mode |= stat.S_IXGRP if other_read: mode |= stat.S_IROTH if other_write: mode |= stat.S_IWOTH if other_exec: mode |= stat.S_IXOTH if sticky: mode |= stat.S_ISVTX if isuid: mode |= stat.ST_UID if isgid: mode |= stat.ST_GID mode |= type return mode
Example #17
Source File: tools.py From ITWSV with MIT License | 4 votes |
def humanUnixAttributes(mode): """ Convert a Unix file attributes (or "file mode") to an unicode string. Original source code: http://cvs.savannah.gnu.org/viewcvs/coreutils/lib/filemode.c?root=coreutils >>> humanUnixAttributes(0644) u'-rw-r--r-- (644)' >>> humanUnixAttributes(02755) u'-rwxr-sr-x (2755)' """ def ftypelet(mode): if stat.S_ISREG (mode) or not stat.S_IFMT(mode): return '-' if stat.S_ISBLK (mode): return 'b' if stat.S_ISCHR (mode): return 'c' if stat.S_ISDIR (mode): return 'd' if stat.S_ISFIFO(mode): return 'p' if stat.S_ISLNK (mode): return 'l' if stat.S_ISSOCK(mode): return 's' return '?' chars = [ ftypelet(mode), 'r', 'w', 'x', 'r', 'w', 'x', 'r', 'w', 'x' ] for i in xrange(1, 10): if not mode & 1 << 9 - i: chars[i] = '-' if mode & stat.S_ISUID: if chars[3] != 'x': chars[3] = 'S' else: chars[3] = 's' if mode & stat.S_ISGID: if chars[6] != 'x': chars[6] = 'S' else: chars[6] = 's' if mode & stat.S_ISVTX: if chars[9] != 'x': chars[9] = 'T' else: chars[9] = 't' return u"%s (%o)" % (''.join(chars), mode)
Example #18
Source File: tools.py From Yuki-Chan-The-Auto-Pentest with MIT License | 4 votes |
def humanUnixAttributes(mode): """ Convert a Unix file attributes (or "file mode") to an unicode string. Original source code: http://cvs.savannah.gnu.org/viewcvs/coreutils/lib/filemode.c?root=coreutils >>> humanUnixAttributes(0644) u'-rw-r--r-- (644)' >>> humanUnixAttributes(02755) u'-rwxr-sr-x (2755)' """ def ftypelet(mode): if stat.S_ISREG (mode) or not stat.S_IFMT(mode): return '-' if stat.S_ISBLK (mode): return 'b' if stat.S_ISCHR (mode): return 'c' if stat.S_ISDIR (mode): return 'd' if stat.S_ISFIFO(mode): return 'p' if stat.S_ISLNK (mode): return 'l' if stat.S_ISSOCK(mode): return 's' return '?' chars = [ ftypelet(mode), 'r', 'w', 'x', 'r', 'w', 'x', 'r', 'w', 'x' ] for i in xrange(1, 10): if not mode & 1 << 9 - i: chars[i] = '-' if mode & stat.S_ISUID: if chars[3] != 'x': chars[3] = 'S' else: chars[3] = 's' if mode & stat.S_ISGID: if chars[6] != 'x': chars[6] = 'S' else: chars[6] = 's' if mode & stat.S_ISVTX: if chars[9] != 'x': chars[9] = 'T' else: chars[9] = 't' return u"%s (%o)" % (''.join(chars), mode)