#!/bin/sh
GS=gs
tmpdir=/tmp
cat <<EOF >$tmpdir/gsQuit
quit
EOF
cat <<EOF >$tmpdir/gsTest
($tmpdir/gsQuit) (r) file quit
EOF

cat <<EOF >$tmpdir/gsTestSameDir
(gsQuit) (r) file quit
EOF


  echo "checking GhostScript -dSAFER and -dPARANOIDSAFER option"
  if ! $GS -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- $tmpdir/gsQuit ; then
	echo ERROR
	exit 1
  fi
  if $GS -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- $tmpdir/gsTest 1>/dev/null 2>/dev/null ; then
  	  cat <<EOF
WARNING: '($GS) -dSAFER -dPARANOIDSAFER ' allows files to be read
Please read README.GhostScriptSecurityProblem
and fix your distribution of GhostScript
EOF
		exit 1
  fi
  cd $tmpdir
  if $GS -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- gsTestSameDir 1>/dev/null 2>/dev/null ; then
	cat <<EOF;
WARNING: '($GS) -dSAFER -dPARANOIDSAFER ' allows files
in same directory to be read.
Please read README.GhostScriptSecurityProblem
and fix your distribution of GhostScript
EOF
	exit 1
  fi

