static void exec_cmd (const s_symtable *cmd) { s_symtable xc; char buf[2048]; assert(cmd); symtable_init(&xc); symtable_add(&xc, SHELL); symtable_add(&xc, "-c"); stracat(buf, sizeof(buf), cmd->sym + 1, cmd->count - 1); symtable_add(&xc, buf); log_cmd("EXEC", &xc); cleanup(); execvp(xc.sym[0], (char **)xc.sym); syslog(LOG_ERR, "execvp: %s", strerror(errno)); err(2, "execvp"); }
int wifi_send_command(const char *cmd, char *reply, size_t *reply_len) { int ret; if (ctrl_conn == NULL) { ALOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd); return -1; } log_cmd(cmd); ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL); if (ret == -2) { ALOGD("'%s' command timed out.\n", cmd); /* unblocks the monitor receive socket for termination */ TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1)); return -2; } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) { LOGI("REPLY: FAIL\n"); return -1; } if (strncmp(cmd, "PING", 4) == 0) { reply[*reply_len] = '\0'; } log_reply(reply, reply_len); return 0; }
int handle_login(struct clientinfo* clntinfo) { struct cmdhandlerstruct *cmdhandler; char *buffer = 0; int ss, cs; int i, expected; int protoviolations = 0; conn_info.lcs = &lcs; conn_info.clntinfo = clntinfo; ss = clntinfo->serversocket; cs = clntinfo->clientsocket; if (clntinfo->transparent == TRANSPARENT_YES /* we are connected */ && config_compare_option("logintime", "connect")) { if (config_get_ioption("loginstyle", 0) != 0) { jlog(5, "A login at the connection time only works with loginstyle == 0, setting loginstyle = 0"); config_option_list_delete("loginstyle"); config_option_list_add("loginstyle", "0"); } } cmdhandler = &login_auth_funcs [ config_get_ioption("loginstyle", 0) ][0]; expected = QUITFUNC + 1; /* skip reset and quit function */ while (1) { if (timeout) { jlog(2, "Timeout in %s line %d\n", __FILE__ ,__LINE__); return -1; } if (buffer) { free(buffer); buffer = 0; } buffer = readline(cs); lcs.cmd = (char*) 0; if (buffer) { lcs.cmd = buffer; free(lcs.method); i = 0; lcs.method = quotstrtok(lcs.cmd, WHITESPACES, &i); if (buffer[0] == '\0') { /* empty line. Prevent logging of the * command */ free(buffer); buffer = 0; continue; } /* log the command */ log_cmd(&lcs); free(lcs.method); lcs.method = (char*) 0; lcs.respcode = 0; lcs.transferred = 0; } if (!buffer) { if (timeout) { jlog(2, "Timeout in %s line %d\n", __FILE__ ,__LINE__); err_time_readline(cs); } else { err_readline(cs); } return -1; } jlog(8, "Expecting %s", cmdhandler[expected].cmd); if (my_strcasestr(buffer, "PASS") == (char*) 0) { jlog(8, "Got: %s", buffer); } else { jlog(8, "Got the password"); } /* check for QUIT */ if (checkbegin(buffer, "QUIT")) { int ret = (cmdhandler[QUITFUNC].func) (buffer, &conn_info); ret = (cmdhandler[RESETFUNC].func) (buffer, &conn_info); free(buffer); /* return 1 to prevent the proxy from entering * handle_cmds */ return 1; } if (cmdhandler[expected].cmd && checkbegin(buffer, cmdhandler[expected].cmd)) { int ret = (cmdhandler[expected].func) (buffer, &conn_info); memset(buffer, 0, strlen(buffer)); protoviolations = 0; switch (ret) { case CMD_DONE: /* we're done - logged in */ /* CMD_DONE is returned if the USER * command got a 230 response back * */ break; case CMD_HANDLED: /* expecting the next */ expected++; break; case CMD_ERROR: /* reset counter, skip reset and * quit function */ ret = (cmdhandler[RESETFUNC].func) (buffer, &conn_info); expected = QUITFUNC + 1; /* errors are handled by the * command handler functions * */ break; case CMD_ABORT: return -1; break; } /* found and called proper function */ } else { protoviolations++; if (protoviolations >= config_get_ioption("loginprotocolviolations", 10)){ /* like ABORT */ sayf(clntinfo->clientsocket, "500 Too many consequent protocol " "violations - Closing connection\r\n"); return -1; } sayf(clntinfo->clientsocket, "530 Login incorrect. Expected %scommand\r\n", cmdhandler[expected].cmd); /* reset counter, skip reset and quit function */ (cmdhandler[RESETFUNC].func) (buffer, &conn_info); expected = QUITFUNC + 1; } if (clntinfo->login.stage == LOGIN_ST_FULL) { /* we are done */ free(buffer); buffer = (char*) 0; return 0; } } /* lcs.host and lcs.user are freed at the termination of the * programm */ }