コード例 #1
0
ファイル: normalize.c プロジェクト: kleopatra999/arvo
term* normalize_fuel_var(context *Sigma, typing_context* Delta, term* t, int fuel) {
  term* defn = context_lookup(t->var, Sigma);
  if (defn == NULL) {
    return term_dup(t);
  }
  return normalize_fuel(Sigma, Delta, defn, fuel-1);
}
コード例 #2
0
ファイル: normalize.c プロジェクト: kleopatra999/arvo
term* whnf(context *Sigma, typing_context* Delta, term* t) {
  if (t == NULL) return NULL;

  switch (t->tag) {
  case VAR:
    {
      term* defn = context_lookup(t->var, Sigma);
      if (defn == NULL) {
        return term_dup(t);
      }
      return whnf(Sigma, Delta, defn);
    }
  case APP:
    {
      term* l = whnf(Sigma, Delta, t->left);
      if (l->tag == LAM) {
        term* subs = substitute(l->var, t->right, l->right);
        free_term(l);
        return whnf_and_free(Sigma, Delta, subs);
      }
      return make_app(l, term_dup(t->right));
    }
  case ELIM:
    {
      term* last = t->args[t->num_args - 1];
      term* nlast = whnf(Sigma, Delta, last);
      term* c = term_dup(t);
      free_term(c->args[c->num_args - 1]);
      c->args[c->num_args - 1] = nlast;
      if (nlast->tag == INTRO) {
        return whnf_and_free(Sigma, Delta, elim_over_intro(Delta, c));
      } else {
        return c;
      }
    }
  case HOLE:
  case DATATYPE:
  case TYPE:
  case LAM:
  case INTRO:
  case PI:
  case IMPLICIT:
    return term_dup(t);
  }
}
コード例 #3
0
ファイル: request.c プロジェクト: gvsurenderreddy/DNDS
/* Authentication Request from the node */
int authRequest(struct session *session, DNDSMessage_t *req_msg)
{
	char *certName = NULL;
	size_t length = 0;
	uint32_t context_id = 0;

	struct session *old_session = NULL;

	AuthRequest_get_certName(req_msg, &certName, &length);

	if (session->state != SESSION_STATE_NOT_AUTHED) {
		jlog(L_WARNING, "authRequest duplicate");
		return -1;
	}

	DNDSMessage_t *msg = NULL;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);

	DNMessage_set_seqNumber(msg, 1);
	DNMessage_set_ackNumber(msg, 0);
	DNMessage_set_operation(msg, dnop_PR_authResponse);

	AuthRequest_get_certName(req_msg, &certName, &length);

	session->node_info = cn2node_info(certName);
	if (session->node_info == NULL) {
		jlog(L_WARNING, "cn2node_info failed");
		DNDSMessage_del(msg);
		return -1;
	}

	jlog(L_DEBUG, "type: %s", session->node_info->type);
	jlog(L_DEBUG, "uuid: %s", session->node_info->uuid);
	jlog(L_DEBUG, "context_id: %s", session->node_info->context_id);

	context_id = atoi(session->node_info->context_id);
	session->context = context_lookup(context_id);

	if (session->context == NULL) {
		AuthResponse_set_result(msg, DNDSResult_insufficientAccessRights);
		net_send_msg(session->netc, msg);
		DNDSMessage_del(msg);
		return -1;
	}

	/* XXX check if the node has access
	if (ctable_find(session->context->atable, session->node_info->uuid) == NULL) {
		AuthResponse_set_result(msg, DNDSResult_insufficientAccessRights);
		net_send_msg(session->netc, msg);
		DNDSMessage_del(msg);
		jlog(L_ERROR, "authentication failed, invalid certificate");
		return -1;
	}
	*/

	/* check if the node is already connected */
	old_session = ctable_find(session->context->ctable, session->node_info->uuid);
	if (old_session == NULL) {
		ctable_insert(session->context->ctable, session->node_info->uuid, session);
	} else {
		// that node is already connected, if the new session is from the same IP
		// disconnect the old session, and let this one connect
		if (strcmp(old_session->ip, session->ip) == 0) {
			net_disconnect(old_session->netc);
			ctable_insert(session->context->ctable, session->node_info->uuid, session);
		}
	}

	session->cert_name = strdup(certName);
	if (session->netc->security_level == NET_UNSECURE) {

		AuthResponse_set_result(msg, DNDSResult_success);
		net_send_msg(session->netc, msg);

		session->state = SESSION_STATE_AUTHED;
		session->netc->on_secure(session->netc);

	} else {

		AuthResponse_set_result(msg, DNDSResult_secureStepUp);
		net_send_msg(session->netc, msg);

		krypt_add_passport(session->netc->kconn, session->context->passport);
		session->state = SESSION_STATE_WAIT_STEPUP;
		net_step_up(session->netc);
	}

	DNDSMessage_del(msg);

	return 0;
}