vpass.c 928 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "config.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <pwd.h>
  6. #include <sys/types.h>
  7. #include <security/pam_appl.h>
  8. static int
  9. test_conv (int num_msg UNUSED, const struct pam_message **msgm UNUSED,
  10. struct pam_response **response UNUSED, void *appdata_ptr UNUSED)
  11. {
  12. return 0;
  13. }
  14. static struct pam_conv conv = {
  15. test_conv,
  16. NULL
  17. };
  18. int main(void)
  19. {
  20. char *user;
  21. pam_handle_t *pamh;
  22. struct passwd *pw;
  23. uid_t uid;
  24. int res;
  25. uid = geteuid();
  26. pw = getpwuid(uid);
  27. if (pw) {
  28. user = pw->pw_name;
  29. } else {
  30. fprintf(stderr, "Invalid userid: %lu\n", (unsigned long) uid);
  31. exit(1);
  32. }
  33. pam_start("vpass", user, &conv, &pamh);
  34. pam_set_item(pamh, PAM_TTY, "/dev/tty");
  35. if ((res = pam_authenticate(pamh, 0)) != PAM_SUCCESS) {
  36. fprintf(stderr, "Oops: %s\n", pam_strerror(pamh, res));
  37. exit(1);
  38. }
  39. pam_end(pamh, res);
  40. exit(0);
  41. }