Software /
code /
prosody
Comparison
core/certmanager.lua @ 11538:30feeb4d9d0b
core.certmanager: Catch error from lfs
lfs.dir() throws a hard error if there's a problem, e.g. no such
directory or permission issues. This also gets called early enough that
the main loop error protection hasn't been brought up yet, causing a
proper crash.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 07 May 2021 16:47:58 +0200 |
parent | 11537:a09685a7b330 |
child | 11560:3bbb1af92514 |
comparison
equal
deleted
inserted
replaced
11537:a09685a7b330 | 11538:30feeb4d9d0b |
---|---|
33 local type = type; | 33 local type = type; |
34 local io_open = io.open; | 34 local io_open = io.open; |
35 local select = select; | 35 local select = select; |
36 local now = os.time; | 36 local now = os.time; |
37 local next = next; | 37 local next = next; |
38 local pcall = pcall; | |
38 | 39 |
39 local prosody = prosody; | 40 local prosody = prosody; |
40 local pathutil = require"util.paths"; | 41 local pathutil = require"util.paths"; |
41 local resolve_path = pathutil.resolve_relative_path; | 42 local resolve_path = pathutil.resolve_relative_path; |
42 local config_path = prosody.paths.config or "."; | 43 local config_path = prosody.paths.config or "."; |
110 local function index_certs(dir, files_by_name, depth_limit) | 111 local function index_certs(dir, files_by_name, depth_limit) |
111 files_by_name = files_by_name or {}; | 112 files_by_name = files_by_name or {}; |
112 depth_limit = depth_limit or 3; | 113 depth_limit = depth_limit or 3; |
113 if depth_limit <= 0 then return files_by_name; end | 114 if depth_limit <= 0 then return files_by_name; end |
114 | 115 |
115 for file in lfs.dir(dir) do | 116 local ok, iter, v, i = pcall(lfs.dir, dir); |
117 if not ok then | |
118 log("error", "Error indexing certificate directory %s: %s", dir, iter); | |
119 -- Return an empty index, otherwise this just triggers a nil indexing | |
120 -- error, plus this function would get called again. | |
121 -- Reloading the config after correcting the problem calls this again so | |
122 -- that's what should be done. | |
123 return {}, iter; | |
124 end | |
125 for file in iter, v, i do | |
116 local full = pathutil.join(dir, file); | 126 local full = pathutil.join(dir, file); |
117 if lfs.attributes(full, "mode") == "directory" then | 127 if lfs.attributes(full, "mode") == "directory" then |
118 if file:sub(1,1) ~= "." then | 128 if file:sub(1,1) ~= "." then |
119 index_certs(full, files_by_name, depth_limit-1); | 129 index_certs(full, files_by_name, depth_limit-1); |
120 end | 130 end |