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
|
# File 'lib/puppet/util/symbolic_file_mode.rb', line 51
def symbolic_mode_to_int(modification, to_mode = 0, is_a_directory = false)
if modification.nil? or modification == ''
raise Puppet::Error, _("An empty mode string is illegal")
elsif modification =~ /^[0-7]+$/
return modification.to_i(8)
elsif modification =~ /^\d+$/
raise Puppet::Error, _("Numeric modes must be in octal, not decimal!")
end
fail _("non-numeric current mode (%{mode})") % { mode: to_mode.inspect } unless to_mode.is_a?(Numeric)
original_mode = {
's' => (to_mode & 0o7000) >> 9,
'u' => (to_mode & 0o0700) >> 6,
'g' => (to_mode & 0o0070) >> 3,
'o' => (to_mode & 0o0007) >> 0,
'any x?' => (to_mode & 0o0111) != 0
}
final_mode = {
's' => original_mode['s'],
'u' => original_mode['u'],
'g' => original_mode['g'],
'o' => original_mode['o'],
}
modification.split(/\s*,\s*/).each do |part|
_, to, dsl = /^([ugoa]*)([-+=].*)$/.match(part).to_a
if dsl.nil? then raise Puppet::Error, _('Missing action') end
to = "a" unless to and to.length > 0
snapshot_mode = {}
final_mode.each { |k, v| snapshot_mode[k] = v }
to.gsub('a', 'ugo').split('').uniq.each do |who|
value = snapshot_mode[who]
action = '!'
actions = {
'!' => ->(_, _) { raise Puppet::Error, _('Missing operation (-, =, or +)') },
'=' => ->(m, v) { m | v },
'+' => ->(m, v) { m | v },
'-' => ->(m, v) { m & ~v },
}
dsl.split('').each do |op|
case op
when /[-+=]/
action = op
value = 0 if op == '='
when /[ugo]/
value = actions[action].call(value, snapshot_mode[op])
when /[rwx]/
value = actions[action].call(value, SymbolicMode[op])
when 'X'
if action != '+'
raise Puppet::Error, _("X only works with the '+' operator")
end
if is_a_directory or original_mode['any x?']
value = actions[action].call(value, ExecBit)
end
when /[st]/
bit = SymbolicSpecialToBit[op][who] or fail _("internal error")
final_mode['s'] = actions[action].call(final_mode['s'], bit)
else
raise Puppet::Error, _('Unknown operation')
end
end
final_mode[who] = value
end
rescue Puppet::Error => e
if part.inspect != modification.inspect
rest = " at #{part.inspect}"
else
rest = ''
end
raise Puppet::Error, _("%{error}%{rest} in symbolic mode %{modification}") % { error: e, rest: rest, modification: modification.inspect }, e.backtrace
end
final_mode['s'] << 9 |
final_mode['u'] << 6 |
final_mode['g'] << 3 |
final_mode['o'] << 0
end
|