예제 #1
0
파일: Pager.c 프로젝트: marciof/show
static void flush_buffer(Pager* pager, int default_fd, Error* error) {
    protect_buffer(pager, true, error);

    if (ERROR_HAS(error)) {
        return;
    }

    if (pager->fd == IO_INVALID_FD) {
        pager->fd = default_fd;
    }

    for (size_t i = 0; i < pager->buffers.length; ++i) {
        Buffer* buffer = (Buffer*) pager->buffers.data[i];

        io_write(pager->fd, buffer, error);
        Buffer_delete(buffer);

        if (ERROR_HAS(error)) {
            pager->buffers.data[i] = (intptr_t) NULL;
            return;
        }
    }

    pager->buffers.length = 0;
    protect_buffer(pager, false, error);
}
예제 #2
0
파일: main.c 프로젝트: numero3/protect_file
int main(int argc, char *argv[])

{
	int ret;

	unsigned char key[32]; //SHA256 used
	char password[32];
	unsigned char salt[16];
	unsigned int iterations;
	unsigned char input[128];
	int input_len;
	unsigned char *output;
	int output_len;

	/* *** initialization *** */
	strcpy(password, "MonMDP !!!");
	memset(salt, 0x00, 16); //salt = 0x00 ... 0x00
	input_len = 128;
	memset(input, 0x99, input_len);

	iterations = 1<<5; //32
	ret = 1;
	output = NULL;

	/* *** protect buffers *** */
	ret = protect_buffer(&output, &output_len,
			input, input_len, password, salt, 16, iterations);
	printf(">>> ret : %d\n", ret);
	print_hex(output, output_len, "OUTPUT");
	if(ret != 0)
		goto cleanup;


	ret = 0;
cleanup:
	/* *** cleanup and return *** */
	memset(key, 0x00, 32);
	memset(password, 0x00, 32);
	memset(salt, 0x00, 16);
	iterations = 0;

	return ret;
}
예제 #3
0
파일: Pager.c 프로젝트: marciof/show
static bool buffer_input(Pager* pager, Buffer** buffer, Error* error) {
    bool should_buffer = true;

    for (size_t i = 0; i < (*buffer)->length; ++i) {
        if ((*buffer)->data[i] == '\n') {
            ++pager->nr_lines;
            pager->nr_line_chars = 0;

            if (pager->nr_lines > (terminal.ws_row * PAGING_THRESHOLD)) {
                should_buffer = false;
                break;
            }
        }
        else {
            ++pager->nr_line_chars;

            if (pager->nr_line_chars > terminal.ws_col) {
                ++pager->nr_lines;
                pager->nr_line_chars = 0;

                if (pager->nr_lines > (terminal.ws_row * PAGING_THRESHOLD)) {
                    should_buffer = false;
                    break;
                }
            }
        }
    }

    if (!should_buffer) {
        return false;
    }

    protect_buffer(pager, true, error);

    if (ERROR_HAS(error)) {
        return false;
    }

    Array_add(
        &pager->buffers, pager->buffers.length, (intptr_t) *buffer, error);

    if (ERROR_HAS(error)) {
        return false;
    }

    protect_buffer(pager, false, error);

    if (ERROR_HAS(error)) {
        return false;
    }

    if (!pager->has_timer) {
        int error_nr = pthread_create(
            &pager->timer_thread, NULL, flush_buffer_timer, pager);

        if (error_nr) {
            Error_add(error, strerror(error_nr));
            return false;
        }

        error_nr = pthread_mutex_init(&pager->timer_mutex, NULL);

        // FIXME: stop thread?
        if (error_nr) {
            Error_add(error, strerror(error_nr));
            return false;
        }

        pager->has_timer = true;
    }

    *buffer = NULL;
    return true;
}