Revision af19cdc5
Added by Marc Dequènes over 15 years ago
- ID af19cdc59052827405ad1a56e347687caba69f41
bin/shadowwalker | ||
---|---|---|
protected
|
||
|
||
def params_shift_location(args)
|
||
location = args.shift
|
||
if args.empty?
|
||
STDERR.puts "syntax error: no location name given"
|
||
exit 1
|
||
end
|
||
|
||
location = args.shift.downcase
|
||
if location =~ /^([a-zA-Z]+)\/(.+)$/
|
||
loc_obj_hdl = $1
|
||
loc_item_hdl = $2
|
||
... | ... | |
STDERR.puts "syntax error: bad location"
|
||
exit 1
|
||
end
|
||
loc_obj_klass = $ldapctl.find_klass(loc_obj_hdl)
|
||
if loc_obj_klass.nil?
|
||
STDERR.puts "No such location object '#{loc_obj_hdl}'."
|
||
|
||
split_args = [loc_obj_hdl, loc_item_hdl]
|
||
loc_obj_klass = params_shift_object(split_args)
|
||
loc_item = params_shift_item(loc_obj_klass, split_args)
|
||
|
||
[loc_obj_klass, loc_item]
|
||
end
|
||
|
||
def params_shift_object(args)
|
||
if args.empty?
|
||
STDERR.puts "syntax error: no object name given"
|
||
exit 1
|
||
end
|
||
|
||
obj_hdl = args.shift.downcase.singularize
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
obj_klass
|
||
end
|
||
|
||
def params_shift_item(obj_klass, args, with_expert = false)
|
||
if args.empty?
|
||
STDERR.puts "syntax error: no item name given"
|
||
exit 1
|
||
end
|
||
|
||
attr_list = ["*"]
|
||
attr_list << "+" if $program_options[:expert] and with_expert # add operational attributes if expert
|
||
|
||
item_hdl = args.shift.downcase
|
||
begin
|
||
loc_item = loc_obj_klass.find(loc_item_hdl)
|
||
item = obj_klass.find(item_hdl, :attributes => attr_list)
|
||
rescue ActiveLdap::EntryNotFound
|
||
STDERR.puts "No such item '#{loc_obj_hdl}/#{loc_item_hdl}'"
|
||
STDERR.puts "No such item '#{obj_klass.handle}/#{item_hdl}'"
|
||
exit 2
|
||
end
|
||
|
||
[loc_obj_klass, loc_item]
|
||
item
|
||
end
|
||
end
|
||
|
||
... | ... | |
puts " - #{obj_name}"
|
||
end
|
||
else
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
obj_klass = params_shift_object([obj_hdl])
|
||
|
||
if args.empty?
|
||
obj_human_name = Translator.translate_object_name(obj_hdl)
|
||
Display.display_item_list("List of #{obj_human_name.pluralize}", obj_klass.find(:all))
|
||
Display.display_item_list("List of #{obj_human_name.pluralize}", obj_klass.find(:all), $program_options)
|
||
else
|
||
subobj_hdl = args.shift.downcase.singularize
|
||
|
||
... | ... | |
end
|
||
|
||
def execute (args)
|
||
if args.size < 1
|
||
STDERR.puts "syntax error: no object name given"
|
||
exit 1
|
||
end
|
||
if args.size < 2
|
||
STDERR.puts "syntax error: no item name given"
|
||
exit 1
|
||
end
|
||
|
||
obj_hdl = args.shift
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
item_hdl = args.shift
|
||
begin
|
||
item = obj_klass.find(item_hdl, :attributes => ["*", "+"])
|
||
rescue ActiveLdap::EntryNotFound
|
||
STDERR.puts "No such item '#{obj_hdl}/#{item_hdl}'"
|
||
exit 2
|
||
end
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args, true)
|
||
|
||
if args.empty?
|
||
$program_options[:skip_binary] = true
|
||
... | ... | |
field_name, file_no = field_info.split("#")
|
||
|
||
unless item.has_field?(field_name)
|
||
STDERR.puts "No such field '#{field_name}' in object '#{obj_hdl}'."
|
||
STDERR.puts "No such field '#{field_name}' in object '#{obj_klass.handle}'."
|
||
exit 2
|
||
end
|
||
unless item.attribute_present?(field_name)
|
||
STDERR.puts "Field '#{field_name}' in item '#{obj_hdl}/#{item_hdl}' is not present."
|
||
STDERR.puts "Field '#{field_name}' in item '#{obj_klass.handle}/#{item.name}' is not present."
|
||
exit 2
|
||
end
|
||
|
||
... | ... | |
|
||
field_single = attr_info.single_value?
|
||
if file_no.nil? and not field_single
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_hdl}' has multiple values, but you didn't select one."
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_klass.handle}' has multiple values, but you didn't select one."
|
||
exit 2
|
||
end
|
||
|
||
file_no = 0 if file_no.nil?
|
||
if file_no > 0 and field_single
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_hdl}' has only a single value"
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_klass.handle}' has only a single value"
|
||
exit 2
|
||
end
|
||
if file_no < 0 or file_no >= field_data.size
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_hdl}' doesn't have such file number '#{file_no}' (select in range [0, #{field_data.size - 1}])"
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_klass.handle}' doesn't have such file number '#{file_no}' (select in range [0, #{field_data.size - 1}])"
|
||
exit 2
|
||
end
|
||
|
||
... | ... | |
gconfig = $ldapctl.get_global_config()
|
||
|
||
(gconfig[:tree_objects] || []).each do |obj_hdl|
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
obj_klass = $ldapctl.find_klass(obj_hdl.downcase)
|
||
unless obj_klass
|
||
STDERR.puts "Location object '#{obj_hdl}' not defined."
|
||
exit 2
|
||
... | ... | |
end
|
||
|
||
def execute (args)
|
||
if args.size < 1
|
||
STDERR.puts "syntax error: no object name given"
|
||
exit 1
|
||
end
|
||
if args.size < 2
|
||
STDERR.puts "syntax error: no item name given"
|
||
exit 1
|
||
end
|
||
|
||
obj_hdl = args.shift
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
item_hdl = args.shift
|
||
begin
|
||
item = obj_klass.find(item_hdl)
|
||
rescue ActiveLdap::EntryNotFound
|
||
STDERR.puts "No such item '#{obj_hdl}/#{item_hdl}'"
|
||
exit 2
|
||
end
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args)
|
||
|
||
modification_done = false
|
||
args.each do |mod_info|
|
||
... | ... | |
case type
|
||
when nil
|
||
unless item.has_field?(field)
|
||
STDERR.puts "No such field '#{field}' in object '#{obj_hdl}'."
|
||
STDERR.puts "No such field '#{field}' in object '#{obj_klass.handle}'."
|
||
exit 2
|
||
end
|
||
|
||
... | ... | |
exit 2
|
||
end
|
||
end
|
||
|
||
old_val = item.send(field, true)
|
||
when 'rel'
|
||
unless item.relations.include?(field)
|
||
STDERR.puts "No such relation '#{field}' for object '#{obj_hdl}'."
|
||
STDERR.puts "No such relation '#{field}' for object '#{obj_klass.handle}'."
|
||
exit 2
|
||
end
|
||
|
||
... | ... | |
case field
|
||
when 'aspects'
|
||
unless item.class.possible_aspects.include?(val)
|
||
STDERR.puts "No such aspect '#{val}' for object '#{obj_hdl}'."
|
||
STDERR.puts "No such aspect '#{val}' for object '#{obj_klass.handle}'."
|
||
exit 2
|
||
end
|
||
else
|
||
... | ... | |
end
|
||
|
||
def execute (args)
|
||
if args.size < 1
|
||
STDERR.puts "syntax error: no object name given"
|
||
exit 1
|
||
end
|
||
if args.size < 2
|
||
STDERR.puts "syntax error: no item name given"
|
||
exit 1
|
||
end
|
||
|
||
obj_hdl = args.shift
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
item_hdl = args.shift
|
||
begin
|
||
item = obj_klass.find(item_hdl, :attributes => ["*", "+"])
|
||
rescue ActiveLdap::EntryNotFound
|
||
STDERR.puts "No such item '#{obj_hdl}/#{item_hdl}'"
|
||
exit 2
|
||
end
|
||
obj_klass = params_shift_object(args)
|
||
item = params_shift_item(obj_klass, args)
|
||
|
||
if $program_options[:recursive_delete]
|
||
item.class.delete_all(nil, :scope => :sub, :base => item.dn)
|
||
... | ... | |
end
|
||
|
||
def execute (args)
|
||
if args.size < 1
|
||
STDERR.puts "syntax error: no object name given"
|
||
exit 1
|
||
end
|
||
if args.size < 2
|
||
obj_klass = params_shift_object(args)
|
||
|
||
if args.empty?
|
||
STDERR.puts "syntax error: no item name given"
|
||
exit 1
|
||
end
|
||
if args.size < 3
|
||
STDERR.puts "syntax error: no location name given"
|
||
exit 1
|
||
end
|
||
|
||
obj_hdl = args.shift
|
||
obj_klass = $ldapctl.find_klass(obj_hdl)
|
||
if obj_klass.nil?
|
||
STDERR.puts "No such object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
|
||
item_hdl = args.shift
|
||
item_hdl = args.shift.downcase
|
||
|
||
loc_obj_klass, loc_item = params_shift_location(args)
|
||
|
||
... | ... | |
field = key
|
||
|
||
unless item.has_field?(field)
|
||
STDERR.puts "No such field '#{field}' in object '#{obj_hdl}'."
|
||
STDERR.puts "No such field '#{field}' in object '#{obj_klass.handle}'."
|
||
exit 2
|
||
end
|
||
|
Also available in: Unified diff
[fix] code cleanup and a few fixes