-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from base64 import b64decode, b64encode | ||
from collections import namedtuple | ||
|
||
from middlewared.utils.sid import ( | ||
lsa_sidtype | ||
) | ||
from socket import htonl, ntohl | ||
|
||
UNIX_GROUP_KEY_PREFIX = 'UNIXGROUP/' | ||
MEMBEROF_PREFIX = 'MEMBEROF/' | ||
|
||
GROUP_MAP = namedtuple('SMBGroupMap', ['gid', 'sid_type', 'name', 'comment']) | ||
GROUPMEM = namedtuple('SMBGroupMembership', ['sid', 'members']) | ||
|
||
def _parse_unixgroup(tdb_key: str, tdb_val: str) -> GROUP_MAP: | ||
sid = tdb_key[len(UNIX_GROUP_KEY_PREFIX):] | ||
data = b64decode(tdb_val) | ||
|
||
# unix groups are written into tdb file via tdb_pack | ||
gid = htonl(data[0:4]) | ||
sid_type = lsa_sidtype(htonl(data[4:8])) | ||
|
||
# remaining bytes are two null-terminated strings | ||
bname, bcomment = data[8:-1].split(b'\x00') | ||
return GROUP_MAP(gid, sid_type, bname.decode(), bcomment.decode()) | ||
|
||
|
||
def _parse_memberof(tdb_key: str, tdb_val: str) -> GROUP_MEMBER: | ||
sid = tdb_key[len(MEMBEROF_PREFIX):] | ||
data = b64decode(tdb_val) | ||
|
||
members = tuple(data[:-1].decode().split()) | ||
return GROUPMEM(sid, members) |