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
1 changed files with 9 additions and 22 deletions

View File

@ -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)