# Copyright 2026 SigmaSRC, Inc. All Rights Reserved.

"""Gather password file."""

import os

def Gather(collector):
    if os.name != "posix":
        raise RuntimeError("can't gather passwd info on non-POSIX system")
    it = iter(open("/etc/passwd", encoding="utf-8", errors="replace"))
    table = collector.table("passwd",
                            "user passwd uid gid name home shell".split())
    for line in it:
        if line.startswith('#'):
            continue
        if line.endswith("\n"):
            line = line[:-1]
        fields = line.split(":")
        table.add(fields)

def _test():
    from sigma.gather import gathering
    gathering.test(Gather)

if __name__ == "__main__":
    _test()
