Skip to content

Commit 7013a27

Browse files
committed
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
1 parent 2818b4e commit 7013a27

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

config/application.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,22 @@ module Framework
3333
class Application < Rails::Application
3434
include Metasploit::Framework::CommonEngine
3535

36-
user_config_root = Pathname.new(Msf::Config.get_config_root)
37-
user_database_yaml = user_config_root.join('database.yml')
38-
39-
if user_database_yaml.exist?
40-
config.paths['config/database'] = [user_database_yaml.to_path]
36+
environment_database_yaml = ENV['MSF_DATABASE_CONFIG']
37+
38+
if environment_database_yaml
39+
# DO NOT check if the path exists: if the environment variable is set, then the user meant to use this path
40+
# and if it doesn't exist then an error should occur so the user knows the environment variable points to a
41+
# non-existent file.
42+
config.paths['config/database'] = environment_database_yaml
43+
else
44+
user_config_root = Pathname.new(Msf::Config.get_config_root)
45+
user_database_yaml = user_config_root.join('database.yml')
46+
47+
# DO check if the path exists as in test environments there may be no config root, in which case the normal
48+
# rails location, `config/database.yml`, should contain the database config.
49+
if user_database_yaml.exist?
50+
config.paths['config/database'] = [user_database_yaml.to_path]
51+
end
4152
end
4253
end
4354
end

0 commit comments

Comments
 (0)