Software /
code /
prosody
Comparison
core/portmanager.lua @ 5009:b27ba2c83dd4
portmanager: Show a friendly error message when initializing SSL fails (thanks MattJ for the entire patch that I fixed one line in)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 25 Jul 2012 20:31:14 +0200 |
parent | 4902:a7c799a7a34b |
child | 5047:aab64739022e |
comparison
equal
deleted
inserted
replaced
5008:28498f29fdd8 | 5009:b27ba2c83dd4 |
---|---|
50 else | 50 else |
51 friendly_message = "this port is in use by another application"; | 51 friendly_message = "this port is in use by another application"; |
52 end | 52 end |
53 elseif err:match("permission") then | 53 elseif err:match("permission") then |
54 friendly_message = "Prosody does not have sufficient privileges to use this port"; | 54 friendly_message = "Prosody does not have sufficient privileges to use this port"; |
55 elseif err == "no ssl context" then | |
56 if not config.get("*", "core", "ssl") then | |
57 friendly_message = "there is no 'ssl' config under Host \"*\" which is " | |
58 .."require for legacy SSL ports"; | |
59 else | |
60 friendly_message = "initializing SSL support failed, see previous log entries"; | |
61 end | |
62 end | 55 end |
63 return friendly_message; | 56 return friendly_message; |
64 end | 57 end |
65 | 58 |
66 prosody.events.add_handler("item-added/net-provider", function (event) | 59 prosody.events.add_handler("item-added/net-provider", function (event) |
108 for port in bind_ports do | 101 for port in bind_ports do |
109 port = tonumber(port); | 102 port = tonumber(port); |
110 if #active_services:search(nil, interface, port) > 0 then | 103 if #active_services:search(nil, interface, port) > 0 then |
111 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>"); | 104 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>"); |
112 else | 105 else |
106 local err; | |
113 -- Create SSL context for this service/port | 107 -- Create SSL context for this service/port |
114 if service_info.encryption == "ssl" then | 108 if service_info.encryption == "ssl" then |
115 local ssl_config = config.get("*", config_prefix.."ssl"); | 109 local ssl_config = config.get("*", config_prefix.."ssl"); |
116 ssl = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port] | 110 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port] |
117 or (ssl_config.certificate and ssl_config))); | 111 or (ssl_config.certificate and ssl_config))); |
112 if not ssl then | |
113 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port, err) or "unknown error"); | |
114 end | |
118 end | 115 end |
119 -- Start listening on interface+port | 116 if not err then |
120 local handler, err = server.addserver(interface, port, listener, mode, ssl); | 117 -- Start listening on interface+port |
121 if not handler then | 118 local handler, err = server.addserver(interface, port, listener, mode, ssl); |
122 log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); | 119 if not handler then |
123 else | 120 log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); |
124 log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); | 121 else |
125 active_services:add(service_name, interface, port, { | 122 log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); |
126 server = handler; | 123 active_services:add(service_name, interface, port, { |
127 service = service_info; | 124 server = handler; |
128 }); | 125 service = service_info; |
126 }); | |
127 end | |
129 end | 128 end |
130 end | 129 end |
131 end | 130 end |
132 end | 131 end |
133 log("info", "Activated service '%s'", service_name); | 132 log("info", "Activated service '%s'", service_name); |