[X2Go-Commits] [libx2goclient] 07/07: src/x2goclient-network-ssh.c: start implementation x2goclient_network_ssh_parse_sockspec ().
git-admin at x2go.org
git-admin at x2go.org
Fri Jul 26 15:01:53 CEST 2019
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository libx2goclient.
commit dc7f904de32f418a1297a8b6cbeaeb6eba601d0f
Author: Mihai Moldovan <ionic at ionic.de>
Date: Fri Jul 26 15:01:32 2019 +0200
src/x2goclient-network-ssh.c: start implementation x2goclient_network_ssh_parse_sockspec ().
---
src/x2goclient-network-ssh.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index 133b112..4b95b6d 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -22,8 +22,13 @@
Boston, MA 02110-1301, USA.
*/
+#include <sys/socket.h>
+#include <sys/un.h>
+
#include <glib.h>
#include <glib/gi18n.h>
+#include <glib/gprintf.h>
+#include <gmodule.h>
#include <gio/gio.h>
#ifdef HAVE_CONFIG_H
@@ -52,6 +57,63 @@ struct _X2GoClientNetworkSSH {
G_DEFINE_TYPE (X2GoClientNetworkSSH, x2goclient_network_ssh, X2GOCLIENT_TYPE_NETWORK);
+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.
+ *
+ * N.B.: do *not* sanitize the string, since UNIX sockets are allowed to
+ * start and end on whitespace.
+ */
+ gboolean is_abstract = FALSE;
+
+ /* Max. path len without terminating NULL byte */
+ if ((sizeof (((struct sockaddr_un*)(NULL))->sun_path) - 1) >= sockspec->len) {
+ /* Smells like a UNIX socket so far. */
+ if (0 == sockspec->str[0]) {
+ /*
+ * Abstract UNIX sockets are specified with a preceding NULL byte.
+ * We can't check for them, since they have no equivalent on the file
+ * system.
+ *
+ * Encountering this means that we have to trust the socket exists.
+ */
+ is_abstract = TRUE;
+ }
+ else {
+ /* Check if such a file exists on the file system. */
+ ... /* Parse error is fine here. */
+ }
+ }
+
+ 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);
+
+ gboolean is_v6 = FALSE;
+ gchar *v6_end = NULL;
+
+ /*
+ * As a very common convention, IPv6 address have to be encapsulated in
+ * brackets, check for that.
+ */
+ if ('[' == sockspec->str[0]) {
+ v6_end = g_strstr_len (sockspec->str, -1, "]");
+
+ if (v6_end) {
+ is_v6 = TRUE;
+ }
+ }
+ }
+ }
+
+ return ret;
+}
+
static void x2goclient_network_ssh_class_init (X2GoClientNetworkSSHClass *klass) {
}
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
More information about the x2go-commits
mailing list