From 410ba2e4a7be437a6c5a47d52d2afa0a8e84beed Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 29 Aug 2018 02:55:02 +0200 Subject: [PATCH] [fix] Remove extra end line of the cmd run with popen --- helpers.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helpers.lua b/helpers.lua index 99cfc83..5e6f4b4 100644 --- a/helpers.lua +++ b/helpers.lua @@ -602,7 +602,7 @@ function secure_cmd_password(cmd, password, start) -- Check password validity math.randomseed( os.time() ) local tmp_file = "/tmp/ssowat_"..math.random() - local w_pwd = io.popen("("..cmd..") tee -a "..tmp_file, 'w') + local w_pwd = io.popen("("..cmd..") | tee -a "..tmp_file, 'w') w_pwd:write(password) -- This second write is just to validate the password question -- Do not remove @@ -610,6 +610,9 @@ function secure_cmd_password(cmd, password, start) w_pwd:close() local r_pwd = io.open(tmp_file, 'r') text = r_pwd:read "*a" + if text:sub(-1, -1) == "\n" then + text = text:sub(1, -2) + end r_pwd:close() os.remove(tmp_file) return text @@ -647,7 +650,7 @@ function edit_user() -- Check password validity local result_msg = secure_cmd_password("python /usr/lib/moulinette/yunohost/utils/password.py", args.newpassword) validation_error = true - + ngx.log(ngx.STDERR, result_msg) if result_msg == 'password_advice' or result_msg == nil or result_msg == "" then validation_error = nil end