static bool test_lifeless(const struct torture_context *ctx)
{
	void *top = talloc_new(ctx);
	char *parent, *child; 
	void *child_owner = talloc_new(ctx);

	parent = talloc_strdup(top, "parent");
	if (!parent)
		return false;
	child = talloc_strdup(parent, "child");  
	if (!child) {
		talloc_free(parent);
		return false;
	}
	if (!talloc_reference(child, parent)) {
		talloc_free(parent);
		return false;
	}

	if (!talloc_reference(child_owner, child)) {
		talloc_unlink(child, parent);
		talloc_free(parent);
		return false;
	}

	talloc_unlink(top, parent);
	talloc_free(child);
	talloc_free(top);
	talloc_free(child_owner);
	talloc_free(child);

	return true;
}
/*
 * Get number of childs of actual Folder
 */
int GetMaildirChildCount(struct EasyLinuxFolder *elFolder, uint32_t table_type)
{
int Val=0;
DIR *dDir;
char *sDir;
struct dirent *dEntry;


switch( table_type )
  {
  case 2:   // MAPISTORE_MESSAGE_TABLE
    // Find Messages in cur & new
    sDir = talloc_asprintf(elFolder->elContext->mem_ctx, "%scur", elFolder->FullPath);
    dDir = opendir(sDir);
    while ((dEntry = readdir(dDir))) 
      {
      if ( dEntry->d_type == isFile)
        {
        Val++;
        }
      }
    closedir(dDir);
    talloc_unlink(elFolder->elContext->mem_ctx, sDir);
    sDir = talloc_asprintf(elFolder->elContext->mem_ctx, "%snew", elFolder->FullPath);
    dDir = opendir(sDir);
    while ((dEntry = readdir(dDir))) 
      {
      if ( dEntry->d_type == isFile)
        {
        Val++;
        }
      }
    closedir(dDir);
    DEBUG(0,("MAPIEasyLinux :      Find %i Messages in %s\n",Val,elFolder->FullPath)); 
    talloc_unlink(elFolder->elContext->mem_ctx, sDir);
    break;
    
  case 3:   // MAPISTORE_FAI_TABLE
    DEBUG(0,("MAPIEasyLinux :    Ask for GetMaildirChildCount\n"));
    break;
    
  case 1:   // MAPISTORE_FOLDER_TABLE
    dDir = opendir(elFolder->FullPath);
    while ((dEntry = readdir(dDir))) 
      {
      if ( dEntry->d_type == isDir)
        Val += OmmitSpecialFolder(elFolder,dEntry->d_name);
      }
    closedir(dDir);
    DEBUG(0,("MAPIEasyLinux :      Find %i Folders in %s\n",Val,elFolder->FullPath)); 
    break;
  }  
return Val;
}
Exemple #3
0
NTSTATUS auth_ntlmssp_client_prepare(TALLOC_CTX *mem_ctx, struct auth_generic_state **auth_ntlmssp_state)
{
	struct auth_generic_state *ans;
	NTSTATUS nt_status;

	struct gensec_settings *gensec_settings;
	struct loadparm_context *lp_ctx;

	ans = talloc_zero(mem_ctx, struct auth_generic_state);
	if (!ans) {
		DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	lp_ctx = loadparm_init_s3(ans, loadparm_s3_context());
	if (lp_ctx == NULL) {
		DEBUG(10, ("loadparm_init_s3 failed\n"));
		TALLOC_FREE(ans);
		return NT_STATUS_INVALID_SERVER_STATE;
	}
	
	gensec_settings = lpcfg_gensec_settings(ans, lp_ctx);
	if (lp_ctx == NULL) {
		DEBUG(10, ("lpcfg_gensec_settings failed\n"));
		TALLOC_FREE(ans);
		return NT_STATUS_NO_MEMORY;
	}
	
	nt_status = gensec_client_start(ans, &ans->gensec_security, gensec_settings);
	
	if (!NT_STATUS_IS_OK(nt_status)) {
		TALLOC_FREE(ans);
		return nt_status;
	}

	ans->credentials = cli_credentials_init(ans);
	if (!ans->credentials) {
		TALLOC_FREE(ans);
		return NT_STATUS_NO_MEMORY;
	}

	cli_credentials_guess(ans->credentials, lp_ctx);

	talloc_unlink(ans, lp_ctx);
	talloc_unlink(ans, gensec_settings);

	*auth_ntlmssp_state = ans;
	return NT_STATUS_OK;
}
Exemple #4
0
static PyObject *py_dsdb_get_wellknown_dn(PyObject *self, PyObject *args)
{
	struct ldb_context *ldb;
	struct ldb_dn *nc_dn, *wk_dn;
	char *wkguid;
	PyObject *py_ldb, *py_nc_dn, *py_wk_dn;
	int ret;

	if (!PyArg_ParseTuple(args, "OOs", &py_ldb, &py_nc_dn, &wkguid))
		return NULL;

	PyErr_LDB_OR_RAISE(py_ldb, ldb);
	PyErr_LDB_DN_OR_RAISE(py_nc_dn, nc_dn);

	ret = dsdb_wellknown_dn(ldb, ldb, nc_dn, wkguid, &wk_dn);
	if (ret == LDB_ERR_NO_SUCH_OBJECT) {
		PyErr_Format(PyExc_KeyError, "Failed to find well known DN for GUID %s", wkguid);
		return NULL;
	}

	PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);

	py_wk_dn = pyldb_Dn_FromDn(wk_dn);
	talloc_unlink(ldb, wk_dn);
	return py_wk_dn;
}
Exemple #5
0
bool serverid_parent_init(TALLOC_CTX *mem_ctx)
{
	struct tdb_wrap *db;
	struct loadparm_context *lp_ctx;

	lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context());
	if (lp_ctx == NULL) {
		DEBUG(0, ("loadparm_init_s3 failed\n"));
		return false;
	}

	/*
	 * Open the tdb in the parent process (smbd) so that our
	 * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
	 * work.
	 */

	db = tdb_wrap_open(mem_ctx, lock_path("serverid.tdb"),
			   0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT,
			   0644, lp_ctx);
	talloc_unlink(mem_ctx, lp_ctx);
	if (db == NULL) {
		DEBUG(1, ("could not open serverid.tdb: %s\n",
			  strerror(errno)));
		return false;
	}
	return true;
}
Exemple #6
0
struct imessaging_context *winbind_imessaging_context(void)
{
	static struct imessaging_context *msg = NULL;
	struct loadparm_context *lp_ctx;

	if (msg != NULL) {
		return msg;
	}

	lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
	if (lp_ctx == NULL) {
		smb_panic("Could not load smb.conf to init winbindd's imessaging context.\n");
	}

	/*
	 * Note we MUST use the NULL context here, not the autofree context,
	 * to avoid side effects in forked children exiting.
	 */
	msg = imessaging_init(NULL, lp_ctx, procid_self(), winbind_event_context(), false);
	talloc_unlink(NULL, lp_ctx);

	if (msg == NULL) {
		smb_panic("Could not init winbindd's messaging context.\n");
	}
	return msg;
}
Exemple #7
0
static bool posix_eadb_init(int snum, struct tdb_wrap **p_db)
{
	struct tdb_wrap *db;
	struct loadparm_context *lp_ctx;
	const char *eadb = lp_parm_const_string(snum, "posix", "eadb", NULL);

	if (!eadb) {
		DEBUG(0, ("Can not use vfs_posix_eadb without posix:eadb set\n"));
		return false;
	}

	lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());

	become_root();
	db = tdb_wrap_open(NULL, eadb, 50000,
			   TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
			   lp_ctx);

	unbecome_root();
	talloc_unlink(NULL, lp_ctx);
	/* now we know dbname is not NULL */

	if (db == NULL) {
#if defined(ENOTSUP)
		errno = ENOTSUP;
#else
		errno = ENOSYS;
#endif
		return false;
	}

	*p_db = db;
	return true;
}
Exemple #8
0
_PUBLIC_ int emsmdbp_source_key_from_fmid(TALLOC_CTX *mem_ctx, struct emsmdbp_context *emsmdbp_ctx, const char *username, uint64_t fmid, struct Binary_r **source_keyP)
{
	struct Binary_r	*source_key;
	uint64_t	gc;
	uint16_t	replid;
	uint8_t		*bytes;
	int		i;

	replid = fmid & 0xffff;
	source_key = talloc_zero(NULL, struct Binary_r);
	source_key->cb = 22;
	source_key->lpb = talloc_array(source_key, uint8_t, source_key->cb);
	if (emsmdbp_replid_to_guid(emsmdbp_ctx, username, replid, (struct GUID *) source_key->lpb)) {
		talloc_free(source_key);
		return MAPISTORE_ERROR;
	}

	(void) talloc_reference(mem_ctx, source_key);
	talloc_unlink(NULL, source_key);

	gc = fmid >> 16;

	bytes = source_key->lpb + 16;
	for (i = 0; i < 6; i++) {
		bytes[i] = gc & 0xff;
		gc >>= 8;
	}

	*source_keyP = source_key;

	return MAPISTORE_SUCCESS;
}
Exemple #9
0
/**
 * Make this ldb use a specified schema, already fully calculated and belonging to another ldb
 */
int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema,
			  bool write_attributes)
{
	int ret;
	struct dsdb_schema *old_schema;
	old_schema = ldb_get_opaque(ldb, "dsdb_schema");
	ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
	if (ret != LDB_SUCCESS) {
		return ret;
	}

	/* Remove the reference to the schema we just overwrote - if there was
	 * none, NULL is harmless here */
	talloc_unlink(ldb, old_schema);

	if (talloc_reference(ldb, schema) == NULL) {
		return ldb_oom(ldb);
	}

	/* Make this ldb use local schema preferably */
	ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", NULL);
	if (ret != LDB_SUCCESS) {
		return ret;
	}

	ret = dsdb_schema_set_attributes(ldb, schema, write_attributes);
	if (ret != LDB_SUCCESS) {
		return ret;
	}

	return LDB_SUCCESS;
}
krb5_error_code smb_krb5_context_set_event_ctx(struct smb_krb5_context *smb_krb5_context,
					       struct tevent_context *ev,
					       struct tevent_context **previous_ev)
{
	int ret;
	if (!ev) {
		return EINVAL;
	}

	*previous_ev = smb_krb5_context->current_ev;

	smb_krb5_context->current_ev = talloc_reference(smb_krb5_context, ev);
	if (!smb_krb5_context->current_ev) {
		return ENOMEM;
	}

	/* Set use of our socket lib */
	ret = krb5_set_send_to_kdc_func(smb_krb5_context->krb5_context,
					smb_krb5_send_and_recv_func,
					ev);
	if (ret) {
		TALLOC_CTX *tmp_ctx = talloc_new(NULL);
		DEBUG(1,("krb5_set_send_recv_func failed (%s)\n",
			 smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, tmp_ctx)));
		talloc_free(tmp_ctx);
		talloc_unlink(smb_krb5_context, smb_krb5_context->current_ev);
		smb_krb5_context->current_ev = NULL;
		return ret;
	}
	return 0;
}
Exemple #11
0
/*
  establish a new connection to the web server
*/
static void websrv_accept(struct stream_connection *conn)
{
    struct web_server_data *wdata = talloc_get_type(conn->private_data, struct web_server_data);
    struct websrv_context *web;
    struct socket_context *tls_socket;

    web = talloc_zero(conn, struct websrv_context);
    if (web == NULL) goto failed;

    web->task = wdata->task;
    web->conn = conn;
    conn->private_data = web;
    talloc_set_destructor(web, websrv_destructor);

    event_add_timed(conn->event.ctx, web,
                    timeval_current_ofs(HTTP_TIMEOUT, 0),
                    websrv_timeout, web);

    /* Overwrite the socket with a (possibly) TLS socket */
    tls_socket = tls_init_server(wdata->tls_params, conn->socket,
                                 conn->event.fde, "GPHO");
    /* We might not have TLS, or it might not have initilised */
    if (tls_socket) {
        talloc_unlink(conn, conn->socket);
        talloc_steal(conn, tls_socket);
        conn->socket = tls_socket;
    } else {
        DEBUG(3, ("TLS not available for web_server connections\n"));
    }

    return;

failed:
    talloc_free(conn);
}
Exemple #12
0
static bool test_unref_reparent(void)
{
	void *root, *p1, *p2, *c1;

	printf("test: unref_reparent\n# UNREFERENCE AFTER PARENT FREED\n");

	root = talloc_named_const(NULL, 0, "root");
	p1 = talloc_named_const(root, 1, "orig parent");
	p2 = talloc_named_const(root, 1, "parent by reference");

	c1 = talloc_named_const(p1, 1, "child");
	talloc_reference(p2, c1);

	CHECK_PARENT("unref_reparent", c1, p1);

	talloc_free(p1);

	CHECK_PARENT("unref_reparent", c1, p2);

	talloc_unlink(p2, c1);

	CHECK_SIZE("unref_reparent", root, 1);

	talloc_free(p2);
	talloc_free(root);

	printf("success: unref_reparent\n");
	return true;
}
Exemple #13
0
/*
 * this function is called from within a ldb transaction from the schema_fsmo module
 */
WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
{
	WERROR status;
	uint32_t attid;
	TALLOC_CTX *mem_ctx;
	struct dsdb_schema_prefixmap *pfm;

	mem_ctx = talloc_new(ldb);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* Read prefixes from disk*/
	status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	/* Check if there is a prefix for the oid in the prefixes array*/
	status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
	if (W_ERROR_IS_OK(status)) {
		/* prefix found*/
		talloc_free(mem_ctx);
		return status;
	} else if (!W_ERROR_EQUAL(status, WERR_NOT_FOUND)) {
		/* error */
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	/* Create the new mapping for the prefix of full_oid */
	status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	talloc_unlink(schema, schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	/* Update prefixMap in ldb*/
	status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
		 full_oid, schema->prefixmap->length));

	talloc_free(mem_ctx);
	return status;
}
Exemple #14
0
void talloc_ref_finalizer(void *ctx, void *ptr)
{
  int res = talloc_unlink(ctx, ptr);
  if (res != 0) {
    fprintf(stderr, "Failed to unlink reference of %p on %p\n", ctx, ptr);
  }
}
Exemple #15
0
/* We have good reason to think the ccache in these credentials is invalid - blow it away */
static void cli_credentials_unconditionally_invalidate_client_gss_creds(struct cli_credentials *cred)
{
	if (cred->client_gss_creds_obtained > CRED_UNINITIALISED) {
		talloc_unlink(cred, cred->client_gss_creds);
		cred->client_gss_creds = NULL;
	}
	cred->client_gss_creds_obtained = CRED_UNINITIALISED;
}
Exemple #16
0
static void py_MAPIStoreFolder_dealloc(PyObject *_self)
{
	PyMAPIStoreFolderObject *self = (PyMAPIStoreFolderObject *)_self;

	talloc_unlink(NULL, self->folder_object);

	Py_XDECREF(self->context);
	PyObject_Del(_self);
}
Exemple #17
0
int language_set_linker(struct language *l, char *cmd)
{
    if (l->link_cmd != NULL) {
        talloc_unlink(l, l->link_cmd);
        l->link_cmd = NULL;
    }

    l->link_cmd = talloc_reference(l, cmd);
    return 0;
}
Exemple #18
0
/*
  test references 
*/
static bool test_ref1(void)
{
	void *root, *p1, *p2, *ref, *r1;

	printf("test: ref1\n# SINGLE REFERENCE FREE\n");

	root = talloc_named_const(NULL, 0, "root");
	p1 = talloc_named_const(root, 1, "p1");
	p2 = talloc_named_const(p1, 1, "p2");
	talloc_named_const(p1, 1, "x1");
	talloc_named_const(p1, 2, "x2");
	talloc_named_const(p1, 3, "x3");

	r1 = talloc_named_const(root, 1, "r1");	
	ref = talloc_reference(r1, p2);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref1", p1, 5);
	CHECK_BLOCKS("ref1", p2, 1);
	CHECK_BLOCKS("ref1", ref, 1);
	CHECK_BLOCKS("ref1", r1, 2);

	fprintf(stderr, "Freeing p2\n");
	talloc_unlink(r1, p2);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref1", p1, 5);
	CHECK_BLOCKS("ref1", p2, 1);
	CHECK_BLOCKS("ref1", r1, 1);

	fprintf(stderr, "Freeing p1\n");
	talloc_free(p1);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref1", r1, 1);

	fprintf(stderr, "Freeing r1\n");
	talloc_free(r1);
	talloc_report_full(NULL, stderr);

	fprintf(stderr, "Testing NULL\n");
	if (talloc_reference(root, NULL)) {
		return false;
	}

	CHECK_BLOCKS("ref1", root, 1);

	CHECK_SIZE("ref1", root, 0);

	talloc_free(root);
	printf("success: ref1\n");
	return true;
}
Exemple #19
0
bool notify_internal_parent_init(TALLOC_CTX *mem_ctx)
{
	struct tdb_wrap *db1, *db2;
	struct loadparm_context *lp_ctx;

	if (lp_clustering()) {
		return true;
	}

	lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context());
	if (lp_ctx == NULL) {
		DEBUG(0, ("loadparm_init_s3 failed\n"));
		return false;
	}
	/*
	 * Open the tdbs in the parent process (smbd) so that our
	 * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
	 * work.
	 */

	db1 = tdb_wrap_open(mem_ctx, lock_path("notify.tdb"),
			    0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
			    O_RDWR|O_CREAT, 0644, lp_ctx);
	if (db1 == NULL) {
		talloc_unlink(mem_ctx, lp_ctx);
		DEBUG(1, ("could not open notify.tdb: %s\n", strerror(errno)));
		return false;
	}
	db2 = tdb_wrap_open(mem_ctx, lock_path("notify_onelevel.tdb"),
			    0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644, lp_ctx);
	talloc_unlink(mem_ctx, lp_ctx);
	if (db2 == NULL) {
		DEBUG(1, ("could not open notify_onelevel.tdb: %s\n",
			  strerror(errno)));
		TALLOC_FREE(db1);
		return false;
	}
	return true;
}
Exemple #20
0
_PUBLIC_ bool emsmdbp_destructor(void *data)
{
	struct emsmdbp_context	*emsmdbp_ctx = (struct emsmdbp_context *)data;

	if (!emsmdbp_ctx) return false;

	talloc_unlink(emsmdbp_ctx, emsmdbp_ctx->oc_ctx);
	talloc_free(emsmdbp_ctx->mem_ctx);

	OC_DEBUG(0, "emsmdbp_ctx found and released\n");

	return true;
}
Exemple #21
0
_PUBLIC_ bool emsmdbp_destructor(void *data)
{
	struct emsmdbp_context	*emsmdbp_ctx = (struct emsmdbp_context *)data;

	if (!emsmdbp_ctx) return false;

	talloc_unlink(emsmdbp_ctx, emsmdbp_ctx->oc_ctx);
	talloc_free(emsmdbp_ctx->mem_ctx);

	DEBUG(0, ("[%s:%d]: emsmdbp_ctx found and released\n", __FUNCTION__, __LINE__));

	return true;
}
Exemple #22
0
/*
  test references 
*/
static bool test_ref2(void)
{
	void *root, *p1, *p2, *ref, *r1;

	printf("test: ref2\n# DOUBLE REFERENCE FREE\n");
	root = talloc_named_const(NULL, 0, "root");
	p1 = talloc_named_const(root, 1, "p1");
	talloc_named_const(p1, 1, "x1");
	talloc_named_const(p1, 1, "x2");
	talloc_named_const(p1, 1, "x3");
	p2 = talloc_named_const(p1, 1, "p2");

	r1 = talloc_named_const(root, 1, "r1");	
	ref = talloc_reference(r1, p2);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref2", p1, 5);
	CHECK_BLOCKS("ref2", p2, 1);
	CHECK_BLOCKS("ref2", r1, 2);

	fprintf(stderr, "Freeing ref\n");
	talloc_unlink(r1, ref);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref2", p1, 5);
	CHECK_BLOCKS("ref2", p2, 1);
	CHECK_BLOCKS("ref2", r1, 1);

	fprintf(stderr, "Freeing p2\n");
	talloc_free(p2);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref2", p1, 4);
	CHECK_BLOCKS("ref2", r1, 1);

	fprintf(stderr, "Freeing p1\n");
	talloc_free(p1);
	talloc_report_full(root, stderr);

	CHECK_BLOCKS("ref2", r1, 1);

	fprintf(stderr, "Freeing r1\n");
	talloc_free(r1);
	talloc_report_full(root, stderr);

	CHECK_SIZE("ref2", root, 0);

	talloc_free(root);
	printf("success: ref2\n");
	return true;
}
Exemple #23
0
static bool test_lifeless(void)
{
	void *top = talloc_new(NULL);
	char *parent, *child; 
	void *child_owner = talloc_new(NULL);

	printf("test: lifeless\n# TALLOC_UNLINK LOOP\n");

	parent = talloc_strdup(top, "parent");
	child = talloc_strdup(parent, "child");  
	(void)talloc_reference(child, parent);
	(void)talloc_reference(child_owner, child); 
	talloc_report_full(top, stderr);
	talloc_unlink(top, parent);
	talloc_unlink(top, child);
	talloc_report_full(top, stderr);
	talloc_free(top);
	talloc_free(child_owner);
	talloc_free(child);

	printf("success: lifeless\n");
	return true;
}
Exemple #24
0
struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
			       const char *name,
			       int hash_size, int tdb_flags,
			       int open_flags, mode_t mode)
{
	struct db_context *result = NULL;
	struct db_tdb_ctx *db_tdb;
	struct loadparm_context *lp_ctx;

	result = talloc_zero(mem_ctx, struct db_context);
	if (result == NULL) {
		DEBUG(0, ("talloc failed\n"));
		goto fail;
	}
	lp_ctx = loadparm_init_s3(result, loadparm_s3_context());

	result->private_data = db_tdb = talloc(result, struct db_tdb_ctx);
	if (db_tdb == NULL) {
		DEBUG(0, ("talloc failed\n"));
		goto fail;
	}

	db_tdb->wtdb = tdb_wrap_open(db_tdb, name, hash_size, tdb_flags,
				     open_flags, mode, lp_ctx);
	talloc_unlink(result, lp_ctx);
	if (db_tdb->wtdb == NULL) {
		DEBUG(3, ("Could not open tdb: %s\n", strerror(errno)));
		goto fail;
	}

	result->fetch_locked = db_tdb_fetch_locked;
	result->traverse = db_tdb_traverse;
	result->traverse_read = db_tdb_traverse_read;
	result->parse_record = db_tdb_parse;
	result->get_seqnum = db_tdb_get_seqnum;
	result->get_flags = db_tdb_get_flags;
	result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
	result->transaction_start = db_tdb_transaction_start;
	result->transaction_commit = db_tdb_transaction_commit;
	result->transaction_cancel = db_tdb_transaction_cancel;
	result->exists = db_tdb_exists;
	result->wipe = db_tdb_wipe;
	return result;

 fail:
	if (result != NULL) {
		TALLOC_FREE(result);
	}
	return NULL;
}
Exemple #25
0
/* For most predictable behaviour, this needs to be called directly after the cli_credentials_init(),
 * otherwise we may still have references to the old smb_krb5_context in a credential cache etc
 */
_PUBLIC_ NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred, 
					  struct smb_krb5_context *smb_krb5_context)
{
	if (smb_krb5_context == NULL) {
		talloc_unlink(cred, cred->smb_krb5_context);
		cred->smb_krb5_context = NULL;
		return NT_STATUS_OK;
	}

	if (!talloc_reference(cred, smb_krb5_context)) {
		return NT_STATUS_NO_MEMORY;
	}
	cred->smb_krb5_context = smb_krb5_context;
	return NT_STATUS_OK;
}
Exemple #26
0
void dsdb_make_schema_global(struct ldb_context *ldb, struct dsdb_schema *schema)
{
	if (!schema) {
		return;
	}

	if (global_schema) {
		talloc_unlink(talloc_autofree_context(), global_schema);
	}

	/* we want the schema to be around permanently */
	talloc_reparent(ldb, talloc_autofree_context(), schema);
	global_schema = schema;

	/* This calls the talloc_reference() of the global schema back onto the ldb */
	dsdb_set_global_schema(ldb);
}
Exemple #27
0
int context_set_srcdir(struct context *c, char *opt)
{
    if (c == NULL)
        return -1;
    if (opt == NULL)
        return -1;

    assert(c->src_dir != NULL);
    /* FIXME: This cast is probably bad, is the talloc API broken? */
    talloc_unlink(c, (char *)c->src_dir);
    c->src_dir = talloc_reference(c, opt);

    if (c->src_dir == NULL)
        return -1;

    return 0;
}
Exemple #28
0
/*
 * \detail Find AD to get User informations
 *
 * EasyLinux backend is heavily based on AD, Maildir is stored into homeDir of user
 * we need to get back this information
 */
int SetUserInformation(struct EasyLinuxContext *elContext, TALLOC_CTX *mem_ctx, char *User, struct ldb_context *ldb)
{
//DEBUG(3, ("MAPIEasyLinux :   Searching for user(%s) data's\n",User));
const char *expression = "(uid=%s)";
char *Search;
const char * const Attribs[] = {"unixHomeDirectory","gidNumber","uidNumber","displayName",NULL};
struct ldb_result *resultMsg;
struct ldb_message_element *MessageElement;
int i,j;

Search = talloc_asprintf(mem_ctx,expression,User);

if( LDB_SUCCESS != ldb_search(ldb, mem_ctx, &resultMsg, NULL, LDB_SCOPE_DEFAULT, Attribs, "%s", Search) )
  {
  DEBUG(0, ("ERROR - MAPIEasyLinux - user informations unavailable !\n"));
  return MAPISTORE_ERROR;
  }

elContext->User.uid = talloc_strdup(mem_ctx, User);
for (i = 0; i < resultMsg->count; ++i) 
  {
  for( j=0 ; j<resultMsg->msgs[i]->num_elements ; j++)
    {
    MessageElement = &resultMsg->msgs[i]->elements[j];
    if( strcmp(MessageElement->name,"displayName") == 0 )
      elContext->User.displayName = talloc_strdup(mem_ctx, (char *)MessageElement->values[0].data);
    if( strcmp(MessageElement->name,"uidNumber") == 0 )
      elContext->User.uidNumber = atoi( (char *)MessageElement->values[0].data) ;
    if( strcmp(MessageElement->name,"gidNumber") == 0 )
      elContext->User.gidNumber = atoi((char *)MessageElement->values[0].data);
    if( strcmp(MessageElement->name,"unixHomeDirectory") == 0 )
      elContext->User.homeDirectory = talloc_strdup(mem_ctx, (char *)MessageElement->values[0].data);
    }
  }
if( elContext->User.homeDirectory == NULL )
  {  
  DEBUG(0, ("ERROR - MAPIEasyLinux - user informations unavailable ! No homeDirectory\n"));
  return MAPISTORE_ERROR;
  }
    
DEBUG(0, ("MAPIEasyLinux :   User (uid:%i gid:%i displayName:%s homeDirectory:%s) \n", elContext->User.uidNumber, elContext->User.gidNumber, 
                                    elContext->User.displayName, elContext->User.homeDirectory));
talloc_unlink(mem_ctx, Search);
return MAPISTORE_SUCCESS;
}
Exemple #29
0
static PyObject *py_creds_get_named_ccache(PyObject *self, PyObject *args)
{
	PyObject *py_lp_ctx = Py_None;
	char *ccache_name;
	struct loadparm_context *lp_ctx;
	struct ccache_container *ccc;
	struct tevent_context *event_ctx;
	int ret;
	const char *error_string;
	struct cli_credentials *creds;
	TALLOC_CTX *mem_ctx;

	creds = PyCredentials_AsCliCredentials(self);

	if (!PyArg_ParseTuple(args, "|Os", &py_lp_ctx, &ccache_name))
		return NULL;

	mem_ctx = talloc_new(NULL);
	if (mem_ctx == NULL) {
		PyErr_NoMemory();
		return NULL;
	}

	lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
	if (lp_ctx == NULL) {
		talloc_free(mem_ctx);
		return NULL;
	}

	event_ctx = samba_tevent_context_init(mem_ctx);

	ret = cli_credentials_get_named_ccache(creds, event_ctx, lp_ctx,
					       ccache_name, &ccc, &error_string);
	talloc_unlink(mem_ctx, lp_ctx);
	if (ret == 0) {
		talloc_steal(ccc, event_ctx);
		talloc_free(mem_ctx);
		return PyCredentialCacheContainer_from_ccache_container(ccc);
	}

	PyErr_SetString(PyExc_RuntimeError, error_string?error_string:"NULL");

	talloc_free(mem_ctx);
	return NULL;
}
Exemple #30
0
void dsdb_make_schema_global(struct ldb_context *ldb)
{
	struct dsdb_schema *schema = dsdb_get_schema(ldb);
	if (!schema) {
		return;
	}

	if (global_schema) {
		talloc_unlink(talloc_autofree_context(), global_schema);
	}

	/* we want the schema to be around permanently */
	talloc_reparent(talloc_parent(schema), talloc_autofree_context(), schema);

	global_schema = schema;

	dsdb_set_global_schema(ldb);
}