From 10d8447d301d880bd2dd9ad8d76560039aff5b03 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sat, 17 Aug 2024 22:00:58 +0200 Subject: [PATCH] Added MAX_UID. --- README.md | 2 +- checkpw.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49d5edf..b0cbede 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/checkpw.c b/checkpw.c index 793d989..29b0206 100644 --- a/checkpw.c +++ b/checkpw.c @@ -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); }