|
Lines 617-622
Link Here
|
| 617 |
sshpam_handle = NULL; |
617 |
sshpam_handle = NULL; |
| 618 |
} |
618 |
} |
| 619 |
|
619 |
|
|
|
620 |
#ifdef PAM_ENHANCEMENT |
| 621 |
char * |
| 622 |
derive_pam_service_name(Authctxt *authctxt) |
| 623 |
{ |
| 624 |
char *svcname = xmalloc(BUFSIZ); |
| 625 |
|
| 626 |
/* |
| 627 |
* If PamServiceName is set we use that for everything, including |
| 628 |
* SSHv1 |
| 629 |
*/ |
| 630 |
if (options.pam_service_name != NULL) { |
| 631 |
(void) strlcpy(svcname, options.pam_service_name, BUFSIZ); |
| 632 |
return (svcname); |
| 633 |
} |
| 634 |
|
| 635 |
if (compat20) { |
| 636 |
char *method_name = authctxt->authmethod_name; |
| 637 |
|
| 638 |
if (!method_name) |
| 639 |
fatal("Userauth method unknown while starting PAM"); |
| 640 |
|
| 641 |
/* |
| 642 |
* For SSHv2 we use "sshd-<userauth name> |
| 643 |
* The "sshd" prefix can be changed via the PAMServicePrefix |
| 644 |
* sshd_config option. |
| 645 |
*/ |
| 646 |
if (strcmp(method_name, "none") == 0) { |
| 647 |
snprintf(svcname, BUFSIZ, "%s-none", |
| 648 |
options.pam_service_prefix); |
| 649 |
} |
| 650 |
if (strcmp(method_name, "password") == 0) { |
| 651 |
snprintf(svcname, BUFSIZ, "%s-password", |
| 652 |
options.pam_service_prefix); |
| 653 |
} |
| 654 |
if (strcmp(method_name, "keyboard-interactive") == 0) { |
| 655 |
/* "keyboard-interactive" is too long, shorten it */ |
| 656 |
snprintf(svcname, BUFSIZ, "%s-kbdint", |
| 657 |
options.pam_service_prefix); |
| 658 |
} |
| 659 |
if (strcmp(method_name, "publickey") == 0) { |
| 660 |
/* "publickey" is too long, shorten it */ |
| 661 |
snprintf(svcname, BUFSIZ, "%s-pubkey", |
| 662 |
options.pam_service_prefix); |
| 663 |
} |
| 664 |
if (strcmp(method_name, "hostbased") == 0) { |
| 665 |
snprintf(svcname, BUFSIZ, "%s-hostbased", |
| 666 |
options.pam_service_prefix); |
| 667 |
} |
| 668 |
if (strncmp(method_name, "gssapi-", 7) == 0) { |
| 669 |
/* |
| 670 |
* Although OpenSSH only supports "gssapi-with-mic" |
| 671 |
* for now. We will still map any userauth method |
| 672 |
* prefixed with "gssapi-" to the gssapi PAM service. |
| 673 |
*/ |
| 674 |
snprintf(svcname, BUFSIZ, "%s-gssapi", |
| 675 |
options.pam_service_prefix); |
| 676 |
} |
| 677 |
return svcname; |
| 678 |
} else { |
| 679 |
/* SSHv1 doesn't get to be so cool */ |
| 680 |
snprintf(svcname, BUFSIZ, "sshd-v1"); |
| 681 |
} |
| 682 |
return svcname; |
| 683 |
} |
| 684 |
#endif /* PAM_ENHANCEMENT */ |
| 685 |
|
| 620 |
static int |
686 |
static int |
| 621 |
sshpam_init(Authctxt *authctxt) |
687 |
sshpam_init(Authctxt *authctxt) |
| 622 |
{ |
688 |
{ |
|
Lines 624-641
Link Here
|
| 624 |
const char *pam_rhost, *pam_user, *user = authctxt->user; |
690 |
const char *pam_rhost, *pam_user, *user = authctxt->user; |
| 625 |
const char **ptr_pam_user = &pam_user; |
691 |
const char **ptr_pam_user = &pam_user; |
| 626 |
|
692 |
|
|
|
693 |
#ifdef PAM_ENHANCEMENT |
| 694 |
const char *pam_service; |
| 695 |
const char **ptr_pam_service = &pam_service; |
| 696 |
char *svc = NULL; |
| 697 |
|
| 698 |
svc = derive_pam_service_name(authctxt); |
| 699 |
debug3("PAM service is %s", svc); |
| 700 |
#endif |
| 701 |
|
| 627 |
if (sshpam_handle != NULL) { |
702 |
if (sshpam_handle != NULL) { |
|
|
703 |
#ifdef PAM_ENHANCEMENT |
| 704 |
/* get the pam service name */ |
| 705 |
sshpam_err = pam_get_item(sshpam_handle, |
| 706 |
PAM_SERVICE, (sshpam_const void **)ptr_pam_service); |
| 707 |
if (sshpam_err != PAM_SUCCESS) |
| 708 |
fatal("Failed to get the PAM service name"); |
| 709 |
debug3("Previous pam_service is %s", pam_service ? |
| 710 |
pam_service : "NULL"); |
| 711 |
|
| 712 |
/* get the pam user name */ |
| 713 |
sshpam_err = pam_get_item(sshpam_handle, |
| 714 |
PAM_USER, (sshpam_const void **)ptr_pam_user); |
| 715 |
|
| 716 |
/* |
| 717 |
* only need to re-start if either user or service is |
| 718 |
* different. |
| 719 |
*/ |
| 720 |
if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0 |
| 721 |
&& strncmp(svc, pam_service, strlen(svc)) == 0) { |
| 722 |
free(svc); |
| 723 |
return (0); |
| 724 |
} |
| 725 |
|
| 726 |
#else /* Original */ |
| 628 |
/* We already have a PAM context; check if the user matches */ |
727 |
/* We already have a PAM context; check if the user matches */ |
| 629 |
sshpam_err = pam_get_item(sshpam_handle, |
728 |
sshpam_err = pam_get_item(sshpam_handle, |
| 630 |
PAM_USER, (sshpam_const void **)ptr_pam_user); |
729 |
PAM_USER, (sshpam_const void **)ptr_pam_user); |
| 631 |
if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0) |
730 |
if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0) |
| 632 |
return (0); |
731 |
return (0); |
|
|
732 |
#endif /* PAM_ENHANCEMENT */ |
| 633 |
pam_end(sshpam_handle, sshpam_err); |
733 |
pam_end(sshpam_handle, sshpam_err); |
| 634 |
sshpam_handle = NULL; |
734 |
sshpam_handle = NULL; |
| 635 |
} |
735 |
} |
| 636 |
debug("PAM: initializing for \"%s\"", user); |
736 |
debug("PAM: initializing for \"%s\"", user); |
|
|
737 |
|
| 738 |
#ifdef PAM_ENHANCEMENT |
| 739 |
debug3("Starting PAM service %s for user %s method %s", svc, user, |
| 740 |
authctxt->authmethod_name); |
| 637 |
sshpam_err = |
741 |
sshpam_err = |
|
|
742 |
pam_start(svc, user, &store_conv, &sshpam_handle); |
| 743 |
free(svc); |
| 744 |
#else /* Original */ |
| 745 |
sshpam_err = |
| 638 |
pam_start(SSHD_PAM_SERVICE, user, &store_conv, &sshpam_handle); |
746 |
pam_start(SSHD_PAM_SERVICE, user, &store_conv, &sshpam_handle); |
|
|
747 |
#endif |
| 639 |
sshpam_authctxt = authctxt; |
748 |
sshpam_authctxt = authctxt; |
| 640 |
|
749 |
|
| 641 |
if (sshpam_err != PAM_SUCCESS) { |
750 |
if (sshpam_err != PAM_SUCCESS) { |