summaryrefslogtreecommitdiff
path: root/auth2-chall.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-12-21 12:42:34 +1100
committerDamien Miller <djm@mindrot.org>2001-12-21 12:42:34 +1100
commitee11625d4309da4d4eb7a307a2a58f35354a001a (patch)
tree11bf0af76b554ec62d238faf1861211763ae18e2 /auth2-chall.c
parent3afe375fd288327716a4a6f1cfc05b1ff6535152 (diff)
- markus@cvs.openbsd.org 2001/12/09 18:45:56
[auth2.c auth2-chall.c auth.h] add auth2_challenge_stop(), simplifies cleanup of kbd-int sessions, fixes memleak.
Diffstat (limited to 'auth2-chall.c')
-rw-r--r--auth2-chall.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/auth2-chall.c b/auth2-chall.c
index 5e6a691f8..4b97e47bd 100644
--- a/auth2-chall.c
+++ b/auth2-chall.c
@@ -23,7 +23,7 @@
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: auth2-chall.c,v 1.8 2001/09/27 15:31:17 markus Exp $"); 26RCSID("$OpenBSD: auth2-chall.c,v 1.9 2001/12/09 18:45:56 markus Exp $");
27 27
28#include "ssh2.h" 28#include "ssh2.h"
29#include "auth.h" 29#include "auth.h"
@@ -156,6 +156,18 @@ auth2_challenge(Authctxt *authctxt, char *devs)
156 return auth2_challenge_start(authctxt); 156 return auth2_challenge_start(authctxt);
157} 157}
158 158
159/* unregister kbd-int callbacks and context */
160void
161auth2_challenge_stop(Authctxt *authctxt)
162{
163 /* unregister callback */
164 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
165 if (authctxt->kbdintctxt != NULL) {
166 kbdint_free(authctxt->kbdintctxt);
167 authctxt->kbdintctxt = NULL;
168 }
169}
170
159/* side effect: sets authctxt->postponed if a reply was sent*/ 171/* side effect: sets authctxt->postponed if a reply was sent*/
160static int 172static int
161auth2_challenge_start(Authctxt *authctxt) 173auth2_challenge_start(Authctxt *authctxt)
@@ -166,21 +178,18 @@ auth2_challenge_start(Authctxt *authctxt)
166 kbdintctxt->devices ? kbdintctxt->devices : "<empty>"); 178 kbdintctxt->devices ? kbdintctxt->devices : "<empty>");
167 179
168 if (kbdint_next_device(kbdintctxt) == 0) { 180 if (kbdint_next_device(kbdintctxt) == 0) {
169 kbdint_free(kbdintctxt); 181 auth2_challenge_stop(authctxt);
170 authctxt->kbdintctxt = NULL;
171 return 0; 182 return 0;
172 } 183 }
173 debug("auth2_challenge_start: trying authentication method '%s'", 184 debug("auth2_challenge_start: trying authentication method '%s'",
174 kbdintctxt->device->name); 185 kbdintctxt->device->name);
175 186
176 if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) { 187 if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) {
177 kbdint_free(kbdintctxt); 188 auth2_challenge_stop(authctxt);
178 authctxt->kbdintctxt = NULL;
179 return 0; 189 return 0;
180 } 190 }
181 if (send_userauth_info_request(authctxt) == 0) { 191 if (send_userauth_info_request(authctxt) == 0) {
182 kbdint_free(kbdintctxt); 192 auth2_challenge_stop(authctxt);
183 authctxt->kbdintctxt = NULL;
184 return 0; 193 return 0;
185 } 194 }
186 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, 195 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE,
@@ -271,10 +280,8 @@ input_userauth_info_response(int type, int plen, void *ctxt)
271 break; 280 break;
272 case 1: 281 case 1:
273 /* Authentication needs further interaction */ 282 /* Authentication needs further interaction */
274 authctxt->postponed = 1; 283 if (send_userauth_info_request(authctxt) == 1)
275 if (send_userauth_info_request(authctxt) == 0) { 284 authctxt->postponed = 1;
276 authctxt->postponed = 0;
277 }
278 break; 285 break;
279 default: 286 default:
280 /* Failure! */ 287 /* Failure! */
@@ -290,12 +297,8 @@ input_userauth_info_response(int type, int plen, void *ctxt)
290 strlcat(method, kbdintctxt->device->name, len); 297 strlcat(method, kbdintctxt->device->name, len);
291 298
292 if (!authctxt->postponed) { 299 if (!authctxt->postponed) {
293 /* unregister callback */
294 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
295
296 if (authenticated) { 300 if (authenticated) {
297 kbdint_free(kbdintctxt); 301 auth2_challenge_stop(authctxt);
298 authctxt->kbdintctxt = NULL;
299 } else { 302 } else {
300 /* start next device */ 303 /* start next device */
301 /* may set authctxt->postponed */ 304 /* may set authctxt->postponed */