xref: /dragonfly/crypto/openssh/auth2-kbdint.c (revision ba1276ac)
1*ba1276acSMatthew Dillon /* $OpenBSD: auth2-kbdint.c,v 1.15 2024/05/17 00:30:23 djm Exp $ */
218de8d7fSPeter Avalos /*
318de8d7fSPeter Avalos  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
418de8d7fSPeter Avalos  *
518de8d7fSPeter Avalos  * Redistribution and use in source and binary forms, with or without
618de8d7fSPeter Avalos  * modification, are permitted provided that the following conditions
718de8d7fSPeter Avalos  * are met:
818de8d7fSPeter Avalos  * 1. Redistributions of source code must retain the above copyright
918de8d7fSPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1018de8d7fSPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1118de8d7fSPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1218de8d7fSPeter Avalos  *    documentation and/or other materials provided with the distribution.
1318de8d7fSPeter Avalos  *
1418de8d7fSPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1518de8d7fSPeter Avalos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1618de8d7fSPeter Avalos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1718de8d7fSPeter Avalos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1818de8d7fSPeter Avalos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1918de8d7fSPeter Avalos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2018de8d7fSPeter Avalos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2118de8d7fSPeter Avalos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2218de8d7fSPeter Avalos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2318de8d7fSPeter Avalos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2418de8d7fSPeter Avalos  */
2518de8d7fSPeter Avalos 
2618de8d7fSPeter Avalos #include "includes.h"
2718de8d7fSPeter Avalos 
2818de8d7fSPeter Avalos #include <sys/types.h>
2918de8d7fSPeter Avalos 
300cbfa66cSDaniel Fojt #include <stdlib.h>
310cbfa66cSDaniel Fojt #include <stdio.h>
3218de8d7fSPeter Avalos #include <stdarg.h>
3318de8d7fSPeter Avalos 
3418de8d7fSPeter Avalos #include "xmalloc.h"
3518de8d7fSPeter Avalos #include "packet.h"
3618de8d7fSPeter Avalos #include "hostfile.h"
3718de8d7fSPeter Avalos #include "auth.h"
3818de8d7fSPeter Avalos #include "log.h"
3936e94dc5SPeter Avalos #include "misc.h"
4018de8d7fSPeter Avalos #include "servconf.h"
41664f4763Szrj #include "ssherr.h"
4218de8d7fSPeter Avalos 
4318de8d7fSPeter Avalos /* import */
4418de8d7fSPeter Avalos extern ServerOptions options;
45*ba1276acSMatthew Dillon extern struct authmethod_cfg methodcfg_kbdint;
4618de8d7fSPeter Avalos 
4718de8d7fSPeter Avalos static int
userauth_kbdint(struct ssh * ssh,const char * method)48ee116499SAntonio Huete Jimenez userauth_kbdint(struct ssh *ssh, const char *method)
4918de8d7fSPeter Avalos {
50664f4763Szrj 	int r, authenticated = 0;
5118de8d7fSPeter Avalos 	char *lang, *devs;
5218de8d7fSPeter Avalos 
53664f4763Szrj 	if ((r = sshpkt_get_cstring(ssh, &lang, NULL)) != 0 ||
54664f4763Szrj 	    (r = sshpkt_get_cstring(ssh, &devs, NULL)) != 0 ||
55664f4763Szrj 	    (r = sshpkt_get_end(ssh)) != 0)
5650a69bb5SSascha Wildner 		fatal_fr(r, "parse packet");
5718de8d7fSPeter Avalos 
5818de8d7fSPeter Avalos 	debug("keyboard-interactive devs %s", devs);
5918de8d7fSPeter Avalos 
6050a69bb5SSascha Wildner 	if (options.kbd_interactive_authentication)
61ce74bacaSMatthew Dillon 		authenticated = auth2_challenge(ssh, devs);
6218de8d7fSPeter Avalos 
6336e94dc5SPeter Avalos 	free(devs);
6436e94dc5SPeter Avalos 	free(lang);
6518de8d7fSPeter Avalos 	return authenticated;
6618de8d7fSPeter Avalos }
6718de8d7fSPeter Avalos 
6818de8d7fSPeter Avalos Authmethod method_kbdint = {
69*ba1276acSMatthew Dillon 	&methodcfg_kbdint,
7018de8d7fSPeter Avalos 	userauth_kbdint,
7118de8d7fSPeter Avalos };
72