diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2020-03-09 17:40:31 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2020-03-09 17:40:31 +0900 |
commit | ec6542835874ca00e3a777334ee049b5b4cd02e4 (patch) | |
tree | 0e466691d85817335c3d2cec6a72a61ac866e5ac /lib | |
parent | 08e12dd9302c1fd517c642bdd7d274e64b354c53 (diff) | |
parent | 035a04ece237105ba3c91a8db8f81dc81d2dc452 (diff) | |
download | ruby-openssl-ec6542835874ca00e3a777334ee049b5b4cd02e4.tar.gz |
Merge branch 'maint-2.0' into maint
* maint-2.0:
ssl: set verify error code in the case of verify_hostname failure
x509: add error code and verify flags constants
Remove taint support
Restore compatibility with older versions of Ruby.
Fix keyword argument separation issues in OpenSSL::SSL::SSLSocket#sys{read,write}_nonblock
config: support .include directive
Diffstat (limited to 'lib')
-rw-r--r-- | lib/openssl/config.rb | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/lib/openssl/config.rb b/lib/openssl/config.rb index 48d8be00..78a2da9e 100644 --- a/lib/openssl/config.rb +++ b/lib/openssl/config.rb @@ -77,29 +77,44 @@ module OpenSSL def parse_config_lines(io) section = 'default' data = {section => {}} - while definition = get_definition(io) + io_stack = [io] + while definition = get_definition(io_stack) definition = clear_comments(definition) next if definition.empty? - if definition[0] == ?[ + case definition + when /\A\[/ if /\[([^\]]*)\]/ =~ definition section = $1.strip data[section] ||= {} else raise ConfigError, "missing close square bracket" end - else - if /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ =~ definition - if $2 - section = $1 - key = $2 - else - key = $1 + when /\A\.include (\s*=\s*)?(.+)\z/ + path = $2 + if File.directory?(path) + files = Dir.glob(File.join(path, "*.{cnf,conf}"), File::FNM_EXTGLOB) + else + files = [path] + end + + files.each do |filename| + begin + io_stack << StringIO.new(File.read(filename)) + rescue + raise ConfigError, "could not include file '%s'" % filename end - value = unescape_value(data, section, $3) - (data[section] ||= {})[key] = value.strip + end + when /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ + if $2 + section = $1 + key = $2 else - raise ConfigError, "missing equal sign" + key = $1 end + value = unescape_value(data, section, $3) + (data[section] ||= {})[key] = value.strip + else + raise ConfigError, "missing equal sign" end end data @@ -212,10 +227,10 @@ module OpenSSL scanned.join end - def get_definition(io) - if line = get_line(io) + def get_definition(io_stack) + if line = get_line(io_stack) while /[^\\]\\\z/ =~ line - if extra = get_line(io) + if extra = get_line(io_stack) line += extra else break @@ -225,9 +240,12 @@ module OpenSSL end end - def get_line(io) - if line = io.gets - line.gsub(/[\r\n]*/, '') + def get_line(io_stack) + while io = io_stack.last + if line = io.gets + return line.gsub(/[\r\n]*/, '') + end + io_stack.pop end end end |