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