Don't send DO/DONT/WILL/WONT when already in the requested mode.

This commit is contained in:
Chris Osborn 2018-03-26 15:45:47 -07:00
parent 7ba448a6d4
commit 45999ba239
2 changed files with 37 additions and 20 deletions

View File

@ -4,7 +4,7 @@
#include "ip.h"
#include "nvt.h"
int nvt_init_config(nvt_vars *vars)
void nvt_init_config(nvt_vars *vars)
{
int i;
@ -116,10 +116,11 @@ int parse_nvt_subcommand(int fd, nvt_vars *vars, unsigned char *data, int len, i
resp[resp_len++] = NVT_SE;
ip_write(fd, resp, resp_len);
}
return rc;
}
int send_nvt_command(int fd, nvt_vars *vars, char action, int opt)
void send_nvt_command(int fd, nvt_vars *vars, char action, int opt)
{
char cmd[3];
@ -131,10 +132,10 @@ int send_nvt_command(int fd, nvt_vars *vars, char action, int opt)
ip_write(fd, cmd, 3);
vars->term[opt] = action;
return 0;
return;
}
int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt, int parity)
void parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt, int parity)
{
char resp[3];
int accept = FALSE;
@ -148,27 +149,43 @@ int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt,
switch (action) {
case NVT_DO:
if (!parity) {
if (!vars->binary_xmit) {
LOG(LOG_INFO, "Enabling telnet binary xmit");
vars->binary_xmit = TRUE;
accept = TRUE;
}
else
return;
}
break;
case NVT_DONT:
if (vars->binary_xmit) {
LOG(LOG_INFO, "Disabling telnet binary xmit");
vars->binary_xmit = FALSE;
accept = TRUE;
}
else
return;
break;
case NVT_WILL:
if (!parity) {
if (!vars->binary_recv) {
LOG(LOG_INFO, "Enabling telnet binary recv");
vars->binary_recv = TRUE;
accept = TRUE;
}
else
return;
}
break;
case NVT_WONT:
if (vars->binary_recv) {
LOG(LOG_INFO, "Disabling telnet binary recv");
vars->binary_recv = FALSE;
accept = TRUE;
}
else
return;
break;
default:
@ -193,5 +210,5 @@ int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt,
break;
}
ip_write(fd, resp, 3);
return 0;
return;
}

View File

@ -1,4 +1,4 @@
#ifndef NVT_H
ifndef NVT_H
#define NVT_H 1
typedef enum {
@ -48,10 +48,10 @@ typedef struct nvt_vars {
char term[256];
} nvt_vars;
extern void nvt_init_config(nvt_vars *vars);
extern int get_nvt_cmd_response(int action, int type);
extern int parse_nvt_subcommand(int fd, nvt_vars *vars, unsigned char *data, int len, int speed);
extern void send_nvt_command(int fd, nvt_vars *vars, char action, int opt);
extern int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt, int parity);
extern int nvt_init_config(nvt_vars *vars);
extern int send_nvt_command(int fd, nvt_vars *vars, char action, int opt);
#endif