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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File '../../src/include/sudo/dialog-spec.rb', line 30
def AddEditUserSpecDialog(what)
caption = ""
spec = {}
commands = []
users = Convert.convert(
Builtins.merge(Sudo.all_users, Sudo.GetAliasNames("user")),
:from => "list",
:to => "list <string>"
)
hosts = Builtins.prepend(Sudo.GetAliasNames("host"), "ALL")
run_as = Convert.convert(
Builtins.merge(Sudo.all_users, Sudo.GetAliasNames("run_as")),
:from => "list",
:to => "list <string>"
)
if what == "Add"
caption = _("New Sudo Rule")
elsif what == "Edit"
caption = _("Existing Sudo Rule ")
spec = Sudo.GetRule(Sudo.GetItem)
commands = Ops.get_list(spec, "commands", [])
end
contents = VBox(
Left(
ComboBox(
Id("user_name"),
Opt(:editable),
_("User, Group or User Alias"),
Builtins.sort(users) { |s, t| Ops.less_than(s, t) }
)
),
Left(
ComboBox(
Id("host_name"),
Opt(:editable),
_("Host or Host Alias"),
Builtins.sort(hosts) { |s, t| Ops.less_than(s, t) }
)
),
Left(
ComboBox(
Id("run_as"),
Opt(:editable),
_("RunAs or RunAs Alias"),
Builtins.sort(run_as) { |s, t| Ops.less_than(s, t) }
)
),
Left(CheckBox(Id("no_passwd"), _("No Password"))),
Left(Label(_("Commands to Run"))),
Table(Id("commands"), Header(_("Command"), _("Parameters")), []),
Left(
HBox(
PushButton(
Id("command_add"),
Opt(:key_F3),
Ops.add(Ops.add(" ", Label.AddButton), " ")
),
PushButton(
Id("command_edit"),
Opt(:key_F4),
Ops.add(Ops.add(" ", Label.EditButton), " ")
),
PushButton(
Id("command_remove"),
Opt(:key_F5),
Ops.add(Ops.add(" ", Label.DeleteButton), " ")
)
)
)
)
Wizard.SetContentsButtons(
caption,
contents,
Ops.get_string(@HELPS, "spec_single", ""),
Label.CancelButton,
Label.OKButton
)
Wizard.HideAbortButton
UI.ChangeWidget(Id("user_name"), :ValidChars, Sudo.ValidCharsUsername)
UI.ChangeWidget(Id("run_as"), :ValidChars, Sudo.ValidCharsUsername)
UI.ChangeWidget(Id("user_name"), :Value, Ops.get_string(spec, "user", ""))
UI.ChangeWidget(Id("host_name"), :Value, Ops.get_string(spec, "host", ""))
UI.ChangeWidget(
Id("run_as"),
:Value,
Builtins.deletechars(Ops.get_string(spec, "run_as", ""), "()")
)
UI.ChangeWidget(
Id("no_passwd"),
:Value,
Ops.get_string(spec, "tag", "") == "NOPASSWD:"
)
RedrawCmndTable(commands)
ret = nil
while true
ret = UI.UserInput
if ret == :next
Ops.set(spec, "user", UI.QueryWidget(Id("user_name"), :Value))
Ops.set(spec, "host", UI.QueryWidget(Id("host_name"), :Value))
Ops.set(
spec,
"run_as",
Convert.to_string(UI.QueryWidget(Id("run_as"), :Value))
)
Ops.set(spec, "commands", commands)
if Convert.to_boolean(UI.QueryWidget(Id("no_passwd"), :Value))
Ops.set(spec, "tag", "NOPASSWD:")
else
Ops.set(spec, "tag", "")
end
if Ops.get_string(spec, "user", "") == ""
Popup.Error(_("Username must not be empty."))
UI.SetFocus(Id("user_name"))
next
end
if Ops.get_string(spec, "host", "") == ""
Popup.Error(_("Hostname must not be empty."))
UI.SetFocus(Id("host_name"))
next
end
if !ValidateHost(Ops.get_string(spec, "host", ""))
UI.SetFocus(Id("host_name"))
next
end
if Ops.get_list(spec, "commands", []) == []
Popup.Error(_("Command list must have at least one entry."))
UI.SetFocus(Id("commands"))
next
end
if Ops.get_string(spec, "run_as", "") != ""
Ops.set(
spec,
"run_as",
Ops.add(Ops.add("(", Ops.get_string(spec, "run_as", "")), ")")
)
end
Sudo.SetRule(Sudo.GetItem, spec)
Sudo.SetModified
break
elsif ret == :back
break
elsif ret == "command_add"
new_command = AddCommandDialog("", "")
if new_command != "" && !Builtins.contains(commands, new_command)
Builtins.y2milestone("%1", new_command)
commands = Builtins.add(commands, new_command)
RedrawCmndTable(commands)
end
elsif ret == "command_edit"
current_item = Convert.to_integer(
UI.QueryWidget(Id("commands"), :CurrentItem)
)
it = Convert.to_term(
UI.QueryWidget(Id("commands"), term(:Item, current_item))
)
new_command = AddCommandDialog(
Ops.get_string(it, 1, ""),
Ops.get_string(it, 2, "")
)
if new_command != ""
Ops.set(commands, current_item, new_command)
RedrawCmndTable(commands)
end
elsif ret == "command_remove"
current_item = Convert.to_integer(
UI.QueryWidget(Id("commands"), :CurrentItem)
)
commands = Builtins.remove(commands, current_item)
RedrawCmndTable(commands)
else
Builtins.y2error("unexpected retcode: %1", ret)
next
end
end
@initial_screen = "user_specs"
Wizard.RestoreNextButton
deep_copy(ret)
end
|