View | Details | Raw Unified | Return to bug 874 | Differences between
and this patch

Collapse All | Expand All

(-)auth-pam.c (+79 lines)
Lines 169-174 static int sshpam_cred_established = 0; Link Here
169
static int sshpam_account_status = -1;
169
static int sshpam_account_status = -1;
170
static char **sshpam_env = NULL;
170
static char **sshpam_env = NULL;
171
static Authctxt *sshpam_authctxt = NULL;
171
static Authctxt *sshpam_authctxt = NULL;
172
static const char *sshpam_password = NULL;
172
173
173
/* Some PAM implementations don't implement this */
174
/* Some PAM implementations don't implement this */
174
#ifndef HAVE_PAM_GETENVLIST
175
#ifndef HAVE_PAM_GETENVLIST
Lines 951-954 free_pam_environment(char **env) Link Here
951
	xfree(env);
952
	xfree(env);
952
}
953
}
953
954
955
static int
956
sshpam_passwd_conv(int n, const struct pam_message **msg,
957
    struct pam_response **resp, void *data)
958
{
959
	struct pam_response *reply;
960
	int i;
961
	size_t len;
962
963
	debug3("PAM: %s called with %d messages", __func__, n);
964
965
	*resp = NULL;
966
967
	if (n <= 0 || n > PAM_MAX_NUM_MSG)
968
		return (PAM_CONV_ERR);
969
970
	if ((reply = malloc(n * sizeof(*reply))) == NULL)
971
		return (PAM_CONV_ERR);
972
	memset(reply, 0, n * sizeof(*reply));
973
974
	for (i = 0; i < n; ++i) {
975
		switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
976
		case PAM_PROMPT_ECHO_OFF:
977
			if (sshpam_password == NULL)
978
				goto fail;
979
			reply[i].resp = xstrdup(sshpam_password);
980
			reply[i].resp_retcode = PAM_SUCCESS;
981
			break;
982
		case PAM_ERROR_MSG:
983
		case PAM_TEXT_INFO:
984
			len = strlen(PAM_MSG_MEMBER(msg, i, msg));
985
			if (len > 0) {
986
				buffer_append(&loginmsg,
987
				    PAM_MSG_MEMBER(msg, i, msg), len);
988
				buffer_append(&loginmsg, "\n", 1);
989
			}
990
			reply[i].resp = xstrdup("");
991
			reply[i].resp_retcode = PAM_SUCCESS;
992
			break;
993
		case PAM_AUTH_ERR:
994
			/* XXX: log error */
995
			/* FALLTHROUGH */
996
		default:
997
			goto fail;
998
		}
999
	}
1000
	*resp = reply;
1001
	return (PAM_SUCCESS);
1002
1003
 fail: 
1004
	for(i = 0; i < n; i++) {
1005
		if (reply[i].resp != NULL)
1006
			xfree(reply[i].resp);
1007
	}
1008
	xfree(reply);
1009
	return (PAM_CONV_ERR);
1010
}
1011
1012
static struct pam_conv passwd_conv = { sshpam_passwd_conv, NULL };
1013
1014
int
1015
sshpam_auth_passwd(Authctxt *authctxt, const char *password)
1016
{
1017
	int result, flags = (options.permit_empty_passwd == 0 ?
1018
	    PAM_DISALLOW_NULL_AUTHTOK : 0);
1019
1020
	sshpam_password = password;
1021
	sshpam_authctxt = authctxt;
1022
1023
	sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
1024
	    (const void *)&passwd_conv);
1025
	if (sshpam_err != PAM_SUCCESS)
1026
		fatal("PAM: %s: failed to set PAM_CONV: %s", __func__,
1027
		    pam_strerror(sshpam_handle, sshpam_err));
1028
1029
	result = pam_authenticate(sshpam_handle, flags);
1030
	sshpam_password = NULL;
1031
	return (result == PAM_SUCCESS);
1032
}
954
#endif /* USE_PAM */
1033
#endif /* USE_PAM */
(-)auth-pam.h (+1 lines)
Lines 44-48 char ** fetch_pam_child_environment(void Link Here
44
void free_pam_environment(char **);
44
void free_pam_environment(char **);
45
void sshpam_thread_cleanup(void);
45
void sshpam_thread_cleanup(void);
46
void sshpam_cleanup(void);
46
void sshpam_cleanup(void);
47
int sshpam_auth_passwd(Authctxt *, const char *);
47
48
48
#endif /* USE_PAM */
49
#endif /* USE_PAM */
(-)auth-passwd.c (+4 lines)
Lines 91-96 auth_password(Authctxt *authctxt, const Link Here
91
		return ok;
91
		return ok;
92
	}
92
	}
93
#endif
93
#endif
94
#ifdef USE_PAM
95
	if (options.use_pam)
96
		return (sshpam_auth_passwd(authctxt, password) && ok);
97
#endif
94
#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
98
#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
95
	if (!expire_checked) {
99
	if (!expire_checked) {
96
		expire_checked = 1;
100
		expire_checked = 1;

Return to bug 874