• 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/complex.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2006 Novell, Inc. All Rights Reserved.
5
#
6
#
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of version 2 of the GNU General Public License as published by the
9
# Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail, you may find
19
# current contact information at www.novell.com.
20
# ------------------------------------------------------------------------------
21

22
# File:        include/sudo/complex.ycp
23
# Package:        Configuration of sudo
24
# Summary:        Dialogs definitions
25
# Authors:        Bubli <kmachalkova@suse.cz>
26
#
27
# $Id: complex.ycp 29363 2006-03-24 08:20:43Z mzugec $
28
module Yast
×
29
  module SudoComplexInclude
×
30
    def initialize_sudo_complex(include_target)
×
31
      Yast.import "UI"
×
32

33
      textdomain "sudo"
×
34

35
      Yast.import "Label"
×
36
      Yast.import "Popup"
×
37
      Yast.import "Wizard"
×
38
      Yast.import "Confirm"
×
39
      Yast.import "Sudo"
×
40
      Yast.import "Report"
×
41
      Yast.import "Address"
×
42
      Yast.import "Netmask"
×
43
      Yast.import "FileUtils"
×
44

45

46
      Yast.include include_target, "sudo/helps.rb"
×
47

48
      @current_alias_name = ""
×
49
      @current_spec_idx = -1
×
50
      @initial_screen = "user_specs"
×
51
    end
×
52

53
    def EnableDisableButtons(edit_button, delete_button, items)
×
54
      items = deep_copy(items)
×
55
      UI.ChangeWidget(Id(edit_button), :Enabled, items != [])
×
56
      UI.ChangeWidget(Id(delete_button), :Enabled, items != [])
×
57

58
      nil
×
59
    end
×
60

61
    def ValidateHost(hostname)
×
62
      netmask = ""
×
63

64
      if Builtins.findfirstof(hostname, "/") != nil
×
65
        tmp = Builtins.splitstring(hostname, "/")
×
66
        hostname = Ops.get(tmp, 0, "")
×
67
        netmask = Ops.get(tmp, 1, "")
×
68

69
        if !Netmask.Check(netmask)
×
70
          netmask = ""
×
71
          Popup.Error(
×
72
            _(
×
73
              "A valid netmask is either in dotted quad notation \n" +
×
74
                "(4 integers in the range 128 - 255 separated by dots) \n" +
×
75
                "or single integer in the range 0 - 32"
×
76
            )
×
77
          )
×
78
          return false
×
79
        end
×
80
      end
×
81
      if !Address.Check(hostname)
×
82
        Popup.Error(Address.Valid4)
×
83
        return false
×
84
      end
×
85
      true
×
86
    end
×
87

88
    def AddHostDialog(host)
×
89
      new_host = host
×
90

91
      UI.OpenDialog(
×
92
        Opt(:decorated),
×
93
        VBox(
×
94
          Frame(
×
95
            _("Add New Host to the Alias"),
×
96
            MarginBox(
×
97
              1,
×
98
              1,
×
99
              InputField(Id("host_name"), _("Hostname or Network"), new_host)
×
100
            )
×
101
          ),
×
102
          ButtonBox(
×
103
            PushButton(Id(:ok), Opt(:default, :okButton), Label.OKButton),
×
104
            PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton)
×
105
          )
×
106
        )
×
107
      )
×
108

109
      ret = nil
×
110
      while true
×
111
        ret = UI.UserInput
×
112
        if ret == :ok
×
113
          new_host = Convert.to_string(UI.QueryWidget(Id("host_name"), :Value))
×
114

115
          if !ValidateHost(new_host)
×
116
            UI.SetFocus(Id("host_name"))
×
117
            next
×
118
          end
×
119
          break
×
120
        elsif ret == :cancel
×
121
          break
×
122
        end
×
123
      end
×
124
      UI.CloseDialog
×
125
      new_host
×
126
    end
×
127

128
    def AddUserDialog(users)
×
129
      users = deep_copy(users)
×
130
      new_user = ""
×
131

132
      UI.OpenDialog(
×
133
        Opt(:decorated),
×
134
        VBox(
×
135
          Frame(
×
136
            _("Add New User to the Alias"),
×
137
            MarginBox(
×
138
              1,
×
139
              1,
×
140
              ComboBox(
×
141
                Id("user_name"),
×
142
                _("Local and System Users (Groups)"),
×
143
                users
×
144
              )
×
145
            )
×
146
          ),
×
147
          ButtonBox(
×
148
            PushButton(Id(:ok), Opt(:default, :okButton), Label.OKButton),
×
149
            PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton)
×
150
          )
×
151
        )
×
152
      )
×
153

154
      ret = nil
×
155
      while true
×
156
        ret = UI.UserInput
×
157
        if ret == :ok
×
158
          new_user = Convert.to_string(UI.QueryWidget(Id("user_name"), :Value))
×
159
          break
×
160
        elsif ret == :cancel
×
161
          break
×
162
        end
×
163
      end
×
164
      UI.CloseDialog
×
165
      new_user
×
166
    end
×
167

168
    def ValidateCommand(cmd)
×
169
      if FileUtils.Exists(cmd) ||
×
170
          Builtins.contains(Sudo.GetAliasNames("command"), cmd) ||
×
171
          cmd == "ALL"
×
172
        return true
×
173
      else
×
174
        Popup.Error(
×
175
          Builtins.sformat(
×
176
            _("File, directory or command alias '%1' does not exist."),
×
177
            cmd
×
178
          )
×
179
        )
×
180
        return false
×
181
      end
×
182
    end
×
183

184
    def AddCommandDialog(c, p)
×
185
      new_command = ""
×
186

187
      items = Sudo.GetAliasNames("command")
×
188

189
      items = Builtins.prepend(items, "ALL")
×
190

191
      UI.OpenDialog(
×
192
        Opt(:decorated),
×
193
        VBox(
×
194
          Frame(
×
195
            _("Add new command with optional parameters"),
×
196
            VBox(
×
197
              VSpacing(0.5),
×
198
              VBox(
×
199
                HBox(
×
200
                  MinWidth(
×
201
                    40,
×
202
                    ComboBox(Id("cmd"), Opt(:editable), _("Command"), items)
×
203
                  ),
×
204
                  VBox(VSpacing(1.1), PushButton(Id("browse_c"), _("Browse")))
×
205
                ),
×
206
                Left(TextEntry(Id("params"), _("Parameters (optional)"), p))
×
207
              ),
×
208
              VSpacing(0.5)
×
209
            )
×
210
          ),
×
211
          VSpacing(0.5),
×
212
          ButtonBox(
×
213
            PushButton(Id(:ok), Opt(:default, :okButton), Label.OKButton),
×
214
            PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton)
×
215
          )
×
216
        )
×
217
      )
×
218

219
      UI.ChangeWidget(Id("cmd"), :Value, c)
×
220

221
      ret = nil
×
222
      while true
×
223
        ret = UI.UserInput
×
224
        if ret == :ok
×
225
          cmd = Convert.to_string(UI.QueryWidget(Id("cmd"), :Value))
×
226
          params = Convert.to_string(UI.QueryWidget(Id("params"), :Value))
×
227

228
          if !ValidateCommand(cmd)
×
229
            UI.SetFocus(Id("cmd"))
×
230
            next
×
231
          end
×
232

233
          new_command = Ops.add(Ops.add(cmd, " "), params)
×
234
          break
×
235
        elsif ret == :cancel
×
236
          break
×
237
        elsif ret == "browse_c"
×
238
          new_cmd = UI.AskForExistingFile("/", "*", "Choose a command")
×
239
          UI.ChangeWidget(Id("cmd"), :Value, new_cmd)
×
240
        end
×
241
      end
×
242
      UI.CloseDialog
×
243
      new_command
×
244
    end
×
245

246
    def UpdateCmdList(members)
×
247
      members = deep_copy(members)
×
248
      idx = 0
×
249
      items = []
×
250

251
      Builtins.foreach(members) do |it|
×
252
        pos = Builtins.findfirstof(it, " \t")
×
253
        cmd = ""
×
254
        param = ""
×
255
        if pos != nil
×
256
          cmd = Builtins.substring(it, 0, pos)
×
257
          param = Builtins.substring(it, Ops.add(pos, 1))
×
258
        else
×
259
          cmd = it
×
260
          param = ""
×
261
        end
×
262
        items = Builtins.add(items, Item(Id(idx), cmd, param))
×
263
        idx = Ops.add(idx, 1)
×
264
      end
×
265

266
      deep_copy(items)
×
267
    end
×
268
    # Read settings dialog (currently unused)
269
    #  * @return `abort if aborted and `next otherwisea
270
    #  *
271
    #     symbol ReadDialog() {
272
    #         Wizard::RestoreHelp(HELPS["read"]:"");
273
    #
274
    #         //Check if user is root
275
    #         if (!Confirm::MustBeRoot())
276
    #                 return `abort;
277
    #
278
    #         boolean ret = Sudo::Read();
279
    #         return ret ? `next : `abort;
280
    #     }
281

282
    # Write settings dialog
283
    # @return `abort if aborted and `next otherwise
284
    def WriteDialog
×
285
      Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))
×
286
      ret = Sudo.Write
×
287

288
      #yes-no popup - an error occured when saving the configuration
289
      if !ret &&
×
290
          Popup.YesNo(
×
291
            _("Saving sudoer's configuration failed. Change the settings?")
×
292
          )
×
293
        return :back
×
294
      end
×
295
      ret ? :next : :abort
×
296
    end
×
297
  end
×
298
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