[systemd-devel] [PATCH] Allow for the use of @ in remote host calls
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Sun Jun 9 07:39:37 PDT 2013
On Sat, Jun 08, 2013 at 08:21:09PM -0500, Daniel Wallace wrote:
> Without this you have to use %40 with the -H flag because dbus doesn't
> like the @ sign being unescaped.
> ---
> src/hostname/hostnamectl.c | 12 ++++++++++--
> src/locale/localectl.c | 12 ++++++++++--
> src/login/loginctl.c | 12 ++++++++++--
> src/shared/dbus-common.c | 4 ++--
> src/systemctl/systemctl.c | 14 +++++++++++---
> src/timedate/timedatectl.c | 12 ++++++++++--
> 6 files changed, 53 insertions(+), 13 deletions(-)
>
> diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
> index d108a24..178f9bc 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,14 @@ static int parse_argv(int argc, char *argv[]) {
>
> case 'H':
> arg_transport = TRANSPORT_SSH;
> - arg_host = optarg;
> + arg_host = strchr(optarg, '@');
> + if (arg_host == NULL)
> + arg_host = optarg;
> + else {
> + arg_host[0] = '\0';
> + arg_host++;
> + arg_user = optarg;
> + }
This part repeats 5 times. Can you add
int parse_user_at_host(char *arg, char **user, char **host)
(or whatever name you think is better), and replace those
invocations? The number of lines of code won't be much different,
but I don't want to have this duplicated in every dbus-using
tool, the number of which is certain to grow above 5.
Zbyszek
> break;
>
> case ARG_SET_TRANSIENT:
> diff --git a/src/locale/localectl.c b/src/locale/localectl.c
> index b5cd344..30a6724 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,14 @@ static int parse_argv(int argc, char *argv[]) {
>
> case 'H':
> arg_transport = TRANSPORT_SSH;
> - arg_host = optarg;
> + arg_host = strchr(optarg, '@');
> + if (arg_host == NULL)
> + arg_host = optarg;
> + else {
> + arg_host[0] = '\0';
> + arg_host++;
> + arg_user = optarg;
> + }
> break;
>
> case ARG_NO_CONVERT:
> diff --git a/src/login/loginctl.c b/src/login/loginctl.c
> index caaea8d..ed24377 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,14 @@ static int parse_argv(int argc, char *argv[]) {
>
> case 'H':
> arg_transport = TRANSPORT_SSH;
> - arg_host = optarg;
> + arg_host = strchr(optarg, '@');
> + if (arg_host == NULL)
> + arg_host = optarg;
> + else {
> + arg_host[0] = '\0';
> + arg_host++;
> + arg_user = optarg;
> + }
> 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 at 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/systemctl/systemctl.c b/src/systemctl/systemctl.c
> index 58a6fd4..cc6db5d 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 *arg_host = NULL;
> +static char *arg_host = NULL;
> +static char *arg_user = NULL;
> static unsigned arg_lines = 10;
> static OutputMode arg_output = OUTPUT_SHORT;
> static bool arg_plain = false;
> @@ -5077,7 +5078,14 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
>
> case 'H':
> arg_transport = TRANSPORT_SSH;
> - arg_host = optarg;
> + arg_host = strchr(optarg, '@');
> + if (arg_host == NULL)
> + arg_host = optarg;
> + else {
> + arg_host[0] = '\0';
> + arg_host++;
> + arg_user = optarg;
> + }
> break;
>
> case ARG_RUNTIME:
> @@ -6098,7 +6106,7 @@ int main(int argc, char*argv[]) {
> bus_connect_system_polkit(&bus, &error);
> private_bus = false;
> } else if (arg_transport == TRANSPORT_SSH) {
> - bus_connect_system_ssh(NULL, arg_host, &bus, &error);
> + bus_connect_system_ssh(arg_user, arg_host, &bus, &error);
> private_bus = false;
> } else
> assert_not_reached("Uh, invalid transport...");
> diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
> index e8bc452..b2cc8ec 100644
> --- a/src/timedate/timedatectl.c
> +++ b/src/timedate/timedatectl.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 void pager_open_if_enabled(void) {
>
> @@ -560,7 +561,14 @@ static int parse_argv(int argc, char *argv[]) {
>
> case 'H':
> arg_transport = TRANSPORT_SSH;
> - arg_host = optarg;
> + arg_host = strchr(optarg, '@');
> + if (arg_host == NULL)
> + arg_host = optarg;
> + else {
> + arg_host[0] = '\0';
> + arg_host++;
> + arg_user = optarg;
> + }
> break;
>
> case ARG_NO_ASK_PASSWORD:
> --
> 1.8.3
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
More information about the systemd-devel
mailing list