aboutsummaryrefslogtreecommitdiffstats
path: root/src/encpipe.c
diff options
context:
space:
mode:
authorGravatar Frank Denis <github@pureftpd.org>2025-02-10 00:45:45 +0100
committerGravatar Frank Denis <github@pureftpd.org>2025-02-10 00:45:45 +0100
commit7a3ba4bbee98b81e44617c10d5727992dbd13e12 (patch)
tree625ae166cb0968c258ba776a257a67d2371443c2 /src/encpipe.c
parente598ed628a54abc94215f4e8dd130e33fade63fe (diff)
downloadtweetpipe-7a3ba4bbee98b81e44617c10d5727992dbd13e12.tar.gz
Read password from the terminal if none was provided
Diffstat (limited to 'src/encpipe.c')
-rw-r--r--src/encpipe.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/encpipe.c b/src/encpipe.c
index 735ed87..7a2b8ff 100644
--- a/src/encpipe.c
+++ b/src/encpipe.c
@@ -172,6 +172,26 @@ read_password_file(Context *ctx, const char *file)
}
static void
+read_password_from_terminal(Context *ctx)
+{
+ char password[512];
+ char *p;
+
+ printf("Password: ");
+ fflush(stdout);
+ if (fgets(password, sizeof password, stdin) == NULL) {
+ die(1, "fgets()");
+ }
+ if ((p = strchr(password, '\r')) != NULL) {
+ *p = 0;
+ }
+ if ((p = strchr(password, '\n')) != NULL) {
+ *p = 0;
+ }
+ derive_key(ctx, password, strlen(password));
+}
+
+static void
passgen(void)
{
unsigned char password[32];
@@ -209,7 +229,7 @@ options_parse(Context *ctx, int argc, char *argv[])
break;
case 'G':
passgen();
- break;
+ break; /* NOTREACHED */
case 'i':
ctx->in = optarg;
break;
@@ -226,9 +246,12 @@ options_parse(Context *ctx, int argc, char *argv[])
usage();
}
}
- if (ctx->has_key == 0 || ctx->encrypt == -1) {
+ if (ctx->encrypt == -1) {
usage();
}
+ if (ctx->has_key == 0) {
+ read_password_from_terminal(ctx);
+ }
}
int