Пример #1
0
int main( int argc, char *argv[] ){
	char *progname = argv[0];
	char conffile[255];

	if( argc > 1 ){

		if(strcmp(argv[1], "-h") == 0){
			print_help(progname);
			exit(0);
		}
		else if(get_conf_name( argv, conffile ) == 0){
			print_help(progname);
			exit(1);
		}
	}
	else{
		print_help(progname);
		exit(1);
	}

	csector = 0;
	cdir = in;
	confname = argv[argc - 1];

	conf_t conf;
	confresult_t confresult = get_conf(conffile, confname, &conf);
	// verificação de erros de get_conf
	if(confresult != ok){
		if(confresult == filenotfound)
			fprintf(stderr, "ficheiro não encontrado\n");
		else if(confresult == confnotfound)
			fprintf(stderr, "configuração não encontrada\n");
		else if(confresult == disknotfound)
			fprintf(stderr, "disco não encontrado\n");
		else
			fprintf(stderr, "erro no ficheiro\n");

		exit(1);
	}

	// tamanho do disco
	struct stat st;
	if(stat(conf.imagefile, &st) == -1){
		perror("tamanho do disco");
		exit(1);
	}
	disksize = st.st_size;

	// verificar tamanho do ficheiro de imagem com número de
	// setores dos discos. Só é necessário verificar com um
	// disco porque a função get_conf verifica o tamanho dos discos.
	if(disksize != conf.disk[0].sectors){
		fprintf(stderr, "Não conseguio carregar o disco\n");
		exit(1);
	}

	// carregar para memória o ficheiro contendo imagem do disco
	int fd = open(conf.imagefile, O_RDONLY);
	if(fd == -1){
		perror(conf.imagefile);
		exit(1);
	}
	secdata_t disk[disksize];
	if(read (fd, disk, disksize) == -1){
		perror("ler ficheiro img");
		exit(1);
	}
	
	reqpool_t reqpool;
	ipc_t ipc;
	ipc.reqpool = &reqpool;

	// inicializar e associar o processo aos mecanismos de comunicação
	if(init_ipc(progname, confname, &ipc) == -1)
		exit(1);

	// criar o processo filho
	int indice = setup_disks(ipc.reqpool->disks);
	strcpy(diskname, conf.disk[indice].name);

	vsslog(confname,diskname, DS, cdir, disksize, ipc.reqpool->policy);
	vsslog(confname,diskname, ER, csector, cdir);
		
	// arma o sinal SIGUSR1
	signal(SIGUSR1, estaciona_disco);

	// atender pedidos
	request_t req;
	while(1){

		if(ipc.reqpool->policy == FCFS){
			if(take_request(&ipc, &req, select_request_FCFS) != 1){
				perror("carregar pedido");
				exit(1);
			}
		}else{
			if(take_request(&ipc, &req, select_request_LOOK) != 1){
				perror("carregar pedido");
				exit(1);
			}
		}
		vsslog(confname,diskname, OR, req.sector);

		secdata_t sect;
		if(move_and_read(&req, &sect,disk) == 0){
			perror("ler pedido");
			exit(1);
		}
		put_sector(csector, &sect);

		vsslog(confname,diskname, RS, csector, cdir);
		vsslog(confname,diskname, ER, csector, cdir);
	}

}
Пример #2
0
/* write_conf_line()
 *
 * inputs       - pointer to struct AccessItem
 *		- string current_date (small date)
 *              - time_t cur_time
 * output       - NONE
 * side effects - This function takes care of
 *                finding right conf file, writing
 *                the right lines to this file, 
 *                notifying the oper that their kline/dline etc. is in place
 *                notifying the opers on the server about the k/d etc. line
 *                
 * - Dianora
 */
void 
write_conf_line(struct Client *source_p, struct ConfItem *conf,
		const char *current_date, time_t cur_time, time_t duration)
{
  FBFILE *out;
  const char *filename, *from, *to;
  struct AccessItem *aconf;
  struct MatchItem *xconf;
  struct ResvChannel *cresv_p=NULL;
  struct MatchItem *nresv_p=NULL;
  ConfType type;

  type = conf->type;
  filename = get_conf_name(type);

  if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
  {
    from = me.id;
    to = source_p->id;
  }
  else
  {
    from = me.name;
    to = source_p->name;
  }

  if ((out = fbopen(filename, "a")) == NULL)
  {
    sendto_realops_flags(UMODE_ALL, L_ALL,
                         "*** Problem opening %s ", filename);
    return;
  }

  switch(type)
  {
  case KLINE_TYPE:
    aconf = (struct AccessItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added K-Line for [%s@%s] [%s]",
          get_oper_name(source_p), aconf->user, aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
          from, to, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added K-Line for [%s@%s] [%s]",
          source_p->name, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d",
          aconf->user, aconf->host, aconf->reason, aconf->oper_reason, 
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. K-Line for [%s@%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->user, aconf->host, 
          aconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", from, to, 
          duration/60, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added temporary %ld min. K-Line for [%s@%s] [%s]",
          source_p->name, duration/60, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d%d", aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case RKLINE_TYPE:
    aconf = map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added RK-Line for [%s@%s] [%s]",
          get_oper_name(source_p),
          aconf->user, aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added RK-Line [%s@%s]",
          from, to, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added K-Line for [%s@%s] [%s]",
          source_p->name, aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_RKLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d",
          aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->user, aconf->host,
          aconf->reason);
      sendto_one(source_p, 
          ":%s NOTICE %s :Added temporary %d min. RK-Line [%s@%s]", from, to, 
          duration/60, aconf->user, aconf->host);
      ilog(L_TRACE, "%s added temporary %ld min. RK-Line for [%s@%s] [%s]",
          source_p->name, duration/60,
          aconf->user, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_RKLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%s%d%d",
          aconf->user, aconf->host,
          aconf->reason, aconf->oper_reason, current_date,
          get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case DLINE_TYPE:
    aconf = (struct AccessItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added D-Line for [%s] [%s]",
          get_oper_name(source_p), aconf->host, aconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s] to %s",
          from, to, aconf->host, filename);
      ilog(L_TRACE, "%s added D-Line for [%s] [%s]",
          get_oper_name(source_p), aconf->host, aconf->reason);
      log_oper_action(LOG_DLINE_TYPE, source_p, "[%s] [%s]\n",
          aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          aconf->host, aconf->reason, aconf->oper_reason, 
          current_date,
          get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. D-Line for [%s] [%s]",
          get_oper_name(source_p), duration/60, aconf->host, aconf->reason);

      sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
          from, to, duration/60, aconf->host);
      ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]",
          source_p->name, (int)duration/60, aconf->host, aconf->reason);
      log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n",
          aconf->user, aconf->host, aconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          aconf->host, aconf->reason, aconf->oper_reason, 
          current_date, get_oper_name(source_p), cur_time, aconf->hold);
    }
    break;

  case XLINE_TYPE:
    xconf = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name,
          xconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added X-Line [%s] [%d] [%s] to %s",
          from, to, conf->name, 
          xconf->action, xconf->reason, filename);
      ilog(L_TRACE, "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. X-Line for [%s] [%s]",
          get_oper_name(source_p), (int)duration/60,
          conf->name, xconf->reason);
      sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
          MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
          source_p->name, (int)duration/60, conf->name);
      ilog(L_TRACE, "%s added temporary %d min. X-Line for [%s] [%s]",
          source_p->name, (int)duration/60,
          conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time, xconf->hold);
 
    }
    break;

  case RXLINE_TYPE:
    xconf = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added RX-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name,
          xconf->reason);
      sendto_one(source_p,
          ":%s NOTICE %s :Added RX-Line [%s] [%s] to %s",
          from, to, conf->name,
          xconf->reason, filename);
      ilog(L_TRACE, "%s added X-Line for [%s] [%s]",
          get_oper_name(source_p), conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time);
    }
    else
    {
      sendto_realops_flags(UMODE_ALL, L_ALL,
          "%s added temporary %d min. RX-Line for [%s] [%s]",
          get_oper_name(source_p), (int)duration/60, conf->name, xconf->reason);
      sendto_one(source_p, 
          ":%s NOTICE %s :Added temporary %d min. RX-Line [%s]",
          from, to, (int)duration/60, conf->name);
      ilog(L_TRACE, "%s added temporary %d min. RX-Line for [%s] [%s]",
          source_p->name, (int)duration/60,
          conf->name, xconf->reason);
      write_csv_line(out, "%s%s%s%s%s%d%d",
          conf->name, xconf->reason, xconf->oper_reason,
          current_date, get_oper_name(source_p), cur_time, xconf->hold);
    }
    break;

  case CRESV_TYPE:
    cresv_p = (struct ResvChannel *)map_to_conf(conf);
    if(duration == 0)
      write_csv_line(out, "%s%s", cresv_p->name, cresv_p->reason);
    else
      write_csv_line(out, "%s%s%d", cresv_p->name, cresv_p->reason, cresv_p->hold);
    break;

  case NRESV_TYPE:
    nresv_p = (struct MatchItem *)map_to_conf(conf);
    if(duration == 0)
      write_csv_line(out, "%s%s", conf->name, nresv_p->reason);
    else
      write_csv_line(out, "%s%s%d", conf->name, nresv_p->reason, nresv_p->hold);
    break;

  default:
    fbclose(out);
    return;
  }

  fbclose(out);
}