/* Main HelpServ routine. */ void helpserv(const char *source, User *callerUser, char *buf) { TRACE_MAIN_FCLT(FACILITY_HELPSERV); if (IS_NULL(buf) || IS_EMPTY_STR(buf)) send_notice_lang_to_user(s_HelpServ, callerUser, GetCallerLang(), ERROR_ACCESS_DENIED); else if (buf[0] == '\001') { if (IS_EMPTY_STR(buf + 1)) LOG_SNOOP(s_HelpServ, "Invalid CTCP from \2%s\2", source); else if (str_equals_nocase(buf + 1, "PING")) { send_notice_to_user(s_HelpServ, callerUser, "\1%s", buf + 1); LOG_SNOOP(s_HelpServ, "CTCP: PING from \2%s\2", source); } else { if (buf[str_len(buf) - 1] == '\001') buf[str_len(buf) - 1] = '\0'; LOG_SNOOP(s_HelpServ, "CTCP: %s from \2%s\2", buf + 1, source); } } else { ServiceCommandData data; data.commandName = buf; data.userLevel = ULEVEL_NOACCESS; data.operMatch = TRUE; data.operName = NULL; data.agent = &a_HelpServ; handle_help(source, callerUser, &data); } }
int handle_cntrl_char (int c, char *cmd) { if(IS_BACK_SPACE(c)) { if(cmd[0] == '\0') return 0; write (gfd,"\b \b",sizeof("\b \b")); cmd[strlen(cmd) - 1] = '\0'; return 0; } else if(c == 0x1b ) { c = read_input(); c = read_input(); if(c == 65) { return 0; } else if(c == 66) { } return 0; } else if(IS_HELP_CHAR(c)) { write_input_on_screen (c); is_help = 1; handle_help(cmd, 0); is_help = 0; goto cmd_print; } else if(IS_TAB(c)) { handle_tab (cmd); goto cmd_print; } else { return 1; } cmd_print: print_prompt (); write_string (cmd); return 0; }
static int handle(char *buf) { TCSession *session = tc_get_session(); char *cmd, *params; int len, retval; len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[--len] = 0; if (len > 0 && buf[len-1] == '\r') buf[--len] = 0; //tc_log_msg(__FILE__, "read from socket: |%s|", buf); cmd = buf + strspn(buf, " \t"); params = cmd + strcspn(cmd, " \t"); *params++ = 0; params += strspn(params, " \t"); if (!*cmd) { // not strictly necessary, but lines up else if's nicely retval = 0; } else if (strncasecmp(cmd, "config", 2) == 0) { retval = handle_config(params); } else if (strncasecmp(cmd, "disable", 2) == 0) { retval = handle_disable(params); } else if (strncasecmp(cmd, "dump", 2) == 0) { dump_vob(client_sock); retval = 1; } else if (strncasecmp(cmd, "enable", 2) == 0) { retval = handle_enable(params); } else if (strncasecmp(cmd, "help", 2) == 0) { retval = handle_help(params); } else if (strncasecmp(cmd, "list", 2) == 0) { retval = handle_list(params); } else if (strncasecmp(cmd, "load", 2) == 0) { retval = handle_load(params); } else if (strncasecmp(cmd, "parameters", 3) == 0) { retval = handle_parameter(params); } else if (strncasecmp(cmd, "pause", 3) == 0) { tc_pause_request(); retval = 1; } else if (strncasecmp(cmd, "preview", 3) == 0) { retval = handle_preview(params); } else if (strncasecmp(cmd, "progress", 5) == 0) { session->progress_meter = !session->progress_meter; retval = 1; } else if (strncasecmp(cmd, "processing", 10) == 0) { dump_processing(client_sock); retval = 1; } else if (strncasecmp(cmd, "quit", 2) == 0 || strncasecmp(cmd, "exit", 2) == 0) { return 0; // tell caller to close socket } else if (strncasecmp(cmd, "unload", 2) == 0) { retval = 0; // FIXME: not implemented } else if (strncasecmp(cmd, "version", 2) == 0) { sendstr(client_sock, PACKAGE_VERSION "\n"); retval = 1; } else if (strncasecmp(cmd, "stop", 4)) { tc_interrupt(); tc_framebuffer_interrupt(); retval = 1; } else { retval = 0; } sendstr(client_sock, retval ? "OK\n" : "FAILED\n"); return 1; // socket remains open }
void process_post_login(struct vsf_session* p_sess) { if (p_sess->is_anonymous) { vsf_sysutil_set_umask(tunable_anon_umask); p_sess->bw_rate_max = tunable_anon_max_rate; } else { vsf_sysutil_set_umask(tunable_local_umask); p_sess->bw_rate_max = tunable_local_max_rate; } if (tunable_async_abor_enable) { vsf_sysutil_install_sighandler(kVSFSysUtilSigURG, handle_sigurg, p_sess); vsf_sysutil_activate_sigurg(VSFTP_COMMAND_FD); } /* Handle any login message */ vsf_banner_dir_changed(p_sess, FTP_LOGINOK); vsf_cmdio_write(p_sess, FTP_LOGINOK, "Login successful."); while(1) { int cmd_ok = 1; if (tunable_setproctitle_enable) { vsf_sysutil_setproctitle("IDLE"); } /* Blocks */ vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (tunable_setproctitle_enable) { struct mystr proctitle_str = INIT_MYSTR; str_copy(&proctitle_str, &p_sess->ftp_cmd_str); if (!str_isempty(&p_sess->ftp_arg_str)) { str_append_char(&proctitle_str, ' '); str_append_str(&proctitle_str, &p_sess->ftp_arg_str); } /* Suggestion from Solar */ str_replace_unprintable(&proctitle_str, '?'); vsf_sysutil_setproctitle_str(&proctitle_str); str_free(&proctitle_str); } /* Test command against the allowed list.. */ if (tunable_cmds_allowed) { static struct mystr s_src_str; static struct mystr s_rhs_str; str_alloc_text(&s_src_str, tunable_cmds_allowed); while (1) { str_split_char(&s_src_str, &s_rhs_str, ','); if (str_isempty(&s_src_str)) { cmd_ok = 0; break; } else if (str_equal(&s_src_str, &p_sess->ftp_cmd_str)) { break; } str_copy(&s_src_str, &s_rhs_str); } } if (!cmd_ok) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); } 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, "PWD") || str_equal_text(&p_sess->ftp_cmd_str, "XPWD")) { handle_pwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CWD") || str_equal_text(&p_sess->ftp_cmd_str, "XCWD")) { handle_cwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CDUP") || str_equal_text(&p_sess->ftp_cmd_str, "XCUP")) { handle_cdup(p_sess); } else if (tunable_pasv_enable && !p_sess->epsv_all && (str_equal_text(&p_sess->ftp_cmd_str, "PASV") || str_equal_text(&p_sess->ftp_cmd_str, "P@SW"))) { handle_pasv(p_sess, 0); } else if (tunable_pasv_enable && str_equal_text(&p_sess->ftp_cmd_str, "EPSV")) { handle_pasv(p_sess, 1); } else if (tunable_download_enable && str_equal_text(&p_sess->ftp_cmd_str, "RETR")) { handle_retr(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "NOOP")) { vsf_cmdio_write(p_sess, FTP_NOOPOK, "NOOP ok."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SYST")) { vsf_cmdio_write(p_sess, FTP_SYSTOK, "UNIX Type: L8"); } else if (str_equal_text(&p_sess->ftp_cmd_str, "HELP")) { handle_help(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "LIST")) { handle_list(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "TYPE")) { handle_type(p_sess); } else if (tunable_port_enable && !p_sess->epsv_all && str_equal_text(&p_sess->ftp_cmd_str, "PORT")) { handle_port(p_sess); } else if (tunable_write_enable && (tunable_anon_upload_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "STOR")) { handle_stor(p_sess); } else if (tunable_write_enable && (tunable_anon_mkdir_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD"))) { handle_mkd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD"))) { handle_rmd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "DELE")) { handle_dele(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "REST")) { handle_rest(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNFR")) { handle_rnfr(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNTO")) { handle_rnto(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "NLST")) { handle_nlst(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SIZE")) { handle_size(p_sess); } else if (!p_sess->is_anonymous && str_equal_text(&p_sess->ftp_cmd_str, "SITE")) { handle_site(p_sess); } /* Note - the weird ABOR string is checking for an async ABOR arriving * without a SIGURG condition. */ else if (str_equal_text(&p_sess->ftp_cmd_str, "ABOR") || str_equal_text(&p_sess->ftp_cmd_str, "\377\364\377\362ABOR")) { vsf_cmdio_write(p_sess, FTP_ABOR_NOCONN, "No transfer to ABOR."); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "APPE")) { handle_appe(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "MDTM")) { handle_mdtm(p_sess); } else if (tunable_port_enable && str_equal_text(&p_sess->ftp_cmd_str, "EPRT")) { handle_eprt(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "STRU")) { str_upper(&p_sess->ftp_arg_str); if (str_equal_text(&p_sess->ftp_arg_str, "F")) { vsf_cmdio_write(p_sess, FTP_STRUOK, "Structure set to F."); } else { vsf_cmdio_write(p_sess, FTP_BADSTRU, "Bad STRU command."); } } else if (str_equal_text(&p_sess->ftp_cmd_str, "MODE")) { str_upper(&p_sess->ftp_arg_str); if (str_equal_text(&p_sess->ftp_arg_str, "S")) { vsf_cmdio_write(p_sess, FTP_MODEOK, "Mode set to S."); } else { vsf_cmdio_write(p_sess, FTP_BADMODE, "Bad MODE command."); } } else if (str_equal_text(&p_sess->ftp_cmd_str, "STOU")) { handle_stou(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "ALLO")) { vsf_cmdio_write(p_sess, FTP_ALLOOK, "ALLO command ignored."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "REIN")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "REIN not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "ACCT")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "ACCT not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SMNT")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "SMNT not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT")) { vsf_cmdio_write_hyphen(p_sess, FTP_FEAT, "Features:"); vsf_cmdio_write_raw(p_sess, " MDTM\r\n"); vsf_cmdio_write_raw(p_sess, " REST STREAM\r\n"); vsf_cmdio_write_raw(p_sess, " SIZE\r\n"); vsf_cmdio_write(p_sess, FTP_FEAT, "End"); } else if (str_equal_text(&p_sess->ftp_cmd_str, "OPTS")) { vsf_cmdio_write(p_sess, FTP_BADOPTS, "Option not understood."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "STAT") && str_isempty(&p_sess->ftp_arg_str)) { handle_stat(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "STAT")) { handle_stat_file(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASV") || str_equal_text(&p_sess->ftp_cmd_str, "PORT") || str_equal_text(&p_sess->ftp_cmd_str, "STOR") || str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD") || str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD") || str_equal_text(&p_sess->ftp_cmd_str, "DELE") || str_equal_text(&p_sess->ftp_cmd_str, "RNFR") || str_equal_text(&p_sess->ftp_cmd_str, "RNTO") || str_equal_text(&p_sess->ftp_cmd_str, "SITE") || str_equal_text(&p_sess->ftp_cmd_str, "APPE") || str_equal_text(&p_sess->ftp_cmd_str, "EPSV") || str_equal_text(&p_sess->ftp_cmd_str, "EPRT") || str_equal_text(&p_sess->ftp_cmd_str, "RETR") || str_equal_text(&p_sess->ftp_cmd_str, "LIST") || str_equal_text(&p_sess->ftp_cmd_str, "NLST") || str_equal_text(&p_sess->ftp_cmd_str, "STOU") || str_equal_text(&p_sess->ftp_cmd_str, "ALLO") || str_equal_text(&p_sess->ftp_cmd_str, "REIN") || str_equal_text(&p_sess->ftp_cmd_str, "ACCT") || str_equal_text(&p_sess->ftp_cmd_str, "SMNT") || str_equal_text(&p_sess->ftp_cmd_str, "FEAT") || str_equal_text(&p_sess->ftp_cmd_str, "OPTS") || str_equal_text(&p_sess->ftp_cmd_str, "STAT")) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); } else { vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown command."); } } }
int command_handle(char *buf) { int cmd = command_interpret(buf); /* get the command index */ switch (cmd) { case 0: break; case 6: nand_query(); break; case 7: handle_nerase(); break; case 8: /* nread */ nand_read(NAND_READ); break; case 9: /* nreadraw */ nand_read(NAND_READ_RAW); break; case 10: /* nreadoob */ nand_read(NAND_READ_OOB); break; case 11: nand_prog(); break; case 12: handle_help(); break; case 13: handle_version(); break; case 14: debug_go(); break; case 16: /* exit */ printf(" exiting usbboot software\n"); return -1; /* return -1 to break the main.c while * then run usb_ingenic_cleanup*/ /*case 17: nand_read(NAND_READ_TO_RAM); */ break; case 18: handle_gpio(2); break; case 19: handle_gpio(3); break; case 20: boot(STAGE1_FILE_PATH, STAGE2_FILE_PATH); break; case 26: handle_nmark(); break; case 28: handle_load(); break; case 29: handle_memtest(); break; default: printf(" command not support or input error!\n"); break; } return 1; }
static void do_input(FILE *ifp) { int c; char escape; /* * Processing user input. * Basically we stuff the user input to a temp. file until * an escape char. is detected, after which we switch * to the appropriate routine to handle the escape. */ if (ifp == stdin) { if (Verbose) fprintf(stdout,"\nGo \n* "); else { if (!Silent) fprintf(stdout, "* "); } } while ((c = getc(ifp)) != EOF ) { if ( c == '\\') { /* handle escapes */ escape = getc(ifp); switch( escape ) { case 'e': handle_editor(); break; case 'g': handle_send(); break; case 'i': { bool oldVerbose; if (SingleStepMode) { oldVerbose = Verbose; Verbose = false; } handle_file_insert(ifp); if (SingleStepMode) Verbose = oldVerbose; } break; case 'p': handle_print(); break; case 'q': handle_exit(0); break; case 'r': handle_clear(); break; case 's': handle_shell(); break; case 't': handle_print_time(); break; case 'w': handle_write_to_file(); break; case '?': case 'h': handle_help(); break; case '\\': c = escape; stuff_buffer(c); break; case ';': c = escape; stuff_buffer(c); break; default: fprintf(stderr, "unknown escape given\n"); break; } /* end-of-switch */ if (ifp == stdin && escape != '\\') { if (Verbose) fprintf(stdout,"\nGo \n* "); else { if (!Silent) fprintf(stdout, "* "); } } } else { stuff_buffer(c); if (c == ';' && SemicolonIsGo) { handle_send(); if (Verbose) fprintf(stdout,"\nGo \n* "); else { if (!Silent) fprintf(stdout, "* "); } } } } }