mirror of
https://github.com/systemd/systemd
synced 2026-03-25 08:14:54 +01:00
Compare commits
3 Commits
56a85121cd
...
85213a7070
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85213a7070 | ||
|
|
5c07745ff9 | ||
|
|
008ee79601 |
@ -3,15 +3,26 @@
|
|||||||
executables += [
|
executables += [
|
||||||
generator_template + {
|
generator_template + {
|
||||||
'name' : 'systemd-ssh-generator',
|
'name' : 'systemd-ssh-generator',
|
||||||
'sources' : files('ssh-generator.c'),
|
'sources' : files(
|
||||||
|
'ssh-generator.c',
|
||||||
|
'ssh-util.c',
|
||||||
|
),
|
||||||
|
'extract' : files(
|
||||||
|
'ssh-util.c',
|
||||||
|
),
|
||||||
},
|
},
|
||||||
libexec_template + {
|
libexec_template + {
|
||||||
'name' : 'systemd-ssh-proxy',
|
'name' : 'systemd-ssh-proxy',
|
||||||
'sources' : files('ssh-proxy.c'),
|
'sources' : files(
|
||||||
|
'ssh-proxy.c',
|
||||||
|
),
|
||||||
},
|
},
|
||||||
libexec_template + {
|
libexec_template + {
|
||||||
'name' : 'systemd-ssh-issue',
|
'name' : 'systemd-ssh-issue',
|
||||||
'sources' : files('ssh-issue.c'),
|
'sources' : files(
|
||||||
|
'ssh-issue.c',
|
||||||
|
),
|
||||||
|
'objects' : ['systemd-ssh-generator'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#include "socket-netlink.h"
|
#include "socket-netlink.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "ssh-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
@ -211,29 +212,15 @@ static int add_vsock_socket(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup_close_ int vsock_fd = socket(AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
r = vsock_open_or_warn(/* ret= */ NULL);
|
||||||
if (vsock_fd < 0) {
|
if (r <= 0)
|
||||||
if (ERRNO_IS_NOT_SUPPORTED(errno)) {
|
return r;
|
||||||
log_debug("Not creating AF_VSOCK ssh listener, since AF_VSOCK is not available.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return log_error_errno(errno, "Unable to test if AF_VSOCK is available: %m");
|
|
||||||
}
|
|
||||||
|
|
||||||
vsock_fd = safe_close(vsock_fd);
|
|
||||||
|
|
||||||
/* Determine the local CID so that we can log it to help users to connect to this VM */
|
/* Determine the local CID so that we can log it to help users to connect to this VM */
|
||||||
unsigned local_cid;
|
unsigned local_cid;
|
||||||
r = vsock_get_local_cid(&local_cid);
|
r = vsock_get_local_cid_or_warn(&local_cid);
|
||||||
if (r < 0) {
|
if (r <= 0)
|
||||||
if (ERRNO_IS_DEVICE_ABSENT(r)) {
|
return r;
|
||||||
log_debug("Not creating AF_VSOCK ssh listener, since /dev/vsock is not available (even though AF_VSOCK is).");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
|
|
||||||
}
|
|
||||||
|
|
||||||
r = make_sshd_template_unit(
|
r = make_sshd_template_unit(
|
||||||
dest,
|
dest,
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include "mkdir.h"
|
#include "mkdir.h"
|
||||||
#include "parse-argument.h"
|
#include "parse-argument.h"
|
||||||
#include "pretty-print.h"
|
#include "pretty-print.h"
|
||||||
#include "socket-util.h"
|
#include "ssh-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
@ -135,33 +135,11 @@ static int acquire_cid(unsigned *ret_cid) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup_close_ int vsock_fd = socket(AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
r = vsock_open_or_warn(/* ret= */ NULL);
|
||||||
if (vsock_fd < 0) {
|
if (r <= 0)
|
||||||
if (ERRNO_IS_NOT_SUPPORTED(errno)) {
|
return r;
|
||||||
log_debug("Not creating issue file, since AF_VSOCK is not available.");
|
|
||||||
*ret_cid = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return log_error_errno(errno, "Unable to test if AF_VSOCK is available: %m");
|
return vsock_get_local_cid_or_warn(ret_cid);
|
||||||
}
|
|
||||||
|
|
||||||
vsock_fd = safe_close(vsock_fd);
|
|
||||||
|
|
||||||
unsigned local_cid;
|
|
||||||
r = vsock_get_local_cid(&local_cid);
|
|
||||||
if (r < 0) {
|
|
||||||
if (ERRNO_IS_DEVICE_ABSENT(r)) {
|
|
||||||
log_debug("Not creating issue file, since /dev/vsock is not available (even though AF_VSOCK is).");
|
|
||||||
*ret_cid = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
|
|
||||||
}
|
|
||||||
|
|
||||||
*ret_cid = local_cid;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run(int argc, char* argv[]) {
|
static int run(int argc, char* argv[]) {
|
||||||
|
|||||||
40
src/ssh-generator/ssh-util.c
Normal file
40
src/ssh-generator/ssh-util.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "errno-util.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "socket-util.h"
|
||||||
|
#include "ssh-util.h"
|
||||||
|
|
||||||
|
int vsock_open_or_warn(int *ret) {
|
||||||
|
int fd = RET_NERRNO(socket(AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0));
|
||||||
|
if (ERRNO_IS_NEG_NOT_SUPPORTED(fd))
|
||||||
|
log_debug_errno(fd, "AF_VSOCK is not available, ignoring: %m");
|
||||||
|
else if (fd < 0)
|
||||||
|
return log_error_errno(fd, "Unable to test if AF_VSOCK is available: %m");
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
*ret = fd;
|
||||||
|
else
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return fd >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vsock_get_local_cid_or_warn(unsigned *ret) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = vsock_get_local_cid(ret);
|
||||||
|
if (ERRNO_IS_NEG_DEVICE_ABSENT(r) || r == -EADDRNOTAVAIL) {
|
||||||
|
if (ERRNO_IS_NEG_DEVICE_ABSENT(r))
|
||||||
|
log_debug_errno(r, "/dev/vsock is not available (even though AF_VSOCK is), ignoring: %m");
|
||||||
|
if (ret)
|
||||||
|
*ret = 0; /* bogus value */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
4
src/ssh-generator/ssh-util.h
Normal file
4
src/ssh-generator/ssh-util.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
|
int vsock_open_or_warn(int *ret);
|
||||||
|
int vsock_get_local_cid_or_warn(unsigned *ret);
|
||||||
Loading…
x
Reference in New Issue
Block a user