You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transaction.c 986B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "_cgo_export.h"
  2. #include <security/pam_appl.h>
  3. #include <string.h>
  4. int cb_pam_conv(
  5. int num_msg,
  6. const struct pam_message **msg,
  7. struct pam_response **resp,
  8. void *appdata_ptr)
  9. {
  10. *resp = calloc(num_msg, sizeof **resp);
  11. if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG) {
  12. return PAM_CONV_ERR;
  13. }
  14. if (!*resp) {
  15. return PAM_BUF_ERR;
  16. }
  17. for (size_t i = 0; i < num_msg; ++i) {
  18. struct cbPAMConv_return result = cbPAMConv(
  19. msg[i]->msg_style,
  20. (char *)msg[i]->msg,
  21. (long)appdata_ptr);
  22. if (result.r1 != PAM_SUCCESS) {
  23. goto error;
  24. }
  25. (*resp)[i].resp = result.r0;
  26. }
  27. return PAM_SUCCESS;
  28. error:
  29. for (size_t i = 0; i < num_msg; ++i) {
  30. if ((*resp)[i].resp) {
  31. memset((*resp)[i].resp, 0, strlen((*resp)[i].resp));
  32. free((*resp)[i].resp);
  33. }
  34. }
  35. memset(*resp, 0, num_msg * sizeof *resp);
  36. free(*resp);
  37. *resp = NULL;
  38. return PAM_CONV_ERR;
  39. }
  40. void init_pam_conv(struct pam_conv *conv, long c)
  41. {
  42. conv->conv = cb_pam_conv;
  43. conv->appdata_ptr = (void *)c;
  44. }