From d32b0c14a217547dfdf9818f8d96fa0be41d1c01 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 1 Apr 2017 15:28:49 +0430 Subject: now the server will only run the driver commands. not anything. --- daemon/daemon_aux.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- daemon/mutatorclient.c | 6 ++--- daemon/mutatord.c | 2 ++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index ce47f37..3a78eb6 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -59,6 +59,7 @@ bool cleanser(char cleansee[]) return (cleansee_health && nullterminated); } + /**********************************************************************************************************************/ int mutator_server(FILE* log_file) { @@ -67,9 +68,11 @@ int mutator_server(FILE* log_file) char client_message[2000]; FILE* clientistream; + FILE* mutator_config; char runresponse[4000]; - char NOOUT[]="command did not return any output. could be an error or not.\n"; - char BADOUT[]="what are you exactly trying to do?"; + const char NOOUT[]="command did not return any output. could be an error or not.\n"; + const char BADOUT[]="what are you exactly trying to do?"; + const char STD_OUT[]="stdout returned:\n"; /*create socket*/ socket_desc = socket(AF_INET, SOCK_STREAM, 0); @@ -120,10 +123,59 @@ int mutator_server(FILE* log_file) fprintf(log_file, "%s", "got command from client.\n"); + mutator_config = fopen("/home/bloodstalker/devi/hell2/daemon/mutator.config", "r"); + + char configline[100]; + const char delimiter[2]="="; + char* token_var; + const char mutator_home_var[]="MUTATOR_HOME"; + const char driver_name[] = "/mutator.sh "; + char* full_command; + char* temp; + +#if 1 +#if 1 + while (fgets(configline,sizeof(configline), mutator_config) != NULL) + { + temp = strstr(configline, mutator_home_var); + + if (temp != NULL) + { + memmove(temp, configline + strlen(mutator_home_var) + 1, strlen(configline) - strlen(mutator_home_var) + 1); + + break; + } + } +#endif + +#if 1 + for (int i = 0; i < strlen(temp); ++i) + { + if (i == strlen(temp) - 1) + { + temp[i] = '\0'; + } + } + full_command = malloc(strlen(temp) + strlen(client_message) + strlen(driver_name) + 1); + + strcpy(full_command,temp); + strcat(full_command, driver_name); + strcat(full_command, client_message); + fprintf(log_file, "%s", full_command); +#endif +#endif + if (cleanser(client_message) == true) { +#ifndef __DBG + clientistream = popen(full_command, "r"); +#endif + +#if defined(__DBG) /*open pipe, run command*/ clientistream = popen(client_message, "r"); + //clientistream = popen(full_command, "r"); +#endif } else { @@ -132,6 +184,9 @@ int mutator_server(FILE* log_file) continue; } + fprintf(log_file, "%s", "freeing memory reserved for command.\n"); + free(full_command); + if (clientistream == NULL) { perror("client command did not run successfully."); @@ -146,16 +201,21 @@ int mutator_server(FILE* log_file) if (fgets(runresponse, sizeof(runresponse), clientistream) == NULL) { /*say there was nothing on stdout to send.*/ + fprintf(log_file, "%s", "command returned no stdout.\n"); write(client_sock, NOOUT, strlen(NOOUT)); } + else + { + fprintf(log_file, "%s", "command returned stdout.\n"); + write(client_sock, STD_OUT, strlen(STD_OUT)); + } rewind(clientistream); while (fgets(runresponse, sizeof(runresponse), clientistream) != NULL) { #if defined(__DBG) - fscanf(log_file, "%s", "command stdout:"); - fscanf(log_file, "%s", runresponse); + fprintf(log_file, "%s", "command stdout:\n"); #endif write(client_sock, runresponse, strlen(runresponse)); fprintf(log_file, "%s", runresponse); diff --git a/daemon/mutatorclient.c b/daemon/mutatorclient.c index 2b61d96..0addc76 100644 --- a/daemon/mutatorclient.c +++ b/daemon/mutatorclient.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* /**********************************************************************************************************************/ /*macros*/ #define __DBG -#if 1 +#if 0 #undef __DBG #endif /**********************************************************************************************************************/ @@ -97,14 +97,14 @@ int main(int argc, char *argv[]) fflush(stdin); #if defined(__DBG) - puts("checkpoint 1"); + puts("checkpoint 11"); #endif /*recieve a reply from the server*/ recvlength = recv(sock, server_reply, 2000, 0); #if defined(__DBG) - puts("checkpoint 2"); + puts("checkpoint 12"); #endif if (recvlength < 0) diff --git a/daemon/mutatord.c b/daemon/mutatord.c index a0496d3..a9d29cd 100644 --- a/daemon/mutatord.c +++ b/daemon/mutatord.c @@ -140,6 +140,8 @@ int main(void) fclose(mut_log); }while(0); + //return server_exit_code; + /*@DEVI-these obviously will never run. theyre just a reminder that i need to handle the gracefull shutdown*/ #if 0 fclose(mut_log); -- cgit v1.2.3