main.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # The source format is the one returned by the <code>RIGHTS <dir> /T /C</code>
  2. # command on a directory existing on a network drive accessible using a NetWare
  3. # client.
  4. #
  5. # This format should be available from NetWare 4.x to 6.5 at least. This script
  6. # has been created for NetWare 6.5 with the latest Win32 client as of 2009-07-01.
  7. #
  8. # Load rights information from the text file generated by redirecting stdout
  9. # on the RIGHTS /T command
  10. class Loader
  11. # The file from which to load
  12. PATH = 'droits_h.txt'
  13. attr_accessor :items
  14. # Actually load the data. The format is a repeated pattern:
  15. # - path line: volume:path
  16. # - user|group|other (x) trustees
  17. # - "no (x) trustees have been assigned", or
  18. # - "(x) trustees:", then
  19. # - trustee lines: (trustee) (spaces) '[' (rights_vector) ']'
  20. # - '----------'
  21. # - the other (x) group(s) of trustees (group|user)
  22. # - "\n"
  23. def load_item_data
  24. line_types = {
  25. 'path' => { 'default' => 'trustee_head'},
  26. 'trustee_head' => { 'default' => 'trustee_row'},
  27. 'trustee_row' => { 'default' => 'trustee_row', 'head' => 'trustee_head', 'path' => 'path'},
  28. 'separator' => { 'default' => 'trustee_head'},
  29. 'empty' => { 'default' => 'path'}
  30. }
  31. line_type = 'path'
  32. @items = {}
  33. path = ''
  34. trustee_type = 'invalid'
  35. File.open(PATH) do |data_file|
  36. data_file.readlines.each do |line|
  37. line.chomp!
  38. # puts "Line type: #{line_type}, value: (#{line})\n"
  39. new_line_key = 'default'
  40. case line_type
  41. when 'path' then
  42. path = line
  43. items[path] = { 'user' => [], 'group' => [], 'other' => []}
  44. # puts " New path: #{path}\n"
  45. when 'trustee_head'
  46. # printf " Checking trustee head (#{line}):"
  47. case line
  48. when /[uU]ser/ then
  49. trustee_type = 'user'
  50. when /[gG]roup/ then
  51. trustee_type = 'group'
  52. when /Other/ then
  53. trustee_type = 'other'
  54. else
  55. trustee_type = 'invalid'
  56. end # case line
  57. # puts " Found type #{trustee_type}\n"
  58. when 'trustee_row'
  59. case line
  60. when /----/ then
  61. new_line_key = 'head'
  62. when '' then
  63. new_line_key = 'path'
  64. else
  65. # puts " Adding #{trustee_type} trustee line to #{path}: #{line}\n"
  66. pattern = / *(.*?) *\[(.*)\]/
  67. matches = line.match pattern
  68. # p line if matches == nil
  69. @items[path][trustee_type] << [ matches[1], matches[2] ]
  70. end
  71. when 'separator'
  72. trustee_type = 'invalid'
  73. when 'empty'
  74. trustee_type = 'invalid'
  75. path = ''
  76. else
  77. raise "Invalid line type '#{line}'\n"
  78. end
  79. line_type = line_types[line_type][new_line_key]
  80. end
  81. end
  82. end
  83. def dump
  84. @items.keys.sort.each do |path|
  85. puts path
  86. @items[path].keys.sort.each do |kind|
  87. @items[path][kind].sort.each do |assignment|
  88. printf(" %-6s|%8s|%s\n", kind, assignment[1], assignment[0])
  89. end
  90. end
  91. end
  92. end
  93. # Loader "constructor"
  94. def initialize
  95. self.load_item_data
  96. end
  97. end
  98. # Main class for the TBackup utility
  99. class Main
  100. # Main "constructor"
  101. def initialize
  102. loader = Loader.new
  103. loader.dump
  104. end
  105. end
  106. Main.new