From c2e27196de7bf089015a20505da167d9c8e489ac Mon Sep 17 00:00:00 2001 From: "aiyion.prime" Date: Sun, 27 Jun 2021 23:04:31 +0200 Subject: [PATCH] gluon-web-admin: use util.popen3 in remote.lua [Matthias Schiffer: whitespace changes, error handling] --- .../gluon/config-mode/model/admin/remote.lua | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua index da6a8a9c..5d614acf 100644 --- a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua +++ b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua @@ -12,8 +12,8 @@ You may obtain a copy of the License at local util = require 'gluon.util' local site = require 'gluon.site' +local sp = util.subprocess -local fcntl = require 'posix.fcntl' local unistd = require 'posix.unistd' local wait = require 'posix.sys.wait' @@ -76,29 +76,16 @@ function pw2.cfgvalue() end local function set_password(password) - local inr, inw = unistd.pipe() - local pid = unistd.fork() - - if pid < 0 then + local options = { + stdin = sp.PIPE, + stdout = sp.DEVNULL, + stderr = sp.DEVNULL, + } + local pid, pipe = sp.popen('passwd', {}, options) + if not pid then return false - elseif pid == 0 then - unistd.close(inw) - - local null = fcntl.open('/dev/null', fcntl.O_WRONLY) - unistd.dup2(null, unistd.STDOUT_FILENO) - unistd.dup2(null, unistd.STDERR_FILENO) - if null > 2 then - unistd.close(null) - end - - unistd.dup2(inr, unistd.STDIN_FILENO) - unistd.close(inr) - - unistd.execp('passwd', {[0] = 'passwd'}) - os.exit(127) end - - unistd.close(inr) + local inw = pipe.stdin unistd.write(inw, string.format('%s\n%s\n', password, password)) unistd.close(inw)