Mantis 402.
authorIain Patterson <me@iain.cx>
Mon, 15 Mar 2010 13:34:50 +0000 (13:34 +0000)
committerIain Patterson <me@iain.cx>
Thu, 18 Mar 2010 15:57:25 +0000 (15:57 +0000)
Don't use mktemp in become and became.  Some systems don't have it and
others want different arguments.

opt/bin/became
opt/bin/become

index 245f75b..694810d 100755 (executable)
@@ -1,11 +1,8 @@
 #!/bin/bash
 
-file="$(mktemp)"
-if [ -n "$file" ]; then
-  ( umask 077; cat > "$file"; echo "/bin/rm -f '$file'" >> "$file" )
-  exec </dev/tty /bin/bash --rcfile "$file"
-else
+file="${TMPDIR:-/tmp}/$SUDO_USER.became.$USER.$RANDOM.$$"
+( umask 077; cat > "$file"; echo "/bin/rm -f '$file'" >> "$file" )
+exec </dev/tty /bin/bash --rcfile "$file"
 # Fall back to the shell.
-  exec </dev/tty /bin/bash
-fi
+exec </dev/tty /bin/bash
 exit 111
index cfc498e..db45e55 100755 (executable)
@@ -37,12 +37,9 @@ BECOME="$HOME/.become"
 profile="$BECOME/$user"
 [ -f "$profile" ] || profile="$BECOME/all"
 
-file="$(mktemp)"
-if [ -n "$file" ]; then
-  exec 3>"$file"
-  exec <"$file"
-  rm "$file"
-
+file="${TMPDIR:-/tmp}/$USER.become.$user.$RANDOM.$$"
+umask 077
+if exec 3>"$file" && exec <"$file" && rm "$file"; then
   echo >&3 "cd"
   echo >&3 "PROFILE_HOME='$HOME'"
   if [ -n "$PRINCIPAL" ]; then
@@ -63,12 +60,14 @@ if [ -n "$file" ]; then
   else
     echo >&3 "unset DISPLAY"
   fi
-
-  echo >&3 2>/dev/null ". $HOME/.bash_profile"
-  [ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
-  [ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
+else
+  exit 111
 fi
 
+echo >&3 ". $HOME/.bash_profile"
+[ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
+[ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
+
 dir=$(dirname "$0")
 [ "$dir" = "." ] && dir="$PWD"
 exec sudo -H -u "$user" "$dir/became"