<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -5,6 +5,7 @@
 # Works with mysql and postgresql
 #
 use POSIX;
+use File::Temp;
 
 $conf=shift||'/usr/local/dialup_admin/conf/admin.conf';
 $back_days = 35;
@@ -42,11 +43,10 @@ if (POSIX::strftime(&quot;%Y-%m-%d %T&quot;,localtime) eq $date){
 
 $query = &quot;DELETE FROM $sql_accounting_table WHERE AcctStopTime IS NULL AND AcctStartTime &lt; '$date';&quot;;
 print &quot;$query\n&quot;;
-open TMP, &quot;&gt;/tmp/clean_radacct.query&quot;
-        or die &quot;Could not open tmp file\n&quot;;
-print TMP $query;
-close TMP;
-$command = &quot;$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database &lt;/tmp/clean_radacct.query&quot; if ($sql_type eq 'mysql');
-$command = &quot;$sqlcmd  -U $sql_username -f /tmp/clean_radacct.query $sql_database&quot; if ($sql_type eq 'pg');
-$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt;/tmp/clean_radacct.query&quot; if ($sql_type eq 'sqlrelay');
+my ($fh, $tmp_filename) = tempfile() or die &quot;Could not open tmp file\n&quot;;
+print $fh $query;
+close $fh;
+$command = &quot;$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database &lt; $tmp_filename&quot; if ($sql_type eq 'mysql');
+$command = &quot;$sqlcmd  -U $sql_username -f  $tmp_filename $sql_database&quot; if ($sql_type eq 'pg');
+$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt; $tmp_filename&quot; if ($sql_type eq 'sqlrelay');
 `$command`;</diff>
      <filename>dialup_admin/bin/clean_radacct</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,7 @@
 
 use Date::Manip qw(ParseDate UnixDate);
 use Digest::MD5;
+use File::Temp;
 $|=1;
 
 $file=shift||'none';
@@ -29,7 +30,8 @@ $all_file=shift||'no';
 # CHANGE THESE TO MATCH YOUR SETUP
 #
 #$regexp = 'from client localhost port 135|from client blabla ';
-$tmpfile='/var/tmp/sql.input';
+$tmpdir=tempdir( CLEANUP =&gt; 1 );
+$tmpfile=&quot;$tmpdir/sql.input&quot;;
 #
 $verbose = 0;
 #</diff>
      <filename>dialup_admin/bin/log_badlogins</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 #!/usr/bin/perl
 use POSIX;
+use File::Temp;
 
 # Log in the mtotacct table aggregated accounting information for
 # each user spaning in one month period.
@@ -51,14 +52,13 @@ $query2 = &quot;INSERT INTO mtotacct (UserName,AcctDate,ConnNum,ConnTotDuration,
 	AcctDate &lt;= '$date_end' GROUP BY UserName,NASIPAddress;&quot;;
 print &quot;$query1\n&quot;;
 print &quot;$query2\n&quot;;
-open TMP, &quot;&gt;/tmp/tot_stats.query&quot;
-	or die &quot;Could not open tmp file\n&quot;;
-print TMP &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
-print TMP $query1;
-print TMP $query2;
-close TMP;
-$command = &quot;$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database &lt;/tmp/tot_stats.query&quot; if ($sql_type eq 'mysql');
-$command = &quot;$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database&quot; if ($sql_type eq 'pg');
+my ($fh, $tmp_filename) = tempfile() or die &quot;Could not open tmp file\n&quot;;
+print $fh &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
+print $fh $query1;
+print $fh $query2;
+close $fh;
+$command = &quot;$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database &lt; $tmp_filename&quot; if ($sql_type eq 'mysql');
+$command = &quot;$sqlcmd  -U $sql_username -f  $tmp_filename $sql_database&quot; if ($sql_type eq 'pg');
 $command = &quot;$sqlcmd  $sql_username/$pass&quot; . &quot;@&quot; . &quot;$sql_database &lt;$tmpfile.$server&quot; if ($sql_type eq 'oracle');
-$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt;/tmp/tot_stats.query&quot; if ($sql_type eq 'sqlrelay');
+$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt; $tmp_filename&quot; if ($sql_type eq 'sqlrelay');
 `$command`;</diff>
      <filename>dialup_admin/bin/monthly_tot_stats</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 #!/usr/bin/perl
 use POSIX;
+use File::Temp;
 
 # Log in the totacct table aggregated daily accounting information for
 # each user.
@@ -48,14 +49,13 @@ $query2 = &quot;INSERT INTO totacct (UserName,AcctDate,ConnNum,ConnTotDuration,
 	AcctStopTime &lt; '$date_end' GROUP BY UserName,NASIPAddress;&quot;;
 print &quot;$query1\n&quot;;
 print &quot;$query2\n&quot;;
-open TMP, &quot;&gt;/tmp/tot_stats.query&quot;
-	or die &quot;Could not open tmp file\n&quot;;
-print TMP &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
-print TMP $query1;
-print TMP $query2;
-close TMP;
-$command = &quot;$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database &lt;/tmp/tot_stats.query&quot; if ($sql_type eq 'mysql');
-$command = &quot;$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database&quot; if ($sql_type eq 'pg');
+my ($fh, $tmp_filename) = tempfile() or die &quot;Could not open tmp file\n&quot;;
+print $fh &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
+print $fh $query1;
+print $fh $query2;
+close $fh;
+$command = &quot;$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database &lt; $tmp_filename&quot; if ($sql_type eq 'mysql');
+$command = &quot;$sqlcmd  -U $sql_username -f  $tmp_filename $sql_database&quot; if ($sql_type eq 'pg');
 $command = &quot;$sqlcmd  $sql_username/$pass&quot; . &quot;@&quot; . &quot;$sql_database &lt;$tmpfile.$server&quot; if ($sql_type eq 'oracle');
-$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt;/tmp/tot_stats.query&quot; if ($sql_type eq 'sqlrelay');
+$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt; $tmp_filename&quot; if ($sql_type eq 'sqlrelay');
 `$command`;</diff>
      <filename>dialup_admin/bin/tot_stats</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@
 # Works with mysql and postgresql
 #
 use POSIX;
+use File::Temp;
 
 $conf=shift||'/usr/local/dialup_admin/conf/admin.conf';
 $back_days = 90;
@@ -44,13 +45,12 @@ $query = &quot;LOCK TABLES $sql_accounting_table WRITE;&quot; if ($sql_type eq 'mysql');
 $query .= &quot;DELETE FROM $sql_accounting_table WHERE AcctStopTime &lt; '$date' AND AcctStopTime IS NOT NULL ;&quot;;
 $query .= &quot;UNLOCK TABLES;&quot; if ($sql_type eq 'mysql');
 print &quot;$query\n&quot;;
-open TMP, &quot;&gt;/tmp/truncate_radacct.query&quot;
-        or die &quot;Could not open tmp file\n&quot;;
-print TMP &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
-print TMP $query;
-close TMP;
-$command = &quot;$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database &lt;/tmp/truncate_radacct.query&quot; if ($sql_type eq 'mysql');
-$command = &quot;$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database&quot; if ($sql_type eq 'pg');
+my ($fh, $tmp_filename) = tempfile() or die &quot;Could not open tmp file\n&quot;;
+print $fh &quot;ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM';\n&quot; if ($sql_type eq 'oracle');
+print $fh $query;
+close $fh;
+$command = &quot;$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database &lt; $tmp_filename&quot; if ($sql_type eq 'mysql');
+$command = &quot;$sqlcmd  -U $sql_username -f  $tmp_filename $sql_database&quot; if ($sql_type eq 'pg');
 $command = &quot;$sqlcmd  $sql_username/$pass&quot; . &quot;@&quot; . &quot;$sql_database &lt;$tmpfile.$server&quot; if ($sql_type eq 'oracle');
-$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt;/tmp/truncate_radacct.query&quot; if ($sql_type eq 'sqlrelay');
+$command = &quot;$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' &lt; $tmp_filename&quot; if ($sql_type eq 'sqlrelay');
 `$command`;</diff>
      <filename>dialup_admin/bin/truncate_radacct</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1e85251f1014c21f3f2d7525aa8773ee925ef2a8</id>
    </parent>
  </parents>
  <author>
    <name>Alan T. DeKok</name>
    <email>aland@freeradius.org</email>
  </author>
  <url>http://github.com/Antti/freeradius-server/commit/57d9720a48961b55027d50745c74cb23938f1523</url>
  <id>57d9720a48961b55027d50745c74cb23938f1523</id>
  <committed-date>2008-12-02T01:15:46-08:00</committed-date>
  <authored-date>2008-12-02T01:11:38-08:00</authored-date>
  <message>Fix for CVE-2008-4474

Dialup-admin uses tmp files insecurely.  Since it isn't running
in a default install, this shouldn't be a major problem.

Patch from bug #605</message>
  <tree>6ff41914fd637da07bcb9931dc3f8c93c23dbd28</tree>
  <committer>
    <name>Alan T. DeKok</name>
    <email>aland@freeradius.org</email>
  </committer>
</commit>
