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*6f786aceSNobutomo Nakano * Copyright 2009 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 #include "auth.h"
337c478bd9Sstevel@tonic-gate #include "xmalloc.h"
347c478bd9Sstevel@tonic-gate #include "packet.h"
357c478bd9Sstevel@tonic-gate #include "log.h"
367c478bd9Sstevel@tonic-gate #include "servconf.h"
377c478bd9Sstevel@tonic-gate #include "atomicio.h"
387c478bd9Sstevel@tonic-gate #include "compat.h"
397c478bd9Sstevel@tonic-gate #include "ssh2.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /* import */
427c478bd9Sstevel@tonic-gate extern ServerOptions options;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /* "none" is allowed only one time */
457c478bd9Sstevel@tonic-gate static int none_enabled = 1;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate char *
auth2_read_banner(void)487c478bd9Sstevel@tonic-gate auth2_read_banner(void)
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate struct stat st;
51*6f786aceSNobutomo Nakano char *banner, *ubanner, *errstr;
527c478bd9Sstevel@tonic-gate off_t len, n;
537c478bd9Sstevel@tonic-gate int fd;
54*6f786aceSNobutomo Nakano uint_t ilen;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate if ((fd = open(options.banner, O_RDONLY)) == -1)
577c478bd9Sstevel@tonic-gate return (NULL);
587c478bd9Sstevel@tonic-gate if (fstat(fd, &st) == -1) {
597c478bd9Sstevel@tonic-gate close(fd);
607c478bd9Sstevel@tonic-gate return (NULL);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate len = st.st_size;
637c478bd9Sstevel@tonic-gate banner = xmalloc(len + 1);
647c478bd9Sstevel@tonic-gate n = atomicio(read, fd, banner, len);
657c478bd9Sstevel@tonic-gate close(fd);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate if (n != len) {
687c478bd9Sstevel@tonic-gate xfree(banner);
697c478bd9Sstevel@tonic-gate return (NULL);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate banner[n] = '\0';
727c478bd9Sstevel@tonic-gate
73*6f786aceSNobutomo Nakano if (datafellows & SSH_BUG_STRING_ENCODING) {
74*6f786aceSNobutomo Nakano ubanner = banner;
75*6f786aceSNobutomo Nakano } else {
76*6f786aceSNobutomo Nakano ilen = (uint_t)n;
77*6f786aceSNobutomo Nakano ubanner = g11n_convert_to_utf8(banner, &ilen, 1, &errstr);
78*6f786aceSNobutomo Nakano if (ubanner == NULL) {
79*6f786aceSNobutomo Nakano if (errstr != NULL) {
80*6f786aceSNobutomo Nakano error("Can't convert banner contents "
81*6f786aceSNobutomo Nakano "to UTF-8: %s\n", errstr);
82*6f786aceSNobutomo Nakano }
83*6f786aceSNobutomo Nakano ubanner = banner;
84*6f786aceSNobutomo Nakano } else {
85*6f786aceSNobutomo Nakano xfree(banner);
86*6f786aceSNobutomo Nakano }
87*6f786aceSNobutomo Nakano }
88*6f786aceSNobutomo Nakano
89*6f786aceSNobutomo Nakano return (ubanner);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate static void
userauth_banner(void)937c478bd9Sstevel@tonic-gate userauth_banner(void)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate char *banner = NULL;
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
987c478bd9Sstevel@tonic-gate return;
997c478bd9Sstevel@tonic-gate
1009a8058b5Sjp161948 if ((banner = auth2_read_banner()) == NULL)
1017c478bd9Sstevel@tonic-gate goto done;
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate packet_start(SSH2_MSG_USERAUTH_BANNER);
1047c478bd9Sstevel@tonic-gate packet_put_cstring(banner);
1057c478bd9Sstevel@tonic-gate packet_put_cstring(""); /* language, unused */
1067c478bd9Sstevel@tonic-gate packet_send();
1077c478bd9Sstevel@tonic-gate debug("userauth_banner: sent");
1087c478bd9Sstevel@tonic-gate done:
1097c478bd9Sstevel@tonic-gate if (banner)
1107c478bd9Sstevel@tonic-gate xfree(banner);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate static void
userauth_none(Authctxt * authctxt)1147c478bd9Sstevel@tonic-gate userauth_none(Authctxt *authctxt)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate none_enabled = 0;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate if (!authctxt || !authctxt->method)
1197c478bd9Sstevel@tonic-gate fatal("%s: missing context", __func__);
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate packet_check_eom();
1227c478bd9Sstevel@tonic-gate userauth_banner();
1237c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN
1247c478bd9Sstevel@tonic-gate if (check_nt_auth(1, authctxt->pw) == 0)
1257c478bd9Sstevel@tonic-gate return (0);
1267c478bd9Sstevel@tonic-gate #endif
1279a8058b5Sjp161948 authctxt->method->authenticated = auth_password(authctxt, "");
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate Authmethod method_none = {
1317c478bd9Sstevel@tonic-gate "none",
1327c478bd9Sstevel@tonic-gate &none_enabled,
1337c478bd9Sstevel@tonic-gate userauth_none,
1347c478bd9Sstevel@tonic-gate NULL, /* no abandon function */
1357c478bd9Sstevel@tonic-gate NULL, NULL, /* method data and hist data */
1367c478bd9Sstevel@tonic-gate 0, /* not really initial userauth */
1377c478bd9Sstevel@tonic-gate 0, 0, 0, /* counters */
1387c478bd9Sstevel@tonic-gate 0, 0, 0, 0, 0, 0 /* state */
1397c478bd9Sstevel@tonic-gate };
140