-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: Move some crypto utils into their own file
- Loading branch information
Showing
8 changed files
with
90 additions
and
65 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
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,79 @@ | ||
/* | ||
* This file is part of Cockpit. | ||
* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Cockpit is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Cockpit is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { encode_filename, decode_filename, parse_options, extract_option, unparse_options } from "../utils.js"; | ||
|
||
export function edit_crypto_config(block, modify) { | ||
let old_config, new_config; | ||
|
||
function commit() { | ||
new_config[1]["track-parents"] = { t: 'b', v: true }; | ||
if (old_config) | ||
return block.UpdateConfigurationItem(old_config, new_config, { }); | ||
else | ||
return block.AddConfigurationItem(new_config, { }); | ||
} | ||
|
||
return block.GetSecretConfiguration({}).then( | ||
function (items) { | ||
old_config = items.find(c => c[0] == "crypttab"); | ||
new_config = ["crypttab", old_config ? Object.assign({ }, old_config[1]) : { }]; | ||
|
||
// UDisks insists on always having a "passphrase-contents" field when | ||
// adding a crypttab entry, but doesn't include one itself when returning | ||
// an entry without a stored passphrase. | ||
// | ||
if (!new_config[1]['passphrase-contents']) | ||
new_config[1]['passphrase-contents'] = { t: 'ay', v: encode_filename("") }; | ||
|
||
return modify(new_config[1], commit); | ||
}); | ||
} | ||
|
||
export function set_crypto_options(block, readonly, auto, nofail, netdev) { | ||
return edit_crypto_config(block, (config, commit) => { | ||
const opts = config.options ? parse_options(decode_filename(config.options.v)) : []; | ||
if (readonly !== null) { | ||
extract_option(opts, "readonly"); | ||
if (readonly) | ||
opts.push("readonly"); | ||
} | ||
if (auto !== null) { | ||
extract_option(opts, "noauto"); | ||
if (!auto) | ||
opts.push("noauto"); | ||
} | ||
if (nofail !== null) { | ||
extract_option(opts, "nofail"); | ||
if (nofail) | ||
opts.push("nofail"); | ||
} | ||
if (netdev !== null) { | ||
extract_option(opts, "_netdev"); | ||
if (netdev) | ||
opts.push("_netdev"); | ||
} | ||
config.options = { t: 'ay', v: encode_filename(unparse_options(opts)) }; | ||
return commit(); | ||
}); | ||
} | ||
|
||
export function set_crypto_auto_option(block, flag) { | ||
return set_crypto_options(block, null, flag, null, null); | ||
} |
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