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
|
# File 'lib/puppet/util/symbolic_file_mode.rb', line 35
def symbolic_mode_to_int(modification, to_mode = 0, is_a_directory = false)
if modification.nil? or modification == '' then
raise Puppet::Error, _("An empty mode string is illegal")
end
if modification =~ /^[0-7]+$/ then return modification.to_i(8) end
if modification =~ /^\d+$/ then
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 & 07000) >> 9,
'u' => (to_mode & 00700) >> 6,
'g' => (to_mode & 00070) >> 3,
'o' => (to_mode & 00007) >> 0,
'any x?' => (to_mode & 00111) != 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|
begin
_, 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 = {
'!' => lambda {|_,_| raise Puppet::Error, _('Missing operation (-, =, or +)') },
'=' => lambda {|m,v| m | v },
'+' => lambda {|m,v| m | v },
'-' => lambda {|m,v| m & ~v },
}
dsl.split('').each do |op|
case op
when /[-+=]/ then
action = op
value = 0 if op == '='
when /[ugo]/ then
value = actions[action].call(value, snapshot_mode[op])
when /[rwx]/ then
value = actions[action].call(value, SymbolicMode[op])
when 'X' then
if action != '+' then
raise Puppet::Error, _("X only works with the '+' operator")
end
if is_a_directory or original_mode['any x?'] then
value = actions[action].call(value, ExecBit)
end
when /[st]/ then
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 then
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
end
result =
final_mode['s'] << 9 |
final_mode['u'] << 6 |
final_mode['g'] << 3 |
final_mode['o'] << 0
return result
end
|