xref: /onnv-gate/usr/src/cmd/ssh/sshd/auth2-none.c (revision 9600:113cf06ae502)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
50Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
60Sstevel@tonic-gate  * are met:
70Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
80Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
90Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
100Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
110Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
140Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
150Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
160Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
170Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
180Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
190Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
200Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
210Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
220Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate /*
25*9600SNobutomo.Nakano@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
260Sstevel@tonic-gate  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include "includes.h"
300Sstevel@tonic-gate RCSID("$OpenBSD: auth2-none.c,v 1.4 2002/06/27 10:35:47 deraadt Exp $");
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include "auth.h"
330Sstevel@tonic-gate #include "xmalloc.h"
340Sstevel@tonic-gate #include "packet.h"
350Sstevel@tonic-gate #include "log.h"
360Sstevel@tonic-gate #include "servconf.h"
370Sstevel@tonic-gate #include "atomicio.h"
380Sstevel@tonic-gate #include "compat.h"
390Sstevel@tonic-gate #include "ssh2.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /* import */
420Sstevel@tonic-gate extern ServerOptions options;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /* "none" is allowed only one time */
450Sstevel@tonic-gate static int none_enabled = 1;
460Sstevel@tonic-gate 
470Sstevel@tonic-gate char *
auth2_read_banner(void)480Sstevel@tonic-gate auth2_read_banner(void)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 	struct stat st;
51*9600SNobutomo.Nakano@Sun.COM 	char *banner, *ubanner, *errstr;
520Sstevel@tonic-gate 	off_t len, n;
530Sstevel@tonic-gate 	int fd;
54*9600SNobutomo.Nakano@Sun.COM 	uint_t ilen;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	if ((fd = open(options.banner, O_RDONLY)) == -1)
570Sstevel@tonic-gate 		return (NULL);
580Sstevel@tonic-gate 	if (fstat(fd, &st) == -1) {
590Sstevel@tonic-gate 		close(fd);
600Sstevel@tonic-gate 		return (NULL);
610Sstevel@tonic-gate 	}
620Sstevel@tonic-gate 	len = st.st_size;
630Sstevel@tonic-gate 	banner = xmalloc(len + 1);
640Sstevel@tonic-gate 	n = atomicio(read, fd, banner, len);
650Sstevel@tonic-gate 	close(fd);
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	if (n != len) {
680Sstevel@tonic-gate 		xfree(banner);
690Sstevel@tonic-gate 		return (NULL);
700Sstevel@tonic-gate 	}
710Sstevel@tonic-gate 	banner[n] = '\0';
720Sstevel@tonic-gate 
73*9600SNobutomo.Nakano@Sun.COM 	if (datafellows & SSH_BUG_STRING_ENCODING) {
74*9600SNobutomo.Nakano@Sun.COM 		ubanner = banner;
75*9600SNobutomo.Nakano@Sun.COM 	} else {
76*9600SNobutomo.Nakano@Sun.COM 		ilen = (uint_t)n;
77*9600SNobutomo.Nakano@Sun.COM 		ubanner = g11n_convert_to_utf8(banner, &ilen, 1, &errstr);
78*9600SNobutomo.Nakano@Sun.COM 		if (ubanner == NULL) {
79*9600SNobutomo.Nakano@Sun.COM 			if (errstr != NULL) {
80*9600SNobutomo.Nakano@Sun.COM 				error("Can't convert banner contents "
81*9600SNobutomo.Nakano@Sun.COM 				    "to UTF-8: %s\n", errstr);
82*9600SNobutomo.Nakano@Sun.COM 			}
83*9600SNobutomo.Nakano@Sun.COM 			ubanner = banner;
84*9600SNobutomo.Nakano@Sun.COM 		} else {
85*9600SNobutomo.Nakano@Sun.COM 			xfree(banner);
86*9600SNobutomo.Nakano@Sun.COM 		}
87*9600SNobutomo.Nakano@Sun.COM 	}
88*9600SNobutomo.Nakano@Sun.COM 
89*9600SNobutomo.Nakano@Sun.COM 	return (ubanner);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate static void
userauth_banner(void)930Sstevel@tonic-gate userauth_banner(void)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	char *banner = NULL;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
980Sstevel@tonic-gate 		return;
990Sstevel@tonic-gate 
1005562Sjp161948 	if ((banner = auth2_read_banner()) == NULL)
1010Sstevel@tonic-gate 		goto done;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	packet_start(SSH2_MSG_USERAUTH_BANNER);
1040Sstevel@tonic-gate 	packet_put_cstring(banner);
1050Sstevel@tonic-gate 	packet_put_cstring("");		/* language, unused */
1060Sstevel@tonic-gate 	packet_send();
1070Sstevel@tonic-gate 	debug("userauth_banner: sent");
1080Sstevel@tonic-gate done:
1090Sstevel@tonic-gate 	if (banner)
1100Sstevel@tonic-gate 		xfree(banner);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate static void
userauth_none(Authctxt * authctxt)1140Sstevel@tonic-gate userauth_none(Authctxt *authctxt)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate 	none_enabled = 0;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	if (!authctxt || !authctxt->method)
1190Sstevel@tonic-gate 		fatal("%s: missing context", __func__);
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	packet_check_eom();
1220Sstevel@tonic-gate 	userauth_banner();
1230Sstevel@tonic-gate #ifdef HAVE_CYGWIN
1240Sstevel@tonic-gate 	if (check_nt_auth(1, authctxt->pw) == 0)
125*9600SNobutomo.Nakano@Sun.COM 		return (0);
1260Sstevel@tonic-gate #endif
1275562Sjp161948 	authctxt->method->authenticated = auth_password(authctxt, "");
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate Authmethod method_none = {
1310Sstevel@tonic-gate 	"none",
1320Sstevel@tonic-gate 	&none_enabled,
1330Sstevel@tonic-gate 	userauth_none,
1340Sstevel@tonic-gate 	NULL,		    /* no abandon function */
1350Sstevel@tonic-gate 	NULL, NULL,	    /* method data and hist data */
1360Sstevel@tonic-gate 	0,		    /* not really initial userauth */
1370Sstevel@tonic-gate 	0, 0, 0,	    /* counters */
1380Sstevel@tonic-gate 	0, 0, 0, 0, 0, 0    /* state */
1390Sstevel@tonic-gate };
140