Added MAX_UID.

This commit is contained in:
Johannes Findeisen 2024-08-17 22:00:58 +02:00
commit 10d8447d30
2 changed files with 8 additions and 4 deletions

View file

@ -1,4 +1,4 @@
# checkpw - 1.0!
# checkpw - 1.0.1!
checkpw is a program that checks the validity of a users password on a Linux/PAM-based system.

View file

@ -29,6 +29,10 @@
#define MAX_USERNAME_LEN 32
#define MAX_PASSWORD_LEN 256
#ifndef MAX_UID
#define MAX_UID 1000
#endif
#ifndef MIN_UID
#define MIN_UID 1000
#endif
@ -238,9 +242,9 @@ int main(int argc, char *argv[]) {
exit(1);
}
// Check if the user's UID is below the minimum allowed UID
if (pwd->pw_uid < MIN_UID) {
fprintf(stderr, "Error: User '%s' has a UID less than %d and is not allowed to authenticate.\n", username, MIN_UID);
// Check if the user's UID is below the minimum allowed UID and not higher than maximum allowed UID
if (pwd->pw_uid < MIN_UID || pwd->pw_uid > MAX_UID) {
fprintf(stderr, "Error: User '%s' has a UID less than %d or higher than %d and is not allowed to authenticate.\n", username, MIN_UID, MAX_UID);
exit(1);
}