diff cmd.c @ 18:1e39a251cbe9

Use libtecla for interactive input
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Thu, 24 Aug 2017 13:10:56 +0200
parents a08ef0674d8e
children 5c6155c8e9b6
line wrap: on
line diff
--- a/cmd.c	Sat Aug 12 10:41:52 2017 +0200
+++ b/cmd.c	Thu Aug 24 13:10:56 2017 +0200
@@ -29,9 +29,6 @@
 #endif /* HAVE_ERR_H */
 #include <errno.h>
 #include <limits.h>
-#ifdef	HAVE_READPASSPHRASE_H
-#include <readpassphrase.h>
-#endif /* READPASSPHRASE_H */
 #include <regex.h>
 #include <stdlib.h>
 #include <string.h>
@@ -860,43 +857,24 @@
 static enum cmd_return
 cmd_changepassword(struct pwm_ctx *ctx, int argc, char *argv[])
 {
-	size_t	password_len;
-	char	password_buf[PWS3_MAX_PASSWORD_LEN + 1];
-	char	confirm_buf[PWS3_MAX_PASSWORD_LEN + 1];
+	size_t	len;
 
 	if (argc > 2) {
 		return (CMD_USAGE);
 	} else if (argc == 2) {
-		password_len = strlen(argv[1]);
-		if (password_len == 0) {
+		len = strlen(argv[1]);
+		if (len == 0) {
 			pwm_err(ctx, "password must not be empty");
 			return (CMD_ERR);
-		} else if (password_len + 1 > sizeof (ctx->password)) {
+		} else if (len + 1 > sizeof (ctx->password)) {
 			pwm_err(ctx, "password too long");
 			return (CMD_ERR);
 		}
-		memcpy(ctx->password, argv[1], password_len + 1);
+		memcpy(ctx->password, argv[1], len + 1);
 	} else {
-		if (readpassphrase("Enter password: ", password_buf,
-		    sizeof (password_buf), RPP_ECHO_OFF | RPP_REQUIRE_TTY) ==
-		    NULL) {
-			err(1, "readpassphrase");
-		}
-		password_len = strlen(password_buf);
-		if (password_len == 0) {
-			pwm_err(ctx, "password must not be empty");
+		if (pwm_read_password(ctx, 1) != 0) {
 			return (CMD_ERR);
 		}
-		if (readpassphrase("Confirm password: ", confirm_buf,
-		    sizeof (confirm_buf),
-		    RPP_ECHO_OFF | RPP_REQUIRE_TTY) == NULL) {
-			err(1, "readpassphrase");
-		}
-		if (strcmp(password_buf, confirm_buf) != 0) {
-			pwm_err(ctx, "passwords do not match");
-			return (CMD_ERR);
-		}
-		memcpy(ctx->password, password_buf, password_len + 1);
 	}
 
 	return (CMD_OK);