Add a new "-f" option to read the password from a file,
authornbk <nbk>
Sat, 4 Nov 2006 12:58:14 +0000 (12:58 +0000)
committernbk <nbk>
Sat, 4 Nov 2006 12:58:14 +0000 (12:58 +0000)
instead of command line. (closes: #395)
Thanks to Jakub Wartak <vnull@pcnet.com.pl>

man/man8/radsqlrelay.8
scripts/radsqlrelay

index 801b522..4849c63 100644 (file)
@@ -9,6 +9,8 @@ radsqlrelay - relay SQL queries to a central database server
 .IR sql_driver ]
 .RB [ \-b
 .IR database ]
+.RB [ \-f
+.IR file ]
 .RB [ \-h
 .IR host ]
 .RB [ \-u
@@ -32,6 +34,8 @@ must be configured in the \fBradiusd\fP server before you can use
 Driver to use: mysql, pg, oracle.
 .IP "\-b \fIdatabase\fP"
 Name of the database to use.
+.IP "\-f \fIfile\fP"
+Read password from file, instead of command line.
 .IP "\-h \fIhost\fP"
 Connect to host.
 .IP "\-u \fIuser\fP"
index 05c3274..92868ed 100755 (executable)
@@ -73,6 +73,7 @@ options:
        -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, 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.
@@ -141,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;
@@ -164,13 +165,24 @@ if (lc($args{d}) eq 'mysql') {
 }
 $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);