diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-07-31 14:38:45 -0400 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2017-07-31 16:58:58 -0400 |
commit | ac5bed6b42d7c1c8839666cfd8906a0950abd6cb (patch) | |
tree | 15605f381dcca15c4dd71b9bddc15097bbee5ac0 /lib | |
parent | 946f7d5acaf3d6192c64d6036216455fa36841f6 (diff) | |
download | gitano-ac5bed6b42d7c1c8839666cfd8906a0950abd6cb.tar.gz |
Update htpasswd when user names change
When deleting or renaming users, the htpasswd file needs
updating so that we don't leave stale or incorrectly assigned
user credentials around.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitano/admincommand.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua index e9f2fdf..be6bf0a 100644 --- a/lib/gitano/admincommand.lua +++ b/lib/gitano/admincommand.lua @@ -124,6 +124,35 @@ local function builtin_as_run(conf, _, cmdline, env) return cmdline.cmd.run(conf, cmdline.repo, cmdline.copy, env) end +local function update_user_in_htpasswd(conf, userfrom, userto) + if conf.clod.settings["use_htpasswd"] ~= "yes" then + return + end + local htpasswd_path = os.getenv("HOME") .. "/htpasswd" + local fh = io.open(htpasswd_path, "r") + if not fh then return end + local to_write = {} + for l in fh:lines() do + if l:sub(1, #userfrom + 1) == userfrom .. ":" then + if userto then + to_write[#to_write + 1] = userto .. ":" .. l:sub(#userfrom + 2, -1) + end + else + to_write[#to_write+1] = l + end + end + fh:close() + fh = assert(io.open(htpasswd_path .. ".new", "w")) + fh:write(table.concat(to_write, "\n")) + fh:write("\n") + fh:close() + local ok, errno = luxio.rename(htpasswd_path .. ".new", htpasswd_path) + if ok ~= 0 then + log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE", + {what="htpasswd", reason=luxio.strerror(errno)})) + end +end + local builtin_user_short = "Manage users in Gitano" local builtin_user_helptext = [[ usage: user [list] @@ -345,6 +374,7 @@ local function builtin_user_run(conf, _, cmdline, env) end log.state("Committed: " .. reason) if cmdline[2] == "rename" then + update_user_in_htpasswd(conf, cmdline[3], cmdline[4]) local function reown_repo(_, repo) if repo:conf_get("project.owner") == cmdline[3] then local ok, msg = repo:conf_set_and_save( @@ -357,6 +387,8 @@ local function builtin_user_run(conf, _, cmdline, env) end end repository.foreach(conf, reown_repo) + elseif cmdline[2] == "del" then + update_user_in_htpasswd(conf, cmdline[3], nil) end end return "exit", 0 |