Favor MSF_DATABASE_CONFIG for paths['config/database']

MSP-10848

Use these locations, in order for
Metasploit::Framework::Application.config.paths['config/database']:

1. MSF_DATABASE_CONFIG environment variable
2. ~/.msf4/database.yml (if it exists)
3. config/database.yml
bug/bundler_fix
Luke Imhoff 2014-08-05 10:16:33 -05:00
parent 2818b4e2f2
commit 7013a2755b
No known key found for this signature in database
GPG Key ID: 5B1FB01FB33356F8
1 changed files with 15 additions and 4 deletions

View File

@ -33,11 +33,22 @@ module Metasploit
class Application < Rails::Application
include Metasploit::Framework::CommonEngine
user_config_root = Pathname.new(Msf::Config.get_config_root)
user_database_yaml = user_config_root.join('database.yml')
environment_database_yaml = ENV['MSF_DATABASE_CONFIG']
if user_database_yaml.exist?
config.paths['config/database'] = [user_database_yaml.to_path]
if environment_database_yaml
# DO NOT check if the path exists: if the environment variable is set, then the user meant to use this path
# and if it doesn't exist then an error should occur so the user knows the environment variable points to a
# non-existent file.
config.paths['config/database'] = environment_database_yaml
else
user_config_root = Pathname.new(Msf::Config.get_config_root)
user_database_yaml = user_config_root.join('database.yml')
# DO check if the path exists as in test environments there may be no config root, in which case the normal
# rails location, `config/database.yml`, should contain the database config.
if user_database_yaml.exist?
config.paths['config/database'] = [user_database_yaml.to_path]
end
end
end
end