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 1.0KB

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