From 4c1a2d24d374d00c656c4489db7d28f80d64f9dc Mon Sep 17 00:00:00 2001 From: shtrophic Date: Mon, 20 Jan 2025 22:59:30 +0100 Subject: add port parsing for sandboxing --- utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index a5b1124..3b0a78f 100644 --- a/utils.c +++ b/utils.c @@ -904,3 +904,55 @@ void import_csv(snac *user) else snac_log(user, xs_fmt("Cannot open file %s", fn)); } + +static const struct { + const char *proto; + unsigned short default_port; +} FALLBACK_PORTS[] = { + /* caution: https > http, smpts > smtp */ + {"https", 443}, + {"http", 80}, + {"smtps", 465}, + {"smtp", 25} +}; + +int parse_port(const char *url, const char **errstr) +{ + const char *col, *rcol; + int tmp, ret = -1; + + if (errstr) + *errstr = NULL; + + if (!(col = strchr(url, ':'))) { + if (errstr) + *errstr = "bad url"; + return -1; + } + + for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { + if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { + ret = FALLBACK_PORTS[i].default_port; + break; + } + } + + if (!(rcol = strchr(col + 1, ':'))) + rcol = col; + + if (rcol) { + tmp = atoi(rcol + 1); + if (tmp == 0) { + if (ret != -1) + return ret; + + *errstr = strerror(errno); + return -1; + } + + return tmp; + } + + *errstr = "unknown protocol"; + return -1; +} -- cgit v1.2.3 From 3d96c576287736ebdf87e4a7b956842a6c6e055f Mon Sep 17 00:00:00 2001 From: shtrophic Date: Fri, 24 Jan 2025 22:24:05 +0100 Subject: enforce tls when supported && add tests --- utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index faf6d12..dbf798a 100644 --- a/utils.c +++ b/utils.c @@ -931,6 +931,7 @@ int parse_port(const char *url, const char **errstr) if (!(col = strchr(url, ':'))) { if (errstr) *errstr = "bad url"; + return -1; } @@ -950,13 +951,17 @@ int parse_port(const char *url, const char **errstr) if (ret != -1) return ret; - *errstr = strerror(errno); + if (errstr) + *errstr = strerror(errno); + return -1; } return tmp; } - *errstr = "unknown protocol"; + if (errstr) + *errstr = "unknown protocol"; + return -1; } -- cgit v1.2.3 From ae9afd47e7b9df111312bb4a6243fdc05101dd55 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 27 Apr 2025 05:14:09 +0200 Subject: Replaced tabs with spaces. --- utils.c | 68 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index bf55b9f..576b17c 100644 --- a/utils.c +++ b/utils.c @@ -914,58 +914,58 @@ void import_csv(snac *user) } static const struct { - const char *proto; - unsigned short default_port; + const char *proto; + unsigned short default_port; } FALLBACK_PORTS[] = { - /* caution: https > http, smpts > smtp */ - {"https", 443}, - {"http", 80}, + /* caution: https > http, smpts > smtp */ + {"https", 443}, + {"http", 80}, {"smtps", 465}, - {"smtp", 25} + {"smtp", 25} }; int parse_port(const char *url, const char **errstr) { - const char *col, *rcol; - int tmp, ret = -1; + const char *col, *rcol; + int tmp, ret = -1; if (errstr) - *errstr = NULL; + *errstr = NULL; - if (!(col = strchr(url, ':'))) { + if (!(col = strchr(url, ':'))) { if (errstr) - *errstr = "bad url"; - - return -1; - } - - for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { - if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { - ret = FALLBACK_PORTS[i].default_port; - break; - } - } - - if (!(rcol = strchr(col + 1, ':'))) - rcol = col; - - if (rcol) { - tmp = atoi(rcol + 1); + *errstr = "bad url"; + + return -1; + } + + for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { + if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { + ret = FALLBACK_PORTS[i].default_port; + break; + } + } + + if (!(rcol = strchr(col + 1, ':'))) + rcol = col; + + if (rcol) { + tmp = atoi(rcol + 1); if (tmp == 0) { - if (ret != -1) + if (ret != -1) return ret; - + if (errstr) *errstr = strerror(errno); return -1; } - - return tmp; - } + + return tmp; + } if (errstr) - *errstr = "unknown protocol"; + *errstr = "unknown protocol"; - return -1; + return -1; } -- cgit v1.2.3 From bf94f6af7741f488f96deb16071707f11e692550 Mon Sep 17 00:00:00 2001 From: postscriptum Date: Tue, 20 May 2025 21:29:17 +0300 Subject: make greetings theme adaptive; define style in header --- utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 576b17c..d50707a 100644 --- a/utils.c +++ b/utils.c @@ -101,8 +101,9 @@ static const char *greeting_html = "\n" "\n" "\n" + "\n" "Welcome to %host%\n\n" - "\n" + "\n" "%blurb%" "

The following users are part of this community:

\n" "\n" -- cgit v1.2.3