version 1.47, 2017/05/30 14:23:52 |
version 1.48, 2017/05/30 14:29:59 |
|
|
#include "dispatch.h" |
#include "dispatch.h" |
#include "log.h" |
#include "log.h" |
|
|
static int auth2_challenge_start(Authctxt *); |
static int auth2_challenge_start(struct ssh *); |
static int send_userauth_info_request(Authctxt *); |
static int send_userauth_info_request(Authctxt *); |
static int input_userauth_info_response(int, u_int32_t, struct ssh *); |
static int input_userauth_info_response(int, u_int32_t, struct ssh *); |
|
|
|
|
* wait for the response. |
* wait for the response. |
*/ |
*/ |
int |
int |
auth2_challenge(Authctxt *authctxt, char *devs) |
auth2_challenge(struct ssh *ssh, char *devs) |
{ |
{ |
|
Authctxt *authctxt = ssh->authctxt; |
debug("auth2_challenge: user=%s devs=%s", |
debug("auth2_challenge: user=%s devs=%s", |
authctxt->user ? authctxt->user : "<nouser>", |
authctxt->user ? authctxt->user : "<nouser>", |
devs ? devs : "<no devs>"); |
devs ? devs : "<no devs>"); |
|
|
return 0; |
return 0; |
if (authctxt->kbdintctxt == NULL) |
if (authctxt->kbdintctxt == NULL) |
authctxt->kbdintctxt = kbdint_alloc(devs); |
authctxt->kbdintctxt = kbdint_alloc(devs); |
return auth2_challenge_start(authctxt); |
return auth2_challenge_start(ssh); |
} |
} |
|
|
/* unregister kbd-int callbacks and context */ |
/* unregister kbd-int callbacks and context */ |
void |
void |
auth2_challenge_stop(Authctxt *authctxt) |
auth2_challenge_stop(struct ssh *ssh) |
{ |
{ |
|
Authctxt *authctxt = ssh->authctxt; |
/* unregister callback */ |
/* unregister callback */ |
dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL); |
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL); |
if (authctxt->kbdintctxt != NULL) { |
if (authctxt->kbdintctxt != NULL) { |
kbdint_free(authctxt->kbdintctxt); |
kbdint_free(authctxt->kbdintctxt); |
authctxt->kbdintctxt = NULL; |
authctxt->kbdintctxt = NULL; |
|
|
|
|
/* side effect: sets authctxt->postponed if a reply was sent*/ |
/* side effect: sets authctxt->postponed if a reply was sent*/ |
static int |
static int |
auth2_challenge_start(Authctxt *authctxt) |
auth2_challenge_start(struct ssh *ssh) |
{ |
{ |
|
Authctxt *authctxt = ssh->authctxt; |
KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt; |
KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt; |
|
|
debug2("auth2_challenge_start: devices %s", |
debug2("auth2_challenge_start: devices %s", |
kbdintctxt->devices ? kbdintctxt->devices : "<empty>"); |
kbdintctxt->devices ? kbdintctxt->devices : "<empty>"); |
|
|
if (kbdint_next_device(authctxt, kbdintctxt) == 0) { |
if (kbdint_next_device(authctxt, kbdintctxt) == 0) { |
auth2_challenge_stop(authctxt); |
auth2_challenge_stop(ssh); |
return 0; |
return 0; |
} |
} |
debug("auth2_challenge_start: trying authentication method '%s'", |
debug("auth2_challenge_start: trying authentication method '%s'", |
kbdintctxt->device->name); |
kbdintctxt->device->name); |
|
|
if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) { |
if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) { |
auth2_challenge_stop(authctxt); |
auth2_challenge_stop(ssh); |
return 0; |
return 0; |
} |
} |
if (send_userauth_info_request(authctxt) == 0) { |
if (send_userauth_info_request(authctxt) == 0) { |
auth2_challenge_stop(authctxt); |
auth2_challenge_stop(ssh); |
return 0; |
return 0; |
} |
} |
dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, |
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE, |
&input_userauth_info_response); |
&input_userauth_info_response); |
|
|
authctxt->postponed = 1; |
authctxt->postponed = 1; |
|
|
devicename = kbdintctxt->device->name; |
devicename = kbdintctxt->device->name; |
if (!authctxt->postponed) { |
if (!authctxt->postponed) { |
if (authenticated) { |
if (authenticated) { |
auth2_challenge_stop(authctxt); |
auth2_challenge_stop(ssh); |
} else { |
} else { |
/* start next device */ |
/* start next device */ |
/* may set authctxt->postponed */ |
/* may set authctxt->postponed */ |
auth2_challenge_start(authctxt); |
auth2_challenge_start(ssh); |
} |
} |
} |
} |
userauth_finish(authctxt, authenticated, "keyboard-interactive", |
userauth_finish(ssh, authenticated, "keyboard-interactive", |
devicename); |
devicename); |
return 0; |
return 0; |
} |
} |