From aea6650cfca5836ab52b48de9f141c2d1a93c8ab Mon Sep 17 00:00:00 2001 From: Marco d'Itri Date: Tue, 31 Dec 2019 02:36:51 +0100 Subject: [PATCH] mkpasswd: support raw $salt$ prefixes If the salt provided to the program starts with '$' then it will be passed straight to crypt(3) without any checks. --- mkpasswd.1 | 7 +++++-- mkpasswd.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mkpasswd.1 b/mkpasswd.1 index 06ab223..e35fac4 100644 --- a/mkpasswd.1 +++ b/mkpasswd.1 @@ -16,8 +16,11 @@ libc function, using the given salt. .BI \-\-salt= STRING Use the .I STRING -as salt. It must not contain prefixes such as -.IR $1$ . +as salt. If it begins with +.I $ +then it will be passed straight to +.BR crypt (3) +without any checks. .TP .BR \-R ", "\c .BI \-\-rounds= NUMBER diff --git a/mkpasswd.c b/mkpasswd.c index 6b98a1f..9d05786 100644 --- a/mkpasswd.c +++ b/mkpasswd.c @@ -282,7 +282,9 @@ int main(int argc, char *argv[]) else rounds_str[0] = '\0'; - if (salt_arg && salt_arg[0] != '\0') { + if (salt_arg && salt_arg[0] == '$') + salt = NOFAIL(strdup(salt_arg)); + else if (salt_arg && salt_arg[0] != '\0') { unsigned int c = strlen(salt_arg); if (c < salt_minlen || c > salt_maxlen) { if (salt_minlen == salt_maxlen)