|
Lines 461-466
sshpam_null_conv(int n, struct pam_messa
Link Here
|
| 461 |
|
461 |
|
| 462 |
static struct pam_conv null_conv = { sshpam_null_conv, NULL }; |
462 |
static struct pam_conv null_conv = { sshpam_null_conv, NULL }; |
| 463 |
|
463 |
|
|
|
464 |
static int |
| 465 |
sshpam_store_conv(int n, struct pam_message **msg, |
| 466 |
struct pam_response **resp, void *data) |
| 467 |
{ |
| 468 |
struct pam_response *reply; |
| 469 |
int i; |
| 470 |
size_t len; |
| 471 |
|
| 472 |
debug3("PAM: %s called with %d messages", __func__, n); |
| 473 |
*resp = NULL; |
| 474 |
|
| 475 |
if (n <= 0 || n > PAM_MAX_NUM_MSG) |
| 476 |
return (PAM_CONV_ERR); |
| 477 |
|
| 478 |
if ((reply = malloc(n * sizeof(*reply))) == NULL) |
| 479 |
return (PAM_CONV_ERR); |
| 480 |
memset(reply, 0, n * sizeof(*reply)); |
| 481 |
|
| 482 |
for (i = 0; i < n; ++i) { |
| 483 |
switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 484 |
case PAM_ERROR_MSG: |
| 485 |
case PAM_TEXT_INFO: |
| 486 |
len = strlen(PAM_MSG_MEMBER(msg, i, msg)); |
| 487 |
buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len); |
| 488 |
buffer_append(&loginmsg, "\n", 1 ); |
| 489 |
reply[i].resp_retcode = PAM_SUCCESS; |
| 490 |
break; |
| 491 |
default: |
| 492 |
goto fail; |
| 493 |
} |
| 494 |
} |
| 495 |
*resp = reply; |
| 496 |
return (PAM_SUCCESS); |
| 497 |
|
| 498 |
fail: |
| 499 |
for(i = 0; i < n; i++) { |
| 500 |
if (reply[i].resp != NULL) |
| 501 |
xfree(reply[i].resp); |
| 502 |
} |
| 503 |
xfree(reply); |
| 504 |
return (PAM_CONV_ERR); |
| 505 |
} |
| 506 |
|
| 507 |
static struct pam_conv store_conv = { sshpam_store_conv, NULL }; |
| 508 |
|
| 464 |
void |
509 |
void |
| 465 |
sshpam_cleanup(void) |
510 |
sshpam_cleanup(void) |
| 466 |
{ |
511 |
{ |
|
Lines 498-504
sshpam_init(Authctxt *authctxt)
Link Here
|
| 498 |
} |
543 |
} |
| 499 |
debug("PAM: initializing for \"%s\"", user); |
544 |
debug("PAM: initializing for \"%s\"", user); |
| 500 |
sshpam_err = |
545 |
sshpam_err = |
| 501 |
pam_start(SSHD_PAM_SERVICE, user, &null_conv, &sshpam_handle); |
546 |
pam_start(SSHD_PAM_SERVICE, user, &store_conv, &sshpam_handle); |
| 502 |
sshpam_authctxt = authctxt; |
547 |
sshpam_authctxt = authctxt; |
| 503 |
|
548 |
|
| 504 |
if (sshpam_err != PAM_SUCCESS) { |
549 |
if (sshpam_err != PAM_SUCCESS) { |
|
Lines 730-740
finish_pam(void)
Link Here
|
| 730 |
u_int |
775 |
u_int |
| 731 |
do_pam_account(void) |
776 |
do_pam_account(void) |
| 732 |
{ |
777 |
{ |
|
|
778 |
debug("%s: called", __func__); |
| 733 |
if (sshpam_account_status != -1) |
779 |
if (sshpam_account_status != -1) |
| 734 |
return (sshpam_account_status); |
780 |
return (sshpam_account_status); |
| 735 |
|
781 |
|
| 736 |
sshpam_err = pam_acct_mgmt(sshpam_handle, 0); |
782 |
sshpam_err = pam_acct_mgmt(sshpam_handle, 0); |
| 737 |
debug3("PAM: %s pam_acct_mgmt = %d", __func__, sshpam_err); |
783 |
debug3("PAM: %s pam_acct_mgmt = %d (%s)", __func__, sshpam_err, |
|
|
784 |
pam_strerror(sshpam_handle, sshpam_err)); |
| 738 |
|
785 |
|
| 739 |
if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) { |
786 |
if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) { |
| 740 |
sshpam_account_status = 0; |
787 |
sshpam_account_status = 0; |
|
Lines 764-770
void
Link Here
|
| 764 |
do_pam_setcred(int init) |
811 |
do_pam_setcred(int init) |
| 765 |
{ |
812 |
{ |
| 766 |
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
813 |
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
| 767 |
(const void *)&null_conv); |
814 |
(const void *)&store_conv); |
| 768 |
if (sshpam_err != PAM_SUCCESS) |
815 |
if (sshpam_err != PAM_SUCCESS) |
| 769 |
fatal("PAM: failed to set PAM_CONV: %s", |
816 |
fatal("PAM: failed to set PAM_CONV: %s", |
| 770 |
pam_strerror(sshpam_handle, sshpam_err)); |
817 |
pam_strerror(sshpam_handle, sshpam_err)); |
|
Lines 863-913
do_pam_chauthtok(void)
Link Here
|
| 863 |
fatal("PAM: pam_chauthtok(): %s", |
910 |
fatal("PAM: pam_chauthtok(): %s", |
| 864 |
pam_strerror(sshpam_handle, sshpam_err)); |
911 |
pam_strerror(sshpam_handle, sshpam_err)); |
| 865 |
} |
912 |
} |
| 866 |
|
|
|
| 867 |
static int |
| 868 |
sshpam_store_conv(int n, struct pam_message **msg, |
| 869 |
struct pam_response **resp, void *data) |
| 870 |
{ |
| 871 |
struct pam_response *reply; |
| 872 |
int i; |
| 873 |
size_t len; |
| 874 |
|
| 875 |
debug3("PAM: %s called with %d messages", __func__, n); |
| 876 |
*resp = NULL; |
| 877 |
|
| 878 |
if (n <= 0 || n > PAM_MAX_NUM_MSG) |
| 879 |
return (PAM_CONV_ERR); |
| 880 |
|
| 881 |
if ((reply = malloc(n * sizeof(*reply))) == NULL) |
| 882 |
return (PAM_CONV_ERR); |
| 883 |
memset(reply, 0, n * sizeof(*reply)); |
| 884 |
|
| 885 |
for (i = 0; i < n; ++i) { |
| 886 |
switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 887 |
case PAM_ERROR_MSG: |
| 888 |
case PAM_TEXT_INFO: |
| 889 |
len = strlen(PAM_MSG_MEMBER(msg, i, msg)); |
| 890 |
buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len); |
| 891 |
buffer_append(&loginmsg, "\n", 1 ); |
| 892 |
reply[i].resp_retcode = PAM_SUCCESS; |
| 893 |
break; |
| 894 |
default: |
| 895 |
goto fail; |
| 896 |
} |
| 897 |
} |
| 898 |
*resp = reply; |
| 899 |
return (PAM_SUCCESS); |
| 900 |
|
| 901 |
fail: |
| 902 |
for(i = 0; i < n; i++) { |
| 903 |
if (reply[i].resp != NULL) |
| 904 |
xfree(reply[i].resp); |
| 905 |
} |
| 906 |
xfree(reply); |
| 907 |
return (PAM_CONV_ERR); |
| 908 |
} |
| 909 |
|
| 910 |
static struct pam_conv store_conv = { sshpam_store_conv, NULL }; |
| 911 |
|
913 |
|
| 912 |
void |
914 |
void |
| 913 |
do_pam_session(void) |
915 |
do_pam_session(void) |