Beispiel #1
0
static bool test_anonymous_shared_simple(struct torture_context *tctx)
{
	void *ptr;
	size_t len;

	torture_comment(tctx, "anonymous_shared_free(NULL)\n");
	anonymous_shared_free(NULL);

	len = 500;
	torture_comment(tctx, "anonymous_shared_allocate(%llu)\n",
			(unsigned long long)len);
	ptr = anonymous_shared_allocate(len);
	torture_assert(tctx, ptr, "valid pointer");
	memset(ptr, 0xfe, len);
	torture_comment(tctx, "anonymous_shared_free(ptr)\n");
	anonymous_shared_free(ptr);

	len = 50000;
	torture_comment(tctx, "anonymous_shared_allocate(%llu)\n",
			(unsigned long long)len);
	ptr = anonymous_shared_allocate(len);
	torture_assert(tctx, ptr, "valid pointer");
	memset(ptr, 0xfe, len);
	torture_comment(tctx, "anonymous_shared_free(ptr)\n");
	anonymous_shared_free(ptr);

	memset(&len, 0xFF, sizeof(len));
	torture_comment(tctx, "anonymous_shared_allocate(%llu)\n",
			(unsigned long long)len);
	ptr = anonymous_shared_allocate(len);
	torture_assert(tctx, ptr == NULL, "null pointer");

	return true;
}
void nbio_shmem(int n)
{
	nprocs = n;
	children = (struct children *)anonymous_shared_allocate(sizeof(*children) * nprocs);
	if (!children) {
		printf("Failed to setup shared memory!\n");
		exit(1);
	}
}
Beispiel #3
0
void nbio_shmem(int n, int t_timelimit, int t_warmup)
{
	nprocs = n;
	children = anonymous_shared_allocate(sizeof(*children) * nprocs);
	if (!children) {
		printf("Failed to setup shared memory!\n");
		nb_exit(1);
	}
	memset(children, 0, sizeof(*children) * nprocs);
	timelimit = t_timelimit;
	warmup = t_warmup;
	in_cleanup = 0;
	tv_start = timeval_current();
}
Beispiel #4
0
bool srv_init_signing(struct smbd_server_connection *conn)
{
    bool allowed = true;
    bool desired;
    bool mandatory = false;

    switch (lp_server_signing()) {
    case SMB_SIGNING_REQUIRED:
        mandatory = true;
        break;
    case SMB_SIGNING_IF_REQUIRED:
        break;
    case SMB_SIGNING_DEFAULT:
    case SMB_SIGNING_OFF:
        allowed = false;
        break;
    }

    /*
     * if the client and server allow signing,
     * we desire to use it.
     *
     * This matches Windows behavior and is needed
     * because not every client that requires signing
     * sends FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED.
     */
    desired = allowed;

    if (lp_async_smb_echo_handler()) {
        struct smbd_shm_signing *s;

        /* setup the signing state in shared memory */
        s = talloc_zero(conn, struct smbd_shm_signing);
        if (s == NULL) {
            return false;
        }
        s->shm_size = 4096;
        s->shm_pointer =
            (uint8_t *)anonymous_shared_allocate(s->shm_size);
        if (s->shm_pointer == NULL) {
            talloc_free(s);
            return false;
        }
        talloc_set_destructor(s, smbd_shm_signing_destructor);
        conn->smb1.signing_state = smb_signing_init_ex(s,
                                   allowed, desired, mandatory,
                                   smbd_shm_signing_alloc,
                                   smbd_shm_signing_free);
        if (!conn->smb1.signing_state) {
            return false;
        }
        return true;
    }

    conn->smb1.signing_state = smb_signing_init(conn,
                               allowed, desired, mandatory);
    if (!conn->smb1.signing_state) {
        return false;
    }

    return true;
}
Beispiel #5
0
bool prefork_create_pool(TALLOC_CTX *mem_ctx,
			 struct tevent_context *ev_ctx,
			 struct messaging_context *msg_ctx,
			 int listen_fd_size, int *listen_fds,
			 int min_children, int max_children,
			 prefork_main_fn_t *main_fn, void *private_data,
			 struct prefork_pool **pf_pool)
{
	struct prefork_pool *pfp;
	pid_t pid;
	time_t now = time(NULL);
	size_t data_size;
	int ret;
	int i;
	bool ok;

	pfp = talloc_zero(mem_ctx, struct prefork_pool);
	if (!pfp) {
		DEBUG(1, ("Out of memory!\n"));
		return false;
	}
	pfp->listen_fd_size = listen_fd_size;
	pfp->listen_fds = talloc_array(pfp, int, listen_fd_size);
	if (!pfp->listen_fds) {
		DEBUG(1, ("Out of memory!\n"));
		return false;
	}
	for (i = 0; i < listen_fd_size; i++) {
		pfp->listen_fds[i] = listen_fds[i];
		/* force sockets in non-blocking mode */
		set_blocking(listen_fds[i], false);
	}
	pfp->main_fn = main_fn;
	pfp->private_data = private_data;

	pfp->pool_size = max_children;
	data_size = sizeof(struct pf_worker_data) * max_children;

	pfp->pool = (struct pf_worker_data *)anonymous_shared_allocate(
		data_size);
	if (pfp->pool == NULL) {
		DEBUG(1, ("Failed to mmap memory for prefork pool!\n"));
		talloc_free(pfp);
		return false;
	}
	talloc_set_destructor(pfp, prefork_pool_destructor);

	for (i = 0; i < min_children; i++) {

		pfp->pool[i].allowed_clients = 1;
		pfp->pool[i].started = now;

		pid = fork();
		switch (pid) {
		case -1:
			DEBUG(1, ("Failed to prefork child n. %d !\n", i));
			break;

		case 0: /* THE CHILD */

			pfp->pool[i].status = PF_WORKER_ALIVE;
			ret = pfp->main_fn(ev_ctx, msg_ctx,
					   &pfp->pool[i], i + 1,
					   pfp->listen_fd_size,
					   pfp->listen_fds,
					   pfp->private_data);
			exit(ret);

		default: /* THE PARENT */
			pfp->pool[i].pid = pid;
			break;
		}
	}

	ok = prefork_setup_sigchld_handler(ev_ctx, pfp);
	if (!ok) {
		DEBUG(1, ("Failed to setup SIGCHLD Handler!\n"));
		talloc_free(pfp);
		return false;
	}

	*pf_pool = pfp;
	return true;
}