sd-bus rework host handling
--machine has been missing for a while in systemd-stdio-bridge this syntax can be switched to be more standard. v2: Support the old syntax too. timedatectl -H server1.myhostingcompany.com:5555/container1 Closes: #8071
This commit is contained in:
parent
026df70eaf
commit
b85b4a70d7
|
@ -1357,38 +1357,88 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
|
||||||
|
|
||||||
int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
||||||
_cleanup_free_ char *e = NULL;
|
_cleanup_free_ char *e = NULL;
|
||||||
char *m = NULL, *c = NULL, *a;
|
char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
assert(host);
|
assert(host);
|
||||||
|
|
||||||
/* Let's see if we shall enter some container */
|
/* Skip ":"s in ipv6 addresses */
|
||||||
m = strchr(host, ':');
|
if (*host == '[') {
|
||||||
if (m) {
|
char *t;
|
||||||
m++;
|
|
||||||
|
|
||||||
/* Let's make sure this is not a port of some kind,
|
rbracket = strchr(host, ']');
|
||||||
* and is a valid machine name. */
|
if (!rbracket)
|
||||||
if (!in_charset(m, DIGITS) && machine_name_is_valid(m)) {
|
return -EINVAL;
|
||||||
char *t;
|
t = strndupa(host + 1, rbracket - host - 1);
|
||||||
|
e = bus_address_escape(t);
|
||||||
|
if (!e)
|
||||||
|
return -ENOMEM;
|
||||||
|
} else if ((a = strchr(host, '@')))
|
||||||
|
if (*(a + 1) == '[') {
|
||||||
|
_cleanup_free_ char *t = NULL;
|
||||||
|
|
||||||
/* Cut out the host part */
|
rbracket = strchr(a + 1, ']');
|
||||||
t = strndupa(host, m - host - 1);
|
if (!rbracket)
|
||||||
|
return -EINVAL;
|
||||||
|
t = new0(char, strlen(host));
|
||||||
|
if (!t)
|
||||||
|
return -ENOMEM;
|
||||||
|
strncat(t, host, a - host + 1);
|
||||||
|
strncat(t, a + 2, rbracket - a - 2);
|
||||||
e = bus_address_escape(t);
|
e = bus_address_escape(t);
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
c = strjoina(",argv5=--machine=", m);
|
/* Let's see if a port was given */
|
||||||
|
m = strchr(rbracket ? rbracket + 1 : host, ':');
|
||||||
|
if (m) {
|
||||||
|
char *t;
|
||||||
|
bool got_forward_slash = false;
|
||||||
|
|
||||||
|
p = m + 1;
|
||||||
|
|
||||||
|
t = strchr(p, '/');
|
||||||
|
if (t) {
|
||||||
|
p = strndupa(p, t - p);
|
||||||
|
got_forward_slash = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_charset(p, "0123456789")) {
|
||||||
|
if (!machine_name_is_valid(p) || got_forward_slash)
|
||||||
|
return -EINVAL;
|
||||||
|
else {
|
||||||
|
m = p;
|
||||||
|
p = NULL;
|
||||||
|
goto interpret_port_as_machine_old_syntax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Let's see if a machine was given */
|
||||||
|
m = strchr(rbracket ? rbracket + 1 : host, '/');
|
||||||
|
if (m) {
|
||||||
|
m++;
|
||||||
|
interpret_port_as_machine_old_syntax:
|
||||||
|
/* Let's make sure this is not a port of some kind,
|
||||||
|
* and is a valid machine name. */
|
||||||
|
if (!in_charset(m, "0123456789") && machine_name_is_valid(m))
|
||||||
|
c = strjoina(",argv", p ? "7" : "5", "=--machine=", m);
|
||||||
|
}
|
||||||
|
|
||||||
if (!e) {
|
if (!e) {
|
||||||
e = bus_address_escape(host);
|
char *t;
|
||||||
|
|
||||||
|
t = strndupa(host, strcspn(host, ":/"));
|
||||||
|
|
||||||
|
e = bus_address_escape(t);
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=systemd-stdio-bridge", c);
|
a = strjoin("unixexec:path=ssh,argv1=-xT", p ? ",argv2=-p,argv3=" : "", strempty(p),
|
||||||
|
",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
|
||||||
|
",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
|
||||||
if (!a)
|
if (!a)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue