From 87d3c6739bb0cf469e8d61e69360aa9a8929fcf5 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Fri, 27 Dec 2013 09:48:03 +0100 Subject: [PATCH] Changed creatation of temp file to use mktemp instead --- Labb7/ovning3.sh | 12 +++++++----- Labb7/ovning3_zenity.sh | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Labb7/ovning3.sh b/Labb7/ovning3.sh index 4977328..ff8fa48 100755 --- a/Labb7/ovning3.sh +++ b/Labb7/ovning3.sh @@ -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 diff --git a/Labb7/ovning3_zenity.sh b/Labb7/ovning3_zenity.sh index 60ceac1..c20d43f 100755 --- a/Labb7/ovning3_zenity.sh +++ b/Labb7/ovning3_zenity.sh @@ -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