enum cmd_retval cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_q *cmdq1; int quiet; cmdq1 = cmdq_new(cmdq->client); cmdq1->flags |= cmdq->flags & CMD_Q_NOHOOKS; cmdq1->emptyfn = cmd_source_file_done; cmdq1->data = cmdq; quiet = args_has(args, 'q'); switch (load_cfg(args->argv[0], cmdq1, quiet)) { case -1: cmdq_free(cmdq1); if (cfg_references == 0) { cfg_print_causes(cmdq); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); case 0: cmdq_free(cmdq1); if (cfg_references == 0) cfg_print_causes(cmdq); return (CMD_RETURN_NORMAL); } cmdq->references++; cfg_references++; cmdq_continue(cmdq1); return (CMD_RETURN_WAIT); }
static void handle_exec_cmd_str(__unused struct tmate_session *session, struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; char *cause; u_int i; int client_id = unpack_int(uk); char *cmd_str = unpack_string(uk); if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist, NULL); cmd_list_free(cmdlist); cmdq_free(cmd_q); /* error messages land in cfg_causes */ for (i = 0; i < cfg_ncauses; i++) { tmate_failed_cmd(client_id, cfg_causes[i]); free(cfg_causes[i]); } free(cfg_causes); cfg_causes = NULL; cfg_ncauses = 0; out: free(cmd_str); }
static void tmate_client_exec_cmd(struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; char *cause; int client_id = unpack_int(uk); char *cmd_str = unpack_string(uk); if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } /* error messages land in cfg_causes */ ARRAY_FREE(&cfg_causes); cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist); cmd_list_free(cmdlist); cmdq_free(cmd_q); if (!ARRAY_EMPTY(&cfg_causes)) { cause = ARRAY_ITEM(&cfg_causes, 0); tmate_failed_cmd(client_id, cause); free(cause); ARRAY_FREE(&cfg_causes); } out: free(cmd_str); }
void cfg_default_done(__unused struct cmd_q *cmdq) { if (--cfg_references != 0) return; cfg_finished = 1; if (!RB_EMPTY(&sessions)) cfg_show_causes(RB_MIN(sessions, &sessions)); cmdq_free(cfg_cmd_q); cfg_cmd_q = NULL; if (cfg_client != NULL) { /* * The client command queue starts with client_exit set to 1 so * only continue if not empty (that is, we have been delayed * during configuration parsing for long enough that the * MSG_COMMAND has arrived), else the client will exit before * the MSG_COMMAND which might tell it not to. */ if (!TAILQ_EMPTY(&cfg_client->cmdq->queue)) cmdq_continue(cfg_client->cmdq); server_client_unref(cfg_client); cfg_client = NULL; } }
void cmd_source_file_done(struct cmd_q *cmdq1) { struct cmd_q *cmdq = cmdq1->data; if (cmdq1->client_exit >= 0) cmdq->client_exit = cmdq1->client_exit; cmdq_free(cmdq1); cfg_references--; if (cmdq_free(cmdq)) return; if (cfg_references == 0) cfg_print_causes(cmdq); cmdq_continue(cmdq); }
void cmd_if_shell_done(struct cmd_q *cmdq1) { struct cmd_if_shell_data *cdata = cmdq1->data; struct cmd_q *cmdq = cdata->cmdq; if (cmdq1->client_exit >= 0) cmdq->client_exit = cmdq1->client_exit; cmdq_free(cmdq1); if (--cdata->references != 0) return; if (!cmdq_free(cmdq) && !cdata->bflag) cmdq_continue(cmdq); free(cdata->cmd_else); free(cdata->cmd_if); free(cdata); }
void cmd_run_shell_free(void *data) { struct cmd_run_shell_data *cdata = data; struct cmd_q *cmdq = cdata->cmdq; if (!cmdq_free(cmdq) && !cdata->bflag) cmdq_continue(cmdq); free(cdata->cmd); free(cdata); }
static void handle_exec_cmd(__unused struct tmate_session *session, struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; struct cmd *cmd; char *cause; u_int i; unsigned int argc; char **argv; int client_id = unpack_int(uk); argc = uk->argc; argv = xmalloc(sizeof(char *) * argc); for (i = 0; i < argc; i++) argv[i] = unpack_string(uk); cmd = cmd_parse(argc, argv, NULL, 0, &cause); if (!cmd) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } cmdlist = xcalloc(1, sizeof *cmdlist); cmdlist->references = 1; TAILQ_INIT(&cmdlist->list); TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry); cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist, NULL); cmd_list_free(cmdlist); cmdq_free(cmd_q); /* error messages land in cfg_causes */ for (i = 0; i < cfg_ncauses; i++) { tmate_failed_cmd(client_id, cfg_causes[i]); free(cfg_causes[i]); } free(cfg_causes); cfg_causes = NULL; cfg_ncauses = 0; out: cmd_free_argv(argc, argv); }
void cmd_if_shell_free(void *data) { struct cmd_if_shell_data *cdata = data; struct cmd_q *cmdq = cdata->cmdq; if (--cdata->references != 0) return; if (!cmdq_free(cmdq) && !cdata->bflag) cmdq_continue(cmdq); free(cdata->cmd_else); free(cdata->cmd_if); free(cdata); }