ssh has moved
[netbsd-mini2440.git] / crypto / dist / ssh / auth-chall.c
blob1a365b860323f4e82dc8df935a30e3496577a52a
1 /* $NetBSD$ */
2 /* $OpenBSD: auth-chall.c,v 1.12 2006/08/03 03:34:41 deraadt Exp $ */
3 /*
4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "includes.h"
28 __RCSID("$NetBSD: auth-chall.c,v 1.6 2003/07/10 01:09:41 lukem Exp $");
29 #include <sys/types.h>
31 #include "xmalloc.h"
32 #include "key.h"
33 #include "hostfile.h"
34 #include "auth.h"
35 #include "log.h"
36 #ifdef USE_PAM
37 #include "buffer.h"
38 #include "servconf.h"
39 extern ServerOptions options;
40 void remove_kbdint_device(const char *);
41 #endif
43 /* limited protocol v1 interface to kbd-interactive authentication */
45 extern KbdintDevice *devices[];
46 static KbdintDevice *device;
48 char *
49 get_challenge(Authctxt *authctxt)
51 char *challenge, *name, *info, **prompts;
52 u_int i, numprompts;
53 u_int *echo_on;
55 #ifdef USE_PAM
56 if (!options.use_pam)
57 remove_kbdint_device("pam");
58 #endif
60 device = devices[0]; /* we always use the 1st device for protocol 1 */
61 if (device == NULL)
62 return NULL;
63 if ((authctxt->kbdintctxt = device->init_ctx(authctxt)) == NULL)
64 return NULL;
65 if (device->query(authctxt->kbdintctxt, &name, &info,
66 &numprompts, &prompts, &echo_on)) {
67 device->free_ctx(authctxt->kbdintctxt);
68 authctxt->kbdintctxt = NULL;
69 return NULL;
71 if (numprompts < 1)
72 fatal("get_challenge: numprompts < 1");
73 challenge = xstrdup(prompts[0]);
74 for (i = 0; i < numprompts; i++)
75 xfree(prompts[i]);
76 xfree(prompts);
77 xfree(name);
78 xfree(echo_on);
79 xfree(info);
81 return (challenge);
83 int
84 verify_response(Authctxt *authctxt, const char *response)
86 char *resp[1];
87 int authenticated = 0;
89 if (device == NULL)
90 return 0;
91 if (authctxt->kbdintctxt == NULL)
92 return 0;
93 resp[0] = (char *)response;
94 if (device->respond(authctxt->kbdintctxt, 1, resp) == 0)
95 authenticated = 1;
96 device->free_ctx(authctxt->kbdintctxt);
97 authctxt->kbdintctxt = NULL;
98 return authenticated;