xref: /titanic_44/usr/src/cmd/ssh/sshd/auth2-none.c (revision d0538f66491267879b7418b21ad78e3dcc2dcc83)
1 /*
2  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 /*
25  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #include "includes.h"
30 RCSID("$OpenBSD: auth2-none.c,v 1.4 2002/06/27 10:35:47 deraadt Exp $");
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include "auth.h"
35 #include "xmalloc.h"
36 #include "packet.h"
37 #include "log.h"
38 #include "servconf.h"
39 #include "atomicio.h"
40 #include "compat.h"
41 #include "ssh2.h"
42 
43 /* import */
44 extern ServerOptions options;
45 
46 /* "none" is allowed only one time */
47 static int none_enabled = 1;
48 
49 char *
50 auth2_read_banner(void)
51 {
52 	struct stat st;
53 	char *banner = NULL;
54 	off_t len, n;
55 	int fd;
56 
57 	if ((fd = open(options.banner, O_RDONLY)) == -1)
58 		return (NULL);
59 	if (fstat(fd, &st) == -1) {
60 		close(fd);
61 		return (NULL);
62 	}
63 	len = st.st_size;
64 	banner = xmalloc(len + 1);
65 	n = atomicio(read, fd, banner, len);
66 	close(fd);
67 
68 	if (n != len) {
69 		xfree(banner);
70 		return (NULL);
71 	}
72 	banner[n] = '\0';
73 
74 	return (banner);
75 }
76 
77 static void
78 userauth_banner(void)
79 {
80 	char *banner = NULL;
81 
82 	if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
83 		return;
84 
85 	if ((banner = auth2_read_banner()) == NULL)
86 		goto done;
87 
88 	packet_start(SSH2_MSG_USERAUTH_BANNER);
89 	packet_put_cstring(banner);
90 	packet_put_cstring("");		/* language, unused */
91 	packet_send();
92 	debug("userauth_banner: sent");
93 done:
94 	if (banner)
95 		xfree(banner);
96 }
97 
98 static void
99 userauth_none(Authctxt *authctxt)
100 {
101 	none_enabled = 0;
102 
103 	if (!authctxt || !authctxt->method)
104 		fatal("%s: missing context", __func__);
105 
106 	packet_check_eom();
107 	userauth_banner();
108 #ifdef HAVE_CYGWIN
109 	if (check_nt_auth(1, authctxt->pw) == 0)
110 		return(0);
111 #endif
112 	authctxt->method->authenticated = auth_password(authctxt, "");
113 }
114 
115 Authmethod method_none = {
116 	"none",
117 	&none_enabled,
118 	userauth_none,
119 	NULL,		    /* no abandon function */
120 	NULL, NULL,	    /* method data and hist data */
121 	0,		    /* not really initial userauth */
122 	0, 0, 0,	    /* counters */
123 	0, 0, 0, 0, 0, 0    /* state */
124 };
125