Skip to content

Commit 97684cf

Browse files
author
Andreas Stuerz
committed
(MODULES-10788) - fix for password prompt when creating mysql_login_path resource
1 parent 5c2572f commit 97684cf

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

lib/puppet/provider/mysql_login_path/mysql_login_path.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
require 'puppet/util/execution'
77
require 'puppet/util/suidmanager'
88
require 'open3'
9+
require 'pty'
10+
require 'expect'
11+
require 'fileutils'
912

1013
# Implementation for the mysql_login_path type using the Resource API.
1114
class Puppet::Provider::MysqlLoginPath::MysqlLoginPath < Puppet::ResourceApi::SimpleProvider
@@ -17,6 +20,7 @@ def get_homedir(_context, uid)
1720
def mysql_config_editor_set_cmd(context, uid, password = nil, *args)
1821
args.unshift('/usr/bin/mysql_config_editor')
1922
homedir = get_homedir(context, uid)
23+
login_file_path = "#{homedir}/.mylogin.cnf"
2024

2125
if args.is_a?(Array)
2226
command = args.flatten.map(&:to_s)
@@ -25,28 +29,27 @@ def mysql_config_editor_set_cmd(context, uid, password = nil, *args)
2529
command_str = command
2630
end
2731

28-
Puppet::Util::SUIDManager.asuser(uid) do
29-
@exit_status = Open3.popen3({ 'HOME' => homedir }, command_str) do |stdin, stdout, stderr, wait_thr|
32+
begin
33+
Puppet::Util::SUIDManager.asuser(uid) do
34+
FileUtils.touch login_file_path
35+
FileUtils.chmod 0o600, login_file_path
36+
end
37+
38+
PTY.spawn({ 'HOME' => homedir }, command_str) do |input, output, _pid|
3039
if password
31-
stdin.puts(password + "\r\n")
32-
stdin.close
40+
input.expect(%r{Enter password:})
41+
output.puts password
3342
end
34-
@captured_stdout = stdout.read
35-
@captured_stderr = stderr.read
36-
wait_thr.value
3743
end
38-
end
39-
40-
if @exit_status.success? == false
44+
rescue => e
4145
raise Puppet::ExecutionFailure, _(
4246
"Execution of '%{str}' returned %{exit_status}: %{output}",
4347
) % {
4448
str: command_str,
45-
exit_status: @exit_status,
46-
output: @captured_stderr.strip,
49+
exit_status: $?.exitstatus,
50+
output: e.message,
4751
}
4852
end
49-
@captured_stdout
5053
end
5154

5255
def mysql_config_editor_cmd(context, uid, *args)

0 commit comments

Comments
 (0)