123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- # The source format is the one returned by the <code>RIGHTS <dir> /T /C</code>
- # command on a directory existing on a network drive accessible using a NetWare
- # client.
- #
- # This format should be available from NetWare 4.x to 6.5 at least. This script
- # has been created for NetWare 6.5 with the latest Win32 client as of 2009-07-01.
- #
- # Load rights information from the text file generated by redirecting stdout
- # on the RIGHTS /T command
- class Loader
- # The file from which to load
- PATH = 'droits_h.txt'
- attr_accessor :items
- # Actually load the data. The format is a repeated pattern:
- # - path line: volume:path
- # - user|group|other (x) trustees
- # - "no (x) trustees have been assigned", or
- # - "(x) trustees:", then
- # - trustee lines: (trustee) (spaces) '[' (rights_vector) ']'
- # - '----------'
- # - the other (x) group(s) of trustees (group|user)
- # - "\n"
- def load_item_data
- line_types = {
- 'path' => { 'default' => 'trustee_head'},
- 'trustee_head' => { 'default' => 'trustee_row'},
- 'trustee_row' => { 'default' => 'trustee_row', 'head' => 'trustee_head', 'path' => 'path'},
- 'separator' => { 'default' => 'trustee_head'},
- 'empty' => { 'default' => 'path'}
- }
- line_type = 'path'
- @items = {}
- path = ''
- trustee_type = 'invalid'
- File.open(PATH) do |data_file|
- data_file.readlines.each do |line|
- line.chomp!
- # puts "Line type: #{line_type}, value: (#{line})\n"
- new_line_key = 'default'
- case line_type
- when 'path' then
- path = line
- items[path] = { 'user' => [], 'group' => [], 'other' => []}
- # puts " New path: #{path}\n"
- when 'trustee_head'
- # printf " Checking trustee head (#{line}):"
- case line
- when /[uU]ser/ then
- trustee_type = 'user'
- when /[gG]roup/ then
- trustee_type = 'group'
- when /Other/ then
- trustee_type = 'other'
- else
- trustee_type = 'invalid'
- end # case line
- # puts " Found type #{trustee_type}\n"
- when 'trustee_row'
- case line
- when /----/ then
- new_line_key = 'head'
- when '' then
- new_line_key = 'path'
- else
- # puts " Adding #{trustee_type} trustee line to #{path}: #{line}\n"
- pattern = / *(.*?) *\[(.*)\]/
- matches = line.match pattern
- # p line if matches == nil
- @items[path][trustee_type] << [ matches[1], matches[2] ]
- end
- when 'separator'
- trustee_type = 'invalid'
- when 'empty'
- trustee_type = 'invalid'
- path = ''
- else
- raise "Invalid line type '#{line}'\n"
- end
- line_type = line_types[line_type][new_line_key]
- end
- end
- end
- def dump
- @items.keys.sort.each do |path|
- puts path
- @items[path].keys.sort.each do |kind|
- @items[path][kind].sort.each do |assignment|
- printf(" %-6s|%8s|%s\n", kind, assignment[1], assignment[0])
- end
- end
- end
- end
- # Loader "constructor"
- def initialize
- self.load_item_data
- end
- end
- # Main class for the TBackup utility
- class Main
- # Main "constructor"
- def initialize
- loader = Loader.new
- loader.dump
- end
- end
- Main.new
|