aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-12-25 10:41:06 +0100
committerDaniel Mueller <deso@posteo.net>2018-12-27 11:12:59 -0800
commit96adac9c5d3399a4890f54515a92472067771303 (patch)
tree99f36d2a81f46f7bb44ac0374743fd78cdb60092 /nitrocli/src/commands.rs
parentf3c13434e91eea3bcceaa95b86bfcd0db1ec56d4 (diff)
downloadnitrocli-96adac9c5d3399a4890f54515a92472067771303.tar.gz
nitrocli-96adac9c5d3399a4890f54515a92472067771303.tar.bz2
Implement the config set subcommand
This change implements the config set subcommand. The subcommand changes the configuration of a Nitrokey device. Its structure is more complex as it allows partial modifications: The user does not have to change all settings, but may choose to change only some. At the same time, the binding settings can be either set to a value or disabled. Therefore, we have the --{num,caps,scrol}lock options to set a value and the --no-{num,caps,scrol}lock options to disable the value. If none of the two is set, the setting is not changed.
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r--nitrocli/src/commands.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index 8ce1076..9aef2de 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -128,7 +128,7 @@ where
{
let mut data = data;
let mut retry = 3;
- let mut error_msg: Option<&str> = None;
+ let mut error_msg = None;
loop {
let passphrase = match pinentry::inquire_passphrase(pin, error_msg) {
Ok(passphrase) => passphrase,
@@ -304,6 +304,28 @@ pub fn config_get() -> Result<()> {
Ok(())
}
+/// Write the Nitrokey configuration.
+pub fn config_set(
+ numlock: args::ConfigOption<u8>,
+ capslock: args::ConfigOption<u8>,
+ scrollock: args::ConfigOption<u8>,
+ user_password: Option<bool>,
+) -> Result<()> {
+ let device = authenticate_admin(get_device()?)?;
+ let config = device
+ .get_config()
+ .map_err(|err| get_error("Could not get configuration", &err))?;
+ let config = nitrokey::Config {
+ numlock: numlock.or(config.numlock),
+ capslock: capslock.or(config.capslock),
+ scrollock: scrollock.or(config.scrollock),
+ user_password: user_password.unwrap_or(config.user_password),
+ };
+ device
+ .write_config(config)
+ .map_err(|err| get_error("Could not set configuration", &err))
+}
+
fn get_otp<T: GenerateOtp>(slot: u8, algorithm: args::OtpAlgorithm, device: &T) -> Result<String> {
match algorithm {
args::OtpAlgorithm::Hotp => device.get_hotp_code(slot),