chef 12.17.44 → 12.18.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +3 -2
- data/Rakefile +9 -0
- data/VERSION +1 -1
- data/acceptance/Gemfile.lock +17 -17
- data/distro/common/html/knife_environment.html +4 -8
- data/distro/common/man/man1/knife-environment.1 +4 -16
- data/distro/powershell/chef/chef.psm1 +139 -24
- data/lib/chef/application.rb +5 -4
- data/lib/chef/application/windows_service_manager.rb +6 -4
- data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
- data/lib/chef/chef_fs/command_line.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +8 -1
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +1 -1
- data/lib/chef/cookbook/chefignore.rb +1 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
- data/lib/chef/cookbook/metadata.rb +2 -2
- data/lib/chef/cookbook_loader.rb +1 -1
- data/lib/chef/data_collector.rb +24 -13
- data/lib/chef/data_collector/messages.rb +8 -6
- data/lib/chef/data_collector/messages/helpers.rb +1 -1
- data/lib/chef/deprecated.rb +30 -0
- data/lib/chef/dsl/platform_introspection.rb +2 -2
- data/lib/chef/encrypted_data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +2 -2
- data/lib/chef/environment.rb +1 -1
- data/lib/chef/exceptions.rb +5 -5
- data/lib/chef/file_access_control/unix.rb +5 -5
- data/lib/chef/formatters/error_description.rb +1 -1
- data/lib/chef/http/basic_client.rb +1 -1
- data/lib/chef/http/json_input.rb +2 -2
- data/lib/chef/knife.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/ui.rb +1 -1
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/deep_merge.rb +1 -1
- data/lib/chef/mixin/shell_out.rb +58 -3
- data/lib/chef/mixin/which.rb +5 -9
- data/lib/chef/mixin/wide_string.rb +1 -1
- data/lib/chef/node.rb +1 -1
- data/lib/chef/node/attribute.rb +4 -5
- data/lib/chef/node_map.rb +18 -2
- data/lib/chef/platform/provider_handler_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -0
- data/lib/chef/platform/resource_handler_map.rb +2 -2
- data/lib/chef/provider/env/windows.rb +1 -1
- data/lib/chef/provider/git.rb +1 -1
- data/lib/chef/provider/group.rb +41 -46
- data/lib/chef/provider/group/aix.rb +12 -19
- data/lib/chef/provider/group/dscl.rb +46 -43
- data/lib/chef/provider/group/gpasswd.rb +7 -7
- data/lib/chef/provider/group/groupadd.rb +29 -34
- data/lib/chef/provider/group/groupmod.rb +26 -31
- data/lib/chef/provider/group/pw.rb +28 -31
- data/lib/chef/provider/group/suse.rb +9 -9
- data/lib/chef/provider/group/usermod.rb +10 -11
- data/lib/chef/provider/group/windows.rb +18 -20
- data/lib/chef/provider/ifconfig.rb +52 -63
- data/lib/chef/provider/ifconfig/aix.rb +23 -28
- data/lib/chef/provider/ifconfig/debian.rb +23 -22
- data/lib/chef/provider/ifconfig/redhat.rb +12 -12
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/osx_profile.rb +4 -2
- data/lib/chef/provider/package.rb +16 -7
- data/lib/chef/provider/package/chocolatey.rb +3 -1
- data/lib/chef/provider/package/dnf.rb +183 -0
- data/lib/chef/provider/package/dnf/dnf_helper.py +91 -0
- data/lib/chef/provider/package/dnf/python_helper.rb +120 -0
- data/lib/chef/provider/package/dnf/version.rb +56 -0
- data/lib/chef/provider/package/easy_install.rb +1 -1
- data/lib/chef/provider/package/freebsd/base.rb +1 -1
- data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
- data/lib/chef/provider/package/powershell.rb +3 -3
- data/lib/chef/provider/package/windows.rb +1 -1
- data/lib/chef/provider/package/zypper.rb +1 -1
- data/lib/chef/provider/route.rb +186 -184
- data/lib/chef/provider/service/arch.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +2 -2
- data/lib/chef/provider/service/insserv.rb +2 -2
- data/lib/chef/provider/service/macosx.rb +2 -2
- data/lib/chef/provider/service/openbsd.rb +1 -1
- data/lib/chef/provider/service/redhat.rb +2 -2
- data/lib/chef/provider/support/yum_repo.erb +10 -3
- data/lib/chef/provider/user.rb +17 -20
- data/lib/chef/provider/user/aix.rb +23 -24
- data/lib/chef/provider/user/dscl.rb +56 -53
- data/lib/chef/provider/user/linux.rb +13 -16
- data/lib/chef/provider/user/pw.rb +26 -30
- data/lib/chef/provider/user/solaris.rb +11 -12
- data/lib/chef/provider/user/useradd.rb +20 -22
- data/lib/chef/provider/user/windows.rb +19 -22
- data/lib/chef/provider_resolver.rb +4 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +7 -0
- data/lib/chef/resource/chocolatey_package.rb +1 -0
- data/lib/chef/resource/dnf_package.rb +64 -0
- data/lib/chef/resource/file/verification.rb +6 -4
- data/lib/chef/resource/yum_package.rb +18 -14
- data/lib/chef/resource/yum_repository.rb +1 -1
- data/lib/chef/resource_reporter.rb +11 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/scan_access_control.rb +4 -4
- data/lib/chef/util/dsc/resource_store.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/memory.rb +1 -1
- data/lib/chef/win32/security.rb +2 -2
- data/lib/chef/win32/security/sid.rb +2 -2
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm +0 -0
- data/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/repomd.xml +55 -0
- data/spec/functional/resource/dnf_package_spec.rb +686 -0
- data/spec/functional/resource/dsc_script_spec.rb +1 -0
- data/spec/functional/resource/user/useradd_spec.rb +10 -1
- data/spec/integration/knife/chef_repo_path_spec.rb +2 -2
- data/spec/integration/recipes/recipe_dsl_spec.rb +3 -0
- data/spec/integration/recipes/resource_load_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -3
- data/spec/support/lib/chef/provider/snakeoil.rb +1 -0
- data/spec/support/lib/chef/resource/cat.rb +1 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -0
- data/spec/support/lib/chef/resource/openldap_includer.rb +2 -0
- data/spec/support/lib/chef/resource/with_state.rb +2 -0
- data/spec/support/lib/chef/resource/zen_master.rb +1 -0
- data/spec/unit/cookbook/metadata_spec.rb +3 -3
- data/spec/unit/data_collector/messages/helpers_spec.rb +7 -0
- data/spec/unit/data_collector_spec.rb +56 -0
- data/spec/unit/decorator/lazy_spec.rb +1 -1
- data/spec/unit/environment_spec.rb +1 -1
- data/spec/unit/lwrp_spec.rb +3 -4
- data/spec/unit/node_spec.rb +23 -2
- data/spec/unit/platform_spec.rb +1 -0
- data/spec/unit/provider/group/dscl_spec.rb +29 -29
- data/spec/unit/provider/group/gpasswd_spec.rb +10 -10
- data/spec/unit/provider/group/groupadd_spec.rb +31 -30
- data/spec/unit/provider/group/groupmod_spec.rb +16 -16
- data/spec/unit/provider/group/pw_spec.rb +11 -11
- data/spec/unit/provider/group/suse_spec.rb +5 -5
- data/spec/unit/provider/group/usermod_spec.rb +15 -15
- data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
- data/spec/unit/provider/ifconfig/debian_spec.rb +10 -22
- data/spec/unit/provider/ifconfig/redhat_spec.rb +4 -4
- data/spec/unit/provider/ifconfig_spec.rb +18 -19
- data/spec/unit/provider/package/chocolatey_spec.rb +21 -21
- data/spec/unit/provider/package/msu_spec.rb +1 -1
- data/spec/unit/provider/route_spec.rb +21 -21
- data/spec/unit/provider/user/dscl_spec.rb +54 -57
- data/spec/unit/provider/user/linux_spec.rb +5 -5
- data/spec/unit/provider/user/pw_spec.rb +26 -22
- data/spec/unit/provider/user/windows_spec.rb +4 -4
- data/spec/unit/provider/user_spec.rb +19 -21
- data/spec/unit/provider_resolver_spec.rb +1 -0
- data/spec/unit/resource/chocolatey_package_spec.rb +12 -0
- data/spec/unit/resource/dnf_package_spec.rb +99 -0
- data/spec/unit/resource/remote_file_spec.rb +2 -2
- data/spec/unit/resource/yum_package_spec.rb +20 -0
- data/spec/unit/resource_reporter_spec.rb +24 -0
- data/spec/unit/resource_spec.rb +2 -0
- data/spec/unit/runner_spec.rb +1 -0
- data/tasks/bin/bundle-platform +1 -1
- data/tasks/gemfile_util.rb +2 -2
- data/tasks/templates/prerelease.md.erb +1 -10
- data/tasks/templates/release.md.erb +1 -9
- metadata +24 -5
- data/lib/chef/platform/handler_map.rb +0 -40
@@ -24,23 +24,23 @@ class Chef
|
|
24
24
|
provides :user, os: "linux"
|
25
25
|
|
26
26
|
def create_user
|
27
|
-
|
27
|
+
shell_out_compact!("useradd", universal_options, useradd_options, new_resource.username)
|
28
28
|
end
|
29
29
|
|
30
30
|
def manage_user
|
31
|
-
|
31
|
+
shell_out_compact!("usermod", universal_options, usermod_options, new_resource.username)
|
32
32
|
end
|
33
33
|
|
34
34
|
def remove_user
|
35
|
-
|
35
|
+
shell_out_compact!("userdel", userdel_options, new_resource.username)
|
36
36
|
end
|
37
37
|
|
38
38
|
def lock_user
|
39
|
-
|
39
|
+
shell_out_compact!("usermod", "-L", new_resource.username)
|
40
40
|
end
|
41
41
|
|
42
42
|
def unlock_user
|
43
|
-
|
43
|
+
shell_out_compact!("usermod", "-U", new_resource.username)
|
44
44
|
end
|
45
45
|
|
46
46
|
# common to usermod and useradd
|
@@ -69,11 +69,11 @@ class Chef
|
|
69
69
|
def useradd_options
|
70
70
|
opts = []
|
71
71
|
opts << "-r" if new_resource.system
|
72
|
-
if managing_home_dir?
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
opts << if managing_home_dir?
|
73
|
+
"-m"
|
74
|
+
else
|
75
|
+
"-M"
|
76
|
+
end
|
77
77
|
opts
|
78
78
|
end
|
79
79
|
|
@@ -97,15 +97,12 @@ class Chef
|
|
97
97
|
def check_lock
|
98
98
|
# there's an old bug in rhel (https://bugzilla.redhat.com/show_bug.cgi?id=578534)
|
99
99
|
# which means that both 0 and 1 can be success.
|
100
|
-
passwd_s =
|
100
|
+
passwd_s = shell_out_compact("passwd", "-S", new_resource.username, returns: [ 0, 1 ])
|
101
101
|
|
102
102
|
# checking "does not exist" has to come before exit code handling since centos and ubuntu differ in exit codes
|
103
103
|
if passwd_s.stderr =~ /does not exist/
|
104
|
-
if whyrun_mode?
|
105
|
-
|
106
|
-
else
|
107
|
-
raise Chef::Exceptions::User, "User #{new_resource.username} does not exist when checking lock status for #{new_resource}"
|
108
|
-
end
|
104
|
+
return false if whyrun_mode?
|
105
|
+
raise Chef::Exceptions::User, "User #{new_resource.username} does not exist when checking lock status for #{new_resource}"
|
109
106
|
end
|
110
107
|
|
111
108
|
# now raise if we didn't get a 0 or 1 (see above)
|
@@ -27,49 +27,45 @@ class Chef
|
|
27
27
|
|
28
28
|
def load_current_resource
|
29
29
|
super
|
30
|
-
raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{
|
30
|
+
raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{new_resource}" unless ::File.exist?("/usr/sbin/pw")
|
31
31
|
end
|
32
32
|
|
33
33
|
def create_user
|
34
|
-
|
35
|
-
command << set_options
|
36
|
-
run_command(:command => command)
|
34
|
+
shell_out_compact!("pw", "useradd", set_options)
|
37
35
|
modify_password
|
38
36
|
end
|
39
37
|
|
40
38
|
def manage_user
|
41
|
-
|
42
|
-
command << set_options
|
43
|
-
run_command(:command => command)
|
39
|
+
shell_out_compact!("pw", "usermod", set_options)
|
44
40
|
modify_password
|
45
41
|
end
|
46
42
|
|
47
43
|
def remove_user
|
48
|
-
command = "pw userdel
|
49
|
-
command << "
|
50
|
-
|
44
|
+
command = [ "pw", "userdel", new_resource.username ]
|
45
|
+
command << "-r" if managing_home_dir?
|
46
|
+
shell_out_compact!(command)
|
51
47
|
end
|
52
48
|
|
53
49
|
def check_lock
|
54
|
-
case
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
@locked = case current_resource.password
|
51
|
+
when /^\*LOCKED\*/
|
52
|
+
true
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
60
56
|
@locked
|
61
57
|
end
|
62
58
|
|
63
59
|
def lock_user
|
64
|
-
|
60
|
+
shell_out_compact!("pw", "lock", new_resource.username)
|
65
61
|
end
|
66
62
|
|
67
63
|
def unlock_user
|
68
|
-
|
64
|
+
shell_out_compact!("pw", "unlock", new_resource.username)
|
69
65
|
end
|
70
66
|
|
71
67
|
def set_options
|
72
|
-
opts =
|
68
|
+
opts = [ new_resource.username ]
|
73
69
|
|
74
70
|
field_list = {
|
75
71
|
"comment" => "-c",
|
@@ -80,26 +76,26 @@ class Chef
|
|
80
76
|
}
|
81
77
|
field_list.sort { |a, b| a[0] <=> b[0] }.each do |field, option|
|
82
78
|
field_symbol = field.to_sym
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
79
|
+
next unless current_resource.send(field_symbol) != new_resource.send(field_symbol)
|
80
|
+
if new_resource.send(field_symbol)
|
81
|
+
Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}")
|
82
|
+
opts << option
|
83
|
+
opts << new_resource.send(field_symbol)
|
88
84
|
end
|
89
85
|
end
|
90
86
|
if managing_home_dir?
|
91
|
-
Chef::Log.debug("#{
|
92
|
-
opts << "
|
87
|
+
Chef::Log.debug("#{new_resource} is managing the users home directory")
|
88
|
+
opts << "-m"
|
93
89
|
end
|
94
90
|
opts
|
95
91
|
end
|
96
92
|
|
97
93
|
def modify_password
|
98
|
-
if
|
94
|
+
if !new_resource.password.nil? && (current_resource.password != new_resource.password)
|
99
95
|
Chef::Log.debug("#{new_resource} updating password")
|
100
|
-
command = "pw usermod #{
|
101
|
-
status = popen4(command, :
|
102
|
-
stdin.puts
|
96
|
+
command = "pw usermod #{new_resource.username} -H 0"
|
97
|
+
status = popen4(command, waitlast: true) do |pid, stdin, stdout, stderr|
|
98
|
+
stdin.puts new_resource.password.to_s
|
103
99
|
end
|
104
100
|
|
105
101
|
unless status.exitstatus == 0
|
@@ -26,7 +26,7 @@ class Chef
|
|
26
26
|
class Solaris < Chef::Provider::User::Useradd
|
27
27
|
provides :solaris_user
|
28
28
|
provides :user, os: %w{omnios solaris2}
|
29
|
-
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]]
|
29
|
+
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]].freeze
|
30
30
|
|
31
31
|
attr_writer :password_file
|
32
32
|
|
@@ -46,22 +46,22 @@ class Chef
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def check_lock
|
49
|
-
user = IO.read(@password_file).match(/^#{Regexp.escape(
|
49
|
+
user = IO.read(@password_file).match(/^#{Regexp.escape(new_resource.username)}:([^:]*):/)
|
50
50
|
|
51
51
|
# If we're in whyrun mode, and the user is not created, we assume it will be
|
52
52
|
return false if whyrun_mode? && user.nil?
|
53
53
|
|
54
|
-
raise Chef::Exceptions::User, "Cannot determine if #{
|
54
|
+
raise Chef::Exceptions::User, "Cannot determine if #{new_resource} is locked!" if user.nil?
|
55
55
|
|
56
56
|
@locked = user[1].start_with?("*LK*")
|
57
57
|
end
|
58
58
|
|
59
59
|
def lock_user
|
60
|
-
|
60
|
+
shell_out_compact!("passwd", "-l", new_resource.username)
|
61
61
|
end
|
62
62
|
|
63
63
|
def unlock_user
|
64
|
-
|
64
|
+
shell_out_compact!("passwd", "-u", new_resource.username)
|
65
65
|
end
|
66
66
|
|
67
67
|
private
|
@@ -82,10 +82,9 @@ class Chef
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def manage_password
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
85
|
+
return unless current_resource.password != new_resource.password && new_resource.password
|
86
|
+
Chef::Log.debug("#{new_resource} setting password to #{new_resource.password}")
|
87
|
+
write_shadow_file
|
89
88
|
end
|
90
89
|
|
91
90
|
def write_shadow_file
|
@@ -93,7 +92,7 @@ class Chef
|
|
93
92
|
::File.open(@password_file) do |shadow_file|
|
94
93
|
shadow_file.each do |entry|
|
95
94
|
user = entry.split(":").first
|
96
|
-
if user ==
|
95
|
+
if user == new_resource.username
|
97
96
|
buffer.write(updated_password(entry))
|
98
97
|
else
|
99
98
|
buffer.write(entry)
|
@@ -104,7 +103,7 @@ class Chef
|
|
104
103
|
|
105
104
|
# FIXME: mostly duplicates code with file provider deploying a file
|
106
105
|
s = ::File.stat(@password_file)
|
107
|
-
mode = s.mode &
|
106
|
+
mode = s.mode & 0o7777
|
108
107
|
uid = s.uid
|
109
108
|
gid = s.gid
|
110
109
|
|
@@ -116,7 +115,7 @@ class Chef
|
|
116
115
|
|
117
116
|
def updated_password(entry)
|
118
117
|
fields = entry.split(":")
|
119
|
-
fields[1] =
|
118
|
+
fields[1] = new_resource.password
|
120
119
|
fields[2] = days_since_epoch
|
121
120
|
fields.join(":")
|
122
121
|
end
|
@@ -23,25 +23,25 @@ class Chef
|
|
23
23
|
class Provider
|
24
24
|
class User
|
25
25
|
class Useradd < Chef::Provider::User
|
26
|
-
#
|
26
|
+
# the linux version of this has been forked off, this is the base class now of solaris and AIX and should be abandoned
|
27
|
+
# and those provider should be rewritten like the linux version.
|
27
28
|
|
28
|
-
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:password, "-p"], [:shell, "-s"], [:uid, "-u"]]
|
29
|
+
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:password, "-p"], [:shell, "-s"], [:uid, "-u"]].freeze
|
29
30
|
|
30
31
|
def create_user
|
31
32
|
command = compile_command("useradd") do |useradd|
|
32
33
|
useradd.concat(universal_options)
|
33
34
|
useradd.concat(useradd_options)
|
34
35
|
end
|
35
|
-
|
36
|
+
shell_out_compact!(command)
|
36
37
|
end
|
37
38
|
|
38
39
|
def manage_user
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
shell_out!(*command)
|
40
|
+
return if universal_options.empty?
|
41
|
+
command = compile_command("usermod") do |u|
|
42
|
+
u.concat(universal_options)
|
44
43
|
end
|
44
|
+
shell_out_compact!(command)
|
45
45
|
end
|
46
46
|
|
47
47
|
def remove_user
|
@@ -49,19 +49,19 @@ class Chef
|
|
49
49
|
command << "-r" if managing_home_dir?
|
50
50
|
command << "-f" if new_resource.force
|
51
51
|
command << new_resource.username
|
52
|
-
|
52
|
+
shell_out_compact!(command)
|
53
53
|
end
|
54
54
|
|
55
55
|
def check_lock
|
56
56
|
# we can get an exit code of 1 even when it's successful on
|
57
57
|
# rhel/centos (redhat bug 578534). See additional error checks below.
|
58
|
-
passwd_s =
|
58
|
+
passwd_s = shell_out_compact!("passwd", "-S", new_resource.username, returns: [0, 1])
|
59
59
|
if whyrun_mode? && passwd_s.stdout.empty? && passwd_s.stderr.match(/does not exist/)
|
60
60
|
# if we're in whyrun mode and the user is not yet created we assume it would be
|
61
61
|
return false
|
62
62
|
end
|
63
63
|
|
64
|
-
raise Chef::Exceptions::User, "Cannot determine if #{
|
64
|
+
raise Chef::Exceptions::User, "Cannot determine if #{new_resource} is locked!" if passwd_s.stdout.empty?
|
65
65
|
|
66
66
|
status_line = passwd_s.stdout.split(" ")
|
67
67
|
case status_line[1]
|
@@ -76,7 +76,7 @@ class Chef
|
|
76
76
|
unless passwd_s.exitstatus == 0
|
77
77
|
raise_lock_error = false
|
78
78
|
if %w{redhat centos}.include?(node[:platform])
|
79
|
-
passwd_version_check =
|
79
|
+
passwd_version_check = shell_out_compact!("rpm", "-q", "passwd")
|
80
80
|
passwd_version = passwd_version_check.stdout.chomp
|
81
81
|
|
82
82
|
unless passwd_version == "passwd-0.73-1"
|
@@ -93,11 +93,11 @@ class Chef
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def lock_user
|
96
|
-
|
96
|
+
shell_out_compact!("usermod", "-L", new_resource.username)
|
97
97
|
end
|
98
98
|
|
99
99
|
def unlock_user
|
100
|
-
|
100
|
+
shell_out_compact!("usermod", "-U", new_resource.username)
|
101
101
|
end
|
102
102
|
|
103
103
|
def compile_command(base_command)
|
@@ -130,12 +130,10 @@ class Chef
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def update_options(field, option, opts)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
end
|
133
|
+
return unless current_resource.send(field).to_s != new_resource.send(field).to_s
|
134
|
+
return unless new_resource.send(field)
|
135
|
+
Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field)}")
|
136
|
+
opts << option << new_resource.send(field).to_s
|
139
137
|
end
|
140
138
|
|
141
139
|
def useradd_options
|
@@ -150,8 +148,8 @@ class Chef
|
|
150
148
|
# Pathname#cleanpath does a better job than ::File::expand_path (on both unix and windows)
|
151
149
|
# ::File.expand_path("///tmp") == ::File.expand_path("/tmp") => false
|
152
150
|
# ::File.expand_path("\\tmp") => "C:/tmp"
|
153
|
-
return true if
|
154
|
-
new_resource.home && Pathname.new(
|
151
|
+
return true if current_resource.home.nil? && new_resource.home
|
152
|
+
new_resource.home && Pathname.new(current_resource.home).cleanpath != Pathname.new(new_resource.home).cleanpath
|
155
153
|
end
|
156
154
|
|
157
155
|
end
|
@@ -31,31 +31,30 @@ class Chef
|
|
31
31
|
|
32
32
|
def initialize(new_resource, run_context)
|
33
33
|
super
|
34
|
-
@net_user = Chef::Util::Windows::NetUser.new(
|
34
|
+
@net_user = Chef::Util::Windows::NetUser.new(new_resource.username)
|
35
35
|
end
|
36
36
|
|
37
37
|
def load_current_resource
|
38
|
-
if
|
38
|
+
if new_resource.gid
|
39
39
|
Chef::Log.warn("The 'gid' attribute is not implemented by the Windows platform. Please use the 'group' resource to assign a user to a group.")
|
40
40
|
end
|
41
41
|
|
42
|
-
@current_resource = Chef::Resource::User.new(
|
43
|
-
|
44
|
-
user_info = nil
|
42
|
+
@current_resource = Chef::Resource::User.new(new_resource.name)
|
43
|
+
current_resource.username(new_resource.username)
|
45
44
|
begin
|
46
45
|
user_info = @net_user.get_info
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
current_resource.uid(user_info[:user_id])
|
48
|
+
current_resource.comment(user_info[:full_name])
|
49
|
+
current_resource.home(user_info[:home_dir])
|
50
|
+
current_resource.shell(user_info[:script_path])
|
52
51
|
rescue Chef::Exceptions::UserIDNotFound => e
|
53
52
|
# e.message should be "The user name could not be found" but checking for that could cause a localization bug
|
54
53
|
@user_exists = false
|
55
|
-
Chef::Log.debug("#{
|
54
|
+
Chef::Log.debug("#{new_resource} does not exist (#{e.message})")
|
56
55
|
end
|
57
56
|
|
58
|
-
|
57
|
+
current_resource
|
59
58
|
end
|
60
59
|
|
61
60
|
# Check to see if the user needs any changes
|
@@ -64,12 +63,12 @@ class Chef
|
|
64
63
|
# <true>:: If a change is required
|
65
64
|
# <false>:: If the users are identical
|
66
65
|
def compare_user
|
67
|
-
unless @net_user.validate_credentials(
|
68
|
-
Chef::Log.debug("#{
|
66
|
+
unless @net_user.validate_credentials(new_resource.password)
|
67
|
+
Chef::Log.debug("#{new_resource} password has changed")
|
69
68
|
return true
|
70
69
|
end
|
71
70
|
[ :uid, :comment, :home, :shell ].any? do |user_attrib|
|
72
|
-
|
71
|
+
!new_resource.send(user_attrib).nil? && new_resource.send(user_attrib) != current_resource.send(user_attrib)
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -98,7 +97,7 @@ class Chef
|
|
98
97
|
end
|
99
98
|
|
100
99
|
def set_options
|
101
|
-
opts = { :
|
100
|
+
opts = { name: new_resource.username }
|
102
101
|
|
103
102
|
field_list = {
|
104
103
|
"comment" => "full_name",
|
@@ -110,14 +109,12 @@ class Chef
|
|
110
109
|
|
111
110
|
field_list.sort { |a, b| a[0] <=> b[0] }.each do |field, option|
|
112
111
|
field_symbol = field.to_sym
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
opts[option.to_sym] = @new_resource.send(field_symbol)
|
119
|
-
end
|
112
|
+
next unless current_resource.send(field_symbol) != new_resource.send(field_symbol)
|
113
|
+
next unless new_resource.send(field_symbol)
|
114
|
+
unless field_symbol == :password
|
115
|
+
Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}")
|
120
116
|
end
|
117
|
+
opts[option.to_sym] = new_resource.send(field_symbol)
|
121
118
|
end
|
122
119
|
opts
|
123
120
|
end
|
@@ -90,8 +90,10 @@ class Chef
|
|
90
90
|
@prioritized_handlers ||= begin
|
91
91
|
supported_handlers = self.supported_handlers
|
92
92
|
if supported_handlers.empty?
|
93
|
-
#
|
94
|
-
#
|
93
|
+
# We always require a provider to be able to call define_resource_requirements on. In the why-run case we need
|
94
|
+
# a provider to say "assuming /etc/init.d/whatever would have been installed" and in the non-why-run case we
|
95
|
+
# need to make a best guess at "cannot find /etc/init.d/whatever". We are essentially defining a "default" provider
|
96
|
+
# for the platform, which is the best we can do, but which might give misleading errors, but we cannot read minds.
|
95
97
|
Chef::Log.debug "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway."
|
96
98
|
supported_handlers = enabled_handlers
|
97
99
|
end
|
data/lib/chef/providers.rb
CHANGED
@@ -65,6 +65,7 @@ require "chef/provider/env/windows"
|
|
65
65
|
require "chef/provider/package/apt"
|
66
66
|
require "chef/provider/package/chocolatey"
|
67
67
|
require "chef/provider/package/dpkg"
|
68
|
+
require "chef/provider/package/dnf"
|
68
69
|
require "chef/provider/package/easy_install"
|
69
70
|
require "chef/provider/package/freebsd/port"
|
70
71
|
require "chef/provider/package/freebsd/pkg"
|