52 lines
986 B
Bash
Executable File
52 lines
986 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
cd $(dirname $0)
|
|
|
|
# Rational:
|
|
# Test useradd -g checks that the given group exists
|
|
|
|
save()
|
|
{
|
|
[ ! -d tmp ] && mkdir tmp
|
|
for i in passwd group shadow gshadow
|
|
do
|
|
[ -f /etc/$i ] && cp /etc/$i tmp/$i
|
|
done
|
|
|
|
true
|
|
}
|
|
|
|
restore()
|
|
{
|
|
for i in passwd group shadow gshadow
|
|
do
|
|
[ -f tmp/$i ] && cp tmp/$i /etc/$i && rm tmp/$i
|
|
done
|
|
rmdir tmp
|
|
}
|
|
|
|
save
|
|
|
|
# restore the files on exit
|
|
trap 'restore' 0
|
|
|
|
cp data/{passwd,shadow,group,gshadow} /etc/
|
|
|
|
lines_passwd=$(wc -l /etc/passwd | cut -f1 -d" ")
|
|
lines_shadow=$(wc -l /etc/shadow | cut -f1 -d" ")
|
|
lines_group=$(wc -l /etc/group | cut -f1 -d" ")
|
|
lines_gshadow=$(wc -l /etc/gshadow | cut -f1 -d" ")
|
|
|
|
################################################################################
|
|
echo -n "Create user test2 in the non existent group nekral..."
|
|
msg=$(useradd test2 -g nekral 2>&1) && exit 1 || {
|
|
status=$?
|
|
echo status: $status
|
|
test "$status" = "6"
|
|
}
|
|
echo msg: $msg
|
|
test "$msg" = "useradd: unknown group nekral"
|
|
echo "OK"
|