diff options
author | Jason King <jason.brian.king@gmail.com> | 2021-11-05 09:48:07 -0500 |
---|---|---|
committer | Jason King <jason.brian.king@gmail.com> | 2021-11-19 15:27:15 -0600 |
commit | d8f839f91e21bea2f5200f95df55608cbecdeeb9 (patch) | |
tree | e346867b613449eeb87674a39fc76497eb3f3bd9 /usr/src/test | |
parent | 705b6680745618ebbf67feb254ce9a62511084a5 (diff) | |
download | illumos-gate-d8f839f91e21bea2f5200f95df55608cbecdeeb9.tar.gz |
14223 Add change key zfs channel program
Portions contributed by: Alex Wilson <alex@cooperi.net>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Mike Zeller <mike.zeller@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/test')
3 files changed, 183 insertions, 2 deletions
diff --git a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/Makefile b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/Makefile index 2034d39599..5f8ea55a97 100644 --- a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/Makefile +++ b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/Makefile @@ -11,15 +11,27 @@ # # Copyright (c) 2016 by Delphix. All rights reserved. +# Copyright 2020 Joyent, Inc. # include $(SRC)/Makefile.master +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/cmd/Makefile.ctf ROOTOPTPKG = $(ROOT)/opt/zfs-tests TESTDIR = $(ROOTOPTPKG)/tests/functional/channel_program/synctask_core KSHFILES :sh= ls *.ksh -PROGS = $(KSHFILES:.ksh=) +KSHPROGS = $(KSHFILES:.ksh=) + +SRCS :sh= ls *.c +CPROGS = $(SRCS:%.c=%.exe) +LDLIBS = $(LDLIBS.cmd) +LDLIBS += -lzfs_core -lnvpair +CSTD = $(CSTD_GNU99) +OBJS = $(SRCS:%.c=%.o) + +PROGS = $(KSHPROGS) $(CPROGS) FILES :sh= ls *.zcp *.out *.err 2>/dev/null; true INSTPROGS = $(PROGS:%=$(TESTDIR)/%) @@ -28,7 +40,9 @@ INSTFILES = $(FILES:%=$(TESTDIR)/%) $(INSTPROGS) := FILEMODE = 0555 $(INSTFILES) := FILEMODE = 0444 -all lint clean clobber: +all: $(CPROGS) + +clean clobber: install: $(INSTPROGS) $(INSTFILES) @@ -43,3 +57,16 @@ $(TESTDIR)/%: %.ksh $(TESTDIR)/%: % $(INS.file) + +%.o: ../%.c + $(COMPILE.c) $< + +%.exe: %.o + $(LINK.c) $< -o $@ $(LDLIBS) + $(POST_PROCESS) + +clobber: clean + -$(RM) $(PROGS) + +clean: + -$(RM) $(OBJS) diff --git a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/change_key.c b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/change_key.c new file mode 100644 index 0000000000..405c232b4e --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/change_key.c @@ -0,0 +1,98 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright 2020 Joyent, Inc. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/debug.h> +#include <sys/fs/zfs.h> +#include <libzfs_core.h> +#include <libnvpair.h> + +const char prog[] = + "arg = ... \n" + "fs = arg[\"dataset\"]\n" + "hexkey = arg[\"" ZPOOL_HIDDEN_ARGS "\"][\"key\"]\n" + "err = zfs.sync.change_key(fs, hexkey, 'hex')\n" + "msg = \"changing key on \" .. fs .. \" err=\" .. err\n" + "return msg"; + +/* + * Get the pool name from a dataset. This is crude but good enough + * for a test. + */ +static char * +get_pool(const char *dataset) +{ + char *res = strdup(dataset); + + if (res == NULL) + abort(); + + char *p = strchr(res, '/'); + + if (p != NULL) + *p = '\0'; + + return (res); +} + +int +main(int argc, char *argv[]) +{ + const char *dataset = argv[1]; + const char *key = argv[2]; + char *pool = NULL; + nvlist_t *args = fnvlist_alloc(); + nvlist_t *hidden_args = fnvlist_alloc(); + nvlist_t *result = NULL; + int ret = 0; + + if (argc != 3) { + (void) fprintf(stderr, "Usage: %s dataset key\n", argv[0]); + exit(2); + } + + VERIFY0(libzfs_core_init()); + + pool = get_pool(dataset); + + fnvlist_add_string(args, "dataset", dataset); + fnvlist_add_string(hidden_args, "key", key); + fnvlist_add_nvlist(args, ZPOOL_HIDDEN_ARGS, hidden_args); + + ret = lzc_channel_program(pool, prog, ZCP_DEFAULT_INSTRLIMIT, + ZCP_DEFAULT_MEMLIMIT, args, &result); + + (void) printf("lzc_channel_program returned %d", ret); + if (ret != 0) + (void) printf(" (%s)", strerror(ret)); + (void) fputc('\n', stdout); + + dump_nvlist(result, 5); + + nvlist_free(args); + nvlist_free(hidden_args); + nvlist_free(result); + free(pool); + + libzfs_core_fini(); + + return (ret); +} diff --git a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.change_key.ksh b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.change_key.ksh new file mode 100644 index 0000000000..5d505226b8 --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.change_key.ksh @@ -0,0 +1,56 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# CDDL HEADER END +# + +# +# Copyright 2020 Joyent, Inc. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: +# Try to change an encrypted dataset key via a ZFS channel program + +verify_runnable "both" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTFS1 && \ + log_must zfs destroy -f $TESTPOOL/$TESTFS1 +} +log_onexit cleanup + +log_assert "zfs.sync.change_key should change key material" + +log_must eval "echo $HEXKEY | zfs create -o encryption=on" \ + "-o keyformat=hex -o keylocation=prompt $TESTPOOL/$TESTFS1" + +log_must $ZCP_ROOT/synctask_core/change_key.exe $TESTPOOL/$TESTFS1 $HEXKEY1 + +# Key shouldn't appear in zpool history when using change_key.exe +log_mustnot eval "zfs history -il $TESTPOOL | grep $HEXKEY1" + +log_must zfs unmount $TESTPOOL/$TESTFS1 +log_must zfs unload-key $TESTPOOL/$TESTFS1 + +log_mustnot eval "echo $HEXKEY | zfs load-key $TESTPOOL/$TESTFS1" +log_must key_unavailable $TESTPOOL/$TESTFS1 + +log_must eval "echo $HEXKEY1 | zfs load-key $TESTPOOL/$TESTFS1" + +log_pass "zfs.sync.change_key should change key material" |