python idls_Python stat.S_ISUID屬性代碼示例

本文整理匯總了Python中stat.S_ISUID屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.S_ISUID屬性的具體用法?Python stat.S_ISUID怎麽用?Python stat.S_ISUID使用的例子?那麽恭喜您, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在模塊stat的用法示例。

在下文中一共展示了stat.S_ISUID屬性的16個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: special_to_letter

​點讚 6

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

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

開發者ID:turingsec,項目名稱:marsnake,代碼行數:22,

示例2: testStatDirectory_filePermissions

​點讚 6

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

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)

開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:20,

示例3: is_suid_sgid

​點讚 6

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def is_suid_sgid(self, file_name):

results = []

try:

f = stat(file_name)

mode = f.st_mode

except:

return [None, None]

if (mode & S_ISUID) == 2048:

print("SUID: " + file_name)

results.append(file_name)

else:

results.append(None)

if (mode & S_ISGID) == 1024:

print("SGIG: " + file_name)

results.append(file_name)

else:

results.append(None)

return results

開發者ID:Josue87,項目名稱:BoomER,代碼行數:22,

示例4: _is_suid_sgid

​點讚 6

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def _is_suid_sgid(self, file_name):

results = []

try:

f = os.stat(file_name)

mode = f.st_mode

except:

return [None, None]

if (mode & stat.S_ISUID) == 2048:

results.append(file_name)

else:

results.append(None)

if (mode & stat.S_ISGID) == 1024:

results.append(file_name)

else:

results.append(None)

return results

開發者ID:Josue87,項目名稱:BoomER,代碼行數:18,

示例5: render_python_value

​點讚 6

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def render_python_value(value):

if not isinstance(value, int):

return

if value & stat.S_IFDIR:

perm = 'd'

else:

perm = '-'

perm += 'r' if value & stat.S_IRUSR else '-'

perm += 'w' if value & stat.S_IWUSR else '-'

if value & stat.S_ISUID:

perm += 's' if value & stat.S_IXUSR else 'S'

else:

perm += 'x' if value & stat.S_IXUSR else '-'

perm += 'r' if value & stat.S_IRGRP else '-'

perm += 'w' if value & stat.S_IWGRP else '-'

if value & stat.S_ISGID:

perm += 's' if value & stat.S_IXGRP else 'S'

else:

perm += 'x' if value & stat.S_IXGRP else '-'

perm += 'r' if value & stat.S_IROTH else '-'

perm += 'w' if value & stat.S_IWOTH else '-'

perm += 'x' if value & stat.S_IXOTH else '-'

return perm

開發者ID:rsmusllp,項目名稱:king-phisher-plugins,代碼行數:27,

示例6: perm_check

​點讚 5

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def perm_check():

"""In our environment the redir program must be suid with root owner. It

needs to open privileged ports. Returns True if permissions are ok, False

otherwise."""

import os, stat

if os.getuid() == 0:

return 1 # we are already running as root...

st = os.stat(REDIR)

return st.st_uid == 0 and (stat.S_IMODE(st.st_mode) & stat.S_ISUID)

開發者ID:kdart,項目名稱:pycopia,代碼行數:11,

示例7: _is_setuid

​點讚 5

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def _is_setuid(path):

return (os.path.isfile(path) and

os.access(path, os.X_OK) and

os.stat(path).st_mode & stat.S_ISUID == stat.S_ISUID)

開發者ID:HewlettPackard,項目名稱:reconbf,代碼行數:6,

示例8: skip_if_no_fusermount

​點讚 5

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def skip_if_no_fusermount():

'''Raise SkipTest if fusermount is not available'''

with subprocess.Popen(['which', 'fusermount'], stdout=subprocess.PIPE,

universal_newlines=True) as which:

fusermount_path = which.communicate()[0].strip()

if not fusermount_path or which.returncode != 0:

pytest.skip("Can't find fusermount executable")

if not os.path.exists('/dev/fuse'):

pytest.skip("FUSE kernel module does not seem to be loaded")

if os.getuid() == 0:

return

mode = os.stat(fusermount_path).st_mode

if mode & stat.S_ISUID == 0:

pytest.skip('fusermount executable not setuid, and we are not root.')

try:

fd = os.open('/dev/fuse', os.O_RDWR)

except OSError as exc:

pytest.skip('Unable to open /dev/fuse: %s' % exc.strerror)

else:

os.close(fd)

開發者ID:s3ql,項目名稱:s3ql,代碼行數:28,

示例9: is_setuid

​點讚 5

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def is_setuid(self):

return True if self.status['st_mode'] & stat.S_ISUID else False

開發者ID:Wenzel,項目名稱:oswatcher,代碼行數:4,

示例10: evaluate

​點讚 5

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def evaluate(self, image_obj, context):

if not image_obj.fs:

return

files = image_obj.fs.files

if not files:

return

found = [x for x in list(files.items()) if int(x[1].get('mode', 0)) & (stat.S_ISUID | stat.S_ISGID)]

for path, entry in found:

self._fire(msg='SUID or SGID found set on file {}. Mode: {}'.format(path, oct(entry.get('mode'))))

開發者ID:anchore,項目名稱:anchore-engine,代碼行數:13,

示例11: humanUnixAttributes

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

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)

開發者ID:Yukinoshita47,項目名稱:Yuki-Chan-The-Auto-Pentest,代碼行數:46,

示例12: __str__

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

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)

開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:48,

示例13: __str__

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

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)

開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:51,

示例14: lsLine

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def lsLine(name, s):

mode = s.st_mode

perms = array.array('c', '-'*10)

ft = stat.S_IFMT(mode)

if stat.S_ISDIR(ft): perms[0] = 'd'

elif stat.S_ISCHR(ft): perms[0] = 'c'

elif stat.S_ISBLK(ft): perms[0] = 'b'

elif stat.S_ISREG(ft): perms[0] = '-'

elif stat.S_ISFIFO(ft): perms[0] = 'f'

elif stat.S_ISLNK(ft): perms[0] = 'l'

elif stat.S_ISSOCK(ft): perms[0] = 's'

else: perms[0] = '!'

# user

if mode&stat.S_IRUSR:perms[1] = 'r'

if mode&stat.S_IWUSR:perms[2] = 'w'

if mode&stat.S_IXUSR:perms[3] = 'x'

# group

if mode&stat.S_IRGRP:perms[4] = 'r'

if mode&stat.S_IWGRP:perms[5] = 'w'

if mode&stat.S_IXGRP:perms[6] = 'x'

# other

if mode&stat.S_IROTH:perms[7] = 'r'

if mode&stat.S_IWOTH:perms[8] = 'w'

if mode&stat.S_IXOTH:perms[9] = 'x'

# suid/sgid

if mode&stat.S_ISUID:

if perms[3] == 'x': perms[3] = 's'

else: perms[3] = 'S'

if mode&stat.S_ISGID:

if perms[6] == 'x': perms[6] = 's'

else: perms[6] = 'S'

l = perms.tostring()

l += str(s.st_nlink).rjust(5) + ' '

un = str(s.st_uid)

l += un.ljust(9)

gr = str(s.st_gid)

l += gr.ljust(9)

sz = str(s.st_size)

l += sz.rjust(8)

l += ' '

sixmo = 60 * 60 * 24 * 7 * 26

if s.st_mtime + sixmo < time(): # last edited more than 6mo ago

l += strftime("%b %d %Y ", localtime(s.st_mtime))

else:

l += strftime("%b %d %H:%M ", localtime(s.st_mtime))

l += name

return l

開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:49,代碼來源:ls.py

示例15: lsLine

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def lsLine(name, s):

mode = s.st_mode

perms = array.array('c', '-'*10)

ft = stat.S_IFMT(mode)

if stat.S_ISDIR(ft): perms[0] = 'd'

elif stat.S_ISCHR(ft): perms[0] = 'c'

elif stat.S_ISBLK(ft): perms[0] = 'b'

elif stat.S_ISREG(ft): perms[0] = '-'

elif stat.S_ISFIFO(ft): perms[0] = 'f'

elif stat.S_ISLNK(ft): perms[0] = 'l'

elif stat.S_ISSOCK(ft): perms[0] = 's'

else: perms[0] = '!'

# user

if mode&stat.S_IRUSR:perms[1] = 'r'

if mode&stat.S_IWUSR:perms[2] = 'w'

if mode&stat.S_IXUSR:perms[3] = 'x'

# group

if mode&stat.S_IRGRP:perms[4] = 'r'

if mode&stat.S_IWGRP:perms[5] = 'w'

if mode&stat.S_IXGRP:perms[6] = 'x'

# other

if mode&stat.S_IROTH:perms[7] = 'r'

if mode&stat.S_IWOTH:perms[8] = 'w'

if mode&stat.S_IXOTH:perms[9] = 'x'

# suid/sgid

if mode&stat.S_ISUID:

if perms[3] == 'x': perms[3] = 's'

else: perms[3] = 'S'

if mode&stat.S_ISGID:

if perms[6] == 'x': perms[6] = 's'

else: perms[6] = 'S'

l = perms.tostring()

l += str(s.st_nlink).rjust(5) + ' '

un = str(s.st_uid)

l += un.ljust(9)

gr = str(s.st_gid)

l += gr.ljust(9)

sz = str(s.st_size)

l += sz.rjust(8)

l += ' '

sixmo = 60 * 60 * 24 * 7 * 26

if s.st_mtime + sixmo < time.time(): # last edited more than 6mo ago

l += time.strftime("%b %2d %Y ", time.localtime(s.st_mtime))

else:

l += time.strftime("%b %2d %H:%S ", time.localtime(s.st_mtime))

l += name

return l

開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:49,代碼來源:ls.py

示例16: create_files_xml

​點讚 4

# 需要導入模塊: import stat [as 別名]

# 或者: from stat import S_ISUID [as 別名]

def create_files_xml(context, package):

""" Create an XML representation of our files """

files = pisi.files.Files()

global history_timestamp

# TODO: Remove reliance on pisi.util functions completely.

for path in sorted(package.emit_files()):

if path[0] == '/':

path = path[1:]

full_path = os.path.join(context.get_install_dir(), path)

fpath, hash = pisi.util.calculate_hash(full_path)

if os.path.islink(fpath):

fsize = long(len(readlink(full_path)))

st = os.lstat(fpath)

else:

fsize = long(os.path.getsize(full_path))

st = os.stat(fpath)

permanent = package.is_permanent("/" + path)

if not permanent:

permanent = None

else:

permanent = "true"

ftype = get_file_type("/" + path)

if (stat.S_IMODE(st.st_mode) & stat.S_ISUID):

# Preserve compatibility with older eopkg implementation

console_ui.emit_warning("Package", "{} has suid bit set".

format(full_path))

path = path.decode("latin1").encode('utf-8')

file_info = pisi.files.FileInfo(path=path, type=ftype,

permanent=permanent, size=fsize,

hash=hash, uid=str(st.st_uid),

gid=str(st.st_gid),

mode=oct(stat.S_IMODE(st.st_mode)))

files.append(file_info)

fpath = os.path.join(context.get_packaging_dir(), "files.xml")

files.write(fpath)

os.utime(fpath, (history_timestamp, history_timestamp))

return files

開發者ID:solus-project,項目名稱:ypkg,代碼行數:47,

注:本文中的stat.S_ISUID屬性示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值