Hacking Linux Exposed

About
Authors
Contents
Reviews
Foreword
Purchase

Articles
Books
Sourcecode
Tools
Errata

Home

 


(view this code in a separate window)

#!/bin/sh -

# An example of the classic tmpdir hack
# to avoid race conditions.
#
# Use this method if you are on a Unix-like
# system which does not have a mktemp utility



umask 077
DIRNAME=/tmp/foo.$$
if ! mkdir $DIRNAME ; then
            echo "temporary directory already exists, possible attack"
            exit 255
fi
 
TMPFILE=$DIRNAME/tmp.$$


date > $TMPFILE		# for example

( The actual script goes here. )

rm -rf $DIRNAME