This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository libx2goclient. from 89dff4d src/x2goclient-network-ssh.c: continue implementation of x2goclient_network_ssh_parse_sockspec(). new cbedb4c src/x2goclient-network-ssh.c: use GError when parsing port specification. new d6ce170 src/x2goclient-network-ssh.c: fully implement IPv6 address checking; also split out into helper function. new 87b21a0 src/x2goclient-network-ssh.c: make reminder to handle IPv6 scope IDs correctly. new 195a3d5 src/x2goclient-network-ssh.c: implement IPv4 address parsing. new 53f7fdf src/x2goclient-network-ssh.c: use IPv6 and IPv4 address spec parsing function(s). new bc2d448 src/x2goclient-network-ssh.c: implement IPv6 scope ID handling. The 6 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: src/x2goclient-network-ssh.c | 259 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 209 insertions(+), 50 deletions(-) -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit cbedb4cf5851ad42acca4594d1a0bfe920f03856 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 09:35:35 2019 +0200 src/x2goclient-network-ssh.c: use GError when parsing port specification. --- src/x2goclient-network-ssh.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 702f279..05c0775 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -46,6 +46,15 @@ #include "x2goclient.h" #include "x2goclient-network-ssh.h" +/* + * Error handling helpers. + */ +#define X2GOCLIENT_NETWORK_SSH_ERROR g_quark_from_static_string ("x2goclient-network-ssh") + +enum { + X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV = 0 +}; + struct _X2GoClientNetworkOptionsSSH { X2GoClientNetworkOptions parent_class; }; @@ -108,29 +117,37 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_unix_socket (const return (ret); } -static gint32 x2goclient_network_ssh_parse_sockspec_port (const GString *portspec) { - gint32 ret = -1; +static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portspec, GError **port_parse_err) { + guint16 ret = 0; if (':' == portspec->str[0]) { /* * In the worst case, portspec->str[1] will point to a terminating NULL * character, but that's non-critical. */ + gchar *err_msg = NULL; errno = 0; + int saved_errno = 0; long long conv = strtoll (portspec->str + 1, NULL, 10); + saved_errno = errno; - if (0 != errno) { - g_log (NULL, G_LOG_LEVEL_WARNING, "Unable to convert port specifier, invalid input."); + if (0 != saved_errno) { + err_msg = "Not a valid number."; } else if ((1 << 16) <= conv) { - g_log (NULL, G_LOG_LEVEL_WARNING, "Port specifier out of range (too big), invalid input."); + err_msg = "Port specifier out of range: too big."; } else if (0 >= conv) { - g_log (NULL, G_LOG_LEVEL_WARNING, "Port specifier out of range (negative or zero), invalid input."); + err_msg = "Port specifier out of range: negative or zero."; } else { ret = conv; } + + if (err_msg) { + g_set_error_literal (port_parse_err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV, err_msg); + err_msg = NULL; + } } else { /* No specifier found, assume default port. */ @@ -155,6 +172,7 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkS gboolean could_be_v6 = FALSE; gboolean is_v6 = FALSE; + gboolean port_parse_err = TRUE; gchar *tmp_start = sockspec->str; gchar *tmp_end = NULL; GString *v6_address = NULL; @@ -200,9 +218,17 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkS * fine. */ GString *portspec = g_string_new (tmp_end + 2); - gint32 port_parse = x2goclient_network_ssh_parse_sockspec_port (portspec); + GError *tmp_err = NULL; + port = x2goclient_network_ssh_parse_sockspec_port (portspec, &tmp_err); g_string_free (portspec, TRUE); portspec = NULL; + + if (tmp_err) { + g_log (NULL, G_LOG_LEVEL_WARNING, "Unable to convert port specifier: %s", tmp_err->message); + } + else { + port_parse_err = FALSE; + } } else { address = g_string_new (v6_address->str); -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit d6ce1707afac4e9930850a8e17c21bd92f0220b9 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 10:51:11 2019 +0200 src/x2goclient-network-ssh.c: fully implement IPv6 address checking; also split out into helper function. --- src/x2goclient-network-ssh.c | 133 ++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 51 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 05c0775..82cccaa 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -52,7 +52,9 @@ #define X2GOCLIENT_NETWORK_SSH_ERROR g_quark_from_static_string ("x2goclient-network-ssh") enum { - X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV = 0 + X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV = 0, + X2GOCLIENT_NETWORK_SSH_ERROR_IPV6_CONV, + X2GOCLIENT_NETWORK_SSH_ERROR_IPV4_CONV }; struct _X2GoClientNetworkOptionsSSH { @@ -117,9 +119,11 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_unix_socket (const return (ret); } -static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portspec, GError **port_parse_err) { +static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portspec, GError **err) { guint16 ret = 0; + g_return_val_if_fail (err == NULL || *err == NULL, ret); + if (':' == portspec->str[0]) { /* * In the worst case, portspec->str[1] will point to a terminating NULL @@ -145,7 +149,7 @@ static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portsp } if (err_msg) { - g_set_error_literal (port_parse_err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV, err_msg); + g_set_error_literal (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV, err_msg); err_msg = NULL; } } @@ -157,54 +161,58 @@ static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portsp return (ret); } -static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkSSH *self, const GString *sockspec) { +static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *sockspec, const gboolean want_v6, GError **err) { GSocketAddress *ret = NULL; - if (sockspec) { - /* Check if it's possibly a UNIX socket. */ - ret = x2goclient_network_ssh_parse_sockspec_unix_socket (sockspec); - - if (!ret) { - /* Must be not a UNIX socket, continue checking for IPv6 addresses. */ - - /* We're free to sanitize the string now. */ - g_strstrip (sockspec->str); + g_return_val_if_fail (err == NULL || *err == NULL, ret); - gboolean could_be_v6 = FALSE; - gboolean is_v6 = FALSE; - gboolean port_parse_err = TRUE; - gchar *tmp_start = sockspec->str; - gchar *tmp_end = NULL; - GString *v6_address = NULL; - GString *address = NULL; - guint16 port = 0; - - /* - * As a very common convention, IPv6 addresses have to be encapsulated in - * brackets if an additional port is specified, check for that. - */ - if ('[' == tmp_start[0]) { - tmp_end = g_strstr_len (tmp_start, -1, "]"); + /* We're free to sanitize the string now. */ + GString *work_sockspec = NULL; + { + gchar *sanitize_sockspec = g_strdup (sockspec->str); + g_strstrip (sanitize_sockspec); + work_sockspec = g_string_new (g_strstrip (sanitize_sockspec)); + g_free (sanitize_sockspec); + sanitize_sockspec = NULL; + } - if (tmp_end) { - /* - * Looks like a bracket-encapsulated IPv6 address so far. - * See if that checks out. - */ - could_be_v6 = TRUE; - ++tmp_start; - --tmp_end; + gchar *tmp_start = work_sockspec->str, + *tmp_end = NULL; + GString *address = NULL; + guint16 port = 0; - v6_address = g_string_new_len (tmp_start, tmp_end - tmp_start); - } + if (want_v6) { + /* + * As a very common convention, IPv6 addresses have to be encapsulated in + * brackets if an additional port is specified, check for that. + */ + if ('[' == tmp_start[0]) { + tmp_end = g_strstr_len (tmp_start, -1, "]"); + + if (tmp_end) { + /* + * Looks like a bracket-encapsulated IPv6 address so far. + * See if that checks out. + */ + ++tmp_start; + --tmp_end; + + address = g_string_new_len (tmp_start, tmp_end - tmp_start); } else { - v6_address = g_string_new_len (tmp_start, sockspec->len); + g_set_error_literal (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV6_CONV, "Found starting bracket, but no matching ending bracket."); } + } + else { + address = g_string_new_len (tmp_start, work_sockspec->len); + } + } - /* Check for an IPv6 address first. */ + if (!err) { + if (want_v6) { + /* Check for an IPv6 address. */ char binary_rep[128] = { 0 }; - is_v6 = (1 == inet_pton (AF_INET6, v6_address->str, &binary_rep)); + gboolean is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep)); if (is_v6) { /* Passed a valid IPv6 address. */ @@ -224,22 +232,45 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkS portspec = NULL; if (tmp_err) { - g_log (NULL, G_LOG_LEVEL_WARNING, "Unable to convert port specifier: %s", tmp_err->message); - } - else { - port_parse_err = FALSE; + g_set_error (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV6_CONV, "Unable to parse IPv6 address: %s", tmp_err->message); + g_clear_error (&tmp_err); } } - else { - address = g_string_new (v6_address->str); - } - } - else { - /* */ } } } + if (!err) { + /* + * Parsed everything successfully so far, so create IP socket address + * object. + */ + ret = g_inet_socket_address_new_from_string (address->str, port); + } + + g_string_free (work_sockspec, TRUE); + work_sockspec = NULL; + + g_string_free (address, TRUE); + address = NULL; + + return (ret); +} + +static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkSSH *self, const GString *sockspec) { + GSocketAddress *ret = NULL; + + if (sockspec) { + /* Check if it's possibly a UNIX socket. */ + ret = x2goclient_network_ssh_parse_sockspec_unix_socket (sockspec); + + if (!ret) { + /* Must be not a UNIX socket, continue checking for IPv6 addresses. */ + GError *tmp_err = NULL; + ret = x2goclient_network_ssh_parse_sockspec_ip (sockspec, TRUE, &tmp_err); + } + } + return ret; } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 87b21a0d615bf216dc7c9ba3368570d6ad34f93d Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 11:02:59 2019 +0200 src/x2goclient-network-ssh.c: make reminder to handle IPv6 scope IDs correctly. --- src/x2goclient-network-ssh.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 82cccaa..00a0aac 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -206,6 +206,8 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * else { address = g_string_new_len (tmp_start, work_sockspec->len); } + + /* FIXME: parse out scope ID! */ } if (!err) { -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 195a3d563571fef3b3b4d1e1b4a9e4be12f4b91b Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 11:20:55 2019 +0200 src/x2goclient-network-ssh.c: implement IPv4 address parsing. --- src/x2goclient-network-ssh.c | 64 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 00a0aac..0a17168 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -209,16 +209,43 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * /* FIXME: parse out scope ID! */ } + else { + /* + * For IPv4 addresses, we'll accept any input of the form address:port. + * + * Note that "address" may not necessarily be in dotted-quad format. + */ + tmp_end = g_strstr_len (tmp_start, -1, ":"); + + if (tmp_end) { + --tmp_end; + + address = g_string_new_len (tmp_start, tmp_end - tmp_start); + } + else { + address = g_string_new_len (tmp_start, work_sockspec->len); + } + } if (!err) { + gboolean is_v6 = FALSE, + is_v4 = FALSE; + char binary_rep[128] = { 0 }; if (want_v6) { /* Check for an IPv6 address. */ - char binary_rep[128] = { 0 }; - gboolean is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep)); + is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep)); + } + else { + /* Check for an IPv4 address. */ + is_v4 = (1 == inet_pton (AF_INET, address->str, &binary_rep)); + } - if (is_v6) { - /* Passed a valid IPv6 address. */ - if (tmp_end) { + if (((is_v6) && (want_v6)) || ((is_v4) && (!(want_v6)))) { + /* Passed a valid IPv4 or IPv6 address. */ + if (tmp_end) { + GString *portspec = NULL; + + if (want_v6) { /* * Specification in brackets, so check if there's a port specifier. * @@ -227,16 +254,29 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * * worst case, point to the terminating NULL character, which is * fine. */ - GString *portspec = g_string_new (tmp_end + 2); - GError *tmp_err = NULL; - port = x2goclient_network_ssh_parse_sockspec_port (portspec, &tmp_err); - g_string_free (portspec, TRUE); - portspec = NULL; + portspec = g_string_new (tmp_end + 2); + } + else { + /* + * IPv4 addresses are not encapsulated in brackets, so the offset is + * lower by one. + */ + portspec = g_string_new (tmp_end + 1); + } - if (tmp_err) { + GError *tmp_err = NULL; + port = x2goclient_network_ssh_parse_sockspec_port (portspec, &tmp_err); + g_string_free (portspec, TRUE); + portspec = NULL; + + if (tmp_err) { + if (want_v6) { g_set_error (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV6_CONV, "Unable to parse IPv6 address: %s", tmp_err->message); - g_clear_error (&tmp_err); } + else { + g_set_error (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV4_CONV, "Unable to parse IPv4 address: %s", tmp_err->message); + } + g_clear_error (&tmp_err); } } } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 53f7fdf601cfdf0f8462f70406391ecf1d53a844 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 11:36:26 2019 +0200 src/x2goclient-network-ssh.c: use IPv6 and IPv4 address spec parsing function(s). --- src/x2goclient-network-ssh.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 0a17168..47f56bf 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -307,9 +307,35 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetworkS ret = x2goclient_network_ssh_parse_sockspec_unix_socket (sockspec); if (!ret) { - /* Must be not a UNIX socket, continue checking for IPv6 addresses. */ + g_log (NULL, G_LOG_LEVEL_INFO, "Failed to parse socket specification as UNIX socket.\n" + "Continuing with IPv6 parsing."); + GError *tmp_err = NULL; ret = x2goclient_network_ssh_parse_sockspec_ip (sockspec, TRUE, &tmp_err); + + if (tmp_err) { + g_assert (!ret); + + g_log (NULL, G_LOG_LEVEL_WARNING, "Socket specification looked like an IPv6 socket, but parsing as such failed: %s", tmp_err->message); + + g_clear_error (&tmp_err); + } + } + + if (!ret) { + g_log (NULL, G_LOG_LEVEL_INFO, "Failed to parse socket specification as IPv6 socket.\n" + "Continuing with IPv4 parsing."); + + GError *tmp_err = NULL; + ret = x2goclient_network_ssh_parse_sockspec_ip (sockspec, FALSE, &tmp_err); + + if (tmp_err) { + g_assert (!ret); + + g_log (NULL, G_LOG_LEVEL_WARNING, "Socket specification looked like an IPv4 socket, but parsing as such failed: %s", tmp_err->message); + + g_clear_error (&tmp_err); + } } } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit bc2d448bf35ea0c7cb0a447410f224418c43c703 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jul 29 12:12:08 2019 +0200 src/x2goclient-network-ssh.c: implement IPv6 scope ID handling. --- src/x2goclient-network-ssh.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 47f56bf..c103007 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -187,7 +187,21 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * * brackets if an additional port is specified, check for that. */ if ('[' == tmp_start[0]) { - tmp_end = g_strstr_len (tmp_start, -1, "]"); + /* + * Do *not* use g_strstr{,_len} () to search for the next closing + * bracket. + * + * We'll have to search for the LAST one, i.e., begin at the end of the + * string. + * + * This might sound weird at first, but consider that IPv6 addresses MAY + * include an optional scope ID and at least the Linux kernel (and + * accompanying userspace tools) are very lenient when it comes to + * allowed characters, so a spec like this might well be a valid one: + * + * [a::b:c:d%[]]$]-]]#]]!![[[]:23 + */ + tmp_end = g_strrstr_len (tmp_start, -1, "]"); if (tmp_end) { /* @@ -206,8 +220,6 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * else { address = g_string_new_len (tmp_start, work_sockspec->len); } - - /* FIXME: parse out scope ID! */ } else { /* @@ -232,8 +244,30 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString * is_v4 = FALSE; char binary_rep[128] = { 0 }; if (want_v6) { - /* Check for an IPv6 address. */ - is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep)); + /* + * Check for an IPv6 address. + * + * Additionally, IPv6 addresses MAY contain a scope ID, which inet_pton () + * can't handle. + * + * We'll have to filter that out first. + */ + gchar *filter_start = address->str, + *filter_end = g_strstr_len (filter_start, -1, "%"); + GString *filter_work = NULL; + + if (filter_end) { + --filter_end; + filter_work = g_string_new_len (filter_start, filter_end - filter_start); + } + else { + filter_work = g_string_new (filter_start); + } + + is_v6 = (1 == inet_pton (AF_INET6, filter_work->str, &binary_rep)); + + g_string_free (filter_work, TRUE); + filter_work = NULL; } else { /* Check for an IPv4 address. */ -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git