Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/lib/fixperms
File: fixperms_ids.py
"""Handles caching user and group database info in memory"""
[0] Fix | Delete
import grp
[1] Fix | Delete
import pwd
[2] Fix | Delete
[3] Fix | Delete
[4] Fix | Delete
class IDCache:
[5] Fix | Delete
"""Handles caching user and group database info in memory"""
[6] Fix | Delete
[7] Fix | Delete
# these lookups are fast, but when looking it up once per file chowned
[8] Fix | Delete
# to form verbose output, it adds up
[9] Fix | Delete
[10] Fix | Delete
def __init__(self, role: str):
[11] Fix | Delete
self._grps = {}
[12] Fix | Delete
self._pwds = {}
[13] Fix | Delete
self._uid2name = {0: 'root'}
[14] Fix | Delete
self._gid2name = {0: 'root'}
[15] Fix | Delete
if role != 'WP3':
[16] Fix | Delete
self.getgrnam('nobody')
[17] Fix | Delete
self.getgrnam('mail')
[18] Fix | Delete
[19] Fix | Delete
def getpwnam(self, name: str) -> pwd.struct_passwd:
[20] Fix | Delete
"""Lookup and cache a struct_passwd by name
[21] Fix | Delete
[22] Fix | Delete
Args:
[23] Fix | Delete
name (str): user name
[24] Fix | Delete
[25] Fix | Delete
Raises:
[26] Fix | Delete
KeyError: user not found in /etc/passwd
[27] Fix | Delete
[28] Fix | Delete
Returns:
[29] Fix | Delete
pwd.struct_passwd: pwd.getpwnam() result
[30] Fix | Delete
"""
[31] Fix | Delete
try:
[32] Fix | Delete
return self._pwds[name]
[33] Fix | Delete
except KeyError:
[34] Fix | Delete
pass
[35] Fix | Delete
try:
[36] Fix | Delete
val = pwd.getpwnam(name)
[37] Fix | Delete
except KeyError as exc:
[38] Fix | Delete
raise KeyError(f"The {name!r} user is missing") from exc
[39] Fix | Delete
self._pwds[name] = val
[40] Fix | Delete
self._uid2name[val.pw_uid] = name
[41] Fix | Delete
return val
[42] Fix | Delete
[43] Fix | Delete
def getgrnam(self, name: str) -> grp.struct_group:
[44] Fix | Delete
"""Lookup and cache a struct_group by name
[45] Fix | Delete
[46] Fix | Delete
Args:
[47] Fix | Delete
name (str): group name
[48] Fix | Delete
[49] Fix | Delete
Raises:
[50] Fix | Delete
KeyError: group not found in /etc/groups
[51] Fix | Delete
[52] Fix | Delete
Returns:
[53] Fix | Delete
grp.struct_group: grp.getgrnam() result
[54] Fix | Delete
"""
[55] Fix | Delete
try:
[56] Fix | Delete
return self._grps[name]
[57] Fix | Delete
except KeyError:
[58] Fix | Delete
pass
[59] Fix | Delete
try:
[60] Fix | Delete
val = grp.getgrnam(name)
[61] Fix | Delete
except KeyError as exc:
[62] Fix | Delete
raise KeyError(f"The {name!r} group is missing") from exc
[63] Fix | Delete
self._grps[name] = val
[64] Fix | Delete
self._gid2name[val.gr_gid] = name
[65] Fix | Delete
return val
[66] Fix | Delete
[67] Fix | Delete
def uid_label(self, uid: int) -> str:
[68] Fix | Delete
"""Lookup and cache a user name by UID
[69] Fix | Delete
[70] Fix | Delete
Args:
[71] Fix | Delete
uid (int): user ID
[72] Fix | Delete
[73] Fix | Delete
Returns:
[74] Fix | Delete
str: user name to display, or string of the uid if it was missing
[75] Fix | Delete
"""
[76] Fix | Delete
assert uid != -1
[77] Fix | Delete
try:
[78] Fix | Delete
return self._uid2name[uid]
[79] Fix | Delete
except KeyError:
[80] Fix | Delete
pass
[81] Fix | Delete
try:
[82] Fix | Delete
val = pwd.getpwuid(uid)
[83] Fix | Delete
except KeyError:
[84] Fix | Delete
self._uid2name[uid] = str(uid)
[85] Fix | Delete
return self._uid2name[uid]
[86] Fix | Delete
self._uid2name[uid] = val.pw_name
[87] Fix | Delete
self._pwds[val.pw_name] = val
[88] Fix | Delete
return self._uid2name[uid]
[89] Fix | Delete
[90] Fix | Delete
def gid_label(self, gid: int) -> str:
[91] Fix | Delete
"""Lookup and cache a group name by GID
[92] Fix | Delete
[93] Fix | Delete
Args:
[94] Fix | Delete
gid (int): group ID
[95] Fix | Delete
[96] Fix | Delete
Returns:
[97] Fix | Delete
str: group name to display, or string of the gid if it was missing
[98] Fix | Delete
"""
[99] Fix | Delete
assert gid != -1
[100] Fix | Delete
try:
[101] Fix | Delete
return self._gid2name[gid]
[102] Fix | Delete
except KeyError:
[103] Fix | Delete
pass
[104] Fix | Delete
try:
[105] Fix | Delete
val = grp.getgrgid(gid)
[106] Fix | Delete
except KeyError:
[107] Fix | Delete
self._gid2name[gid] = str(gid)
[108] Fix | Delete
return self._gid2name[gid]
[109] Fix | Delete
self._gid2name[gid] = val.gr_name
[110] Fix | Delete
self._grps[val.gr_name] = val
[111] Fix | Delete
return self._gid2name[gid]
[112] Fix | Delete
[113] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function