From d819e7c8212de55e97907e418eba2657a7a52668 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 4 Jun 2025 19:06:31 +0200 Subject: [PATCH 01/26] 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 02/26] 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 03/26] 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 04/26] 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 05/26] 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 06/26] 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 07/26] 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 08/26] 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 09/26] 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 10/26] 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 11/26] 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 12/26] 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 13/26] 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 14/26] 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 15/26] 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 16/26] 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 17/26] 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 18/26] 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 19/26] 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 20/26] 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 21/26] 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 22/26] 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 23/26] 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 24/26] 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 25/26] 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 26/26] 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. +