/** * @brief Deregisters a command from being executed * during the Windows boot process. * @param[in] command the name of the command's * executable, without the extension. * @return Zero for success, negative value otherwise. */ int winx_bootex_unregister(const wchar_t *command) { struct cmd *c, *list = NULL; struct cmd *head, *next = NULL; int result = (-1); DbgCheck1(command,-1); if(!wcscmp(command,L"")) return 0; /* get list of registered commands */ if(get_boot_exec_list(&list) < 0) goto done; /* remove specified command */ for(c = list; c; c = next){ head = list; next = c->next; if(cmd_compare(c->cmd,command) > 0){ winx_list_remove((list_entry **)(void *)&list, (list_entry *)c); } if(list == NULL) break; if(next == head) break; } /* save list of registered commands */ result = save_boot_exec_list(list); done: destroy_boot_exec_list(list); return result; }
/** * @brief Checks wheter a command is registered for * being executed during the Windows boot process or not. * @param[in] command the name of the command's * executable, without the extension. * @return Positive value indicates that the command * is registered, zero indicates that it isn't, * negative value indicates a failure of the check. */ int winx_bootex_check(const wchar_t *command) { struct cmd *c, *list = NULL; int result = (-1); DbgCheck1(command,-1); if(!wcscmp(command,L"")) return 0; /* get list of registered commands */ if(get_boot_exec_list(&list) < 0) goto done; /* check for specified command presence */ result = 0; for(c = list; c; c = c->next){ if(cmd_compare(c->cmd,command) > 0){ result = 1; break; } if(c->next == list) break; } done: destroy_boot_exec_list(list); return result; }
/** * @brief Registers a command to be executed * during the Windows boot process. * @param[in] command the name of the command's * executable, without the extension. * @return Zero for success, negative value otherwise. * @note Command's executable must be placed inside * the system32 directory to be executed successfully. */ int winx_bootex_register(const wchar_t *command) { struct cmd *c, *list = NULL; struct cmd *prev_command = NULL; int cmd_found = 0; wchar_t *cmd_copy; int result = (-1); DbgCheck1(command,-1); if(!wcscmp(command,L"")) return 0; /* get list of registered commands */ if(get_boot_exec_list(&list) < 0) goto done; /* append specified command if necessary */ for(c = list; c; c = c->next){ if(cmd_compare(c->cmd,command) > 0){ cmd_found = 1; break; } if(c->next == list) break; } if(cmd_found){ result = 0; goto done; } cmd_copy = winx_wcsdup(command); if(cmd_copy == NULL){ mtrace(); goto done; } if(list) prev_command = list->prev; c = (struct cmd *)winx_list_insert( (list_entry **)(void *)&list, (list_entry *)prev_command, sizeof(struct cmd)); c->cmd = cmd_copy; /* save list of registered commands */ result = save_boot_exec_list(list); done: destroy_boot_exec_list(list); return result; }
/* Returns 0 if OK, 1 if *any* error! */ int msg_get(client_state_t *client) { con_t con = client->connection; client_list_t *clients = client->global->clients; client_state_t *curr_client; char *buffer = NULL; unsigned int textsize = 128; char *text = malloc(textsize); int status = con_line(con, &buffer); cmd_t *command = NULL; msg_t *msg = NULL; /*Sanity check for input, len<4 is nonsense (say ,the shortest message*/ if ( (status != CON_ERROR_NONE) || (!buffer) || (4 > strlen(buffer))){ free(buffer); return (status != CON_ERROR_NONE);/*Not an error, just some noise, closed?*/ } if (status != CON_ERROR_NONE) { printf("ERROR! No. : %d\r\n", status); return 2; } command = parse_command(buffer); msg = malloc(sizeof(msg_t)); if (!(strcmp(command->command, " "))) return -1; else if (!(msg && command && command->command)) return 1; if (!(text)) return 1; if (cmd_compare(command->command, "CHAT")) { if (client->state & CLIENT_STATE_CONNECTED) { /* Received "CHAT", client auths, send "+OK" */ msg->arg = "\r\n"; msg->status = STATUS_POS; msg->msg_type = MSG_TYPE_CHAT; send_msg(msg, client); client->state |= CLIENT_STATE_AUTHED; } else { return -1; } } else if(cmd_compare(command->command, "USER")) { if (client->state & CLIENT_STATE_AUTHED) { /* Received "USER", check in users_list if exists, if no match, reg.*/ int found = 0; while(clients) { curr_client = clients->current; if ((curr_client) && (curr_client->username) && (cmd_compare(curr_client->username, command->msg))) { // Match in list: return neg. msg. found = 42; break; } clients = clients->next; } msg->status = (found) ? STATUS_NEG : STATUS_POS; msg->msg_type = (found) ? MSG_TYPE_IN_USE : MSG_TYPE_OK; msg->arg = (found) ? "Username in use\r\n" : "\r\n"; /* Send all other clients RENAME or JOIN msg. */ if (!(found)) { if (client->state & CLIENT_STATE_LOGGED_IN) { msg_t *mesg = malloc(sizeof(msg_t)); mesg->arg = malloc(strlen(curr_client->username) + strlen(command->msg) + 4); sprintf(mesg->arg, "%s/%s\r\n", curr_client->username, command->msg); mesg->msg_type = MSG_TYPE_RENAME; mesg->status = STATUS_POS; send_msg(mesg, client); } else if (client->state & CLIENT_STATE_AUTHED) { msg_t *mesg = malloc(sizeof(msg_t)); mesg->arg = malloc(strlen(curr_client->username) + strlen(command->msg) + 4); sprintf(mesg->arg, "%s\r\n", command->msg); mesg->msg_type = MSG_TYPE_JOIN; mesg->status = STATUS_POS; send_msg(mesg, client); } } client->username = (found) ? client->username : command->msg; client->state |= (found) ? client->state : CLIENT_STATE_LOGGED_IN; send_msg(msg, client); } else { return -1; } } else if(cmd_compare(command->command, "NAMES")) { /* Received "NAMES"*/ if (client->state & CLIENT_STATE_LOGGED_IN) { while(clients) { curr_client = clients->current; if (curr_client) { if (curr_client->state & CLIENT_STATE_LOGGED_IN) { if (strlen(text) < textsize - 2) { sprintf(text, "%s%s\r\n", text, curr_client->username); } else { text = realloc(text, textsize += 128); sprintf(text, "%s%s\r\n", text, curr_client->username); } } clients = clients->next; } } sprintf(text, "%s\r\n", text); msg->arg = text; msg->status = STATUS_POS; msg->msg_type = MSG_TYPE_NAMES; send_msg(msg, client); } else { return -1; } } else if(cmd_compare(command->command, "SAY")) { /* Received "SAY"*/ if (client->state & CLIENT_STATE_LOGGED_IN) { msg->arg = malloc(strlen(command->msg) + strlen(client->username) + 4); if (! msg->arg) return 1; sprintf(msg->arg, "%s/%s\r\n", client->username, command->msg); msg->status = STATUS_POS; msg->msg_type = MSG_TYPE_SAY; send_msg(msg, client); } else { return -1; } } else { return -1; } free(buffer); return 0; }