Date: Wed, 20 Nov 2024 09:42:21 GMT From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 3e502866073f - main - nuageinit: use io.popen instead of pipes in shell for password Message-ID: <202411200942.4AK9gLLP084047@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=3e502866073f8d922eecb9016920a56b90c35e38 commit 3e502866073f8d922eecb9016920a56b90c35e38 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2024-11-20 09:39:50 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2024-11-20 09:41:46 +0000 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. --- libexec/nuageinit/nuage.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index 4e21405a443b..978de02a63fc 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202411200942.4AK9gLLP084047>