• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-sudo / 10832030092

12 Sep 2024 01:38PM UTC coverage: 6.074%. Remained the same
10832030092

push

github

lslezak
Import the changes from the OBS SLE15-SP6 project

140 of 2305 relevant lines covered (6.07%)

0.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/include/sudo/dialog-spec.rb
1
# encoding: utf-8
2

3
module Yast
×
4
  module SudoDialogSpecInclude
×
5
    def initialize_sudo_dialog_spec(include_target)
×
6
      Yast.import "UI"
×
7

8
      textdomain "sudo"
×
9

10
      Yast.import "Wizard"
×
11
      Yast.import "Sudo"
×
12
      Yast.import "Label"
×
13
      Yast.import "Popup"
×
14

15
      Yast.include include_target, "sudo/helps.rb"
×
16
      Yast.include include_target, "sudo/complex.rb"
×
17
    end
×
18

19
    def RedrawCmndTable(commands)
×
20
      commands = deep_copy(commands)
×
21
      items = UpdateCmdList(commands)
×
22

23
      UI.ChangeWidget(Id("commands"), :Items, items)
×
24
      EnableDisableButtons("command_edit", "command_remove", items)
×
25

26
      nil
×
27
    end
×
28

29

30
    def AddEditUserSpecDialog(what)
×
31
      caption = ""
×
32
      spec = {}
×
33
      commands = []
×
34
      users = Convert.convert(
×
35
        Builtins.merge(Sudo.all_users, Sudo.GetAliasNames("user")),
×
36
        :from => "list",
×
37
        :to   => "list <string>"
×
38
      )
×
39
      hosts = Builtins.prepend(Sudo.GetAliasNames("host"), "ALL")
×
40
      run_as = Convert.convert(
×
41
        Builtins.merge(Sudo.all_users, Sudo.GetAliasNames("run_as")),
×
42
        :from => "list",
×
43
        :to   => "list <string>"
×
44
      )
×
45

46
      if what == "Add"
×
47
        caption = _("New Sudo Rule") 
×
48
        #Setting default values
49
      elsif what == "Edit"
×
50
        caption = _("Existing Sudo Rule ")
×
51
        spec = Sudo.GetRule(Sudo.GetItem)
×
52
        commands = Ops.get_list(spec, "commands", [])
×
53
      end
×
54

55
      contents = VBox(
×
56
        Left(
×
57
          ComboBox(
×
58
            Id("user_name"),
×
59
            Opt(:editable),
×
60
            _("User, Group or User Alias"),
×
61
            Builtins.sort(users) { |s, t| Ops.less_than(s, t) }
×
62
          )
×
63
        ),
×
64
        Left(
×
65
          ComboBox(
×
66
            Id("host_name"),
×
67
            Opt(:editable),
×
68
            _("Host or Host Alias"),
×
69
            Builtins.sort(hosts) { |s, t| Ops.less_than(s, t) }
×
70
          )
×
71
        ),
×
72
        Left(
×
73
          ComboBox(
×
74
            Id("run_as"),
×
75
            Opt(:editable),
×
76
            _("RunAs or RunAs Alias"),
×
77
            Builtins.sort(run_as) { |s, t| Ops.less_than(s, t) }
×
78
          )
×
79
        ),
×
80
        Left(CheckBox(Id("no_passwd"), _("No Password"))),
×
81
        Left(Label(_("Commands to Run"))),
×
82
        Table(Id("commands"), Header(_("Command"), _("Parameters")), []),
×
83
        Left(
×
84
          HBox(
×
85
            PushButton(
×
86
              Id("command_add"),
×
87
              Opt(:key_F3),
×
88
              Ops.add(Ops.add(" ", Label.AddButton), " ")
×
89
            ),
×
90
            PushButton(
×
91
              Id("command_edit"),
×
92
              Opt(:key_F4),
×
93
              Ops.add(Ops.add(" ", Label.EditButton), " ")
×
94
            ),
×
95
            PushButton(
×
96
              Id("command_remove"),
×
97
              Opt(:key_F5),
×
98
              Ops.add(Ops.add(" ", Label.DeleteButton), " ")
×
99
            )
×
100
          )
×
101
        )
×
102
      )
×
103

104
      Wizard.SetContentsButtons(
×
105
        caption,
×
106
        contents,
×
107
        Ops.get_string(@HELPS, "spec_single", ""),
×
108
        Label.CancelButton,
×
109
        Label.OKButton
×
110
      )
×
111
      Wizard.HideAbortButton
×
112
      UI.ChangeWidget(Id("user_name"), :ValidChars, Sudo.ValidCharsUsername)
×
113
      UI.ChangeWidget(Id("run_as"), :ValidChars, Sudo.ValidCharsUsername)
×
114

115
      #initialize UI
116
      UI.ChangeWidget(Id("user_name"), :Value, Ops.get_string(spec, "user", ""))
×
117
      UI.ChangeWidget(Id("host_name"), :Value, Ops.get_string(spec, "host", ""))
×
118
      UI.ChangeWidget(
×
119
        Id("run_as"),
×
120
        :Value,
×
121
        Builtins.deletechars(Ops.get_string(spec, "run_as", ""), "()")
×
122
      )
×
123
      UI.ChangeWidget(
×
124
        Id("no_passwd"),
×
125
        :Value,
×
126
        Ops.get_string(spec, "tag", "") == "NOPASSWD:"
×
127
      )
×
128
      RedrawCmndTable(commands)
×
129

130

131
      ret = nil
×
132
      while true
×
133
        ret = UI.UserInput
×
134
        # next
135
        if ret == :next
×
136
          Ops.set(spec, "user", UI.QueryWidget(Id("user_name"), :Value))
×
137
          Ops.set(spec, "host", UI.QueryWidget(Id("host_name"), :Value))
×
138
          Ops.set(
×
139
            spec,
×
140
            "run_as",
×
141
            Convert.to_string(UI.QueryWidget(Id("run_as"), :Value))
×
142
          )
×
143
          Ops.set(spec, "commands", commands)
×
144

145
          if Convert.to_boolean(UI.QueryWidget(Id("no_passwd"), :Value))
×
146
            Ops.set(spec, "tag", "NOPASSWD:")
×
147
          else
×
148
            Ops.set(spec, "tag", "")
×
149
          end
×
150

151
          if Ops.get_string(spec, "user", "") == ""
×
152
            Popup.Error(_("Username must not be empty."))
×
153
            UI.SetFocus(Id("user_name"))
×
154
            next
×
155
          end
×
156
          if Ops.get_string(spec, "host", "") == ""
×
157
            Popup.Error(_("Hostname must not be empty."))
×
158
            UI.SetFocus(Id("host_name"))
×
159
            next
×
160
          end
×
161
          if !ValidateHost(Ops.get_string(spec, "host", ""))
×
162
            UI.SetFocus(Id("host_name"))
×
163
            next
×
164
          end
×
165
          if Ops.get_list(spec, "commands", []) == []
×
166
            Popup.Error(_("Command list must have at least one entry."))
×
167
            UI.SetFocus(Id("commands"))
×
168
            next
×
169
          end
×
170
          if Ops.get_string(spec, "run_as", "") != ""
×
171
            Ops.set(
×
172
              spec,
×
173
              "run_as",
×
174
              Ops.add(Ops.add("(", Ops.get_string(spec, "run_as", "")), ")")
×
175
            )
×
176
          end
×
177
          Sudo.SetRule(Sudo.GetItem, spec)
×
178
          Sudo.SetModified
×
179
          break 
×
180
          # back
181
        elsif ret == :back
×
182
          break 
×
183
          # add command
184
        elsif ret == "command_add"
×
185
          new_command = AddCommandDialog("", "")
×
186

187
          if new_command != "" && !Builtins.contains(commands, new_command)
×
188
            Builtins.y2milestone("%1", new_command)
×
189
            commands = Builtins.add(commands, new_command)
×
190
            RedrawCmndTable(commands)
×
191
          end 
×
192
          # edit command
193
        elsif ret == "command_edit"
×
194
          current_item = Convert.to_integer(
×
195
            UI.QueryWidget(Id("commands"), :CurrentItem)
×
196
          )
×
197
          it = Convert.to_term(
×
198
            UI.QueryWidget(Id("commands"), term(:Item, current_item))
×
199
          )
×
200

201
          new_command = AddCommandDialog(
×
202
            Ops.get_string(it, 1, ""),
×
203
            Ops.get_string(it, 2, "")
×
204
          )
×
205
          if new_command != ""
×
206
            Ops.set(commands, current_item, new_command)
×
207
            RedrawCmndTable(commands)
×
208
          end 
×
209

210
          # remove command
211
        elsif ret == "command_remove"
×
212
          current_item = Convert.to_integer(
×
213
            UI.QueryWidget(Id("commands"), :CurrentItem)
×
214
          )
×
215

216
          commands = Builtins.remove(commands, current_item)
×
217
          RedrawCmndTable(commands)
×
218
        else
×
219
          Builtins.y2error("unexpected retcode: %1", ret)
×
220
          next
×
221
        end
×
222
      end
×
223

224
      @initial_screen = "user_specs"
×
225
      Wizard.RestoreNextButton
×
226
      deep_copy(ret)
×
227
    end
×
228

229
    def SaveUserSpec
×
230
      :next
×
231
    end
×
232
  end
×
233
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc