gluon-web-admin: use util.popen3 in remote.lua

[Matthias Schiffer: whitespace changes, error handling]
This commit is contained in:
aiyion.prime 2021-06-27 23:04:31 +02:00 committed by Matthias Schiffer
parent e410a9c2e5
commit c2e27196de
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C

View File

@ -12,8 +12,8 @@ You may obtain a copy of the License at
local util = require 'gluon.util' local util = require 'gluon.util'
local site = require 'gluon.site' local site = require 'gluon.site'
local sp = util.subprocess
local fcntl = require 'posix.fcntl'
local unistd = require 'posix.unistd' local unistd = require 'posix.unistd'
local wait = require 'posix.sys.wait' local wait = require 'posix.sys.wait'
@ -76,29 +76,16 @@ function pw2.cfgvalue()
end end
local function set_password(password) local function set_password(password)
local inr, inw = unistd.pipe() local options = {
local pid = unistd.fork() stdin = sp.PIPE,
stdout = sp.DEVNULL,
if pid < 0 then stderr = sp.DEVNULL,
}
local pid, pipe = sp.popen('passwd', {}, options)
if not pid then
return false 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 end
local inw = pipe.stdin
unistd.dup2(inr, unistd.STDIN_FILENO)
unistd.close(inr)
unistd.execp('passwd', {[0] = 'passwd'})
os.exit(127)
end
unistd.close(inr)
unistd.write(inw, string.format('%s\n%s\n', password, password)) unistd.write(inw, string.format('%s\n%s\n', password, password))
unistd.close(inw) unistd.close(inw)