This thread contains a patchset. You're looking at the original emails,
but you may wish to use the patch review UI.
Review patch
3
2
[PATCH himitsu v3] himitsu-init: prompt before overwriting secstore
---
cmd/himitsu-init/main.ha | 23 +++++++++++++++++++++ --
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/cmd/himitsu-init/main.ha b/cmd/himitsu-init/main.ha
index 0989c6d..0608690 100644
--- a/cmd/himitsu-init/main.ha
+++ b/cmd/himitsu-init/main.ha
@@ -1,3 +1,4 @@
+ use ascii;
use bufio;
use bytes;
use dirs;
@@ -24,7 +25,6 @@ export fn main() void = {
};
const termios = tty::termios_query(tty)!;
- tty::noecho(&termios)!;
defer tty::termios_restore(&termios);
let rbuf: [os::BUFSIZ]u8 = [0...];
@@ -32,7 +32,26 @@ export fn main() void = {
const tty = &bufio::buffered(tty, rbuf, wbuf);
defer io::close(tty)!;
- // TODO: Prompt before overwriting existing secstore
+ match (secstore::open()) {
+ case let store: secstore::secstore =>
+ secstore::close(&store);
+ fmt::error("A himitsu secstore already exists. Do you want to overwrite it? [y/N]: ")!;
+ const answer = match (bufio::scanline(tty)!) {
+ case let buf: []u8 =>
+ yield buf;
+ case io::EOF =>
+ fmt::fatal("Skipping secstore initialization.");
+ };
+ defer free(answer);
+ const answer = strings::fromutf8(answer)!;
+ if (ascii::strcasecmp(answer, "y") != 0 && ascii::strcasecmp(answer, "yes") != 0) {
+ fmt::fatal("Skipping secstore initialization.");
+ };
+ case => yield;
+ };
+
+ tty::noecho(&termios)!;
+
fmt::errorln("Initializing a new himitsu secstore.")!;
fmt::error("Please enter a passphrase: ")!;
const pass1 = match (bufio::scanline(tty)!) {
--
2.40.0
CC'ing apreiml on this since they've pushed commit 5a4df343 to
himitsu and this patch does pretty much the same thing.
On 5/5/23 05:09, sam@samnystrom.dev wrote:
> CC'ing apreiml on this since they've pushed commit 5a4df343 to
> himitsu and this patch does pretty much the same thing.
Sorry, I've overlooked that one. If you want to rebase, we can use your
variant. But I think it should only continue on errors::noentry. And
it's probably better to remove the himitsu dir before creating a new
one, since otherwise the secret files of the previous store will be
orphaned.
Sure, I'll send a v4 patch later today.