Ejemplo n.º 1
0
int cmd_type(int ac, char **av)
{
  int rc;
  int handle=0;
  block_t buf_blk=0;
  block_t blk;
  int readbyte;
  unsigned long pos;

//display_puts("cdfs_open\n");
  handle = cdfs_open(av[0]);
  if(handle<0) {
    dsp_open_error(handle);
    goto EXITCMD;
  }

//display_puts("block_init\n");
  blk = block_init(BLOCK_SHM_ID);
  if(blk==0) {
    display_puts("error:block_open\n");
    goto EXITCMD;
  }

//display_puts("block_alloc\n");
  buf_blk = block_alloc(blk);
  if(buf_blk==0) {
    display_puts("rc=");
    sint2dec(handle,s);
    display_puts(s);
    goto EXITCMD;
  }

  char *buf=block_addr(blk,buf_blk);

//display_puts("cdfs_read\n");
  pos=0;
  readbyte=cdfs_read(handle,pos,BLOCK_SHM_ID,buf_blk,BLOCK_SIZE);
  if(readbyte<0) {
    display_puts("rc=");
    sint2dec(readbyte,s);
    display_puts(s);
    goto EXITCMD;
  }


//  display_puts("\n");
//syscall_wait(10);
  //dump(buf);

  int i;
  for(i=0;i<readbyte;i++) {
    display_putc(*buf);
//syscall_wait(10);
    buf++;
  }

//display_puts("\n");
//display_puts("-------\n");
//display_puts("len=");
//sint2dec(readbyte,s);
//display_puts(s);
//display_puts("\n");
//syscall_wait(50);


EXITCMD:

  if(handle>0) {
//display_puts("cdfs_close\n");
    rc = cdfs_close(handle);
    if(rc<0) {
      display_puts("rc=");
      sint2dec(rc,s);
      display_puts(s);
    }
  }

  if(buf_blk) {
    block_free(blk,buf_blk);
  }

  return 0;
}
Ejemplo n.º 2
0
Archivo: httpd.c Proyecto: aol/thrasher
void
httpd_action(struct evhttp_request *req, void *arg)
{
    struct evbuffer *buf;
    const char      *authorization;
    char            *v;

    if (!http_password) {
        LOG(logfile, "http-password not set in config file%s", "");
        return;
    }

    buf = evbuffer_new();

    authorization = evhttp_find_header(req->input_headers, "authorization");
    if (!authorization || g_ascii_strncasecmp(authorization, "Basic ", 6) != 0) {
        evhttp_add_header(req->output_headers, "WWW-Authenticate", "Basic realm=\"Thrashd\"");
        evhttp_send_reply(req, 401, "Authorization Required", buf);
        evbuffer_free(buf);
        return;
    }

    gsize   decoded_len;
    guchar *decoded = g_base64_decode(authorization+6, &decoded_len);
    char *colon = strchr((char*)decoded, ':');
    if (!colon || decoded[0] == ':' || strcmp(colon+1, http_password) != 0) {
        g_free(decoded);
        evhttp_add_header(req->output_headers, "WWW-Authenticate", "Basic realm=\"Thrashd\"");
        evhttp_send_reply(req, 401, "Authorization Required", buf);
        evbuffer_free(buf);
        return;
    }

    struct evkeyvalq    args;
    evhttp_parse_query(req->uri, &args);

    char *action = (char *)evhttp_find_header(&args, "action");
    char *key = (char *)evhttp_find_header(&args, "key");
    char *redir = "config.html";

    if (!action || !key) {
        evhttp_clear_headers(&args);
        g_free(decoded);
        return;
    }

    LOG(logfile, "webaction user:%.*s action:%s key:%s", 
        (int)((char *)colon-(char *)decoded), decoded, action, key);

    if (strcmp(action, "removeHolddown") == 0) {
        redir = "holddowns.html";
        uint128_t       s6addr;
        blocked_node_t *bnode;

        inet_pton(AF_INET6, key, s6addr);

        if ((bnode = g_tree_lookup(current_blocks, &s6addr)))
            expire_bnode(0, 0, bnode);
    } else if (strcmp(action, "removeAddr") == 0) {
        redir = "addrs.html";
        qstats_t *stats = g_hash_table_lookup(addr_table, key);
        if (stats)
            expire_stats_node(0, 0, stats);
    } else if (strcmp(action, "blockAddr") == 0) {
        redir = "addrs.html";
        qstats_t *stats = g_hash_table_lookup(addr_table, key);
        if (stats)
            block_addr(0, stats->s6addr, "web:blockAddr");
    } else if (strcmp(action, "removeUri") == 0) {
        redir = "uris.html";
        qstats_t *stats = g_hash_table_lookup(uri_table, key);
        if (stats)
            expire_stats_node(0, 0, stats);
    } else if (strcmp(action, "blockUri") == 0) {
        redir = "uris.html";
        qstats_t *stats = g_hash_table_lookup(uri_table, key);
        if (stats)
            block_addr(0, stats->s6addr, "web:blockUri");
    } else if (strcmp(action, "removeHost") == 0) {
        redir = "hosts.html";
        qstats_t *stats = g_hash_table_lookup(host_table, key);
        if (stats)
            expire_stats_node(0, 0, stats);
    } else if (strcmp(action, "blockHost") == 0) {
        redir = "hosts.html";
        qstats_t *stats = g_hash_table_lookup(host_table, key);
        if (stats)
            block_addr(0, stats->s6addr, "web:blockHost");
    } else if (strcmp(action, "updateurl") == 0) {
        redir = "config.html";
        block_ratio_t *request_uri_ratio = g_hash_table_lookup(uris_ratio_table, key);
        if (!request_uri_ratio) {
            request_uri_ratio = malloc(sizeof(block_ratio_t));
            g_hash_table_insert(uris_ratio_table, g_strdup(key), request_uri_ratio);
            request_uri_ratio->num_connections = uri_ratio.num_connections;
            request_uri_ratio->timelimit = uri_ratio.timelimit;
        }

        if ((v = (char *)evhttp_find_header(&args, "hit")))
            request_uri_ratio->num_connections = atoi(v);

        if ((v = (char *)evhttp_find_header(&args, "sec")))
            request_uri_ratio->timelimit = atoi(v);

    } else if (strcmp(action, "reloadconfig") == 0) {
        redir = "config.html";
        load_config(TRUE);
    }

    evhttp_add_header(req->output_headers, "Location", redir);
    evhttp_send_reply(req, 302, "Redirection", buf);
    evhttp_clear_headers(&args);
    g_free(decoded);
}
Ejemplo n.º 3
0
int cmd_exec(int ac, char **av)
{
  int handle=0;
  int pgmid=0;
  block_t buf_blk=0;
  int rc;
  block_t blk;
  int readbyte;
  unsigned long pos;

//display_puts("cdfs_open\n");
  handle = cdfs_open(av[0]);
  if(handle<0) {
    dsp_open_error(handle);
    goto EXITCMD;
  }

//display_puts("cdfs_stat\n");
  char infobuf[sizeof(struct file_info)+CDFS_FULLPATH_MAXLENGTH];
  struct file_info *info=(void*)infobuf;
  rc = cdfs_stat(handle,info,sizeof(infobuf));
  if(rc<0) {
    display_puts("rc=");
    sint2dec(rc,s);
    display_puts(s);
    goto EXITCMD;
  }

//display_puts("block_init\n");
  blk = block_init(BLOCK_SHM_ID);
  if(blk==0) {
    display_puts("error:block_init\n");
    goto EXITCMD;
  }

//display_puts("block_alloc\n");
  buf_blk = block_alloc(blk);
  if(buf_blk==0) {
    display_puts("error:block_alloc\n");
    goto EXITCMD;
  }

  char *buf=block_addr(blk,buf_blk);

  char *pgname = get_filename(av[0]);
//display_puts("pgm_alloc\n");
  pgmid = environment_allocimage(pgname,info->size);
  if(pgmid<0) {
    display_puts("rc=");
    sint2dec(pgmid,s);
    display_puts(s);
    goto EXITCMD;
  }
//display_puts("size=");
//sint2dec(info->size,s);
//display_puts(s);
//display_puts("\n");

//display_puts("cdfs_read\n");
  pos=0;

  for(;;) {
    readbyte=cdfs_read(handle,pos,BLOCK_SHM_ID,buf_blk,BLOCK_SIZE);
    if(readbyte<0) {
      break;
    }

//display_puts(" readbyte=");
//sint2dec(readbyte,s);
//display_puts(s);

    rc=environment_loadimage(pgmid,buf,readbyte);
    if(rc<0) {
      display_puts(" loadimage rc=");
      sint2dec(rc,s);
      display_puts(s);
      goto EXITCMD;
    }

    pos += readbyte;
  }

  rc = program_exec(pgmid,ac, av);
  if(rc<0) {
    goto EXITCMD;
  }

  int exitcode;
  program_wait(&exitcode, MESSAGE_MODE_WAIT);


EXITCMD:

  if(handle>0) {
//display_puts("cdfs_close\n");
    rc = cdfs_close(handle);
    if(rc<0) {
      display_puts("rc=");
      sint2dec(rc,s);
      display_puts(s);
    }
  }

  if(buf_blk) {
    block_free(blk,buf_blk);
  }

//display_puts("\n");
//syscall_wait(10);
  //dump(buf);


  return 0;
}