diff --git a/src/functions.c b/src/functions.c index a6fe93f..9f40406 100644 --- a/src/functions.c +++ b/src/functions.c @@ -84,11 +84,10 @@ char *process_line(char *line) char srch[MAX_NETSRCH_BUF]; char port[7]; // Should never be more than 6 characters tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:netlisten syntax error, missing quote?"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:netlisten syntax error, missing quote?"); if(strlen(parse_vars(tok_srch)) < 7) @@ -102,17 +101,29 @@ char *process_line(char *line) /* strtok to the content that will be written to file */ tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + syn_error("ss:error:netlisten syntax error, missing quote?"); + tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) { - syn_error("ss:error:netconnect syntax error on data entry (are you quoted?)"); + if(tok_srch == NULL) + syn_error("ss:error:netlisten syntax error, missing quote?"); + + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { + syn_error("ss:error:netlisten syntax error, missing quote?"); } strcpy(srch, parse_vars(tok_srch)); /* strtok to the socket response */ tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + syn_error("ss:error:netlisten syntax error, missing quote?"); + tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) { + if(tok_srch == NULL) + syn_error("ss:error:netlisten syntax error, missing quote?"); + + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) { syn_error("ss:error:netconnect syntax error on data entry (are you quoted?)"); } @@ -128,9 +139,11 @@ char *process_line(char *line) { char port[7]; // Should never be more than 6 characters tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) - syn_error("ss:error:sleep syntax error, need trailing integer for operation"); + if(tok_srch == NULL) + syn_error("ss:error:nethttp syntax error, missing quote?"); + + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + syn_error("ss:error:netlisten syntax error, missing quote?"); if(strlen(parse_vars(tok_srch)) < 7) { @@ -143,10 +156,12 @@ char *process_line(char *line) /* strtok to the content that will be written to file */ tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + syn_error("ss:error:nethttp syntax error, missing quote?"); + tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) { + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:nethttp syntax error on data entry (are you quoted?)"); - } if(strtok(NULL, "\"") == NULL) syn_error("ss:error:nethttp syntax error, missing end quote"); @@ -171,24 +186,23 @@ char *process_line(char *line) char port[7]; /* strtok to filename of function */ tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) - syn_error("ss:error:netconnect syntax error, missing quote?"); + if(tok_srch == NULL) + syn_error("ss:error:nettoss syntax error, missing quote?"); /* Check to see if syntax is correct */ - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) - syn_error("ss:error:netconnect syntax error, missing quote?"); + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + syn_error("ss:error:nettoss syntax error, missing quote?"); /* open file */ strcpy(address, parse_vars(tok_srch)); /* strtok to the content that will be written to file */ tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + syn_error("ss:error:nettoss syntax error, missing quote?"); tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) { - syn_error("ss:error:netconnect syntax error on data entry (are you quoted?)"); - } + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + syn_error("ss:error:nettoss syntax error on data entry (are you quoted?)"); if(strlen(parse_vars(tok_srch)) > 6) syn_error("ss:error:nettoss port too long"); @@ -196,14 +210,18 @@ char *process_line(char *line) strcpy(port, parse_vars(tok_srch)); tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + syn_error("ss:error:nettoss syntax error, missing quote?"); + tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) { - syn_error("ss:error:netconnect syntax error on data entry (are you quoted?)"); - } + if(tok_srch == NULL) + syn_error("ss:error:nettoss syntax error, missing quote?"); + + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + syn_error("ss:error:nettoss syntax error, missing quote?"); if(strtok(NULL, "\"") == NULL) - syn_error("ss:error:netconnect syntax error, missing end quote"); + syn_error("ss:error:nettoss syntax error, missing end quote"); strcpy(data, parse_vars(tok_srch)); @@ -216,11 +234,10 @@ char *process_line(char *line) { char *var_conv; tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:encode syntax error, requires data in quotes"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:encode syntax error, requires data in quotes"); var_conv = parse_vars(tok_srch); @@ -237,11 +254,10 @@ char *process_line(char *line) { char *var_conv; tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:decode syntax error, requires data in quotes"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:decode syntax error, requires data in quotes"); var_conv = parse_vars(tok_srch); @@ -259,11 +275,10 @@ char *process_line(char *line) char *file_line, *catfile, *file_md5_val; tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:md5 syntax error, requires a file argument in quotes"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:md5 syntax error, requires a file argument in quotes"); file_line = parse_vars(tok_srch); @@ -288,13 +303,15 @@ char *process_line(char *line) char *cmd_line; int return_val; tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:exec syntax error, requires a file argument in quotes"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:exec syntax error, requires argument in quotes"); + if(strtok(NULL, "\"") == NULL) + syn_error("ss:error:exec syntax error, missing end quote"); + cmd_line = parse_vars(tok_srch); return_val = system(cmd_line); if(return_val != 0) @@ -312,12 +329,11 @@ char *process_line(char *line) FILE* write_file = NULL; /* strtok to filename of function */ tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:write syntax error, requires a file argument in quotes"); /* Check to see if syntax is correct */ - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:write syntax error, requires filename followed by data; both in quotes"); /* open file */ @@ -357,13 +373,15 @@ char *process_line(char *line) /* strtok to filename of function */ tok_srch = strtok(NULL, "\""); - if(strtok(NULL, "\"") == NULL) + if(tok_srch == NULL) syn_error("ss:error:read syntax error, requires a file argument in quotes"); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:read syntax error, missing filename / in quotes"); + if(strtok(NULL, "\"") == NULL) + syn_error("ss:error:read syntax error, missing end quote"); + /* Pull any variables out of the file name that may be, and BAM, variable fill! */ filename = parse_vars(tok_srch); @@ -409,10 +427,15 @@ char *process_line(char *line) else if(strncmp("delete", tok_srch, 6) == 0) { char *del_filename; tok_srch = strtok(NULL, "\""); - if(strcmp(tok_srch, "\n") == 0 || - strcmp(tok_srch, " \n") == 0 || tok_srch == NULL) + if(tok_srch == NULL) + syn_error("ss:error:delete syntax error, missing end quote"); + + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) syn_error("ss:error:delete syntax error, missing file argument"); + if(strtok(NULL, "\"") == NULL) + syn_error("ss:error:delete syntax error, missing end quote"); + /* Pull variables out of filename if any */ del_filename = parse_vars(tok_srch); if(access(del_filename, F_OK) == 0)