unet-tool: add support for confirming password
authorFelix Fietkau <nbd@nbd.name>
Mon, 16 Dec 2024 12:41:41 +0000 (13:41 +0100)
committerFelix Fietkau <nbd@nbd.name>
Mon, 16 Dec 2024 12:41:41 +0000 (13:41 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
cli.c

diff --git a/cli.c b/cli.c
index e7235ee739ae0126d0f24b4f1e952710eb58bab0..fcf9755854d8a57b3003a43f0d5beef6c2e51d4e 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -38,7 +38,7 @@ static FILE *out_file;
 static bool quiet;
 static bool sync_done;
 static bool has_key;
-static bool password_prompt;
+static int password_prompt;
 static enum {
        CMD_UNKNOWN,
        CMD_GENERATE,
@@ -539,9 +539,20 @@ static bool parse_seed(uint8_t *dest, const char *salt)
        }
 
        if (password_prompt) {
+               char *pw2;
+
                pw = getpass("Password: ");
                if (pw)
                        len = strlen(pw);
+
+               if (pw && password_prompt > 1) {
+                       pw = strcpy(buf, pw);
+                       pw2 = getpass("Retype password: ");
+                       if (!pw2 || strcmp(pw, pw2) != 0) {
+                               INFO("Passwords do not match\n");
+                               return false;
+                       }
+               }
        } else {
                len = fread(buf, 1, sizeof(buf), stdin);
                if (!feof(stdin)) {
@@ -685,7 +696,7 @@ int main(int argc, char **argv)
                        has_pubkey = true;
                        break;
                case 'p':
-                       password_prompt = true;
+                       password_prompt++;
                        break;
                case 'b':
                        if (load_network_data(optarg))