xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth2-kbdint.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: auth2-kbdint.c,v 1.15 2022/02/23 19:07:20 christos Exp $	*/
2 /* $OpenBSD: auth2-kbdint.c,v 1.14 2021/12/19 22:12:07 djm Exp $ */
3 /*
4  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
5  *
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.
14  *
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.
25  */
26 
27 #include "includes.h"
28 __RCSID("$NetBSD: auth2-kbdint.c,v 1.15 2022/02/23 19:07:20 christos Exp $");
29 #include <sys/types.h>
30 
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 
35 #include "xmalloc.h"
36 #include "packet.h"
37 #include "hostfile.h"
38 #include "auth.h"
39 #include "log.h"
40 #include "misc.h"
41 #include "servconf.h"
42 #include "ssherr.h"
43 
44 /* import */
45 extern ServerOptions options;
46 
47 static int
48 userauth_kbdint(struct ssh *ssh, const char *method)
49 {
50 	int r, authenticated = 0;
51 	char *lang, *devs;
52 
53 	if ((r = sshpkt_get_cstring(ssh, &lang, NULL)) != 0 ||
54 	    (r = sshpkt_get_cstring(ssh, &devs, NULL)) != 0 ||
55 	    (r = sshpkt_get_end(ssh)) != 0)
56 		fatal_fr(r, "parse packet");
57 
58 	debug("keyboard-interactive devs %s", devs);
59 
60 	if (options.kbd_interactive_authentication)
61 		authenticated = auth2_challenge(ssh, devs);
62 
63 	free(devs);
64 	free(lang);
65 	return authenticated;
66 }
67 
68 Authmethod method_kbdint = {
69 	"keyboard-interactive",
70 	NULL,
71 	userauth_kbdint,
72 	&options.kbd_interactive_authentication
73 };
74