root/conf/ldap_shadows/worlds/MilkyPond/shadows/Administration/plugins/aspects/fs.rb @ 4b490148
dba6a81b | Marc Dequènes (Duck) | ||
953a2b4d | Marc Dequènes (Duck) | def self.hook_before_create(item)
|
|
hook_common(item)
|
|||
f706cc1d | Marc Dequènes (Duck) | end
|
|
953a2b4d | Marc Dequènes (Duck) | def self.hook_before_modify(item)
|
|
hook_common(item)
|
|||
f706cc1d | Marc Dequènes (Duck) | end
|
|
953a2b4d | Marc Dequènes (Duck) | def self.hook_common(item)
|
|
pconfig_default = {
|
|||
:default_group => 'users',
|
|||
:min_uid => 1000,
|
|||
:max_uid => 65535,
|
|||
:step_uid => 100,
|
|||
:default_home_base => "/home"
|
|||
}
|
|||
pconfig = pconfig_default.merge(self.parameters[:plugin])
|
|||
dba6a81b | Marc Dequènes (Duck) | unless item.attribute_present?('gidNumber')
|
|
953a2b4d | Marc Dequènes (Duck) | item.primaryGroup = item.class.shadow.get_object(:group).find(:first, pconfig[:default_group])
|
|
dba6a81b | Marc Dequènes (Duck) | end
|
|
f706cc1d | Marc Dequènes (Duck) | if item.attribute_present?('uidNumber')
|
|
user = ActiveLdap::Base.find(:first, :scope => :sub, :filter => "(&(objectClass=posixAccount)(uidNumber=#{item.uidNumber}))", :attributes => ['uidNumber'])
|
|||
unless user.nil? or user.dn == item.dn
|
|||
raise_error "UID already used by another item"
|
|||
end
|
|||
else
|
|||
users = ActiveLdap::Base.find(:all, :scope => :sub, :filter => "(&(objectClass=posixAccount)(uidNumber=*))", :attributes => ['uidNumber'])
|
|||
uidnumbers = users.collect {|user| user.uidNumber }
|
|||
dba6a81b | Marc Dequènes (Duck) | ||
avail_uidnumber = nil
|
|||
953a2b4d | Marc Dequènes (Duck) | min_uidn = pconfig[:min_uid]
|
|
max_uidn = [min_uidn + pconfig[:step_uid], pconfig[:max_uid]].min
|
|||
dba6a81b | Marc Dequènes (Duck) | while avail_uidnumber.nil?
|
|
avail = (min_uidn..max_uidn).to_a - uidnumbers
|
|||
unless avail.empty?
|
|||
avail_uidnumber = avail.first
|
|||
break
|
|||
end
|
|||
min_uidn = max_uidn
|
|||
953a2b4d | Marc Dequènes (Duck) | max_uidn = [min_uidn + pconfig[:step_uid], pconfig[:max_uid]].min
|
|
dba6a81b | Marc Dequènes (Duck) | end
|
|
if avail_uidnumber.nil?
|
|||
f706cc1d | Marc Dequènes (Duck) | raise_error "Available UID range is depleted."
|
|
dba6a81b | Marc Dequènes (Duck) | else
|
|
item.uidNumber = avail_uidnumber
|
|||
end
|
|||
end
|
|||
unless item.attribute_present?('homeDirectory')
|
|||
953a2b4d | Marc Dequènes (Duck) | item.homeDirectory = File.join(pconfig[:default_home_base], item.uid)
|
|
dba6a81b | Marc Dequènes (Duck) | end
|
|
end
|