HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/apport/user_group.py
# Copyright (C) 2023 Canonical Ltd.
# Author: Benjamin Drung <benjamin.drung@canonical.com>
# SPDX-License-Identifier: GPL-2.0-or-later

"""Functions around users and groups."""

import dataclasses
import os


@dataclasses.dataclass()
class UserGroupID:
    """Pair of user and group ID."""

    uid: int
    gid: int

    def is_root(self) -> bool:
        """Check if the user or group ID is root."""
        return self.uid == 0 or self.gid == 0


def get_process_user_and_group() -> UserGroupID:
    """Return the current process’s real user and group."""
    return UserGroupID(os.getuid(), os.getgid())