{
char salt[MAX_PW_SALT_LEN];
char *salt_ptr;
+ char *password;
const char *opt_m, *opt_S;
int fd;
applet_long_options = mkpasswd_longopts;
#endif
fd = STDIN_FILENO;
- opt_m = "d";
+ opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
opt_S = NULL;
/* at most two non-option arguments; -P NUM */
opt_complementary = "?2:P+";
xmove_fd(fd, STDIN_FILENO);
- puts(pw_encrypt(
- argv[0] ? argv[0] : (
- /* Only mkpasswd, and only from tty, prompts.
- * Otherwise it is a plain read. */
- (isatty(STDIN_FILENO) && applet_name[0] == 'm')
+ password = argv[0];
+ if (!password) {
+ /* Only mkpasswd, and only from tty, prompts.
+ * Otherwise it is a plain read. */
+ password = (isatty(STDIN_FILENO) && applet_name[0] == 'm')
? bb_ask_stdin("Password: ")
: xmalloc_fgetline(stdin)
- ),
- salt, 1));
+ ;
+ /* may still be NULL on EOF/error */
+ }
+
+ if (password)
+ puts(pw_encrypt(password, salt, 1));
return EXIT_SUCCESS;
}