LDP/LDP/guide/docbook/abs-guide/userlist.sh

30 lines
633 B
Bash
Raw Normal View History

2002-04-01 16:05:47 +00:00
#!/bin/bash
# userlist.sh
PASSWORD_FILE=/etc/passwd
n=1 # User number
for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
2002-04-01 16:05:47 +00:00
# Field separator = : ^^^^^^
# Print first field ^^^^^^^^
2012-11-27 14:56:18 +00:00
# Get input from password file /etc/passwd ^^^^^^^^^^^^^^^^^
2002-04-01 16:05:47 +00:00
do
echo "USER #$n = $name"
let "n += 1"
done
# USER #1 = root
# USER #2 = bin
# USER #3 = daemon
# ...
2012-11-27 14:56:18 +00:00
# USER #33 = bozo
2002-04-01 16:05:47 +00:00
2011-08-29 23:59:19 +00:00
exit $?
2005-05-08 20:09:31 +00:00
2011-08-29 23:59:19 +00:00
# Discussion:
# ----------
# How is it that an ordinary user, or a script run by same,
#+ can read /etc/passwd? (Hint: Check the /etc/passwd file permissions.)
2012-11-27 14:56:18 +00:00
# Is this a security hole? Why or why not?