Method: Msf::DataStore#search_for
- Defined in:
- lib/msf/core/data_store.rb
permalink #search_for(key) ⇒ DataStoreSearchResult
Search for a value within the current datastore, taking into consideration any registered aliases, fallbacks, etc.
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/msf/core/data_store.rb', line 443 def search_for(key) k = find_key_case(key) return search_result(:user_defined, @user_defined[k]) if @user_defined.key?(k) option = @options.fetch(k) { @options.find { |option_name, _option| option_name.casecmp?(k) }&.last } if option # If the key isn't present - check any additional fallbacks that have been registered with the option. # i.e. handling the scenario of SMBUser not being explicitly set, but the option has registered a more # generic 'Username' fallback option.fallbacks.each do |fallback| fallback_search = search_for(fallback) if fallback_search.found? return search_result(:option_fallback, fallback_search.value, fallback_key: fallback) end end end # Checking for imported default values, ignoring case again imported_default_match = @defaults.find { |default_key, _default_value| default_key.casecmp?(k) } return search_result(:imported_default, imported_default_match.last) if imported_default_match return search_result(:option_default, option.default) if option search_result(:not_found, nil) end |