Exemplo n.º 1
0
	void EncryptionModeLRW::DecryptSectorsCurrentThread (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const
	{
		if_debug (ValidateState ());
		if_debug (ValidateParameters (data, sectorCount, sectorSize));

		DecryptBuffer (data,
			sectorCount * sectorSize,
			SectorToBlockIndex (sectorIndex));
	}
Exemplo n.º 2
0
bool
service_cmd_handler(struct request *req)
{
    size_t i;

    for (i=0; i < ARRAY_SIZE(service_cmd_list); i++)
    {
        struct service_cmd *q = &service_cmd_list[i];
        const char *str = (req->argc-1 != q->max_args) ? "bad args" : "ok";

        if (strncmp(req->argv[0], q->cmd, strlen(q->cmd)))
            continue;

        if_debug(service, D_DEBUG3("Calling command '%s' with %d arguments, expected is %d (%s)\n",
                        q->cmd, req->argc - 1, q->max_args, str));

        if ((req->argc-1) != q->max_args)
        {
            request_appendf(req, "RESULT: INVALID\nBODY: syntax of \"%s\" is \"%s\"\n", q->cmd, q->syntax);
            return true;
        }

        q->callback(req);
        return true;
    }

    return false;
}
Exemplo n.º 3
0
int
cmd_cb_LMIP(struct request *req)
{
    struct tunnel_context *tun;
    size_t i = 0;
    struct in_addr addr;

    assert (req != NULL);

    if_debug(service, D_DEBUG2("Checking macs from cpe '%s'\n", req->argv[1]));

    addr.s_addr = inet_addr(req->argv[1]);

    tun = provision_get_tunnel_byip(&addr, NULL);
    if (!tun)
    {
        request_appendf(req, "RESULT: NOTFOUND\n");
        return 0;
    }

    helper_lock();
    request_appendf(req, "RESULT: OK\nBODY: ");
    for (; i < PROVISION_MAX_CLIENTS; i++)
    {
        const char *cur = tun->filter[i].src_mac;
        char com = tun->filter[i+1].src_mac[0] != '\0' ? ';' : 0x00;

        if (cur[0] != '\0')
            request_appendf(req, "%s%c", cur, com);
    }
    helper_unlock();

    return 0;
}
Exemplo n.º 4
0
uint64 File::Length () const
{
    if_debug (ValidateState());

    // BSD does not support seeking to the end of a device
#ifdef TC_BSD
    if (Path.IsBlockDevice() || Path.IsCharacterDevice())
    {
#	ifdef TC_MACOSX
        uint32 blockSize;
        uint64 blockCount;
        throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKSIZE, &blockSize) == -1, wstring (Path));
        throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKCOUNT, &blockCount) == -1, wstring (Path));
        return blockCount * blockSize;
#	else
        uint64 mediaSize;
        throw_sys_sub_if (ioctl (FileHandle, DIOCGMEDIASIZE, &mediaSize) == -1, wstring (Path));
        return mediaSize;
#	endif
    }
#endif
    off_t current = lseek (FileHandle, 0, SEEK_CUR);
    throw_sys_sub_if (current == -1, wstring (Path));
    SeekEnd (0);
    uint64 length = lseek (FileHandle, 0, SEEK_CUR);
    SeekAt (current);
    return length;
}
Exemplo n.º 5
0
void File::Close ()
{
    if_debug (ValidateState());

    if (!SharedHandle)
    {
        close (FileHandle);
        FileIsOpen = false;

        if ((mFileOpenFlags & File::PreserveTimestamps) && Path.IsFile())
        {
            struct utimbuf u;
            u.actime = AccTime;
            u.modtime = ModTime;

            try
            {
                throw_sys_sub_if (utime (string (Path).c_str(), &u) == -1, wstring (Path));
            }
            catch (...) // Suppress errors to allow using read-only files
            {
#ifdef DEBUG
                throw;
#endif
            }
        }
    }
}
Exemplo n.º 6
0
void File::WriteAt (const ConstBufferPtr &buffer, uint64 position) const
{
    if_debug (ValidateState());

#ifdef TC_TRACE_FILE_OPERATIONS
    TraceFileOperation (FileHandle, Path, true, buffer.Size(), position);
#endif
    throw_sys_sub_if (pwrite (FileHandle, buffer, buffer.Size(), position) != (ssize_t) buffer.Size(), wstring (Path));
}
Exemplo n.º 7
0
uint64 File::ReadAt (const BufferPtr &buffer, uint64 position) const
{
    if_debug (ValidateState());

#ifdef TC_TRACE_FILE_OPERATIONS
    TraceFileOperation (FileHandle, Path, false, buffer.Size(), position);
#endif
    ssize_t bytesRead = pread (FileHandle, buffer, buffer.Size(), position);
    throw_sys_sub_if (bytesRead == -1, wstring (Path));

    return bytesRead;
}
Exemplo n.º 8
0
	void EncryptionModeXTS::DecryptBuffer (byte *data, uint64 length, uint64 startDataUnitNo) const
	{
		if_debug (ValidateState());

		CipherList::const_iterator iSecondaryCipher = SecondaryCiphers.end();

		for (CipherList::const_reverse_iterator iCipher = Ciphers.rbegin(); iCipher != Ciphers.rend(); ++iCipher)
		{
			--iSecondaryCipher;
			DecryptBufferXTS (**iCipher, **iSecondaryCipher, data, length, startDataUnitNo, 0);
		}

		assert (iSecondaryCipher == SecondaryCiphers.begin());
	}
Exemplo n.º 9
0
void File::SeekEnd (int offset) const
{
    if_debug (ValidateState());

    // BSD does not support seeking to the end of a device
#ifdef TC_BSD
    if (Path.IsBlockDevice() || Path.IsCharacterDevice())
    {
        SeekAt (Length() + offset);
        return;
    }
#endif

    throw_sys_sub_if (lseek (FileHandle, offset, SEEK_END) == -1, wstring (Path));
}
Exemplo n.º 10
0
void
Summarize::do_opt_unit(OptUnit *unit)
{
    const char *unit_name = get_name(unit).chars();
    LineNote note = get_note(unit, k_line);
    claim(!is_null(note), "Missing `line' annotation on unit `%s'", unit_name);

    const char *file_name = note.get_file().chars();

    debug(1, "Processing procedure `%s' from file `%s'", unit_name, file_name);

    // This pass requires a unit's body to be a CFG.  Be sure that a
    // preceding pass has left it in that form.

    claim(is_kind_of<Cfg>(get_body(unit)), "Body is not in CFG form");
    Cfg *unit_cfg = static_cast<Cfg*>(get_body(unit));
    if_debug(5)
	fprint(stdout, unit_cfg, false, true);		// no layout, just code

	for (int i = 0; i < nodes_size(unit_cfg); ++i)
	{
	    CfgNode *block = get_node(unit_cfg, i);
	    for (InstrHandle h = start(block); h != end(block); ++h)
		if (HaltLabelNote note = get_note(*h, k_halt))
		    switch (note.get_kind())
		    {
		      case halt::CBR:
			summarize_branch('c', out, block, note, max_event_id);
			break;
		      case halt::MBR:
			summarize_branch('m', out, block, note, max_event_id);
			break;
		      case halt::ENTRY:
			fprintf(out, "p %ld 1 %d %s:%s\n",
				note.get_unique_id(),
				find_branch_id(block, max_event_id),
				file_name,
				unit_name);
			break;
		      case halt::EXIT:
			fprintf(out, "r %ld 0\n", note.get_unique_id());
			break;
		    }
	}

}
Exemplo n.º 11
0
struct request *
request_new (int sock,
             struct sockaddr_in *saddr)
{
    struct request *ref = calloc(1, sizeof(struct request));
    char *arg;

    ref->fd = sock;
    ref->saddr = *saddr; 

    if_debug(service, D_DEBUG3("request accepted from %s\n", inet_ntoa(ref->saddr.sin_addr)));

    /* read the data */
    if ((ref->data_len = read(ref->fd, ref->data, sizeof(ref->data))) < 1)
    {
        free (ref);
        return NULL;
    }

    /* parser the commands */
    for(arg = strtok(ref->data, " ");
        arg != NULL && ref->argc < SOFTGRED_REQUEST_MAX_PARAMS;
        arg = strtok(NULL, " "))
    {
        if (arg[0] != '\0')
            ref->argv[ref->argc++] = arg;
    }

    /* strip */
    if (ref->argc > 0)
    {
        char *str = ref->argv[ref->argc-1];

        for (; *str; str++)
        {
            if (!isgraph(*str))
                *str = '\0';
        }
    }

    return ref;
}
Exemplo n.º 12
0
int
cmd_cb_GTMC(struct request *req)
{
    struct tunnel_context *tun;

    assert (req != NULL);

    if_debug(service, D_DEBUG2("Checking CPE by MAC '%s'\n", req->argv[1]));

    tun = provision_get_tunnel_by_mac(req->argv[1]);
    if (!tun)
    {
        request_appendf(req, "RESULT: NOTFOUND\n");
        return 0;
    }

    const char *ip_remote = inet_ntoa(tun->ip_remote);
    request_appendf(req, "RESULT: OK\nBODY: %s@%s\n", ip_remote, tun->ifgre);

    return 0;
}
Exemplo n.º 13
0
void
Summarize::initialize()
{
    DefinitionBlock *db = the_file_block->get_definition_block();

    max_event_id = 0;
    for (Iter<ProcedureDefinition*> iter = db-> get_procedure_definition_iterator();
	 iter.is_valid();
	 iter.next())
    {
	OptUnit *unit = iter.current();
	claim(is_kind_of<Cfg>(get_body(unit)), "Body is not in CFG form");
	Cfg *unit_cfg = static_cast<Cfg*>(get_body(unit));
	debug(5, "Procedure %s", get_name(unit).chars());
	if_debug(5)
	    fprint(stdout, unit_cfg, true, true); // layout and code

	for (int i = 0; i < nodes_size(unit_cfg); ++i)
	{
	    CfgNode *block = get_node(unit_cfg, i);
	    for (InstrHandle h = start(block); h != end(block); ++h)
		if (HaltLabelNote note = get_note(*h, k_halt))
		    switch (note.get_kind())
		    {
		      case halt::CBR:
		      case halt::MBR:
		      case halt::ENTRY:
		      case halt::EXIT:
		      {
			  long id = note.get_unique_id();
			  if (max_event_id <= id)
			      max_event_id =  id + 1;
		      }
		    }
	}
    }
    fprintf(out, "%d\n", max_event_id);
}
Exemplo n.º 14
0
int
cmd_cb_STUN(struct request *req)
{
    struct tunnel_context **tuns = NULL;
    uint64_t tuns_len = 0;

    assert (req != NULL);

    if_debug(service, D_DEBUG2("Return list with all GRE tunnels.\n"));

    if (tunnel_context_get_all(&tuns, &tuns_len) != 0)
    {
        D_CRIT("Problems with tunnel_context_get_all()\n");
    }

    if (tuns_len < 1)
    {
        request_appendf(req, "RESULT: NULL\n");
        return 0;
    }

    request_appendf(req, "RESULT: OK\nBODY: ");
    while(tuns_len--)
    {
        struct tunnel_context *tun = tuns[tuns_len];
        const char *ip_remote = inet_ntoa(tun->ip_remote);

        request_appendf(req, "%s@%s;", ip_remote, tun->ifgre);
    }

    request_appendf(req, "\n");

    free (tuns);

    return 0;
}
Exemplo n.º 15
0
	void EncryptionAlgorithm::EncryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const
	{
		if_debug (ValidateState ());
		Mode->EncryptSectors (data, sectorIndex, sectorCount, sectorSize);
	}
Exemplo n.º 16
0
	void EncryptionAlgorithm::Encrypt (byte *data, uint64 length) const
	{
		if_debug (ValidateState());
		Mode->Encrypt (data, length);
	}
Exemplo n.º 17
0
	FilePath File::GetPath () const
	{
		if_debug (ValidateState());
		return Path;
	}
Exemplo n.º 18
0
void File::Flush () const
{
    if_debug (ValidateState());
    throw_sys_sub_if (fsync (FileHandle) != 0, wstring (Path));
}
Exemplo n.º 19
0
	void Whirlpool::ProcessData (const ConstBufferPtr &data)
	{
		if_debug (ValidateDataParameters (data));
		WHIRLPOOL_add (data.Get(), (int) data.Size() * 8, (WHIRLPOOL_CTX *) Context.Ptr());
	}
Exemplo n.º 20
0
	void Ripemd160::GetDigest (const BufferPtr &buffer)
	{
		if_debug (ValidateDigestParameters (buffer));
		RMD160Final (buffer, (RMD160_CTX *) Context.Ptr());
	}
Exemplo n.º 21
0
	void Ripemd160::ProcessData (const ConstBufferPtr &data)
	{
		if_debug (ValidateDataParameters (data));
		RMD160Update ((RMD160_CTX *) Context.Ptr(), data.Get(), (int) data.Size());
	}
Exemplo n.º 22
0
	void Whirlpool::GetDigest (const BufferPtr &buffer)
	{
		if_debug (ValidateDigestParameters (buffer));
		WHIRLPOOL_finalize ((WHIRLPOOL_CTX *) Context.Ptr(), buffer);
	}
Exemplo n.º 23
0
	void Sha256::GetDigest (const BufferPtr &buffer)
	{
		if_debug (ValidateDigestParameters (buffer));
		sha256_end (buffer, (sha256_ctx *) Context.Ptr());
	}
Exemplo n.º 24
0
	void Sha256::ProcessData (const ConstBufferPtr &data)
	{
		if_debug (ValidateDataParameters (data));
		sha256_hash (data.Get(), (int) data.Size(), (sha256_ctx *) Context.Ptr());
	}
Exemplo n.º 25
0
void File::SeekAt (uint64 position) const
{
    if_debug (ValidateState());
    throw_sys_sub_if (lseek (FileHandle, position, SEEK_SET) == -1, wstring (Path));
}
Exemplo n.º 26
0
	void EncryptionModeLRW::Decrypt (byte *data, uint64 length) const
	{
		if_debug (ValidateState ());
		DecryptBuffer (data, length, 1);
	}