Some housekeeping...

This commit is contained in:
Johannes Findeisen 2025-01-11 04:42:45 +01:00
commit 6d3e3393b5
6 changed files with 19 additions and 8 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
checkpw
checkpw.o
checkpw.1.gz
test
test.c

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -6,6 +6,8 @@
* License: Apache-2.0 (see LICENSE)
*/
#include "checkpw.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -13,8 +15,6 @@
#include <termios.h>
#include <unistd.h>
#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 {

View file

@ -9,10 +9,12 @@
#include <pwd.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <stdbool.h>
#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;