/* wrapped connection to a tdb database to close just talloc_free() the tdb_wrap pointer */ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode) { struct tdb_wrap *result; struct tdb_wrap_private *w; if (name == NULL) { errno = EINVAL; return NULL; } result = talloc(mem_ctx, struct tdb_wrap); if (result == NULL) { return NULL; } for (w=tdb_list;w;w=w->next) { if (strcmp(name, w->name) == 0) { break; } } if (w == NULL) { if (tdb_flags & TDB_MUTEX_LOCKING) { if (!tdb_runtime_check_for_robust_mutexes()) { tdb_flags &= ~TDB_MUTEX_LOCKING; } } w = tdb_wrap_private_open(result, name, hash_size, tdb_flags, open_flags, mode); } else { /* * Correctly use talloc_reference: The tdb will be * closed when "w" is being freed. The caller never * sees "w", so an incorrect use of talloc_free(w) * instead of calling talloc_unlink is not possible. * To avoid having to refcount ourselves, "w" will * have multiple parents that hang off all the * tdb_wrap's being returned from here. Those parents * can be freed without problem. */ if (talloc_reference(result, w) == NULL) { goto fail; } } if (w == NULL) { goto fail; } result->tdb = w->tdb; return result; fail: TALLOC_FREE(result); return NULL; }
/* wrapped connection to a tdb database to close just talloc_free() the tdb_wrap pointer */ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode, struct loadparm_context *lp_ctx) { struct tdb_wrap *result; struct tdb_wrap_private *w; /* If they specify a .ntdb extension, but the code hasn't been * converted, we want to complain. */ if (name && strends(name, ".ntdb")) { DEBUG(2, ("tdb(%s): This code does not yet understand ntdb. Please report.\n", name)); return NULL; } result = talloc(mem_ctx, struct tdb_wrap); if (result == NULL) { return NULL; } for (w=tdb_list;w;w=w->next) { if (strcmp(name, w->name) == 0) { break; } } if (w == NULL) { w = tdb_wrap_private_open(result, name, hash_size, tdb_flags, open_flags, mode, lp_ctx); } else { /* * Correctly use talloc_reference: The tdb will be * closed when "w" is being freed. The caller never * sees "w", so an incorrect use of talloc_free(w) * instead of calling talloc_unlink is not possible. * To avoid having to refcount ourselves, "w" will * have multiple parents that hang off all the * tdb_wrap's being returned from here. Those parents * can be freed without problem. */ if (talloc_reference(result, w) == NULL) { goto fail; } } if (w == NULL) { goto fail; } result->tdb = w->tdb; return result; fail: TALLOC_FREE(result); return NULL; }