xref: /titanic_41/usr/src/cmd/ssh/sshd/auth2-none.c (revision 9a8058b57457911fab0e3b4b6f0a97740e7a816d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
57c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
67c478bd9Sstevel@tonic-gate  * are met:
77c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
87c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
97c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
107c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
117c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
147c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
157c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
167c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
177c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
187c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
197c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
207c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
217c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
227c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate /*
25*9a8058b5Sjp161948  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "includes.h"
307c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth2-none.c,v 1.4 2002/06/27 10:35:47 deraadt Exp $");
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include "auth.h"
357c478bd9Sstevel@tonic-gate #include "xmalloc.h"
367c478bd9Sstevel@tonic-gate #include "packet.h"
377c478bd9Sstevel@tonic-gate #include "log.h"
387c478bd9Sstevel@tonic-gate #include "servconf.h"
397c478bd9Sstevel@tonic-gate #include "atomicio.h"
407c478bd9Sstevel@tonic-gate #include "compat.h"
417c478bd9Sstevel@tonic-gate #include "ssh2.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /* import */
447c478bd9Sstevel@tonic-gate extern ServerOptions options;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /* "none" is allowed only one time */
477c478bd9Sstevel@tonic-gate static int none_enabled = 1;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate char *
507c478bd9Sstevel@tonic-gate auth2_read_banner(void)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	struct stat st;
537c478bd9Sstevel@tonic-gate 	char *banner = NULL;
547c478bd9Sstevel@tonic-gate 	off_t len, n;
557c478bd9Sstevel@tonic-gate 	int fd;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	if ((fd = open(options.banner, O_RDONLY)) == -1)
587c478bd9Sstevel@tonic-gate 		return (NULL);
597c478bd9Sstevel@tonic-gate 	if (fstat(fd, &st) == -1) {
607c478bd9Sstevel@tonic-gate 		close(fd);
617c478bd9Sstevel@tonic-gate 		return (NULL);
627c478bd9Sstevel@tonic-gate 	}
637c478bd9Sstevel@tonic-gate 	len = st.st_size;
647c478bd9Sstevel@tonic-gate 	banner = xmalloc(len + 1);
657c478bd9Sstevel@tonic-gate 	n = atomicio(read, fd, banner, len);
667c478bd9Sstevel@tonic-gate 	close(fd);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	if (n != len) {
697c478bd9Sstevel@tonic-gate 		xfree(banner);
707c478bd9Sstevel@tonic-gate 		return (NULL);
717c478bd9Sstevel@tonic-gate 	}
727c478bd9Sstevel@tonic-gate 	banner[n] = '\0';
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	return (banner);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate static void
787c478bd9Sstevel@tonic-gate userauth_banner(void)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	char *banner = NULL;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
837c478bd9Sstevel@tonic-gate 		return;
847c478bd9Sstevel@tonic-gate 
85*9a8058b5Sjp161948 	if ((banner = auth2_read_banner()) == NULL)
867c478bd9Sstevel@tonic-gate 		goto done;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	packet_start(SSH2_MSG_USERAUTH_BANNER);
897c478bd9Sstevel@tonic-gate 	packet_put_cstring(banner);
907c478bd9Sstevel@tonic-gate 	packet_put_cstring("");		/* language, unused */
917c478bd9Sstevel@tonic-gate 	packet_send();
927c478bd9Sstevel@tonic-gate 	debug("userauth_banner: sent");
937c478bd9Sstevel@tonic-gate done:
947c478bd9Sstevel@tonic-gate 	if (banner)
957c478bd9Sstevel@tonic-gate 		xfree(banner);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate static void
997c478bd9Sstevel@tonic-gate userauth_none(Authctxt *authctxt)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	none_enabled = 0;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	if (!authctxt || !authctxt->method)
1047c478bd9Sstevel@tonic-gate 		fatal("%s: missing context", __func__);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	packet_check_eom();
1077c478bd9Sstevel@tonic-gate 	userauth_banner();
1087c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN
1097c478bd9Sstevel@tonic-gate 	if (check_nt_auth(1, authctxt->pw) == 0)
1107c478bd9Sstevel@tonic-gate 		return(0);
1117c478bd9Sstevel@tonic-gate #endif
112*9a8058b5Sjp161948 	authctxt->method->authenticated = auth_password(authctxt, "");
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate Authmethod method_none = {
1167c478bd9Sstevel@tonic-gate 	"none",
1177c478bd9Sstevel@tonic-gate 	&none_enabled,
1187c478bd9Sstevel@tonic-gate 	userauth_none,
1197c478bd9Sstevel@tonic-gate 	NULL,		    /* no abandon function */
1207c478bd9Sstevel@tonic-gate 	NULL, NULL,	    /* method data and hist data */
1217c478bd9Sstevel@tonic-gate 	0,		    /* not really initial userauth */
1227c478bd9Sstevel@tonic-gate 	0, 0, 0,	    /* counters */
1237c478bd9Sstevel@tonic-gate 	0, 0, 0, 0, 0, 0    /* state */
1247c478bd9Sstevel@tonic-gate };
125