From a1f63c428cfaf6a00cfec66b9f2b127f652be4fc Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 28 Aug 2024 02:05:27 +0200 Subject: [PATCH 01/67] Added -V to show the program version. Updated to 1.0.3. --- README.md | 2 +- checkpw.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a5b758a..2119d53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# checkpw - 1.0.2! +# checkpw 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 e8c11ac..9da39ee 100644 --- a/checkpw.c +++ b/checkpw.c @@ -2,19 +2,7 @@ * checkpw is a program that checks the validity of a users password on a * Linux/PAM-based system. * - * Usage: checkpw [-u ] [-p ] [-i] [-v] [-h] - * - * Options: - * -u Specify username. - * -p Specify password. - * -i Enable interactive mode to prompt for missing username/password. - * -v Enable verbose mode. - * -h Show this help. - * - * Returns 0 on success, 1 otherwise. - * - * Author: Johannes Findeisen - * Version: 1.0.2 + * Author: Johannes Findeisen - 2024 * License: MIT (see LICENSE) */ @@ -39,6 +27,8 @@ #define MIN_UID 1000 #endif +#define VERSION 1_0_3 + // Custom data structure to hold user-entered password struct pam_credentials { const char *password; @@ -169,18 +159,20 @@ void print_usage(const char *prog_name) { fprintf(stderr, " -p Specify password.\n"); fprintf(stderr, " -i Enable interactive mode to prompt for missing username/password.\n"); fprintf(stderr, " -v Enable verbose mode.\n"); + fprintf(stderr, " -V Show version.\n"); fprintf(stderr, " -h Show this help.\n"); } int main(int argc, char *argv[]) { bool interactive = false; bool verbose = false; + bool version = false; char username[MAX_USERNAME_LEN] = {0}; char password[MAX_PASSWORD_LEN] = {0}; int opt; // Parse command-line arguments - while ((opt = getopt(argc, argv, "u:p:hiv")) != -1) { + while ((opt = getopt(argc, argv, "u:p:hivV")) != -1) { switch (opt) { case 'u': if (strlen(optarg) >= MAX_USERNAME_LEN) { @@ -205,12 +197,20 @@ int main(int argc, char *argv[]) { case 'v': verbose = true; break; + case 'V': + version = true; + break; default: print_usage(argv[0]); exit(1); } } + if (version) { + printf("1.0.3\n"); + exit(0); + } + // If interactive mode is enabled, prompt for missing username and/or password if (interactive) { if (username[0] == '\0') { From f0b23529757f2db66b18bbe09ab51da27d166616 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 28 Aug 2024 02:09:30 +0200 Subject: [PATCH 02/67] Mirror to GitHub repo fix. --- README.md | 1 + checkpw.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2119d53..7ac0016 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Options: -p Specify password. -i Enable interactive mode to prompt for missing username/password. -v Enable verbose mode. + -v Show program version. -h Show this help. ``` diff --git a/checkpw.c b/checkpw.c index 9da39ee..d54d23e 100644 --- a/checkpw.c +++ b/checkpw.c @@ -159,7 +159,7 @@ void print_usage(const char *prog_name) { fprintf(stderr, " -p Specify password.\n"); fprintf(stderr, " -i Enable interactive mode to prompt for missing username/password.\n"); fprintf(stderr, " -v Enable verbose mode.\n"); - fprintf(stderr, " -V Show version.\n"); + fprintf(stderr, " -V Show program version.\n"); fprintf(stderr, " -h Show this help.\n"); } From 689d1cbe181c21b4bb234fe25634bc88f516c9c2 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 28 Aug 2024 02:24:15 +0200 Subject: [PATCH 03/67] README fix. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ac0016..4ab7209 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Exactly a program like this... not more! **WARNING:** Install this software with care. checkpw could easily be used for bruteforcing passwords from local users! ``` -git clone https://git.xw3.org/hanez/checkpw.git +git clone https://git.xw3.org/xw3/checkpw.git cd checkpw make sudo make install From 4efe3efa96084b9133a8d5cfe62eb5fcb02e87b3 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 28 Aug 2024 18:16:59 +0200 Subject: [PATCH 04/67] README update. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ab7209..d8bbce9 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ sudo make install The code only supports verifying passwords for user id 1000 by default. Look a the code for some compile time options! +### Manual installation: + Set MAX_UID and MIN_UID in the code or you can compile checkpw without editing the code using the following command and install it manually: ``` @@ -45,7 +47,7 @@ Options: -p Specify password. -i Enable interactive mode to prompt for missing username/password. -v Enable verbose mode. - -v Show program version. + -V Show program version. -h Show this help. ``` From e7b7397c933beb34c757aa9c1190c04f534cb6f6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 28 Aug 2024 18:18:57 +0200 Subject: [PATCH 05/67] Changed -Werror to -Wall in Makefile and README.md. --- Makefile | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9854825..229ff1c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - $(CC) -Werror -o checkpw checkpw.c -lpam -lpam_misc + $(CC) -Wall -o checkpw checkpw.c -lpam -lpam_misc clean: rm -f ./checkpw diff --git a/README.md b/README.md index d8bbce9..e5f8a5a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The code only supports verifying passwords for user id 1000 by default. Look a t Set MAX_UID and MIN_UID in the code or you can compile checkpw without editing the code using the following command and install it manually: ``` -gcc -Werror -DMAX_UID=1000 -DMIN_UID=1000 -o checkpw checkpw.c -lpam -lpam_misc +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o checkpw checkpw.c -lpam -lpam_misc sudo cp ./checkpw /usr/bin/ ``` From 1ee8e07b0a9bd9555c86fb82115d98e9c9cc3054 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Sep 2024 04:48:06 +0200 Subject: [PATCH 06/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5f8a5a..66ce0f6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # checkpw -checkpw is a program that checks the validity of a users password on a Linux/PAM-based system. +checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. ## The idea behind: From 7ffe30647bc08e93792900843c37609814c54dd5 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Sep 2024 04:50:29 +0200 Subject: [PATCH 07/67] README update. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 66ce0f6..fc71748 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. +Currently only tested on Linux, but it should work on the AIX operating system, DragonFly BSD, FreeBSD, HP-UX, Linux, macOS, NetBSD and Solaris. + ## The idea behind: I needed a program to verify passwords of users on Linux based systems using PAM. From 60919c1ca8bf5d19db79bcbf608b51e284e46534 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 25 Sep 2024 06:30:21 +0200 Subject: [PATCH 08/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc71748..56a8c24 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. -Currently only tested on Linux, but it should work on the AIX operating system, DragonFly BSD, FreeBSD, HP-UX, Linux, macOS, NetBSD and Solaris. +Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX){:class="ext" target="_blank"}, [DragonFly BSD](https://www.dragonflybsd.org/){:class="ext" target="_blank"}, [FreeBSD](https://www.freebsd.org/){:class="ext" target="_blank"}, [HP-UX](https://en.wikipedia.org/wiki/HP-UX){:class="ext" target="_blank"}, [Linux](https://kernel.org/){:class="ext" target="_blank"}, [macOS](https://en.wikipedia.org/wiki/MacOS){:class="ext" target="_blank"}, [NetBSD](https://netbsd.org/){:class="ext" target="_blank"} and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris){:class="ext" target="_blank"} operating system too. I will test API compatibility for all OS's soon... ;) ## The idea behind: From 04ad31fb2e6e1c1d5a424f7bd377e1eae29a26dd Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 25 Sep 2024 06:31:16 +0200 Subject: [PATCH 09/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56a8c24..3c819e4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. -Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX){:class="ext" target="_blank"}, [DragonFly BSD](https://www.dragonflybsd.org/){:class="ext" target="_blank"}, [FreeBSD](https://www.freebsd.org/){:class="ext" target="_blank"}, [HP-UX](https://en.wikipedia.org/wiki/HP-UX){:class="ext" target="_blank"}, [Linux](https://kernel.org/){:class="ext" target="_blank"}, [macOS](https://en.wikipedia.org/wiki/MacOS){:class="ext" target="_blank"}, [NetBSD](https://netbsd.org/){:class="ext" target="_blank"} and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris){:class="ext" target="_blank"} operating system too. I will test API compatibility for all OS's soon... ;) +Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. I will test API compatibility for all OS's soon... ;) ## The idea behind: From 2cc879245238f4c81f0fd27375e6314107bb8e78 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 25 Sep 2024 23:09:41 +0200 Subject: [PATCH 10/67] README update. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3c819e4..c5f66f6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM- Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. I will test API compatibility for all OS's soon... ;) +HELP! I need some people porting or helping me porting this to other OS's than Linux. AFAIK it should compile on listed OS's above and should then work, but I don't know how... + ## The idea behind: I needed a program to verify passwords of users on Linux based systems using PAM. From 7b0d7ce7a77a2a0f600fb65af9a2e4c8cf589a09 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 26 Sep 2024 00:26:34 +0200 Subject: [PATCH 11/67] Fix applied. --- checkpw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/checkpw.c b/checkpw.c index d54d23e..fd5b2ff 100644 --- a/checkpw.c +++ b/checkpw.c @@ -36,7 +36,8 @@ struct pam_credentials { // PAM conversation function to supply the password int pam_conversation(int num_msg, const struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) { + struct pam_response **resp, void *appdata_ptr) +{ struct pam_response *response = NULL; struct pam_credentials *credentials = (struct pam_credentials *)appdata_ptr; int i; From a771e28f3b3840c0215fd05d7c7bbadf88f349f0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 29 Oct 2024 06:36:16 +0100 Subject: [PATCH 12/67] Added some newlines to help output. --- checkpw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/checkpw.c b/checkpw.c index fd5b2ff..bb3587b 100644 --- a/checkpw.c +++ b/checkpw.c @@ -154,7 +154,9 @@ void prompt_for_input(char *buffer, size_t size, const char *prompt, int hide_in } void print_usage(const char *prog_name) { + fprintf(stderr, "\n"); fprintf(stderr, "Usage: %s [-u ] [-p ] [-i] [-v] [-h]\n", prog_name); + fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " -u Specify username.\n"); fprintf(stderr, " -p Specify password.\n"); @@ -162,6 +164,7 @@ void print_usage(const char *prog_name) { fprintf(stderr, " -v Enable verbose mode.\n"); fprintf(stderr, " -V Show program version.\n"); fprintf(stderr, " -h Show this help.\n"); + fprintf(stderr, "\n"); } int main(int argc, char *argv[]) { From 97d9abd6c1cc5b5f527c71ea508f45ef575af653 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 29 Oct 2024 06:45:35 +0100 Subject: [PATCH 13/67] Some code-style fixes. --- checkpw.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/checkpw.c b/checkpw.c index bb3587b..ffdf126 100644 --- a/checkpw.c +++ b/checkpw.c @@ -63,7 +63,8 @@ int pam_conversation(int num_msg, const struct pam_message **msg, return PAM_SUCCESS; } -int authenticate(const char *username, const char *password, int verbose) { +int authenticate(const char *username, const char *password, int verbose) +{ int retval; pam_handle_t *pamh = NULL; struct pam_credentials credentials = { password }; @@ -110,7 +111,8 @@ int authenticate(const char *username, const char *password, int verbose) { } // Function to prompt user for input, optionally hiding input -void prompt_for_input(char *buffer, size_t size, const char *prompt, int hide_input) { +void prompt_for_input(char *buffer, size_t size, const char *prompt, int hide_input) +{ printf("%s", prompt); fflush(stdout); @@ -153,7 +155,8 @@ void prompt_for_input(char *buffer, size_t size, const char *prompt, int hide_in } } -void print_usage(const char *prog_name) { +void print_usage(const char *prog_name) +{ fprintf(stderr, "\n"); fprintf(stderr, "Usage: %s [-u ] [-p ] [-i] [-v] [-h]\n", prog_name); fprintf(stderr, "\n"); @@ -167,7 +170,8 @@ void print_usage(const char *prog_name) { fprintf(stderr, "\n"); } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ bool interactive = false; bool verbose = false; bool version = false; From 5bd3572c7584b4d444b737a366caf2419edf222c Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 12 Dec 2024 00:17:22 +0100 Subject: [PATCH 14/67] Code style fixes. --- checkpw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/checkpw.c b/checkpw.c index ffdf126..4acbd99 100644 --- a/checkpw.c +++ b/checkpw.c @@ -30,7 +30,8 @@ #define VERSION 1_0_3 // Custom data structure to hold user-entered password -struct pam_credentials { +struct pam_credentials +{ const char *password; }; @@ -63,7 +64,7 @@ int pam_conversation(int num_msg, const struct pam_message **msg, return PAM_SUCCESS; } -int authenticate(const char *username, const char *password, int verbose) +int authenticate(const char *username, const char *password, int verbose) { int retval; pam_handle_t *pamh = NULL; @@ -111,7 +112,8 @@ int authenticate(const char *username, const char *password, int verbose) } // Function to prompt user for input, optionally hiding input -void prompt_for_input(char *buffer, size_t size, const char *prompt, int hide_input) +void prompt_for_input(char *buffer, size_t size, const char *prompt, + int hide_input) { printf("%s", prompt); fflush(stdout); From 70550ffa7ff21b23436d3b7c291215fdb1beb57b Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 12 Dec 2024 00:20:22 +0100 Subject: [PATCH 15/67] README update. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index c5f66f6..9a6e7d1 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. -Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. I will test API compatibility for all OS's soon... ;) - -HELP! I need some people porting or helping me porting this to other OS's than Linux. AFAIK it should compile on listed OS's above and should then work, but I don't know how... +Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. ## The idea behind: From 6f859b18b23540bd86ae03db212a066da56dfa2e Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Dec 2024 00:40:01 +0100 Subject: [PATCH 16/67] License change from MIT to Apache-2.0. --- LICENSE | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index 6e58503..0c72923 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,13 @@ -MIT License +Copyright 2024 Johannes Findeisen -Copyright (c) 2024 hanez +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + http://www.apache.org/licenses/LICENSE-2.0 -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. From 82aced57b6606aa6560f069617443eba323e6aa4 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 06:23:03 +0100 Subject: [PATCH 17/67] Removed interactive mode (is default now), moved some code to checkpw.h and many fixes. --- LICENSE | 2 +- Makefile | 2 + README.md | 68 +++++++++++-------- checkpw.c | 191 ++++++++++++------------------------------------------ checkpw.h | 121 ++++++++++++++++++++++++++++++++++ 5 files changed, 206 insertions(+), 178 deletions(-) create mode 100644 checkpw.h diff --git a/LICENSE b/LICENSE index 0c72923..247aa29 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2024 Johannes Findeisen +Copyright 2024 Johannes Findeisen Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 229ff1c..6b1f110 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,9 @@ clean: install: cp ./checkpw /usr/bin/ + cp ./checkpw.h /usr/include/ uninstall: rm -f /usr/bin/checkpw + rm -f /usr/include/checkpw.h diff --git a/README.md b/README.md index 9a6e7d1..2f53c6a 100644 --- a/README.md +++ b/README.md @@ -4,84 +4,96 @@ checkpw is a program that checks the validity of a users password on a UNIX/PAM- Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. -## The idea behind: +## The idea -I needed a program to verify passwords of users on Linux based systems using PAM. +I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just return 0 on success and 1 on error. -Exactly a program like this... not more! - -## Installation: - -**WARNING:** Install this software with care. checkpw could easily be used for bruteforcing passwords from local users! +## Building checkpw ``` git clone https://git.xw3.org/xw3/checkpw.git cd checkpw make -sudo make install ``` -The code only supports verifying passwords for user id 1000 by default. Look a the code for some compile time options! +The code only supports verifying passwords for user id 1000 by default. Look at the file checkpw.h for some compile time options! -### Manual installation: +### Custom build example -Set MAX_UID and MIN_UID in the code or you can compile checkpw without editing the code using the following command and install it manually: +Set MAX_UID and MIN_UID at compile time: ``` gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o checkpw checkpw.c -lpam -lpam_misc -sudo cp ./checkpw /usr/bin/ ``` -## Uninstall: +## Installation + +**WARNING:** Install this software with care. checkpw could easily be used for bruteforcing passwords from local users! + +``` +sudo make install +``` + +checkpw is installed to /usr/bin/. + +checkpw.h is installed to /usr/include/ for use in other applications. + +## Uninstall ``` sudo make uninstall ``` -## Usage: +## Usage ``` checkpw -h -Usage: checkpw [-u ] [-p ] [-i] [-v] [-h] +Usage: checkpw [-u ] [-p ] [-v] [-V] [-h] Options: -u Specify username. -p Specify password. - -i Enable interactive mode to prompt for missing username/password. -v Enable verbose mode. - -V Show program version. + -V Print program version. -h Show this help. ``` -Returns 0 on success, 1 otherwise. - -### Examples: - -#### Interactive mode: +You can also use checkpw even without installing by just running the following command: ``` -checkpw -i +./checkpk ``` -#### Interactive mode only asking for a password: +checkpw returns 0 on success, 1 otherwise. + +### Examples + + +#### Interactive mode asking for a username and a password ``` -checkpw -u hanez -i +checkpw ``` -#### None interactive mode with username and password provided as arguments to checkpw: +#### Interactive mode only asking for a password + +``` +checkpw -u hanez +``` + +#### None interactive mode with username and password provided as arguments to checkpw ``` checkpw -u hanez -p password ``` -#### Request the result from the above commands: +#### Request the result from the above commands ``` echo $? ``` -## Links: +## Links - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) diff --git a/checkpw.c b/checkpw.c index 4acbd99..847b287 100644 --- a/checkpw.c +++ b/checkpw.c @@ -1,119 +1,23 @@ /** * checkpw is a program that checks the validity of a users password on a - * Linux/PAM-based system. + * UNIX/PAM-based system. * * Author: Johannes Findeisen - 2024 - * License: MIT (see LICENSE) + * License: Apache-2.0 (see LICENSE) */ -#include // For struct passwd and getpwnam -#include -#include #include #include #include #include -#include // For terminal input settings -#include // For getopt and access to user info +#include +#include -#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 - -#define VERSION 1_0_3 - -// Custom data structure to hold user-entered password -struct pam_credentials -{ - const char *password; -}; - -// PAM conversation function to supply the password -int pam_conversation(int num_msg, const struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) -{ - struct pam_response *response = NULL; - struct pam_credentials *credentials = (struct pam_credentials *)appdata_ptr; - int i; - - response = (struct pam_response *)malloc(sizeof(struct pam_response) * num_msg); - if (response == NULL) - return PAM_CONV_ERR; - - for (i = 0; i < num_msg; i++) { - switch (msg[i]->msg_style) { - case PAM_PROMPT_ECHO_ON: - case PAM_PROMPT_ECHO_OFF: - response[i].resp = strdup(credentials->password); - response[i].resp_retcode = 0; - break; - default: - free(response); - return PAM_CONV_ERR; - } - } - - *resp = response; - return PAM_SUCCESS; -} - -int authenticate(const char *username, const char *password, int verbose) -{ - int retval; - pam_handle_t *pamh = NULL; - struct pam_credentials credentials = { password }; - struct pam_conv conv = { pam_conversation, &credentials }; - - if (verbose) - printf("Starting PAM authentication for user '%s'.\n", username); - - retval = pam_start("login", username, &conv, &pamh); - - if (retval == PAM_SUCCESS) { - if (verbose) - printf("PAM authentication initialized.\n"); - retval = pam_authenticate(pamh, 0); // Attempt to authenticate - } else { - if (verbose) - printf("pam_start failed: %s\n", pam_strerror(pamh, retval)); - } - - if (retval == PAM_SUCCESS) { - if (verbose) - printf("User '%s' authenticated successfully.\n", username); - - retval = pam_acct_mgmt(pamh, 0); // Check account validity - if (retval != PAM_SUCCESS && verbose) - printf("pam_acct_mgmt failed: %s\n", pam_strerror(pamh, retval)); - - } else { - if (verbose) - printf("pam_authenticate failed: %s\n", pam_strerror(pamh, retval)); - } - - if (pam_end(pamh, retval) != PAM_SUCCESS) { - pamh = NULL; - fprintf(stderr, "Failed to release PAM authenticator\n"); - exit(1); - } - - if (retval != PAM_SUCCESS && verbose) { - printf("Authentication failed for user '%s'.\n", username); - } - - return (retval == PAM_SUCCESS ? 0 : 1); // 0 for success, 1 for failure -} +#include "checkpw.h" // Function to prompt user for input, optionally hiding input void prompt_for_input(char *buffer, size_t size, const char *prompt, - int hide_input) + bool hide_input) { printf("%s", prompt); fflush(stdout); @@ -159,41 +63,42 @@ void prompt_for_input(char *buffer, size_t size, const char *prompt, void print_usage(const char *prog_name) { - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: %s [-u ] [-p ] [-i] [-v] [-h]\n", prog_name); - fprintf(stderr, "\n"); - fprintf(stderr, "Options:\n"); - fprintf(stderr, " -u Specify username.\n"); - fprintf(stderr, " -p Specify password.\n"); - fprintf(stderr, " -i Enable interactive mode to prompt for missing username/password.\n"); - fprintf(stderr, " -v Enable verbose mode.\n"); - fprintf(stderr, " -V Show program version.\n"); - fprintf(stderr, " -h Show this help.\n"); - fprintf(stderr, "\n"); + printf("\n"); + printf("Usage: %s [-u ] [-p ] [-v] [-V] [-h]\n", + prog_name); + printf("\n"); + printf("Options:\n"); + printf(" -u Set username (if not set, the program asks for it).\n"); + printf(" -p Set password (if not set, the program asks for it).\n"); + printf(" -v Enable verbose mode.\n"); + printf(" -V Print program version.\n"); + printf(" -h Show this help.\n"); + printf("\n"); } int main(int argc, char *argv[]) { - bool interactive = false; bool verbose = false; bool version = false; - char username[MAX_USERNAME_LEN] = {0}; char password[MAX_PASSWORD_LEN] = {0}; + char username[MAX_USERNAME_LEN] = {0}; int opt; // Parse command-line arguments - while ((opt = getopt(argc, argv, "u:p:hivV")) != -1) { + while ((opt = getopt(argc, argv, "u:p:hvV")) != -1) { switch (opt) { case 'u': if (strlen(optarg) >= MAX_USERNAME_LEN) { - fprintf(stderr, "Error: Username is too long (maximum %d characters).\n", MAX_USERNAME_LEN); + fprintf(stderr, "Error: Username is too long (maximum %d characters).\n", + MAX_USERNAME_LEN); exit(1); } strncpy(username, optarg, MAX_USERNAME_LEN - 1); break; case 'p': if (strlen(optarg) >= MAX_PASSWORD_LEN) { - fprintf(stderr, "Error: Password is too long (maximum %d characters).\n", MAX_PASSWORD_LEN); + fprintf(stderr, "Error: Password is too long (maximum %d characters).\n", + MAX_PASSWORD_LEN); exit(1); } strncpy(password, optarg, MAX_PASSWORD_LEN - 1); @@ -201,9 +106,6 @@ int main(int argc, char *argv[]) case 'h': print_usage(argv[0]); exit(0); - case 'i': - interactive = true; - break; case 'v': verbose = true; break; @@ -211,38 +113,27 @@ int main(int argc, char *argv[]) version = true; break; default: - print_usage(argv[0]); - exit(1); + break; } } if (version) { - printf("1.0.3\n"); + printf("%s\n", VERSION); exit(0); } - // If interactive mode is enabled, prompt for missing username and/or password - if (interactive) { - if (username[0] == '\0') { - prompt_for_input(username, sizeof(username), "Username: ", 0); - if (strlen(username) == 0) { - fprintf(stderr, "Error: Username cannot be empty.\n"); - exit(1); - } + if (username[0] == '\0') { + prompt_for_input(username, sizeof(username), "Username: ", false); + if (strlen(username) == 0) { + fprintf(stderr, "Error: Username cannot be empty.\n"); + exit(1); } + } - if (password[0] == '\0') { - prompt_for_input(password, sizeof(password), "Password: ", 1); - if (strlen(password) == 0) { - fprintf(stderr, "Error: Password cannot be empty.\n"); - exit(1); - } - } - } else { - // If not in interactive mode, ensure username and password are provided - if (username[0] == '\0' || password[0] == '\0') { - fprintf(stderr, "Error: Username and password must be provided unless interactive mode is enabled.\n"); - print_usage(argv[0]); + if (password[0] == '\0') { + prompt_for_input(password, sizeof(password), "Password: ", true); + if (strlen(password) == 0) { + fprintf(stderr, "Error: Password cannot be empty.\n"); exit(1); } } @@ -254,17 +145,19 @@ int main(int argc, char *argv[]) exit(1); } - // Check if the user's UID is below the minimum allowed UID and not higher than maximum allowed 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); + fprintf(stderr, "Error: User '%s' has a UID higher than %d or lower than %d and is not allowed to authenticate.\n", + username, MAX_UID, MIN_UID); exit(1); } if (verbose) - printf("User '%s' passed UID check (UID: %d).\n", username, pwd->pw_uid); + printf("User '%s' passed UID check (UID: %d).\n", username, + pwd->pw_uid); - // Authenticate the user - if (authenticate(username, password, verbose) == 0) { + if (authenticate(username, password, verbose) == true) { printf("Authenticated successfully.\n"); return 0; } else { diff --git a/checkpw.h b/checkpw.h new file mode 100644 index 0000000..3620e40 --- /dev/null +++ b/checkpw.h @@ -0,0 +1,121 @@ +/** + * checkpw.h is part of checkpw, a program that checks the validity of a users + * password on a UNIX/PAM-based system. + * + * Author: Johannes Findeisen - 2025 + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include + +#define VERSION "1.1.0" + +#ifndef MAX_PASSWORD_LEN +#define MAX_PASSWORD_LEN 256 +#endif + +#ifndef MAX_USERNAME_LEN +#define MAX_USERNAME_LEN 32 +#endif + +#ifndef MAX_UID +#define MAX_UID 1000 +#endif + +#ifndef MIN_UID +#define MIN_UID 1000 +#endif + +bool authenticate(const char *username, const char *password, bool verbose); + +int pam_conversation(int num_msg, const struct pam_message **msg, + struct pam_response **resp, void *appdata_ptr); + +struct pam_credentials +{ + const char *password; +}; + +bool authenticate(const char *username, const char *password, bool verbose) +{ + int retval; + pam_handle_t *pamh = NULL; + struct pam_credentials credentials = { password }; + struct pam_conv conv = { pam_conversation, &credentials }; + + if (verbose) + printf("Starting PAM authentication for user '%s'.\n", username); + + retval = pam_start("login", username, &conv, &pamh); + + if (retval == PAM_SUCCESS) { + if (verbose) + printf("PAM authentication initialized.\n"); + retval = pam_authenticate(pamh, 0); // Attempt to authenticate + } else { + if (verbose) + fprintf(stderr, "Error: pam_start failed: %s\n", pam_strerror(pamh, + retval)); + } + + if (retval == PAM_SUCCESS) { + if (verbose) + printf("User '%s' authenticated successfully.\n", username); + + retval = pam_acct_mgmt(pamh, 0); // Check account validity + if (retval != PAM_SUCCESS && verbose) + fprintf(stderr, "Error: pam_acct_mgmt failed: %s\n", + pam_strerror(pamh, retval)); + } else { + if (verbose) + fprintf(stderr, "Error: pam_authenticate failed: %s\n", + pam_strerror(pamh, retval)); + } + + if (pam_end(pamh, retval) != PAM_SUCCESS) { + pamh = NULL; + fprintf(stderr, "Error: Failed to release PAM authenticator.\n"); + exit(1); + } + + if (retval != PAM_SUCCESS && verbose) { + fprintf(stderr, "Error: Authentication failed for user '%s'.\n", + username); + } + + return (retval == PAM_SUCCESS ? true : false); +} + +// PAM conversation function to supply the password +int pam_conversation(int num_msg, const struct pam_message **msg, + struct pam_response **resp, void *appdata_ptr) +{ + struct pam_response *response = NULL; + struct pam_credentials *credentials = (struct pam_credentials *)appdata_ptr; + int i; + + response = (struct pam_response *)malloc(sizeof(struct pam_response) + * num_msg); + + if (response == NULL) + return PAM_CONV_ERR; + + for (i = 0; i < num_msg; i++) { + switch (msg[i]->msg_style) { + case PAM_PROMPT_ECHO_ON: + case PAM_PROMPT_ECHO_OFF: + response[i].resp = strdup(credentials->password); + response[i].resp_retcode = 0; + break; + default: + free(response); + return PAM_CONV_ERR; + } + } + + *resp = response; + return PAM_SUCCESS; +} + From d7780a2d41ad633c1fc99fbb8a020703652217fd Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 06:43:23 +0100 Subject: [PATCH 18/67] Added license to README. --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 2f53c6a..bac0031 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,23 @@ checkpw -u hanez -p password echo $? ``` +## License + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + ## Links + - [Homepage of checkpw](https://git.xw3.org/xw3/checkpw) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) From 6ee75766b093824c9ec747b71da0a3eab04b62ca Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 06:46:29 +0100 Subject: [PATCH 19/67] README update. --- README.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bac0031..0ebac51 100644 --- a/README.md +++ b/README.md @@ -95,17 +95,9 @@ echo $? ## License -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +See LICENSE for details. ## Links From 4e0bd0df755d2e9a865579f1b51f9f86036a0456 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 06:51:41 +0100 Subject: [PATCH 20/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ebac51..746829e 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ echo $? ## License -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. +checkpw is licensed under the Apache License, Version 2.0. See LICENSE for details. From 23d4719078139d8fade1deb0d1a406c2218f42ef Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 07:19:45 +0100 Subject: [PATCH 21/67] README fix. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 746829e..73736db 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ checkpw -h Usage: checkpw [-u ] [-p ] [-v] [-V] [-h] Options: - -u Specify username. - -p Specify password. + -u Set username. + -p Set password. -v Enable verbose mode. -V Print program version. -h Show this help. From 27bfe141d1668045da62b5b53901605cd7eb8636 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 07:31:22 +0100 Subject: [PATCH 22/67] README fix. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73736db..b012953 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Currently only tested on Linux, but it should work on the [AIX](https://en.wikip ## The idea -I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just return 0 on success and 1 on error. +I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just returns 0 on success and 1 on error. ## Building checkpw From e0a32fcedc06e00d98de3ca65e264232a6417cb0 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 08:13:06 +0100 Subject: [PATCH 23/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b012953..81ba89f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # checkpw -checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. +checkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. From ec9b6c38ae30a86cad83de5c8fa11e6c02016d53 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 08:43:08 +0100 Subject: [PATCH 24/67] Added basic man page. --- checkpw.1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 checkpw.1 diff --git a/checkpw.1 b/checkpw.1 new file mode 100644 index 0000000..2a88fb9 --- /dev/null +++ b/checkpw.1 @@ -0,0 +1,24 @@ +.TH man 1 "01 Jan 2025" "checkpw 1.1.0" "checkpw man page" +.SH NAME +checkpw \- checks the validity of a users password on a UNIX/PAM-based system. +.SH SYNOPSIS +checkpw [OPTION]... +.SH DESCRIPTION +checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. +.SH OPTIONS +The options which apply to the checkpw command are: + + -u Set username. + -p Set password. + -v Enable verbose mode. + -V Print program version. + -h Show this help. + +checkpw runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. + +.SH SEE ALSO +pam(3), pam_authenticate(3), PAM(8) +.SH BUGS +No known bugs. +.SH AUTHOR +Johannes Findeisen (you@hanez.org) From 84d481aa6f15c39457f6b6d20595764ee8e24563 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 08:54:26 +0100 Subject: [PATCH 25/67] Added man page to Makefile and README fixes. --- Makefile | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6b1f110..2fcc755 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,12 @@ clean: install: cp ./checkpw /usr/bin/ + cp ./checkpw.1 /usr/share/man/man1/ + gzip /usr/share/man/man1/checkpw.1 cp ./checkpw.h /usr/include/ uninstall: rm -f /usr/bin/checkpw + rm -f /usr/share/man/man1/checkpw.1.gz rm -f /usr/include/checkpw.h diff --git a/README.md b/README.md index 81ba89f..6ee6876 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ checkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. -Currently only tested on Linux, but it should work on the [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. +Currently checkpw is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. ## The idea From 66d7b352d637c06264ef5304faa865549db9d4e0 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 09:05:56 +0100 Subject: [PATCH 26/67] Makefile fix. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2fcc755..7e9ebc9 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ clean: install: cp ./checkpw /usr/bin/ cp ./checkpw.1 /usr/share/man/man1/ - gzip /usr/share/man/man1/checkpw.1 + gzip -f /usr/share/man/man1/checkpw.1 cp ./checkpw.h /usr/include/ uninstall: From ae586d053b06a188c5d9b82c1ee15a525c358291 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 09:17:52 +0100 Subject: [PATCH 27/67] Version update to 1.1.1. --- checkpw.1 | 2 +- checkpw.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/checkpw.1 b/checkpw.1 index 2a88fb9..90206b8 100644 --- a/checkpw.1 +++ b/checkpw.1 @@ -1,4 +1,4 @@ -.TH man 1 "01 Jan 2025" "checkpw 1.1.0" "checkpw man page" +.TH man 1 "01 Jan 2025" "checkpw 1.1.1" "checkpw man page" .SH NAME checkpw \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS diff --git a/checkpw.h b/checkpw.h index 3620e40..bdfc1bf 100644 --- a/checkpw.h +++ b/checkpw.h @@ -10,7 +10,7 @@ #include #include -#define VERSION "1.1.0" +#define VERSION "1.1.1" #ifndef MAX_PASSWORD_LEN #define MAX_PASSWORD_LEN 256 From f53aaced692fd4d15b75da544f021d356dded5e4 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 09:33:15 +0100 Subject: [PATCH 28/67] Makefile fix. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7e9ebc9..3c40407 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ clean: install: cp ./checkpw /usr/bin/ - cp ./checkpw.1 /usr/share/man/man1/ + install -g 0 -o 0 -m 0644 checkpw.1 /usr/share/man/man1/ gzip -f /usr/share/man/man1/checkpw.1 cp ./checkpw.h /usr/include/ From bd2ac5b82954b0830d91aef0ba262bc699afb5f6 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 10:28:34 +0100 Subject: [PATCH 29/67] Makefile update. I like absolute paths... ;) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c40407..f6b9a65 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ clean: install: cp ./checkpw /usr/bin/ - install -g 0 -o 0 -m 0644 checkpw.1 /usr/share/man/man1/ + install -g 0 -o 0 -m 0644 ./checkpw.1 /usr/share/man/man1/ gzip -f /usr/share/man/man1/checkpw.1 cp ./checkpw.h /usr/include/ From 5e80936967a4332174017cd71bf2fda7333e39fe Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 10:59:44 +0100 Subject: [PATCH 30/67] Made the Makefile more generic and .gitignore update. --- .gitignore | 1 + Makefile | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 73aa35c..be30294 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ checkpw checkpw.o +checkpw.1.gz diff --git a/Makefile b/Makefile index f6b9a65..17a7074 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,18 @@ all: - $(CC) -Wall -o checkpw checkpw.c -lpam -lpam_misc + $(CC) -Wall -o ./checkpw ./checkpw.c -lpam -lpam_misc + gzip -fk ./checkpw.1 clean: rm -f ./checkpw + rm -f ./checkpw.1.gz install: - cp ./checkpw /usr/bin/ - install -g 0 -o 0 -m 0644 ./checkpw.1 /usr/share/man/man1/ - gzip -f /usr/share/man/man1/checkpw.1 - cp ./checkpw.h /usr/include/ + install -g 0 -o 0 -m 0655 ./checkpw /usr/bin/ + install -g 0 -o 0 -m 0644 ./checkpw.h /usr/include/ + install -g 0 -o 0 -m 0644 ./checkpw.1.gz /usr/share/man/man1/ uninstall: rm -f /usr/bin/checkpw - rm -f /usr/share/man/man1/checkpw.1.gz rm -f /usr/include/checkpw.h + rm -f /usr/share/man/man1/checkpw.1.gz From 0b7219c6d811590d8b0c04f35bc8889e6048bc2a Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 10 Jan 2025 02:54:20 +0100 Subject: [PATCH 31/67] Moved defines from .h to .c. These are not used in the .h file. --- checkpw.c | 16 ++++++++++++++++ checkpw.h | 18 +----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/checkpw.c b/checkpw.c index 847b287..daf43e1 100644 --- a/checkpw.c +++ b/checkpw.c @@ -15,6 +15,22 @@ #include "checkpw.h" +#ifndef MAX_PASSWORD_LEN +#define MAX_PASSWORD_LEN 256 +#endif + +#ifndef MAX_USERNAME_LEN +#define MAX_USERNAME_LEN 32 +#endif + +#ifndef MAX_UID +#define MAX_UID 1000 +#endif + +#ifndef MIN_UID +#define MIN_UID 1000 +#endif + // Function to prompt user for input, optionally hiding input void prompt_for_input(char *buffer, size_t size, const char *prompt, bool hide_input) diff --git a/checkpw.h b/checkpw.h index bdfc1bf..d3f1a6c 100644 --- a/checkpw.h +++ b/checkpw.h @@ -10,23 +10,7 @@ #include #include -#define VERSION "1.1.1" - -#ifndef MAX_PASSWORD_LEN -#define MAX_PASSWORD_LEN 256 -#endif - -#ifndef MAX_USERNAME_LEN -#define MAX_USERNAME_LEN 32 -#endif - -#ifndef MAX_UID -#define MAX_UID 1000 -#endif - -#ifndef MIN_UID -#define MIN_UID 1000 -#endif +#define VERSION "1.1.2" bool authenticate(const char *username, const char *password, bool verbose); From bc4713e82ecd91b0dde500d10d6f23052dcab9ae Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 10 Jan 2025 02:55:42 +0100 Subject: [PATCH 32/67] Man page version fix. --- checkpw.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkpw.1 b/checkpw.1 index 90206b8..47c160d 100644 --- a/checkpw.1 +++ b/checkpw.1 @@ -1,4 +1,4 @@ -.TH man 1 "01 Jan 2025" "checkpw 1.1.1" "checkpw man page" +.TH man 1 "01 Jan 2025" "checkpw 1.1.2" "checkpw man page" .SH NAME checkpw \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS From 687777f90bd2ea69411b0e28a94173f1d5fa1f5a Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 10 Jan 2025 02:57:12 +0100 Subject: [PATCH 33/67] Man page version fix... --- checkpw.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkpw.1 b/checkpw.1 index 47c160d..6ffb35f 100644 --- a/checkpw.1 +++ b/checkpw.1 @@ -1,4 +1,4 @@ -.TH man 1 "01 Jan 2025" "checkpw 1.1.2" "checkpw man page" +.TH man 1 "10 Jan 2025" "checkpw 1.1.2" "checkpw man page" .SH NAME checkpw \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS From 6d3e3393b523fe40d2191a09c9751bcb4c7d1f53 Mon Sep 17 00:00:00 2001 From: hanez Date: Sat, 11 Jan 2025 04:42:45 +0100 Subject: [PATCH 34/67] Some housekeeping... --- .gitignore | 2 ++ Makefile | 6 +++++- README.md | 2 ++ checkpw.1 | 2 +- checkpw.c | 6 +++--- checkpw.h | 9 ++++++--- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index be30294..91246d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ checkpw checkpw.o checkpw.1.gz +test +test.c diff --git a/Makefile b/Makefile index 17a7074..54a6b59 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ all: - $(CC) -Wall -o ./checkpw ./checkpw.c -lpam -lpam_misc + $(CC) -Wall -o ./checkpw ./checkpw.c -lpam gzip -fk ./checkpw.1 clean: rm -f ./checkpw rm -f ./checkpw.1.gz + rm -f ./test install: install -g 0 -o 0 -m 0655 ./checkpw /usr/bin/ @@ -16,3 +17,6 @@ uninstall: rm -f /usr/include/checkpw.h rm -f /usr/share/man/man1/checkpw.1.gz +test: + $(CC) -Wall -DPAM_DEBUG -o test test.c + diff --git a/README.md b/README.md index 6ee6876..4bfabad 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ You can also use checkpw even without installing by just running the following c ./checkpk ``` +### Return codes + checkpw returns 0 on success, 1 otherwise. ### Examples diff --git a/checkpw.1 b/checkpw.1 index 6ffb35f..cbdb452 100644 --- a/checkpw.1 +++ b/checkpw.1 @@ -1,4 +1,4 @@ -.TH man 1 "10 Jan 2025" "checkpw 1.1.2" "checkpw man page" +.TH man 1 "11 Jan 2025" "checkpw 1.1.3" "checkpw man page" .SH NAME checkpw \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS diff --git a/checkpw.c b/checkpw.c index daf43e1..7072648 100644 --- a/checkpw.c +++ b/checkpw.c @@ -6,6 +6,8 @@ * License: Apache-2.0 (see LICENSE) */ +#include "checkpw.h" + #include #include #include @@ -13,8 +15,6 @@ #include #include -#include "checkpw.h" - #ifndef MAX_PASSWORD_LEN #define MAX_PASSWORD_LEN 256 #endif @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) printf("User '%s' passed UID check (UID: %d).\n", username, pwd->pw_uid); - if (authenticate(username, password, verbose) == true) { + if (checkpw_authenticate(username, password, verbose) == true) { printf("Authenticated successfully.\n"); return 0; } else { diff --git a/checkpw.h b/checkpw.h index d3f1a6c..970e8d8 100644 --- a/checkpw.h +++ b/checkpw.h @@ -9,10 +9,12 @@ #include #include #include +#include -#define VERSION "1.1.2" +#define VERSION "1.1.3" -bool authenticate(const char *username, const char *password, bool verbose); +bool checkpw_authenticate(const char *username, const char *password, + bool verbose); int pam_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr); @@ -22,7 +24,8 @@ struct pam_credentials const char *password; }; -bool authenticate(const char *username, const char *password, bool verbose) +bool checkpw_authenticate(const char *username, const char *password, + bool verbose) { int retval; pam_handle_t *pamh = NULL; From 4c50974efc85bc54689695e1baaf1700d6430f3c Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 10 Mar 2025 00:51:40 +0100 Subject: [PATCH 35/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bfabad..8d0f9cf 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Options: You can also use checkpw even without installing by just running the following command: ``` -./checkpk +./checkpw ``` ### Return codes From bec3be67469b0e4d141bf1e61037553574e5355b Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 30 May 2025 04:17:15 +0200 Subject: [PATCH 36/67] Added requirements to README. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d0f9cf..f17bd0d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Currently checkpw is only tested on Linux, but it should work on a [AIX](https:/ I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just returns 0 on success and 1 on error. +## Requirements + +You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. + ## Building checkpw ``` @@ -103,7 +107,7 @@ See LICENSE for details. ## Links - - [Homepage of checkpw](https://git.xw3.org/xw3/checkpw) + - [https://git.xw3.org/hanez/checkpw](https://git.xw3.org/hanez/checkpw) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) From 1665cdc1a3c79d1b50ee81f45e93b015b214613f Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 30 May 2025 04:18:12 +0200 Subject: [PATCH 37/67] README fix. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f17bd0d..bd0cbb0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ You need the PAM development package installed. On Alpine it is named linux-pam- ## Building checkpw ``` -git clone https://git.xw3.org/xw3/checkpw.git +git clone https://git.xw3.org/hanez/checkpw.git cd checkpw make ``` From 22e4f0790a93c3af5085d0f3b5fcc89b67ca086e Mon Sep 17 00:00:00 2001 From: hanez Date: Sun, 1 Jun 2025 19:23:47 +0200 Subject: [PATCH 38/67] Renamed project from checkpw to chkpw. (1.2.0) --- .gitignore | 6 +++--- Makefile | 20 ++++++++++---------- README.md | 34 +++++++++++++++++----------------- checkpw.1 | 24 ------------------------ chkpw.1 | 24 ++++++++++++++++++++++++ checkpw.c => chkpw.c | 4 ++-- checkpw.h => chkpw.h | 4 ++-- 7 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 checkpw.1 create mode 100644 chkpw.1 rename checkpw.c => chkpw.c (98%) rename checkpw.h => chkpw.h (96%) diff --git a/.gitignore b/.gitignore index 91246d1..5188112 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -checkpw -checkpw.o -checkpw.1.gz +chkpw +chkpw.o +chkpw.1.gz test test.c diff --git a/Makefile b/Makefile index 54a6b59..4f06b3b 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,21 @@ all: - $(CC) -Wall -o ./checkpw ./checkpw.c -lpam - gzip -fk ./checkpw.1 + $(CC) -Wall -o ./chkpw ./chkpw.c -lpam + gzip -fk ./chkpw.1 clean: - rm -f ./checkpw - rm -f ./checkpw.1.gz + rm -f ./chkpw + rm -f ./chkpw.1.gz rm -f ./test install: - install -g 0 -o 0 -m 0655 ./checkpw /usr/bin/ - install -g 0 -o 0 -m 0644 ./checkpw.h /usr/include/ - install -g 0 -o 0 -m 0644 ./checkpw.1.gz /usr/share/man/man1/ + install -g 0 -o 0 -m 0655 ./chkpw /usr/bin/ + install -g 0 -o 0 -m 0644 ./chkpw.h /usr/include/ + install -g 0 -o 0 -m 0644 ./chkpw.1.gz /usr/share/man/man1/ uninstall: - rm -f /usr/bin/checkpw - rm -f /usr/include/checkpw.h - rm -f /usr/share/man/man1/checkpw.1.gz + rm -f /usr/bin/chkpw + rm -f /usr/include/chkpw.h + rm -f /usr/share/man/man1/chkpw.1.gz test: $(CC) -Wall -DPAM_DEBUG -o test test.c diff --git a/README.md b/README.md index bd0cbb0..f27f21c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# checkpw +# chkpw -checkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. +chkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. Currently checkpw is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. @@ -15,32 +15,32 @@ You need the PAM development package installed. On Alpine it is named linux-pam- ## Building checkpw ``` -git clone https://git.xw3.org/hanez/checkpw.git +git clone https://git.xw3.org/hanez/chkpw.git cd checkpw make ``` -The code only supports verifying passwords for user id 1000 by default. Look at the file checkpw.h for some compile time options! +The code only supports verifying passwords for user id 1000 by default. Look at the file chkpw.h for some compile time options! ### Custom build example Set MAX_UID and MIN_UID at compile time: ``` -gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o checkpw checkpw.c -lpam -lpam_misc +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpw chkpw.c -lpam -lpam_misc ``` ## Installation -**WARNING:** Install this software with care. checkpw could easily be used for bruteforcing passwords from local users! +**WARNING:** Install this software with care. chkpw could easily be used for bruteforcing passwords from local users! ``` sudo make install ``` -checkpw is installed to /usr/bin/. +chkpw is installed to /usr/bin/. -checkpw.h is installed to /usr/include/ for use in other applications. +chkpw.h is installed to /usr/include/ for use in other applications. ## Uninstall @@ -52,7 +52,7 @@ sudo make uninstall ``` checkpw -h -Usage: checkpw [-u ] [-p ] [-v] [-V] [-h] +Usage: chkpw [-u ] [-p ] [-v] [-V] [-h] Options: -u Set username. @@ -62,15 +62,15 @@ Options: -h Show this help. ``` -You can also use checkpw even without installing by just running the following command: +You can also use chkpw even without installing by just running the following command: ``` -./checkpw +./chkpw ``` ### Return codes -checkpw returns 0 on success, 1 otherwise. +chkpw returns 0 on success, 1 otherwise. ### Examples @@ -78,19 +78,19 @@ checkpw returns 0 on success, 1 otherwise. #### Interactive mode asking for a username and a password ``` -checkpw +chkpw ``` #### Interactive mode only asking for a password ``` -checkpw -u hanez +chkpw -u hanez ``` #### None interactive mode with username and password provided as arguments to checkpw ``` -checkpw -u hanez -p password +chkpw -u hanez -p password ``` #### Request the result from the above commands @@ -101,13 +101,13 @@ echo $? ## License -checkpw is licensed under the Apache License, Version 2.0. +chkpw is licensed under the Apache License, Version 2.0. See LICENSE for details. ## Links - - [https://git.xw3.org/hanez/checkpw](https://git.xw3.org/hanez/checkpw) + - [https://git.xw3.org/hanez/chkpw](https://git.xw3.org/hanez/chkpw) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) diff --git a/checkpw.1 b/checkpw.1 deleted file mode 100644 index cbdb452..0000000 --- a/checkpw.1 +++ /dev/null @@ -1,24 +0,0 @@ -.TH man 1 "11 Jan 2025" "checkpw 1.1.3" "checkpw man page" -.SH NAME -checkpw \- checks the validity of a users password on a UNIX/PAM-based system. -.SH SYNOPSIS -checkpw [OPTION]... -.SH DESCRIPTION -checkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. -.SH OPTIONS -The options which apply to the checkpw command are: - - -u Set username. - -p Set password. - -v Enable verbose mode. - -V Print program version. - -h Show this help. - -checkpw runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. - -.SH SEE ALSO -pam(3), pam_authenticate(3), PAM(8) -.SH BUGS -No known bugs. -.SH AUTHOR -Johannes Findeisen (you@hanez.org) diff --git a/chkpw.1 b/chkpw.1 new file mode 100644 index 0000000..ebfc480 --- /dev/null +++ b/chkpw.1 @@ -0,0 +1,24 @@ +.TH man 1 "01 Jun 2025" "chkpw 1.2.0" "chkpw man page" +.SH NAME +chkpw \- checks the validity of a users password on a UNIX/PAM-based system. +.SH SYNOPSIS +chkpw [OPTION]... +.SH DESCRIPTION +chkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. +.SH OPTIONS +The options which apply to the chkpw command are: + + -u Set username. + -p Set password. + -v Enable verbose mode. + -V Print program version. + -h Show this help. + +chkpw runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. + +.SH SEE ALSO +pam(3), pam_authenticate(3), PAM(8) +.SH BUGS +No known bugs. +.SH AUTHOR +Johannes Findeisen (you@hanez.org) diff --git a/checkpw.c b/chkpw.c similarity index 98% rename from checkpw.c rename to chkpw.c index 7072648..47b589d 100644 --- a/checkpw.c +++ b/chkpw.c @@ -1,12 +1,12 @@ /** - * checkpw is a program that checks the validity of a users password on a + * chkpw is a program that checks the validity of a users password on a * UNIX/PAM-based system. * * Author: Johannes Findeisen - 2024 * License: Apache-2.0 (see LICENSE) */ -#include "checkpw.h" +#include "chkpw.h" #include #include diff --git a/checkpw.h b/chkpw.h similarity index 96% rename from checkpw.h rename to chkpw.h index 970e8d8..95b8b21 100644 --- a/checkpw.h +++ b/chkpw.h @@ -1,5 +1,5 @@ /** - * checkpw.h is part of checkpw, a program that checks the validity of a users + * chkpw.h is part of chkpw, a program that checks the validity of a users * password on a UNIX/PAM-based system. * * Author: Johannes Findeisen - 2025 @@ -11,7 +11,7 @@ #include #include -#define VERSION "1.1.3" +#define VERSION "1.2.0" bool checkpw_authenticate(const char *username, const char *password, bool verbose); From bdc6fab467830a6ff81434cfa5b449877e090e72 Mon Sep 17 00:00:00 2001 From: hanez Date: Sun, 1 Jun 2025 19:27:19 +0200 Subject: [PATCH 39/67] I am stupid... :) --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f27f21c..c7a8368 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ chkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. -Currently checkpw is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. +Currently chkpw is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. ## The idea @@ -12,11 +12,11 @@ I needed a program to verify passwords of users on Linux/UNIX systems using PAM You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. -## Building checkpw +## Building chkpw ``` git clone https://git.xw3.org/hanez/chkpw.git -cd checkpw +cd chkpw make ``` @@ -51,7 +51,7 @@ sudo make uninstall ## Usage ``` -checkpw -h +chkpw -h Usage: chkpw [-u ] [-p ] [-v] [-V] [-h] Options: @@ -87,7 +87,7 @@ chkpw chkpw -u hanez ``` -#### None interactive mode with username and password provided as arguments to checkpw +#### None interactive mode with username and password provided as arguments to chkpw ``` chkpw -u hanez -p password From 0fb2bc12e7728332bce0247c36fae1a5347d15d3 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 4 Jun 2025 00:25:02 +0200 Subject: [PATCH 40/67] Added link to unix_chkpwd man page. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c7a8368..e6ac795 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ See LICENSE for details. ## Links - [https://git.xw3.org/hanez/chkpw](https://git.xw3.org/hanez/chkpw) + - [https://linux.die.net/man/8/unix_chkpwd](https://linux.die.net/man/8/unix_chkpwd) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) From a2bcc55b38636a7aae0e075e42fc8e84e9c9f84e Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 4 Jun 2025 18:43:26 +0200 Subject: [PATCH 41/67] Renamed chkpw to chkpwd. (1.3.0) --- Makefile | 20 ++++++++++---------- README.md | 46 ++++++++++++++++++++++----------------------- chkpw.1 | 24 ----------------------- chkpwd.1 | 24 +++++++++++++++++++++++ chkpw.c => chkpwd.c | 4 ++-- chkpw.h => chkpwd.h | 4 ++-- 6 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 chkpw.1 create mode 100644 chkpwd.1 rename chkpw.c => chkpwd.c (98%) rename chkpw.h => chkpwd.h (96%) diff --git a/Makefile b/Makefile index 4f06b3b..2498611 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,21 @@ all: - $(CC) -Wall -o ./chkpw ./chkpw.c -lpam - gzip -fk ./chkpw.1 + $(CC) -Wall -o ./chkpwd ./chkpwd.c -lpam + gzip -fk ./chkpwd.1 clean: - rm -f ./chkpw - rm -f ./chkpw.1.gz + rm -f ./chkpwd + rm -f ./chkpwd.1.gz rm -f ./test install: - install -g 0 -o 0 -m 0655 ./chkpw /usr/bin/ - install -g 0 -o 0 -m 0644 ./chkpw.h /usr/include/ - install -g 0 -o 0 -m 0644 ./chkpw.1.gz /usr/share/man/man1/ + install -g 0 -o 0 -m 0655 ./chkpwd /usr/bin/ + install -g 0 -o 0 -m 0644 ./chkpwd.h /usr/include/ + install -g 0 -o 0 -m 0644 ./chkpwd.1.gz /usr/share/man/man1/ uninstall: - rm -f /usr/bin/chkpw - rm -f /usr/include/chkpw.h - rm -f /usr/share/man/man1/chkpw.1.gz + rm -f /usr/bin/chkpwd + rm -f /usr/include/chkpwd.h + rm -f /usr/share/man/man1/chkpwd.1.gz test: $(CC) -Wall -DPAM_DEBUG -o test test.c diff --git a/README.md b/README.md index e6ac795..f59d457 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# chkpw +# chkpwd -chkpw is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. +chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. -Currently chkpw is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. +Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. ## The idea @@ -12,35 +12,35 @@ I needed a program to verify passwords of users on Linux/UNIX systems using PAM You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. -## Building chkpw +## Building chkpwd ``` -git clone https://git.xw3.org/hanez/chkpw.git -cd chkpw +git clone https://git.xw3.org/hanez/chkpwd.git +cd chkpwd make ``` -The code only supports verifying passwords for user id 1000 by default. Look at the file chkpw.h for some compile time options! +The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! ### Custom build example Set MAX_UID and MIN_UID at compile time: ``` -gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpw chkpw.c -lpam -lpam_misc +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ``` ## Installation -**WARNING:** Install this software with care. chkpw could easily be used for bruteforcing passwords from local users! +**WARNING:** Install this software with care. chkpwd could easily be used for bruteforcing passwords from local users! ``` sudo make install ``` -chkpw is installed to /usr/bin/. +chkpwd is installed to /usr/bin/. -chkpw.h is installed to /usr/include/ for use in other applications. +chkpwd.h is installed to /usr/include/ for use in other applications. ## Uninstall @@ -51,8 +51,8 @@ sudo make uninstall ## Usage ``` -chkpw -h -Usage: chkpw [-u ] [-p ] [-v] [-V] [-h] +chkpwd -h +Usage: chkpwd [-u ] [-p ] [-v] [-V] [-h] Options: -u Set username. @@ -62,15 +62,15 @@ Options: -h Show this help. ``` -You can also use chkpw even without installing by just running the following command: +You can also use chkpwd even without installing by just running the following command: ``` -./chkpw +./chkpwd ``` ### Return codes -chkpw returns 0 on success, 1 otherwise. +chkpwd returns 0 on success, 1 otherwise. ### Examples @@ -78,19 +78,19 @@ chkpw returns 0 on success, 1 otherwise. #### Interactive mode asking for a username and a password ``` -chkpw +chkpwd ``` #### Interactive mode only asking for a password ``` -chkpw -u hanez +chkpwd -u hanez ``` -#### None interactive mode with username and password provided as arguments to chkpw +#### None interactive mode with username and password provided as arguments to chkpwd ``` -chkpw -u hanez -p password +chkpwd -u hanez -p password ``` #### Request the result from the above commands @@ -101,14 +101,14 @@ echo $? ## License -chkpw is licensed under the Apache License, Version 2.0. +chkpwd is licensed under the Apache License, Version 2.0. See LICENSE for details. ## Links - - [https://git.xw3.org/hanez/chkpw](https://git.xw3.org/hanez/chkpw) - - [https://linux.die.net/man/8/unix_chkpwd](https://linux.die.net/man/8/unix_chkpwd) + - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) + - [https://linux.die.net/man/8/unix_chkpwdd](https://linux.die.net/man/8/unix_chkpwd) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) diff --git a/chkpw.1 b/chkpw.1 deleted file mode 100644 index ebfc480..0000000 --- a/chkpw.1 +++ /dev/null @@ -1,24 +0,0 @@ -.TH man 1 "01 Jun 2025" "chkpw 1.2.0" "chkpw man page" -.SH NAME -chkpw \- checks the validity of a users password on a UNIX/PAM-based system. -.SH SYNOPSIS -chkpw [OPTION]... -.SH DESCRIPTION -chkpw is a program that checks the validity of a users password on a UNIX/PAM-based system. -.SH OPTIONS -The options which apply to the chkpw command are: - - -u Set username. - -p Set password. - -v Enable verbose mode. - -V Print program version. - -h Show this help. - -chkpw runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. - -.SH SEE ALSO -pam(3), pam_authenticate(3), PAM(8) -.SH BUGS -No known bugs. -.SH AUTHOR -Johannes Findeisen (you@hanez.org) diff --git a/chkpwd.1 b/chkpwd.1 new file mode 100644 index 0000000..cc83125 --- /dev/null +++ b/chkpwd.1 @@ -0,0 +1,24 @@ +.TH man 1 "01 Jun 2025" "chkpwd 1.3.0" "chkpwd man page" +.SH NAME +chkpwd \- checks the validity of a users password on a UNIX/PAM-based system. +.SH SYNOPSIS +chkpwd [OPTION]... +.SH DESCRIPTION +chkpwd is a program that checks the validity of a users password on a UNIX/PAM-based system. +.SH OPTIONS +The options which apply to the chkpwd command are: + + -u Set username. + -p Set password. + -v Enable verbose mode. + -V Print program version. + -h Show this help. + +chkpwd runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. + +.SH SEE ALSO +pam(3), pam_authenticate(3), PAM(8) +.SH BUGS +No known bugs. +.SH AUTHOR +Johannes Findeisen (you@hanez.org) diff --git a/chkpw.c b/chkpwd.c similarity index 98% rename from chkpw.c rename to chkpwd.c index 47b589d..7339620 100644 --- a/chkpw.c +++ b/chkpwd.c @@ -1,12 +1,12 @@ /** - * chkpw is a program that checks the validity of a users password on a + * chkpwd is a program that checks the validity of a users password on a * UNIX/PAM-based system. * * Author: Johannes Findeisen - 2024 * License: Apache-2.0 (see LICENSE) */ -#include "chkpw.h" +#include "chkpwd.h" #include #include diff --git a/chkpw.h b/chkpwd.h similarity index 96% rename from chkpw.h rename to chkpwd.h index 95b8b21..ef1e97b 100644 --- a/chkpw.h +++ b/chkpwd.h @@ -1,5 +1,5 @@ /** - * chkpw.h is part of chkpw, a program that checks the validity of a users + * chkpwd.h is part of chkpwd, a program that checks the validity of a users * password on a UNIX/PAM-based system. * * Author: Johannes Findeisen - 2025 @@ -11,7 +11,7 @@ #include #include -#define VERSION "1.2.0" +#define VERSION "1.3.0" bool checkpw_authenticate(const char *username, const char *password, bool verbose); From d819e7c8212de55e97907e418eba2657a7a52668 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 4 Jun 2025 19:06:31 +0200 Subject: [PATCH 42/67] gitignore fix. --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5188112..1b5bb4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -chkpw -chkpw.o -chkpw.1.gz +chkpwd +chkpwd.o +chkpwd.1.gz test test.c From 3d0022ced183f064ac49dff01d8a40ce53d611ce Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 5 Jun 2025 01:51:44 +0200 Subject: [PATCH 43/67] Typo fix. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f59d457..f72d0af 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ See LICENSE for details. ## Links - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) - - [https://linux.die.net/man/8/unix_chkpwdd](https://linux.die.net/man/8/unix_chkpwd) + - [https://linux.die.net/man/8/unix_chkpwd](https://linux.die.net/man/8/unix_chkpwd) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) From ce7fc820a7ec99985b3af6aeb696582439d2b6ae Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 5 Jun 2025 04:23:43 +0200 Subject: [PATCH 44/67] Added links to README. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f72d0af..0726431 100644 --- a/README.md +++ b/README.md @@ -111,4 +111,7 @@ See LICENSE for details. - [https://linux.die.net/man/8/unix_chkpwd](https://linux.die.net/man/8/unix_chkpwd) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) + - [https://github.com/AlexanderZhirov/chkpass](https://github.com/AlexanderZhirov/chkpass) + - [https://github.com/ViKingIX/pam_test](https://github.com/ViKingIX/pam_test) + - [https://github.com/Dareka826/chk_pw](https://github.com/Dareka826/chk_pw) From ccfd170bae11a0d042b0ffcf18f671f1b7f57e08 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 5 Jun 2025 20:07:03 +0200 Subject: [PATCH 45/67] Fixed man page. --- chkpwd.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chkpwd.1 b/chkpwd.1 index cc83125..f0af81c 100644 --- a/chkpwd.1 +++ b/chkpwd.1 @@ -1,4 +1,4 @@ -.TH man 1 "01 Jun 2025" "chkpwd 1.3.0" "chkpwd man page" +.TH checkpw 1 "June 2025" "chkpwd 1.3.0" "chkpwd man page" .SH NAME chkpwd \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS @@ -17,7 +17,7 @@ The options which apply to the chkpwd command are: chkpwd runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. .SH SEE ALSO -pam(3), pam_authenticate(3), PAM(8) +pam(3), pam_authenticate(3), PAM(8), pam_unix(8) .SH BUGS No known bugs. .SH AUTHOR From dbd240f31f61f2947af67ef26d2c0ff4f5777390 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 5 Jun 2025 20:23:53 +0200 Subject: [PATCH 46/67] Just some small fixes and cosmetics... (1.3.1) --- chkpwd.1 | 11 +++++++---- chkpwd.c | 1 + chkpwd.h | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/chkpwd.1 b/chkpwd.1 index f0af81c..89c70bd 100644 --- a/chkpwd.1 +++ b/chkpwd.1 @@ -1,10 +1,11 @@ -.TH checkpw 1 "June 2025" "chkpwd 1.3.0" "chkpwd man page" +.TH checkpw 1 "June 2025" "chkpwd 1.3.1" "chkpwd man page" .SH NAME chkpwd \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS chkpwd [OPTION]... .SH DESCRIPTION -chkpwd is a program that checks the validity of a users password on a UNIX/PAM-based system. +chkpwd is a program that checks the validity of a users password on a +UNIX/PAM-based system. .SH OPTIONS The options which apply to the chkpwd command are: @@ -14,11 +15,13 @@ The options which apply to the chkpwd command are: -V Print program version. -h Show this help. -chkpwd runs in an interactive mode when no username and/or password are set. A missing username and/or password will then be asked for program execution. +chkpwd runs in an interactive mode when no username and/or password are set. +A missing username and/or password will then be asked for while program +execution. .SH SEE ALSO pam(3), pam_authenticate(3), PAM(8), pam_unix(8) .SH BUGS No known bugs. .SH AUTHOR -Johannes Findeisen (you@hanez.org) +Written by Johannes Findeisen . diff --git a/chkpwd.c b/chkpwd.c index 7339620..69fbc46 100644 --- a/chkpwd.c +++ b/chkpwd.c @@ -3,6 +3,7 @@ * UNIX/PAM-based system. * * Author: Johannes Findeisen - 2024 + * Homepage: https://git.xw3.org/hanez/chkpwd * License: Apache-2.0 (see LICENSE) */ diff --git a/chkpwd.h b/chkpwd.h index ef1e97b..d2ff23f 100644 --- a/chkpwd.h +++ b/chkpwd.h @@ -3,6 +3,7 @@ * password on a UNIX/PAM-based system. * * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkpwd * License: Apache-2.0 (see LICENSE) */ @@ -11,7 +12,7 @@ #include #include -#define VERSION "1.3.0" +#define VERSION "1.3.1" bool checkpw_authenticate(const char *username, const char *password, bool verbose); From b2461ba7a0d9fda961192859be299330888bd1c2 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 5 Jun 2025 20:46:08 +0200 Subject: [PATCH 47/67] Link update as the site used Google adds. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0726431..483cda6 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ See LICENSE for details. ## Links - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) - - [https://linux.die.net/man/8/unix_chkpwd](https://linux.die.net/man/8/unix_chkpwd) + - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) - [https://github.com/AlexanderZhirov/chkpass](https://github.com/AlexanderZhirov/chkpass) From 8644ccbdc5676f9d5e904960366b2c81962d397e Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 00:57:42 +0200 Subject: [PATCH 48/67] Merged with chkgrp and renamed to chkusr. --- .gitignore | 9 +- Makefile | 26 +++++ README.md | 54 ++++++---- chkgrp-min.c | 48 +++++++++ chkgrp-native-min-extended.c | 102 +++++++++++++++++++ chkgrp-native-min.c | 60 +++++++++++ chkgrp-native.c | 78 +++++++++++++++ chkgrp-ng.c | 153 +++++++++++++++++++++++++++++ chkgrp.c | 77 +++++++++++++++ lua/checkgroup.lua | 79 +++++++++++++++ lua/chkgrp-native-min-extended.lua | 89 +++++++++++++++++ lua/test.lua | 26 +++++ 12 files changed, 779 insertions(+), 22 deletions(-) create mode 100644 chkgrp-min.c create mode 100644 chkgrp-native-min-extended.c create mode 100644 chkgrp-native-min.c create mode 100644 chkgrp-native.c create mode 100644 chkgrp-ng.c create mode 100644 chkgrp.c create mode 100644 lua/checkgroup.lua create mode 100755 lua/chkgrp-native-min-extended.lua create mode 100755 lua/test.lua diff --git a/.gitignore b/.gitignore index 1b5bb4a..bd76ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,12 @@ +*.o +*.so +chkgrp +chkgrp-min +chkgrp-native +chkgrp-native-min +chkgrp-native-min-extended +chkgrp-ng chkpwd -chkpwd.o chkpwd.1.gz test test.c diff --git a/Makefile b/Makefile index 2498611..f4058d2 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,44 @@ all: + $(CC) -Wall -o ./chkgrp ./chkgrp.c + $(CC) -Wall -o ./chkgrp-min ./chkgrp-min.c + $(CC) -Wall -o ./chkgrp-native ./chkgrp-native.c + $(CC) -Wall -o ./chkgrp-native-min ./chkgrp-native-min.c + $(CC) -Wall -o ./chkgrp-native-min-extended ./chkgrp-native-min-extended.c + $(CC) -Wall -o ./chkgrp-ng ./chkgrp-ng.c $(CC) -Wall -o ./chkpwd ./chkpwd.c -lpam gzip -fk ./chkpwd.1 clean: + rm -f ./chkgrp + rm -f ./chkgrp-min + rm -f ./chkgrp-native + rm -f ./chkgrp-native-min + rm -f ./chkgrp-native-min-extended + rm -f ./chkgrp-ng rm -f ./chkpwd rm -f ./chkpwd.1.gz rm -f ./test install: + install -g 0 -o 0 -m 0655 ./chkgrp /usr/bin/ + install -g 0 -o 0 -m 0655 ./chkgrp-min /usr/bin/ + install -g 0 -o 0 -m 0655 ./chkgrp-native /usr/bin/ + install -g 0 -o 0 -m 0655 ./chkgrp-native-min /usr/bin/ + install -g 0 -o 0 -m 0655 ./chkgrp-native-min-extended /usr/bin/ + install -g 0 -o 0 -m 0655 ./chkgrp-ng /usr/bin/ install -g 0 -o 0 -m 0655 ./chkpwd /usr/bin/ install -g 0 -o 0 -m 0644 ./chkpwd.h /usr/include/ install -g 0 -o 0 -m 0644 ./chkpwd.1.gz /usr/share/man/man1/ + install -g 0 -o 0 -m 0655 ./lua/chkgrp-native-min-extended.lua /usr/bin/ uninstall: + rm -f /usr/bin/chkgrp + rm -f /usr/bin/chkgrp-min + rm -f /usr/bin/chkgrp-native + rm -f /usr/bin/chkgrp-native-min + rm -f /usr/bin/chkgrp-native-min-extended + rm -f /usr/bin/chkgrp-native-min-extended.lua + rm -f /usr/bin/chkgrp-ng rm -f /usr/bin/chkpwd rm -f /usr/include/chkpwd.h rm -f /usr/share/man/man1/chkpwd.1.gz diff --git a/README.md b/README.md index 483cda6..0bdadc6 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,30 @@ -# chkpwd +# MERGED PROJECT!!! I WILL UPDATE THIS README IN THE NEXT DAYS!!! THE FOLLOWING DOCUMENTATION WILL NOT WORK ACTUALLY! + +# chkusr + +chkusr is a set of programs to verify information about a user on a UNIX based systems. + +## chkgrp + +chkgrp is a set of programs to verify if a user is a member of a group on a UNIX based system. This code is so simple that it describes itself very good. + +More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. + +## chkpwd chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. -## The idea +### The idea I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just returns 0 on success and 1 on error. -## Requirements +### Requirements You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. -## Building chkpwd +### Building chkpwd ``` git clone https://git.xw3.org/hanez/chkpwd.git @@ -22,7 +34,7 @@ make The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! -### Custom build example +#### Custom build example Set MAX_UID and MIN_UID at compile time: @@ -30,7 +42,7 @@ Set MAX_UID and MIN_UID at compile time: gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ``` -## Installation +### Installation **WARNING:** Install this software with care. chkpwd could easily be used for bruteforcing passwords from local users! @@ -42,13 +54,13 @@ chkpwd is installed to /usr/bin/. chkpwd.h is installed to /usr/include/ for use in other applications. -## Uninstall +### Uninstall ``` sudo make uninstall ``` -## Usage +### Usage ``` chkpwd -h @@ -68,44 +80,38 @@ You can also use chkpwd even without installing by just running the following co ./chkpwd ``` -### Return codes +#### Return codes chkpwd returns 0 on success, 1 otherwise. -### Examples +#### Examples -#### Interactive mode asking for a username and a password +##### Interactive mode asking for a username and a password ``` chkpwd ``` -#### Interactive mode only asking for a password +##### Interactive mode only asking for a password ``` chkpwd -u hanez ``` -#### None interactive mode with username and password provided as arguments to chkpwd +##### None interactive mode with username and password provided as arguments to chkpwd ``` chkpwd -u hanez -p password ``` -#### Request the result from the above commands +##### Request the result from the above commands ``` echo $? ``` -## License - -chkpwd is licensed under the Apache License, Version 2.0. - -See LICENSE for details. - -## Links +#### Links - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) @@ -115,3 +121,9 @@ See LICENSE for details. - [https://github.com/ViKingIX/pam_test](https://github.com/ViKingIX/pam_test) - [https://github.com/Dareka826/chk_pw](https://github.com/Dareka826/chk_pw) +## License + +chkpwd is licensed under the Apache License, Version 2.0. + +See LICENSE for details. + diff --git a/chkgrp-min.c b/chkgrp-min.c new file mode 100644 index 0000000..2fe002a --- /dev/null +++ b/chkgrp-min.c @@ -0,0 +1,48 @@ +/** + * chkgrp-min is a program that checks if a user is a member of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include +#include +#include + +#define MAX_NAME 256 + +int main(int argc, char *argv[]) +{ + if (argc != 3) + return 2; + + if (strlen(argv[1]) > MAX_NAME || strlen(argv[2]) > MAX_NAME) + return 2; + + struct passwd *pw = getpwnam(argv[1]); + if (!pw) + return 2; + + struct group *gr = getgrnam(argv[2]); + if (!gr) + return 2; + + if (pw->pw_gid == gr->gr_gid) { + puts("Yes"); + return 0; + } + + for (char **m = gr->gr_mem; *m; ++m) { + if (!strcmp(*m, argv[1])) { + puts("Yes"); + return 0; + } + } + + puts("No"); + return 1; +} + diff --git a/chkgrp-native-min-extended.c b/chkgrp-native-min-extended.c new file mode 100644 index 0000000..c46d184 --- /dev/null +++ b/chkgrp-native-min-extended.c @@ -0,0 +1,102 @@ +/** + * chkgrp-min-native-extended is a program that checks if a user is a member + * of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include +#include + +#define MAX_LINE 1024 +#define MAX_NAME 256 + +int main(int argc, char *argv[]) +{ + if (argc != 3) + return 2; + + const char *username = argv[1]; + const char *groupname = argv[2]; + + if (strlen(username) > MAX_NAME || strlen(groupname) > MAX_NAME) + return 2; + + // Step 1: Find user in /etc/passwd to get their primary GID + FILE *passwd = fopen("/etc/passwd", "r"); + if (!passwd) + return 2; + + char line[MAX_LINE]; + int user_gid = -1; + while (fgets(line, sizeof(line), passwd)) { + char *u = strtok(line, ":"); + if (!u || strcmp(u, username) != 0) + continue; + + strtok(NULL, ":"); // skip password + strtok(NULL, ":"); // skip UID + char *gid_str = strtok(NULL, ":"); + if (!gid_str) + break; + + user_gid = atoi(gid_str); + break; + } + fclose(passwd); + if (user_gid < 0) + return 2; + + // Step 2: Find group in /etc/group and check membership or GID match + FILE *group = fopen("/etc/group", "r"); + if (!group) + return 2; + + int found = 0; + while (fgets(line, sizeof(line), group)) { + char *grp = strtok(line, ":"); + if (!grp || strcmp(grp, groupname) != 0) + continue; + + strtok(NULL, ":"); // skip password + char *gid_str = strtok(NULL, ":"); + if (!gid_str) + break; + + int group_gid = atoi(gid_str); + if (group_gid == user_gid) { + puts("Yes"); + fclose(group); + return 0; + } + + char *members = strtok(NULL, ":\n"); + if (!members) + break; + + char *m = strtok(members, ","); + while (m) { + if (!strcmp(m, username)) { + puts("Yes"); + fclose(group); + return 0; + } + m = strtok(NULL, ","); + } + + found = 1; + break; + } + + fclose(group); + if (!found) + return 2; + + puts("No"); + return 1; +} + diff --git a/chkgrp-native-min.c b/chkgrp-native-min.c new file mode 100644 index 0000000..c067695 --- /dev/null +++ b/chkgrp-native-min.c @@ -0,0 +1,60 @@ +/** + * chkgrp-min-native is a program that checks if a user is a member of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include + +#define MAX_LINE 1024 +#define MAX_NAME 256 + +int main(int argc, char *argv[]) +{ + if (argc != 3) + return 2; + + const char *username = argv[1]; + const char *groupname = argv[2]; + + if (strlen(username) > MAX_NAME || strlen(groupname) > MAX_NAME) + return 2; + + FILE *fp = fopen("/etc/group", "r"); + if (!fp) + return 2; + + char line[MAX_LINE]; + while (fgets(line, sizeof(line), fp)) { + char *grp = strtok(line, ":"); + if (!grp || strcmp(grp, groupname) != 0) + continue; + + strtok(NULL, ":"); // skip password + strtok(NULL, ":"); // skip GID + + char *members = strtok(NULL, ":\n"); + if (!members) break; + + char *m = strtok(members, ","); + while (m) { + if (!strcmp(m, username)) { + puts("Yes"); + fclose(fp); + return 0; + } + m = strtok(NULL, ","); + } + + break; // group matched, no user found + } + + fclose(fp); + puts("No"); + return 1; +} + diff --git a/chkgrp-native.c b/chkgrp-native.c new file mode 100644 index 0000000..bec5808 --- /dev/null +++ b/chkgrp-native.c @@ -0,0 +1,78 @@ +/** + * chkgrp-native is a program that checks if a user is a member of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include + +#define MAX_LINE 1024 +#define MAX_NAME 256 + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 2; + } + + const char *username = argv[1]; + const char *groupname = argv[2]; + + if (strlen(username) > MAX_NAME || strlen(groupname) > MAX_NAME) { + fprintf(stderr, "Error: Name too long (max %d characters).\n", MAX_NAME); + return 2; + } + + FILE *fp = fopen("/etc/group", "r"); + if (!fp) { + perror("Error opening /etc/group"); + return 2; + } + + char line[MAX_LINE]; + int found = 0; + + while (fgets(line, sizeof(line), fp)) { + char *grp_name = strtok(line, ":"); + if (!grp_name) continue; + + strtok(NULL, ":"); // skip password + strtok(NULL, ":"); // skip GID + + char *members = strtok(NULL, ":\n"); + if (!members) continue; + + if (strcmp(grp_name, groupname) != 0) + continue; + + // Group found, now check for user in member list + found = 1; + char *member = strtok(members, ","); + while (member) { + if (strcmp(member, username) == 0) { + fclose(fp); + puts("Yes"); + return 0; + } + member = strtok(NULL, ","); + } + + break; // no need to continue scanning + } + + fclose(fp); + + if (!found) { + fprintf(stderr, "Group '%s' not found.\n", groupname); + return 2; + } + + puts("No"); + return 1; +} + diff --git a/chkgrp-ng.c b/chkgrp-ng.c new file mode 100644 index 0000000..8faa900 --- /dev/null +++ b/chkgrp-ng.c @@ -0,0 +1,153 @@ +/** + * chkgrp-ng is a program that checks if a user is a member of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include + +#define MAX_LINE 1024 +#define MAX_NAME 256 + +void print_help(const char *prog) +{ + printf("Usage: %s [OPTIONS] \n", prog); + printf("Options:\n"); + printf(" --passwd PATH Use custom /etc/passwd file\n"); + printf(" --group PATH Use custom /etc/group file\n"); + printf(" -q Quiet mode (no output)\n"); + printf(" -h Show this help message\n"); +} + +const char *get_arg(int *i, int argc, char *argv[], const char *opt) +{ + if (*i + 1 >= argc) { + fprintf(stderr, "Missing argument after %s\n", opt); + exit(2); + } + return argv[++(*i)]; +} + +int get_user_gid(const char *user, const char *passwd_path) +{ + FILE *fp = fopen(passwd_path, "r"); + if (!fp) { + fprintf(stderr, "Error: Cannot open passwd file: %s\n", passwd_path); + return -1; + } + + char line[MAX_LINE]; + while (fgets(line, sizeof(line), fp)) { + char *name = strtok(line, ":"); + if (!name || strcmp(name, user) != 0) continue; + + strtok(NULL, ":"); // password + strtok(NULL, ":"); // UID + char *gid_str = strtok(NULL, ":"); + fclose(fp); + return gid_str ? atoi(gid_str) : -1; + } + + fclose(fp); + return -1; +} + +int check_group(const char *user, const char *group, int user_gid, + const char *group_path) +{ + FILE *fp = fopen(group_path, "r"); + if (!fp) { + fprintf(stderr, "Error: Cannot open group file: %s\n", group_path); + return -1; + } + + char line[MAX_LINE]; + while (fgets(line, sizeof(line), fp)) { + char *grp = strtok(line, ":"); + if (!grp || strcmp(grp, group) != 0) continue; + + strtok(NULL, ":"); // password + char *gid_str = strtok(NULL, ":"); + if (!gid_str) break; + + int group_gid = atoi(gid_str); + if (group_gid == user_gid) { + fclose(fp); + return 1; + } + + char *members = strtok(NULL, ":\n"); + if (!members) break; + + char *m = strtok(members, ","); + while (m) { + if (strcmp(m, user) == 0) { + fclose(fp); + return 1; + } + m = strtok(NULL, ","); + } + + fclose(fp); + return 0; + } + + fclose(fp); + return -1; +} + +int main(int argc, char *argv[]) +{ + const char *passwd_file = "/etc/passwd"; + const char *group_file = "/etc/group"; + int quiet = 0; + + int i = 1; + const char *username = NULL, *groupname = NULL; + + while (i < argc) { + if (!strcmp(argv[i], "--passwd")) { + passwd_file = get_arg(&i, argc, argv, "--passwd"); + } else if (!strcmp(argv[i], "--group")) { + group_file = get_arg(&i, argc, argv, "--group"); + } else if (!strcmp(argv[i], "-q")) { + quiet = 1; + } else if (!strcmp(argv[i], "-h")) { + print_help(argv[0]); + return 0; + } else if (!username) { + username = argv[i]; + } else if (!groupname) { + groupname = argv[i]; + } else { + fprintf(stderr, "Unexpected argument: %s\n", argv[i]); + return 2; + } + i++; + } + + if (!username || !groupname || + strlen(username) > MAX_NAME || strlen(groupname) > MAX_NAME) { + return 2; + } + + int user_gid = get_user_gid(username, passwd_file); + if (user_gid < 0) + return 2; + + int result = check_group(username, groupname, user_gid, group_file); + if (result == 1) { + if (!quiet) puts("Yes"); + return 0; + } else if (result == 0) { + if (!quiet) puts("No"); + return 1; + } + + return 2; +} + diff --git a/chkgrp.c b/chkgrp.c new file mode 100644 index 0000000..0c668c1 --- /dev/null +++ b/chkgrp.c @@ -0,0 +1,77 @@ +/** + * chkgrp is a program that checks if a user is a member of a group. + * + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkgrp + * License: Apache-2.0 (see LICENSE) + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef LOGIN_NAME_MAX +#define LOGIN_NAME_MAX 256 +#endif + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 2; + } + + const char *username = argv[1]; + const char *groupname = argv[2]; + + // Runtime check for max name length + long max_name_len = sysconf(_SC_LOGIN_NAME_MAX); + if (max_name_len <= 0 || max_name_len > 1024) { + max_name_len = LOGIN_NAME_MAX; + } + + if (strlen(username) > (size_t)max_name_len) { + fprintf(stderr, "Error: Username too long (max %ld characters).\n", + max_name_len); + return 2; + } + + if (strlen(groupname) > (size_t)max_name_len) { + fprintf(stderr, "Error: Group name too long (max %ld characters).\n", + max_name_len); + return 2; + } + + struct passwd *pw = getpwnam(username); + if (!pw) { + fprintf(stderr, "Error: User '%s' not found.\n", username); + return 2; + } + + struct group *gr = getgrnam(groupname); + if (!gr) { + fprintf(stderr, "Error: Group '%s' not found.\n", groupname); + return 2; + } + + if (pw->pw_gid == gr->gr_gid) { + puts("Yes"); + return 0; + } + + for (char **members = gr->gr_mem; *members != NULL; members++) { + if (strcmp(*members, username) == 0) { + puts("Yes"); + return 0; + } + } + + puts("No"); + return 1; +} + diff --git a/lua/checkgroup.lua b/lua/checkgroup.lua new file mode 100644 index 0000000..a8ee0db --- /dev/null +++ b/lua/checkgroup.lua @@ -0,0 +1,79 @@ +-- This file is part of chkgrp that is a program that checks if a user is a +-- member of a group. +-- +-- Author: Johannes Findeisen - 2025 +-- Homepage: https://git.xw3.org/hanez/chkgrp +-- License: Apache-2.0 (see LICENSE) + +local checkgroup = {} + +local MAX_NAME = 256 + +local function read_passwd_gid(username) + local f = io.open("/etc/passwd", "r") + if not f then return nil end + + for line in f:lines() do + local fields = {} + for field in string.gmatch(line, "([^:]+)") do + table.insert(fields, field) + end + if fields[1] == username then + f:close() + return tonumber(fields[4]) + end + end + + f:close() + return nil +end + +local function check_group_membership(username, groupname, user_gid) + local f = io.open("/etc/group", "r") + if not f then return nil end + + for line in f:lines() do + local fields = {} + for field in string.gmatch(line, "([^:]+)") do + table.insert(fields, field) + end + if fields[1] == groupname then + local group_gid = tonumber(fields[3]) + if group_gid == user_gid then + f:close() + return true + end + + for member in string.gmatch(fields[4] or "", "[^,]+") do + if member == username then + f:close() + return true + end + end + + f:close() + return false + end + end + + f:close() + return nil +end + +function checkgroup.is_user_in_group(username, groupname) + if not username or not groupname then + return nil + end + + if #username > MAX_NAME or #groupname > MAX_NAME then + return nil + end + + local gid = read_passwd_gid(username) + if not gid then return nil end + + return check_group_membership(username, groupname, gid) +end + +return checkgroup + diff --git a/lua/chkgrp-native-min-extended.lua b/lua/chkgrp-native-min-extended.lua new file mode 100755 index 0000000..6b5f22f --- /dev/null +++ b/lua/chkgrp-native-min-extended.lua @@ -0,0 +1,89 @@ +#!/usr/bin/env lua + +-- This file is part of chkgrp that is a program that checks if a user is a +-- member of a group. +-- +-- Author: Johannes Findeisen - 2025 +-- Homepage: https://git.xw3.org/hanez/chkgrp +-- License: Apache-2.0 (see LICENSE) + +local MAX_NAME = 256 + +local function read_passwd_gid(username) + local f = io.open("/etc/passwd", "r") + if not f then return nil end + + for line in f:lines() do + local fields = {} + for field in string.gmatch(line, "([^:]+)") do + table.insert(fields, field) + end + if fields[1] == username then + f:close() + return tonumber(fields[4]) -- GID is 4th field + end + end + + f:close() + return nil +end + +local function check_group_membership(username, groupname, user_gid) + local f = io.open("/etc/group", "r") + if not f then return nil end + + for line in f:lines() do + local fields = {} + for field in string.gmatch(line, "([^:]+)") do + table.insert(fields, field) + end + if fields[1] == groupname then + local group_gid = tonumber(fields[3]) + if group_gid == user_gid then + f:close() + return true + end + + for member in string.gmatch(fields[4] or "", "[^,]+") do + if member == username then + f:close() + return true + end + end + + f:close() + return false + end + end + + f:close() + return nil +end + +local username = arg[1] +local groupname = arg[2] + +if not username or not groupname then + os.exit(2) +end + +if #username > MAX_NAME or #groupname > MAX_NAME then + os.exit(2) +end + +local user_gid = read_passwd_gid(username) +if not user_gid then + os.exit(2) +end + +local result = check_group_membership(username, groupname, user_gid) +if result == nil then + os.exit(2) +elseif result == true then + print("Yes") + os.exit(0) +else + print("No") + os.exit(1) +end + diff --git a/lua/test.lua b/lua/test.lua new file mode 100755 index 0000000..0bfb5e8 --- /dev/null +++ b/lua/test.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +-- This file is part of chkgrp that is a program that checks if a user is a +-- member of a group. +-- +-- Author: Johannes Findeisen - 2025 +-- Homepage: https://git.xw3.org/hanez/chkgrp +-- License: Apache-2.0 (see LICENSE) + +local checkgroup = require("checkgroup") + +local user = arg[1] +local group = arg[2] + +local result = checkgroup.is_user_in_group(user, group) + +if result == true then + print("Yes") + os.exit(0) +elseif result == false then + print("No") + os.exit(1) +else + os.exit(2) +end + From bf732541c04ff86a56c825aad410abf72dc4e755 Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 01:09:31 +0200 Subject: [PATCH 49/67] README update. --- README.md | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0bdadc6..e26505f 100644 --- a/README.md +++ b/README.md @@ -4,44 +4,24 @@ chkusr is a set of programs to verify information about a user on a UNIX based systems. -## chkgrp +## The idea -chkgrp is a set of programs to verify if a user is a member of a group on a UNIX based system. This code is so simple that it describes itself very good. - -More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. - -## chkpwd - -chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. +I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. -### The idea - -I needed a program to verify passwords of users on Linux/UNIX systems using PAM that just returns 0 on success and 1 on error. - ### Requirements You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. -### Building chkpwd +### Building chkusr ``` -git clone https://git.xw3.org/hanez/chkpwd.git -cd chkpwd +git clone https://git.xw3.org/hanez/chkusr.git +cd chkusr make ``` -The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! - -#### Custom build example - -Set MAX_UID and MIN_UID at compile time: - -``` -gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc -``` - ### Installation **WARNING:** Install this software with care. chkpwd could easily be used for bruteforcing passwords from local users! @@ -50,7 +30,7 @@ gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc sudo make install ``` -chkpwd is installed to /usr/bin/. +chkusr programs are installed to /usr/bin/. chkpwd.h is installed to /usr/include/ for use in other applications. @@ -60,6 +40,28 @@ chkpwd.h is installed to /usr/include/ for use in other applications. sudo make uninstall ``` +## chkgrp + +chkgrp is a program to verify if a user is a member of a group. + +More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. + + +## chkpwd + +chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. + + +The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! + +#### Custom build + +Set MAX_UID and MIN_UID at compile time: + +``` +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc +``` + ### Usage ``` @@ -82,11 +84,10 @@ You can also use chkpwd even without installing by just running the following co #### Return codes -chkpwd returns 0 on success, 1 otherwise. +chk returns 0 on success, 1 otherwise. #### Examples - ##### Interactive mode asking for a username and a password ``` @@ -111,7 +112,7 @@ chkpwd -u hanez -p password echo $? ``` -#### Links +## Links - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) From 12ea8e827327d23a880e5d57078dfdf36eaba059 Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 01:30:22 +0200 Subject: [PATCH 50/67] README update. --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index e26505f..c97918e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,26 @@ chkusr is a set of programs to verify information about a user on a UNIX based systems. + * [The idea](#the-idea) + * [Requirements](#requirements) + * [Building chkusr](#building-chkusr) + * [Installation](#installation) + * [Uninstall](#uninstall) + * [chkgrp](#chkgrp) + * [chkpwd](#chkpwd) + * [Custom build](#custom-build) + * [Usage](#usage) + * [Return codes](#return-codes) + * [Examples](#examples) + * [Interactive mode asking for a username and a password](#interactive-mode-asking-for-a-username-and-a-password) + * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) + * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) + * [Request the result from the above commands](#request-the-result-from-the-above-commands) + * [Links](#links) + * [License](#license) + + + ## The idea I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. From 45973a3a9021352d302711c18b8c78d56bb2a9af Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 01:32:23 +0200 Subject: [PATCH 51/67] README update. --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c97918e..064acf5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ chkusr is a set of programs to verify information about a user on a UNIX based s * [Uninstall](#uninstall) * [chkgrp](#chkgrp) * [chkpwd](#chkpwd) - * [Custom build](#custom-build) * [Usage](#usage) * [Return codes](#return-codes) * [Examples](#examples) @@ -19,6 +18,7 @@ chkusr is a set of programs to verify information about a user on a UNIX based s * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) * [Request the result from the above commands](#request-the-result-from-the-above-commands) + * [Custom build](#custom-build) * [Links](#links) * [License](#license) @@ -74,13 +74,7 @@ chkpwd is a program that checks the validity of a users password on a UNIX/[PAM] The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! -#### Custom build -Set MAX_UID and MIN_UID at compile time: - -``` -gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc -``` ### Usage @@ -102,6 +96,8 @@ You can also use chkpwd even without installing by just running the following co ./chkpwd ``` + + #### Return codes chk returns 0 on success, 1 otherwise. @@ -132,6 +128,14 @@ chkpwd -u hanez -p password echo $? ``` +#### Custom build + +Set MAX_UID and MIN_UID at compile time: + +``` +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc +``` + ## Links - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) From f8870f6c808f4cb4c7d36c5f522cd36b842e01bd Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 02:30:01 +0200 Subject: [PATCH 52/67] Cleanups. --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 064acf5..4e5ebde 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@ chkusr is a set of programs to verify information about a user on a UNIX based s * [Links](#links) * [License](#license) - - ## The idea I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. @@ -66,16 +64,12 @@ chkgrp is a program to verify if a user is a member of a group. More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. - ## chkpwd chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. - The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! - - ### Usage ``` @@ -96,8 +90,6 @@ You can also use chkpwd even without installing by just running the following co ./chkpwd ``` - - #### Return codes chk returns 0 on success, 1 otherwise. From d92c2d2a76b04a69c68e0515adadf8d9fb4107df Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 02:56:55 +0200 Subject: [PATCH 53/67] Merge nearly ready for 1.4.0. --- README.md | 2 +- chkgrp-min.c | 4 +++- chkgrp-native-min-extended.c | 4 +++- chkgrp-native-min.c | 4 +++- chkgrp-native.c | 4 +++- chkgrp-ng.c | 4 +++- chkgrp.c | 4 +++- chkpwd.1 | 6 +++--- chkpwd.c | 1 + chkpwd.h | 10 ++++------ version.h | 1 + 11 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 version.h diff --git a/README.md b/README.md index 4e5ebde..b70fa48 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ## License -chkpwd is licensed under the Apache License, Version 2.0. +chkusr is licensed under the Apache License, Version 2.0. See LICENSE for details. diff --git a/chkgrp-min.c b/chkgrp-min.c index 2fe002a..728d0d6 100644 --- a/chkgrp-min.c +++ b/chkgrp-min.c @@ -2,10 +2,12 @@ * chkgrp-min is a program that checks if a user is a member of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ + #include "version.h" + #include #include #include diff --git a/chkgrp-native-min-extended.c b/chkgrp-native-min-extended.c index c46d184..a1c3a38 100644 --- a/chkgrp-native-min-extended.c +++ b/chkgrp-native-min-extended.c @@ -3,10 +3,12 @@ * of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ +#include "version.h" + #include #include #include diff --git a/chkgrp-native-min.c b/chkgrp-native-min.c index c067695..1e810ed 100644 --- a/chkgrp-native-min.c +++ b/chkgrp-native-min.c @@ -2,10 +2,12 @@ * chkgrp-min-native is a program that checks if a user is a member of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ +#include "version.h" + #include #include #include diff --git a/chkgrp-native.c b/chkgrp-native.c index bec5808..695fd6d 100644 --- a/chkgrp-native.c +++ b/chkgrp-native.c @@ -2,10 +2,12 @@ * chkgrp-native is a program that checks if a user is a member of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ +#include "version.h" + #include #include #include diff --git a/chkgrp-ng.c b/chkgrp-ng.c index 8faa900..3387a70 100644 --- a/chkgrp-ng.c +++ b/chkgrp-ng.c @@ -2,10 +2,12 @@ * chkgrp-ng is a program that checks if a user is a member of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ +#include "version.h" + #include #include #include diff --git a/chkgrp.c b/chkgrp.c index 0c668c1..b1bca2c 100644 --- a/chkgrp.c +++ b/chkgrp.c @@ -2,10 +2,12 @@ * chkgrp is a program that checks if a user is a member of a group. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkgrp + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ +#include "version.h" + #include #include #include diff --git a/chkpwd.1 b/chkpwd.1 index 89c70bd..da6b5cb 100644 --- a/chkpwd.1 +++ b/chkpwd.1 @@ -1,10 +1,10 @@ -.TH checkpw 1 "June 2025" "chkpwd 1.3.1" "chkpwd man page" +.TH checkpw 1 "June 2025" "chkpwd 1.4.0" "chkpwd man page" .SH NAME chkpwd \- checks the validity of a users password on a UNIX/PAM-based system. .SH SYNOPSIS chkpwd [OPTION]... .SH DESCRIPTION -chkpwd is a program that checks the validity of a users password on a +chkpwd is a program that checks the validity of a users password on a UNIX/PAM-based system. .SH OPTIONS The options which apply to the chkpwd command are: @@ -16,7 +16,7 @@ The options which apply to the chkpwd command are: -h Show this help. chkpwd runs in an interactive mode when no username and/or password are set. -A missing username and/or password will then be asked for while program +A missing username and/or password will then be asked for while program execution. .SH SEE ALSO diff --git a/chkpwd.c b/chkpwd.c index 69fbc46..036368d 100644 --- a/chkpwd.c +++ b/chkpwd.c @@ -8,6 +8,7 @@ */ #include "chkpwd.h" +#include "version.h" #include #include diff --git a/chkpwd.h b/chkpwd.h index d2ff23f..d97c229 100644 --- a/chkpwd.h +++ b/chkpwd.h @@ -1,18 +1,16 @@ /** - * chkpwd.h is part of chkpwd, a program that checks the validity of a users - * password on a UNIX/PAM-based system. + * chkpwd.h is part of chkusr, a set of programs to verify information about + * a user on UNIX based systems. * * Author: Johannes Findeisen - 2025 - * Homepage: https://git.xw3.org/hanez/chkpwd + * Homepage: https://git.xw3.org/hanez/chkusr * License: Apache-2.0 (see LICENSE) */ #include +#include #include #include -#include - -#define VERSION "1.3.1" bool checkpw_authenticate(const char *username, const char *password, bool verbose); diff --git a/version.h b/version.h new file mode 100644 index 0000000..7851500 --- /dev/null +++ b/version.h @@ -0,0 +1 @@ +#define VERSION "1.4.0" From eb69c6989c77b5c8336327f5dbf851eddb0857b2 Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 03:09:43 +0200 Subject: [PATCH 54/67] README update. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b70fa48..dc061ea 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,9 @@ gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ## Links - - [https://git.xw3.org/hanez/chkpwd](https://git.xw3.org/hanez/chkpwd) + - [https://git.xw3.org/hanez/chkusr](https://git.xw3.org/hanez/chkusr) + - [https://github.com/shadow-maint/shadow](https://github.com/shadow-maint/shadow) + - [https://github.com/linux-pam/linux-pam](https://github.com/linux-pam/linux-pam) - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) From 0957057793d91be020c1bf8d378ec67a2032224b Mon Sep 17 00:00:00 2001 From: hanez Date: Fri, 27 Jun 2025 03:10:35 +0200 Subject: [PATCH 55/67] README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc061ea..97bccef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # chkusr -chkusr is a set of programs to verify information about a user on a UNIX based systems. +chkusr is a set of programs to verify information about a user on UNIX based systems. * [The idea](#the-idea) * [Requirements](#requirements) From 71555fc27548af1cddffec75bb24bb9188b5b89f Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 02:34:46 +0200 Subject: [PATCH 56/67] Merged chkpwr to chkusr and moved defines to config.h. --- .gitignore | 1 + Makefile | 4 ++ chkgrp-min.c | 4 +- chkgrp-native-min-extended.c | 5 +- chkgrp-native-min.c | 5 +- chkgrp-native.c | 5 +- chkgrp-ng.c | 5 +- chkgrp.c | 8 +-- chkpwd.c | 34 ++++-------- chkpwr.c | 100 +++++++++++++++++++++++++++++++++++ config.h | 50 ++++++++++++++++++ version.h | 1 - 12 files changed, 171 insertions(+), 51 deletions(-) create mode 100644 chkpwr.c create mode 100644 config.h delete mode 100644 version.h diff --git a/.gitignore b/.gitignore index bd76ebb..d980a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ chkgrp-native-min-extended chkgrp-ng chkpwd chkpwd.1.gz +chkpwr test test.c diff --git a/Makefile b/Makefile index f4058d2..1628df2 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ all: $(CC) -Wall -o ./chkgrp-ng ./chkgrp-ng.c $(CC) -Wall -o ./chkpwd ./chkpwd.c -lpam gzip -fk ./chkpwd.1 + $(CC) -Wall -o ./chkpwr ./chkpwr.c clean: rm -f ./chkgrp @@ -17,6 +18,7 @@ clean: rm -f ./chkgrp-ng rm -f ./chkpwd rm -f ./chkpwd.1.gz + rm -f ./chkpwr rm -f ./test install: @@ -29,6 +31,7 @@ install: install -g 0 -o 0 -m 0655 ./chkpwd /usr/bin/ install -g 0 -o 0 -m 0644 ./chkpwd.h /usr/include/ install -g 0 -o 0 -m 0644 ./chkpwd.1.gz /usr/share/man/man1/ + install -g 0 -o 0 -m 0655 ./chkpwr /usr/bin/ install -g 0 -o 0 -m 0655 ./lua/chkgrp-native-min-extended.lua /usr/bin/ uninstall: @@ -40,6 +43,7 @@ uninstall: rm -f /usr/bin/chkgrp-native-min-extended.lua rm -f /usr/bin/chkgrp-ng rm -f /usr/bin/chkpwd + rm -f /usr/bin/chkpwr rm -f /usr/include/chkpwd.h rm -f /usr/share/man/man1/chkpwd.1.gz diff --git a/chkgrp-min.c b/chkgrp-min.c index 728d0d6..4bc4dcb 100644 --- a/chkgrp-min.c +++ b/chkgrp-min.c @@ -6,7 +6,7 @@ * License: Apache-2.0 (see LICENSE) */ - #include "version.h" + #include "config.h" #include #include @@ -14,8 +14,6 @@ #include #include -#define MAX_NAME 256 - int main(int argc, char *argv[]) { if (argc != 3) diff --git a/chkgrp-native-min-extended.c b/chkgrp-native-min-extended.c index a1c3a38..320c57f 100644 --- a/chkgrp-native-min-extended.c +++ b/chkgrp-native-min-extended.c @@ -7,16 +7,13 @@ * License: Apache-2.0 (see LICENSE) */ -#include "version.h" +#include "config.h" #include #include #include #include -#define MAX_LINE 1024 -#define MAX_NAME 256 - int main(int argc, char *argv[]) { if (argc != 3) diff --git a/chkgrp-native-min.c b/chkgrp-native-min.c index 1e810ed..8786a20 100644 --- a/chkgrp-native-min.c +++ b/chkgrp-native-min.c @@ -6,15 +6,12 @@ * License: Apache-2.0 (see LICENSE) */ -#include "version.h" +#include "config.h" #include #include #include -#define MAX_LINE 1024 -#define MAX_NAME 256 - int main(int argc, char *argv[]) { if (argc != 3) diff --git a/chkgrp-native.c b/chkgrp-native.c index 695fd6d..d19de61 100644 --- a/chkgrp-native.c +++ b/chkgrp-native.c @@ -6,15 +6,12 @@ * License: Apache-2.0 (see LICENSE) */ -#include "version.h" +#include "config.h" #include #include #include -#define MAX_LINE 1024 -#define MAX_NAME 256 - int main(int argc, char *argv[]) { if (argc != 3) { diff --git a/chkgrp-ng.c b/chkgrp-ng.c index 3387a70..e22c053 100644 --- a/chkgrp-ng.c +++ b/chkgrp-ng.c @@ -6,15 +6,12 @@ * License: Apache-2.0 (see LICENSE) */ -#include "version.h" +#include "config.h" #include #include #include -#define MAX_LINE 1024 -#define MAX_NAME 256 - void print_help(const char *prog) { printf("Usage: %s [OPTIONS] \n", prog); diff --git a/chkgrp.c b/chkgrp.c index b1bca2c..35fcd75 100644 --- a/chkgrp.c +++ b/chkgrp.c @@ -6,7 +6,7 @@ * License: Apache-2.0 (see LICENSE) */ -#include "version.h" +#include "config.h" #include #include @@ -17,10 +17,6 @@ #include #include -#ifndef LOGIN_NAME_MAX -#define LOGIN_NAME_MAX 256 -#endif - int main(int argc, char *argv[]) { if (argc != 3) { @@ -34,7 +30,7 @@ int main(int argc, char *argv[]) // Runtime check for max name length long max_name_len = sysconf(_SC_LOGIN_NAME_MAX); if (max_name_len <= 0 || max_name_len > 1024) { - max_name_len = LOGIN_NAME_MAX; + max_name_len = MAX_NAME; } if (strlen(username) > (size_t)max_name_len) { diff --git a/chkpwd.c b/chkpwd.c index 036368d..4273372 100644 --- a/chkpwd.c +++ b/chkpwd.c @@ -8,7 +8,7 @@ */ #include "chkpwd.h" -#include "version.h" +#include "config.h" #include #include @@ -17,22 +17,6 @@ #include #include -#ifndef MAX_PASSWORD_LEN -#define MAX_PASSWORD_LEN 256 -#endif - -#ifndef MAX_USERNAME_LEN -#define MAX_USERNAME_LEN 32 -#endif - -#ifndef MAX_UID -#define MAX_UID 1000 -#endif - -#ifndef MIN_UID -#define MIN_UID 1000 -#endif - // Function to prompt user for input, optionally hiding input void prompt_for_input(char *buffer, size_t size, const char *prompt, bool hide_input) @@ -98,28 +82,28 @@ int main(int argc, char *argv[]) { bool verbose = false; bool version = false; - char password[MAX_PASSWORD_LEN] = {0}; - char username[MAX_USERNAME_LEN] = {0}; + char password[MAX_PASSWORD] = {0}; + char username[MAX_NAME] = {0}; int opt; // Parse command-line arguments while ((opt = getopt(argc, argv, "u:p:hvV")) != -1) { switch (opt) { case 'u': - if (strlen(optarg) >= MAX_USERNAME_LEN) { + if (strlen(optarg) >= MAX_NAME) { fprintf(stderr, "Error: Username is too long (maximum %d characters).\n", - MAX_USERNAME_LEN); + MAX_NAME); exit(1); } - strncpy(username, optarg, MAX_USERNAME_LEN - 1); + strncpy(username, optarg, MAX_NAME - 1); break; case 'p': - if (strlen(optarg) >= MAX_PASSWORD_LEN) { + if (strlen(optarg) >= MAX_PASSWORD) { fprintf(stderr, "Error: Password is too long (maximum %d characters).\n", - MAX_PASSWORD_LEN); + MAX_PASSWORD); exit(1); } - strncpy(password, optarg, MAX_PASSWORD_LEN - 1); + strncpy(password, optarg, MAX_PASSWORD - 1); break; case 'h': print_usage(argv[0]); diff --git a/chkpwr.c b/chkpwr.c new file mode 100644 index 0000000..e6be5eb --- /dev/null +++ b/chkpwr.c @@ -0,0 +1,100 @@ +/** + * checkpwrule is a program that checks if an input string validates a + * password rule. + * + * Author: Johannes Findeisen - 2024 + * License: MIT (see LICENSE) + */ + +#include "config.h" + +#include +#include +#include + +// Return 1 if non-ASCII characters are found, 0 if all are ASCII +int is_valid_ascii(char *str) { + for (int i = 0; i < strlen(str); i++) { + if ((unsigned char)str[i] > 127) { + return 1; // Non-ASCII character detected, return 1 (indicating invalid) + } + } + return 0; // All characters are ASCII +} + +int is_valid(char *str) { + int lowercase_count = 0, uppercase_count = 0, digit_count = 0, special_count = 0; + int i; + int length = strlen(str); + + // Check if the input contains any non-ASCII characters + if (is_valid_ascii(str)) { + printf("Password contains non-ASCII characters.\n"); + return 1; // Invalid input, return 1 to signal failure + } + + // Check if the length is within the allowed range + if (length < MIN_PASSWORD_LENGTH) { + printf("Password is too short! It must be at least %d characters long.\n", MIN_PASSWORD_LENGTH); + return 1; + } + if (length > MAX_PASSWORD_LENGTH) { + printf("Password exceeds the maximum length of %d characters.\n", MAX_PASSWORD_LENGTH); + return 1; + } + + // Check each character of the string and count occurrences + for (i = 0; i < length; i++) { + if (islower(str[i])) { + lowercase_count++; + } else if (isupper(str[i])) { + uppercase_count++; + } else if (isdigit(str[i])) { + digit_count++; + } else if (ispunct(str[i])) { // Checks for special characters like !, @, #, etc. + special_count++; + } + } + + // Check if all counts meet the required minimums + if (lowercase_count < MIN_LOWERCASE) { + printf("Password needs at least %d lowercase letters.\n", MIN_LOWERCASE); + return 1; + } + if (uppercase_count < MIN_UPPERCASE) { + printf("Password needs at least %d uppercase letters.\n", MIN_UPPERCASE); + return 1; + } + if (digit_count < MIN_DIGITS) { + printf("Password needs at least %d digits.\n", MIN_DIGITS); + return 1; + } + if (special_count < MIN_SPECIAL) { + printf("Password needs at least %d special characters.\n", MIN_SPECIAL); + return 1; + } + + // If all conditions are met, return 0 (indicating success) + return 0; +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + if (is_valid(argv[1]) == 0) { + printf("The string is valid.\n"); + return 0; // Success + } else { + printf("The string is invalid. It must contain at least:\n"); + printf("- %d lowercase letters\n", MIN_LOWERCASE); + printf("- %d uppercase letters\n", MIN_UPPERCASE); + printf("- %d digits\n", MIN_DIGITS); + printf("- %d special characters\n", MIN_SPECIAL); + printf("And be between %d and %d characters long.\n", MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH); + return 1; // Invalid password, return 1 + } +} + diff --git a/config.h b/config.h new file mode 100644 index 0000000..5c7db49 --- /dev/null +++ b/config.h @@ -0,0 +1,50 @@ +#define VERSION "1.5.0" + +/* For chkgrp */ +#ifndef MAX_LINE +#define MAX_LINE 1024 +#endif + +/* MAX_NAME is also used by chkpwd */ +#ifndef MAX_NAME +#define MAX_NAME 256 +#endif + +/* For chkpwd */ +#ifndef MAX_PASSWORD +#define MAX_PASSWORD 256 +#endif + +#ifndef MAX_UID +#define MAX_UID 1000 +#endif + +#ifndef MIN_UID +#define MIN_UID 1000 +#endif + +/* For chkpwr */ +#ifndef MAX_PASSWORD_LENGTH +#define MAX_PASSWORD_LENGTH 32 +#endif + +#ifndef MIN_PASSWORD_LENGTH +#define MIN_PASSWORD_LENGTH 12 +#endif + +#ifndef MIN_LOWERCASE +#define MIN_LOWERCASE 2 +#endif + +#ifndef MIN_UPPERCASE +#define MIN_UPPERCASE 2 +#endif + +#ifndef MIN_DIGITS +#define MIN_DIGITS 2 +#endif + +#ifndef MIN_SPECIAL +#define MIN_SPECIAL 2 +#endif + diff --git a/version.h b/version.h deleted file mode 100644 index 7851500..0000000 --- a/version.h +++ /dev/null @@ -1 +0,0 @@ -#define VERSION "1.4.0" From 92fdb05161c4070d167afc808289d7e6506dd054 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 02:55:20 +0200 Subject: [PATCH 57/67] Some content update and fixes... --- README.md | 7 ++++++- config.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 97bccef..68f05a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MERGED PROJECT!!! I WILL UPDATE THIS README IN THE NEXT DAYS!!! THE FOLLOWING DOCUMENTATION WILL NOT WORK ACTUALLY! +# THE FOLLOWING DOCUMENTATION WILL NOT WORK ACTUALLY! YOU NEED TO READ THE CODE ACTUALLY, SORRY... # chkusr @@ -19,6 +19,7 @@ chkusr is a set of programs to verify information about a user on UNIX based sys * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) * [Request the result from the above commands](#request-the-result-from-the-above-commands) * [Custom build](#custom-build) + * [chkpwr](#chkpwr) * [Links](#links) * [License](#license) @@ -128,6 +129,10 @@ Set MAX_UID and MIN_UID at compile time: gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ``` +## chkpwr + +A program to validate a string with a password rule. More to come... + ## Links - [https://git.xw3.org/hanez/chkusr](https://git.xw3.org/hanez/chkusr) diff --git a/config.h b/config.h index 5c7db49..be0bc9a 100644 --- a/config.h +++ b/config.h @@ -1,4 +1,10 @@ -#define VERSION "1.5.0" +/* + * Author: Johannes Findeisen - 2025 + * Homepage: https://git.xw3.org/hanez/chkusr + * License: Apache-2.0 (see LICENSE) + */ + +#define VERSION "1.5.1" /* For chkgrp */ #ifndef MAX_LINE @@ -10,7 +16,7 @@ #define MAX_NAME 256 #endif -/* For chkpwd */ +/* For chkpwd; Also uses MAX_NAME from chkgrp above */ #ifndef MAX_PASSWORD #define MAX_PASSWORD 256 #endif From f9e1cf4c057135e71b2717eddcfd3dcc482fc9b8 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:05:56 +0200 Subject: [PATCH 58/67] Some content update and fixes... --- README.md | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 68f05a9..10fb277 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ chkusr is a set of programs to verify information about a user on UNIX based sys * [The idea](#the-idea) * [Requirements](#requirements) + * [Configuration](#configuration) * [Building chkusr](#building-chkusr) * [Installation](#installation) * [Uninstall](#uninstall) @@ -25,13 +26,15 @@ chkusr is a set of programs to verify information about a user on UNIX based sys ## The idea -I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. - -Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. +I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Some programs also return a message. ### Requirements -You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is libpam0g-dev. +You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is named libpam0g-dev. + +### Configuration + +chkusr needs to be configured before compilation. Always look at config.h for configuration options. I did it this way because I need the programs as small and simple as possible, and I don't want to parse a configuration file. ### Building chkusr @@ -59,19 +62,23 @@ chkpwd.h is installed to /usr/include/ for use in other applications. sudo make uninstall ``` -## chkgrp +## Programs + +### chkgrp chkgrp is a program to verify if a user is a member of a group. More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. -## chkpwd +### chkpwd chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. +Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. + The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! -### Usage +#### Usage ``` chkpwd -h @@ -91,37 +98,37 @@ You can also use chkpwd even without installing by just running the following co ./chkpwd ``` -#### Return codes +##### Return codes chk returns 0 on success, 1 otherwise. -#### Examples +##### Examples -##### Interactive mode asking for a username and a password +###### Interactive mode asking for a username and a password ``` chkpwd ``` -##### Interactive mode only asking for a password +###### Interactive mode only asking for a password ``` chkpwd -u hanez ``` -##### None interactive mode with username and password provided as arguments to chkpwd +###### None interactive mode with username and password provided as arguments to chkpwd ``` chkpwd -u hanez -p password ``` -##### Request the result from the above commands +###### Request the result from the above commands ``` echo $? ``` -#### Custom build +##### Custom build Set MAX_UID and MIN_UID at compile time: @@ -129,7 +136,7 @@ Set MAX_UID and MIN_UID at compile time: gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ``` -## chkpwr +### chkpwr A program to validate a string with a password rule. More to come... From 22303a35068f6cf68a056f23c18b5dd87310de92 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:08:28 +0200 Subject: [PATCH 59/67] Some content update and fixes... --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 10fb277..2247806 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,18 @@ chkusr is a set of programs to verify information about a user on UNIX based sys * [Building chkusr](#building-chkusr) * [Installation](#installation) * [Uninstall](#uninstall) - * [chkgrp](#chkgrp) - * [chkpwd](#chkpwd) - * [Usage](#usage) - * [Return codes](#return-codes) - * [Examples](#examples) - * [Interactive mode asking for a username and a password](#interactive-mode-asking-for-a-username-and-a-password) - * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) - * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) - * [Request the result from the above commands](#request-the-result-from-the-above-commands) - * [Custom build](#custom-build) - * [chkpwr](#chkpwr) + * [Programs](#programs) + * [chkgrp](#chkgrp) + * [chkpwd](#chkpwd) + * [Usage](#usage) + * [Return codes](#return-codes) + * [Examples](#examples) + * [Interactive mode asking for a username and a password](#interactive-mode-asking-for-a-username-and-a-password) + * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) + * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) + * [Request the result from the above commands](#request-the-result-from-the-above-commands) + * [Custom build](#custom-build) + * [chkpwr](#chkpwr) * [Links](#links) * [License](#license) From 9709333e763b5468e3ff98336a7b482a9aebf2e7 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:13:19 +0200 Subject: [PATCH 60/67] Some content update and fixes... --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2247806..bb4d64d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # chkusr -chkusr is a set of programs to verify information about a user on UNIX based systems. +chkusr is a set of programs to verify information about a user and/or group on UNIX based systems. * [The idea](#the-idea) * [Requirements](#requirements) @@ -31,7 +31,7 @@ I needed some programs to verify some information about users and groups on a Li ### Requirements -You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is named libpam0g-dev. +You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is named libpam0g-dev. Not all programs require PAM but you need to edit the Makefile to disable PAM based programs in the build process. ### Configuration From 025f7922610f2354cf0841544d1a54fab871da7f Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:17:18 +0200 Subject: [PATCH 61/67] Some content update... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb4d64d..c1d8687 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # chkusr -chkusr is a set of programs to verify information about a user and/or group on UNIX based systems. +chkusr is a set of programs (chkgrp, chkpwd and chkpwr) to verify information about a user and/or group on UNIX based systems. * [The idea](#the-idea) * [Requirements](#requirements) From 7adcaf989fadc9e0192d3cc9bc2aa2b34beac884 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:32:40 +0200 Subject: [PATCH 62/67] Some fix. --- lua/checkgroup.lua | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 lua/checkgroup.lua diff --git a/lua/checkgroup.lua b/lua/checkgroup.lua old mode 100644 new mode 100755 From b082f1592ba0eeb11e519916471b334d3383b77c Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:35:08 +0200 Subject: [PATCH 63/67] Some content update... --- lua/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 lua/README.md diff --git a/lua/README.md b/lua/README.md new file mode 100644 index 0000000..f891075 --- /dev/null +++ b/lua/README.md @@ -0,0 +1 @@ +This is experimental at the monent but I really will implement some programs from chkusr in Lua or write some wrappers for the C programs... From 5a092b3b65f846a01d13eb133f4a4f67e51f6396 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:37:36 +0200 Subject: [PATCH 64/67] Some content update... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1d8687..1a2f0d6 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ chkusr is a set of programs (chkgrp, chkpwd and chkpwr) to verify information ab ## The idea -I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Some programs also return a message. +I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Nonetheless, some programs also return a message. ### Requirements From 37a10d5c078336ebf09dbffe5a73a226bd794aa7 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:49:31 +0200 Subject: [PATCH 65/67] Some content update... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a2f0d6..bb931d5 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc ### chkpwr -A program to validate a string with a password rule. More to come... +A program that checks if an input string validates a password rule. More to come... look at the code! ## Links From fd829f156914b492a8d812f2b5861348a961cfe8 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 8 Sep 2025 03:59:43 +0200 Subject: [PATCH 66/67] Some content update... --- README.md | 157 +----------------------------------------------------- 1 file changed, 1 insertion(+), 156 deletions(-) diff --git a/README.md b/README.md index bb931d5..baa738a 100644 --- a/README.md +++ b/README.md @@ -1,161 +1,6 @@ -# THE FOLLOWING DOCUMENTATION WILL NOT WORK ACTUALLY! YOU NEED TO READ THE CODE ACTUALLY, SORRY... - # chkusr chkusr is a set of programs (chkgrp, chkpwd and chkpwr) to verify information about a user and/or group on UNIX based systems. - * [The idea](#the-idea) - * [Requirements](#requirements) - * [Configuration](#configuration) - * [Building chkusr](#building-chkusr) - * [Installation](#installation) - * [Uninstall](#uninstall) - * [Programs](#programs) - * [chkgrp](#chkgrp) - * [chkpwd](#chkpwd) - * [Usage](#usage) - * [Return codes](#return-codes) - * [Examples](#examples) - * [Interactive mode asking for a username and a password](#interactive-mode-asking-for-a-username-and-a-password) - * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) - * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) - * [Request the result from the above commands](#request-the-result-from-the-above-commands) - * [Custom build](#custom-build) - * [chkpwr](#chkpwr) - * [Links](#links) - * [License](#license) - -## The idea - -I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Nonetheless, some programs also return a message. - -### Requirements - -You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is named libpam0g-dev. Not all programs require PAM but you need to edit the Makefile to disable PAM based programs in the build process. - -### Configuration - -chkusr needs to be configured before compilation. Always look at config.h for configuration options. I did it this way because I need the programs as small and simple as possible, and I don't want to parse a configuration file. - -### Building chkusr - -``` -git clone https://git.xw3.org/hanez/chkusr.git -cd chkusr -make -``` - -### Installation - -**WARNING:** Install this software with care. chkpwd could easily be used for bruteforcing passwords from local users! - -``` -sudo make install -``` - -chkusr programs are installed to /usr/bin/. - -chkpwd.h is installed to /usr/include/ for use in other applications. - -### Uninstall - -``` -sudo make uninstall -``` - -## Programs - -### chkgrp - -chkgrp is a program to verify if a user is a member of a group. - -More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. - -### chkpwd - -chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. - -Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. - -The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! - -#### Usage - -``` -chkpwd -h -Usage: chkpwd [-u ] [-p ] [-v] [-V] [-h] - -Options: - -u Set username. - -p Set password. - -v Enable verbose mode. - -V Print program version. - -h Show this help. -``` - -You can also use chkpwd even without installing by just running the following command: - -``` -./chkpwd -``` - -##### Return codes - -chk returns 0 on success, 1 otherwise. - -##### Examples - -###### Interactive mode asking for a username and a password - -``` -chkpwd -``` - -###### Interactive mode only asking for a password - -``` -chkpwd -u hanez -``` - -###### None interactive mode with username and password provided as arguments to chkpwd - -``` -chkpwd -u hanez -p password -``` - -###### Request the result from the above commands - -``` -echo $? -``` - -##### Custom build - -Set MAX_UID and MIN_UID at compile time: - -``` -gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc -``` - -### chkpwr - -A program that checks if an input string validates a password rule. More to come... look at the code! - -## Links - - - [https://git.xw3.org/hanez/chkusr](https://git.xw3.org/hanez/chkusr) - - [https://github.com/shadow-maint/shadow](https://github.com/shadow-maint/shadow) - - [https://github.com/linux-pam/linux-pam](https://github.com/linux-pam/linux-pam) - - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) - - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) - - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) - - [https://github.com/AlexanderZhirov/chkpass](https://github.com/AlexanderZhirov/chkpass) - - [https://github.com/ViKingIX/pam_test](https://github.com/ViKingIX/pam_test) - - [https://github.com/Dareka826/chk_pw](https://github.com/Dareka826/chk_pw) - -## License - -chkusr is licensed under the Apache License, Version 2.0. - -See LICENSE for details. +Go over to [https://hanez.org/project/chkusr/](https://hanez.org/project/chkusr/) for details... From cb8edf2913005d89f829cab25696a715839f4205 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 13 Jan 2026 00:20:45 +0100 Subject: [PATCH 67/67] README update. --- README.md | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index baa738a..d7e1945 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,161 @@ chkusr is a set of programs (chkgrp, chkpwd and chkpwr) to verify information about a user and/or group on UNIX based systems. -Go over to [https://hanez.org/project/chkusr/](https://hanez.org/project/chkusr/) for details... +## THE FOLLOWING DOCUMENTATION WILL NOT WORK ACTUALLY! YOU NEED TO READ THE CODE! SORRY... + + * [The idea](#the-idea) + * [Requirements](#requirements) + * [Configuration](#configuration) + * [Building chkusr](#building-chkusr) + * [Installation](#installation) + * [Uninstall](#uninstall) + * [Programs](#programs) + * [chkgrp](#chkgrp) + * [chkpwd](#chkpwd) + * [Usage](#usage) + * [Return codes](#return-codes) + * [Examples](#examples) + * [Interactive mode asking for a username and a password](#interactive-mode-asking-for-a-username-and-a-password) + * [Interactive mode only asking for a password](#interactive-mode-only-asking-for-a-password) + * [None interactive mode with username and password provided as arguments to chkpwd](#none-interactive-mode-with-username-and-password-provided-as-arguments-to-chkpwd) + * [Request the result from the above commands](#request-the-result-from-the-above-commands) + * [Custom build](#custom-build) + * [chkpwr](#chkpwr) + * [Links](#links) + * [License](#license) + +### The idea + +I needed some programs to verify some information about users and groups on a Linux/UNIX system just returning 0 on success and 1 on error. Nonetheless, some programs also return a message. + +#### Requirements + +You need the PAM development package installed. On Alpine it is named linux-pam-dev, on Debian based systems it is named libpam0g-dev. Not all programs require PAM but you need to edit the Makefile to disable PAM based programs in the build process. + +#### Configuration + +chkusr needs to be configured before compilation. Always look at config.h for configuration options. I did it this way because I need the programs as small and simple as possible, and I don't want to parse a configuration file. + +#### Building chkusr + +``` +git clone https://git.xw3.org/hanez/chkusr.git +cd chkusr +make +``` + +#### Installation + +**WARNING:** Install this software with care. chkpwd could easily be used for bruteforcing passwords from local users! + +``` +sudo make install +``` + +chkusr programs are installed to /usr/bin/. + +chkpwd.h is installed to /usr/include/ for use in other applications. + +#### Uninstall + +``` +sudo make uninstall +``` + +### Programs + +#### chkgrp + +chkgrp is a program to verify if a user is a member of a group. + +More information will follow... Actually there are multiple programs with some different behavior. I will write more about this, but for now I will not. + +#### chkpwd + +chkpwd is a program that checks the validity of a users password on a UNIX/[PAM](https://en.wikipedia.org/wiki/Pluggable_Authentication_Module)-based system. + +Currently chkpwd is only tested on Linux, but it should work on a [AIX](https://en.wikipedia.org/wiki/IBM_AIX), [DragonFly BSD](https://www.dragonflybsd.org/), [FreeBSD](https://www.freebsd.org/), [HP-UX](https://en.wikipedia.org/wiki/HP-UX), [Linux](https://kernel.org/), [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/) and [Solaris](https://en.wikipedia.org/wiki/Oracle_Solaris) operating system too. + +The code only supports verifying passwords for user id 1000 by default. Look at the file chkpwd.h for some compile time options! + +##### Usage + +``` +chkpwd -h +Usage: chkpwd [-u ] [-p ] [-v] [-V] [-h] + +Options: + -u Set username. + -p Set password. + -v Enable verbose mode. + -V Print program version. + -h Show this help. +``` + +You can also use chkpwd even without installing by just running the following command: + +``` +./chkpwd +``` + +##### Return codes + +chk returns 0 on success, 1 otherwise. + +##### Examples + +###### Interactive mode asking for a username and a password + +``` +chkpwd +``` + +###### Interactive mode only asking for a password + +``` +chkpwd -u hanez +``` + +###### None interactive mode with username and password provided as arguments to chkpwd + +``` +chkpwd -u hanez -p password +``` + +###### Request the result from the above commands + +``` +echo $? +``` + +##### Custom build + +Set MAX_UID and MIN_UID at compile time: + +``` +gcc -Wall -DMAX_UID=1000 -DMIN_UID=1000 -o chkpwd chkpwd.c -lpam -lpam_misc +``` + +#### chkpwr + +A program that checks if an input string validates a password rule. More to come... look at the code! + +### Links + + - [https://git.xw3.org/hanez/chkusr](https://git.xw3.org/hanez/chkusr) + - [https://github.com/shadow-maint/shadow](https://github.com/shadow-maint/shadow) + - [https://github.com/linux-pam/linux-pam](https://github.com/linux-pam/linux-pam) + - [https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html](https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html) + - [https://cr.yp.to/checkpwd.html](https://cr.yp.to/checkpwd.html) + - [https://pamtester.sourceforge.net/](https://pamtester.sourceforge.net/) + - [https://github.com/AlexanderZhirov/chkpass](https://github.com/AlexanderZhirov/chkpass) + - [https://github.com/ViKingIX/pam_test](https://github.com/ViKingIX/pam_test) + - [https://github.com/Dareka826/chk_pw](https://github.com/Dareka826/chk_pw) + +### License + +chkusr is licensed under the Apache License, Version 2.0. + +See LICENSE for details. +