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