Commit 6ce7c0f16552fdf8ee23bb76067893dd3b93355c

Authored by Georg GH. Hopp
Committed by Georg Hopp
1 parent cdaf490a

cleanups and small changes

- move ldap specific config handling int storage/ldap.rb
- update shadowlastchange only if the users password changes (actually
  not sure that this is the correct behaviour.)
- change config accessor in storage to config reader
- create a generic eval_pattern method in SdAdmin::Storage::Config
@@ -18,8 +18,8 @@ class DsAdmin::Model::User @@ -18,8 +18,8 @@ class DsAdmin::Model::User
18 @shadowlastchange = args[:shadowlastchange] 18 @shadowlastchange = args[:shadowlastchange]
19 end 19 end
20 20
21 - def save 21 + def pass=(pass)
  22 + @pass = pass
22 @shadowlastchange = (Time::now.to_i/60/60/24).to_s 23 @shadowlastchange = (Time::now.to_i/60/60/24).to_s
23 - super  
24 end 24 end
25 end 25 end
@@ -5,7 +5,7 @@ module DsAdmin::Storage @@ -5,7 +5,7 @@ module DsAdmin::Storage
5 DsAdmin::Storage.autoload(:Ldap, 'storage/ldap') 5 DsAdmin::Storage.autoload(:Ldap, 'storage/ldap')
6 DsAdmin::Storage.autoload(:Mysql, 'storage/mysql') 6 DsAdmin::Storage.autoload(:Mysql, 'storage/mysql')
7 7
8 - attr_accessor :config 8 + attr_reader :config
9 9
10 def initialize(config) 10 def initialize(config)
11 @config = config 11 @config = config
@@ -17,11 +17,21 @@ class DsAdmin::Storage::Config @@ -17,11 +17,21 @@ class DsAdmin::Storage::Config
17 @config[storage.config_key][@model.config_key][:map] 17 @config[storage.config_key][@model.config_key][:map]
18 end 18 end
19 19
20 - def object_class(storage)  
21 - @config[storage.config_key][@model.config_key][:objectClass]  
22 - end 20 + ##
  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 replaces data e.g. for some kind of subtitution.
  24 + #
  25 + def eval_pattern(pattern, data = {})
  26 + scan_exp = /([^#]*)(#\{(:[^}|]+)(\|([^}]*))?\})?/
  27 +
  28 + result = String.new
  29 + pattern.scan(scan_exp) do |m|
  30 + key = m[2][1..m[2].length].to_sym if m[2]
  31 + val = eval('"' + data[key] + '".send ' + m[4]) if data[key] && m[4]
23 32
24 - def dn_pat(storage)  
25 - @config[storage.config_key][@model.config_key][:dnPat] 33 + result += m[0] + (val || "")
  34 + end
  35 + result
26 end 36 end
27 end 37 end
1 require 'net/ldap' 1 require 'net/ldap'
2 2
  3 +##
  4 +# some additional ldap specific config handlings.
  5 +#
  6 +class DsAdmin::Storage::Config
  7 + def object_class(storage)
  8 + @config[storage.config_key][@model.config_key][:objectClass]
  9 + end
  10 +
  11 + def dn(storage, data)
  12 + eval_pattern(
  13 + @config[storage.config_key][@model.config_key][:dnPat],
  14 + data) + ',' + query(storage)[:base]
  15 + end
  16 +end
  17 +
3 class DsAdmin::Storage::Ldap 18 class DsAdmin::Storage::Ldap
4 include DsAdmin::Storage 19 include DsAdmin::Storage
5 20
@@ -38,18 +53,7 @@ class DsAdmin::Storage::Ldap @@ -38,18 +53,7 @@ class DsAdmin::Storage::Ldap
38 53
39 protected 54 protected
40 def create(data) 55 def create(data)
41 - map = @config.map(self).invert  
42 - scan_exp = /(^|, *)([^=]*=)(([^#][^,]*)|#\{([^|}]*)(\|([^}]*))?\})/  
43 -  
44 - dn = String.new  
45 - @config.dn_pat(self).scan(scan_exp) do |m|  
46 - val = m[3] if m[3]  
47 - val = data[m[4][1..m[4].length].to_sym] if m[4]  
48 - val = eval('"' + val + '".send ' + m[6]) if data && m[6]  
49 -  
50 - dn += m[0] + m[1] + val  
51 - end  
52 - dn += ',' + @config.query(self)[:base] 56 + dn = @config.dn(self, data)
53 57
54 data.delete(:id) 58 data.delete(:id)
55 59
@@ -79,6 +83,7 @@ class DsAdmin::Storage::Ldap @@ -79,6 +83,7 @@ class DsAdmin::Storage::Ldap
79 replace.each do |key,value| 83 replace.each do |key,value|
80 if old[:id] =~ /(^|, *)#{key.to_s}=([^, ]+)/ && $2 != value 84 if old[:id] =~ /(^|, *)#{key.to_s}=([^, ]+)/ && $2 != value
81 delete(old[:id]) 85 delete(old[:id])
  86 + puts
82 return create(new) 87 return create(new)
83 end 88 end
84 end 89 end
Please register or login to post a comment