chkusr
Table of contents
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
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-based system.
Currently chkpwd is only tested on Linux, but it should work on a AIX, DragonFly BSD, FreeBSD, HP-UX, Linux, macOS, NetBSD and 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 <username>] [-p <password>] [-v] [-V] [-h]
Options:
-u <username> Set username.
-p <password> 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://github.com/shadow-maint/shadow
- https://github.com/linux-pam/linux-pam
- https://www.man7.org/linux/man-pages/man8/unix_chkpwd.8.html
- https://cr.yp.to/checkpwd.html
- https://pamtester.sourceforge.net/
- https://github.com/AlexanderZhirov/chkpass
- https://github.com/ViKingIX/pam_test
- https://github.com/Dareka826/chk_pw
License
chkusr is licensed under the Apache License, Version 2.0.
See LICENSE for details.