1
0
mirror of https://github.com/moparisthebest/sslh synced 2024-11-24 18:12:17 -05:00

Support RFC5952-style IPv6 addresses

This commit is contained in:
Yves Rutschle 2014-12-22 18:19:02 +01:00
parent 9a0a9b9492
commit b9ddfb4c7a
2 changed files with 18 additions and 6 deletions

View File

@ -1,4 +1,6 @@
vNEXT: vNEXT:
Support RFC5952-style IPv6 addresses, e.g. [::]:443.
Call setgroups() before setgid() (fixes potential Call setgroups() before setgid() (fixes potential
privilege escalation). privilege escalation).
(Lars Vogdt) (Lars Vogdt)

View File

@ -349,21 +349,31 @@ fullname: input string -- it gets clobbered
*/ */
void resolve_name(struct addrinfo **out, char* fullname) void resolve_name(struct addrinfo **out, char* fullname)
{ {
char *serv, *host; char *serv, *host, *end;
int res; int res;
/* Find port */
char *sep = strrchr(fullname, ':'); char *sep = strrchr(fullname, ':');
if (!sep) { /* No separator: parameter is just a port */
if (!sep) /* No separator: parameter is just a port */
{
fprintf(stderr, "%s: names must be fully specified as hostname:port\n", fullname); fprintf(stderr, "%s: names must be fully specified as hostname:port\n", fullname);
exit(1); exit(1);
} }
host = fullname;
serv = sep+1; serv = sep+1;
*sep = 0; *sep = 0;
host = fullname;
/* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
* around IP address */
if (host[0] == '[') {
end = strrchr(host, ']');
if (!end) {
fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
}
host++; /* skip first bracket */
*end = 0; /* remove last bracket */
}
res = resolve_split_name(out, host, serv); res = resolve_split_name(out, host, serv);
if (res) { if (res) {
fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname); fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);