static void parse_username_password(struct vsf_session* p_sess) { while (1) { /* Kitsune: update point */ kitsune_update("prelogin.c"); /**DSU updatepoint */ /* Kitsune */ vsf_sysutil_kitsune_set_update_point("prelogin.c"); vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (str_equal_text(&p_sess->ftp_cmd_str, "USER")) { handle_user_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASS")) { handle_pass_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT")) { vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye."); vsf_sysutil_exit(0); } else { vsf_cmdio_write(p_sess, FTP_LOGINERR, "Please login with USER and PASS."); } } }
static void parse_username_password(struct vsf_session* p_sess) { while (1) { vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (str_equal_text(&p_sess->ftp_cmd_str, "USER")) { handle_user_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASS")) { handle_pass_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT")) { vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye."); vsf_sysutil_exit(0); } else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT")) { handle_feat(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "AUTH")) { handle_auth(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PBSZ")) { handle_pbsz(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PROT")) { handle_prot(p_sess); } else { vsf_cmdio_write(p_sess, FTP_LOGINERR, "Please login with USER and PASS."); } } }
static void parse_username_password(struct vsf_session* p_sess) { while (1) { vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (tunable_ftp_enable) { if (str_equal_text(&p_sess->ftp_cmd_str, "USER")) { handle_user_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASS")) { handle_pass_command(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT")) { vsf_cmdio_write_exit(p_sess, FTP_GOODBYE, "Goodbye."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT")) { handle_feat(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "OPTS")) { handle_opts(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "AUTH") && !p_sess->control_use_ssl) { handle_auth(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PBSZ")) { handle_pbsz(p_sess); } else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PROT")) { handle_prot(p_sess); } else if (str_isempty(&p_sess->ftp_cmd_str) && str_isempty(&p_sess->ftp_arg_str)) { /* Deliberately ignore to avoid NAT device bugs, as per ProFTPd. */ } else { vsf_cmdio_write(p_sess, FTP_LOGINERR, "Please login with USER and PASS."); } } else if (tunable_http_enable) { if (str_equal_text(&p_sess->ftp_cmd_str, "GET")) { handle_get(p_sess); } else { vsf_cmdio_write(p_sess, FTP_LOGINERR, "Bad HTTP verb."); } vsf_sysutil_exit(0); } } }
int main(int argc, char *argv[]) { struct server_settings settings = {30000, 0, 1}; handle_arguments(argc, argv, &settings); struct player_character hero; init_player_character(&hero); char stat_buffer[256]; randomize_player_character_stats(&hero); snprintf(stat_buffer, 255, "STR - %i\r\nDEX - %i\r\nCON - %i\r\n", hero.strength, hero.dexterity, hero.constitution); if (catch_signal(SIGINT, handle_shutdown) == -1) { error("Can't set the interrupt handler"); } else if (settings.verbose) { puts("Interrupt handler set"); } listener_d = open_listener_socket(); bind_to_port(listener_d, settings.port_number); if (listen(listener_d, 10) == -1) { error("Can't listen"); } else if (settings.verbose) { printf("Listening on port %i", settings.port_number); } struct sockaddr_storage client_addr; unsigned int address_size = sizeof(client_addr); if (settings.verbose) { puts("Waiting for connection"); } while(1) { int connect_d = accept(listener_d, (struct sockaddr *)&client_addr, &address_size); if (connect_d == -1) { error("Can't open secondary socket"); } else if (settings.verbose) { puts("New connection started"); } if (!fork()) { close(listener_d); char input_buffer[512]; char output_buffer[512]; char send_buffer[512]; char action_buffer[3]; send_version(connect_d); while (1) { get_command(connect_d, action_buffer); puts(action_buffer); if (action_buffer[0] == 's') { puts("opening chat buffer"); listen_to_client(connect_d, input_buffer); parse_command(input_buffer, output_buffer); sprintf(send_buffer, "You said: \"%s\"\r\n", output_buffer); puts(send_buffer); send_to_client(connect_d, send_buffer); } else { handle_user_command(connect_d, action_buffer); } } close(connect_d); exit(0); } close(connect_d); } return 0; }
void *client_handler(void *void_args) { user_session_t *session = (user_session_t *) void_args; status_t error; //Finish session initialization session->directory = realpath(".", NULL); if (session->directory == NULL) { error = REALPATH_ERROR; goto exit0; } session->data_sock = -1; //End session initialization error = send_response(session->command_sock, SERVICE_READY, "Ready. Please send USER.", session->server->log, 0); if (error) { goto exit1; } string_t command; string_initialize(&command); uint8_t done = 0; do { char_vector_clear(&command); error = read_single_line(session->command_sock, &command); if (!error) { error = write_received_message_to_log(session->server->log, &command); if (!error) { //Remove the CRLF from the command char_vector_pop_back(&command); char_vector_pop_back(&command); //Split the string up by spaces size_t len; string_t *split = string_split_skip_consecutive(&command, ' ', &len, 1); char *c_str = string_c_str(split + 0); //Determine which command has been sent if (bool_strcmp(c_str, "USER")) { error = handle_user_command(session, split, len); } else if (bool_strcmp(c_str, "PASS")) { error = handle_pass_command(session, split, len); } else if (bool_strcmp(c_str, "CWD")) { error = handle_cwd_command(session, split, len); } else if (bool_strcmp(c_str, "CDUP")) { error = handle_cdup_command(session, split, len); } else if (bool_strcmp(c_str, "QUIT")) { done = 1; error = handle_quit_command(session, split, len); } else if (bool_strcmp(c_str, "PASV")) { error = handle_pasv_command(session, split, len); } else if (bool_strcmp(c_str, "EPSV")) { error = handle_epsv_command(session, split, len); } else if (bool_strcmp(c_str, "PORT")) { error = handle_port_command(session, split, len); } else if (bool_strcmp(c_str, "EPRT")) { error = handle_eprt_command(session, split, len); } else if (bool_strcmp(c_str, "RETR")) { error = handle_retr_command(session, split, len); } else if (bool_strcmp(c_str, "PWD")) { error = handle_pwd_command(session, split, len); } else if (bool_strcmp(c_str, "LIST")) { error = handle_list_command(session, split, len); } else if (bool_strcmp(c_str, "HELP")) { error = handle_help_command(session, split, len); } else { error = handle_unrecognized_command(session, split, len); } size_t i; for (i = 0; i < len; i++) { string_uninitialize(split + i); } free(split); } } if (error) { char message[] = "Error encountered while processing: "; string_t error_message; string_initialize(&error_message); char *error_string = get_error_message(error); string_assign_from_char_array(&error_message, error_string); prepend_and_write_to_log(session->server->log, &error_message, message, sizeof message); string_uninitialize(&error_message); } } while (!error && !done); char quitting_message[] = "Client quitting.\n"; exit2: string_uninitialize(&command); exit1: free(session->directory); exit0: write_log(session->server->log, quitting_message, sizeof quitting_message); printf("%s", quitting_message); free(session); pthread_exit(NULL); }