File: restricted_from_passwd.py

package info (click to toggle)
denyhosts 2.6-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 444 kB
  • ctags: 420
  • sloc: python: 2,104; sh: 223; makefile: 18
file content (31 lines) | stat: -rwxr-xr-x 906 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/env python
#
############################################################################
# this script will read the /etc/passwd file and extract usernames
# that have one of the RESTRICTED_SHELLS.  The ouput of this
# script is a list of these restricted usernames suitable for
# use in WORK_DIR/restricted-usernames
#
# such as: python restricted_from_passwd > $WORK_DIR/restricted-usernames
# where $WORK_DIR is your DenyHosts WORK_DIR parameter
#
############################################################################

RESTRICTED_SHELLS = ("/sbin/nologin",
                     "/sbin/shutdown",
                     "/sbin/halt")

from pwd import getpwall

passwd = getpwall()

usernames = []
for pw_tuple in passwd:
    if pw_tuple[6] in RESTRICTED_SHELLS:
        usernames.append(pw_tuple[0])

usernames.sort()
for username in usernames:
    print username