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