Commit c31be4f4e1bfe957d538bf952e12304a6a5fe8d1
Committed by
Georg Hopp
1 parent
14471a2f
another small change to eval_patter. I will keep those two evals as i actually d…
…on't see any security impact and performance is good enough
Showing
2 changed files
with
10 additions
and
16 deletions
... | ... | @@ -58,7 +58,7 @@ |
58 | 58 | - 'organizationalRole' |
59 | 59 | - 'MailAlias' |
60 | 60 | |
61 | - :dnPat: "cn=#{:user},o=#{:mail|:sub, /.*@/, ''}" | |
61 | + :dnPat: "cn=#{:user},o=#{:mail|/.*@/, ''}" | |
62 | 62 | |
63 | 63 | :map: |
64 | 64 | :cn: :user |
... | ... | @@ -72,7 +72,7 @@ |
72 | 72 | - 'person' |
73 | 73 | - 'MailAlias' |
74 | 74 | |
75 | - :dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}" | |
75 | + :dnPat: "mail=#{:mail},o=#{:mail|/.*@/, ''}" | |
76 | 76 | |
77 | 77 | :map: |
78 | 78 | :sn: :surname |
... | ... | @@ -87,7 +87,7 @@ |
87 | 87 | - 'person' |
88 | 88 | - 'MailAccount' |
89 | 89 | |
90 | - :dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}" | |
90 | + :dnPat: "mail=#{:mail},o=#{:mail|/.*@/, ''}" | |
91 | 91 | |
92 | 92 | :map: |
93 | 93 | :homedirectory: :home | ... | ... |
... | ... | @@ -19,30 +19,24 @@ class DsAdmin::Storage::Config |
19 | 19 | |
20 | 20 | ## |
21 | 21 | # replace special patterns within config strings with data |
22 | - # given by the data hash param. These patterns also allow to send | |
23 | - # a message to the actual substituted data to do any kind of | |
24 | - # conversion to it. | |
22 | + # given by the data hash param. These patterns also allow to | |
23 | + # substitute part of the data giving the argument for a | |
24 | + # String#sub call after a | to it. | |
25 | 25 | # |
26 | 26 | # actually this is used within the handling of the ldap specific |
27 | 27 | # :dnPat config parameter to generate the dn entry for a given model |
28 | 28 | # Data (create or replace) |
29 | 29 | # |
30 | - # TODO: I would like to get rid of the eval statements but i don't know | |
31 | - # a better way to build the correct objects from the config strings | |
32 | - # | |
33 | 30 | def eval_pattern(pattern, data = {}) |
34 | 31 | scan_exp = /([^#]*)(#\{(:[^}|]+)(\|([^}]*))?\})?/ |
35 | 32 | |
36 | 33 | result = String.new |
37 | 34 | pattern.scan(scan_exp) do |m| |
38 | - key = (eval m[2]) if m[2] | |
39 | - val = data[key] if data[key] | |
35 | + key = eval m[2] if m[2] | |
36 | + msg = eval '[:sub, ' + m[4] + ']' if m[4] | |
40 | 37 | |
41 | - args = m[4].split(',').map do |arg| | |
42 | - eval arg.strip | |
43 | - end if m[4] | |
44 | - | |
45 | - val = val.send *args if args | |
38 | + val = data[key] if data[key] | |
39 | + val = val.send *msg if msg | |
46 | 40 | |
47 | 41 | result += m[0] + (val || "") |
48 | 42 | end | ... | ... |
Please
register
or
login
to post a comment