2 /* $OpenBSD: auth-chall.c,v 1.12 2006/08/03 03:34:41 deraadt Exp $ */
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
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.
28 __RCSID("$NetBSD: auth-chall.c,v 1.9 2006/09/28 21:22:14 christos Exp $");
29 #include <sys/types.h>
39 extern ServerOptions options
;
40 void remove_kbdint_device(const char *);
43 /* limited protocol v1 interface to kbd-interactive authentication */
45 extern KbdintDevice
*devices
[];
46 static KbdintDevice
*device
;
49 get_challenge(Authctxt
*authctxt
)
51 char *challenge
, *name
, *info
, **prompts
;
57 remove_kbdint_device("pam");
60 device
= devices
[0]; /* we always use the 1st device for protocol 1 */
63 if ((authctxt
->kbdintctxt
= device
->init_ctx(authctxt
)) == NULL
)
65 if (device
->query(authctxt
->kbdintctxt
, &name
, &info
,
66 &numprompts
, &prompts
, &echo_on
)) {
67 device
->free_ctx(authctxt
->kbdintctxt
);
68 authctxt
->kbdintctxt
= NULL
;
72 fatal("get_challenge: numprompts < 1");
73 challenge
= xstrdup(prompts
[0]);
74 for (i
= 0; i
< numprompts
; i
++)
84 verify_response(Authctxt
*authctxt
, const char *response
)
87 int authenticated
= 0;
91 if (authctxt
->kbdintctxt
== NULL
)
93 resp
[0] = (char *)response
;
94 if (device
->respond(authctxt
->kbdintctxt
, 1, resp
) == 0)
96 device
->free_ctx(authctxt
->kbdintctxt
);
97 authctxt
->kbdintctxt
= NULL
;