120 Star 0 Fork 18

src-openEuler / freeradius

 / 详情

【21.03】【arm/x86】radsqlrelay -P参数无效

已验收
缺陷
创建于  
2021-03-15 16:45

【环境信息】
系统:21.03
镜像:base和everything
【问题复现步骤】

  1. dnf -y install freeradius freeradius-utils perl-DBD-MySQL mysql5 mysql5-server freeradius-mysql
  2. 启动mysql服务systemctl start mysqld
  3. 修改mysql密码mysqladmin -uroot password Test123
  4. 导入radius常用表mysql -uroot -pTest123 -e "create database radius;
    use radius;
    source /etc/raddb/mods-config/sql/main/mysql/schema.sql;
    "
  5. 修改sql配置文件并软连接
    sed -i 's/driver = "rlm_sql_null"/driver = "rlm_sql_mysql"/g' /etc/raddb/mods-available/sql
    sed -i 's/dialect = "sqlite"/dialect = "mysql"/g' /etc/raddb/mods-available/sql
    sed -i '/server = "localhost"/a server = "localhost"' /etc/raddb/mods-available/sql
    sed -i '/port = 3306/a port = 3306' /etc/raddb/mods-available/sql
    sed -i '/login = "radius"/a login = "root"' /etc/raddb/mods-available/sql
    sed -i '/password = "radpass"/a password = "Test123"' /etc/raddb/mods-available/sql
    ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/
  6. 新增测试文件echo "insert into radcheck (username,attribute,op,value) values ('wjf','Cleartext-Password',':=','wjf123');" >/tmp/radius.sql
  7. 使用任意端口执行命令radsqlrelay -1 -d mysql -b radius -h localhost -p Test123 -u root -P 33 -x /tmp/radius.sql

【预期结果】

  1. 连接数据库失败,该命令进程一直读取/tmp/radius.sql,查询sql没有新增数据

【实际结果】

  1. 连接数据库成功,该命令进程结束,查询sql有数据
    输入图片说明
    输入图片说明

评论 (2)

wjf008 创建了缺陷
wjf008 负责人设置为small_leek
wjf008 里程碑设置为openEuler 21.03-RC2
wjf008 计划开始日期设置为2021-03-15
wjf008 计划截止日期设置为2021-03-16
wjf008 优先级设置为主要
wjf008 关联仓库设置为src-openEuler/freeradius
展开全部操作日志

问题分析
radsqlrelay命令的-P是指定端口号,此处的端口号似乎未生效,radsqlrelay执行完,第一条打印信息如下:

Connecting to DBI:mysql:database=radius;host=localhost;port=33.

从信息中,可以看到port被使用了……

radsqlrelay是perl脚本,最终会调用perl-DBD-MySQL包提供的DBD::connect连接数据库
下面是DBI的使用demo

=head1 NAME 

DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)

=head1 SYNOPSIS

    use DBI; 

    my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
    my $dbh = DBI->connect($dsn, $user, $password);

    my $sth = $dbh->prepare(
        'SELECT id, first_name, last_name FROM authors WHERE last_name = ?')
        or die "prepare statement failed: $dbh->errstr()";
    $sth->execute('Eggers') or die "execution failed: $dbh->errstr()";
    print $sth->rows . " rows found.\n";
    while (my $ref = $sth->fetchrow_hashref()) {
        print "Found a row: id = $ref->{'id'}, fn = $ref->{'first_name'}\n";
    }    
    $sth->finish;


=head1 EXAMPLE

  #!/usr/bin/perl

  use strict;
  use warnings;
  use DBI; 

  # Connect to the database.
  my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
                         "joe", "joe's password",
                         {'RaiseError' => 1}); 

  # Drop table 'foo'. This may fail, if 'foo' doesn't exist
  # Thus we put an eval around it.
  eval { $dbh->do("DROP TABLE foo") };
  print "Dropping foo failed: $@\n" if $@;

从demo中可以看到,当host为localhost时,似乎不需要指定port
关于port,脚本中给出了说明:

=item port

The hostname, if not specified or specified as '' or 'localhost', will
default to a MySQL server running on the local machine using the default for
the UNIX socket. To connect to a MySQL server on the local machine via TCP,
you must specify the loopback IP address (127.0.0.1) as the host.

Should the MySQL server be running on a non-standard port number,
you may explicitly state the port number to connect to in the C<hostname>
argument, by concatenating the I<hostname> and I<port number> together
separated by a colon ( C<:> ) character or by using the  C<port> argument.

To connect to a MySQL server on localhost using TCP/IP, you must specify the
hostname as 127.0.0.1 (with the optional port).

When connecting to a MySQL Server with IPv6, a bracketed IPv6 address should be used.
Example DSN:

  my $dsn = "DBI:mysql:;host=[1a12:2800:6f2:85::f20:8cf];port=3306";

1)如果host不指定,或指定为""或localhost,那么port将不作用,即不使用port
2)如果host指定为ip地址,那么port指定的端口才起作用

验证如下

[root@localhost maminjie]# radsqlrelay -1 -d mysql -b radius -h 127.0.0.1 -u root -p 123456 -P 33 -x test.sql
Connecting to DBI:mysql:database=radius;host=127.0.0.1;port=33.Sleeping for 1 secs.
.Sleeping for 1 secs.
.Sleeping for 1 secs.
.Sleeping for 1 secs.
^C[root@localhost maminjie]# radsqlrelay -1 -d mysql -b radius -h localhost -u root -p 123456 -P 33 -x test.sql
Connecting to DBI:mysql:database=radius;host=localhost;port=33.
Waiting for test.sql
Renamed test.sql to test.sql.work

Opening test.sql.work
Getting file lock
Reading: I.>Table 'radius.wu' doesn't exist
Sleeping for 1 secs.

No more lines to read, doing any final inserts: I
Processed 1 lines
Removing and closing test.sql.work

Disconnecting from database

结论
1)如果host不指定,或指定为""或localhost,那么port将不作用,即不使用port
2)如果host指定为ip地址,那么port指定的端口才起作用

small_leek 任务状态待办的 修改为已完成
wjf008 任务状态已完成 修改为已验收

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
1
https://gitee.com/src-openeuler/freeradius.git
git@gitee.com:src-openeuler/freeradius.git
src-openeuler
freeradius
freeradius

搜索帮助