# Copyright 2026 SigmaSRC, Inc. All Rights Reserved.

"""Gather shadow password file.

This requires root permission.
"""

import os

def Gather(collector):
    if os.name != "posix":
        raise RuntimeError("can't gather passwd info on non-POSIX system")
    it = iter(open("/etc/shadow"))
    table = collector.table("shadow",
        "user passwd lastchange min max warn inact expire flag".split())
    for line in it:
        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()
