Fix radsqlrelay debug mode
This commit is contained in:
parent
aefe741205
commit
e1bfbb7ec0
@ -4,7 +4,7 @@
|
||||
|
||||
Name: freeradius
|
||||
Version: 3.0.15
|
||||
Release: 23
|
||||
Release: 24
|
||||
Summary: Remote Authentication Dial-In User Service
|
||||
|
||||
License: GPLv2+ and LGPLv2+
|
||||
@ -23,6 +23,7 @@ Patch6003: remove-unused-arguement.patch
|
||||
Patch6004: backport-CVE-2019-13456.patch
|
||||
Patch6005: CVE-2019-17185.patch
|
||||
Patch6006: Fix-radeapclient-option-q.patch
|
||||
Patch6007: radsqlrelay-actually-do-something-in-debug-mode.patch
|
||||
|
||||
BuildRequires: autoconf gdbm-devel openssl openssl-devel pam-devel zlib-devel net-snmp-devel
|
||||
BuildRequires: net-snmp-utils readline-devel libpcap-devel systemd-units libtalloc-devel
|
||||
@ -438,6 +439,9 @@ exit 0
|
||||
%attr(640,root,radiusd) %config(noreplace) /etc/raddb/mods-available/ldap
|
||||
|
||||
%changelog
|
||||
* Mon May 10 2021 lingsheng <lingsheng@huawei.com> - 3.0.15-24
|
||||
- Fix radsqlrelay debug mode
|
||||
|
||||
* Thu Mar 11 2021 lingsheng <lingsheng@huawei.com> - 3.0.15-23
|
||||
- Fix radeapclient option -q
|
||||
|
||||
|
||||
147
radsqlrelay-actually-do-something-in-debug-mode.patch
Normal file
147
radsqlrelay-actually-do-something-in-debug-mode.patch
Normal file
@ -0,0 +1,147 @@
|
||||
From d3845bea5d9f8dd0269cbc45e840e334fc1f9558 Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
|
||||
Date: Tue, 24 Jul 2018 22:46:59 +0100
|
||||
Subject: [PATCH] radsqlrelay: actually do something in debug mode
|
||||
|
||||
---
|
||||
scripts/sql/radsqlrelay | 28 ++++++++++++++++++++++++++++
|
||||
1 file changed, 28 insertions(+)
|
||||
|
||||
diff --git a/scripts/sql/radsqlrelay b/scripts/sql/radsqlrelay
|
||||
index f72acec0117..e2c1f5ead20 100755
|
||||
--- a/scripts/sql/radsqlrelay
|
||||
+++ b/scripts/sql/radsqlrelay
|
||||
@@ -41,12 +41,18 @@ my $lastinsert;
|
||||
my @values;
|
||||
|
||||
my $need_exit = 0;
|
||||
+my $debug = 0;
|
||||
|
||||
sub got_signal()
|
||||
{
|
||||
$need_exit = 1;
|
||||
}
|
||||
|
||||
+sub debug
|
||||
+{
|
||||
+ print shift if $debug;
|
||||
+}
|
||||
+
|
||||
# /!\ OS-dependent structure
|
||||
# Linux struct flock
|
||||
# short l_type;
|
||||
@@ -91,13 +97,16 @@ sub connect_wait($)
|
||||
{
|
||||
my $dbinfo = shift;
|
||||
my $dbh;
|
||||
+ debug "Connecting to " . $dbinfo->{base};
|
||||
while (!$dbh) {
|
||||
+ debug ".";
|
||||
$dbh = DBI->connect($dbinfo->{base}, $dbinfo->{user}, $dbinfo->{pass},
|
||||
{ RaiseError => 0, PrintError => 0,
|
||||
AutoCommit => 1 });
|
||||
sleep (1) if !$dbh;
|
||||
exit if $need_exit;
|
||||
}
|
||||
+ debug "\n";
|
||||
$dbinfo->{handle} = $dbh;
|
||||
}
|
||||
|
||||
@@ -109,6 +118,7 @@ sub process_file($$)
|
||||
|
||||
sub do_inserts($) {
|
||||
my $dbinfo = shift;
|
||||
+ debug "I";
|
||||
if (scalar(@values) > 0) {
|
||||
my $query = $lastinsert . " ";
|
||||
$query .= join(" ), ( ",@values);
|
||||
@@ -120,6 +130,7 @@ sub process_file($$)
|
||||
|
||||
sub do_query($$) {
|
||||
my ($dbinfo,$query) = @_;
|
||||
+ debug ">";
|
||||
until ($dbinfo->{handle}->do($query)) {
|
||||
print $dbinfo->{handle}->errstr."\n";
|
||||
if ($dbinfo->{handle}->ping) {
|
||||
@@ -133,6 +144,7 @@ sub process_file($$)
|
||||
}
|
||||
|
||||
unless (-e $path.'.work') {
|
||||
+ debug "Waiting for $path\n";
|
||||
until (rename($path, $path.'.work')) {
|
||||
if ($! == ENOENT) {
|
||||
sleep(1);
|
||||
@@ -142,27 +154,35 @@ sub process_file($$)
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
+ debug "Renamed $path to $path.work\n";
|
||||
}
|
||||
|
||||
+ debug "\nOpening $path.work\n";
|
||||
open(FILE, "+< $path.work") or die "error: Couldn't open $path.work: $!\n";
|
||||
+ debug "Getting file lock\n";
|
||||
setlock(\*FILE) or die "error: Couldn't lock $path.work: $!\n";
|
||||
|
||||
$lastinsert = "";
|
||||
@values = ();
|
||||
|
||||
+ debug "Reading: ";
|
||||
+ my $lines = 0;
|
||||
while (<FILE>) {
|
||||
chomp (my $line = $_);
|
||||
+ $lines++;
|
||||
|
||||
if (!($line =~ /^\s*insert\s+into\s+`?\w+`?\s+(?:\(.*?\)\s+)?
|
||||
values\s*\(.*\)\s*;\s*$/ix)) {
|
||||
# This is no INSERT, so start new collection
|
||||
do_inserts($dbinfo);
|
||||
+ debug ".";
|
||||
$lastinsert = "";
|
||||
# must output this line
|
||||
do_query($dbinfo, "$line");
|
||||
|
||||
} else {
|
||||
# This is an INSERT, so collect it
|
||||
+ debug "+";
|
||||
my $insert = $line;
|
||||
my $values = $line;
|
||||
$insert =~ s/^\s*(insert\s+into\s+`?\w+`?\s+(?:\(.*?\)\s+)?
|
||||
@@ -180,13 +200,18 @@ sub process_file($$)
|
||||
|
||||
# limit to $maxcollect collected lines
|
||||
if (scalar(@values) >= $maxcollect) {
|
||||
+ debug "hit maxcollect limit, doing inserts";
|
||||
do_inserts($dbinfo);
|
||||
}
|
||||
}
|
||||
|
||||
# Cleanup
|
||||
+ debug "\nNo more lines to read, doing any final inserts: ";
|
||||
do_inserts($dbinfo);
|
||||
+ debug "\n";
|
||||
|
||||
+ debug "Processed $lines lines\n";
|
||||
+ debug "Removing and closing $path.work\n\n";
|
||||
unlink($path.'.work');
|
||||
close(FILE); # and unlock
|
||||
}
|
||||
@@ -209,6 +234,7 @@ if ($args{'?'}) {
|
||||
usage();
|
||||
exit 0;
|
||||
}
|
||||
+$debug = 1 if $args{'x'};
|
||||
|
||||
my $data_source;
|
||||
if (lc($args{d}) eq 'mysql') {
|
||||
@@ -251,8 +277,10 @@ my $path = shift @ARGV;
|
||||
until ($need_exit) {
|
||||
process_file(\%dbinfo, $path);
|
||||
last if ($args{1} || $need_exit);
|
||||
+ debug "Sleeping\n";
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
+debug "Disconnecting from database\n";
|
||||
$dbinfo{handle}->disconnect;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user