Skip to content

Commit

Permalink
Adapt Linux base reader to read home permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Oct 27, 2021
1 parent 781fb54 commit c8ad7d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib/y2users/linux/base_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "yast"
require "yast2/execute"
require "abstract_method"
require "y2users/config"
require "y2users/login_config"
Expand All @@ -44,6 +45,7 @@ def read
read_elements(config)
read_root_aliases(config)
read_passwords(config)
read_home_permissions(config)
read_authorized_keys(config)
read_useradd_config(config)
read_login(config)
Expand Down Expand Up @@ -122,6 +124,24 @@ def read_passwords(config)
# @return [String] loaded passwords from the system
abstract_method :load_passwords

# Command for reading home directory permissions
STAT = "/usr/bin/stat".freeze
private_constant :STAT

# Reads home permissions
#
# @return [Array<Y2Users::User>]
def read_home_permissions(config)
config.users.reject(&:system?).each do |user|
next unless user.home && Dir.exist?(user.home.path)

user.home.permissions = Yast::Execute.locally!(
STAT, "--printf", "%a", user.home.path,
stdout: :capture
)
end
end

# Reads users authorized keys
#
# @see Yast::Users::SSHAuthorizedKeyring#read_keys
Expand Down
11 changes: 11 additions & 0 deletions test/lib/y2users/linux/base_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@

allow(subject.log).to receive(:warn)
allow(Yast::MailAliases).to receive(:GetRootAlias).and_return("games, unknown, news")
allow(Yast::Execute).to receive(:locally!)
allow(Yast::Execute).to receive(:locally!)
.with("/usr/bin/stat", any_args, "/root", stdout: :capture)
.and_return("700")
end

it "generates a config with read data" do
Expand Down Expand Up @@ -81,5 +85,12 @@
expect(root_aliases.size).to eq 2
expect(root_aliases.map(&:name)).to contain_exactly("games", "news")
end

it "sets home permissions" do
config = subject.read

root = config.users.root
expect(root.home.permissions).to eq("700")
end
end
end

0 comments on commit c8ad7d8

Please sign in to comment.