mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-17 10:26:15 +00:00
nuageinit: use io.popen instead of pipes in shell for password
using echo in a sh(1) command line, requires many escaping to be done right, using io.popen we don't need to do this escaping anymore.
This commit is contained in:
parent
fc34a2463c
commit
3e50286607
@ -119,11 +119,12 @@ local function adduser(pwd)
|
||||
end
|
||||
local precmd = ""
|
||||
local postcmd = ""
|
||||
local input = nil
|
||||
if pwd.passwd then
|
||||
precmd = "echo '" .. pwd.passwd .. "' | "
|
||||
input = pwd.passwd
|
||||
postcmd = " -H 0"
|
||||
elseif pwd.plain_text_passwd then
|
||||
precmd = "echo '" .. pwd.plain_text_passwd .. "' | "
|
||||
input = pwd.plain_text_passwd
|
||||
postcmd = " -h 0"
|
||||
end
|
||||
cmd = precmd .. "pw "
|
||||
@ -134,7 +135,11 @@ local function adduser(pwd)
|
||||
cmd = cmd .. extraargs .. " -c '" .. pwd.gecos
|
||||
cmd = cmd .. "' -d '" .. pwd.homedir .. "' -s " .. pwd.shell .. postcmd
|
||||
|
||||
local r = os.execute(cmd)
|
||||
local f = io.popen(cmd, "w")
|
||||
if input then
|
||||
f:write(input)
|
||||
end
|
||||
local r = f:close(cmd)
|
||||
if not r then
|
||||
warnmsg("fail to add user " .. pwd.name)
|
||||
warnmsg(cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user