pamtest.c 1021 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * pamtest.c - minimal PAM client for testing pam_fp.so via the "fptest" service.
  3. * Build: gcc -O2 -Wall -o pamtest pamtest.c -lpam
  4. * Run: ./pamtest <username> (from a terminal; touch sensor or type password)
  5. */
  6. #include <security/pam_appl.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. static int noop_conv(int n, const struct pam_message **m,
  10. struct pam_response **r, void *d)
  11. {
  12. (void)n;
  13. (void)m;
  14. (void)r;
  15. (void)d;
  16. return PAM_CONV_ERR;
  17. }
  18. int main(int argc, char **argv)
  19. {
  20. const char *user = argc > 1 ? argv[1] : getenv("USER");
  21. struct pam_conv conv = { noop_conv, NULL };
  22. pam_handle_t *pamh = NULL;
  23. int ret;
  24. ret = pam_start("fptest", user, &conv, &pamh);
  25. if (ret != PAM_SUCCESS) {
  26. printf("pam_start: %s\n", pam_strerror(pamh, ret));
  27. return 2;
  28. }
  29. ret = pam_authenticate(pamh, 0);
  30. printf("\npam_authenticate => %d (%s)\n", ret, pam_strerror(pamh, ret));
  31. pam_end(pamh, ret);
  32. return ret == PAM_SUCCESS ? 0 : 1;
  33. }