Mercurial > prosody-hg
comparison core/configmanager.lua @ 10375:3d0adbc74c39
core.configmanager: Handle nameprep validation errors
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 02 Nov 2019 13:56:13 +0100 |
| parents | a83233559253 |
| children | ec21e379c145 |
comparison
equal
deleted
inserted
replaced
| 10374:a83233559253 | 10375:3d0adbc74c39 |
|---|---|
| 139 rawset(env, "__currenthost", "*") -- Default is global | 139 rawset(env, "__currenthost", "*") -- Default is global |
| 140 function env.VirtualHost(name) | 140 function env.VirtualHost(name) |
| 141 if not name then | 141 if not name then |
| 142 error("Host must have a name", 2); | 142 error("Host must have a name", 2); |
| 143 end | 143 end |
| 144 name = nameprep(name); | 144 local prepped_name = nameprep(name); |
| 145 if not prepped_name then | |
| 146 error(format("Name of Host %q contains forbidden characters", name), 0); | |
| 147 end | |
| 148 name = prepped_name; | |
| 145 if rawget(config_table, name) and rawget(config_table[name], "component_module") then | 149 if rawget(config_table, name) and rawget(config_table[name], "component_module") then |
| 146 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", | 150 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
| 147 name, config_table[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); | 151 name, config_table[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
| 148 end | 152 end |
| 149 rawset(env, "__currenthost", name); | 153 rawset(env, "__currenthost", name); |
| 160 | 164 |
| 161 function env.Component(name) | 165 function env.Component(name) |
| 162 if not name then | 166 if not name then |
| 163 error("Component must have a name", 2); | 167 error("Component must have a name", 2); |
| 164 end | 168 end |
| 165 name = nameprep(name); | 169 local prepped_name = nameprep(name); |
| 170 if not prepped_name then | |
| 171 error(format("Name of Component %q contains forbidden characters", name), 0); | |
| 172 end | |
| 173 name = prepped_name; | |
| 166 if rawget(config_table, name) and rawget(config_table[name], "defined") | 174 if rawget(config_table, name) and rawget(config_table[name], "defined") |
| 167 and not rawget(config_table[name], "component_module") then | 175 and not rawget(config_table[name], "component_module") then |
| 168 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", | 176 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", |
| 169 name, name, name), 0); | 177 name, name, name), 0); |
| 170 end | 178 end |
