dav/main.c

changeset 731
e0358fa1a3b1
parent 728
35a421f441d5
child 732
b0eb645cd26e
equal deleted inserted replaced
730:83f832e345e0 731:e0358fa1a3b1
464 static int decrypt_secrets(CmdArgs *a, PwdStore *secrets) { 464 static int decrypt_secrets(CmdArgs *a, PwdStore *secrets) {
465 if(cmd_getoption(a, "noinput")) { 465 if(cmd_getoption(a, "noinput")) {
466 return 1; 466 return 1;
467 } 467 }
468 468
469 char *ps_password = util_password_input("Master password: "); 469 char *ps_password = NULL;
470 if(secrets->unlock_cmd && strlen(secrets->unlock_cmd) > 0) {
471 UcxBuffer *cmd_out = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
472 if(!util_exec_command(secrets->unlock_cmd, cmd_out)) {
473 // command successful, get first line from output without newline
474 // and use that as password for the secretstore
475 size_t len = 0;
476 for(size_t i=0;i<=cmd_out->size;i++) {
477 if(i == cmd_out->size || cmd_out->space[i] == '\n') {
478 len = i;
479 break;
480 }
481 }
482 if(len > 0) {
483 ps_password = malloc(len + 1);
484 memcpy(ps_password, cmd_out->space, len);
485 ps_password[len] = 0;
486 }
487 }
488 ucx_buffer_free(cmd_out);
489 }
490
470 if(!ps_password) { 491 if(!ps_password) {
471 return 1; 492 ps_password = util_password_input("Master password: ");
472 } 493 if(!ps_password) {
494 return 1;
495 }
496 }
497
473 if(pwdstore_setpassword(secrets, ps_password)) { 498 if(pwdstore_setpassword(secrets, ps_password)) {
474 fprintf(stderr, "Error: cannot create key from password\n"); 499 fprintf(stderr, "Error: cannot create key from password\n");
475 return 1; 500 return 1;
476 } 501 }
477 if(pwdstore_decrypt(secrets)) { 502 if(pwdstore_decrypt(secrets)) {

mercurial