Skip to content

Commit

Permalink
WIP: facts.server.Users: go through libnss
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 committed Jan 11, 2025
1 parent 3188ad8 commit f0a2ef6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pyinfra/facts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,13 @@ class Users(FactBase):
}
"""

def command(self):
return """
def requires_command(self) -> str:
return "getent"

for i in `cat /etc/passwd | cut -d: -f1`; do
ENTRY=`grep ^$i: /etc/passwd`;
def command(self) -> str:
return """
for i in `getent passwd | cut -d: -f1`; do
ENTRY=`getent passwd | grep ^$i:`;
LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;
LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;
PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;
Expand Down
5 changes: 3 additions & 2 deletions tests/facts/server.Users/mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"freebsd:*:1001:1001:FreeBSD:/home/freebsd:/bin/sh|freebsd|freebsd|freebsd pts/0 10.1.10.10 Thu Aug 31 05:37:58 2023|$bsdpw$",
"freebsdnologin:*:1001:1001:FreeBSD NoLogin:/home/freebsdnologin:/bin/sh|freebsdnologin|freebsdnologin||"
],
"command": "for i in `cat /etc/passwd | cut -d: -f1`; do\n ENTRY=`grep ^$i: /etc/passwd`;\n LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;\n LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;\n PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;\n echo \"$ENTRY|`id -gn $i`|`id -Gn $i`|$LASTLOG|$PASSWORD\";\n done",
"command": "for i in `getent passwd | cut -d: -f1`; do\n ENTRY=`getent passwd | grep ^$i:`;\n LASTLOG_RAW=`(lastlog -u $i 2> /dev/null || lastlogin $i 2> /dev/null)`;\n LASTLOG=`echo $LASTLOG_RAW | grep ^$i | tr -s ' '`;\n PASSWORD=`grep ^$i: /etc/shadow | cut -d: -f2`;\n echo \"$ENTRY|`id -gn $i`|`id -Gn $i`|$LASTLOG|$PASSWORD\";\n done",
"requires_command": "getent",
"fact": {
"root": {
"home": "/root",
Expand Down Expand Up @@ -104,4 +105,4 @@
"password": ""
}
}
}
}

0 comments on commit f0a2ef6

Please sign in to comment.