PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pam.py

"""
Support for pam
"""

import logging
import os

import salt.utils.files

log = logging.getLogger(__name__)

# Define the module's virtual name
__virtualname__ = "pam"


def __virtual__():
    """
    Set the virtual name for the module
    """
    return __virtualname__


def _parse(contents=None, file_name=None):
    """
    Parse a standard pam config file
    """
    if contents:
        pass
    elif file_name and os.path.exists(file_name):
        with salt.utils.files.fopen(file_name, "r") as ifile:
            contents = salt.utils.stringutils.to_unicode(ifile.read())
    else:
        log.error('File "%s" does not exist', file_name)
        return False

    rules = []
    for line in contents.splitlines():
        if not line:
            continue
        if line.startswith("#"):
            continue
        control_flag = ""
        module = ""
        arguments = []
        comps = line.split()
        interface = comps[0]
        position = 1
        if comps[1].startswith("["):
            control_flag = comps[1].replace("[", "")
            for part in comps[2:]:
                position += 1
                if part.endswith("]"):
                    control_flag += " {}".format(part.replace("]", ""))
                    position += 1
                    break
                else:
                    control_flag += f" {part}"
        else:
            control_flag = comps[1]
            position += 1
        module = comps[position]
        if len(comps) > position:
            position += 1
            arguments = comps[position:]
        rules.append(
            {
                "interface": interface,
                "control_flag": control_flag,
                "module": module,
                "arguments": arguments,
            }
        )
    return rules


def read_file(file_name):
    """
    This is just a test function, to make sure parsing works

    CLI Example:

    .. code-block:: bash

        salt '*' pam.read_file /etc/pam.d/login
    """
    return _parse(file_name=file_name)