mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04: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. (cherry picked from commit 3e502866073f8d922eecb9016920a56b90c35e38)
This commit is contained in:
parent
707a34afe1
commit
68f025feeb
1 changed files with 8 additions and 3 deletions
|
|
@ -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 a new issue