Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Created February 3, 2016 04:08
Show Gist options
  • Save jessepeterson/b1380009b2b2e9e3bd3f to your computer and use it in GitHub Desktop.
Save jessepeterson/b1380009b2b2e9e3bd3f to your computer and use it in GitHub Desktop.
Print files that have a specific length ACL text presentation
#!/usr/bin/python
"""Print files that have a specific length ACL text presentation
Used to debug a backup tool that may have been having problems with files
with this precise ACL representation.
Created by Jesse Peterson on 2/2/16
"""
import sys
import os
from ctypes import *
from ctypes.util import find_library
libc = cdll.LoadLibrary(find_library('c'))
# from <sys/acl.h>
ACL_TYPE_EXTENDED = 0x00000100
acl_get_file = libc.acl_get_file
acl_get_file.argtypes = [c_char_p, c_int]
acl_get_file.restype = c_void_p
acl_to_text = libc.acl_to_text
# note the second ulong here is actually a pointer,
# havn't looked into how to provide a ptr arg yet
acl_to_text.argtypes = [c_void_p, c_ulong]
acl_to_text.restype = c_char_p
acl_free = libc.acl_free
acl_free.argtypes = [c_void_p]
acl_free.restype = c_int
for stdinline in sys.stdin:
if stdinline[-1] == '\n':
filename = stdinline[:-1]
if os.path.exists(filename):
acl = acl_get_file(filename, ACL_TYPE_EXTENDED)
if acl:
textacl = acl_to_text(acl, 0)
modded = len(textacl) % 1024
if modded <= 5 or modded >= 1018:
print len(textacl), modded, filename
acl_free(acl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment