From patchwork Tue Oct 15 18:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 11191459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17B2E14DB for ; Tue, 15 Oct 2019 18:25:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E13882084B for ; Tue, 15 Oct 2019 18:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571163958; bh=pwVNxTtVN+m0L52bFTfYVUOhbuFSQvegc/P9hqmluas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PbGt0x+sLbL1HNvR0vByEDFFvjCuygW3nX8eW1ygM0OVgBStK37CyorZoSx1Pw/gJ Fkv+p2Iqe2WPZHRD9F+Q4f6r09ELkP13/c1KLOOLVG0O5LSFxOFbqx1UCyjqERNbrh KWcoYA7uk5N+UcG2b/fPgy8UTdPstgK1JCM7IGG4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388927AbfJOSZ5 (ORCPT ); Tue, 15 Oct 2019 14:25:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389040AbfJOSZ5 (ORCPT ); Tue, 15 Oct 2019 14:25:57 -0400 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E9B71222C5; Tue, 15 Oct 2019 18:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571163443; bh=pwVNxTtVN+m0L52bFTfYVUOhbuFSQvegc/P9hqmluas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k/dviEbwWYMy7IsZiRCUbR0A8ac68ENh9C6BD3cDGaToLxvVuhd+/5JewAm24yAT5 2sU2yMpJXdDoq1GzkbbinfynftBIEHBUZkRMYPeOJgSALuqGWG/gN4XjITzHZkqMoN QcKwp8nnX8WDPbjwS0eXMvz1qjXflgVkoYA2IYm0= From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org Subject: [PATCH v3 2/9] common/encrypt: add helper functions that wrap new xfs_io commands Date: Tue, 15 Oct 2019 11:16:36 -0700 Message-Id: <20191015181643.6519-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191015181643.6519-1-ebiggers@kernel.org> References: <20191015181643.6519-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org From: Eric Biggers Wrap the new xfs_io commands 'add_enckey', 'rm_enckey', and 'enckey_status' with helper functions. Also add _user_do_get_encpolicy(), so that all encryption xfs_io commands have a _user_do() version. Signed-off-by: Eric Biggers --- common/encrypt | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/common/encrypt b/common/encrypt index 7bbe1936..a086e80f 100644 --- a/common/encrypt +++ b/common/encrypt @@ -261,6 +261,71 @@ _get_encpolicy() $XFS_IO_PROG -c "get_encpolicy $*" "$file" } +_user_do_get_encpolicy() +{ + local file=$1 + shift + + _user_do "$XFS_IO_PROG -c \"get_encpolicy $*\" \"$file\"" +} + +# Add an encryption key to the given filesystem. +_add_enckey() +{ + local mnt=$1 + local raw_key=$2 + shift 2 + + echo -ne "$raw_key" | $XFS_IO_PROG -c "add_enckey $*" "$mnt" +} + +_user_do_add_enckey() +{ + local mnt=$1 + local raw_key=$2 + shift 2 + + _user_do "echo -ne \"$raw_key\" | $XFS_IO_PROG -c \"add_enckey $*\" \"$mnt\"" +} + +# Remove the given encryption key from the given filesystem. +_rm_enckey() +{ + local mnt=$1 + local keyspec=$2 + shift 2 + + $XFS_IO_PROG -c "rm_enckey $* $keyspec" "$mnt" +} + +_user_do_rm_enckey() +{ + local mnt=$1 + local keyspec=$2 + shift 2 + + _user_do "$XFS_IO_PROG -c \"rm_enckey $* $keyspec\" \"$mnt\"" +} + +# Get the status of the given encryption key on the given filesystem. +_enckey_status() +{ + local mnt=$1 + local keyspec=$2 + shift 2 + + $XFS_IO_PROG -c "enckey_status $* $keyspec" "$mnt" +} + +_user_do_enckey_status() +{ + local mnt=$1 + local keyspec=$2 + shift 2 + + _user_do "$XFS_IO_PROG -c \"enckey_status $* $keyspec\" \"$mnt\"" +} + # Retrieve the encryption nonce of the given inode as a hex string. The nonce # was randomly generated by the filesystem and isn't exposed directly to # userspace. But it can be read using the filesystem's debugging tools.