Merge pull request #10996 from poettering/oci-prep
Preparation for the nspawn-OCI work
This commit is contained in:
@@ -405,7 +405,7 @@ static int verify_esp(
|
||||
sd_id128_t *ret_uuid) {
|
||||
#if HAVE_BLKID
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
|
||||
char t[DEV_NUM_PATH_MAX];
|
||||
_cleanup_free_ char *node = NULL;
|
||||
const char *v;
|
||||
#endif
|
||||
uint64_t pstart = 0, psize = 0;
|
||||
@@ -469,9 +469,11 @@ static int verify_esp(
|
||||
goto finish;
|
||||
|
||||
#if HAVE_BLKID
|
||||
xsprintf_dev_num_path(t, "block", st.st_dev);
|
||||
r = device_path_make_major_minor(S_IFBLK, st.st_dev, &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format major/minor device path: %m");
|
||||
errno = 0;
|
||||
b = blkid_new_probe_from_filename(t);
|
||||
b = blkid_new_probe_from_filename(node);
|
||||
if (!b)
|
||||
return log_error_errno(errno ?: ENOMEM, "Failed to open file system \"%s\": %m", p);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "label.h"
|
||||
#include "log.h"
|
||||
#include "path-util.h"
|
||||
#include "umask-util.h"
|
||||
#include "user-util.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -54,3 +55,61 @@ int dev_setup(const char *prefix, uid_t uid, gid_t gid) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int make_inaccessible_nodes(const char *root, uid_t uid, gid_t gid) {
|
||||
static const struct {
|
||||
const char *name;
|
||||
mode_t mode;
|
||||
} table[] = {
|
||||
{ "/run/systemd", S_IFDIR | 0755 },
|
||||
{ "/run/systemd/inaccessible", S_IFDIR | 0000 },
|
||||
{ "/run/systemd/inaccessible/reg", S_IFREG | 0000 },
|
||||
{ "/run/systemd/inaccessible/dir", S_IFDIR | 0000 },
|
||||
{ "/run/systemd/inaccessible/fifo", S_IFIFO | 0000 },
|
||||
{ "/run/systemd/inaccessible/sock", S_IFSOCK | 0000 },
|
||||
|
||||
/* The following two are likely to fail if we lack the privs for it (for example in an userns
|
||||
* environment, if CAP_SYS_MKNOD is missing, or if a device node policy prohibit major/minor of 0
|
||||
* device nodes to be created). But that's entirely fine. Consumers of these files should carry
|
||||
* fallback to use a different node then, for example /run/systemd/inaccessible/sock, which is close
|
||||
* enough in behaviour and semantics for most uses. */
|
||||
{ "/run/systemd/inaccessible/chr", S_IFCHR | 0000 },
|
||||
{ "/run/systemd/inaccessible/blk", S_IFBLK | 0000 },
|
||||
};
|
||||
|
||||
_cleanup_umask_ mode_t u;
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
u = umask(0000);
|
||||
|
||||
/* Set up inaccessible (and empty) file nodes of all types. This are used to as mount sources for over-mounting
|
||||
* ("masking") file nodes that shall become inaccessible and empty for specific containers or services. We try
|
||||
* to lock down these nodes as much as we can, but otherwise try to match them as closely as possible with the
|
||||
* underlying file, i.e. in the best case we offer the same node type as the underlying node. */
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(table); i++) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
|
||||
path = prefix_root(root, table[i].name);
|
||||
if (!path)
|
||||
return log_oom();
|
||||
|
||||
if (S_ISDIR(table[i].mode))
|
||||
r = mkdir(path, table[i].mode & 07777);
|
||||
else
|
||||
r = mknod(path, table[i].mode, makedev(0, 0));
|
||||
if (r < 0) {
|
||||
if (errno != EEXIST)
|
||||
log_debug_errno(errno, "Failed to create '%s', ignoring: %m", path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (uid != UID_INVALID || gid != GID_INVALID) {
|
||||
if (lchown(path, uid, gid) < 0)
|
||||
log_debug_errno(errno, "Failed to chown '%s': %m", path);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,3 +4,5 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
int dev_setup(const char *prefix, uid_t uid, gid_t gid);
|
||||
|
||||
int make_inaccessible_nodes(const char *root, uid_t uid, gid_t gid);
|
||||
|
||||
@@ -220,8 +220,9 @@ int dissect_image(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (asprintf(&n, "/dev/block/%u:%u", major(st.st_rdev), minor(st.st_rdev)) < 0)
|
||||
return -ENOMEM;
|
||||
r = device_path_make_major_minor(st.st_mode, st.st_rdev, &n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
m->partitions[PARTITION_ROOT] = (DissectedPartition) {
|
||||
.found = true,
|
||||
|
||||
+44
-2
@@ -392,11 +392,14 @@ int pty_forward_new(
|
||||
struct winsize ws;
|
||||
int r;
|
||||
|
||||
f = new0(PTYForward, 1);
|
||||
f = new(PTYForward, 1);
|
||||
if (!f)
|
||||
return -ENOMEM;
|
||||
|
||||
f->flags = flags;
|
||||
*f = (struct PTYForward) {
|
||||
.flags = flags,
|
||||
.master = -1,
|
||||
};
|
||||
|
||||
if (event)
|
||||
f->event = sd_event_ref(event);
|
||||
@@ -587,3 +590,42 @@ int pty_forward_set_priority(PTYForward *f, int64_t priority) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pty_forward_set_width_height(PTYForward *f, unsigned width, unsigned height) {
|
||||
struct winsize ws;
|
||||
|
||||
assert(f);
|
||||
|
||||
if (width == (unsigned) -1 && height == (unsigned) -1)
|
||||
return 0; /* noop */
|
||||
|
||||
if (width != (unsigned) -1 &&
|
||||
(width == 0 || width > USHRT_MAX))
|
||||
return -ERANGE;
|
||||
|
||||
if (height != (unsigned) -1 &&
|
||||
(height == 0 || height > USHRT_MAX))
|
||||
return -ERANGE;
|
||||
|
||||
if (width == (unsigned) -1 || height == (unsigned) -1) {
|
||||
if (ioctl(f->master, TIOCGWINSZ, &ws) < 0)
|
||||
return -errno;
|
||||
|
||||
if (width != (unsigned) -1)
|
||||
ws.ws_col = width;
|
||||
if (height != (unsigned) -1)
|
||||
ws.ws_row = height;
|
||||
} else
|
||||
ws = (struct winsize) {
|
||||
.ws_row = height,
|
||||
.ws_col = width,
|
||||
};
|
||||
|
||||
if (ioctl(f->master, TIOCSWINSZ, &ws) < 0)
|
||||
return -errno;
|
||||
|
||||
/* Make sure we ignore SIGWINCH window size events from now on */
|
||||
f->sigwinch_event_source = sd_event_source_unref(f->sigwinch_event_source);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,4 +37,6 @@ bool pty_forward_drain(PTYForward *f);
|
||||
|
||||
int pty_forward_set_priority(PTYForward *f, int64_t priority);
|
||||
|
||||
int pty_forward_set_width_height(PTYForward *f, unsigned width, unsigned height);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);
|
||||
|
||||
Reference in New Issue
Block a user