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

yast / yast-users / 16077312203

04 Jul 2025 03:51PM UTC coverage: 70.346% (+10.0%) from 60.368%
16077312203

Pull #402

github

imobachgs
Bump version and update changes file
Pull Request #402: Disable auto client unit tests

3212 of 4566 relevant lines covered (70.35%)

40.81 hits per line

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

30.67
/src/modules/UsersUI.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2006-2012 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:        modules/UsersUI.ycp
23
# Package:        Configuration of users and groups
24
# Summary:        UI-related routines to be run from perl modules (Users.pm etc.)
25
# Author:        Jiri Suchomel <jsuchome@suse.cz>
26
#
27
# $Id$
28
require "yast"
1✔
29

30
module Yast
1✔
31
  class UsersUIClass < Module
1✔
32
    def main
1✔
33
      Yast.import "UI"
1✔
34
      textdomain "users"
1✔
35

36
      Yast.import "Label"
1✔
37
    end
38

39
    # Return the translated name for system user
40
    def SystemUserName(name)
1✔
41
      # TODO users are added manualy.... :-(
42
      _SystemUsers = {
43
        # User name for user: "root"
44
        "root"                                           => _(
×
45
          "root"
46
        ),
47
        # User name for user: "bin"
48
        "bin"                                            => _(
49
          "bin"
50
        ),
51
        # User name for user: "daemon"
52
        "Daemon"                                         => _(
53
          "Daemon"
54
        ),
55
        # User name for user: "lp"
56
        "Printing daemon"                                => _(
57
          "Printing Daemon"
58
        ),
59
        # User name for user: "mail"
60
        "Mailer daemon"                                  => _(
61
          "Mailer Daemon"
62
        ),
63
        # User name for user: "news"
64
        "News system"                                    => _(
65
          "News System"
66
        ),
67
        # User name for user: "uucp"
68
        "Unix-to-Unix CoPy system"                       => _(
69
          "Unix-to-Unix Copy System"
70
        ),
71
        # User name for user: "games"
72
        "Games account"                                  => _(
73
          "Games Account"
74
        ),
75
        # User name for user: "man"
76
        "Manual pages viewer"                            => _(
77
          "Manual Page Viewer"
78
        ),
79
        # User name for user: "at"
80
        "Batch jobs daemon"                              => _(
81
          "Batch Jobs Daemon"
82
        ),
83
        # User name for user: "wwwrun"
84
        "WWW daemon apache"                              => _(
85
          "WWW Daemon Apache"
86
        ),
87
        # User name for user: "ftp"
88
        "FTP account"                                    => _(
89
          "FTP Account"
90
        ),
91
        # User name for user: "named"
92
        "Nameserver daemon"                              => _(
93
          "Name Server Daemon"
94
        ),
95
        # User name for user: "gdm"
96
        "Gnome Display Manager daemon"                   => _(
97
          "GNOME Display Manager Daemon"
98
        ),
99
        # User name for user: "postfix"
100
        "Postfix Daemon"                                 => _(
101
          "Postfix Daemon"
102
        ),
103
        # User name for user: "sshd"
104
        "SSH daemon"                                     => _(
105
          "SSH Daemon"
106
        ),
107
        # User name for user: "ntp"
108
        "NTP daemon"                                     => _(
109
          "NTP Daemon"
110
        ),
111
        # User name for user: "ldap"
112
        "User for OpenLDAP"                              => _(
113
          "User for OpenLDAP"
114
        ),
115
        # User name for user: "nobody"
116
        "nobody"                                         => _(
117
          "Nobody"
118
        ),
119
        # User name for user: "amanda"
120
        "Amanda admin"                                   => _(
121
          "Amanda Admin"
122
        ),
123
        # User name for user: "vscan"
124
        "Vscan account"                                  => _(
125
          "Vscan Account"
126
        ),
127
        # User name for user: "bigsister"
128
        "Big Sister"                                     => _(
129
          "Big Sister"
130
        ),
131
        # User name for user: "wnn"
132
        "Wnn System Account"                             => _(
133
          "Wnn System Account"
134
        ),
135
        # User name for user: "cyrus"
136
        "User for cyrus-imapd"                           => _(
137
          "User for cyrus-imapd"
138
        ),
139
        # User name for user: "dpbox"
140
        "DpBox account"                                  => _(
141
          "DpBox Account"
142
        ),
143
        # User name for user: "gnats"
144
        "GNATS GNU Backtracking System"                  => _(
145
          "GNATS GNU Backtracking System"
146
        ),
147
        # User name for user: "gnump3d"
148
        "GNUMP3 daemon"                                  => _(
149
          "GNUMP3 Daemon"
150
        ),
151
        # User name for user: "hacluster"
152
        "heartbeat processes"                            => _(
153
          "Heartbeat Processes"
154
        ),
155
        # User name for user: "irc"
156
        "IRC daemon"                                     => _(
157
          "IRC Daemon"
158
        ),
159
        # User name for user: "mailman"
160
        "GNU mailing list manager"                       => _(
161
          "GNU Mailing List Manager"
162
        ),
163
        # User name for user: "mdom"
164
        "Mailing list agent"                             => _(
165
          "Mailing List Agent"
166
        ),
167
        # User name for user: "mysql"
168
        "MySQL database admin"                           => _(
169
          "MySQL Database Admin"
170
        ),
171
        # User name for user: "oracle"
172
        "Oracle user"                                    => _(
173
          "Oracle User"
174
        ),
175
        # User name for user: "postgres"
176
        "PostgreSQL Server"                              => _(
177
          "PostgreSQL Server"
178
        ),
179
        # User name for user: "pop"
180
        "POP admin"                                      => _(
181
          "POP Admin"
182
        ),
183
        # User name for user: "sapdb"
184
        "SAPDB account"                                  => _(
185
          "SAPDB Account"
186
        ),
187
        # User name for user: "snort"
188
        "Snort network monitor"                          => _(
189
          "Snort Network Monitor"
190
        ),
191
        # User name for user: "squid"
192
        "WWW-proxy squid"                                => _(
193
          "WWW Proxy Squid"
194
        ),
195
        # User name for user: "stunnel"
196
        "Daemon user for stunnel (universal SSL tunnel)" => _(
197
          "Daemon User for stunnel (Universal SSL Tunnel)"
198
        ),
199
        # User name for user: "zope"
200
        "Zope"                                           => _(
201
          "Zope"
202
        ),
203
        # User name for user: "radiusd"
204
        "Radius daemon"                                  => _(
205
          "Radius Daemon"
206
        ),
207
        # User name for user: "otrs"
208
        "OTRS System User"                               => _(
209
          "OTRS System User"
210
        ),
211
        # User name for user: "privoxy"
212
        "Daemon user for privoxy"                        => _(
213
          "Daemon User for privoxy"
214
        ),
215
        # User name for user: "vdr"
216
        "Video Disk Recorder"                            => _(
217
          "Video Disk Recorder"
218
        ),
219
        # User name for user: "icecream"
220
        "Icecream Daemon"                                => _(
221
          "Icecream Daemon"
222
        ),
223
        # User name for user: "bitlbee"
224
        "Bitlbee Daemon User"                            => _(
225
          "Bitlbee Daemon User"
226
        ),
227
        # User name for user: "dhcpd"
228
        "DHCP server daemon"                             => _(
229
          "DHCP Server Daemon"
230
        ),
231
        # User name for user: "distcc"
232
        "Distcc Daemon"                                  => _(
233
          "Distcc Daemon"
234
        ),
235
        # User name for user: "dovecot"
236
        "Dovecot imap daemon"                            => _(
237
          "Dovecot IMAP Daemon"
238
        ),
239
        # User name for user: "fax"
240
        "Facsimile agent"                                => _(
241
          "Facsimile Agent"
242
        ),
243
        # User name for user: "partimag"
244
        "Partimage Daemon User"                          => _(
245
          "Partimage Daemon User"
246
        ),
247
        # User name for user: "avahi"
248
        "User for Avahi"                                 => _(
249
          "User for Avahi"
250
        ),
251
        # User name for user: "beagleindex"
252
        "User for Beagle indexing"                       => _(
253
          "User for Beagle indexing"
254
        ),
255
        # User name for user: "casaauth"
256
        "casa_atvd System User"                          => _(
257
          "casa_atvd System User"
258
        ),
259
        # User name for user: "dvbdaemon"
260
        "User for DVB daemon"                            => _(
261
          "User for DVB daemon"
262
        ),
263
        # User name for user: "festival"
264
        "Festival daemon"                                => _(
265
          "Festival daemon"
266
        ),
267
        # User name for user: "haldaemon"
268
        "User for haldaemon"                             => _(
269
          "User for haldaemon"
270
        ),
271
        # User name for user: "icecast"
272
        "Icecast streaming server"                       => _(
273
          "Icecast streaming server"
274
        ),
275
        # User name for user: "lighttpd"
276
        "user for lighttpd"                              => _(
277
          "User for lighttpd"
278
        ),
279
        # User name for user: "nagios"
280
        "User for Nagios"                                => _(
281
          "User for Nagios"
282
        ),
283
        # User name for user: "pdns"
284
        "pdns"                                           => _(
285
          "User for PowerDNS"
286
        ),
287
        # User name for user: "polkituser"
288
        "PolicyKit"                                      => _(
289
          "PolicyKit"
290
        ),
291
        # User name for user: "pound"
292
        "Pound"                                          => _(
293
          "User for Pound"
294
        ),
295
        # User name for user: "pulse"
296
        "PulseAudio daemon"                              => _(
297
          "PulseAudio daemon"
298
        ),
299
        # User name for user: "quagga"
300
        "Quagga routing daemon"                          => _(
301
          "Quagga routing daemon"
302
        ),
303
        # User name for user: "sabayon-admin"
304
        "Sabayon user"                                   => _(
305
          "Sabayon user"
306
        ),
307
        # User name for user: "tomcat"
308
        "Tomcat - Apache Servlet/JSP Engine"             => _(
309
          "Tomcat - Apache Servlet/JSP Engine"
310
        ),
311
        # User name for user: "tomcat"
312
        "Apache Tomcat"                                  => _(
313
          "Apache Tomcat"
314
        ),
315
        # User name for user: "pegasus"
316
        # User name for user: "cimsrvr"
317
        "tog-pegasus OpenPegasus WBEM/CIM services"      => _(
318
          "tog-pegasus OpenPegasus WBEM/CIM services"
319
        ),
320
        # User name for user: "ulogd"
321
        "ulog daemon"                                    => _(
322
          "ulog daemon"
323
        ),
324
        # User name for user: "uuidd"
325
        "User for uuidd"                                 => _(
326
          "User for uuidd"
327
        ),
328
        # User name for user: "suse-ncc"
329
        "Novell Customer Center User"                    => _(
330
          "Novell Customer Center User"
331
        )
332
      }
333
      Ops.get_string(_SystemUsers, name, name)
×
334
    end
335

336
    # Ask user for configuration type (standard or NIS)
337
    # @param [String] dir string directory with NIS settings
338
    # @return [Symbol] `passwd or `nis or `abort
339
    def getConfigurationType(dir)
1✔
340
      contents = VBox(
×
341
        # label
342
        Label(
343
          _(
344
            "You have installed a NIS master server.\n" +
345
              "It is configured to use a different database\n" +
346
              "of users and groups than the local system \n" +
347
              "database in the /etc directory.\n" +
348
              "Select which one to configure.\n"
349
          )
350
        ),
351
        VSpacing(1),
352
        RadioButtonGroup(
353
          Id(:configtype),
354
          VBox(
355
            # radio button
356
            RadioButton(
357
              Id(:passwd),
358
              Opt(:hstretch),
359
              _("&Local (/etc directory)"),
360
              true
361
            ),
362
            VSpacing(1),
363
            # radio button, %1 is path (eg. /etc)
364
            RadioButton(
365
              Id(:nis),
366
              Opt(:hstretch),
367
              Builtins.sformat(_("&NIS (%1 directory)"), dir),
368
              false
369
            )
370
          )
371
        ),
372
        VSpacing(1),
373
        HBox(
374
          HStretch(),
375
          PushButton(Id(:ok), Opt(:default), Label.OKButton),
376
          HStretch(),
377
          PushButton(Id(:abort), Label.AbortButton),
378
          HStretch()
379
        )
380
      )
381
      UI.OpenDialog(contents)
×
382
      ret = nil
×
383
      while ret == nil
×
384
        ret = Convert.to_symbol(UI.UserInput)
×
385
        next if ret != :cancel && ret != :ok
×
386
      end
387
      if ret == :ok
×
388
        ret = Convert.to_symbol(UI.QueryWidget(Id(:configtype), :CurrentButton))
×
389
      end
390
      UI.CloseDialog
×
391
      ret
×
392
    end
393

394
    # If we can ask and are a NIS server, ask which set of users
395
    # to administer and set UserWriteStack accordingly.
396
    # @param [String] basedir the directory, where the data are stored
397
    # @return directory
398
    def ReadNISConfigurationType(basedir)
1✔
399
      ypdir = Convert.to_string(
×
400
        SCR.Read(path(".sysconfig.ypserv.YPPWD_SRCDIR"))
401
      )
402
      while Builtins.substring(ypdir, Ops.subtract(Builtins.size(ypdir), 1)) == "/"
×
403
        ypdir = Builtins.substring(
×
404
          ypdir,
405
          0,
406
          Ops.subtract(Builtins.size(ypdir), 1)
407
        )
408
      end
409
      ypdir = basedir if ypdir == "" || ypdir == nil
×
410
      if ypdir != basedir
×
411
        type = getConfigurationType(ypdir)
×
412
        return nil if type == :abort
×
413
        ypdir = basedir if type != :nis
×
414
      end
415
      ypdir
×
416
    end
417

418
    def ChooseTemplates(user_templates, group_templates)
1✔
419
      user_templates = deep_copy(user_templates)
×
420
      group_templates = deep_copy(group_templates)
×
421
      user_template = Ops.get(user_templates, 0, "")
×
422
      group_template = Ops.get(group_templates, 0, "")
×
423

424
      # label above radiobutton box
425
      rbu_buttons = VBox(Left(Label(_("User Templates"))))
×
426
      # label above radiobutton box
427
      rbg_buttons = VBox(Left(Label(_("Group Templates"))))
×
428
      Builtins.foreach(user_templates) do |templ|
×
429
        rbu_buttons = Builtins.add(
×
430
          rbu_buttons,
431
          Left(RadioButton(Id(templ), templ, true))
432
        )
433
      end
434
      Builtins.foreach(group_templates) do |templ|
×
435
        rbg_buttons = Builtins.add(
×
436
          rbg_buttons,
437
          Left(RadioButton(Id(templ), templ, true))
438
        )
439
      end
440
      rb_users = RadioButtonGroup(Id(:rbu), rbu_buttons)
×
441
      rb_groups = RadioButtonGroup(Id(:rbg), rbg_buttons)
×
442

443
      UI.OpenDialog(
×
444
        Opt(:decorated),
445
        HBox(
446
          HSpacing(1),
447
          VBox(
448
            HSpacing(50),
449
            VSpacing(0.5),
450
            # label
451
            Label(
452
              _(
453
                "Multiple templates are defined as default. Select the one to read."
454
              )
455
            ),
456
            VSpacing(0.5),
457
            user_templates == [] ? Empty() : rb_users,
×
458
            VSpacing(0.5),
459
            group_templates == [] ? Empty() : rb_groups,
×
460
            HBox(
461
              PushButton(Id(:ok), Opt(:default), Label.OKButton),
462
              PushButton(Id(:cancel), Label.CancelButton)
463
            )
464
          ),
465
          HSpacing(1)
466
        )
467
      )
468
      ret = UI.UserInput
×
469
      if ret == :ok
×
470
        if user_templates != []
×
471
          user_template = Convert.to_string(
×
472
            UI.QueryWidget(Id(:rbu), :CurrentButton)
473
          )
474
        end
475
        if group_templates != []
×
476
          group_template = Convert.to_string(
×
477
            UI.QueryWidget(Id(:rbg), :CurrentButton)
478
          )
479
        end
480
      end
481
      UI.CloseDialog
×
482
      { "user" => user_template, "group" => user_template }
×
483
    end
484

485
    # Error messages for errors detected during reading via .passwd agent
486
    # @param errno [Integer] number returned by passwd-agent
487
    # @param more [String] additional information
488
    # @return error message
489
    def GetPasswdErrorMessage(errno, more)
1✔
490
      last =
491
        # error message 2/2 (= next sentence)
492
        _("Correct them manually before running the YaST users module again.")
×
493

494
      read_error = {
495
        2 => Builtins.sformat(
×
496
          # error message 1/2: %1 is file name, %2 is username, %3 is next sentence (2/2)
497
          _(
498
            "There are multiple users with the same name (\"%2\") in the file %1.\n%3"
499
          ),
500
          "/etc/passwd",
501
          more,
502
          last
503
        ),
504
        3 => Builtins.sformat(
505
          # error message 1/2: %1 is file name, %2 is username, %3 is next sentence (2/2)
506
          _(
507
            "There are multiple users with the same name (\"%2\") in the file %1.\n%3"
508
          ),
509
          "/etc/shadow",
510
          more,
511
          last
512
        ),
513
        6 => Builtins.sformat(
514
          # error message 1/2: %1 is file name, %2 is groupname, %3 next sentence (2/2)
515
          _(
516
            "There are multiple groups with the same name (\"%2\") in the file %1.\n%3"
517
          ),
518
          "/etc/group",
519
          more,
520
          last
521
        ),
522
        7 => Builtins.sformat(
523
          # error message 1/2: %1 is file name, %2 is line
524
          _(
525
            "There is a strange line in the file %1:\n" +
526
              "%2\n" +
527
              "Perhaps the number of colons is wrong or some line entry is missing.\n" +
528
              "Correct the file manually before running the YaST users module again."
529
          ),
530
          "/etc/passwd",
531
          more
532
        ),
533
        8 => Builtins.sformat(
534
          # error message 1/2: %1 is file name, %2 is line
535
          _(
536
            "There is a strange line in the file %1:\n" +
537
              "%2\n" +
538
              "Perhaps the number of colons is wrong or some line entry is missing.\n" +
539
              "Correct the file manually before running the YaST users module again."
540
          ),
541
          "/etc/group",
542
          more
543
        ),
544
        9 => Builtins.sformat(
545
          # error message 1/2: %1 is file name
546
          _(
547
            "There is a strange line in the file %1.\n" +
548
              "Perhaps the number of colons is wrong or some line entry is missing.\n" +
549
              "Correct the file manually before running the YaST users module again."
550
          ),
551
          "/etc/shadow"
552
        )
553
      }
554

555
      # default error message
556
      Ops.get_locale(read_error, errno, _("Cannot read user or group data."))
×
557
    end
558

559

560
    # recode the string from "environment encoding" to UTF-8
561
    def RecodeUTF(text)
1✔
562
      Convert.to_string(UI.Recode(WFM.GetEnvironmentEncoding, "UTF-8", text))
3✔
563
    end
564

565

566
    def HashPassword(method, pw)
1✔
567
      return Builtins.cryptmd5(pw) if method == "md5"
×
568
      return Builtins.cryptblowfish(pw) if method == "blowfish"
×
569
      return Builtins.cryptsha256(pw) if method == "sha256"
×
570
      return Builtins.cryptsha512(pw) if method == "sha512"
×
571
      Builtins.crypt(pw)
×
572
    end
573

574
    publish :function => :SystemUserName, :type => "string (string)"
1✔
575
    publish :function => :ReadNISConfigurationType, :type => "string (string)"
1✔
576
    publish :function => :ChooseTemplates, :type => "map (list <string>, list <string>)"
1✔
577
    publish :function => :GetPasswdErrorMessage, :type => "string (integer, string)"
1✔
578
    publish :function => :RecodeUTF, :type => "string (string)"
1✔
579
    publish :function => :HashPassword, :type => "string (string, string)"
1✔
580
  end
581

582
  UsersUI = UsersUIClass.new
1✔
583
  UsersUI.main
1✔
584
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