mirror of
https://github.com/minetest/minetest.git
synced 2024-11-26 17:43:45 +01:00
Make use of safe file writing in auth handler (fixes #6576)
This commit is contained in:
parent
b816c63196
commit
0fe3e7574d
@ -67,16 +67,15 @@ local function save_auth_file()
|
|||||||
assert(type(stuff.privileges) == "table")
|
assert(type(stuff.privileges) == "table")
|
||||||
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
|
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
|
||||||
end
|
end
|
||||||
local file, errmsg = io.open(core.auth_file_path, 'w+b')
|
local content = ""
|
||||||
if not file then
|
|
||||||
error(core.auth_file_path.." could not be opened for writing: "..errmsg)
|
|
||||||
end
|
|
||||||
for name, stuff in pairs(core.auth_table) do
|
for name, stuff in pairs(core.auth_table) do
|
||||||
local priv_string = core.privs_to_string(stuff.privileges)
|
local priv_string = core.privs_to_string(stuff.privileges)
|
||||||
local parts = {name, stuff.password, priv_string, stuff.last_login or ""}
|
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
|
end
|
||||||
io.close(file)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
read_auth_file()
|
read_auth_file()
|
||||||
|
Loading…
Reference in New Issue
Block a user