Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

auth2-none.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00014  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00015  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00016  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00017  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00018  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00019  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00020  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00021  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00022  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023  */
00024 
00025 #include "includes.h"
00026 RCSID("$OpenBSD: auth2-none.c,v 1.7 2004/05/11 19:01:43 deraadt Exp $");
00027 
00028 #include "auth.h"
00029 #include "xmalloc.h"
00030 #include "packet.h"
00031 #include "log.h"
00032 #include "servconf.h"
00033 #include "atomicio.h"
00034 #include "compat.h"
00035 #include "ssh2.h"
00036 #include "monitor_wrap.h"
00037 
00038 /* import */
00039 extern ServerOptions options;
00040 
00041 /* "none" is allowed only one time */
00042 static int none_enabled = 1;
00043 
00044 char *
00045 auth2_read_banner(void)
00046 {
00047         struct stat st;
00048         char *banner = NULL;
00049         size_t len, n;
00050         int fd;
00051 
00052         if ((fd = open(options.banner, O_RDONLY)) == -1)
00053                 return (NULL);
00054         if (fstat(fd, &st) == -1) {
00055                 close(fd);
00056                 return (NULL);
00057         }
00058         if (st.st_size > 1*1024*1024) {
00059                 close(fd);
00060                 return (NULL);
00061         }
00062 
00063         len = (size_t)st.st_size;               /* truncate */
00064         banner = xmalloc(len + 1);
00065         n = atomicio(read, fd, banner, len);
00066         close(fd);
00067 
00068         if (n != len) {
00069                 xfree(banner);
00070                 return (NULL);
00071         }
00072         banner[n] = '\0';
00073 
00074         return (banner);
00075 }
00076 
00077 void
00078 userauth_send_banner(const char *msg)
00079 {
00080         if (datafellows & SSH_BUG_BANNER)
00081                 return;
00082 
00083         packet_start(SSH2_MSG_USERAUTH_BANNER);
00084         packet_put_cstring(msg);
00085         packet_put_cstring("");         /* language, unused */
00086         packet_send();
00087         debug("%s: sent", __func__);
00088 }
00089 
00090 static void
00091 userauth_banner(void)
00092 {
00093         char *banner = NULL;
00094 
00095         if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
00096                 return;
00097 
00098         if ((banner = PRIVSEP(auth2_read_banner())) == NULL)
00099                 goto done;
00100         userauth_send_banner(banner);
00101 
00102 done:
00103         if (banner)
00104                 xfree(banner);
00105 }
00106 
00107 static int
00108 userauth_none(Authctxt *authctxt)
00109 {
00110         none_enabled = 0;
00111         packet_check_eom();
00112         userauth_banner();
00113 #ifdef HAVE_CYGWIN
00114         if (check_nt_auth(1, authctxt->pw) == 0)
00115                 return (0);
00116 #endif
00117         if (options.password_authentication)
00118                 return (PRIVSEP(auth_password(authctxt, "")));
00119         return (0);
00120 }
00121 
00122 Authmethod method_none = {
00123         "none",
00124         userauth_none,
00125         &none_enabled
00126 };

© sourcejam.com 2005-2008