Commit 85d6aac8c8469ac1ad29eb150425cef4c9cf3902
Committed by
Georg Hopp
1 parent
aab45409
further improvements on database updates and some fixes
Showing
4 changed files
with
57 additions
and
21 deletions
... | ... | @@ -43,8 +43,7 @@ class SystemDataBackendLdap |
43 | 43 | LDAP_LAMBDA_USER = lambda do |entry| |
44 | 44 | entry[:cn] = entry[:uid] |
45 | 45 | entry[:shadowlastchange] = (Time::now.to_i/60/60/24).to_s |
46 | - entry[:shadowmax] = '99999' | |
47 | - entry[:shadowwarning] = '7' | |
46 | + entry[:replace] += ['shadowreplace'] if entry[:replace] | |
48 | 47 | end |
49 | 48 | |
50 | 49 | LDAP_LAMBDA = { |
... | ... | @@ -64,7 +63,9 @@ class SystemDataBackendLdap |
64 | 63 | end |
65 | 64 | |
66 | 65 | def load!(kind) |
67 | - @ldapData[kind] = @ldap.search( | |
66 | + @ldapData[kind] = Hash.new if ! @ldapData[kind] | |
67 | + | |
68 | + @ldapData[kind][:internal] = @ldap.search( | |
68 | 69 | :base => ldapBase(kind), |
69 | 70 | :filter => LDAP_FILTER[kind] |
70 | 71 | ) |
... | ... | @@ -73,7 +74,7 @@ class SystemDataBackendLdap |
73 | 74 | def load(kind) |
74 | 75 | load!(kind) if ! @ldapData[kind] |
75 | 76 | |
76 | - @ldapData[kind].each do |data| | |
77 | + @ldapData[kind][:external] = @ldapData[kind][:internal].map do |data| | |
77 | 78 | map = { :dn => :id } |
78 | 79 | map.merge!(LDAP_MAP[kind]) if LDAP_MAP[kind] |
79 | 80 | |
... | ... | @@ -81,9 +82,10 @@ class SystemDataBackendLdap |
81 | 82 | data.each do |key,value| |
82 | 83 | ydata.merge!({ map[key] || key => value.size==1?value[0]:value.to_a }) |
83 | 84 | end |
85 | + ydata | |
86 | + end if ! @ldapData[kind][:external] | |
84 | 87 | |
85 | - yield ydata | |
86 | - end | |
88 | + @ldapData[kind][:external].each{|ydata| yield ydata} | |
87 | 89 | end |
88 | 90 | |
89 | 91 | def update(kind, data) |
... | ... | @@ -91,19 +93,27 @@ class SystemDataBackendLdap |
91 | 93 | map.merge!(LDAP_MAP[kind].invert) if LDAP_MAP[kind] |
92 | 94 | |
93 | 95 | entry = Net::LDAP::Entry.new(data[:id]) |
94 | - data.delete(:id) | |
95 | 96 | |
96 | - entry[:changetype] = 'add' | |
97 | - entry[:objectclass] = LDAP_OBJECTCLASS[kind] | |
97 | + odata = @ldapData[kind][:external].find{|edata| edata[:id] == data[:id]} | |
98 | + data = data.find_all{|key,value| value != odata[key]} | |
99 | + data.delete(:id) | |
98 | 100 | |
101 | + replace = Array.new | |
99 | 102 | data.each do |key,value| |
100 | 103 | key = map[key] if map[key] |
104 | + replace.push(key.to_s) | |
101 | 105 | entry[key] = value |
102 | 106 | end |
103 | - | |
104 | - LDAP_LAMBDA[kind].call(entry) if LDAP_LAMBDA[kind] | |
105 | 107 | |
106 | - puts entry.to_ldif | |
108 | + if not replace.empty? | |
109 | + entry[:changetype] = 'modify' | |
110 | + entry[:replace] = replace | |
111 | + LDAP_LAMBDA[kind].call(entry) if LDAP_LAMBDA[kind] | |
112 | + | |
113 | + puts entry.to_ldif | |
114 | + else | |
115 | + puts 'INFO: no changes' | |
116 | + end | |
107 | 117 | end |
108 | 118 | |
109 | 119 | private | ... | ... |
... | ... | @@ -6,11 +6,13 @@ class User < SystemData |
6 | 6 | def initialize(args = {}) |
7 | 7 | super(args) |
8 | 8 | |
9 | - @name = args[:name] | |
10 | - @pass = args[:pass] | |
11 | - @uid = args[:uid] | |
12 | - @gid = args[:gid] | |
13 | - @shell = args[:shell] | |
14 | - @home = args[:home] | |
9 | + @name = args[:name] | |
10 | + @pass = args[:pass] | |
11 | + @uid = args[:uid] | |
12 | + @gid = args[:gid] | |
13 | + @shell = args[:shell] | |
14 | + @home = args[:home] | |
15 | + @shadowmax = args[:shadowmax] | |
16 | + @shadowwarning = args[:shadowwarning] | |
15 | 17 | end |
16 | 18 | end | ... | ... |
... | ... | @@ -46,8 +46,30 @@ end |
46 | 46 | |
47 | 47 | puts |
48 | 48 | |
49 | -backend.userByName('georg').save | |
49 | +georg = backend.userByName('georg') | |
50 | +georg.save | |
50 | 51 | |
51 | 52 | puts |
52 | 53 | |
53 | -backend.groupByName('wheel').save | |
54 | +georg.uid = 1001 | |
55 | +georg.save | |
56 | + | |
57 | +puts | |
58 | + | |
59 | +wheel = backend.groupByName('wheel') | |
60 | +wheel.save | |
61 | + | |
62 | +puts | |
63 | + | |
64 | +wheel.gid = 100 | |
65 | +wheel.save | |
66 | + | |
67 | +puts | |
68 | + | |
69 | +site = backend.siteByName('kommandozeilenchef.de') | |
70 | +site.save | |
71 | + | |
72 | +puts | |
73 | + | |
74 | +site.name = 'wumbaba.de' | |
75 | +site.save | ... | ... |
Please
register
or
login
to post a comment