forked from illumos/illumos-gate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
705b668
commit d8f839f
Showing
13 changed files
with
496 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/change_key.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
56 changes: 56 additions & 0 deletions
56
usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.change_key.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.