xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth2-kbdint.c (revision 1c7715dda22cf2bd169e2f84953c050393e8fe9c)
1*1c7715ddSchristos /*	$NetBSD: auth2-kbdint.c,v 1.16 2024/07/08 22:33:43 christos Exp $	*/
2*1c7715ddSchristos /* $OpenBSD: auth2-kbdint.c,v 1.15 2024/05/17 00:30:23 djm Exp $ */
3*1c7715ddSchristos 
4ca32bd8dSchristos /*
5ca32bd8dSchristos  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
6ca32bd8dSchristos  *
7ca32bd8dSchristos  * Redistribution and use in source and binary forms, with or without
8ca32bd8dSchristos  * modification, are permitted provided that the following conditions
9ca32bd8dSchristos  * are met:
10ca32bd8dSchristos  * 1. Redistributions of source code must retain the above copyright
11ca32bd8dSchristos  *    notice, this list of conditions and the following disclaimer.
12ca32bd8dSchristos  * 2. Redistributions in binary form must reproduce the above copyright
13ca32bd8dSchristos  *    notice, this list of conditions and the following disclaimer in the
14ca32bd8dSchristos  *    documentation and/or other materials provided with the distribution.
15ca32bd8dSchristos  *
16ca32bd8dSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17ca32bd8dSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18ca32bd8dSchristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19ca32bd8dSchristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20ca32bd8dSchristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21ca32bd8dSchristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22ca32bd8dSchristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23ca32bd8dSchristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24ca32bd8dSchristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25ca32bd8dSchristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26ca32bd8dSchristos  */
27ca32bd8dSchristos 
28313c6c94Schristos #include "includes.h"
29*1c7715ddSchristos __RCSID("$NetBSD: auth2-kbdint.c,v 1.16 2024/07/08 22:33:43 christos Exp $");
30ca32bd8dSchristos #include <sys/types.h>
31ca32bd8dSchristos 
32cd4ada6aSchristos #include <stdlib.h>
33cd4ada6aSchristos #include <stdio.h>
34ed75d7a8Schristos #include <stdarg.h>
35cd4ada6aSchristos 
36ca32bd8dSchristos #include "xmalloc.h"
37ca32bd8dSchristos #include "packet.h"
38ca32bd8dSchristos #include "hostfile.h"
39ca32bd8dSchristos #include "auth.h"
40ca32bd8dSchristos #include "log.h"
418a4530f9Schristos #include "misc.h"
42ca32bd8dSchristos #include "servconf.h"
4355a4608bSchristos #include "ssherr.h"
44ca32bd8dSchristos 
45ca32bd8dSchristos /* import */
46ca32bd8dSchristos extern ServerOptions options;
47*1c7715ddSchristos extern struct authmethod_cfg methodcfg_kbdint;
48ca32bd8dSchristos 
49ca32bd8dSchristos static int
userauth_kbdint(struct ssh * ssh,const char * method)50a03ec00cSchristos userauth_kbdint(struct ssh *ssh, const char *method)
51ca32bd8dSchristos {
5255a4608bSchristos 	int r, authenticated = 0;
53ca32bd8dSchristos 	char *lang, *devs;
54ca32bd8dSchristos 
5555a4608bSchristos 	if ((r = sshpkt_get_cstring(ssh, &lang, NULL)) != 0 ||
5655a4608bSchristos 	    (r = sshpkt_get_cstring(ssh, &devs, NULL)) != 0 ||
5755a4608bSchristos 	    (r = sshpkt_get_end(ssh)) != 0)
5817418e98Schristos 		fatal_fr(r, "parse packet");
59ca32bd8dSchristos 
60ca32bd8dSchristos 	debug("keyboard-interactive devs %s", devs);
61ca32bd8dSchristos 
62b592f463Schristos 	if (options.kbd_interactive_authentication)
637a183406Schristos 		authenticated = auth2_challenge(ssh, devs);
64ca32bd8dSchristos 
6500a838c4Schristos 	free(devs);
6600a838c4Schristos 	free(lang);
67ca32bd8dSchristos 	return authenticated;
68ca32bd8dSchristos }
69ca32bd8dSchristos 
70ca32bd8dSchristos Authmethod method_kbdint = {
71*1c7715ddSchristos 	&methodcfg_kbdint,
72ca32bd8dSchristos 	userauth_kbdint,
73ca32bd8dSchristos };
74