xref: /titanic_44/usr/src/cmd/ssh/sshd/auth2-none.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-none.c,v 1.4 2002/06/27 10:35:47 deraadt 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 "auth.h"
35*7c478bd9Sstevel@tonic-gate #include "xmalloc.h"
36*7c478bd9Sstevel@tonic-gate #include "packet.h"
37*7c478bd9Sstevel@tonic-gate #include "log.h"
38*7c478bd9Sstevel@tonic-gate #include "servconf.h"
39*7c478bd9Sstevel@tonic-gate #include "atomicio.h"
40*7c478bd9Sstevel@tonic-gate #include "compat.h"
41*7c478bd9Sstevel@tonic-gate #include "ssh2.h"
42*7c478bd9Sstevel@tonic-gate #include "monitor_wrap.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /* import */
45*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /* "none" is allowed only one time */
48*7c478bd9Sstevel@tonic-gate static int none_enabled = 1;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate char *
51*7c478bd9Sstevel@tonic-gate auth2_read_banner(void)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	struct stat st;
54*7c478bd9Sstevel@tonic-gate 	char *banner = NULL;
55*7c478bd9Sstevel@tonic-gate 	off_t len, n;
56*7c478bd9Sstevel@tonic-gate 	int fd;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	if ((fd = open(options.banner, O_RDONLY)) == -1)
59*7c478bd9Sstevel@tonic-gate 		return (NULL);
60*7c478bd9Sstevel@tonic-gate 	if (fstat(fd, &st) == -1) {
61*7c478bd9Sstevel@tonic-gate 		close(fd);
62*7c478bd9Sstevel@tonic-gate 		return (NULL);
63*7c478bd9Sstevel@tonic-gate 	}
64*7c478bd9Sstevel@tonic-gate 	len = st.st_size;
65*7c478bd9Sstevel@tonic-gate 	banner = xmalloc(len + 1);
66*7c478bd9Sstevel@tonic-gate 	n = atomicio(read, fd, banner, len);
67*7c478bd9Sstevel@tonic-gate 	close(fd);
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 	if (n != len) {
70*7c478bd9Sstevel@tonic-gate 		xfree(banner);
71*7c478bd9Sstevel@tonic-gate 		return (NULL);
72*7c478bd9Sstevel@tonic-gate 	}
73*7c478bd9Sstevel@tonic-gate 	banner[n] = '\0';
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	return (banner);
76*7c478bd9Sstevel@tonic-gate }
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate static void
79*7c478bd9Sstevel@tonic-gate userauth_banner(void)
80*7c478bd9Sstevel@tonic-gate {
81*7c478bd9Sstevel@tonic-gate 	char *banner = NULL;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
84*7c478bd9Sstevel@tonic-gate 		return;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	if ((banner = PRIVSEP(auth2_read_banner())) == NULL)
87*7c478bd9Sstevel@tonic-gate 		goto done;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	packet_start(SSH2_MSG_USERAUTH_BANNER);
90*7c478bd9Sstevel@tonic-gate 	packet_put_cstring(banner);
91*7c478bd9Sstevel@tonic-gate 	packet_put_cstring("");		/* language, unused */
92*7c478bd9Sstevel@tonic-gate 	packet_send();
93*7c478bd9Sstevel@tonic-gate 	debug("userauth_banner: sent");
94*7c478bd9Sstevel@tonic-gate done:
95*7c478bd9Sstevel@tonic-gate 	if (banner)
96*7c478bd9Sstevel@tonic-gate 		xfree(banner);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate static void
100*7c478bd9Sstevel@tonic-gate userauth_none(Authctxt *authctxt)
101*7c478bd9Sstevel@tonic-gate {
102*7c478bd9Sstevel@tonic-gate 	none_enabled = 0;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	if (!authctxt || !authctxt->method)
105*7c478bd9Sstevel@tonic-gate 		fatal("%s: missing context", __func__);
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	packet_check_eom();
108*7c478bd9Sstevel@tonic-gate 	userauth_banner();
109*7c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN
110*7c478bd9Sstevel@tonic-gate 	if (check_nt_auth(1, authctxt->pw) == 0)
111*7c478bd9Sstevel@tonic-gate 		return(0);
112*7c478bd9Sstevel@tonic-gate #endif
113*7c478bd9Sstevel@tonic-gate 	authctxt->method->authenticated = PRIVSEP(auth_password(authctxt, ""));
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate Authmethod method_none = {
117*7c478bd9Sstevel@tonic-gate 	"none",
118*7c478bd9Sstevel@tonic-gate 	&none_enabled,
119*7c478bd9Sstevel@tonic-gate 	userauth_none,
120*7c478bd9Sstevel@tonic-gate 	NULL,		    /* no abandon function */
121*7c478bd9Sstevel@tonic-gate 	NULL, NULL,	    /* method data and hist data */
122*7c478bd9Sstevel@tonic-gate 	0,		    /* not really initial userauth */
123*7c478bd9Sstevel@tonic-gate 	0, 0, 0,	    /* counters */
124*7c478bd9Sstevel@tonic-gate 	0, 0, 0, 0, 0, 0    /* state */
125*7c478bd9Sstevel@tonic-gate };
126