From 23d4719078139d8fade1deb0d1a406c2218f42ef Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Jan 2025 07:19:45 +0100 Subject: [PATCH 01/47] 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 02/47] 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 03/47] 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 04/47] 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 05/47] 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 06/47] 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 07/47] 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 08/47] 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 09/47] 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 10/47] 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 11/47] 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 12/47] 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 13/47] 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 14/47] 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 15/47] 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 16/47] 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 17/47] 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 18/47] 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 19/47] 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 20/47] 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 21/47] 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 22/47] 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 23/47] 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 24/47] 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 25/47] 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 26/47] 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 27/47] 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 28/47] 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 29/47] 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 30/47] 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 31/47] 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 32/47] 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 33/47] 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 34/47] 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 35/47] 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 36/47] 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 37/47] 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 38/47] 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 39/47] 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 40/47] 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 41/47] 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 42/47] 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 43/47] 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 44/47] 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 45/47] 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 46/47] 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 47/47] 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. +