mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
lint mysql
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
9885e7683b
commit
d28c5a85fe
1 changed files with 8 additions and 8 deletions
|
@ -2,22 +2,21 @@
|
|||
# copyright: 2015, Vulcano Security GmbH
|
||||
# license: All rights reserved
|
||||
|
||||
$__SCOPE = self
|
||||
|
||||
class MysqlSession < Vulcano.resource(1)
|
||||
name 'mysql_session'
|
||||
|
||||
def initialize(user, pass)
|
||||
@user = user
|
||||
@pass = pass
|
||||
initialize_fallback if user.nil? or pass.nil?
|
||||
init_fallback if user.nil? or pass.nil?
|
||||
skip_resource("Can't run MySQL SQL checks without authentication") if @user.nil? or @pass.nil?
|
||||
end
|
||||
|
||||
def describe(query, db = '', &block)
|
||||
def query(q, db = '')
|
||||
# TODO: simple escape, must be handled by a library
|
||||
# that does this securely
|
||||
escaped_query = query.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
|
||||
escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
|
||||
|
||||
# run the query
|
||||
cmd = vulcano.run_command("mysql -u#{@user} -p#{@pass} #{db} -s -e \"#{escaped_query}\"")
|
||||
out = cmd.stdout + "\n" + cmd.stderr
|
||||
|
@ -25,14 +24,15 @@ class MysqlSession < Vulcano.resource(1)
|
|||
out.downcase =~ /^error/
|
||||
# skip this test if the server can't run the query
|
||||
skip_resource("Can't connect to MySQL instance for SQL checks.")
|
||||
else
|
||||
$__SCOPE.describe(cmd, &block)
|
||||
end
|
||||
|
||||
# return the raw command output
|
||||
cmd
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initialize_fallback
|
||||
def init_fallback
|
||||
# support debian mysql administration login
|
||||
debian = vulcano.run_command('test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf').stdout
|
||||
return if debian.empty?
|
||||
|
|
Loading…
Reference in a new issue