Intrusion Exploit
Server: LiteSpeed
System: Linux cisadane.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: lenf4658 (1805)
PHP: 8.4.19
Disabled: NONE
Upload Files
File: //proc/thread-self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/fs.py
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2024 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
import functools
import grp

import secureio
from clcommon import ClPwd

from .const import BASEDIR
from .exceptions import UserNotFoundError


def get_user_prefix(username) -> str:
    base = 100
    try:
        uid = secureio.clpwd.get_uid(username)
    except ClPwd.NoSuchUserException:
        raise UserNotFoundError(username)
    b = uid % base
    prefix = "%02d" % b
    return prefix


def get_var_cagefs_prefixed(username):
    prefix = get_user_prefix(username)
    return f"{BASEDIR}/{prefix}"


def get_user_var_cagefs_path(username):
    return f"{get_var_cagefs_prefixed(username)}/{username}/"


@functools.cache
def get_linksafe_gid() -> int | None:
    try:
        return grp.getgrnam('linksafe').gr_gid
    except KeyError:
        return None


def user_exists(user):
    return user in secureio.clpwd.get_user_dict()