pamtest2.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * pamtest2.c - minimal PAM client with a configurable service name.
  3. * Used to exercise pam_fprintd.so against the real GDM service files
  4. * without touching /etc/pam.d (e.g. -s gdm-fingerprint).
  5. *
  6. * Build: gcc -O2 -Wall -o pamtest2 pamtest2.c -lpam
  7. * Run: ./pamtest2 -s gdm-fingerprint [username]
  8. */
  9. #include <security/pam_appl.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. static int noop_conv(int n, const struct pam_message **m,
  14. struct pam_response **r, void *d)
  15. {
  16. (void)n;
  17. (void)m;
  18. (void)r;
  19. (void)d;
  20. return PAM_CONV_ERR;
  21. }
  22. int main(int argc, char **argv)
  23. {
  24. const char *service = "fptest";
  25. const char *user = getenv("USER");
  26. struct pam_conv conv = { noop_conv, NULL };
  27. pam_handle_t *pamh = NULL;
  28. int ret, i;
  29. for (i = 1; i < argc; i++) {
  30. if (strcmp(argv[i], "-s") == 0 && i + 1 < argc)
  31. service = argv[++i];
  32. else
  33. user = argv[i];
  34. }
  35. if (!user)
  36. user = "nobody";
  37. ret = pam_start(service, user, &conv, &pamh);
  38. if (ret != PAM_SUCCESS) {
  39. printf("pam_start: %s\n", pam_strerror(pamh, ret));
  40. return 2;
  41. }
  42. printf("service=%s user=%s\n", service, user);
  43. ret = pam_authenticate(pamh, 0);
  44. printf("\npam_authenticate => %d (%s)\n", ret, pam_strerror(pamh, ret));
  45. pam_end(pamh, ret);
  46. return ret == PAM_SUCCESS ? 0 : 1;
  47. }