/usr/share/pcsd/pcsd_file.rb is in pcs 0.9.164-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | require 'base64'
require 'pcs.rb' #write_file_lock, read_file_lock
require 'settings.rb'
require 'pcsd_exchange_format.rb'
module PcsdFile
class PutFile
def initialize(id, file)
@id = id
@file = file
end
def validate()
PcsdFile::validate_file_key_with_string(@id, @file, :data)
end
def rewrite_existing()
return @file[:rewrite_existing]
end
def full_file_name()
raise NotImplementedError.new(
"'#{__method__}' is not implemented in '#{self.class}'"
)
end
def binary?()
return true
end
def exists?()
return @exists if defined? @exists
@exists ||= File.file?(self.full_file_name)
end
def exists_with_same_content()
unless self.exists?
return false
end
if self.binary?
return Base64.strict_encode64(self.read()) == @file[:data]
end
return self.read() == @file[:data]
end
def write()
write_file_lock(
self.full_file_name,
self.permissions,
self.binary? ? Base64.decode64(@file[:data]) : @file[:data],
self.binary?,
self.user,
self.group
)
end
def permissions()
return nil
end
def user()
return nil
end
def group()
return nil
end
def read()
return read_file_lock(self.full_file_name, self.binary?)
end
def process()
self.validate()
begin
unless self.exists?
self.write()
return PcsdExchangeFormat::result(:written)
end
if self.rewrite_existing
self.write()
return PcsdExchangeFormat::result(:rewritten)
end
if self.exists_with_same_content()
return PcsdExchangeFormat::result(:same_content)
end
return PcsdExchangeFormat::result(:conflict)
rescue => e
return PcsdExchangeFormat::result(:unexpected, e.message)
end
end
end
class PutFileBooth < PutFile
def validate()
super
PcsdFile::validate_file_key_with_string(@id, @file, :name)
if @file[:name].empty?
raise PcsdExchangeFormat::Error.for_item('file', @id, "'name' is empty")
end
if @file[:name].include?('/')
raise PcsdExchangeFormat::Error.for_item(
'file', @id, "'name' cannot contain '/'"
)
end
end
def dir()
return BOOTH_CONFIG_DIR
end
def full_file_name()
@full_file_name ||= File.join(self.dir, @file[:name])
end
end
class PutFileBoothAuthfile < PutFileBooth
def permissions()
return 0600
end
end
class PutFileBoothConfig < PutFileBooth
def binary?()
return false
end
end
class PutFilePcmkRemoteAuthkey < PutFile
def full_file_name
#TODO determine the file name from the system
@full_file_name ||= PACEMAKER_AUTHKEY
end
def permissions()
return 0400
end
def user()
return 'hacluster'
end
def group()
return 'haclient'
end
def write()
pacemaker_config_dir = File.dirname(PACEMAKER_AUTHKEY)
if not File.directory?(pacemaker_config_dir)
Dir.mkdir(pacemaker_config_dir)
end
super
end
end
class PutFileCorosyncAuthkey < PutFile
def full_file_name
@full_file_name ||= COROSYNC_AUTHKEY
end
def permissions()
return 0400
end
end
TYPES = {
"booth_authfile" => PutFileBoothAuthfile,
"booth_config" => PutFileBoothConfig,
"pcmk_remote_authkey" => PutFilePcmkRemoteAuthkey,
"corosync_authkey" => PutFileCorosyncAuthkey,
}
end
def PcsdFile.validate_file_key_with_string(id, file_hash, key_name)
unless file_hash.has_key?(key_name)
raise PcsdExchangeFormat::Error.for_item(
'file', id, "'#{key_name}' is missing"
)
end
unless file_hash[key_name].is_a? String
raise PcsdExchangeFormat::Error.for_item(
'file',
id,
"'#{key_name}' is not String: '#{file_hash[key_name].class}'"
)
end
end
|