static int str_netfd_write_common(const struct mystr* p_str, int fd, int noblock) { int ret = 0; int retval; unsigned int str_len = str_getlen(p_str); if (str_len == 0) { bug("zero str_len in str_netfd_write_common"); } if (noblock) { vsf_sysutil_activate_noblock(fd); } retval = str_write_loop(p_str, fd); if (vsf_sysutil_retval_is_error(retval) || (unsigned int) retval != str_len) { ret = -1; } if (noblock) { vsf_sysutil_deactivate_noblock(fd); } return ret; }
static void handle_alarm_timeout(void* p_private) { struct vsf_session* p_sess = (struct vsf_session*) p_private; p_sess->idle_timeout = 1; vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); vsf_sysutil_shutdown_read_failok(VSFTP_COMMAND_FD); }
void bug(const char* p_text) { /* Rats. Try and write the reason to the network for diagnostics */ vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, FTP_500_STRING, FTP_500_SIZE); (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text, vsf_sysutil_strlen(p_text)); (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2); vsf_sysutil_exit(2); }
void vsf_cmdio_write_exit(struct vsf_session* p_sess, int status, const char* p_text, int exit_val) { /* Unblock any readers on the dying control channel. This is needed for SSL * connections, where the SSL control channel slave is in a separate * process. */ vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); vsf_sysutil_shutdown_read_failok(VSFTP_COMMAND_FD); vsf_cmdio_write(p_sess, status, p_text); vsf_sysutil_shutdown_failok(VSFTP_COMMAND_FD); vsf_sysutil_exit(exit_val); }
static void handle_sigalrm(void* p_private) { struct vsf_session* p_sess = (struct vsf_session*) p_private; if (!p_sess->data_progress) { p_sess->data_timeout = 1; vsf_sysutil_shutdown_failok(p_sess->data_fd); vsf_sysutil_shutdown_read_failok(VSFTP_COMMAND_FD); vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); } else { p_sess->data_progress = 0; start_data_alarm(p_sess); } }
static void ftp_write_str_common(struct vsf_session* p_sess, int status, char sep, const struct mystr* p_str, int noblock) { static struct mystr s_write_buf_str; static struct mystr s_text_mangle_str; int retval; if (tunable_log_ftp_protocol) { str_alloc_ulong(&s_write_buf_str, (unsigned long) status); str_append_char(&s_write_buf_str, sep); str_append_str(&s_write_buf_str, p_str); vsf_log_line(p_sess, kVSFLogEntryFTPOutput, &s_write_buf_str); } str_copy(&s_text_mangle_str, p_str); /* Process the output response according to the specifications.. */ /* Escape telnet characters properly */ str_replace_text(&s_text_mangle_str, "\377", "\377\377"); /* Change \n for \0 in response */ str_replace_char(&s_text_mangle_str, '\n', '\0'); /* Build string to squirt down network */ str_alloc_ulong(&s_write_buf_str, (unsigned long) status); str_append_char(&s_write_buf_str, sep); str_append_str(&s_write_buf_str, &s_text_mangle_str); str_append_text(&s_write_buf_str, "\r\n"); if (noblock) { vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); } retval = ftp_write_str(p_sess, &s_write_buf_str, kVSFRWControl); if (retval != 0 && !noblock) { die("ftp_write"); } if (noblock) { vsf_sysutil_deactivate_noblock(VSFTP_COMMAND_FD); } }