mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
Fix API initialisation to actually ignore invalid packets or passwords
This commit is contained in:
parent
c552db6443
commit
d2bafa716d
|
@ -381,7 +381,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
|
||||||
/* we reuse the buffer already on the stack for all our strings */
|
/* we reuse the buffer already on the stack for all our strings */
|
||||||
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
|
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
|
||||||
|
|
||||||
mgmt_req_init2(req, buf, (char *)&cmdlinebuf);
|
if (!mgmt_req_init2(req, buf, (char *)&cmdlinebuf)) {
|
||||||
|
// if anything failed during init
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(req->type == N2N_MGMT_SUB) {
|
if(req->type == N2N_MGMT_SUB) {
|
||||||
int handler;
|
int handler;
|
||||||
|
|
|
@ -210,7 +210,7 @@ int mgmt_auth (mgmt_req_t *req, char *auth) {
|
||||||
/*
|
/*
|
||||||
* Handle the common and shred parts of the mgmt_req_t initialisation
|
* Handle the common and shred parts of the mgmt_req_t initialisation
|
||||||
*/
|
*/
|
||||||
void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
|
bool mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
|
||||||
char *typechar;
|
char *typechar;
|
||||||
char *options;
|
char *options;
|
||||||
char *flagstr;
|
char *flagstr;
|
||||||
|
@ -226,7 +226,7 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
|
||||||
if(!typechar) {
|
if(!typechar) {
|
||||||
/* should not happen */
|
/* should not happen */
|
||||||
mgmt_error(req, buf, "notype");
|
mgmt_error(req, buf, "notype");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if(*typechar == 'r') {
|
if(*typechar == 'r') {
|
||||||
req->type=N2N_MGMT_READ;
|
req->type=N2N_MGMT_READ;
|
||||||
|
@ -236,20 +236,20 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
|
||||||
req->type=N2N_MGMT_SUB;
|
req->type=N2N_MGMT_SUB;
|
||||||
} else {
|
} else {
|
||||||
mgmt_error(req, buf, "badtype");
|
mgmt_error(req, buf, "badtype");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the tag to use in all reply packets */
|
/* Extract the tag to use in all reply packets */
|
||||||
options = strtok(NULL, " \r\n");
|
options = strtok(NULL, " \r\n");
|
||||||
if(!options) {
|
if(!options) {
|
||||||
mgmt_error(req, buf, "nooptions");
|
mgmt_error(req, buf, "nooptions");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
req->argv0 = strtok(NULL, " \r\n");
|
req->argv0 = strtok(NULL, " \r\n");
|
||||||
if(!req->argv0) {
|
if(!req->argv0) {
|
||||||
mgmt_error(req, buf, "nocmd");
|
mgmt_error(req, buf, "nocmd");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -281,6 +281,8 @@ void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline) {
|
||||||
|
|
||||||
if(!mgmt_auth(req, auth)) {
|
if(!mgmt_auth(req, auth)) {
|
||||||
mgmt_error(req, buf, "badauth");
|
mgmt_error(req, buf, "badauth");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,6 @@ void mgmt_event_post2 (enum n2n_event_topic topic, int data0, void *data1, mgmt_
|
||||||
void mgmt_help_row (mgmt_req_t *req, strbuf_t *buf, char *cmd, char *help);
|
void mgmt_help_row (mgmt_req_t *req, strbuf_t *buf, char *cmd, char *help);
|
||||||
void mgmt_help_events_row (mgmt_req_t *req, strbuf_t *buf, mgmt_req_t *sub, char *cmd, char *help);
|
void mgmt_help_events_row (mgmt_req_t *req, strbuf_t *buf, mgmt_req_t *sub, char *cmd, char *help);
|
||||||
int mgmt_auth (mgmt_req_t *req, char *auth);
|
int mgmt_auth (mgmt_req_t *req, char *auth);
|
||||||
void mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline);
|
bool mgmt_req_init2 (mgmt_req_t *req, strbuf_t *buf, char *cmdline);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -241,7 +241,10 @@ static void handleMgmtJson (mgmt_req_t *req, char *udp_buf, const int recvlen) {
|
||||||
// xx
|
// xx
|
||||||
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
|
STRBUF_INIT(buf, udp_buf, N2N_SN_PKTBUF_SIZE);
|
||||||
|
|
||||||
mgmt_req_init2(req, buf, (char *)&cmdlinebuf);
|
if (!mgmt_req_init2(req, buf, (char *)&cmdlinebuf)) {
|
||||||
|
// if anything failed during init
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int handler;
|
int handler;
|
||||||
lookup_handler(handler, mgmt_handlers, req->argv0);
|
lookup_handler(handler, mgmt_handlers, req->argv0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user