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;