From 078694c78772d8a219273c5b48a15ad991ce0ec6 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 31 Jul 2017 16:17:27 -0400 Subject: Use new lock/unlock functions to guard htpasswd updates --- lib/gitano/admincommand.lua | 2 ++ lib/gitano/usercommand.lua | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua index be6bf0a..5f1bcf9 100644 --- a/lib/gitano/admincommand.lua +++ b/lib/gitano/admincommand.lua @@ -129,6 +129,7 @@ local function update_user_in_htpasswd(conf, userfrom, userto) return end local htpasswd_path = os.getenv("HOME") .. "/htpasswd" + local lock = util.lockfile(htpasswd_path .. ".lock") local fh = io.open(htpasswd_path, "r") if not fh then return end local to_write = {} @@ -151,6 +152,7 @@ local function update_user_in_htpasswd(conf, userfrom, userto) log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE", {what="htpasswd", reason=luxio.strerror(errno)})) end + util.unlockfile(lock) end local builtin_user_short = "Manage users in Gitano" diff --git a/lib/gitano/usercommand.lua b/lib/gitano/usercommand.lua index 5d3d7ac..af7141c 100644 --- a/lib/gitano/usercommand.lua +++ b/lib/gitano/usercommand.lua @@ -282,6 +282,7 @@ end local function update_htpasswd(user, passwd) local htpasswd_path = os.getenv("HOME") .. "/htpasswd" + local lock = util.lockfile(htpasswd_path .. ".lock") local flags = io.open(htpasswd_path, "r") and "-i" or "-ic" local exit_code @@ -303,7 +304,7 @@ local function update_htpasswd(user, passwd) _, exit_code = proc:wait() end - + util.unlockfile(lock) return exit_code == 0 end -- cgit v1.2.1