def is_setuid_root(path):
"""Return True if the file is owned by root and has
the setuid bit set."""
# Can't be setuid root if it's not there.
if not os.path.isfile(path):
return False
pstat = os.stat(path)
# Owned by root?
if pstat.st_uid != 0:
return False
# Setuid bit set?
if pstat.st_mode & stat.S_ISUID == 0:
return False
# Yay, passed all test!
return True
评论列表
文章目录