This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository libx2goclient. from bc07aef src/x2goclient-network.c: don't call g_string_free () on NULL pointers. new dc2e6b8 src/x2goclient-network-ssh.c: fix sockaddr_ho definition and usage. new 9589080 configure.ac: check for C99 support and bail out otherwise. new b3edb07 src/x2goclient-network-ssh.h: whitespace-only. new 5d80a10 src/: add x2goclient-openssh-version.{c,h}. new d61878a src/Makefile.am: add x2goclient-openssh-version.{c,h}. new 93676cc po/POTFILES.in: add src/x2goclient-openssh-version.c. new a31d40e src/x2goclient-utils.{c,h}: add x2goclient_str_to_int (). new 7a24c13 src/x2goclient-network-ssh.c: replace older code with x2goclient_str_to_int (). new 19ca400 src/x2goclient-openssh-version: x2goclient_openssh_version_parse (). The 9 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: configure.ac | 6 + po/POTFILES.in | 1 + src/Makefile.am | 2 + src/x2goclient-network-ssh.c | 59 ++++---- src/x2goclient-network-ssh.h | 1 + src/x2goclient-openssh-version.c | 293 +++++++++++++++++++++++++++++++++++++++ src/x2goclient-openssh-version.h | 80 +++++++++++ src/x2goclient-utils.c | 118 ++++++++++++++++ src/x2goclient-utils.h | 4 + 9 files changed, 537 insertions(+), 27 deletions(-) create mode 100644 src/x2goclient-openssh-version.c create mode 100644 src/x2goclient-openssh-version.h -- 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 9589080f2d41084a13c7aa025d09859a31145e88 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 11:46:02 2020 +0100 configure.ac: check for C99 support and bail out otherwise. --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 44e36b3..6da9081 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,12 @@ AC_SUBST(LT_VERSION) AM_MAINTAINER_MODE AC_PROG_CC +AC_PROG_CC_C99 + +if test "x$ac_cv_prog_cc_c99" = "xno"; then + AC_MSG_ERROR([your C compiler does not support C99]) +fi + AC_STDC_HEADERS AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG -- 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 d61878a1011356998c846fc90290eb9a892298eb Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 14:47:37 2020 +0100 src/Makefile.am: add x2goclient-openssh-version.{c,h}. --- src/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 907f824..866247e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,7 @@ libx2goclientinclude_HEADERS = \ x2goclient-proxy-start-nx.h \ x2goclient-renderer-start-kdrive.h \ x2goclient-object.h \ + x2goclient-openssh-version.h \ x2goclient-session-resume.h \ x2goclient-session-runcommand.h \ x2goclient-session-suspend.h \ @@ -41,6 +42,7 @@ libx2goclient_la_SOURCES = \ x2goclient-proxy-start-nx.c \ x2goclient-renderer-start-kdrive.c \ x2goclient-object.c \ + x2goclient-openssh-version.c \ x2goclient-session-resume.c \ x2goclient-session-runcommand.c \ x2goclient-session-suspend.c \ -- 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 b3edb07956a1dadb72dbb331349dbefc448112ee Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 12:21:04 2020 +0100 src/x2goclient-network-ssh.h: whitespace-only. --- src/x2goclient-network-ssh.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/x2goclient-network-ssh.h b/src/x2goclient-network-ssh.h index 636cb79..1af7d70 100644 --- a/src/x2goclient-network-ssh.h +++ b/src/x2goclient-network-ssh.h @@ -46,6 +46,7 @@ G_DECLARE_FINAL_TYPE (X2GoClientNetworkSSH, x2goclient_network_ssh, X2GOCLIENT, X2GoClientNetworkSSH* x2goclient_network_ssh_new (const gchar *session_path); + /* * Error handling helpers. */ -- 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 dc2e6b8dce9d6c27322d92239b5915eaf1f33222 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 11:04:25 2020 +0100 src/x2goclient-network-ssh.c: fix sockaddr_ho definition and usage. Typedeffing a struct to the same name might (rightfully) confuse compilers and lead to undefined behavior. Let's avoid this and choose a temporary name for the actual struct. --- src/x2goclient-network-ssh.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 4a13184..a3762a1 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -77,7 +77,7 @@ GPtrArray* x2goclient_network_options_ssh_to_array (X2GoClientNetworkOptionsSSH * Custom sockaddr structure used to represent socket endpoints based on a FQDN * or ssh_config-specific host alias. */ -typedef struct sockaddr_ho { +typedef struct sockaddr_ho_ { sa_family_t sho_family; in_port_t sho_port; char sho_addr[256]; @@ -466,7 +466,7 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_alias (const GStrin * FIXME: for now only the size, but maybe we should do extra checks on the * name. */ - const gsize max_len = (sizeof (((struct sockaddr_ho*)(NULL))->sho_addr) - 1); + const gsize max_len = (sizeof (((sockaddr_ho*)(NULL))->sho_addr) - 1); if (max_len < address->len) { g_set_error (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_ALIAS_CONV, "Unable to parse FQDN or alias pseudo-address: name too long, expected at most %" G_GSIZE_FORMAT " bytes, got %" G_GSIZE_FORMAT " bytes.", max_len, address->len); int_err = TRUE; @@ -498,10 +498,10 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_alias (const GStrin * Parsed everything successfully so far, so create native socket address * object. */ - struct sockaddr_ho tmp_sockaddr = { AF_HOST, }; + sockaddr_ho tmp_sockaddr = { AF_HOST, }; g_strlcpy (tmp_sockaddr.sho_addr, address->str, max_len + 1); tmp_sockaddr.sho_port = port; - ret = g_native_socket_address_new (&tmp_sockaddr, sizeof (struct sockaddr_ho)); + ret = g_native_socket_address_new (&tmp_sockaddr, sizeof (sockaddr_ho)); } g_string_free (work_sockspec, TRUE); @@ -707,13 +707,13 @@ static gboolean x2goclient_network_ssh_parent_connect (X2GoClientNetwork *parent else if (G_IS_NATIVE_SOCKET_ADDRESS (sock_addr)) { GNativeSocketAddress *native_sock_addr = G_NATIVE_SOCKET_ADDRESS (sock_addr); - g_assert (sizeof (struct sockaddr_ho) == g_socket_address_get_native_size (sock_addr)); + g_assert (sizeof (sockaddr_ho) == g_socket_address_get_native_size (sock_addr)); - struct sockaddr_ho tmp_sockaddr = { 0 }; + sockaddr_ho tmp_sockaddr = { 0 }; /* Fetch data. */ GError *tmp_err = NULL; - g_socket_address_to_native (sock_addr, &tmp_sockaddr, sizeof (struct sockaddr_ho), &tmp_err); + g_socket_address_to_native (sock_addr, &tmp_sockaddr, sizeof (sockaddr_ho), &tmp_err); if (tmp_err) { g_set_error (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_CONNECT_NATIVE_FETCH, "Unable to convert native socket address object to sockaddr struct: %s", tmp_err->message); -- 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 5d80a109baa1bed55772d02a212ed7a30d218b7d Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 14:46:08 2020 +0100 src/: add x2goclient-openssh-version.{c,h}. Simple GBoxed-type wrapper for an OpenSSH version struct. Needs actual version fetching and updating code. --- src/x2goclient-openssh-version.c | 48 ++++++++++++++++++++++++++++++++++++++ src/x2goclient-openssh-version.h | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/src/x2goclient-openssh-version.c b/src/x2goclient-openssh-version.c new file mode 100644 index 0000000..3ea53db --- /dev/null +++ b/src/x2goclient-openssh-version.c @@ -0,0 +1,48 @@ +/* -*- Mode: C; c-set-style: linux indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* x2goclient-openssh-version.c - Simple OpenSSH Glib Boxed wrapper implementation + + Copyright (C) 2019 Mike Gabriel + Copyright (C) 2019-2020 Mihai Moldovan + All rights reserved. + + The libx2goclient library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The libx2goclient library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Mate Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "x2goclient-openssh-version.h" + +X2GoClientOpenSSHVersion* x2goclient_openssh_version_new (void) { + return (g_slice_new0 (X2GoClientOpenSSHVersion)); +} + +void x2goclient_openssh_version_free (X2GoClientOpenSSHVersion *openssh_version) { + g_free (openssh_version); +} + +static X2GoClientOpenSSHVersion* x2goclient_openssh_version_copy (X2GoClientOpenSSHVersion *src) { + g_return_val_if_fail (src != NULL, NULL); + + X2GoClientOpenSSHVersion *dst = x2goclient_openssh_version_new (); + *dst = *src; + + return (dst); +} + +G_DEFINE_BOXED_TYPE (X2GoClientOpenSSHVersion, x2goclient_openssh_version, &x2goclient_openssh_version_copy, &x2goclient_openssh_version_free) diff --git a/src/x2goclient-openssh-version.h b/src/x2goclient-openssh-version.h new file mode 100644 index 0000000..af6aebe --- /dev/null +++ b/src/x2goclient-openssh-version.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; c-set-style: linux indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* x2goclient-openssh-version.h - Simple OpenSSH version struct and Glib Boxed wrapper + + Copyright (C) 2019 Mike Gabriel + Copyright (C) 2019-2020 Mihai Moldovan + All rights reserved. + + The libx2goclient library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The libx2goclient library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Mate Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef x2goclient_openssh_version_h +#define x2goclient_openssh_version_h + +#include <glib-object.h> + +G_BEGIN_DECLS + +typedef struct X2GoClientOpenSSHVersion_ { + guint32 major; + guint32 minor; + guint32 patch; + gchar addon[256]; +} X2GoClientOpenSSHVersion; + + +#define X2GOCLIENT_TYPE_OPENSSH_VERSION (x2goclient_openssh_version_get_type ()) + + +GType x2goclient_openssh_version_get_type (void) G_GNUC_CONST; + +X2GoClientOpenSSHVersion* x2goclient_openssh_version_new (void); +void x2goclient_openssh_version_free (X2GoClientOpenSSHVersion *openssh_version); + +G_END_DECLS + +#endif /* x2goclient_openssh_version_h */ -- 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 a31d40ee8c640215023c801a2b64ccf0ba4acb37 Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Mar 28 09:24:29 2020 +0100 src/x2goclient-utils.{c,h}: add x2goclient_str_to_int (). Helper function that converts a string number to a long-long-type. --- src/x2goclient-utils.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ src/x2goclient-utils.h | 4 ++ 2 files changed, 122 insertions(+) diff --git a/src/x2goclient-utils.c b/src/x2goclient-utils.c index ccdd82c..39e448a 100644 --- a/src/x2goclient-utils.c +++ b/src/x2goclient-utils.c @@ -22,6 +22,9 @@ Boston, MA 02110-1301, USA. */ +#include <errno.h> +#include <stdlib.h> + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -31,3 +34,118 @@ void x2goclient_clear_strings (gpointer data) { g_free (data); } + +/** + * x2goclient_str_to_int: + * @str: (in) (not optional) (not nullable): input string + * @min: (in): true if a minimum limit should be checked for + * @limit_min: (in): the minimum limit to check for + * @max: (in): true if a maximum limit should be checked for + * @limit_max: (in) the maximum limit to check for + * @end: (out) (optional) (nullable): pointer to final string after the scanned + * value + * @conv_err: (out) (not optional) (not nullable): will be set to true on + * conversion errors + * @min_err: (out) (not optional) (not nullable): will be set to true if value + * falls short of minimum limit + * and on underflows + * @max_err: (out) (not optional) (not nullable): will be set to true if value + * exceeds maximum limit and on + * overflows + * + * Takes a string and converts it into a #long long integer. + * + * The error output parameters @conv_err, @min_err and @max_err MUST NOT be + * %NULL at any time. + * + * Multiple error conditions exist: + * - If the value pointed to by @conv_err is %TRUE and the values pointed to + * by @min_err and @max_err are both %FALSE, there was an error converting + * the initial string to a proper integer value. The return value will not + * contain a meaningful value. + * - If the values pointed to by @conv_err and @min_err are both %TRUE, an + * underflow occurred and the scanned input value was smaller than the + * minimum representable value by #long long. The return value will + * not contain a meaningful value. + * - If the values pointed to by @conv_err and @max_err are both %TRUE, an + * overflow occurred and the scanned input value was higher than the + * maximum representable value by #long long. The return value will + * not contain a meaningful value. + * - If the value pointed to by @conv_err is %FALSE and the value pointed to + * by @min_err is %TRUE, the value was converted successfully but was + * lower than the value passed via @limit_min and failed the minimum + * check. The return value will still contain the originally converted + * number. + * - If the value pointed to by @conv_err is %FALSE and the value pointed to + * by @max_err is %TRUE, the value was converted successfully but was + * higher than the value passed via @limit_max and failed the maximum + * check. The returned value will still contain the originally converted + * number. + * + * The values pointed to by @conv_err, @min_err and @max_err SHOULD never be + * all set to %TRUE by this function at the same time. Otherwise, that's a bug. + * + * If the value pointed to by @min is %FALSE, @limit_min will not be touched + * and has no meaning to the function. The same logic applies to @max and + * @limit_max. + * + * If the pointer passed as @end is not %NULL its value will be set to the + * first character after the parsed integer value like strtoll() does under + * the following circumstances: + * - If %conv_err is %FALSE. + * - If %conv_err is %TRUE and %min_err is %TRUE. + * - If %conv_err is %TRUE and %max_err is %TRUE. + * Otherwise, the pointer value will not be a meaningful one and you should not + * use or rely on it. + * + * Returns: the converted value as a #long long, unless an error occurred + */ +long long x2goclient_str_to_int (const gchar *restrict str, _Bool min, long long limit_min, _Bool max, long long limit_max, const gchar **restrict end, _Bool *restrict conv_err, _Bool *restrict min_err, _Bool *restrict max_err) { + long long ret = 42; + + *min_err = *max_err = FALSE; + + if (end) { + *end = NULL; + } + + errno = 0; + int saved_errno = 0; + gchar *endptr = NULL; + ret = strtoll (str, &endptr, 10); + saved_errno = errno; + + if (0 != saved_errno) { + *conv_err = TRUE; + ret = 42; + + if (ERANGE == saved_errno) { + if (end) { + *end = endptr; + } + + if (LLONG_MIN == ret) { + *min_err = TRUE; + } + else if (LLONG_MAX == ret) { + *max_err = TRUE; + } + } + } + else { + *conv_err = FALSE; + + if (end) { + *end = endptr; + } + + if ((min) && (limit_min > ret)) { + *min_err = TRUE; + } + else if ((max) && (limit_max < ret)) { + *max_err = TRUE; + } + } + + return (ret); +} diff --git a/src/x2goclient-utils.h b/src/x2goclient-utils.h index 0959a32..1a100d2 100644 --- a/src/x2goclient-utils.h +++ b/src/x2goclient-utils.h @@ -25,12 +25,16 @@ #ifndef x2goclient_utils_h #define x2goclient_utils_h +#include <stdbool.h> + #include <gmodule.h> G_BEGIN_DECLS void x2goclient_clear_strings (gpointer data); +long long x2goclient_str_to_int (const gchar *restrict str, _Bool min, long long limit_min, _Bool max, long long limit_max, const gchar **restrict end, _Bool *restrict conv_err, _Bool *restrict min_err, _Bool *restrict max_err); + G_END_DECLS #endif /* x2goclient_utils_h */ -- 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 7a24c133398a7b8e17273ff51ee9887fb88f6444 Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Mar 28 09:42:20 2020 +0100 src/x2goclient-network-ssh.c: replace older code with x2goclient_str_to_int (). --- src/x2goclient-network-ssh.c | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index a3762a1..0f72712 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -45,6 +45,7 @@ #include "x2goclient.h" #include "x2goclient-network-ssh.h" +#include "x2goclient-utils.h" struct _X2GoClientNetworkOptionsSSH { @@ -219,28 +220,32 @@ static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString *portsp * 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 != saved_errno) { - err_msg = "Not a valid number."; - } - else if ((1 << 16) <= conv) { - err_msg = "Port specifier out of range: too big."; - } - else if (0 >= conv) { - err_msg = "Port specifier out of range: negative or zero."; + _Bool conv_err = TRUE, + min_err = TRUE, + max_err = TRUE; + long long conv = x2goclient_str_to_int (portspec->str + 1, TRUE, 1, TRUE, ((1 << 16) - 1), NULL, &conv_err, &min_err, &max_err); + + if (conv_err) { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_UNDERFLOW, "Port specifier too small to fit into long long type."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_OVERFLOW, "Port specifier too big to fit into long long type."); + } + else { + g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_NOT_NUMERIC, "Port specifier is not numeric."); + } } else { - ret = conv; - } - - if (err_msg) { - g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV, err_msg); - err_msg = NULL; + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_NEGATIVE_ZERO, "Port specifier out of range: negative or zero."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_PORT_CONV_TOO_BIG, "Port specifier out of range: negative or zero."); + } + else { + ret = conv; + } } } else { -- 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 93676cc51b5309f6ae86c42c8d64729b1515fa3f Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Mar 26 14:48:12 2020 +0100 po/POTFILES.in: add src/x2goclient-openssh-version.c. --- po/POTFILES.in | 1 + 1 file changed, 1 insertion(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index bac2515..50d2077 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ src/x2goclient-network.c src/x2goclient-network-ssh.c src/x2goclient-proxy-start-nx.c src/x2goclient-object.c +src/x2goclient-openssh-version.c src/x2goclient-renderer-start-kdrive.c src/x2goclient-session-resume.c src/x2goclient-session-runcommand.c -- 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 19ca40073e7e02d3167f9e01afa2fc506393a92e Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Apr 4 17:54:52 2020 +0200 src/x2goclient-openssh-version: x2goclient_openssh_version_parse (). Parses the OpenSSH version string into a version struct for later use. --- src/x2goclient-openssh-version.c | 245 +++++++++++++++++++++++++++++++++++++++ src/x2goclient-openssh-version.h | 30 +++++ 2 files changed, 275 insertions(+) diff --git a/src/x2goclient-openssh-version.c b/src/x2goclient-openssh-version.c index 3ea53db..6fb193a 100644 --- a/src/x2goclient-openssh-version.c +++ b/src/x2goclient-openssh-version.c @@ -22,11 +22,15 @@ Boston, MA 02110-1301, USA. */ +#include <glib.h> +#include <glib/gprintf.h> + #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "x2goclient-openssh-version.h" +#include "x2goclient-utils.h" X2GoClientOpenSSHVersion* x2goclient_openssh_version_new (void) { return (g_slice_new0 (X2GoClientOpenSSHVersion)); @@ -46,3 +50,244 @@ static X2GoClientOpenSSHVersion* x2goclient_openssh_version_copy (X2GoClientOpen } G_DEFINE_BOXED_TYPE (X2GoClientOpenSSHVersion, x2goclient_openssh_version, &x2goclient_openssh_version_copy, &x2goclient_openssh_version_free) + +void x2goclient_openssh_version_parse (X2GoClientOpenSSHVersion *openssh_version, const gchar *version_string, GError **gerr) { + /* Basic sanity checks on struct and string. */ + if (!(openssh_version)) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_STRUCT, "No version struct passed, cannot store extracted information."); + return; + } + + if (!(version_string)) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_VERSION_STRING, "No version string passed, cannot extract information."); + return; + } + + X2GoClientOpenSSHVersion *struct_work_copy = x2goclient_openssh_version_copy (openssh_version); + + /* + * We expect the version string to have a more-or-less fixed format, such as: + * + * OpenSSH_<major>.<minor>p<patch><additional data>[,<whitespace><end of line>] + */ + /* Start with the fixed preamble. */ + const gchar *tmp = version_string; + if (!(g_str_has_prefix (tmp, "OpenSSH_"))) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_PREAMBLE, "Preamble in version string does not match expected value 'OpenSSH_'."); + + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + + /* Skip preamble, scan for major version number separator (dot). */ + tmp += 8; + const gchar *dot_search = g_strstr_len (tmp, -1, "."); + if (!(dot_search)) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_NO_MAJOR_SEPARATOR, "Version string does not contain major version number separator."); + + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + + g_assert (tmp < dot_search); + + /* Sanity check on major version number - must be numeric/all digits. */ + const gchar *int_search = NULL; + for (int_search = tmp; int_search < dot_search; ++int_search) { + if (!(g_ascii_isdigit (*int_search))) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_NOT_NUMERIC, "Major version number is not numeric."); + + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + } + + /* Copy and convert major version number. */ + gchar *tmp_copy = g_strndup (tmp, dot_search - tmp); + struct_work_copy->major = -1; + + _Bool conv_err = TRUE, + min_err = TRUE, + max_err = TRUE; + const gchar *end = NULL; + long long conv = x2goclient_str_to_int (tmp_copy, TRUE, 0, TRUE, G_MAXUINT32, &end, &conv_err, &min_err, &max_err); + + if (conv_err) { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_UNDERFLOW, "Major version number is too small to fit into long long type."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_OVERFLOW, "Major version number is too big to fit into long long type."); + } + else { + end = NULL; + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_NOT_NUMERIC, "Major version number is not numeric."); + } + } + else { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_NEGATIVE, "Major version number is not numeric."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_TOO_BIG, "Major version number is too big."); + } + else { + struct_work_copy->major = conv; + } + } + + if (end) { + /* Map end pointer to original string. */ + tmp += (end - tmp_copy); + } + + g_free (tmp_copy); + tmp_copy = NULL; + + if (0 > struct_work_copy->major) { + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + + /* Copy and convert minor version number. */ + tmp_copy = g_strdup (tmp); + struct_work_copy->minor = -1; + + conv_err = min_err = max_err = TRUE; + end = NULL; + conv = x2goclient_str_to_int (tmp_copy, TRUE, 0, TRUE, G_MAXUINT32, &end, &conv_err, &min_err, &max_err); + + if (conv_err) { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_UNDERFLOW, "Minor version number is too small to fit into long long type."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_OVERFLOW, "Minor version number is too big to fit into long long type."); + } + else { + end = NULL; + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_NOT_NUMERIC, "Minor version number is not numeric."); + } + } + else { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_NEGATIVE, "Minor version number is not numeric."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_TOO_BIG, "Minor version number is too big."); + } + else { + struct_work_copy->minor = conv; + } + } + + if (end) { + /* Map end pointer to original string. */ + tmp += (end - tmp_copy); + } + + g_free (tmp_copy); + tmp_copy = NULL; + + /* + * Handle error and additionally scan for the next character which MUST be a + * 'p' according to our scheme. + */ + if ((0 > struct_work_copy->minor) || ('p' != *tmp)) { + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + else { + /* Skip 'p' character. */ + ++tmp; + } + + /* Copy and convert patch version number. */ + tmp_copy = g_strdup (tmp); + struct_work_copy->patch = -1; + + conv_err = min_err = max_err = TRUE; + end = NULL; + conv = x2goclient_str_to_int (tmp_copy, TRUE, 0, TRUE, G_MAXUINT32, &end, &conv_err, &min_err, &max_err); + + if (conv_err) { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_UNDERFLOW, "Patch version number is too small to fit into long long type."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_OVERFLOW, "Patch version number is too big to fit into long long type."); + } + else { + end = NULL; + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_NOT_NUMERIC, "Patch version number is not numeric."); + } + } + else { + if (min_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_NEGATIVE, "Patch version number is not numeric."); + } + else if (max_err) { + g_set_error_literal (gerr, X2GOCLIENT_OPENSSH_VERSION_ERROR, X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_TOO_BIG, "Patch version number is too big."); + } + else { + struct_work_copy->patch = conv; + } + } + + if (end) { + /* Map end pointer to original string. */ + tmp += (end - tmp_copy); + } + + g_free (tmp_copy); + tmp_copy = NULL; + + if (0 > struct_work_copy->patch) { + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; + + return; + } + + /* Scan for a comma which should follow any additional version data. */ + end = g_strstr_len (tmp, -1, ","); + if (!(end)) { + /* + * Alternatively, scan for whitespace and we'll treat that as the + * additional version data separator. + */ + end = g_strstr_len (tmp, -1, " \t"); + + if (!(end)) { + /* + * No separator means or trailing whitespace means that we'll have to + * fast-forward to the actual end. + */ + end = (tmp + (strlen (tmp))); + } + } + + if ((end) && (0 < (end - tmp))) { + /* If we have additional data, copy it. */ + g_strlcpy (struct_work_copy->addon, tmp, (end - tmp)); + } + + /* Not having additional data is not an error. */ + + /* Copy the struct. */ + *openssh_version = *struct_work_copy; + + /* Lastly, free data. */ + x2goclient_openssh_version_free (struct_work_copy); + struct_work_copy = NULL; +} diff --git a/src/x2goclient-openssh-version.h b/src/x2goclient-openssh-version.h index af6aebe..fcb5f83 100644 --- a/src/x2goclient-openssh-version.h +++ b/src/x2goclient-openssh-version.h @@ -45,6 +45,36 @@ GType x2goclient_openssh_version_get_type (void) G_GNUC_CONST; X2GoClientOpenSSHVersion* x2goclient_openssh_version_new (void); void x2goclient_openssh_version_free (X2GoClientOpenSSHVersion *openssh_version); +/* + * Error handling helpers. + */ +#define X2GOCLIENT_OPENSSH_VERSION_ERROR g_quark_from_static_string ("x2goclient-openssh-version") + +enum { + X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_STRUCT = 0, + X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_VERSION_STRING, + X2GOCLIENT_OPENSSH_VERSION_ERROR_INVALID_PREAMBLE, + X2GOCLIENT_OPENSSH_VERSION_ERROR_NO_MAJOR_SEPARATOR, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_NOT_NUMERIC, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_UNDERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_OVERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_TOO_BIG, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MAJOR_NEGATIVE, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_NOT_NUMERIC, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_UNDERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_OVERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_TOO_BIG, + X2GOCLIENT_OPENSSH_VERSION_ERROR_MINOR_NEGATIVE, + X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_NOT_NUMERIC, + X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_UNDERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_OVERFLOW, + X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_TOO_BIG, + X2GOCLIENT_OPENSSH_VERSION_ERROR_PATCH_NEGATIVE, +}; + + +void x2goclient_openssh_version_parse (X2GoClientOpenSSHVersion *openssh_version, const gchar *version_string, GError **gerr); + G_END_DECLS #endif /* x2goclient_openssh_version_h */ -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git