Skip to content

Instantly share code, notes, and snippets.

@krisk0
Created October 9, 2024 11:43
Show Gist options
  • Save krisk0/e50cd53bd78d79fde62486f772aabdf8 to your computer and use it in GitHub Desktop.
Save krisk0/e50cd53bd78d79fde62486f772aabdf8 to your computer and use it in GitHub Desktop.
List files and directories with GID/UID bit set
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, pathlib, stat
g_both,g_uid,g_gid = [],[],[]
g_both_bits = stat.S_ISUID | stat.S_ISGID
def visit_file(f):
try:
p = os.stat(f)[stat.ST_MODE]
except:
return
if p & g_both_bits == g_both_bits:
g_both.append(f)
elif p & stat.S_ISUID:
g_uid.append(f)
elif p & stat.S_ISGID:
g_gid.append(f)
def show_slave(ff, mes):
if not ff:
return
print('Установлен %s:' % mes)
ff.sort()
for f in ff:
print(' ' + f)
def show():
show_slave(g_both, 'UID и GID')
show_slave(g_uid, 'UID')
show_slave(g_gid, 'GID')
for g_x in pathlib.Path('.').rglob('*'):
if not g_x.is_symlink():
visit_file(str(g_x))
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment