Esempio n. 1
0
int user_action(char board1[BOARD_SIZE][BOARD_SIZE], char board2[BOARD_SIZE][BOARD_SIZE], char user) {
	switch (user) {
		case 'a': 
			add_cell(board2) ;
			break ;

		case 'r':
			remove_cell(board2) ;
			break ;

		case 'n':
			apply_rules(board1, board2) ;
			break ;

		case 'q':
			return 0 ;

		case 'p':		
			while (1) {
				apply_rules(board1, board2) ;	
				copy_board(board1, board2) ;
				printf("\033[2J\033[H") ;
				usleep(500000) ;
				print_board(board1) ;			
			}
	}
	return 1 ;
}
Esempio n. 2
0
static bool
apply_relevant_rules(Postprocessor *pp,
                     bool (applyfn)(PP_data *, Linkage, pp_rule *),
                     Linkage sublinkage,
                     pp_rule *rule_array,
                     int *relevant_rules,
                     const char **msg)
{
	int i, idx;
	PP_data *pp_data = &pp->pp_data;

	/* If we didn't accumulate link names for this sentence, we need
	 *  to apply all rules. */
	if (pp_linkset_population(pp->set_of_links_of_sentence) == 0) {
		return apply_rules(pp_data, applyfn, sublinkage, rule_array, msg);
	}

	/* We did, and we don't. */
	for (i = 0; (idx = relevant_rules[i]) != -1; i++)
	{
		*msg = rule_array[idx].msg;
		if (!applyfn(pp_data, sublinkage, &(rule_array[idx]))) return false;
	}
	return true;
}
Esempio n. 3
0
void schedule_window(xcb_window_t win)
{
	coordinates_t loc;
	uint8_t override_redirect = 0;
	xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL);

	if (wa != NULL) {
		override_redirect = wa->override_redirect;
		free(wa);
	}

	if (override_redirect || locate_window(win, &loc)) {
		return;
	}

	/* ignore pending windows */
	for (pending_rule_t *pr = pending_rule_head; pr != NULL; pr = pr->next) {
		if (pr->win == win) {
			return;
		}
	}

	rule_consequence_t *csq = make_rule_conquence();
	apply_rules(win, csq);
	if (!schedule_rules(win, csq)) {
		manage_window(win, csq, -1);
		free(csq);
	}
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	int clear = 0;
	int c;

	if (!smack_smackfs_path()) {
		fprintf(stderr, "SmackFS is not mounted.\n");
		exit(1);
	}

	while ((c = getopt(argc, argv, "c")) != -1) {
		switch (c) {
		case 'c':
			clear = 1;
			break;
		default:
			usage(argv[0]);
		}
	}

	if (optind == argc) {
		if (apply_rules_file(STDIN_FILENO, clear))
			exit(1);
	} else {
		if (apply_rules(argv[optind], clear))
			exit(1);
	}

	exit(0);
}
Esempio n. 5
0
int
build_job (void)
{
	struct ndm_job_param *	job = &the_job;
	int			i, rc, n_err;
	char			errbuf[100];

	NDMOS_MACRO_ZEROFILL(job);

	args_to_job ();

	ndma_job_auto_adjust (job);

	if (o_rules)
		apply_rules (job, o_rules);

	i = n_err = 0;
	do {
		rc = ndma_job_audit (job, errbuf, i);
		if (rc > n_err || rc < 0) {
			ndmjob_log (0, "error: %s", errbuf);
		}
		n_err = rc;
	} while (i++ < n_err);

	if (n_err) {
		error_byebye ("can't proceed");
		/* no return */
	}

	return 0;
}
Esempio n. 6
0
static void modify_access_rules(char *file, enum mask_action action)
{
	char path[PATH_MAX];
	int ret;

	sprintf(path,"%s/%s", ACCESSES_D_PATH, file);

	if (action == CREATE)
		ret = apply_rules(path, 0);
	else if (action == MODIFY) {
		ret = apply_rules(path, 1);
		ret = apply_rules(path, 0);
	}

	if (ret)
		syslog(LOG_ERR, "Failed load access rules (%s), action (%d) :%m",
		       path, action);
}
Esempio n. 7
0
static int
internal_process(Postprocessor *pp, Linkage sublinkage, const char **msg)
{
	size_t i;
	PP_data *pp_data = &pp->pp_data;

	/* quick test: try applying just the relevant global rules */
	if (!apply_relevant_rules(pp, apply_contains_one_globally,
	                          sublinkage,
	                          pp->knowledge->contains_one_rules,
	                          pp->relevant_contains_one_rules, msg))
	{
		for (i = 0; i < pp_data->wowlen; i++)
			pp_data->word_links[i] = NULL;
		pp_data->N_domains = 0;
		return -1;
	}

	/* build graph; confirm that it's legally connected */
	build_graph(pp, sublinkage);
	build_domains(pp, sublinkage);
	build_domain_forest(&pp->pp_data, sublinkage);

#if defined(CHECK_DOMAIN_NESTING)
	/* These messages were deemed to not be useful, so
	 * this code is commented out. See comment above. */
	if (!check_domain_nesting(pp, sublinkage->num_links))
		printf("WARNING: The domains are not nested.\n");
#endif

	/* The order below should be optimal for most cases */
	if (!apply_relevant_rules(pp, apply_contains_one, sublinkage,
	                          pp->knowledge->contains_one_rules,
	                          pp->relevant_contains_one_rules, msg)) return 1;
	if (!apply_relevant_rules(pp, apply_contains_none, sublinkage,
	                          pp->knowledge->contains_none_rules,
	                          pp->relevant_contains_none_rules, msg)) return 1;
	if (!apply_rules(pp_data, apply_must_form_a_cycle, sublinkage,
	                 pp->knowledge->form_a_cycle_rules,msg)) return 1;
	if (!apply_rules(pp_data, apply_bounded, sublinkage,
	                 pp->knowledge->bounded_rules, msg)) return 1;
	return 0; /* This linkage satisfied all the rules */
}
static int interval_limit_access_checker(request_rec *r)
{
    interval_limit_config *conf = ap_get_module_config(r->per_dir_config, &interval_limit_module);
    int i, block_access;
    char *threshold_exceeded_rules=NULL;
    threshold_exceeded_entry *threshold_exceeded, *ol;

    if (!conf || !conf->enabled) {
        return DECLINED;
    }
    if (!conf->rules || conf->rules->nelts < 1) {
        return DECLINED;
    }
    block_access =0;
    apr_array_header_t *threshold_exceededs =apr_array_make(r->pool, 2, sizeof(threshold_exceeded_entry));
    if(  apply_rules(r, conf->rules, threshold_exceededs) !=0 ) {
        ILLOG_ERROR(r, MODTAG "apply_rules failure!");
        return DECLINED;
    }
    if (threshold_exceededs->nelts > 0) {
        ol = (threshold_exceeded_entry *)threshold_exceededs->elts;
        for ( i =0; i <threshold_exceededs->nelts; i++) {
            threshold_exceeded =  &ol[i];
            ILLOG_DEBUG(r, MODTAG "dump threshold_exceeded: name=%s block=%d",
                                        threshold_exceeded->name, threshold_exceeded->block);

            if (threshold_exceeded_rules == NULL) {
                threshold_exceeded_rules = (char*)apr_pstrdup(r->pool, threshold_exceeded->name);
            } else {
                threshold_exceeded_rules = (char*)apr_psprintf(r->pool, "%s,%s", threshold_exceeded_rules, threshold_exceeded->name);
            }
            if (threshold_exceeded->block){
                block_access = 1;
            }
        }
        if (threshold_exceeded_rules) {
            apr_table_setn(r->subprocess_env, "threshold_exceeded_rules", threshold_exceeded_rules);
            apr_table_set(r->headers_in, "threshold_exceeded_rules", threshold_exceeded_rules);
        }
    }
    if (block_access) {
        return (HTTP_SERVICE_UNAVAILABLE);
    }

    return OK;
}
Esempio n. 9
0
static int apply_all(void)
{
	if (!smack_smackfs_path()) {
		fprintf(stderr, "SmackFS is not mounted.\n");
		return -1;
	}

	if (clear())
		return -1;

	if (apply_rules(ACCESSES_D_PATH, 0))
		return -1;

	if (apply_cipso(CIPSO_D_PATH))
		return -1;

	return 0;
}
Esempio n. 10
0
static int apply_all(void)
{
	if (is_smackfs_mounted() != 1) {
		fprintf(stderr, "ERROR: SmackFS is not mounted.\n");
		return -1;
	}

	if (clear())
		return -1;

	if (apply_rules(ACCESSES_D_PATH, 0))
		perror("apply_rules");

	if (apply_cipso(CIPSO_D_PATH))
		perror("apply_cipso");

	return 0;
}
Esempio n. 11
0
std::string apply_rules(const std::vector<rule_t> & rules, const string_view_t &numview) {

    std::string result = "";

    for (std::string old_number; numview.str != old_number && numview.size(); ) {
        old_number = numview.str;
        for (const auto &rule : rules) {
            if (const string_view_t matched_view = rule.match(numview)) {
                matched_view.fill('?');
                result = concat(rule.replacement, result);
                if (const auto n_hashes = rule.n_hashes()) {
                    const size_t pos_begin = (matched_view.pos_begin > n_hashes)? matched_view.pos_begin - n_hashes : 0;
                    result = concat(apply_rules(rules, string_view_t{numview.str, pos_begin, matched_view.pos_begin}), result);
                }
                break;
            }
        }
    }
    return result;
}
Esempio n. 12
0
static int 
apply_relevant_rules(Postprocessor *pp,
		     int(applyfn)(Postprocessor *pp,Sublinkage*,pp_rule *rule),
		     Sublinkage *sublinkage,
		     pp_rule *rule_array,   
		     int *relevant_rules,
		     char **msg) 
{
  int i, idx;

  /* if we didn't accumulate link names for this sentence, we need to apply
     all rules */
  if (pp_linkset_population(pp->set_of_links_of_sentence)==0) {
      return apply_rules(pp, applyfn, sublinkage, rule_array, msg);
  }
  
  /* we did, and we don't */
  for (i=0; (idx=relevant_rules[i])!=-1; i++) {
      *msg = rule_array[idx].msg;   /* Adam had forgotten this -- DS 4/9/98 */
      if (!applyfn(pp, sublinkage, &(rule_array[idx]))) return 0;
  }      
  return 1;
}
Esempio n. 13
0
int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len)
{
  const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
  const hashconfig_t     *hashconfig     = hashcat_ctx->hashconfig;
  const hashes_t         *hashes         = hashcat_ctx->hashes;
  const mask_ctx_t       *mask_ctx       = hashcat_ctx->mask_ctx;
  const straight_ctx_t   *straight_ctx   = hashcat_ctx->straight_ctx;
  const user_options_t   *user_options   = hashcat_ctx->user_options;

  const u32 gidvid = plain->gidvid;
  const u32 il_pos = plain->il_pos;

  int plain_len = 0;

  u8 *plain_ptr = (u8 *) plain_buf;

  if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
  {
    pw_t pw;

    const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

    if (rc == -1) return -1;

    for (int i = 0; i < 16; i++)
    {
      plain_buf[i] = pw.i[i];
    }

    plain_len = (int) pw.pw_len;

    const u32 off = device_param->innerloop_pos + il_pos;

    plain_len = (int) apply_rules (straight_ctx->kernel_rules_buf[off].cmds, &plain_buf[0], &plain_buf[4], (u32) plain_len);

    if (plain_len > (int) hashconfig->pw_max) plain_len = (int) hashconfig->pw_max;
  }
  else if (user_options->attack_mode == ATTACK_MODE_COMBI)
  {
    pw_t pw;

    const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

    if (rc == -1) return -1;

    for (int i = 0; i < 16; i++)
    {
      plain_buf[i] = pw.i[i];
    }

    plain_len = (int) pw.pw_len;

    char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
    u32   comb_len =          device_param->combs_buf[il_pos].pw_len;

    if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
    {
      memcpy (plain_ptr + plain_len, comb_buf, (size_t) comb_len);
    }
    else
    {
      memmove (plain_ptr + comb_len, plain_ptr, (size_t) plain_len);

      memcpy (plain_ptr, comb_buf, comb_len);
    }

    plain_len += comb_len;

    if (plain_len > (int) hashconfig->pw_max) plain_len = (int) hashconfig->pw_max;
  }
  else if (user_options->attack_mode == ATTACK_MODE_BF)
  {
    u64 l_off = device_param->kernel_params_mp_l_buf64[3] + gidvid;
    u64 r_off = device_param->kernel_params_mp_r_buf64[3] + il_pos;

    u32 l_start = device_param->kernel_params_mp_l_buf32[5];
    u32 r_start = device_param->kernel_params_mp_r_buf32[5];

    u32 l_stop = device_param->kernel_params_mp_l_buf32[4];
    u32 r_stop = device_param->kernel_params_mp_r_buf32[4];

    sp_exec (l_off, (char *) plain_ptr + l_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, l_start, l_start + l_stop);
    sp_exec (r_off, (char *) plain_ptr + r_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, r_start, r_start + r_stop);

    plain_len = (int) mask_ctx->css_cnt;
  }
  else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
  {
    pw_t pw;

    const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

    if (rc == -1) return -1;

    for (int i = 0; i < 16; i++)
    {
      plain_buf[i] = pw.i[i];
    }

    plain_len = (int) pw.pw_len;

    u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;

    u32 start = 0;
    u32 stop  = device_param->kernel_params_mp_buf32[4];

    sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);

    plain_len += start + stop;

    if (plain_len > (int) hashconfig->pw_max) plain_len = (int) hashconfig->pw_max;
  }
  else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
  {
    pw_t pw;

    const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

    if (rc == -1) return -1;

    for (int i = 0; i < 16; i++)
    {
      plain_buf[i] = pw.i[i];
    }

    plain_len = (int) pw.pw_len;

    u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;

    u32 start = 0;
    u32 stop  = device_param->kernel_params_mp_buf32[4];

    memmove (plain_ptr + stop, plain_ptr, plain_len);

    sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);

    plain_len += start + stop;

    if (plain_len > (int) hashconfig->pw_max) plain_len = (int) hashconfig->pw_max;
  }

  if (user_options->attack_mode == ATTACK_MODE_BF)
  {
    if (hashconfig->opti_type & OPTI_TYPE_BRUTE_FORCE) // lots of optimizations can happen here
    {
      if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
      {
        if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT)
        {
          plain_len = plain_len - hashes->salts_buf[0].salt_len;
        }
      }

      if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE)
      {
        for (int i = 0, j = 0; i < plain_len; i += 2, j += 1)
        {
          plain_ptr[j] = plain_ptr[i];
        }

        plain_len = plain_len / 2;
      }
    }
  }

  plain_ptr[plain_len] = 0;

  *out_len = plain_len;

  return 0;
}
Esempio n. 14
0
static void load_all_rules()
{
	if (apply_rules(ACCESSES_D_PATH, 0))
		syslog(LOG_DEBUG, "Failed to load all rules");
}
Esempio n. 15
0
int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_cnt)
{
  combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
  hashconfig_t     *hashconfig     = hashcat_ctx->hashconfig;
  mask_ctx_t       *mask_ctx       = hashcat_ctx->mask_ctx;
  outfile_ctx_t    *outfile_ctx    = hashcat_ctx->outfile_ctx;
  straight_ctx_t   *straight_ctx   = hashcat_ctx->straight_ctx;
  user_options_t   *user_options   = hashcat_ctx->user_options;

  out_t out;

  out.fp = stdout;

  char *filename = outfile_ctx->filename;

  if (filename)
  {
    FILE *fp = fopen (filename, "ab");

    if (fp == NULL)
    {
      event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno));

      return -1;
    }

    if (lock_file (fp) == -1)
    {
      fclose (fp);

      event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno));

      return -1;
    }

    out.fp = fp;
  }

  out.len = 0;

  u32 plain_buf[64] = { 0 };

  u8 *plain_ptr = (u8 *) plain_buf;

  u32 plain_len = 0;

  const u32 il_cnt = device_param->kernel_params_buf32[30]; // ugly, i know

  if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
  {
    pw_t pw;

    for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
    {
      const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

      if (rc == -1)
      {
        if (filename) fclose (out.fp);

        return -1;
      }

      for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
      {
        const u32 off = device_param->innerloop_pos + il_pos;

        if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
        {
          for (int i = 0; i < 8; i++)
          {
            plain_buf[i] = pw.i[i];
          }

          plain_len = apply_rules_optimized (straight_ctx->kernel_rules_buf[off].cmds, &plain_buf[0], &plain_buf[4], pw.pw_len);
        }
        else
        {
          for (int i = 0; i < 64; i++)
          {
            plain_buf[i] = pw.i[i];
          }

          plain_len = apply_rules (straight_ctx->kernel_rules_buf[off].cmds, plain_buf, pw.pw_len);
        }

        if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;

        out_push (&out, plain_ptr, plain_len);
      }
    }
  }
  else if (user_options->attack_mode == ATTACK_MODE_COMBI)
  {
    pw_t pw;

    for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
    {
      const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

      if (rc == -1)
      {
        if (filename) fclose (out.fp);

        return -1;
      }

      for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
      {
        for (int i = 0; i < 64; i++)
        {
          plain_buf[i] = pw.i[i];
        }

        plain_len = pw.pw_len;

        char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
        u32   comb_len =          device_param->combs_buf[il_pos].pw_len;

        if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
        {
          memcpy (plain_ptr + plain_len, comb_buf, comb_len);
        }
        else
        {
          memmove (plain_ptr + comb_len, plain_ptr, plain_len);

          memcpy (plain_ptr, comb_buf, comb_len);
        }

        plain_len += comb_len;

        if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;

        out_push (&out, plain_ptr, plain_len);
      }
    }
  }
  else if (user_options->attack_mode == ATTACK_MODE_BF)
  {
    for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
    {
      for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
      {
        u64 l_off = device_param->kernel_params_mp_l_buf64[3] + gidvid;
        u64 r_off = device_param->kernel_params_mp_r_buf64[3] + il_pos;

        u32 l_start = device_param->kernel_params_mp_l_buf32[5];
        u32 r_start = device_param->kernel_params_mp_r_buf32[5];

        u32 l_stop = device_param->kernel_params_mp_l_buf32[4];
        u32 r_stop = device_param->kernel_params_mp_r_buf32[4];

        sp_exec (l_off, (char *) plain_ptr + l_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, l_start, l_start + l_stop);
        sp_exec (r_off, (char *) plain_ptr + r_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, r_start, r_start + r_stop);

        plain_len = mask_ctx->css_cnt;

        out_push (&out, plain_ptr, plain_len);
      }
    }
  }
  else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
  {
    pw_t pw;

    for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
    {
      const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

      if (rc == -1)
      {
        if (filename) fclose (out.fp);

        return -1;
      }

      for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
      {
        for (int i = 0; i < 64; i++)
        {
          plain_buf[i] = pw.i[i];
        }

        plain_len = pw.pw_len;

        u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;

        u32 start = 0;
        u32 stop  = device_param->kernel_params_mp_buf32[4];

        sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);

        plain_len += start + stop;

        out_push (&out, plain_ptr, plain_len);
      }
    }
  }
  else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
  {
    pw_t pw;

    for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
    {
      const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);

      if (rc == -1)
      {
        if (filename) fclose (out.fp);

        return -1;
      }

      for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
      {
        u64 off = device_param->kernel_params_mp_buf64[3] + gidvid;

        u32 start = 0;
        u32 stop  = device_param->kernel_params_mp_buf32[4];

        sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);

        plain_len = stop;

        char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
        u32   comb_len =          device_param->combs_buf[il_pos].pw_len;

        memcpy (plain_ptr + plain_len, comb_buf, comb_len);

        plain_len += comb_len;

        if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;

        out_push (&out, plain_ptr, plain_len);
      }
    }
  }

  out_flush (&out);

  if (filename) fclose (out.fp);

  return 0;
}
Esempio n. 16
0
void tell(const std::vector<rule_t> & rules, std::string number) {
    std::cout << number << " --> ";
    std::string result = apply_rules(rules, string_view_t{number});
    number.erase( std::remove(number.begin(), number.end(), '?'), number.end());
    std::cout << number << (number.empty()?"":" ") << result << std::endl;
}