Class: IO
- Inherits:
-
Object
- Object
- IO
- Defined in:
- lib/tcell_agent/instrumentation/monkey_patches/io.rb
Class Method Summary collapse
- .binread(*args, &block) ⇒ Object
- .binwrite(*args, &block) ⇒ Object
- .foreach(*args, &block) ⇒ Object
- .popen(*args, &block) ⇒ Object
- .read(*args, &block) ⇒ Object
- .readlines(*args, &block) ⇒ Object
- .sysopen(*args, &block) ⇒ Object
- .tcell_original_binread ⇒ Object
- .tcell_original_binwrite ⇒ Object
- .tcell_original_foreach ⇒ Object
- .tcell_original_popen ⇒ Object
- .tcell_original_read ⇒ Object
- .tcell_original_readlines ⇒ Object
- .tcell_original_sysopen ⇒ Object
- .tcell_original_write ⇒ Object
- .write(*args, &block) ⇒ Object
Class Method Details
.binread(*args, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 4 def binread(*args, &block) path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end if path.empty? cmd = TCellAgent::Cmdi.parse_command_from_open(*args) if cmd && TCellAgent::Cmdi.block_command?(cmd) raise "tCell.io Agent: Command not allowed by policy: #{cmd}" end end tcell_original_binread(*args, &block) end |
.binwrite(*args, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 22 def binwrite(*args, &block) path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) mode = 'Write' if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end tcell_original_binwrite(*args, &block) end |
.foreach(*args, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 34 def foreach(*args, &block) path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) mode = 'Read' if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end tcell_original_foreach(*args, &block) end |
.popen(*args, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 46 def popen(*args, &block) unless args.empty? cmd = '' TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do args_copy = Array.new(args) args_copy.shift if args_copy.first.is_a?(Hash) args_copy.pop if args_copy.last.is_a?(Hash) cmd = if args_copy.first.is_a?(String) args_copy.shift else TCellAgent::Cmdi.parse_command(*args_copy.shift) end end if TCellAgent::Cmdi.block_command?(cmd) raise "tCell.io Agent: Command not allowed by policy: #{cmd}" end end tcell_original_popen(*args, &block) end |
.read(*args, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 71 def read(*args, &block) path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) mode = 'Read' if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end if path.empty? cmd = TCellAgent::Cmdi.parse_command_from_open(*args) if cmd && TCellAgent::Cmdi.block_command?(cmd) raise "tCell.io Agent: Command not allowed by policy: #{cmd}" end end tcell_original_read(*args, &block) end |
.readlines(*args, &block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 90 def readlines(*args, &block) path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) mode = 'Read' if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end if path.empty? cmd = TCellAgent::Cmdi.parse_command_from_open(*args) if cmd && TCellAgent::Cmdi.block_command?(cmd) raise "tCell.io Agent: Command not allowed by policy: #{cmd}" end end tcell_original_readlines(*args, &block) end |
.sysopen(*args, &block) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 109 def sysopen(*args, &block) path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end tcell_original_sysopen(*args, &block) end |
.tcell_original_binread ⇒ Object
3 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 3 alias_method :tcell_original_binread, :binread |
.tcell_original_binwrite ⇒ Object
21 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 21 alias_method :tcell_original_binwrite, :binwrite |
.tcell_original_foreach ⇒ Object
33 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 33 alias_method :tcell_original_foreach, :foreach |
.tcell_original_popen ⇒ Object
45 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 45 alias_method :tcell_original_popen, :popen |
.tcell_original_read ⇒ Object
70 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 70 alias_method :tcell_original_read, :read |
.tcell_original_readlines ⇒ Object
89 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 89 alias_method :tcell_original_readlines, :readlines |
.tcell_original_sysopen ⇒ Object
108 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 108 alias_method :tcell_original_sysopen, :sysopen |
.tcell_original_write ⇒ Object
119 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 119 alias_method :tcell_original_write, :write |
.write(*args, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tcell_agent/instrumentation/monkey_patches/io.rb', line 120 def write(*args, &block) path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args) mode = 'Write' if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode) raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied" end tcell_original_write(*args, &block) end |