__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- test-case-name: twisted.python.test.test_fakepwd -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
L{twisted.python.fakepwd} provides a fake implementation of the L{pwd} API.
"""
from typing import List, Optional
__all__ = ["UserDatabase", "ShadowDatabase"]
class _UserRecord:
"""
L{_UserRecord} holds the user data for a single user in L{UserDatabase}.
It corresponds to the C{passwd} structure from the L{pwd} module.
See that module for attribute documentation.
"""
def __init__(
self,
name: str,
password: str,
uid: int,
gid: int,
gecos: str,
home: str,
shell: str,
) -> None:
self.pw_name = name
self.pw_passwd = password
self.pw_uid = uid
self.pw_gid = gid
self.pw_gecos = gecos
self.pw_dir = home
self.pw_shell = shell
def __len__(self) -> int:
return 7
def __getitem__(self, index):
return (
self.pw_name,
self.pw_passwd,
self.pw_uid,
self.pw_gid,
self.pw_gecos,
self.pw_dir,
self.pw_shell,
)[index]
class UserDatabase:
"""
L{UserDatabase} holds a traditional POSIX user data in memory and makes it
available via the same API as L{pwd}.
@ivar _users: A C{list} of L{_UserRecord} instances holding all user data
added to this database.
"""
_users: List[_UserRecord]
_lastUID: int = 10101
_lastGID: int = 20202
def __init__(self) -> None:
self._users = []
def addUser(
self,
username: str,
password: str = "password",
uid: Optional[int] = None,
gid: Optional[int] = None,
gecos: str = "",
home: str = "",
shell: str = "/bin/sh",
) -> None:
"""
Add a new user record to this database.
@param username: The value for the C{pw_name} field of the user
record to add.
@param password: The value for the C{pw_passwd} field of the user
record to add.
@param uid: The value for the C{pw_uid} field of the user record to
add.
@param gid: The value for the C{pw_gid} field of the user record to
add.
@param gecos: The value for the C{pw_gecos} field of the user record
to add.
@param home: The value for the C{pw_dir} field of the user record to
add.
@param shell: The value for the C{pw_shell} field of the user record to
add.
"""
if uid is None:
uid = self._lastUID
self._lastUID += 1
if gid is None:
gid = self._lastGID
self._lastGID += 1
newUser = _UserRecord(username, password, uid, gid, gecos, home, shell)
self._users.append(newUser)
def getpwuid(self, uid: int) -> _UserRecord:
"""
Return the user record corresponding to the given uid.
"""
for entry in self._users:
if entry.pw_uid == uid:
return entry
raise KeyError()
def getpwnam(self, name: str) -> _UserRecord:
"""
Return the user record corresponding to the given username.
"""
if not isinstance(name, str):
raise TypeError(f"getpwuam() argument must be str, not {type(name)}")
for entry in self._users:
if entry.pw_name == name:
return entry
raise KeyError()
def getpwall(self) -> List[_UserRecord]:
"""
Return a list of all user records.
"""
return self._users
class _ShadowRecord:
"""
L{_ShadowRecord} holds the shadow user data for a single user in
L{ShadowDatabase}. It corresponds to C{spwd.struct_spwd}. See that class
for attribute documentation.
"""
def __init__(
self,
username: str,
password: str,
lastChange: int,
min: int,
max: int,
warn: int,
inact: int,
expire: int,
flag: int,
) -> None:
self.sp_nam = username
self.sp_pwd = password
self.sp_lstchg = lastChange
self.sp_min = min
self.sp_max = max
self.sp_warn = warn
self.sp_inact = inact
self.sp_expire = expire
self.sp_flag = flag
def __len__(self) -> int:
return 9
def __getitem__(self, index):
return (
self.sp_nam,
self.sp_pwd,
self.sp_lstchg,
self.sp_min,
self.sp_max,
self.sp_warn,
self.sp_inact,
self.sp_expire,
self.sp_flag,
)[index]
class ShadowDatabase:
"""
L{ShadowDatabase} holds a shadow user database in memory and makes it
available via the same API as C{spwd}.
@ivar _users: A C{list} of L{_ShadowRecord} instances holding all user data
added to this database.
@since: 12.0
"""
_users: List[_ShadowRecord]
def __init__(self) -> None:
self._users = []
def addUser(
self,
username: str,
password: str,
lastChange: int,
min: int,
max: int,
warn: int,
inact: int,
expire: int,
flag: int,
) -> None:
"""
Add a new user record to this database.
@param username: The value for the C{sp_nam} field of the user record to
add.
@param password: The value for the C{sp_pwd} field of the user record to
add.
@param lastChange: The value for the C{sp_lstchg} field of the user
record to add.
@param min: The value for the C{sp_min} field of the user record to add.
@param max: The value for the C{sp_max} field of the user record to add.
@param warn: The value for the C{sp_warn} field of the user record to
add.
@param inact: The value for the C{sp_inact} field of the user record to
add.
@param expire: The value for the C{sp_expire} field of the user record
to add.
@param flag: The value for the C{sp_flag} field of the user record to
add.
"""
self._users.append(
_ShadowRecord(
username, password, lastChange, min, max, warn, inact, expire, flag
)
)
def getspnam(self, username: str) -> _ShadowRecord:
"""
Return the shadow user record corresponding to the given username.
"""
if not isinstance(username, str):
raise TypeError(f"getspnam() argument must be str, not {type(username)}")
for entry in self._users:
if entry.sp_nam == username:
return entry
raise KeyError(username)
def getspall(self):
"""
Return a list of all shadow user records.
"""
return self._users
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| _pydoctortemplates | Folder | 0755 |
|
|
| test | Folder | 0755 |
|
|
| __init__.py | File | 598 B | 0644 |
|
| _appdirs.py | File | 828 B | 0644 |
|
| _inotify.py | File | 3.42 KB | 0644 |
|
| _release.py | File | 8.57 KB | 0644 |
|
| _shellcomp.py | File | 24.68 KB | 0644 |
|
| _textattributes.py | File | 8.88 KB | 0644 |
|
| _tzhelper.py | File | 3.12 KB | 0644 |
|
| _url.py | File | 228 B | 0644 |
|
| compat.py | File | 16.42 KB | 0644 |
|
| components.py | File | 13.87 KB | 0644 |
|
| constants.py | File | 460 B | 0644 |
|
| context.py | File | 3.96 KB | 0644 |
|
| deprecate.py | File | 27.49 KB | 0644 |
|
| failure.py | File | 27.43 KB | 0644 |
|
| fakepwd.py | File | 6.88 KB | 0644 |
|
| filepath.py | File | 58.92 KB | 0644 |
|
| formmethod.py | File | 11.82 KB | 0644 |
|
| htmlizer.py | File | 3.54 KB | 0644 |
|
| lockfile.py | File | 7.79 KB | 0644 |
|
| log.py | File | 21.89 KB | 0644 |
|
| logfile.py | File | 9.88 KB | 0644 |
|
| modules.py | File | 26.21 KB | 0644 |
|
| monkey.py | File | 2.23 KB | 0644 |
|
| procutils.py | File | 1.34 KB | 0644 |
|
| randbytes.py | File | 3.43 KB | 0644 |
|
| rebuild.py | File | 6.96 KB | 0644 |
|
| reflect.py | File | 20.02 KB | 0644 |
|
| release.py | File | 1.08 KB | 0644 |
|
| roots.py | File | 7.01 KB | 0644 |
|
| runtime.py | File | 5.79 KB | 0644 |
|
| sendmsg.py | File | 2.62 KB | 0644 |
|
| shortcut.py | File | 2.23 KB | 0644 |
|
| syslog.py | File | 3.57 KB | 0644 |
|
| systemd.py | File | 5.45 KB | 0644 |
|
| text.py | File | 5.28 KB | 0644 |
|
| threadable.py | File | 3.25 KB | 0644 |
|
| threadpool.py | File | 10.65 KB | 0644 |
|
| twisted-completion.zsh | File | 1.34 KB | 0644 |
|
| url.py | File | 244 B | 0644 |
|
| urlpath.py | File | 8.25 KB | 0644 |
|
| usage.py | File | 33.79 KB | 0644 |
|
| util.py | File | 26.86 KB | 0644 |
|
| versions.py | File | 273 B | 0644 |
|
| win32.py | File | 4.66 KB | 0644 |
|
| zippath.py | File | 11.99 KB | 0644 |
|
| zipstream.py | File | 9.45 KB | 0644 |
|