GA

2023/11/21

MySQL 8.0.35で旧McAfeeのmysql-auditをビルドしてみる

【2023/11/21 15:58】タイトルが8.0.32だったけど8.0.35でした…

TL;DR

  • ビルドしてみただけ。動作確認はしていない

  • MySQL 8.0.35はあらかじめビルドしてある


そのまま素直にビルドできなくなっているのでパッチを3つ用意した


$ git clone git@github.com:yoku0825/mysql-audit.git

$ cd mysql-audit/

$ git checkout support_8035

$ bash bootstrap.sh

bootstrap.sh: line 2: autoreconf: command not found

autoreconfがない…Oracle Linux 8では autoconf パッケージらしい(最後に明示的にインストールしたのはだいぶ前なのでパッケージ名がどうだったか覚えてない…)


$ cat /etc/os-release

NAME="Oracle Linux Server"

VERSION="8.8"

$ dnf provides */bin/autoreconf

..

autoconf-2.69-27.el8.noarch : A GNU tool for automatically configuring source code
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/autoreconf

autoconf-2.69-29.el8.noarch : A GNU tool for automatically configuring source code
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/autoreconf

$ sudo dnf install autoconf

今度は aclocal がないって怒られた。

$ bash bootstrap.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

$ dnf provides */bin/aclocal
..
automake-1.16.1-6.el8.noarch : A GNU tool for automatically creating Makefiles
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/aclocal

automake-1.16.1-7.el8.noarch : A GNU tool for automatically creating Makefiles
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/aclocal

$ sudo dnf install automake

その次はlibtoolが無い。

$ bash bootstrap.sh
..
configure.ac:83: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1

$ sudo dnf install libtool

取り敢えずbootstrapまで終わった。

$ bash bootstrap.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config-aux'.
libtoolize: copying file 'config-aux/ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:82: installing 'config-aux/compile'
configure.ac:7: installing 'config-aux/config.guess'
configure.ac:7: installing 'config-aux/config.sub'
configure.ac:41: installing 'config-aux/install-sh'
configure.ac:41: installing 'config-aux/missing'
src/Makefile.am: installing 'config-aux/depcomp'
autoreconf: Leaving directory `.'

configure スクリプトの中身はいつも --help で見る派。よくあるパターンでソースコードの場所を指定する。

$ ./configure --help

..

$ mkdir /home/yoku0825/audit_plugin
$ ./configure --with-mysql=/home/yoku0825/mysql/src/mysql-8.0.35 --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
checking for mysql source code... configure: error: Failed to find required header file include/mysql_version.h in /usr/mysql/src/mysql-8.0.35, check the path and make sure you've run './configure ..<options>.. && cd include && make' in MySQL 5.1 sources dir or 'cmake . && make' in MySQL 5.5 sources dir.

ソースコードのディレクトリじゃなくてビルドしたディレクトリが必要だったらしい。 (8.0からインソースビルドするにはMySQLのcmakeに -DFORCE_INSOURCE_BUILD=ON が必要)

$ ./configure --with-mysql=/home/yoku0825/mysql/src/build_8.0.35  --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
checking for mysql source code... configure: error: Failed to find required header file include/my_dir.h in /usr/mysql/src/build_8.0.35, check the path and make sure you've run './configure ..<options>.. && cd include && make' in MySQL 5.1 sources dir or 'cmake . && make' in MySQL 5.5 sources dir.

また違うファイルがつかめずに転けた。これインソースビルドしないとダメなんだろうか…。ということでインソースビルドしたディレクトリを用意。

$ ./configure --with-mysql=/home/yoku0825/mysql/src/insource_build_8.0.35/ --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
Version: 1.0.0-99999 Symbol version: 1_0_0_99999
no

checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating yajl/Makefile
config.status: creating yajl/src/Makefile
config.status: creating udis86/Makefile
config.status: creating udis86/libudis86/Makefile
config.status: creating include/_config.h
config.status: executing depfiles commands
config.status: executing libtool commands

/usr/bin/rm: cannot remove 'libtoolT': No such file or directory
configure: CPPFLAGS:  -g -O2 -DDBUG_OFF -DNDEBUG -Werror -Wall -DMYSQL_AUDIT_PLUGIN_VERSION='"1.0.0"' -DMYSQL_AUDIT_PLUGIN_REVISION='"99999"' '-DMYSQL_AUDIT_PLUGIN_SYMBOL_VERSION()=extern const char audit_plugin_version_1_0_0_99999'

configureは成功した。

$ make
..
Making all in udis86
make[1]: Entering directory '/home/yoku0825/git/mysql-audit/udis86'
Making all in libudis86
make[2]: Entering directory '/home/yoku0825/git/mysql-audit/udis86/libudis86'
python ./opgen.py
  File "./opgen.py", line 259
    print "error: no mnemonic given in <instruction>."
                                                     ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("error: no mnemonic given in <instruction>.")?
make[2]: *** [Makefile:662: itab.c] Error 1
make[2]: Leaving directory '/home/yoku0825/git/mysql-audit/udis86/libudis86'
make[1]: *** [Makefile:371: all-recursive] Error 1
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/udis86'
make: *** [Makefile:426: all-recursive] Error 1

print ".." が print("..") でなければならないのはPython3のアレだとして、切り分けのためにPython 2.7に取り替えてみた。

$ python
Python 3.6.8 (default, Jun 14 2023, 10:42:30)

$ sudo dnf install python2
$ sudo alternatives --config python

There are 4 programs which provide 'python'.

  Selection    Command
-----------------------------------------------
*  1           /usr/libexec/no-python
   2           /usr/bin/python3.9
 + 3           /usr/bin/python3
   4           /usr/bin/python2

Enter to keep the current selection[+], or type selection number: 4

$ python --version
Python 2.7.18

$ make
..
/usr/mysql/src/insource_build_8.0.35/sql/query_term.h:630:12: error: 'if constexpr' only available with -std=c++17 or -std=gnu++17 [-Werror]
         if constexpr (visit_leaves == VL_VISIT_LEAVES)                                                                                                                                                                     ^~~~~~~~~                                                                                                   

cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:480: hot_patch.lo] Error 1
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make: *** [Makefile:426: all-recursive] Error 1

エラーが変わったのでどうやらこの opgen.py はこれで良い(?)らしい。新しいのは -std=c++17 で対処できそうなのでconfigureしなおし。

$ CPPFLAGS="-std=c++17" ./configure --with-mysql=/home/yoku0825/mysql/src/insource_build_8.0.35/ --with-mysql-plugindir=/home/yoku0825/audit_plugin
$ make
..
/home/yoku0825/git/mysql-audit/pcre/missing: line 81: aclocal-1.15: command not found
WARNING: 'aclocal-1.15' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <http://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <http://www.gnu.org/software/autoconf>
         <http://www.gnu.org/software/m4/>
         <http://www.perl.org/>
make[2]: *** [Makefile:1357: aclocal.m4] Error 127
make[2]: Leaving directory '/home/yoku0825/git/mysql-audit/pcre'
make[1]: *** [Makefile:715: ../pcre/libpcre.la] Error 2
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make: *** [Makefile:426: all-recursive] Error 1

今更aclocal-1.15を欲しがられる。boostrap.shの時点で言ってくれてもいいのよ…。

$ /usr/bin/aclocal --version
aclocal (GNU automake) 1.16.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.

ちなみにこれCentOS7だとaclocal-1.13なのでやっぱり嫌がられる。

$ sudo ln -s /usr/bin/aclocal-1.16 /usr/bin/aclocal-1.15
$ sudo ln -s /usr/bin/automake-1.16 /usr/bin/automake-1.15

1.13 -> 1.15へのリンクは憚られたけど、1.16 -> 1.15なら互換性あるかなと軽く思い込んでシンボリックリンクで済ませてしまう()

$ make
..
libtool: link: rm -fr .libs/libaudit_plugin.lax
libtool: link: ( cd ".libs" && rm -f "libaudit_plugin.la" && ln -s "../libaudit_plugin.la" "libaudit_plugin.la" )
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make[1]: Entering directory '/home/yoku0825/git/mysql-audit'
make[1]: Nothing to be done for 'all-am'.
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit'

$ make install
..

$ ll /home/yoku0825/audit_plugin/
total 17040
-rw-r--r--. 1 yoku0825 yoku0825 12445670 Nov 21 04:57 libaudit_plugin.a
-rwxr-xr-x. 1 yoku0825 yoku0825      996 Nov 21 04:57 libaudit_plugin.la
lrwxrwxrwx. 1 yoku0825 yoku0825       24 Nov 21 04:57 libaudit_plugin.so -> libaudit_plugin.so.0.0.0
lrwxrwxrwx. 1 yoku0825 yoku0825       24 Nov 21 04:57 libaudit_plugin.so.0 -> libaudit_plugin.so.0.0.0
-rwxr-xr-x. 1 yoku0825 yoku0825  4994296 Nov 21 04:57 libaudit_plugin.so.0.0.0

出来上がった。

$ bash ./offset-extract/offset-extract.sh /usr/mysql/8.0.35/bin/mysqld
//offsets for: /usr/mysql/8.0.35/bin/mysqld (8.0.35)
{"8.0.35","d9bdda3fe1822230d5b5d265b9359ffc", 9496, 9536, 4952, 6436, 1288, 0, 0, 32, 64, 160, 1376, 9636, 6056, 4248, 4256, 4260, 7720, 1576, 32, 8680, 8720, 8704, 12880, 140, 664, 320},

あとはこれで.soファイルをコピーしてmy.cnfを編集してINSTALL PLUGINしたりすれば一応動きそう

0 件のコメント :

コメントを投稿