]> git.sur5r.net Git - bacula/bacula/commitdiff
Apply autochanger temp file security fix to examples files
authorLukáš Nykrýn <lnykryn@redhat.com>
Tue, 25 Oct 2011 10:28:34 +0000 (12:28 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:50:07 +0000 (14:50 +0200)
bacula/examples/autochangers/chio-bacula
bacula/examples/autochangers/chio-changer.Sony-TSL-SA300C
bacula/examples/autochangers/locking-mtx-changer
bacula/examples/autochangers/mtx-changer.Adic-Scalar-100
bacula/examples/autochangers/mtx-changer.Adic-Scalar-24
bacula/examples/autochangers/mtx-changer.StorageTek-HPA4853
bacula/examples/autochangers/solaris-mtx-changer

index d988b0151a138b5798dbf6b3c59833d91588f2c6..e12dc2044f527ac0516880e774a349cd08fe405d 100644 (file)
 # The labels of the virtual barcode reader are located in the BARCODE_FILE
 SIMULATE_BARCODE=true
 BARCODE_FILE=/usr/local/etc/bacula-barcodes
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
 
 me=$(basename $0)
 
@@ -119,11 +132,12 @@ case ${COMMAND} in
 
     loaded)
         # echo "Request loaded"
-        ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
+        make_temp_file
+        ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
         rtn=$?
-        cat /tmp/mtx.$$ | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
-        cat /tmp/mtx.$$ | grep "^drive ${DRIVE}:  source: <>" | awk "{print 0}"
-        rm -f /tmp/mtx.$$
+        cat ${TMPFILE} | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
+        cat ${TMPFILE} | grep "^drive ${DRIVE}:  source: <>" | awk "{print 0}"
+        rm -f ${TMPFILE}
         exit $rtn
         ;;
 
index 758e416ebe7dcbf61e5f8643626cd79c648b5462..6e3505ab5217653a23d69313d084d08927888153 100755 (executable)
 SIMULATE_BARCODE=true
 BARCODE_FILE=/usr/local/etc/bacula-barcodes
 
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
 me=$(basename $0)
 fullpath_me=$0
 
@@ -129,14 +144,15 @@ case ${COMMAND} in
 
     loaded)
         # echo "Request loaded"
-        ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
+        make_temp_file
+        ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
         rtn=$?
-        cat /tmp/mtx.$$ | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
-        drive=`cat /tmp/mtx.$$ | grep "^drive .: <ACCESS>"`
+        cat ${TMPFILE} | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
+        drive=`cat ${TMPFILE}| grep "^drive .: <ACCESS>"`
         if [ -n "$drive" ]; then
                 echo 0
         fi
-        rm -f /tmp/mtx.$$
+        rm -f ${TMPFILE}
         exit $rtn
         ;;
 
index c71169af39dd254b3b461afbd6b32c773a1186b7..78848305b4c5312f099954fe864396fb1a59c6ba 100644 (file)
 MTX=/lysator/bin/mtx
 LOCKDIR=/tmp
 
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
 if test $# -lt 2 ; then
   echo "usage: mtx-changer ctl-device command slot archive-device drive"
   echo "  Insufficient number of arguments arguments given."
@@ -64,14 +79,15 @@ wait_for_drive() {
 LOCKFILE="${LOCKDIR}/mtx-changer:`echo $ctl | tr / _'"
 
 changer_lock() {
-    echo "$$" >$LOCKFILE.$$
+       make_temp_file lock
+    echo "$$" >${TMPFILE}
     
-    while ! ln -n $LOCKFILE.$$ $LOCKFILE 2>/dev/null; do
+    while ! ln -n ${TMPFILE} $LOCKFILE 2>/dev/null; do
        echo "$0: changer lock busy, retrying in 30 seconds..."
        sleep 30
     done
 
-    rm $LOCKFILE.$$
+    rm ${TMPFILE}
 }
 
 changer_unlock() {
@@ -141,11 +157,12 @@ case $cmd in
       ;;
 
    loaded)
-      ${MTX} -f $ctl status >/tmp/mtx.$$
+         make_temp_file
+      ${MTX} -f $ctl status >${TMPFILE}
       rtn=$?
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
-      rm -f /tmp/mtx.$$
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+      rm -f ${TMPFILE}
       changer_unlock $ctl
       exit $rtn
       ;;
index 8c09ba3c3dd9d5ebcae119205afe3df3ced08da2..3795410f7c29cd6d8f999d3a7460545df090e47a 100755 (executable)
@@ -110,6 +110,21 @@ MTX=/usr/local/sbin/mtx
 
 ######################### Functions
 
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
 
 
 
@@ -372,17 +387,18 @@ case "$2" in
 
    loaded)
       echo "Request loaded, DREW YOU HAVEN'T IMPLEMENTED YET!!!!"
-      ${MTX} -f $1 status >/tmp/mtx.$$
+      make_temp_file
+      ${MTX} -f $1 status >${TMPFILE}
       rtn=$?
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print
+      cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print
 \$7}"
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Empty" | awk "{print
+      cat ${TMPFILE} | grep "^Data Transfer Element 0:Empty" | awk "{print
 0}"
-#       cat /tmp/mtx.$$ | grep "^Data Transfer Element 1:Full" | awk "{print
+#       cat ${TMPFILE} | grep "^Data Transfer Element 1:Full" | awk "{print
 \$7}"
-#       cat /tmp/mtx.$$ | grep "^Data Transfer Element 1:Empty" | awk
+#       cat ${TMPFILE} | grep "^Data Transfer Element 1:Empty" | awk
 "{print 0}"
-      rm -f /tmp/mtx.$$
+      rm -f ${TMPFILE}
 
       echo "mtx-changer returning value: $rtn"
       exit $rtn
index 70a7409eee2f1741b7df520565a45c0926abc1b6..eec9e569e8d8449c9406d457c50fb43d91ff7155 100755 (executable)
 
 MTX=/usr/sbin/mtx
 
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
 if test $# -lt 2 ; then
   echo "usage: mtx-changer ctl-device command slot archive-device drive"
   echo "  Insufficient number of arguments arguments given."
@@ -102,12 +117,12 @@ case $cmd in
       ;;
 
    loaded)
-      tempfile=`mktemp -t` || exit 33 
-      ${MTX} -f $ctl status > $tempfile
+      make_temp_file
+      ${MTX} -f $ctl status > ${TMPFILE}
       rtn=$?
-      cat $tempfile | grep "^Data Transfer Element $drive:Full"  | awk '{print $7}'
-      cat $tempfile | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
-      rm -f $tempfile
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full"  | awk '{print $7}'
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
+      rm -f ${TMPFILE}
       exit $rtn
       ;;
 
index d2eacf96a20fc227a7dd7478d77469f6a8b53e2e..25428db9c936bbb721b0f646dbcf8953f3ebe30d 100755 (executable)
 #TAPEDRIVE0 holds the device/name of your 1st and only DLT drive (Bacula supports only 1 drive currently)
 #
 #Read TAPEDRIVE from command line parameters
+
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
+
 if [ -z "$4" ] ; then
   TAPEDRIVE0=/dev/st0 
 else
@@ -51,10 +68,11 @@ case "$2" in
 #
       #Check if you want to fool me
       if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we unload. I Request loaded" ; fi
-      mtx -f $1 status >/tmp/mtx.$$
+      make_temp_file
+      mtx -f $1 status >${TMPFILE}
       rm -f /tmp/mtxloaded
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
-      rm -f /tmp/mtx.$$
+      cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
+      rm -f ${TMPFILE}
       read LOADEDVOL </tmp/mtxloaded
       if [ -z "$LOADEDVOL" ] ; then
          LOADEDVOL=0
@@ -71,10 +89,11 @@ case "$2" in
    load)
       #Let's check if drive is loaded before we load it
       if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we load. I Request loaded" ; fi
-      mtx -f $1 status >/tmp/mtx.$$
+      make_temp_file
+      mtx -f $1 status >${TMPFILE}
       rm -f /tmp/mtxloaded
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
-      rm -f /tmp/mtx.$$
+      cat ${TMPFILE}| grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
+      rm -f ${TMPFILE}
       read LOADEDVOL </tmp/mtxloaded 
       if [ -z "$LOADEDVOL" ] ; then 
          LOADEDVOL=0
@@ -124,10 +143,11 @@ case "$2" in
 
    loaded)
       if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request loaded" ; fi
-      mtx -f $1 status >/tmp/mtx.$$
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" 
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"  
-      rm -f /tmp/mtx.$$
+      make_temp_file
+      mtx -f $1 status >${TMPFILE}
+      cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" 
+      cat ${TMPFILE} | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"  
+      rm -f ${TMPFILE}
       ;;
 
    slots)
index 6f6859585914813f54577b068d2b9d69cc77324d..30bce538c1691b3c5f7251d1b917eec2c46747e6 100755 (executable)
@@ -34,6 +34,22 @@ export PATH="/usr/local/bin:/usr/sfw/bin:/usr/xpg4/bin:/usr/bin"
 
 MTX=mtx
 
+TMPDIR=/tmp
+
+make_temp_file() 
+{
+  TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+  if test $? -ne 0 || test x${TMPFILE} = x; then
+     TMPFILE="${TMPDIR}/mtx$1.$$"
+     if test -f ${TMPFILE}; then
+        echo "ERROR: Temp file security problem on: ${TMPFILE}"
+        exit 1
+     fi
+  fi
+}
+
+
+
 
 #
 # The purpose of this function to wait a maximum 
@@ -142,11 +158,12 @@ case $cmd in
       ;;
 
    loaded)
-      ${MTX} -f $ctl status >/tmp/mtx.$$
+      make_temp_file
+      ${MTX} -f $ctl status >${TMPFILE}
       rtn=$?
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
-      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
-      rm -f /tmp/mtx.$$
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
+      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+      rm -f ${TMPFILE}
       exit $rtn
       ;;