Skip to content

Commit

Permalink
Refactoring: Shared functionality moved to UsersUtils module
Browse files Browse the repository at this point in the history
  • Loading branch information
kobliha committed Dec 4, 2015
1 parent 5a89704 commit 14baa92
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Expand Up @@ -13,7 +13,8 @@ module_DATA = \
modules/UsersPluginLDAPAll.pm \
modules/UsersPluginLDAPPasswordPolicy.pm \
modules/UsersPluginKerberos.pm \
modules/UsersPasswd.pm
modules/UsersPasswd.pm \
modules/UsersUtils.rb

module1dir = @moduledir@/YaPI
module1_DATA = \
Expand Down
18 changes: 5 additions & 13 deletions src/lib/users/clients/inst_root_first.rb
Expand Up @@ -38,21 +38,14 @@ def main
Yast.import "ProductFeatures"
Yast.import "Report"
Yast.import "UsersSimple"
Yast.import "UsersUtils"
Yast.import "Wizard"

if UsersSimple.RootPasswordDialogSkipped
Builtins.y2milestone("root password was set with first user, skipping")
return :auto
end

@check_CA_constraints = ProductFeatures.GetBooleanFeature(
"globals",
"root_password_ca_check"
) == true

# minimal pw length for CA-management (F#300438)
@pw_min_CA = 4

# Title for root-password dialogue
@title = _("Password for the System Administrator \"root\"")

Expand Down Expand Up @@ -137,15 +130,15 @@ def main
)
)

if @check_CA_constraints
if UsersUtils.check_ca_constraints?
@helptext = Ops.add(
@helptext,
Builtins.sformat(
# additional help text about password
_(
"<p>If you intend to use this password for creating certificates,\nit has to be at least %1 characters long.</p>"
),
@pw_min_CA
UsersUtilsClass::MIN_PASSWORD_LENGTH_CA
)
)
end
Expand Down Expand Up @@ -215,16 +208,15 @@ def main
{ "uid" => "root", "userPassword" => @pw1, "type" => "system" }
)

if @check_CA_constraints &&
Ops.less_than(Builtins.size(@pw1), @pw_min_CA)
if UsersUtils.check_ca_constraints? && @pw1.size < UsersUtilsClass::MIN_PASSWORD_LENGTH_CA
@errors = Builtins.add(
@errors,
Builtins.sformat(
# yes/no popup question, %1 is a number
_(
"If you intend to create certificates,\nthe password should have at least %1 characters."
),
@pw_min_CA
UsersUtilsClass::MIN_PASSWORD_LENGTH_CA
)
)
end
Expand Down
18 changes: 5 additions & 13 deletions src/lib/users/clients/inst_user_first.rb
Expand Up @@ -30,9 +30,6 @@
module Yast
class InstUserFirstClient < Client

# minimal pw length for CA-management (F#300438)
MIN_PW_LEN_CA = 4

def main
Yast.import "UI"
Yast.import "GetInstArgs"
Expand All @@ -41,21 +38,16 @@ def main
Yast.import "Popup"
Yast.import "Package"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
Yast.import "Progress"
Yast.import "Report"
Yast.import "UsersSimple"
Yast.import "UsersUtils"
Yast.import "Wizard"

textdomain "users"

@text_mode = UI.TextMode

@check_CA_constraints = ProductFeatures.GetBooleanFeature(
"globals",
"root_password_ca_check"
) == true

# full info about imported users
@imported_users = {}
# user names of imported users
Expand Down Expand Up @@ -462,10 +454,10 @@ def main_help
) +
UsersSimple.ValidPasswordHelptext

if @check_CA_constraints
if UsersUtils.check_ca_constraints?
# additional help text about password
help += (_("<p>If you intend to use this password for creating certificates,\n" +
"it has to be at least %s characters long.</p>") % MIN_PW_LEN_CA)
"it has to be at least %s characters long.</p>") % UsersUtilsClass::MIN_PASSWORD_LENGTH_CA)
end

# help text for main add user dialog
Expand Down Expand Up @@ -704,10 +696,10 @@ def valid_password?(username, pw1, pw2)
{ "uid" => username, "userPassword" => pw1, "type" => "local", "root" => @use_pw_for_root }
)

if @use_pw_for_root && @check_CA_constraints && pw1.size < MIN_PW_LEN_CA
if @use_pw_for_root && UsersUtils.check_ca_constraints? && pw1.size < UsersUtilsClass::MIN_PASSWORD_LENGTH_CA
# yes/no popup question, %s is a number
errors << (_("If you intend to create certificates,\n" +
"the password should have at least %s characters.") % MIN_PW_LEN_CA)
"the password should have at least %s characters.") % UsersUtilsClass::MIN_PASSWORD_LENGTH_CA)
end

if !errors.empty?
Expand Down
51 changes: 51 additions & 0 deletions src/modules/UsersUtils.rb
@@ -0,0 +1,51 @@
# encoding: utf-8

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

require "yast"

module Yast
class UsersUtilsClass < Module
# Minimal length of password that can be used for CA (FATE#300438)
# See also installation control file: globals->root_password_ca_check
MIN_PASSWORD_LENGTH_CA = 4

def main
textdomain "users"

Yast.import "ProductFeatures"
end

# Returns whether Users module should check CA constraints
# @return [Boolean] whether to check them
def check_ca_constraints?
if @check_ca_constraints.nil?
@check_ca_constraints = ProductFeatures.GetBooleanFeature(
"globals", "root_password_ca_check"
) == true
end

@check_ca_constraints
end
end

UsersUtils = UsersUtilsClass.new
UsersUtils.main
end

0 comments on commit 14baa92

Please sign in to comment.