From 05c68ae9f070c3c95d29aac9c673f82642a044b7 Mon Sep 17 00:00:00 2001 From: Marco d'Itri Date: Thu, 6 Jan 2022 16:09:42 +0100 Subject: [PATCH] mkpasswd: add some comments --- mkpasswd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mkpasswd.c b/mkpasswd.c index 5a6a10c..8c9bd00 100644 --- a/mkpasswd.c +++ b/mkpasswd.c @@ -283,8 +283,10 @@ int main(int argc, char *argv[]) rounds_str[0] = '\0'; if (salt_arg && salt_arg[0] == '$') + /* the salt begins with the prefix which specifies the method */ salt = NOFAIL(strdup(salt_arg)); else if (salt_prefix && salt_arg && strchr(salt_arg, '$')) { + /* looks like a salt, but with no initial method prefix */ salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str) + strlen(salt_arg) + 1)); *salt = '\0'; @@ -292,6 +294,7 @@ int main(int argc, char *argv[]) strcat(salt, rounds_str); strcat(salt, salt_arg); } else if (salt_arg && salt_arg[0] != '\0') { + /* just the salt string with no metadata */ unsigned int c = strlen(salt_arg); if (c < salt_minlen || c > salt_maxlen) { if (salt_minlen == salt_maxlen) @@ -316,6 +319,10 @@ int main(int argc, char *argv[]) } } + /* + * Build the actual argument to crypt(3) by concatenating the + * method prefix, the rounds metadata (if any) and the salt string. + */ salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str) + strlen(salt_arg) + 1)); *salt = '\0'; @@ -323,6 +330,7 @@ int main(int argc, char *argv[]) strcat(salt, rounds_str); strcat(salt, salt_arg); } else { + /* no salt was specified by the user, so generate one */ #ifdef HAVE_SOLARIS_CRYPT_GENSALT salt = crypt_gensalt(salt_prefix, NULL); if (!salt) {