Changed creatation of temp file to use mktemp instead

This commit is contained in:
Jack-Benny Persson 2013-12-27 09:48:03 +01:00
parent ec6f3c7ec7
commit 87d3c6739b
2 changed files with 11 additions and 8 deletions

View File

@ -13,17 +13,19 @@ Dialog="/usr/bin/dialog"
Grep="/bin/grep"
Cat="/bin/cat"
Rm="/bin/rm"
Temp=`mktemp -t createuser.XXXX` # This is safer than just creating the file
# manualy, since it will be chmod 600 now
# Functions
ask()
{
$Dialog --backtitle "Create new user" --inputbox "$1" 10 60\
2> /tmp/createuser
2> $Temp
if [ $? -eq 255 ]; then
echo "Aborting, user hit ESC"
exit 1
fi
Input=`$Cat /tmp/createuser`
Input=`$Cat $Temp`
}
@ -53,19 +55,19 @@ HowMany=`echo $Shell | wc -w` # How many shells are avaliable?
$Dialog --backtitle "Create new user"\
--menu "Choose a shell for your new user" 14 60 $HowMany $ShellList\
2> /tmp/createuser
2> $Temp
if [ $? -eq 255 ]; then
echo "Aborting, user hit ESC"
exit 1
fi
Input=`$Cat /tmp/createuser`
Input=`$Cat $Temp`
UserShell=$Input
ask "Enter a password for the new user"
Password=$Input
# Remove the temp file (it contains the password of latest created user)
$Rm /tmp/createuser
$Rm $Temp
# Create the user and set the password
$Useradd -m -s $UserShell $Username

View File

@ -13,6 +13,7 @@ Zenity="/usr/bin/zenity"
Grep="/bin/grep"
Cat="/bin/cat"
Rm="/bin/rm"
Temp=`mktemp -t createuser.XXXXXX`
# Functions
ask()
@ -22,12 +23,12 @@ ask()
--add-entry="Full path of shell" \
--add-entry="Comment (Full name etc)" \
--add-password="Password" \
> /tmp/createuser
> $Temp
if [ $? -eq 1 ]; then
echo "Aborting, user hit cancel..."
exit 1
fi
Input=`$Cat /tmp/createuser`
Input=`$Cat $Temp`
}
extract_data()
@ -61,7 +62,7 @@ ask
extract_data
# Remove temp file for security reasons
$Rm /tmp/createuser
$Rm $Temp
# Create the user and set the password
$Useradd -m -s $UserShell -c "$Comment" $Username