xref: /titanic_50/usr/src/cmd/ssh/sshd/auth2-kbdint.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
5*7c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
6*7c478bd9Sstevel@tonic-gate  * are met:
7*7c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
8*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
9*7c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
10*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
11*7c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
12*7c478bd9Sstevel@tonic-gate  *
13*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15*7c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16*7c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17*7c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18*7c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19*7c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20*7c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21*7c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*7c478bd9Sstevel@tonic-gate  */
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
27*7c478bd9Sstevel@tonic-gate  */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include "includes.h"
30*7c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth2-kbdint.c,v 1.2 2002/05/31 11:35:15 markus Exp $");
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include "packet.h"
35*7c478bd9Sstevel@tonic-gate #include "auth.h"
36*7c478bd9Sstevel@tonic-gate #include "log.h"
37*7c478bd9Sstevel@tonic-gate #include "servconf.h"
38*7c478bd9Sstevel@tonic-gate #include "xmalloc.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /* import */
41*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate static void
44*7c478bd9Sstevel@tonic-gate userauth_kbdint(Authctxt *authctxt)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate 	char *lang, *devs;
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate 	if (!authctxt || !authctxt->method)
49*7c478bd9Sstevel@tonic-gate 		fatal("%s: missing contex", __func__);
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate 	lang = packet_get_string(NULL);
52*7c478bd9Sstevel@tonic-gate 	devs = packet_get_string(NULL);
53*7c478bd9Sstevel@tonic-gate 	packet_check_eom();
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	debug("keyboard-interactive devs %s", devs);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #ifdef USE_PAM
58*7c478bd9Sstevel@tonic-gate 	if (options.pam_authentication_via_kbd_int)
59*7c478bd9Sstevel@tonic-gate 		auth2_pam(authctxt);
60*7c478bd9Sstevel@tonic-gate #else
61*7c478bd9Sstevel@tonic-gate 	if (options.challenge_response_authentication)
62*7c478bd9Sstevel@tonic-gate 		auth2_challenge(authctxt, devs);
63*7c478bd9Sstevel@tonic-gate #endif /* USE_PAM */
64*7c478bd9Sstevel@tonic-gate 	xfree(devs);
65*7c478bd9Sstevel@tonic-gate 	xfree(lang);
66*7c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN
67*7c478bd9Sstevel@tonic-gate 	if (check_nt_auth(0, authctxt->pw) == 0) {
68*7c478bd9Sstevel@tonic-gate 		authctxt->method->authenticated = 0;
69*7c478bd9Sstevel@tonic-gate 		return;
70*7c478bd9Sstevel@tonic-gate 	}
71*7c478bd9Sstevel@tonic-gate #endif
72*7c478bd9Sstevel@tonic-gate 	return;
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate #if 0
76*7c478bd9Sstevel@tonic-gate static int
77*7c478bd9Sstevel@tonic-gate userauth_kbdint_abandon_chk(Authctxt *authctxt, Authmethod *method)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate #ifdef USE_PAM
80*7c478bd9Sstevel@tonic-gate 	return kbdint_pam_abandon_chk(authctxt, method);
81*7c478bd9Sstevel@tonic-gate #endif /* USE_PAM */
82*7c478bd9Sstevel@tonic-gate 	if (method->method_data || method->postponed)
83*7c478bd9Sstevel@tonic-gate 		return 1;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	return 0;
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate #endif
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate static void
90*7c478bd9Sstevel@tonic-gate userauth_kbdint_abandon(Authctxt *authctxt, Authmethod *method)
91*7c478bd9Sstevel@tonic-gate {
92*7c478bd9Sstevel@tonic-gate #ifdef USE_PAM
93*7c478bd9Sstevel@tonic-gate 	kbdint_pam_abandon(authctxt, method);
94*7c478bd9Sstevel@tonic-gate #else
95*7c478bd9Sstevel@tonic-gate 	auth2_challenge_abandon(authctxt);
96*7c478bd9Sstevel@tonic-gate #endif /* USE_PAM */
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate Authmethod method_kbdint = {
100*7c478bd9Sstevel@tonic-gate 	"keyboard-interactive",
101*7c478bd9Sstevel@tonic-gate 	&options.kbd_interactive_authentication,
102*7c478bd9Sstevel@tonic-gate 	userauth_kbdint,
103*7c478bd9Sstevel@tonic-gate 	userauth_kbdint_abandon,
104*7c478bd9Sstevel@tonic-gate 	NULL, NULL,	    /* method data and historical data */
105*7c478bd9Sstevel@tonic-gate 	1,		    /* initial userauth */
106*7c478bd9Sstevel@tonic-gate 	0, 0, 0,	    /* counters */
107*7c478bd9Sstevel@tonic-gate 	0, 0, 0, 0, 0, 0    /* state */
108*7c478bd9Sstevel@tonic-gate };
109