Пример #1
0
Файл: subp.c Проект: flavioc/XSB
/*
 * Maintains max stack usage when "-s" option is given at startup.
 */
void intercept(CTXTdeclc Psc psc) {

  if (pflags[CLAUSE_INT])
    synint_proc(CTXTc psc, MYSIG_CLAUSE);
  else if (flags[DEBUG_ON] && !flags[HIDE_STATE]) {
    if (get_spy(psc)) { /* spy'ed pred, interrupted */
      synint_proc(CTXTc psc, MYSIG_SPY);
      flags[HIDE_STATE]++; /* hide interrupt handler */
    }
    else if (flags[TRACE]) {
      synint_proc(CTXTc psc, MYSIG_TRACE);
      flags[HIDE_STATE]++; /* hide interrupt handler */
    }
  }
  if (flags[HITRACE])
    debug_call(CTXTc psc);

#ifndef MULTI_THREAD
  if (flags[TRACE_STA]) {
    unsigned long  byte_size;

    byte_size = (top_of_heap - (CPtr)(glstack.low) + 1) * sizeof(Cell);
    if ( byte_size > tds.maxgstack_count )
      tds.maxgstack_count = byte_size;

    byte_size = ((CPtr)glstack.high - top_of_localstk) * sizeof(Cell);
    if ( byte_size > tds.maxlstack_count )
      tds.maxlstack_count = byte_size;

    byte_size = (top_of_trail - (CPtr *)tcpstack.low + 1) * sizeof(CPtr);
    if ( byte_size > tds.maxtrail_count )
      tds.maxtrail_count = byte_size;

    byte_size = ((CPtr)tcpstack.high - top_of_cpstack) * sizeof(Cell);
    if ( byte_size > tds.maxcpstack_count )
      tds.maxcpstack_count = byte_size;

    byte_size = ((CPtr)complstack.high - top_of_complstk) * sizeof(Cell);
    if ( byte_size > tds.maxopenstack_count )
      tds.maxopenstack_count = byte_size;

    if ((unsigned long)level_num > tds.maxlevel_num)
      tds.maxlevel_num = level_num;
  }
#endif
}
Пример #2
0
END_TEST

START_TEST(test_signature)
{
	mark_point();
	LocalCertificate &cert = KeyCtrl::instance()->getLocalCertificate();
	struct anoubis_sig *raw_cert = cert.getCertificate();

	mark_point();
	/* Create a new file */
	wxString fileName = JobCtrl_tempfile();
	fail_if(fileName.IsEmpty(), "Failed to create file");

	mark_point();
	u_int8_t cs_in[ANOUBIS_CS_LEN];
	fail_unless(JobCtrl_calculate_checksum(fileName, cs_in, sizeof(cs_in)),
	    "Failed to calculate checksum");

	mark_point();
	/* Register signature: Success */
	TaskEventSpy add_spy(jobCtrl, anTASKEVT_CSUM_ADD);

	mark_point();
	ComCsumAddTask add_task;
	add_task.addPath(fileName);
	fail_unless(add_task.setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	add_task.setPrivateKey(&KeyCtrl::instance()->getPrivateKey());
	mark_point();

	jobCtrl->addTask(&add_task);
	add_spy.waitForInvocation(1);

	mark_point();
	/* Receive signature: Success */
	TaskEventSpy get_spy(jobCtrl, anTASKEVT_CSUM_GET);

	mark_point();
	ComCsumGetTask *get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	fail_unless(get_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");

	mark_point();
	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(1);

	mark_point();
	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to get a checksum!\nComTaskResult = %i\n"
	    "ResultDetails = %i\n", get_task->getComTaskResult(),
	    get_task->getResultDetails());
	fail_unless(get_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(get_task->getResultDetails()),
	    get_task->getResultDetails());
	fail_unless(get_task->haveKeyId(), "No key-id is assigned");
	size_t len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_SIG);
	fail_unless(len > ANOUBIS_CS_LEN, "Unexpected csum-len\nIs: %i", len);
	mark_point();

	/* Remove signature: Success */
	TaskEventSpy del_spy(jobCtrl, anTASKEVT_CSUM_DEL);
	ComCsumDelTask	*del_task = new ComCsumDelTask;
	del_task->addPath(fileName);
	fail_unless(del_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	mark_point();

	jobCtrl->addTask(del_task);
	del_spy.waitForInvocation(1);
	mark_point();

	fail_unless(del_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to remove a checksum!\nComTaskResult = %i\n"
	    "ResultDetails = %i\n", del_task->getComTaskResult(),
	    del_task->getResultDetails());
	fail_unless(del_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(del_task->getResultDetails()),
	    del_task->getResultDetails());
	fail_unless(del_task->haveKeyId(), "No key-id is assigned");
	delete del_task;

	mark_point();
	delete get_task;
	get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	mark_point();
	fail_unless(get_task->setKeyId(raw_cert->keyid, raw_cert->idlen),
	    "Failed to setup task with key-id.");
	mark_point();
	/* Fetch signature again: Failure */
	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(2);

	mark_point();
	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Checksum request failed!\nComTaskResult = %i\nResultDetails = %i",
	    get_task->getComTaskResult(), get_task->getResultDetails());
	fail_unless(get_task->getSignatureError(0) == ENOENT,
	    "Signature error: %s (%i)\n",
	    anoubis_strerror(get_task->getSignatureError(0)),
	    get_task->getSignatureError(0));
	len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_SIG);
	fail_unless(len == 0, "Task contains a signature");
	mark_point();

	wxRemoveFile(fileName);
	mark_point();
}
Пример #3
0
END_TEST

START_TEST(test_csum_symlink_link)
{
	/* Create a new file */
	mark_point();
	wxString fileName = JobCtrl_tempfile();
	fail_if(fileName.IsEmpty(), "Failed to create file");
	mark_point();

	u_int8_t cs_in[ANOUBIS_CS_LEN];
	fail_unless(JobCtrl_calculate_checksum_buffer(
	    fileName.To8BitData(), fileName.Len(), cs_in, sizeof(cs_in)),
	    "Failed to calculate checksum");

	mark_point();
	/* Symlink the file */
	wxString symlinkName = wxFileName::GetTempDir() + wxT("/csumsymlink");
	fail_if(wxFileExists(symlinkName), "Symlink already exists");
	fail_unless(
	    symlink(fileName.To8BitData(), symlinkName.To8BitData()) == 0,
	    "Failed to create symlink (%s)", anoubis_strerror(errno));
	mark_point();

	/* Register symlink at daemon: Success */
	TaskEventSpy add_spy(jobCtrl, anTASKEVT_CSUM_ADD);
	mark_point();
	ComCsumAddTask add_task;
	add_task.addPath(symlinkName);
	mark_point();

	jobCtrl->addTask(&add_task);
	add_spy.waitForInvocation(1);
	mark_point();

	fail_unless(add_task.getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to add a checksum: %i\n", add_task.getComTaskResult());
	fail_unless(add_task.getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(add_task.getResultDetails()),
	    add_task.getResultDetails());
	fail_unless(add_task.haveKeyId() == false, "A key-id is assigned");
	mark_point();

	/* Receive from daemon: success */
	TaskEventSpy get_spy(jobCtrl, anTASKEVT_CSUM_GET);
	ComCsumGetTask *get_task = new ComCsumGetTask;
	get_task->addPath(symlinkName);
	mark_point();

	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(1);
	mark_point();

	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to get a checksum!\nComTaskResult = %i\n"
	    "ResultDetails = %s\n", get_task->getComTaskResult(),
	    anoubis_strerror(get_task->getResultDetails()));
	fail_unless(get_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(get_task->getResultDetails()),
	    get_task->getResultDetails());
	fail_unless(get_task->haveKeyId() == false, "A key-id is assigned");
	mark_point();
	size_t len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_CS);
	mark_point();
	fail_unless(len == ANOUBIS_CS_LEN,
	    "Unexpected csum-len\n"
	    "Is: %i\n"
	    "Expected: %i\n", len, ANOUBIS_CS_LEN);

	mark_point();
	const u_int8_t *cs_out;
	bool ok = get_task->getChecksumData(0, ANOUBIS_SIG_TYPE_CS,
	    cs_out, len);
	fail_unless(ok && len == ANOUBIS_CS_LEN,
	    "Unexpected checksum received!");
	fail_unless(memcmp(cs_in, cs_out, ANOUBIS_CS_LEN) == 0,
	    "Unexpected checksum fetched from daemon");
	mark_point();

	wxRemoveFile(symlinkName);
	wxRemoveFile(fileName);
	mark_point();
}
Пример #4
0
END_TEST

START_TEST(test_csum_orphaned)
{
	size_t		len;
	/* Create a new file */
	wxString fileName = JobCtrl_tempfile();
	fail_if(fileName.IsEmpty(), "Failed to create file");

	mark_point();
	u_int8_t cs_in[ANOUBIS_CS_LEN];
	fail_unless(JobCtrl_calculate_checksum(fileName, cs_in, sizeof(cs_in)),
	    "Failed to calculate checksum");
	mark_point();

	/* Register checksum: Success */
	TaskEventSpy add_spy(jobCtrl, anTASKEVT_CSUM_ADD);
	ComCsumAddTask add_task;
	add_task.addPath(fileName);
	mark_point();

	jobCtrl->addTask(&add_task);
	add_spy.waitForInvocation(1);
	mark_point();

	fail_unless(add_task.getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to add a checksum: %i\n", add_task.getComTaskResult());
	fail_unless(add_task.getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(add_task.getResultDetails()),
	    add_task.getResultDetails());
	fail_unless(add_task.haveKeyId() == false, "A key-id is assigned");
	mark_point();

	/* Remove file -> orphaned */
	fail_unless(wxRemoveFile(fileName), "Failed to remove file");
	mark_point();

	/* Receive checksum: Success */
	TaskEventSpy get_spy(jobCtrl, anTASKEVT_CSUM_GET);
	ComCsumGetTask *get_task = new ComCsumGetTask;
	get_task->addPath(fileName);
	mark_point();

	jobCtrl->addTask(get_task);
	get_spy.waitForInvocation(1);
	mark_point();

	fail_unless(get_task->getComTaskResult() == ComTask::RESULT_SUCCESS,
	    "Failed to get a checksum!\n"
	    "ComTaskResult = %i\n"
	    "ResultDetails = %i (%s)\n",
	    get_task->getComTaskResult(), get_task->getResultDetails(),
	    anoubis_strerror(get_task->getResultDetails()));
	fail_unless(get_task->getResultDetails() == 0,
	    "ResultDetails: %s (%i)\n",
	    anoubis_strerror(get_task->getResultDetails()),
	    get_task->getResultDetails());
	fail_unless(get_task->haveKeyId() == false, "A key-id is assigned");
	len = get_task->getChecksumLen(0, ANOUBIS_SIG_TYPE_CS);
	fail_unless(len == ANOUBIS_CS_LEN,
	    "Unexpected csum-len\nIs: %i\nExpected: %i\n",
	    len, ANOUBIS_CS_LEN);
	mark_point();

	const u_int8_t *cs_out;
	bool ok = get_task->getChecksumData(0, ANOUBIS_SIG_TYPE_CS,
	    cs_out, len);
	fail_unless(ok && len == ANOUBIS_CS_LEN,
	    "Unexpected checksum received!");
	fail_unless(memcmp(cs_in, cs_out, ANOUBIS_CS_LEN) == 0,
	    "Unexpected checksum fetched from daemon");
	mark_point();
}