Revision ca51664c
Added by Marc Dequènes over 15 years ago
- ID ca51664c01bb6d5460669b093245b10609e007b0
bin/shadowwalker | ||
---|---|---|
exit 2
|
||
end
|
||
|
||
$program_options[:skip_binary] = true
|
||
Display.display_item(item, $program_options)
|
||
if args.empty?
|
||
$program_options[:skip_binary] = true
|
||
Display.display_item(item, $program_options)
|
||
else
|
||
field_info = args.shift
|
||
field_name, file_no = field_info.split("#")
|
||
|
||
unless item.has_attribute?(field_name)
|
||
STDERR.puts "No such field '#{field_name}' in object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
unless item.attribute_present?(field_name)
|
||
STDERR.puts "Field '#{field_name}' in item '#{obj_hdl}/#{item_hdl}' is not present."
|
||
exit 2
|
||
end
|
||
|
||
field_data = item.send(field_name)
|
||
|
||
if file_no == "?"
|
||
result = field_data.size
|
||
else
|
||
file_no_i = file_no.to_i
|
||
file_no = (file_no_i.to_s == file_no) ? file_no_i : nil
|
||
|
||
attr_info = ActiveLdap::Base.schema.attribute(field_name)
|
||
|
||
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."
|
||
exit 2
|
||
end
|
||
if file_no > 0 and field_single
|
||
STDERR.puts "Field '#{field_name}' in object '#{obj_hdl}' 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}])"
|
||
exit 2
|
||
end
|
||
|
||
result = field_data[file_no]
|
||
end
|
||
|
||
if args.empty?
|
||
puts result
|
||
else
|
||
file_name = args.shift
|
||
if File.exists?(file_name)
|
||
STDERR.puts "File '#{file_name}' already exists, and i won't overwrite it."
|
||
exit 2
|
||
end
|
||
|
||
begin
|
||
open(file_name, "w") do |fp|
|
||
fp.write result
|
||
end
|
||
rescue
|
||
STDERR.puts "Cannot save file: " + $!
|
||
exit 3
|
||
end
|
||
|
||
puts "File saved."
|
||
end
|
||
end
|
||
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
... | ... | |
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
cmd = CmdParse::Command.new('getbin', false)
|
||
cmd.short_desc = "download object binary information"
|
||
cmd.set_execution_block do |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
|
||
if args.size < 3
|
||
STDERR.puts "syntax error: no field name given"
|
||
exit 1
|
||
end
|
||
if args.size < 4
|
||
STDERR.puts "syntax error: no file 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
|
||
|
||
field_info = args.shift
|
||
field_name, file_no = field_info.split("#")
|
||
file_no = file_no.to_i
|
||
|
||
unless item.has_attribute?(field_name)
|
||
STDERR.puts "No such field '#{field_name}' in object '#{obj_hdl}'."
|
||
exit 2
|
||
end
|
||
unless item.attribute_present?(field_name)
|
||
STDERR.puts "Field '#{field_name}' in item '#{obj_hdl}/#{item_hdl}' is not present."
|
||
exit 2
|
||
end
|
||
|
||
field_single = ActiveLdap::Base.schema.attribute(field_name).single_value?
|
||
if file_no.nil? and not field_single
|
||
STDERR.puts "Binary field '#{field_name}' in object '#{obj_hdl}' has multiple values, but you didn't select one."
|
||
exit 2
|
||
end
|
||
if file_no > 0 and field_single
|
||
STDERR.puts "Binary field '#{field_name}' in object '#{obj_hdl}' has only a single value"
|
||
exit 2
|
||
end
|
||
|
||
field_data = item.send(field_name)
|
||
if file_no < 0 and file_no >= field_data.size
|
||
STDERR.puts "Binary field '#{field_name}' in object '#{obj_hdl}' doesn't have such file number '#{file_no}' (select in range [0, #{file_no - 1}])"
|
||
exit 2
|
||
end
|
||
|
||
file_name = args.shift
|
||
if File.exists?(file_name)
|
||
STDERR.puts "File '#{file_name}' already exists, and i won't overwrite it."
|
||
exit 2
|
||
end
|
||
|
||
begin
|
||
open(file_name, "w") do |fp|
|
||
fp.write field_data
|
||
end
|
||
rescue
|
||
STDERR.puts "Cannot save file: " + $!
|
||
exit 3
|
||
end
|
||
|
||
puts "File saved."
|
||
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
cmdparser.parse
|
Also available in: Unified diff
[evol] enhanced the 'show' command, replacing totally the 'getbin' command in a more generic way