Project

General

Profile

Download (1.11 KB) Statistics
| Branch: | Tag: | Revision:
dba6a81b Marc Dequènes (Duck)
# should be in the configuration file
MIN_UID = 10000
MAX_UID = 65535
STEP_UID = 100
DEFAULT_GROUP = 'dc-users'

def self.hook_mod(mapper, item)
unless item.attribute_present?('gidNumber')
3d58e226 Marc Dequènes (Duck)
item.primaryGroup = mapper.find_klass(:group).find(:first, DEFAULT_GROUP)
dba6a81b Marc Dequènes (Duck)
end

unless item.attribute_present?('uidNumber')
groups = ActiveLdap::Base.search(:scope => :sub, :filter => "(uidNumber=*)", :attributes => ['uidNumber'])
uidnumbers = groups.collect {|group| group[1]['uidNumber'].first.to_i }

avail_uidnumber = nil
min_uidn = MIN_UID
max_uidn = [min_uidn + STEP_UID, MAX_UID].min
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
max_uidn = [min_uidn + STEP_UID, MAX_UID].min
end

if avail_uidnumber.nil?
STDERR.puts "Available UID range is depleted."
exit 4
else
item.uidNumber = avail_uidnumber
end
end

unless item.attribute_present?('homeDirectory')
item.homeDirectory = "/home/" + item.uid
end
end