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

View File

@ -1,4 +1,4 @@
#ifndef NVT_H ifndef NVT_H
#define NVT_H 1 #define NVT_H 1
typedef enum { typedef enum {
@ -48,10 +48,10 @@ typedef struct nvt_vars {
char term[256]; char term[256];
} nvt_vars; } nvt_vars;
extern void nvt_init_config(nvt_vars *vars);
extern int get_nvt_cmd_response(int action, int type); 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 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 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 #endif