Skip to content

Commit

Permalink
Merge pull request #387 from yast/yppwd_srcdir_master
Browse files Browse the repository at this point in the history
Merge to master - support for alternative YPPWD_SRCDIR
  • Loading branch information
ancorgs committed Jul 24, 2023
2 parents f91b954 + b84eef9 commit c699518
Show file tree
Hide file tree
Showing 40 changed files with 607 additions and 258 deletions.
8 changes: 8 additions & 0 deletions package/yast2-users.changes
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon Jul 24 13:21:21 UTC 2023 - Ancor Gonzalez Sosa <ancor@suse.com>

- Allow to edit the NIS master server databases instead of the
local ones, relying on the --prefix argument added to several
commands in the "shadow" package (bsc#1206627).
- 4.6.3

-------------------------------------------------------------------
Wed Jun 7 16:22:59 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-users.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-users
Version: 4.6.2
Version: 4.6.3
Release: 0
Summary: YaST2 - User and Group Configuration
License: GPL-2.0-only
Expand Down
5 changes: 4 additions & 1 deletion src/Makefile.am
Expand Up @@ -110,7 +110,8 @@ ylib_y2users_DATA = \
lib/y2users/read_result.rb \
lib/y2users/home.rb \
lib/y2users/commit_config.rb \
lib/y2users/commit_config_collection.rb
lib/y2users/user_commit_config.rb \
lib/y2users/user_commit_config_collection.rb

ylib_y2users_clientsdir = @ylibdir@/y2users/clients
ylib_y2users_clients_DATA = \
Expand All @@ -136,6 +137,8 @@ ylib_y2users_linux_DATA = \
lib/y2users/linux/create_group_action.rb \
lib/y2users/linux/action.rb \
lib/y2users/linux/action_result.rb \
lib/y2users/linux/root_path.rb \
lib/y2users/linux/temporary_root.rb \
lib/y2users/linux/useradd_config_writer.rb \
lib/y2users/linux/login_config_writer.rb \
lib/y2users/linux/action_writer.rb \
Expand Down
63 changes: 16 additions & 47 deletions src/lib/y2users/commit_config.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -17,59 +17,28 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2users/user_commit_config_collection"

module Y2Users
# Class for configuring the commit action for a user
# Class for configuring the commit actions
#
# Writers can receive a collection of objects of this class (see {CommitConfigCollection}) in
# order to decide what actions to perform over the user. For example, a writer can use the commit
# config to check whether the content of the home directory should be moved or not.
# TODO: It is confusing to have config for different commit actions, so for future it makes sense
# to split it
# Writers can receive an object of this class in order to decide what actions to perform and how.
# For example, a writer can use the commit config to check whether the content of the home
# directory of a specific user should be moved or not.
class CommitConfig
# Name of the user this commit config applies to
#
# @return [String]
attr_accessor :username

# Whether the home should be empty after the creation (i.e., do not use skels)
#
# @return [Boolean]
attr_writer :home_without_skel

# Whether to move the content of the current home directory to the new location
#
# @return [Boolean]
attr_writer :move_home

# Whether this user should own the home. This is useful when changing the home to reuse an
# existing directory/subvolume.
# Directory where the files passwd, shadow and group are located
#
# @return [Boolean]
attr_writer :adapt_home_ownership
# @return [String, nil] nil to use the default directory
attr_accessor :target_dir

# Whether to remove user home when removing it.
# Configuration for each user
#
# @return [Boolean]
attr_writer :remove_home

# @return [Boolean]
def home_without_skel?
!!@home_without_skel
end

# @return [Boolean]
def move_home?
!!@move_home
end

# @return [Boolean]
def adapt_home_ownership?
!!@adapt_home_ownership
end
# @return [UserCommitConfigCollection]
attr_reader :user_configs

# @return [Boolean]
def remove_home?
!!@remove_home
# Constructor
def initialize
@user_configs = UserCommitConfigCollection.new
end
end
end
9 changes: 2 additions & 7 deletions src/lib/y2users/linux/action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -43,10 +43,8 @@ class Action
# Constructor
#
# @param action_element [Object] object to perform the action (e.g., a user)
# @param commit_config [CommitConfig, nil] optional configuration for the commit
def initialize(action_element, commit_config = nil)
def initialize(action_element)
@action_element = action_element
@commit_config = commit_config
end

# Performs the action
Expand All @@ -63,9 +61,6 @@ def perform
# @return [Object]
attr_reader :action_element

# @return [CommitConfig]
attr_reader :commit_config

# Issues generated while performing the action
#
# @return [Y2Issues::List]
Expand Down
11 changes: 7 additions & 4 deletions src/lib/y2users/linux/create_group_action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,21 +22,24 @@
require "yast2/execute"
require "y2issues/issue"
require "y2users/linux/action"
require "y2users/linux/root_path"

module Y2Users
module Linux
# Action for creating a new group
class CreateGroupAction < Action
include Yast::I18n
include Yast::Logger
include RootPath

# Constructor
#
# @see Action
def initialize(group, commit_config = nil)
def initialize(group, root_path: nil)
textdomain "users"

super
super(group)
@root_path = root_path
end

private
Expand Down Expand Up @@ -66,7 +69,7 @@ def run_action
#
# @return [Array<String>]
def groupadd_options
opts = []
opts = root_path_options
opts += ["--non-unique", "--gid", group.gid] if group.gid
opts << "--system" if group.system?
opts << group.name
Expand Down
11 changes: 7 additions & 4 deletions src/lib/y2users/linux/create_user_action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021-2022] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,21 +22,24 @@
require "yast2/execute"
require "y2issues/issue"
require "y2users/linux/action"
require "y2users/linux/root_path"

module Y2Users
module Linux
# Action for creating a new user
class CreateUserAction < Action
include Yast::I18n
include Yast::Logger
include RootPath

# Constructor
#
# @see Action
def initialize(user, commit_config = nil)
def initialize(user, root_path: nil)
textdomain "users"

super
super(user)
@root_path = root_path
end

private
Expand Down Expand Up @@ -84,7 +87,7 @@ def create_user
# @param skip_home [Boolean] whether the home creation should be explicitly skip
# @return [Array<String>]
def useradd_options(skip_home: false)
user_options + home_options(skip_home: skip_home) + [user.name]
root_path_options + user_options + home_options(skip_home: skip_home) + [user.name]
end

# Options from user attributes
Expand Down
11 changes: 7 additions & 4 deletions src/lib/y2users/linux/delete_group_action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,21 +22,24 @@
require "yast2/execute"
require "y2issues/issue"
require "y2users/linux/action"
require "y2users/linux/root_path"

module Y2Users
module Linux
# Action for deleting a group
class DeleteGroupAction < Action
include Yast::I18n
include Yast::Logger
include RootPath

# Constructor
#
# @see Action
def initialize(group, commit_config = nil)
def initialize(group, root_path: nil)
textdomain "users"

super
super(group)
@root_path = root_path
end

private
Expand All @@ -51,7 +54,7 @@ def initialize(group, commit_config = nil)
#
# Issues are generated when the group cannot be deleted.
def run_action
Yast::Execute.on_target!(GROUPDEL, group.name)
Yast::Execute.on_target!(GROUPDEL, *root_path_options, group.name)
true
rescue Cheetah::ExecutionFailed => e
issues << Y2Issues::Issue.new(
Expand Down
22 changes: 17 additions & 5 deletions src/lib/y2users/linux/delete_user_action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,27 +22,39 @@
require "yast2/execute"
require "y2issues/issue"
require "y2users/linux/action"
require "y2users/linux/root_path"

module Y2Users
module Linux
# Action for deleting an existing user
class DeleteUserAction < Action
include Yast::I18n
include Yast::Logger
include RootPath

# Constructor
#
# @see Action
def initialize(user, commit_config = nil)
# @see #remove_home?
def initialize(user, remove_home: true, root_path: nil)
textdomain "users"

super
super(user)
@remove_home = remove_home
@root_path = root_path
end

private

alias_method :user, :action_element

# Whether to also remove the user home directory
#
# @return [Boolean]
def remove_home?
!!@remove_home
end

# Command for deleting a user
USERDEL = "/usr/sbin/userdel".freeze
private_constant :USERDEL
Expand All @@ -62,8 +74,8 @@ def run_action
#
# @return [Array<String>]
def userdel_options
options = []
options << "--remove" if commit_config&.remove_home?
options = root_path_options
options << "--remove" if remove_home?

options
end
Expand Down
11 changes: 7 additions & 4 deletions src/lib/y2users/linux/delete_user_password_action.rb
@@ -1,4 +1,4 @@
# Copyright (c) [2021] SUSE LLC
# Copyright (c) [2021-2023] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,21 +22,24 @@
require "yast2/execute"
require "y2issues/issue"
require "y2users/linux/action"
require "y2users/linux/root_path"

module Y2Users
module Linux
# Action for deleting the user password
class DeleteUserPasswordAction < Action
include Yast::I18n
include Yast::Logger
include RootPath

# Constructor
#
# @see Action
def initialize(user, commit_config = nil)
def initialize(user, root_path: nil)
textdomain "users"

super
super(user)
@root_path = root_path
end

private
Expand All @@ -51,7 +54,7 @@ def initialize(user, commit_config = nil)
#
# Issues are generated when the password cannot be deleted
def run_action
Yast::Execute.on_target!(PASSWD, "--delete", user.name)
Yast::Execute.on_target!(PASSWD, "--delete", *root_path_options, user.name)
true
rescue Cheetah::ExecutionFailed => e
issues << Y2Issues::Issue.new(
Expand Down

0 comments on commit c699518

Please sign in to comment.