aboutgitcodebugslistschat
path: root/test/nstool.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-04-06 13:28:12 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-04-08 01:11:57 +0200
commitf6a9ea3af5384ac561b67494073d520145ae2281 (patch)
tree4b9bbcce00a0f66f86c4943e7ee07b61d911ed37 /test/nstool.c
parent4311066bdbf463981b079a7bdfb702c8b7b27f50 (diff)
downloadpasst-f6a9ea3af5384ac561b67494073d520145ae2281.tar
passt-f6a9ea3af5384ac561b67494073d520145ae2281.tar.gz
passt-f6a9ea3af5384ac561b67494073d520145ae2281.tar.bz2
passt-f6a9ea3af5384ac561b67494073d520145ae2281.tar.lz
passt-f6a9ea3af5384ac561b67494073d520145ae2281.tar.xz
passt-f6a9ea3af5384ac561b67494073d520145ae2281.tar.zst
passt-f6a9ea3af5384ac561b67494073d520145ae2281.zip
nstool: Add magic number to advertized information
So that we'll probably give a better error if you point it at something that's not an nstool hold control socket. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'test/nstool.c')
-rw-r--r--test/nstool.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/nstool.c b/test/nstool.c
index 2682c6b..fccbfb9 100644
--- a/test/nstool.c
+++ b/test/nstool.c
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
@@ -45,7 +46,10 @@ const struct ns_type nstypes[] = {
{ CLONE_NEWUTS, "uts" },
};
+#define NSTOOL_MAGIC 0x7570017575601d75ULL
+
struct holder_info {
+ uint64_t magic;
pid_t pid;
uid_t uid;
gid_t gid;
@@ -104,6 +108,10 @@ static int connect_ctl(const char *sockpath, bool wait,
if ((size_t)len < sizeof(*info))
die("short read() on control socket %s\n", sockpath);
+ if (info->magic != NSTOOL_MAGIC)
+ die("Control socket %s doesn't appear to belong to nstool\n",
+ sockpath);
+
if (peercred) {
socklen_t optlen = sizeof(*peercred);
@@ -143,6 +151,7 @@ static void cmd_hold(int argc, char *argv[])
if (rc < 0)
die("listen() on %s: %s\n", sockpath, strerror(errno));
+ info.magic = NSTOOL_MAGIC;
info.pid = getpid();
info.uid = getuid();
info.gid = getgid();