Browse Source

another small change to eval_patter. I will keep those two evals as i actually don't see any security impact and performance is good enough

master
Georg Hopp 15 years ago
committed by Georg Hopp
parent
commit
c31be4f4e1
  1. 6
      app/config/storage.yml
  2. 20
      app/storage/config.rb

6
app/config/storage.yml

@ -58,7 +58,7 @@
- 'organizationalRole'
- 'MailAlias'
:dnPat: "cn=#{:user},o=#{:mail|:sub, /.*@/, ''}"
:dnPat: "cn=#{:user},o=#{:mail|/.*@/, ''}"
:map:
:cn: :user
@ -72,7 +72,7 @@
- 'person'
- 'MailAlias'
:dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}"
:dnPat: "mail=#{:mail},o=#{:mail|/.*@/, ''}"
:map:
:sn: :surname
@ -87,7 +87,7 @@
- 'person'
- 'MailAccount'
:dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}"
:dnPat: "mail=#{:mail},o=#{:mail|/.*@/, ''}"
:map:
:homedirectory: :home

20
app/storage/config.rb

@ -19,30 +19,24 @@ class DsAdmin::Storage::Config
##
# replace special patterns within config strings with data
# given by the data hash param. These patterns also allow to send
# a message to the actual substituted data to do any kind of
# conversion to it.
# given by the data hash param. These patterns also allow to
# substitute part of the data giving the argument for a
# String#sub call after a | to it.
#
# actually this is used within the handling of the ldap specific
# :dnPat config parameter to generate the dn entry for a given model
# Data (create or replace)
#
# TODO: I would like to get rid of the eval statements but i don't know
# a better way to build the correct objects from the config strings
#
def eval_pattern(pattern, data = {})
scan_exp = /([^#]*)(#\{(:[^}|]+)(\|([^}]*))?\})?/
result = String.new
pattern.scan(scan_exp) do |m|
key = (eval m[2]) if m[2]
val = data[key] if data[key]
key = eval m[2] if m[2]
msg = eval '[:sub, ' + m[4] + ']' if m[4]
args = m[4].split(',').map do |arg|
eval arg.strip
end if m[4]
val = val.send *args if args
val = data[key] if data[key]
val = val.send *msg if msg
result += m[0] + (val || "")
end

Loading…
Cancel
Save