Esempio n. 1
0
int ALU(int command, int operand)
{
    trace;
    if (command == 10) {
        return command_read(operand);
    } else if (command == 11) {
        return command_write(operand);
    } else if (command == 20) {
        return command_load(operand);
    } else if (command == 21) {
        return command_store(operand);
    } else if (command == 30) {
        return command_add(operand);
    } else if (command == 31) {
        return command_sub(operand);
    } else if (command == 32) {
        return command_divide(operand);
    } else if (command == 33) {
        return command_mul(operand);
    } else if (command == 40) {
        return command_jump(operand);
    } else if (command == 41) {
        return command_jneg(operand);
    } else if (command == 42) {
        return command_jz(operand);
    } else if (command == 43) {
        return command_halt();
    } else if (command == 51) {
        return command_not(operand);
    } else if (command == 52) {
        return command_and(operand);
    } else if (command == 53) {
        return command_or(operand);
    } else if (command == 54) {
        return command_xor(operand);
    } else if (command == 55) {
        return command_jns(operand);
    } else if (command == 56) {
        return command_jc(operand);
    } else if (command == 57) {
        return command_jnc(operand);
    } else if (command == 58) {
        return command_jp(operand);
    } else if (command == 59) {
        return command_jnp(operand);
    } else if (command == 60) {
        return command_chl(operand);
    } else if (command == 61) {
        return command_shr(operand);
    } else if (command == 62) {
        return command_rcl(operand);
    } else if (command == 63) {
        return command_rcr(operand);
    } else if (command == 64) {
        return command_neg(operand);
    } else if (command == 65 || command == 75) {
        return command_addc(operand);
    } else if (command == 66 || command == 76) {
        return command_subc(operand);
    } else if (command == 67) {
        return command_loglc(operand);
    } else if (command == 68) {
        return command_logrc(operand);
    } else if (command == 69) {
        return command_rccl(operand);
    } else if (command == 70) {
        return command_rccr(operand);
    } else if (command == 71) {
        return command_mova(operand);
    } else if (command == 72) {
        return command_movr(operand);
    } else if (command == 73) {
        return command_movca(operand);
    } else if (command == 74) {
        return command_movcr(operand);
    }

    sc_regSet(COMMAND_ERROR, 1);
    return -1;
}
Esempio n. 2
0
/*PAGE
 *
 * exec_command
 *
 * Parse and execute FTP command.
 *
 * FIXME: This section is somewhat of a hack.  We should have a better
 *        way to parse commands.
 *
 * Input parameters:
 *   info - corresponding SessionInfo structure
 *   cmd  - command to be executed (upper-case)
 *   args - arguments of the command
 *
 * Output parameters:
 *    NONE
 */
static void
exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
{
  char fname[FTPD_BUFSIZE];
  int wrong_command = 0;

  fname[0] = '\0';

  if (!strcmp("PORT", cmd))
  {
    command_port(info, args);
  }
  else if (!strcmp("PASV", cmd))
  {
    command_pasv(info);
  }
  else if (!strcmp("RETR", cmd))
  {
    strncpy(fname, args, 254);
    command_retrieve(info, fname);
  }
  else if (!strcmp("STOR", cmd))
  {
    strncpy(fname, args, 254);
    command_store(info, fname);
  }
  else if (!strcmp("LIST", cmd))
  {
    strncpy(fname, args, 254);
    command_list(info, fname, 1);
  }
  else if (!strcmp("NLST", cmd))
  {
    strncpy(fname, args, 254);
    command_list(info, fname, 0);
  }
  else if (!strcmp("MDTM", cmd))
  {
    strncpy(fname, args, 254);
    command_mdtm(info, fname);
  }
  else if (!strcmp("SYST", cmd))
  {
    send_reply(info, 215, FTPD_SYSTYPE);
  }
  else if (!strcmp("TYPE", cmd))
  {
    if (args[0] == 'I')
    {
      info->xfer_mode = TYPE_I;
      send_reply(info, 200, "Type set to I.");
    }
    else if (args[0] == 'A')
    {
      info->xfer_mode = TYPE_A;
      send_reply(info, 200, "Type set to A.");
    }
    else
    {
      info->xfer_mode = TYPE_I;
      send_reply(info, 504, "Type not implemented.  Set to I.");
    }
  }
  else if (!strcmp("USER", cmd) || !strcmp("PASS", cmd))
  {
    send_reply(info, 230, "User logged in.");
  }
  else if (!strcmp("DELE", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      unlink(fname) == 0)
    {
      send_reply(info, 257, "DELE successful.");
    }
    else
    {
      send_reply(info, 550, "DELE failed.");
    }
  }
  else if (!strcmp("SITE", cmd))
  {
    char* opts;
    split_command(args, &cmd, &opts, &args);
    if(!strcmp("CHMOD", cmd))
    {
      int mask;

      if(!can_write())
      {
        send_reply(info, 550, "Access denied.");
      }
      else {
        char *c;
        c = strchr(args, ' ');
        if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254) 
          && (chmod(fname, (mode_t)mask) == 0))
          send_reply(info, 257, "CHMOD successful.");
        else
          send_reply(info, 550, "CHMOD failed.");
      }
    }
    else
      wrong_command = 1;
  }
  else if (!strcmp("RMD", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      rmdir(fname) == 0)
    {
      send_reply(info, 257, "RMD successful.");
    }
    else
    {
      send_reply(info, 550, "RMD failed.");
    }
  }
  else if (!strcmp("MKD", cmd))
  {
    if(!can_write())
    {
      send_reply(info, 550, "Access denied.");
    }
    else if (
      strncpy(fname, args, 254) &&
      mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
    {
      send_reply(info, 257, "MKD successful.");
    }
    else
    {
      send_reply(info, 550, "MKD failed.");
    }
  }
  else if (!strcmp("CWD", cmd))
  {
    strncpy(fname, args, 254);
    command_cwd(info, fname);
  }
  else if (!strcmp("CDUP", cmd))
  {
    command_cwd(info, "..");
  }
  else if (!strcmp("PWD", cmd))
  {
    command_pwd(info);
  }
  else
    wrong_command = 1;

  if(wrong_command)
    send_reply(info, 500, "Command not understood.");
}