1
0
forked from Georg/pyacl
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-09-16 02:46:57 +02:00
parent 00cd5f9c94
commit 191c0fac6a
Signed by untrusted user: Georg
GPG Key ID: 1ED2F138E7E6FF57
4 changed files with 130 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
dist
venv
__pycache__

9
pyacl/__init__.py Normal file
View File

@ -0,0 +1,9 @@
"""
pyacl - high level abstractions over pylibacl
Copyright 2024, Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
You may not use this work except in compliance with the Licence.
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
"""

98
pyacl/acl.py Normal file
View File

@ -0,0 +1,98 @@
#!/usr/bin/python3
"""
pyacl - high level abstractions over pylibacl
Copyright 2024, Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
You may not use this work except in compliance with the Licence.
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
"""
import posix1e
myacl = posix1e.ACL(file='/tmp/testacl')
print(myacl)
myentries = list(myacl)
DEFAULT_ENTRIES = [
'u::rw-',
'g::r--',
'm::r--',
'o::r--',
]
DEFAULT_PERMISSIONS = {
'read': None,
'write': None,
'execute': None,
}
DEFAULT_ENTRYTYPES = [
'user',
'group',
'mask',
'other'
]
def acl_reduce_entries(acl):
entries = acl.to_any_text().decode().split()
entries = [entry for entry in entries if entry not in DEFAULT_ENTRIES]
return entries
def acl_parse_permission(strpermission):
if len(strpermission) != 3:
return ValueError('Invalid permission')
permap = {
0: 'read',
1: 'write',
2: 'execute',
}
outmap = DEFAULT_PERMISSIONS.copy()
for i, perm in permap.items():
permval = strpermission[i]
if permval in ['r', 'w', 'x']:
outmap[perm] = True
elif permval == '-':
outmap[perm] = False
else:
return ValueError('Invalid permission flag')
return outmap
def acl_parse_entry(strentry):
if not strentry:
raise ValueError('Got empty string')
entrytype, entryvalue, permissions = strentry.split(':')
if entrytype not in DEFAULT_ENTRYTYPES:
raise ValueError('Invalid entry')
if entryvalue == '':
entryvalue = None
elif not entryvalue:
return ValueError('Invalid entry value')
if len(permissions) != 3:
raise ValueError('Unsupported amount of permissions')
return {
entrytype: {
entryvalue: acl_parse_permission(permissions)
}
}
def acl_parse_entries(acl):
outmap = {
group: DEFAULT_PERMISSIONS for group in DEFAULT_ENTRYTYPES
}
for entry in acl:
outmap.update(acl_parse_entry(entry))
return outmap

20
pyproject.toml Normal file
View File

@ -0,0 +1,20 @@
[build-system]
requires = [
'hatchling',
]
build-backend = 'hatchling.build'
[project]
name = 'pyacl'
description = 'High level abstractions over pylibacl'
version = '0.0.1'
authors = [
{ name='Georg Pfuetzenreuter', email='georg+python@lysergic.dev' },
]
readme = 'README.txt'
requires-python = '>=3.6'
[tool.hatch.build.targets.pyacl]
dependencies = [
'pylibacl',
]