Beispiel #1
0
static struct tevent_req *aio_posix_pwrite_send(
	struct vfs_handle_struct *handle,
	TALLOC_CTX *mem_ctx, struct tevent_context *ev,
	struct files_struct *fsp, const void *data, size_t n, off_t offset)
{
	struct tevent_req *req;
	struct aio_posix_state *state;
	struct aiocb *a;
	int ret;

	req = tevent_req_create(mem_ctx, &state, struct aio_posix_state);
	if (req == NULL) {
		return NULL;
	}

	a = &state->acb;

	a->aio_fildes = fsp->fh->fd;
	a->aio_buf = discard_const(data);
	a->aio_nbytes = n;
	a->aio_offset = offset;
	a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
	a->aio_sigevent.sigev_signo  = RT_SIGNAL_AIO;
	a->aio_sigevent.sigev_value.sival_ptr = req;

	ret = aio_write(a);
	if (ret == 0) {
		talloc_set_destructor(state, aio_posix_state_destructor);
		return req;
	}

	if (errno == EAGAIN) {
		/*
		 * aio overloaded, do the sync fallback
		 */
		state->ret = sys_pwrite(fsp->fh->fd, data, n, offset);
		if (state->ret == -1) {
			state->err = errno;
		}
		tevent_req_done(req);
		return tevent_req_post(req, ev);
	}

	tevent_req_error(req, errno);
	return tevent_req_post(req, ev);
}
Beispiel #2
0
/*
  put a request into the send queue
*/
void smbcli_transport_send(struct smbcli_request *req)
{
	DATA_BLOB blob;
	NTSTATUS status;

	/* check if the transport is dead */
	if (req->transport->socket->sock == NULL) {
		req->state = SMBCLI_REQUEST_ERROR;
		req->status = NT_STATUS_NET_WRITE_FAULT;
		return;
	}

	blob = data_blob_const(req->out.buffer, req->out.size);
	status = packet_send(req->transport->packet, blob);
	if (!NT_STATUS_IS_OK(status)) {
		req->state = SMBCLI_REQUEST_ERROR;
		req->status = status;
		return;
	}

	packet_queue_run(req->transport->packet);
	if (req->transport->socket->sock == NULL) {
		req->state = SMBCLI_REQUEST_ERROR;
		req->status = NT_STATUS_NET_WRITE_FAULT;
		return;
	}

	if (req->one_way_request) {
		req->state = SMBCLI_REQUEST_DONE;
		smbcli_request_destroy(req);
		return;
	}

	req->state = SMBCLI_REQUEST_RECV;
	DLIST_ADD(req->transport->pending_recv, req);

	/* add a timeout */
	if (req->transport->options.request_timeout) {
		event_add_timed(req->transport->socket->event.ctx, req, 
				timeval_current_ofs(req->transport->options.request_timeout, 0), 
				smbcli_timeout_handler, req);
	}

	talloc_set_destructor(req, smbcli_request_destructor);
}
static void *mod_conn_create(void *instance)
{
	int rcode;
	rlm_sql_t *inst = instance;
	rlm_sql_handle_t *handle;

	handle = talloc_zero(instance, rlm_sql_handle_t);

	/*
	 *	Handle requires a pointer to the SQL inst so the
	 *	destructor has access to the module configuration.
	 */
	handle->inst = inst;
	handle->init = false;

	/*
	 *	When something frees this handle the destructor set by
	 *	the driver will be called first, closing any open sockets.
	 *	Then we call our destructor to trigger an modules.sql.close
	 *	event, then all the memory is freed.
	 */
	talloc_set_destructor(handle, _sql_conn_destructor);

	rcode = (inst->module->sql_socket_init)(handle, inst->config);
	if (rcode != 0) {
	fail:
		exec_trigger(NULL, inst->cs, "modules.sql.fail", true);

		/*
		 *	Destroy any half opened connections.
		 */
		talloc_free(handle);
		return NULL;
	}

	if (inst->config->open_query && *inst->config->open_query) {
		if (rlm_sql_select_query(&handle, inst, inst->config->open_query)) {
			goto fail;
		}
	}

	exec_trigger(NULL, inst->cs, "modules.sql.open", false);
	handle->init = true;
	return handle;
}
Beispiel #4
0
static struct share_mode_lock *get_share_mode_lock_internal(
	TALLOC_CTX *mem_ctx, struct file_id id,
	const char *servicepath, const struct smb_filename *smb_fname,
	const struct timespec *old_write_time)
{
	struct share_mode_lock *lck;
	struct share_mode_data *d;
	struct db_record *rec;
	TDB_DATA key = locking_key(&id);
	TDB_DATA value;

	rec = dbwrap_fetch_locked(lock_db, mem_ctx, key);
	if (rec == NULL) {
		DEBUG(3, ("Could not lock share entry\n"));
		return NULL;
	}

	value = dbwrap_record_get_value(rec);

	if (value.dptr == NULL) {
		d = fresh_share_mode_lock(mem_ctx, servicepath, smb_fname,
					  old_write_time);
	} else {
		d = parse_share_modes(mem_ctx, value);
	}

	if (d == NULL) {
		DEBUG(5, ("get_share_mode_lock_internal: "
			"Could not get share mode lock\n"));
		TALLOC_FREE(rec);
		return NULL;
	}
	d->id = id;
	d->record = talloc_move(d, &rec);
	talloc_set_destructor(d, share_mode_data_destructor);

	lck = talloc(mem_ctx, struct share_mode_lock);
	if (lck == NULL) {
		DEBUG(1, ("talloc failed\n"));
		TALLOC_FREE(d);
		return NULL;
	}
	lck->data = talloc_move(lck, &d);
	return lck;
}
Beispiel #5
0
struct context *context_new_test(struct context *parent, void *context,
                                 const char *called_path)
{
    struct context *c;

    c = talloc(context, struct context);
    c->type = CONTEXT_TYPE_TEST;
    c->parent = c;
    c->test_parent = parent;
    c->bin_dir = talloc_reference(c, parent->chk_dir);
    c->lib_dir = talloc_reference(c, parent->lib_dir);
    c->hdr_dir = talloc_reference(c, parent->hdr_dir);
    c->obj_dir = talloc_reference(c, parent->obj_dir);
    c->src_dir = talloc_asprintf(c, "%s/%s", parent->tst_dir,
                                 parent->called_path);
    c->chk_dir = talloc_reference(c, parent->chk_dir);
    c->tst_dir = talloc_reference(c, parent->tst_dir);
    c->gen_dir = talloc_reference(c, parent->gen_dir);
    c->prefix = talloc_reference(c, parent->prefix);
    c->libexec_dir = talloc_reference(c, parent->libexec_dir);
    c->share_dir = talloc_reference(c, parent->share_dir);
    c->compile_opts = stringlist_copy(parent->compile_opts, c);
    c->link_opts = stringlist_copy(parent->link_opts, c);
    c->mf = talloc_reference(c, parent->mf);
    c->ll = talloc_reference(c, parent->ll);
    c->shared_target = false;
    c->s = parent->s;
    c->language = NULL;
    c->objects = stringlist_new(c);
    c->libraries = stringlist_new(c);
    c->testdeps = stringlist_copy(parent->testdeps, c);
    c->testdir = talloc_strdup(c, parent->testdir);
    c->src_dir = talloc_strdup(c, parent->testdir);
    c->autodeps = parent->autodeps;

    c->called_path = talloc_strdup(c, called_path);
    c->full_path = talloc_asprintf(c, "%s/%s/%s", c->bin_dir,
                                   parent->called_path, called_path);
    c->link_path = talloc_strdup(c, "");
    c->link_path_install = talloc_strdup(c, "");

    talloc_set_destructor(c, &context_test_destructor);

    return c;
}
Beispiel #6
0
/**
 * Create a directory that will be automatically removed either on
 * PRoot termination if @context is NULL, or once its path name
 * (attached to @context) is freed.  This function returns NULL on
 * error, otherwise the absolute path name to the created directory
 * (@prefix-ed).
 */
const char *create_temp_directory(TALLOC_CTX *context, const char *prefix)
{
	char *name;

	name = create_temp_name(context, prefix);
	if (name == NULL)
		return NULL;

	name = mkdtemp(name);
	if (name == NULL) {
		note(NULL, ERROR, SYSTEM, "can't create temporary directory");
		return NULL;
	}

	talloc_set_destructor(name, remove_temp_directory);

	return name;
}
/** Creates a new connection handle for use by the FR connection API.
 *
 * Matches the fr_connection_create_t function prototype, is passed to
 * fr_connection_pool_init, and called when a new connection is required by the
 * connection pool API.
 *
 * @see fr_connection_pool_init
 * @see fr_connection_create_t
 * @see connection.c
 */
static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED struct timeval const *timeout)
{
	rlm_yubikey_t *inst = instance;
	ykclient_rc status;
	ykclient_handle_t *yandle, **marker;

	status = ykclient_handle_init(inst->ykc, &yandle);
	if (status != YKCLIENT_OK) {
		ERROR("rlm_yubikey (%s): %s", inst->name, ykclient_strerror(status));

		return NULL;
	}
	marker = talloc(ctx, ykclient_handle_t *);
	talloc_set_destructor(marker, _mod_conn_free);
	*marker = yandle;

	return yandle;
}
Beispiel #8
0
/* create a red black tree */
trbt_tree_t *
trbt_create(TALLOC_CTX *memctx, uint32_t flags)
{
	trbt_tree_t *tree;

	tree = talloc_zero(memctx, trbt_tree_t);
	NO_MEMORY_FATAL(tree);

	/* If the tree is freed, we must walk over all entries and steal the
	   node from the stored data pointer and release the node.
	   Note, when we free the tree  we only free the tree and not any of 
	   the data stored in the tree.
	*/
	talloc_set_destructor(tree, tree_destructor);
	tree->flags = flags;

	return tree;
}
Beispiel #9
0
struct mpv_opengl_cb_context *mp_opengl_create(struct mpv_global *g,
                                               struct mp_client_api *client_api)
{
    mpv_opengl_cb_context *ctx = talloc_zero(NULL, mpv_opengl_cb_context);
    talloc_set_destructor(ctx, free_ctx);
    pthread_mutex_init(&ctx->lock, NULL);
    pthread_cond_init(&ctx->wakeup, NULL);

    ctx->global = g;
    ctx->log = mp_log_new(ctx, g->log, "opengl-cb");
    ctx->client_api = client_api;

    ctx->hwdec_api = g->opts->vo.hwdec_preload_api;
    if (ctx->hwdec_api == HWDEC_NONE)
        ctx->hwdec_api = g->opts->hwdec_api;

    return ctx;
}
Beispiel #10
0
static bool
parent_dbus_string_arrays(struct sbus_request *request, int first_arg_type,
                          va_list va)
{
    struct array_arg *array_arg;
    int arg_type;
    void **arg_ptr;

    /*
     * Here we iterate through the entire thing again and look for
     * things we need to fix allocation for. Normally certain types
     * returned from dbus_message_get_args() and friends require
     * later freeing. We tie those to the talloc context here.
     *
     * The list of argument has already been validated by the previous
     * dbus_message_get_args() call, so we can be cheap.
     */

    arg_type = first_arg_type;
    while (arg_type != DBUS_TYPE_INVALID) {

        if (arg_type == DBUS_TYPE_ARRAY) {
            arg_type = va_arg(va, int);     /* the array element type */
            arg_ptr = va_arg(va, void **);  /* the array elements */
            va_arg(va, int *);              /* the array length */

            /* Arrays of these things need to be freed */
            if (arg_type == DBUS_TYPE_STRING ||
                arg_type == DBUS_TYPE_OBJECT_PATH ||
                arg_type == DBUS_TYPE_SIGNATURE) {

                array_arg = talloc_zero(request, struct array_arg);
                if (array_arg == NULL) {
                    /* no kidding ... */
                    DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory while trying not to leak memory\n");
                    return false;
                }

                array_arg->dbus_array = *arg_ptr;
                talloc_set_destructor(array_arg, array_arg_destructor);
            }

        /* A non array argument */
        } else {
Beispiel #11
0
/*
  Open up the notify.tdb database. You should close it down using
  talloc_free(). We need the imessaging_ctx to allow for notifications
  via internal messages
*/
struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
				   struct imessaging_context *imessaging_ctx,
				   struct loadparm_context *lp_ctx,
				   struct tevent_context *ev,
				   struct share_config *scfg)
{
	struct notify_context *notify;

	if (share_bool_option(scfg, NOTIFY_ENABLE, NOTIFY_ENABLE_DEFAULT) != true) {
		return NULL;
	}

	if (ev == NULL) {
		return NULL;
	}

	notify = talloc(mem_ctx, struct notify_context);
	if (notify == NULL) {
		return NULL;
	}

	notify->w = cluster_tdb_tmp_open(notify, lp_ctx, "notify.tdb", TDB_SEQNUM);
	if (notify->w == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->server = server;
	notify->imessaging_ctx = imessaging_ctx;
	notify->list = NULL;
	notify->array = NULL;
	notify->seqnum = tdb_get_seqnum(notify->w->tdb);

	talloc_set_destructor(notify, notify_destructor);

	/* register with the messaging subsystem for the notify
	   message type */
	imessaging_register(notify->imessaging_ctx, notify,
			   MSG_PVFS_NOTIFY, notify_handler);

	notify->sys_notify_ctx = sys_notify_context_create(scfg, notify, ev);

	return notify;
}
Beispiel #12
0
static NTSTATUS smbXsrv_open_global_lookup(struct smbXsrv_open_table *table,
        uint32_t open_global_id,
        TALLOC_CTX *mem_ctx,
        struct smbXsrv_open_global0 **_global)
{
    TDB_DATA key;
    uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
    struct db_record *global_rec = NULL;
    bool is_free = false;

    *_global = NULL;

    if (table->global.db_ctx == NULL) {
        return NT_STATUS_INTERNAL_ERROR;
    }

    key = smbXsrv_open_global_id_to_key(open_global_id, key_buf);

    global_rec = dbwrap_fetch_locked(table->global.db_ctx, mem_ctx, key);
    if (global_rec == NULL) {
        DEBUG(0, ("smbXsrv_open_global_lookup(0x%08x): "
                  "Failed to lock global key '%s'\n",
                  open_global_id,
                  hex_encode_talloc(talloc_tos(), key.dptr,
                                    key.dsize)));
        return NT_STATUS_INTERNAL_DB_ERROR;
    }

    smbXsrv_open_global_verify_record(global_rec,
                                      &is_free,
                                      NULL,
                                      mem_ctx,
                                      _global);
    if (is_free) {
        talloc_free(global_rec);
        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
    }

    (*_global)->db_rec = talloc_move(*_global, &global_rec);

    talloc_set_destructor(*_global, smbXsrv_open_global_destructor);

    return NT_STATUS_OK;
}
Beispiel #13
0
/*****************************************************************************
 * Cache_Create
 *****************************************************************************/
Cache* 
Cache_Create (void* talloc_context, size_t size, time_t max_age,
	      Cache_FreeExpiredData free_expired_data)
{
	if (size < 1) {
		Log_Printf (LOG_ERROR, "Cache: invalid size : %ld\n", 
			    (long) size);
		return NULL; // ---------->
	}
	Cache* cache = talloc (talloc_context, Cache);
	if (cache == NULL)
		return NULL; // ---------->
	*cache = (Cache) { 
		.size    	   = size,
		.max_age 	   = max_age,
		.next_clean	   = 0,
		.free_expired_data = free_expired_data,
		// other data initialized to 0
	};  
#if CACHE_FIXED_SIZE
	cache->table = talloc_array (cache, Entry, size);
	if (cache->table) {
		int i;
		for (i = 0; i < size; i++)
			cache->table[i] = (Entry) { 
				.key  = NULL, 
				.rip  = 0,
				.data = NULL
			};
	}
#else
	cache->table = hash_initialize (size, NULL,
					cache_hasher, cache_comparator,
					NULL);
#endif
	if (cache->table == NULL) {
		Log_Printf (LOG_ERROR, "Cache: can't create table");
		talloc_free (cache);
		return NULL; // ---------->
	}
	
	talloc_set_destructor (cache, cache_destroy);
	return cache;
}
Beispiel #14
0
static int cli_credentials_shallow_ccache(struct cli_credentials *cred)
{
	krb5_error_code ret;
	const struct ccache_container *old_ccc = NULL;
	struct ccache_container *ccc = NULL;
	char *ccache_name = NULL;

	old_ccc = cred->ccache;
	if (old_ccc == NULL) {
		return 0;
	}

	ccc = talloc(cred, struct ccache_container);
	if (ccc == NULL) {
		return ENOMEM;
	}
	*ccc = *old_ccc;
	ccc->ccache = NULL;

	ccache_name = talloc_asprintf(ccc, "MEMORY:%p", ccc);

	ret = krb5_cc_resolve(ccc->smb_krb5_context->krb5_context,
			      ccache_name, &ccc->ccache);
	if (ret != 0) {
		TALLOC_FREE(ccc);
		return ret;
	}

	talloc_set_destructor(ccc, free_mccache);

	TALLOC_FREE(ccache_name);

	ret = smb_krb5_cc_copy_creds(ccc->smb_krb5_context->krb5_context,
				     old_ccc->ccache, ccc->ccache);
	if (ret != 0) {
		TALLOC_FREE(ccc);
		return ret;
	}

	cred->ccache = ccc;
	cred->client_gss_creds = NULL;
	cred->client_gss_creds_obtained = CRED_UNINITIALISED;
	return ret;
}
/*************************************************************************
 *
 *	Function: sql_socket_init
 *
 *	Purpose: Establish connection to the db
 *
 *************************************************************************/
static int sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config) {

	rlm_sql_oracle_conn_t *conn;

	MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_oracle_conn_t));
	talloc_set_destructor((void *) conn, sql_socket_destructor);

	if (OCIEnvCreate(&conn->env, OCI_DEFAULT|OCI_THREADED, (dvoid *)0,
		(dvoid * (*)(dvoid *, size_t)) 0,
		(dvoid * (*)(dvoid *, dvoid *, size_t))0,
		(void (*)(dvoid *, dvoid *)) 0,
		0, (dvoid **)0 )) {
		radlog(L_ERR,"rlm_sql_oracle: Couldn't init Oracle OCI environment (OCIEnvCreate())");
		return -1;
	}

	if (OCIHandleAlloc((dvoid *) conn->env, (dvoid **) &conn->errHandle,
		(ub4) OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0))
	{
		radlog(L_ERR,"rlm_sql_oracle: Couldn't init Oracle ERROR handle (OCIHandleAlloc())");
		return -1;
	}

	/* Allocate handles for select and update queries */
	if (OCIHandleAlloc((dvoid *)conn->env, (dvoid **) &conn->queryHandle,
				(ub4)OCI_HTYPE_STMT, (CONST size_t) 0, (dvoid **) 0))
	{
		radlog(L_ERR,"rlm_sql_oracle: Couldn't init Oracle query handles: %s",
			sql_error(handle, config));
		return -1;
	}


	if (OCILogon(conn->env, conn->errHandle, &conn->ctx,
			config->sql_login, strlen(config->sql_login),
			config->sql_password,  strlen(config->sql_password),
			config->sql_db, strlen(config->sql_db)))
	{
		radlog(L_ERR,"rlm_sql_oracle: Oracle logon failed: '%s'", sql_error(handle, config));
		return -1;
	}

	return 0;
}
Beispiel #16
0
/*
  composite session setup function that hides the details of all the
  different session setup varients, including the multi-pass nature of
  the spnego varient
*/
struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *session, 
						       struct smb_composite_sesssetup *io)
{
	struct composite_context *c;
	struct sesssetup_state *state;
	NTSTATUS status;

	c = composite_create(session, session->transport->ev);
	if (c == NULL) return NULL;

	state = talloc_zero(c, struct sesssetup_state);
	if (composite_nomem(state, c)) return c;
	c->private_data = state;

	state->io = io;

	talloc_set_destructor(state, sesssetup_state_destructor);

	/* no session setup at all in earliest protocol varients */
	if (session->transport->negotiate.protocol < PROTOCOL_LANMAN1) {
		ZERO_STRUCT(io->out);
		composite_done(c);
		return c;
	}

	/* see what session setup interface we will use */
	if (session->transport->negotiate.protocol < PROTOCOL_NT1) {
		status = session_setup_old(c, session, io, &state->req);
	} else if (!session->transport->options.use_spnego ||
		   !(io->in.capabilities & CAP_EXTENDED_SECURITY)) {
		status = session_setup_nt1(c, session, io, &state->req);
	} else {
		status = session_setup_spnego(c, session, io, &state->req);
	}

	if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) || 
	    NT_STATUS_IS_OK(status)) {
		composite_continue_smb(c, state->req, request_handler, c);	
		return c;
	}

	composite_error(c, status);
	return c;
}
int cli_credentials_set_client_gss_creds(struct cli_credentials *cred, 
					 gss_cred_id_t gssapi_cred,
					 enum credentials_obtained obtained) 
{
	int ret;
	OM_uint32 maj_stat, min_stat;
	struct ccache_container *ccc;
	struct gssapi_creds_container *gcc;
	if (cred->client_gss_creds_obtained > obtained) {
		return 0;
	}

	gcc = talloc(cred, struct gssapi_creds_container);
	if (!gcc) {
		return ENOMEM;
	}

	ret = cli_credentials_new_ccache(cred, &ccc);
	if (ret != 0) {
		return ret;
	}

	maj_stat = gss_krb5_copy_ccache(&min_stat, 
					gssapi_cred, ccc->ccache);
	if (maj_stat) {
		if (min_stat) {
			ret = min_stat;
		} else {
			ret = EINVAL;
		}
	}

	if (ret == 0) {
		ret = cli_credentials_set_from_ccache(cred, obtained);
	}
	if (ret == 0) {
		gcc->creds = gssapi_cred;
		talloc_set_destructor(gcc, free_gssapi_creds);
		
		cred->client_gss_creds_obtained = obtained;
		cred->client_gss_creds = gcc;
	}
	return ret;
}
Beispiel #18
0
/*
  Private function called by "standard" backend fallback.
  Note this only allows fallback to "poll" backend, not "poll-mt".
*/
_PRIVATE_ void tevent_poll_event_add_fd_internal(struct tevent_context *ev,
						 struct tevent_fd *fde)
{
	struct poll_event_context *poll_ev = talloc_get_type_abort(
		ev->additional_data, struct poll_event_context);
	struct tevent_fd **listp;

	if (fde->flags != 0) {
		listp = &poll_ev->fresh;
	} else {
		listp = &poll_ev->disabled;
	}

	fde->additional_flags	= UINT64_MAX;
	fde->additional_data	= listp;

	DLIST_ADD((*listp), fde);
	talloc_set_destructor(fde, poll_event_fd_destructor);
}
Beispiel #19
0
static int poll_event_context_init_mt(struct tevent_context *ev)
{
	struct poll_event_context *poll_ev;
	struct pollfd *pfd;
	int fds[2];
	int ret;

	ret = poll_event_context_init(ev);
	if (ret == -1) {
		return ret;
	}

	poll_ev = talloc_get_type_abort(
		ev->additional_data, struct poll_event_context);

	poll_ev->fds = talloc_zero(poll_ev, struct pollfd);
	if (poll_ev->fds == NULL) {
		return -1;
	}

	ret = pipe(fds);
	if (ret == -1) {
		return -1;
	}

	if (!set_nonblock(fds[0]) || !set_nonblock(fds[1])) {
		close(fds[0]);
		close(fds[1]);
		return -1;
	}

	poll_ev->signal_fd = fds[1];

	pfd = &poll_ev->fds[0];
	pfd->fd = fds[0];
	pfd->events = (POLLIN|POLLHUP);

	poll_ev->num_fds = 1;

	talloc_set_destructor(poll_ev, poll_event_context_destructor);

	return 0;
}
Beispiel #20
0
struct ipmi *ipmi_open(void *ctx)
{
	struct ipmi *ipmi;
	int fd;

	fd = open(ipmi_devnode, O_RDWR);
	if (fd < 0) {
		pb_log("IPMI: can't open IPMI device %s: %m\n", ipmi_devnode);
		return NULL;
	}

	ipmi = talloc(ctx, struct ipmi);
	ipmi->fd = fd;
	ipmi->seq = 0;

	talloc_set_destructor(ipmi, ipmi_destroy);

	return ipmi;
}
/** Create a new rlm_cache_memcached instance
 *
 * @param conf memcached specific conf section.
 * @param inst main rlm_cache instance.
 * @return 0 on success, -1 on failure.
 */
static int mod_instantiate(CONF_SECTION *conf, rlm_cache_t *inst)
{
	rlm_cache_memcached_t *driver;
	memcached_return_t ret;

	char buffer[256];

	static bool version_done;

	buffer[0] = '\0';

	/*
	 *	Get version info from the libmemcached API.
	 */
	if (!version_done) {
		version_done = true;

		INFO("rlm_cache_memcached: libmemcached version: %s", memcached_lib_version());
	}

	driver = talloc_zero(inst, rlm_cache_memcached_t);
	talloc_set_destructor(driver, _mod_detach);

	if (cf_section_parse(conf, driver, driver_config) < 0) return -1;

	ret = libmemcached_check_configuration(driver->options, talloc_array_length(driver->options) -1,
					       buffer, sizeof(buffer));
	if (ret != MEMCACHED_SUCCESS) {
		ERROR("rlm_cache_memcached: Failed validating options string: %s", buffer);
		return -1;
	}

	inst->driver = driver;

	snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", inst->name);

	driver->pool = fr_connection_pool_module_init(conf, inst, mod_conn_create, NULL, buffer);
	if (!driver->pool) return -1;

	if (inst->max_entries > 0) WARN("rlm_cache_memcached: max_entries is not supported by this driver");

	return 0;
}
Beispiel #22
0
/*
 Init the port fd
*/
static int port_init_ctx(struct port_event_context *port_ev)
{
	port_ev->port_fd = port_create();
	if (port_ev->port_fd == -1) {
		tevent_debug(port_ev->ev, TEVENT_DEBUG_FATAL,
			     "Failed to create port handle.\n");
		return -1;
	}

	if (!ev_set_close_on_exec(port_ev->port_fd)) {
		tevent_debug(port_ev->ev, TEVENT_DEBUG_WARNING,
			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
	}

	port_ev->pid = getpid();
	talloc_set_destructor(port_ev, port_ctx_destructor);

	return 0;
}
Beispiel #23
0
struct DBusConnection *
test_dbus_setup_mock(TALLOC_CTX *mem_ctx,
                     struct tevent_context *loop,
                     sbus_server_conn_init_fn init_fn,
                     void *init_pvt_data)
{
    struct mock_server *mock;
    char dummy;

    mock = talloc_zero(mem_ctx, struct mock_server);
    talloc_set_destructor(mock, mock_server_cleanup);
    mock->init_fn = init_fn;
    mock->init_pvt_data = init_pvt_data;

    mock->temp_dir = mkdtemp(talloc_strdup(mock, "/tmp/sssd-dbus-tests.XXXXXX"));
    verify_neq (mock->temp_dir, NULL);
    mock->dbus_address = talloc_asprintf(mock, "unix:path=%s/sbus", mock->temp_dir);
    verify_neq (mock->dbus_address, NULL);

    /* We use an fd pair as a synchronization device, integrates with tevent well */
    verify_eq (socketpair(PF_LOCAL, SOCK_STREAM, 0, mock->sync_fds), 0);

    /* Run the dbus server in a child process */
    mock->pid = fork();
    if (mock->pid == 0) {
        mock_server_child(mock);
        _exit(0);
    }

    verify_neq (mock->pid, -1);

    /* Synchronization point: wait for sync point in mock_server_child */
    verify_eq (read(mock->sync_fds[0], &dummy, 1), 1);

    /* Open a shared D-BUS connection to the address */
    mock->client = dbus_connection_open_private(mock->dbus_address, NULL);
    verify_neq (mock->client, NULL);

    /* Synchronization point: wait for sync point in on_accept_connection */
    verify_eq (read(mock->sync_fds[0], &dummy, 1), 1);

    return mock->client;
}
Beispiel #24
0
static struct dbwrap_lock_order_state *dbwrap_check_lock_order(
	struct db_context *db, TALLOC_CTX *mem_ctx)
{
	int idx;
	static struct db_context *locked_dbs[DBWRAP_LOCK_ORDER_MAX];
	struct dbwrap_lock_order_state *state = NULL;

	if (!DBWRAP_LOCK_ORDER_VALID(db->lock_order)) {
		DEBUG(0,("Invalid lock order %d of %s\n",
			 (int)db->lock_order, db->name));
		smb_panic("invalid lock_order\n");
		return NULL;
	}

	DEBUG(5, ("check lock order %d for %s\n",
		  (int)db->lock_order, db->name));


	for (idx=db->lock_order - 1; idx < DBWRAP_LOCK_ORDER_MAX; idx++) {
		if (locked_dbs[idx] != NULL) {
			DEBUG(0, ("Lock order violation: Trying %s at %d while %s at %d is locked\n",
				  db->name, (int)db->lock_order, locked_dbs[idx]->name, idx + 1));
			debug_lock_order(0, locked_dbs);
			smb_panic("invalid lock_order");
			return NULL;
		}
	}

	state = talloc(mem_ctx, struct dbwrap_lock_order_state);
	if (state == NULL) {
		DEBUG(1, ("talloc failed\n"));
		return NULL;
	}
	state->db = db;
	state->locked_dbs = locked_dbs;
	talloc_set_destructor(state, dbwrap_lock_order_state_destructor);

	locked_dbs[db->lock_order - 1] = db;

	debug_lock_order(10, locked_dbs);

	return state;
}
/*************************************************************************
 *
 *	Function: sql_socket_init
 *
 *	Purpose: Establish connection to the db
 *
 *************************************************************************/
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config) {

	rlm_sql_iodbc_conn_t *conn;
	SQLRETURN rcode;

	MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_iodbc_conn_t));
	talloc_set_destructor((void *) conn, sql_socket_destructor);

	rcode = SQLAllocEnv(&conn->env_handle);
	if (!SQL_SUCCEEDED(rcode)) {
		ERROR("sql_create_socket: SQLAllocEnv failed:  %s",
				sql_error(handle, config));
		return -1;
	}

	rcode = SQLAllocConnect(conn->env_handle,
				&conn->dbc_handle);
	if (!SQL_SUCCEEDED(rcode)) {
		ERROR("sql_create_socket: SQLAllocConnect failed:  %s",
				sql_error(handle, config));
		return -1;
	}

	/*
	 *	The iodbc API doesn't qualify arguments as const even when they should be.
	 */
	{
		SQLCHAR *server, *login, *password;

		memcpy(&server, &config->sql_server, sizeof(server));
		memcpy(&login, &config->sql_login, sizeof(login));
		memcpy(&password, &config->sql_password, sizeof(password));

		rcode = SQLConnect(conn->dbc_handle, server, SQL_NTS, login, SQL_NTS, password, SQL_NTS);
	}
	if (!SQL_SUCCEEDED(rcode)) {
		ERROR("sql_create_socket: SQLConnectfailed:  %s",
				sql_error(handle, config));
		return -1;
	}

	return 0;
}
Beispiel #26
0
/*
 init the epoll fd
*/
static int epoll_init_ctx(struct epoll_event_context *epoll_ev)
{
	epoll_ev->epoll_fd = epoll_create(64);
	if (epoll_ev->epoll_fd == -1) {
		tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL,
			     "Failed to create epoll handle.\n");
		return -1;
	}

	if (!ev_set_close_on_exec(epoll_ev->epoll_fd)) {
		tevent_debug(epoll_ev->ev, TEVENT_DEBUG_WARNING,
			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
	}

	epoll_ev->pid = getpid();
	talloc_set_destructor(epoll_ev, epoll_ctx_destructor);

	return 0;
}
Beispiel #27
0
/*
 *	Add opaque data (with a "free" function) to a REQUEST.
 *
 *	The unique ptr is meant to be a module configuration,
 *	and the unique integer allows the caller to have multiple
 *	opaque data associated with a REQUEST.
 */
int request_data_add(REQUEST *request,
		     void *unique_ptr, int unique_int,
		     void *opaque, void (*free_opaque)(void *))
{
	request_data_t *this, **last, *next;

	/*
	 *	Some simple sanity checks.
	 */
	if (!request || !opaque) return -1;

	this = next = NULL;
	for (last = &(request->data); *last != NULL; last = &((*last)->next)) {
		if (((*last)->unique_ptr == unique_ptr) &&
		    ((*last)->unique_int == unique_int)) {
			this = *last;

			next = this->next;

			if (this->opaque && /* free it, if necessary */
			    this->free_opaque) {
				this->free_opaque(this->opaque);
			}
			break;	/* replace the existing entry */
		}
	}

	if (!this) this = talloc_zero(request, request_data_t);

	this->next = next;
	this->unique_ptr = unique_ptr;
	this->unique_int = unique_int;
	this->opaque = opaque;

	if (free_opaque) {
		this->free_opaque = free_opaque;
		talloc_set_destructor((void *) this, request_data_free_opaque);
	}

	*last = this;

	return 0;
}
Beispiel #28
0
/*
  Open up the notify.tdb database. You should close it down using
  talloc_free(). We need the messaging_ctx to allow for notifications
  via internal messages
*/
struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
				   struct messaging_context *messaging_ctx,
				   struct event_context *ev,
				   connection_struct *conn)
{
	struct notify_context *notify;

	if (!lp_change_notify(conn->params)) {
		return NULL;
	}

	notify = talloc(mem_ctx, struct notify_context);
	if (notify == NULL) {
		return NULL;
	}

	notify->db = db_open(notify, lock_path("notify.tdb"),
				  0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
				  O_RDWR|O_CREAT, 0644);
	if (notify->db == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->server = server;
	notify->messaging_ctx = messaging_ctx;
	notify->list = NULL;
	notify->array = NULL;
	notify->seqnum = notify->db->get_seqnum(notify->db);
	notify->key = string_term_tdb_data(NOTIFY_KEY);

	talloc_set_destructor(notify, notify_destructor);

	/* register with the messaging subsystem for the notify
	   message type */
	messaging_register(notify->messaging_ctx, notify, 
			   MSG_PVFS_NOTIFY, notify_handler);

	notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);

	return notify;
}
int cli_credentials_get_client_gss_creds(struct cli_credentials *cred, 
					 struct gssapi_creds_container **_gcc) 
{
	int ret = 0;
	OM_uint32 maj_stat, min_stat;
	struct gssapi_creds_container *gcc;
	struct ccache_container *ccache;
	if (cred->client_gss_creds_obtained >= (MAX(cred->ccache_obtained, 
					     MAX(cred->principal_obtained, 
						 cred->username_obtained)))) {
		*_gcc = cred->client_gss_creds;
		return 0;
	}
	ret = cli_credentials_get_ccache(cred, 
					 &ccache);
	if (ret) {
		DEBUG(1, ("Failed to get CCACHE for GSSAPI client: %s\n", error_message(ret)));
		return ret;
	}

	gcc = talloc(cred, struct gssapi_creds_container);
	if (!gcc) {
		return ENOMEM;
	}

	maj_stat = gss_krb5_import_cred(&min_stat, ccache->ccache, NULL, NULL, 
					&gcc->creds);
	if (maj_stat) {
		if (min_stat) {
			ret = min_stat;
		} else {
			ret = EINVAL;
		}
	}
	if (ret == 0) {
		cred->client_gss_creds_obtained = cred->ccache_obtained;
		talloc_set_destructor(gcc, free_gssapi_creds);
		cred->client_gss_creds = gcc;
		*_gcc = gcc;
	}
	return ret;
}
Beispiel #30
0
static NTSTATUS smbd_smb2_session_setup(struct smbd_smb2_request *smb2req,
					uint64_t in_session_id,
					uint8_t in_security_mode,
					DATA_BLOB in_security_buffer,
					uint16_t *out_session_flags,
					DATA_BLOB *out_security_buffer,
					uint64_t *out_session_id)
{
	struct smbd_smb2_session *session;

	*out_session_flags = 0;
	*out_session_id = 0;

	if (in_session_id == 0) {
		int id;

		/* create a new session */
		session = talloc_zero(smb2req->sconn, struct smbd_smb2_session);
		if (session == NULL) {
			return NT_STATUS_NO_MEMORY;
		}
		session->status = NT_STATUS_MORE_PROCESSING_REQUIRED;
		id = idr_get_new_random(smb2req->sconn->smb2.sessions.idtree,
					session,
					smb2req->sconn->smb2.sessions.limit);
		if (id == -1) {
			return NT_STATUS_INSUFFICIENT_RESOURCES;
		}
		session->vuid = id;

		session->tcons.idtree = idr_init(session);
		if (session->tcons.idtree == NULL) {
			return NT_STATUS_NO_MEMORY;
		}
		session->tcons.limit = 0x0000FFFE;
		session->tcons.list = NULL;

		DLIST_ADD_END(smb2req->sconn->smb2.sessions.list, session,
			      struct smbd_smb2_session *);
		session->sconn = smb2req->sconn;
		talloc_set_destructor(session, smbd_smb2_session_destructor);
	} else {