00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00039 extern ServerOptions options;
00040
00041
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;
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("");
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 };