/** * @brief Request a subsystem (for example "sftp"). * * @param channel The channel to send the request. * * @param system The subsystem to request (for example "sftp"). * * @return SSH_SUCCESS on success, SSH_ERROR on error. * * @warning You normally don't have to call it for sftp, see sftp_new(). */ int channel_request_subsystem(CHANNEL *channel, const char *sys) { BUFFER *buffer = NULL; STRING *subsystem = NULL; int rc = SSH_ERROR; buffer = buffer_new(); if (buffer == NULL) { goto error; } subsystem = string_from_char(sys); if (subsystem == NULL) { goto error; } if (buffer_add_ssh_string(buffer, subsystem) < 0) { goto error; } rc = channel_request(channel, "subsystem", buffer, 1); error: buffer_free(buffer); string_free(subsystem); return rc; }
/** * @brief Run a shell command without an interactive shell. * * This is similar to 'sh -c command'. * * @param channel The channel to execute the command. * * @param cmd The command to execute * (e.g. "ls ~/ -al | grep -i reports"). * * @return SSH_SUCCESS on success, SSH_ERROR on error. * * @see channel_request_shell() */ int channel_request_exec(CHANNEL *channel, const char *cmd) { BUFFER *buffer = NULL; STRING *command = NULL; int rc = SSH_ERROR; #ifdef HAVE_SSH1 if (channel->version == 1) { return channel_request_exec1(channel, cmd); } #endif buffer = buffer_new(); if (buffer == NULL) { goto error; } command = string_from_char(cmd); if (command == NULL) { goto error; } if (buffer_add_ssh_string(buffer, command) < 0) { goto error; } rc = channel_request(channel, "exec", buffer, 1); error: buffer_free(buffer); string_free(command); return rc; }
/** * @brief Change the size of the terminal associated to a channel. * * @param channel The channel to change the size. * * @param cols The new number of columns. * * @param rows The new number of rows. * * @warning Do not call it from a signal handler if you are not * sure any other libssh function using the same channel/session * is running at same time (not 100% threadsafe). */ int channel_change_pty_size(CHANNEL *channel, int cols, int rows) { SSH_SESSION *session = channel->session; BUFFER *buffer = NULL; int rc = SSH_ERROR; enter_function(); #ifdef HAVE_SSH1 if (channel->version == 1) { rc = channel_change_pty_size1(channel,cols,rows); leave_function(); return rc; } #endif buffer = buffer_new(); if (buffer == NULL) { goto error; } if (buffer_add_u32(buffer, htonl(cols)) < 0 || buffer_add_u32(buffer, htonl(rows)) < 0 || buffer_add_u32(buffer, 0) < 0 || buffer_add_u32(buffer, 0) < 0) { goto error; } rc = channel_request(channel, "window-change", buffer, 0); error: buffer_free(buffer); leave_function(); return rc; }
/** * @brief Request a shell. * * @param channel The channel to send the request. * * @returns SSH_SUCCESS on success, SSH_ERROR on error. */ int channel_request_shell(CHANNEL *channel) { #ifdef HAVE_SSH1 if (channel->version == 1) { return channel_request_shell1(channel); } #endif return channel_request(channel, "shell", NULL, 1); }
/** * @brief Request a pty with a specific type and size. * * @param channel The channel to sent the request. * * @param terminal The terminal type ("vt100, xterm,..."). * * @param col The number of columns. * * @param row The number of rows. * * @return SSH_SUCCESS on success, SSH_ERROR on error. */ int channel_request_pty_size(CHANNEL *channel, const char *terminal, int col, int row) { SSH_SESSION *session = channel->session; STRING *term = NULL; BUFFER *buffer = NULL; int rc = SSH_ERROR; enter_function(); #ifdef HAVE_SSH1 if (channel->version==1) { channel_request_pty_size1(channel,terminal, col, row); leave_function(); return rc; } #endif buffer = buffer_new(); if (buffer == NULL) { goto error; } term = string_from_char(terminal); if (term == NULL) { goto error; } if (buffer_add_ssh_string(buffer, term) < 0 || buffer_add_u32(buffer, htonl(col)) < 0 || buffer_add_u32(buffer, htonl(row)) < 0 || buffer_add_u32(buffer, 0) < 0 || buffer_add_u32(buffer, 0) < 0 || buffer_add_u32(buffer, htonl(1)) < 0 || /* Add a 0byte string */ buffer_add_u8(buffer, 0) < 0) { goto error; } rc = channel_request(channel, "pty-req", buffer, 1); error: buffer_free(buffer); string_free(term); leave_function(); return rc; }
/** * @brief Set environement variables. * * @param channel The channel to set the environement variables. * * @param name The name of the variable. * * @param value The value to set. * * @return SSH_SUCCESS on success, SSH_ERROR on error. * * @warning Some environement variables may be refused by security reasons. * */ int channel_request_env(CHANNEL *channel, const char *name, const char *value) { BUFFER *buffer = NULL; STRING *str = NULL; int rc = SSH_ERROR; buffer = buffer_new(); if (buffer == NULL) { goto error; } str = string_from_char(name); if (str == NULL) { goto error; } if (buffer_add_ssh_string(buffer, str) < 0) { goto error; } string_free(str); str = string_from_char(value); if (str == NULL) { goto error; } if (buffer_add_ssh_string(buffer, str) < 0) { goto error; } rc = channel_request(channel, "env", buffer,1); error: buffer_free(buffer); string_free(str); return rc; }
BOOL ap_table_parse_process(void) { switch(g_priv.status) { case INIT_IDLE: //idle break; case INIT_NIT_REQUEST_TABLE: nit_request_start(); if(g_priv.channel_parse->channel_bit !=0) { channel_request(); } g_priv.status = INIT_WAIT_TABLE; break; case INIT_REQUEST_TABLE:// request channel_request(); g_priv.status = INIT_WAIT_TABLE; break; case INIT_WAIT_TABLE: //running break; case INIT_DONE_CHANNEL_PARSE: //done //release resource { u8 vid = 0; u32 channel_version = 0; #ifdef CHANNEL_FOLLOWING_TABLE channel_version = (u32)sys_status_get_channel_version(); #endif if(g_priv.version != channel_version) { if(g_priv.channel_parse->p_channel_process != NULL) { g_priv.channel_parse->p_channel_process(); } } vid = db_dvbs_create_view(DB_DVBS_ALL_PG, 0, NULL); if((g_priv.table_found_bit == TRUE) && (db_dvbs_get_count(vid) > 0)) { startup_nit_channel_status = TRUE; } if((g_priv.nit_finish ==1) && (g_priv.channel_finish ==1)) { g_priv.status = INIT_FINISH; } else { g_priv.status = INIT_WAIT_TABLE; } } break; case INIT_FINISH: { dvb_t *p_dvb = class_get_handle_by_id(DVB_CLASS_ID); p_dvb->remove_svc_instance(p_dvb, g_priv.p_dvb_svc); nc_remove_svc_instance(class_get_handle_by_id(NC_CLASS_ID), g_priv.p_nc_svc); } return TRUE; break; default: break; } return FALSE; }