user: Improve password length handling

No longer truncate passwords (16 < p <= 20) silently, instead attempt
to set a 20-char password when such a password is given.
Fail if an explicit length is exceeded, and any time the upper limit
is exceeded.
This commit is contained in:
G Dutton 2019-09-02 21:51:11 +01:00 committed by Alexander Amelkin
parent af062a9a5e
commit 51a2ab8180

View File

@ -657,22 +657,23 @@ ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv)
} }
} else { } else {
password = argv[3]; password = argv[3];
}
if (argc > 4) { if (argc > 4) {
if ((str2uchar(argv[4], &password_type) != 0) if ((str2uchar(argv[4], &password_type) != 0)
|| (password_type != 16 && password_type != 20)) { || (password_type != 16 && password_type != 20)) {
lprintf(LOG_ERR, "Invalid password length '%s'", argv[4]); lprintf(LOG_ERR, "Invalid password length '%s'", argv[4]);
return (-1); return (-1);
} }
} else { } else if (strlen(password) > 16) {
password_type = 16; password_type = 20;
}
} }
if (!password) { if (!password) {
lprintf(LOG_ERR, "Unable to parse password argument."); lprintf(LOG_ERR, "Unable to parse password argument.");
return (-1); return (-1);
} else if (strlen(password) > 20) { } else if (strlen(password) > password_type) {
lprintf(LOG_ERR, "Password is too long (> 20 bytes)"); lprintf(LOG_ERR, "Password is too long (> %d bytes)", password_type);
return (-1); return (-1);
} }