2001-01-19 10:10:37 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-02-05 13:04:00 +00:00
|
|
|
#include <ctype.h>
|
2001-01-19 10:10:37 +00:00
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 17:09:23 +00:00
|
|
|
#define RLOGIN_MAX_BACKLOG 4096
|
|
|
|
|
2001-01-19 10:10:37 +00:00
|
|
|
static Socket s = NULL;
|
2001-08-25 17:09:23 +00:00
|
|
|
static int rlogin_bufsize;
|
2001-01-19 10:10:37 +00:00
|
|
|
|
|
|
|
static void rlogin_size(void);
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static void c_write(char *buf, int len)
|
|
|
|
{
|
2001-08-25 17:09:23 +00:00
|
|
|
int backlog = from_backend(0, buf, len);
|
|
|
|
sk_set_frozen(s, backlog > RLOGIN_MAX_BACKLOG);
|
2001-01-19 10:10:37 +00:00
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static int rlogin_closing(Plug plug, char *error_msg, int error_code,
|
|
|
|
int calling_back)
|
|
|
|
{
|
2001-07-31 14:23:21 +00:00
|
|
|
if (s) {
|
|
|
|
sk_close(s);
|
|
|
|
s = NULL;
|
|
|
|
}
|
2001-03-13 10:22:45 +00:00
|
|
|
if (error_msg) {
|
2001-05-06 14:35:20 +00:00
|
|
|
/* A socket error has occurred. */
|
|
|
|
connection_fatal(error_msg);
|
|
|
|
} /* Otherwise, the remote side closed the connection normally. */
|
2001-03-13 10:22:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static int rlogin_receive(Plug plug, int urgent, char *data, int len)
|
|
|
|
{
|
2001-01-19 10:10:37 +00:00
|
|
|
if (urgent == 2) {
|
2001-05-06 14:35:20 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
c = *data++;
|
|
|
|
len--;
|
|
|
|
if (c == '\x80')
|
|
|
|
rlogin_size();
|
|
|
|
/*
|
|
|
|
* We should flush everything (aka Telnet SYNCH) if we see
|
|
|
|
* 0x02, and we should turn off and on _local_ flow control
|
|
|
|
* on 0x10 and 0x20 respectively. I'm not convinced it's
|
|
|
|
* worth it...
|
|
|
|
*/
|
2001-02-01 14:09:00 +00:00
|
|
|
} else {
|
2001-05-06 14:35:20 +00:00
|
|
|
/*
|
|
|
|
* Main rlogin protocol. This is really simple: the first
|
|
|
|
* byte is expected to be NULL and is ignored, and the rest
|
|
|
|
* is printed.
|
|
|
|
*/
|
|
|
|
static int firstbyte = 1;
|
|
|
|
if (firstbyte) {
|
|
|
|
if (data[0] == '\0') {
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
firstbyte = 0;
|
|
|
|
}
|
|
|
|
c_write(data, len);
|
2001-01-19 10:10:37 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set up the rlogin connection.
|
|
|
|
*
|
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
2001-05-09 14:01:15 +00:00
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
2001-01-19 10:10:37 +00:00
|
|
|
*/
|
2001-05-06 14:35:20 +00:00
|
|
|
static char *rlogin_init(char *host, int port, char **realhost)
|
|
|
|
{
|
2001-03-13 10:22:45 +00:00
|
|
|
static struct plug_function_table fn_table = {
|
|
|
|
rlogin_closing,
|
|
|
|
rlogin_receive
|
|
|
|
}, *fn_table_ptr = &fn_table;
|
|
|
|
|
2001-01-19 10:10:37 +00:00
|
|
|
SockAddr addr;
|
|
|
|
char *err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
|
|
|
addr = sk_namelookup(host, realhost);
|
2001-05-06 14:35:20 +00:00
|
|
|
if ((err = sk_addr_error(addr)))
|
2001-01-19 10:10:37 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 513; /* default rlogin port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
2001-03-13 10:22:45 +00:00
|
|
|
s = sk_new(addr, port, 1, 0, &fn_table_ptr);
|
2001-05-06 14:35:20 +00:00
|
|
|
if ((err = sk_socket_error(s)))
|
2001-01-19 10:10:37 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
sk_addr_free(addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send local username, remote username, terminal/speed
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
2001-05-06 14:35:20 +00:00
|
|
|
char z = 0;
|
|
|
|
char *p;
|
|
|
|
sk_write(s, &z, 1);
|
|
|
|
sk_write(s, cfg.localusername, strlen(cfg.localusername));
|
|
|
|
sk_write(s, &z, 1);
|
|
|
|
sk_write(s, cfg.username, strlen(cfg.username));
|
|
|
|
sk_write(s, &z, 1);
|
|
|
|
sk_write(s, cfg.termtype, strlen(cfg.termtype));
|
|
|
|
sk_write(s, "/", 1);
|
|
|
|
for (p = cfg.termspeed; isdigit(*p); p++);
|
|
|
|
sk_write(s, cfg.termspeed, p - cfg.termspeed);
|
2001-08-25 17:09:23 +00:00
|
|
|
rlogin_bufsize = sk_write(s, &z, 1);
|
2001-01-19 10:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to send data down the rlogin connection.
|
|
|
|
*/
|
2001-08-25 17:09:23 +00:00
|
|
|
static int rlogin_send(char *buf, int len)
|
2001-05-06 14:35:20 +00:00
|
|
|
{
|
2001-01-19 10:10:37 +00:00
|
|
|
if (s == NULL)
|
2001-08-27 15:55:44 +00:00
|
|
|
return 0;
|
2001-01-19 10:10:37 +00:00
|
|
|
|
2001-08-25 17:09:23 +00:00
|
|
|
rlogin_bufsize = sk_write(s, buf, len);
|
|
|
|
|
|
|
|
return rlogin_bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current socket sendability status.
|
|
|
|
*/
|
|
|
|
static int rlogin_sendbuffer(void)
|
|
|
|
{
|
|
|
|
return rlogin_bufsize;
|
2001-01-19 10:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2001-05-06 14:35:20 +00:00
|
|
|
static void rlogin_size(void)
|
|
|
|
{
|
2001-01-22 17:24:38 +00:00
|
|
|
char b[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
|
2001-01-19 10:10:37 +00:00
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
b[6] = cols >> 8;
|
|
|
|
b[7] = cols & 0xFF;
|
|
|
|
b[4] = rows >> 8;
|
|
|
|
b[5] = rows & 0xFF;
|
2001-08-25 17:09:23 +00:00
|
|
|
rlogin_bufsize = sk_write(s, b, 12);
|
2001-01-19 10:10:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send rlogin special codes.
|
|
|
|
*/
|
2001-05-06 14:35:20 +00:00
|
|
|
static void rlogin_special(Telnet_Special code)
|
|
|
|
{
|
2001-01-19 10:10:37 +00:00
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static Socket rlogin_socket(void)
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
2001-01-19 10:10:37 +00:00
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static int rlogin_sendok(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2001-01-19 10:10:37 +00:00
|
|
|
|
2001-08-25 17:09:23 +00:00
|
|
|
static void rlogin_unthrottle(int backlog)
|
|
|
|
{
|
|
|
|
sk_set_frozen(s, backlog > RLOGIN_MAX_BACKLOG);
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
static int rlogin_ldisc(int option)
|
|
|
|
{
|
2001-01-24 14:08:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 10:10:37 +00:00
|
|
|
Backend rlogin_backend = {
|
|
|
|
rlogin_init,
|
|
|
|
rlogin_send,
|
2001-08-25 17:09:23 +00:00
|
|
|
rlogin_sendbuffer,
|
2001-01-19 10:10:37 +00:00
|
|
|
rlogin_size,
|
|
|
|
rlogin_special,
|
|
|
|
rlogin_socket,
|
|
|
|
rlogin_sendok,
|
2001-01-24 14:08:20 +00:00
|
|
|
rlogin_ldisc,
|
2001-08-25 17:09:23 +00:00
|
|
|
rlogin_unthrottle,
|
2001-01-19 10:10:37 +00:00
|
|
|
1
|
|
|
|
};
|