diff -r 83f832e345e0 -r e0358fa1a3b1 dav/main.c --- a/dav/main.c Sun Aug 08 11:45:36 2021 +0200 +++ b/dav/main.c Sun Aug 08 12:45:31 2021 +0200 @@ -466,10 +466,35 @@ return 1; } - char *ps_password = util_password_input("Master password: "); + char *ps_password = NULL; + if(secrets->unlock_cmd && strlen(secrets->unlock_cmd) > 0) { + UcxBuffer *cmd_out = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); + if(!util_exec_command(secrets->unlock_cmd, cmd_out)) { + // command successful, get first line from output without newline + // and use that as password for the secretstore + size_t len = 0; + for(size_t i=0;i<=cmd_out->size;i++) { + if(i == cmd_out->size || cmd_out->space[i] == '\n') { + len = i; + break; + } + } + if(len > 0) { + ps_password = malloc(len + 1); + memcpy(ps_password, cmd_out->space, len); + ps_password[len] = 0; + } + } + ucx_buffer_free(cmd_out); + } + if(!ps_password) { - return 1; + ps_password = util_password_input("Master password: "); + if(!ps_password) { + return 1; + } } + if(pwdstore_setpassword(secrets, ps_password)) { fprintf(stderr, "Error: cannot create key from password\n"); return 1;