Add support for extended attributes: draft-dekok-radext-radius-extensions
[freeradius.git] / scripts / radsqlrelay
index 75cc91a..92868ed 100755 (executable)
@@ -24,7 +24,7 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with this program; if not, write to the Free Software
-##  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+##  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 ##
 
 use DBI;
@@ -72,7 +72,8 @@ options:
        -?              Print this help message.
        -1              One-shot mode: push the file to database and exit.
        -b database     Name of the database to use.
-       -d sql_driver   Driver to use: mysql, pg.
+       -d sql_driver   Driver to use: mysql, pg, oracle.
+       -f file         Read password from file, instead of command line.
        -h host         Connect to host.
        -P port         Port number to use for connection.
        -p passord      Password to use when connecting to server.
@@ -99,13 +100,15 @@ sub process_file($$)
 {
     my ($dbinfo, $path) = @_;
 
-    until (rename($path, $path.'.work')) {
-       if ($! == ENOENT) {
-           sleep(1);
-           return if $need_exit;
-       } else {
-           print STDERR "error: Couldn't move $path to $path.work: $!\n";
-           exit 1;
+    unless (-e $path.'.work') {
+       until (rename($path, $path.'.work')) {
+           if ($! == ENOENT) {
+               sleep(1);
+               return if $need_exit;
+           } else {
+               print STDERR "error: Couldn't move $path to $path.work: $!\n";
+               exit 1;
+           }
        }
     }
 
@@ -139,7 +142,7 @@ my %args = (
            p => 'radius',
            u => 'radius',
 );
-my $ret = getopts("b:d:fh:P:p:u:x1?", \%args);
+my $ret = getopts("b:d:f:h:P:p:u:x1?", \%args);
 if (!$ret or @ARGV != 1) {
     usage();
     exit 1;
@@ -154,28 +157,37 @@ if (lc($args{d}) eq 'mysql') {
     $data_source = "DBI:mysql:database=$args{b};host=$args{h}";
 } elsif (lc($args{d}) eq 'pg') {
     $data_source = "DBI:Pg:dbname=$args{b};host=$args{h}";
+} elsif (lc($args{d}) eq 'oracle') {
+    $data_source = "DBI:Oracle:$args{b}";
 } else {
     print STDERR "error: SQL driver not supported yet: $args{d}\n";
     exit 1;
 }
 $data_source .= ";port=$args{P}" if $args{'P'};
 
+my $pw;
+if($args{f}) {
+    open(FILE, "< $args{f}") or die "error: Couldn't open $args{f}: $!\n";
+    $pw = <FILE>;
+    chomp($pw);
+    close(FILE);
+} else {
+    # args{p} is always defined.
+    $pw = $args{p};
+}
+
 $SIG{INT} = \&got_signal;
 $SIG{TERM} = \&got_signal;
 
 my %dbinfo = (
              base => $data_source,
              user => $args{u},
-             pass => $args{p},
+             pass => $pw,
 );
 connect_wait(\%dbinfo);
 
 my $path = shift @ARGV;
 
-if (-e $path.'.work') {
-    process_file(\%dbinfo, $path.'.work');
-}
-
 until ($need_exit) {
     process_file(\%dbinfo, $path);
     last if ($args{1} || $need_exit);