This repository has been archived by the owner on Dec 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permls
executable file
·56 lines (51 loc) · 1.84 KB
/
permls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# permls - Helper tool for the tests to produce a consistent permission output
# against which we can easily diff.
#
# Copyright (C) 2008 Fabian Knittel <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import sys
import stat
import posix1e
import pwd
import grp
def sorted_depthfirst_walk(root, handler):
for elem in sorted(os.listdir(root)):
elem_path = os.path.join(root, elem)
handler(elem_path)
if os.path.isdir(elem_path):
sorted_depthfirst_walk(os.path.join(root, elem), handler)
def handle_dir_entry(path):
print 'PATH:', path
si = os.stat(path)
print 'user owner: %s' % (pwd.getpwuid(si.st_uid).pw_name)
print 'group owner: %s' % (grp.getgrgid(si.st_gid).gr_name)
mode = stat.S_IMODE(si.st_mode)
if mode & stat.S_ISUID:
print 'user sticky bit'
if mode & stat.S_ISGID:
print 'group sticky bit'
if os.path.isdir(path):
print 'default ACL:'
print posix1e.ACL(filedef = path)
print 'access ACL:'
print posix1e.ACL(file = path)
def main():
handle_dir_entry(sys.argv[1])
sorted_depthfirst_walk(sys.argv[1], handle_dir_entry)
if __name__ == '__main__':
main()