[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bad permissions on /tmp



On Wed, 5 Jan 2000, Marco d'Itri wrote:

> On Jan 04, Jules Bean <jmlb2@hermes.cam.ac.uk> wrote:
>  
>  >Never use /tmp to un-anything files would be one solution.
> Maybe we should put in the default /etc/profile:
> 
> if [ ! -e /tmp/$LOGNAME ]; then
>  mkdir /tmp/$LOGNNAME
> fi
> export TMPNAME=/tmp/$LOGNAME

I think the right variable to use would be TMPDIR, but I like the idea.
However, I would change it to something like this:

if [ -d "/tmp/$LOGNAME" -a ! -h "/tmp/$LOGNAME" ]
then
   if chmod 700 "/tmp/$LOGNAME" 2> /dev/null
   then
      TMPDIR="/tmp/$LOGNAME"
   else
      echo
      echo "A directory /tmp/$LOGNAME exists, but it appears not to be"
      echo "owned by you. Setting TMPDIR to /tmp"
      echo
      TMPDIR="/tmp"
   fi
elsif mkdir "/tmp/$LOGNAME" 2> /dev/null && \
      chmod 700 "/tmp/$LOGNAME" 2> /dev/null
then
   TMPDIR="/tmp/$LOGNAME"
else
   echo
   echo "/tmp/$LOGNAME exists, but it is not a directory or it is"
   echo "not owned by you. Setting TMPDIR to /tmp"
   echo
   TMPDIR=/tmp
fi
export TMPDIR

This would account for an existing "/tmp/$LOGNAME" that might not be a
directory (-d and ! -h tests) or might not be owned by the user in
question (chmod fails). In those cases, it sets TMPDIR to /tmp. If a
regular file or a symbolic link "/tmp/$LOGNAME" exists, mkdir fails and
TMPDIR is set to /tmp.

On my own system, I use TMPDIR="$HOME/tmp", with $HOME/tmp chmod'ed to
700. I can see why somebody would not like to have TMPDIR on /home, but
the idea of one seperate TMPDIR for each user seems attractive to me.

Any comments?

Remco
-- 
rd1936:  9:45pm  up 2 days,  2:24,  8 users,  load average: 2.68, 2.50, 2.28


Reply to: