diff options
author | sfan5 <sfan5@live.de> | 2017-11-07 11:47:28 +0100 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-06-03 17:32:00 +0200 |
commit | 0fe3e7574de0b82b080932e446caed1f2cb3b85c (patch) | |
tree | 9c5cddd6b7f5ae1cc24cbdb47d258e8768d18d60 /builtin | |
parent | b816c631963a429658473b030ab6e7641b587562 (diff) | |
download | minetest-0fe3e7574de0b82b080932e446caed1f2cb3b85c.tar.gz minetest-0fe3e7574de0b82b080932e446caed1f2cb3b85c.tar.bz2 minetest-0fe3e7574de0b82b080932e446caed1f2cb3b85c.zip |
Make use of safe file writing in auth handler (fixes #6576)
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/game/auth.lua | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 8cb4ebf57..74eb6ae88 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -67,16 +67,15 @@ local function save_auth_file() assert(type(stuff.privileges) == "table") assert(stuff.last_login == nil or type(stuff.last_login) == "number") end - local file, errmsg = io.open(core.auth_file_path, 'w+b') - if not file then - error(core.auth_file_path.." could not be opened for writing: "..errmsg) - end + local content = "" for name, stuff in pairs(core.auth_table) do local priv_string = core.privs_to_string(stuff.privileges) local parts = {name, stuff.password, priv_string, stuff.last_login or ""} - file:write(table.concat(parts, ":").."\n") + content = content .. table.concat(parts, ":") .. "\n" + end + if not core.safe_file_write(core.auth_file_path, content) then + error(core.auth_file_path.." could not be written to") end - io.close(file) end read_auth_file() |