Re: [systemd-devel] [PATCHv2] Allow for the use of @ in remote host calls

2013-06-10 Thread Lennart Poettering
On Mon, 10.06.13 00:28, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:

 
 On Sun, Jun 09, 2013 at 03:54:39PM -0500, Daniel Wallace wrote:
  Without this you have to use %40 with the -H flag because dbus doesn't
  like the @ sign being unescaped.
 Applied.

Umm, I am pretty sure we should instead properly escape the hostname
specification when putting together the bus server string. It's probably
a good idea to not attempt to parse the string and take it mostly
opaque...

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCHv2] Allow for the use of @ in remote host calls

2013-06-09 Thread Daniel Wallace
Without this you have to use %40 with the -H flag because dbus doesn't
like the @ sign being unescaped.
---
 src/hostname/hostnamectl.c |  5 +++--
 src/locale/localectl.c |  5 +++--
 src/login/loginctl.c   |  5 +++--
 src/shared/dbus-common.c   |  4 ++--
 src/shared/util.c  | 10 ++
 src/shared/util.h  |  1 +
 src/systemctl/systemctl.c  |  7 ---
 src/timedate/timedatectl.c |  5 +++--
 8 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index d108a24..f7d844b 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -44,7 +44,8 @@ static enum transport {
 TRANSPORT_POLKIT
 } arg_transport = TRANSPORT_NORMAL;
 static bool arg_ask_password = true;
-static const char *arg_host = NULL;
+static char *arg_host = NULL;
+static char *arg_user = NULL;
 static bool arg_set_transient = false;
 static bool arg_set_pretty = false;
 static bool arg_set_static = false;
@@ -421,7 +422,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 case 'H':
 arg_transport = TRANSPORT_SSH;
-arg_host = optarg;
+parse_user_at_host(optarg, arg_user, arg_host);
 break;
 
 case ARG_SET_TRANSIENT:
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index b5cd344..cd7356a 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -46,7 +46,8 @@ static enum transport {
 TRANSPORT_POLKIT
 } arg_transport = TRANSPORT_NORMAL;
 static bool arg_ask_password = true;
-static const char *arg_host = NULL;
+static char *arg_host = NULL;
+static char *arg_user = NULL;
 static bool arg_convert = true;
 
 static void pager_open_if_enabled(void) {
@@ -777,7 +778,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 case 'H':
 arg_transport = TRANSPORT_SSH;
-arg_host = optarg;
+parse_user_at_host(optarg, arg_user, arg_host);
 break;
 
 case ARG_NO_CONVERT:
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index caaea8d..b09aa37 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -50,7 +50,8 @@ static enum transport {
 TRANSPORT_POLKIT
 } arg_transport = TRANSPORT_NORMAL;
 static bool arg_ask_password = true;
-static const char *arg_host = NULL;
+static char *arg_host = NULL;
+static char *arg_user = NULL;
 
 static void pager_open_if_enabled(void) {
 
@@ -1421,7 +1422,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 case 'H':
 arg_transport = TRANSPORT_SSH;
-arg_host = optarg;
+parse_user_at_host(optarg, arg_user, arg_host);
 break;
 
 case ARG_FULL:
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c
index b8c15cb..f579567 100644
--- a/src/shared/dbus-common.c
+++ b/src/shared/dbus-common.c
@@ -178,9 +178,9 @@ int bus_connect_system_ssh(const char *user, const char 
*host, DBusConnection **
 assert(user || host);
 
 if (user  host)
-asprintf(p, 
unixexec:path=ssh,argv1=-xT,argv2=%s@%s,argv3=systemd-stdio-bridge, user, 
host);
+asprintf(p, 
unixexec:path=ssh,argv1=-xT,argv2=%s%%40%s,argv3=systemd-stdio-bridge, user, 
host);
 else if (user)
-asprintf(p, 
unixexec:path=ssh,argv1=-xT,argv2=%s@localhost,argv3=systemd-stdio-bridge, 
user);
+asprintf(p, 
unixexec:path=ssh,argv1=-xT,argv2=%s%%40localhost,argv3=systemd-stdio-bridge, 
user);
 else if (host)
 asprintf(p, 
unixexec:path=ssh,argv1=-xT,argv2=%s,argv3=systemd-stdio-bridge, host);
 
diff --git a/src/shared/util.c b/src/shared/util.c
index 2edf9cd..6cdd762 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5847,3 +5847,13 @@ bool id128_is_valid(const char *s) {
 
 return true;
 }
+
+void parse_user_at_host(char *arg, char **user, char **host) {
+*host = strchr(arg, '@');
+if (*host == NULL)
+*host = arg;
+else {
+*host[0]++ = '\0';
+*user = arg;
+}
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 64e63b8..e6f9312 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -732,3 +732,4 @@ static inline void _reset_locale_(struct _locale_struct_ 
*s) {
  _saved_locale_.quit = true)
 
 bool id128_is_valid(const char *s) _pure_;
+void parse_user_at_host(char *arg, char **user, char **host);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 58a6fd4..a20290e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -129,7 +129,8 @@ static enum transport {
 TRANSPORT_SSH,
 TRANSPORT_POLKIT
 } arg_transport = TRANSPORT_NORMAL;
-static const char 

Re: [systemd-devel] [PATCHv2] Allow for the use of @ in remote host calls

2013-06-09 Thread Zbigniew Jędrzejewski-Szmek
On Sun, Jun 09, 2013 at 03:54:39PM -0500, Daniel Wallace wrote:
 Without this you have to use %40 with the -H flag because dbus doesn't
 like the @ sign being unescaped.
Applied.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel