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*5562Sjp161948 * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include "auth.h" 350Sstevel@tonic-gate #include "xmalloc.h" 360Sstevel@tonic-gate #include "packet.h" 370Sstevel@tonic-gate #include "log.h" 380Sstevel@tonic-gate #include "servconf.h" 390Sstevel@tonic-gate #include "atomicio.h" 400Sstevel@tonic-gate #include "compat.h" 410Sstevel@tonic-gate #include "ssh2.h" 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* import */ 440Sstevel@tonic-gate extern ServerOptions options; 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* "none" is allowed only one time */ 470Sstevel@tonic-gate static int none_enabled = 1; 480Sstevel@tonic-gate 490Sstevel@tonic-gate char * 500Sstevel@tonic-gate auth2_read_banner(void) 510Sstevel@tonic-gate { 520Sstevel@tonic-gate struct stat st; 530Sstevel@tonic-gate char *banner = NULL; 540Sstevel@tonic-gate off_t len, n; 550Sstevel@tonic-gate int fd; 560Sstevel@tonic-gate 570Sstevel@tonic-gate if ((fd = open(options.banner, O_RDONLY)) == -1) 580Sstevel@tonic-gate return (NULL); 590Sstevel@tonic-gate if (fstat(fd, &st) == -1) { 600Sstevel@tonic-gate close(fd); 610Sstevel@tonic-gate return (NULL); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate len = st.st_size; 640Sstevel@tonic-gate banner = xmalloc(len + 1); 650Sstevel@tonic-gate n = atomicio(read, fd, banner, len); 660Sstevel@tonic-gate close(fd); 670Sstevel@tonic-gate 680Sstevel@tonic-gate if (n != len) { 690Sstevel@tonic-gate xfree(banner); 700Sstevel@tonic-gate return (NULL); 710Sstevel@tonic-gate } 720Sstevel@tonic-gate banner[n] = '\0'; 730Sstevel@tonic-gate 740Sstevel@tonic-gate return (banner); 750Sstevel@tonic-gate } 760Sstevel@tonic-gate 770Sstevel@tonic-gate static void 780Sstevel@tonic-gate userauth_banner(void) 790Sstevel@tonic-gate { 800Sstevel@tonic-gate char *banner = NULL; 810Sstevel@tonic-gate 820Sstevel@tonic-gate if (options.banner == NULL || (datafellows & SSH_BUG_BANNER)) 830Sstevel@tonic-gate return; 840Sstevel@tonic-gate 85*5562Sjp161948 if ((banner = auth2_read_banner()) == NULL) 860Sstevel@tonic-gate goto done; 870Sstevel@tonic-gate 880Sstevel@tonic-gate packet_start(SSH2_MSG_USERAUTH_BANNER); 890Sstevel@tonic-gate packet_put_cstring(banner); 900Sstevel@tonic-gate packet_put_cstring(""); /* language, unused */ 910Sstevel@tonic-gate packet_send(); 920Sstevel@tonic-gate debug("userauth_banner: sent"); 930Sstevel@tonic-gate done: 940Sstevel@tonic-gate if (banner) 950Sstevel@tonic-gate xfree(banner); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate static void 990Sstevel@tonic-gate userauth_none(Authctxt *authctxt) 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate none_enabled = 0; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate if (!authctxt || !authctxt->method) 1040Sstevel@tonic-gate fatal("%s: missing context", __func__); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate packet_check_eom(); 1070Sstevel@tonic-gate userauth_banner(); 1080Sstevel@tonic-gate #ifdef HAVE_CYGWIN 1090Sstevel@tonic-gate if (check_nt_auth(1, authctxt->pw) == 0) 1100Sstevel@tonic-gate return(0); 1110Sstevel@tonic-gate #endif 112*5562Sjp161948 authctxt->method->authenticated = auth_password(authctxt, ""); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate Authmethod method_none = { 1160Sstevel@tonic-gate "none", 1170Sstevel@tonic-gate &none_enabled, 1180Sstevel@tonic-gate userauth_none, 1190Sstevel@tonic-gate NULL, /* no abandon function */ 1200Sstevel@tonic-gate NULL, NULL, /* method data and hist data */ 1210Sstevel@tonic-gate 0, /* not really initial userauth */ 1220Sstevel@tonic-gate 0, 0, 0, /* counters */ 1230Sstevel@tonic-gate 0, 0, 0, 0, 0, 0 /* state */ 1240Sstevel@tonic-gate }; 125