/* put a packet in the send queue. When the packet is actually sent, call send_callback. Useful for operations that must occur after sending a message, such as the switch to SASL encryption after as sucessful LDAP bind relpy. */ _PUBLIC_ NTSTATUS packet_send_callback(struct packet_context *pc, DATA_BLOB blob, packet_send_callback_fn_t send_callback, void *private_data) { struct send_element *el; el = talloc(pc, struct send_element); NT_STATUS_HAVE_NO_MEMORY(el); DLIST_ADD_END(pc->send_queue, el, struct send_element *); el->blob = blob; el->nsent = 0; el->send_callback = send_callback; el->send_callback_private = private_data; /* if we aren't going to free the packet then we must reference it to ensure it doesn't disappear before going out */ if (pc->nofree) { if (!talloc_reference(el, blob.data)) { return NT_STATUS_NO_MEMORY; } } else { talloc_steal(el, blob.data); } if (private_data && !talloc_reference(el, private_data)) { return NT_STATUS_NO_MEMORY; } TEVENT_FD_WRITEABLE(pc->fde); return NT_STATUS_OK; }
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; }
struct context *context_new_defaults(struct clopts *o, void *context, struct makefile *mf, struct languagelist *ll, struct contextstack *s) { struct context *c; c = talloc(context, struct context); c->type = CONTEXT_TYPE_DEFAULTS; c->parent = NULL; c->test_parent = NULL; c->bin_dir = talloc_strdup(c, "bin"); c->lib_dir = talloc_strdup(c, "lib"); c->hdr_dir = talloc_asprintf(c, "%sinclude", o->source_path); c->obj_dir = talloc_strdup(c, "obj"); c->src_dir = talloc_asprintf(c, "%ssrc", o->source_path); c->chk_dir = talloc_strdup(c, "check"); c->tst_dir = talloc_asprintf(c, "%stest", o->source_path); c->gen_dir = talloc_strdup(c, "obj/proc"); c->prefix = talloc_strdup(c, DEFAULT_PREFIX); c->libexec_dir = talloc_strdup(c, "libexec"); c->share_dir = talloc_strdup(c, "share"); c->compile_opts = stringlist_new(c); c->link_opts = stringlist_new(c); c->shared_target = false; c->mf = talloc_reference(c, mf); c->ll = talloc_reference(c, ll); c->s = s; c->language = NULL; c->autodeps = true; return c; }
static bool test_talloc_free_in_destructor(void) { void *level0; void *level1; void *level2; void *level3; void *level4; void **level5; printf("test: free_in_destructor\n# TALLOC FREE IN DESTRUCTOR\n"); level0 = talloc_new(NULL); level1 = talloc_new(level0); level2 = talloc_new(level1); level3 = talloc_new(level2); level4 = talloc_new(level3); level5 = talloc(level4, void *); *level5 = level3; (void)talloc_reference(level0, level3); (void)talloc_reference(level3, level3); (void)talloc_reference(level5, level3); talloc_set_destructor(level5, _test_talloc_free_in_destructor); talloc_free(level1); talloc_free(level0); printf("success: free_in_destructor\n"); return true; }
/** Start the GENSEC system, returning a context pointer. @param mem_ctx The parent TALLOC memory context. @param gensec_security Returned GENSEC context pointer. @note The mem_ctx is only a parent and may be NULL. @note, the auth context is moved to be a referenced pointer of the @ gensec_security return */ static NTSTATUS gensec_start(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct gensec_settings *settings, struct auth_context *auth_context, struct gensec_security **gensec_security) { if (ev == NULL) { DEBUG(0, ("No event context available!\n")); return NT_STATUS_INTERNAL_ERROR; } (*gensec_security) = talloc_zero(mem_ctx, struct gensec_security); NT_STATUS_HAVE_NO_MEMORY(*gensec_security); (*gensec_security)->event_ctx = ev; SMB_ASSERT(settings->lp_ctx != NULL); (*gensec_security)->settings = talloc_reference(*gensec_security, settings); /* We need to reference this, not steal, as the caller may be * python, which won't like it if we steal it's object away * from it */ (*gensec_security)->auth_context = talloc_reference(*gensec_security, auth_context); return NT_STATUS_OK; }
static bool test_free_ref_null_context(void) { void *p1, *p2, *p3; int ret; talloc_disable_null_tracking(); p1 = talloc_new(NULL); p2 = talloc_new(NULL); p3 = talloc_reference(p2, p1); torture_assert("reference", p3 == p1, "failed: reference on null"); ret = talloc_free(p1); torture_assert("ref free with null parent", ret == 0, "failed: free with null parent"); talloc_free(p2); talloc_enable_null_tracking_no_autofree(); p1 = talloc_new(NULL); p2 = talloc_new(NULL); p3 = talloc_reference(p2, p1); torture_assert("reference", p3 == p1, "failed: reference on null"); ret = talloc_free(p1); torture_assert("ref free with null tracked parent", ret == 0, "failed: free with null parent"); talloc_free(p2); return true; }
/* 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; }
struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb, TALLOC_CTX *reference_ctx) { const void *p; struct dsdb_schema *schema_out; struct dsdb_schema *schema_in; bool use_global_schema; TALLOC_CTX *tmp_ctx = talloc_new(reference_ctx); if (!tmp_ctx) { return NULL; } /* see if we have a cached copy */ use_global_schema = dsdb_uses_global_schema(ldb); if (use_global_schema) { schema_in = global_schema; } else { p = ldb_get_opaque(ldb, "dsdb_schema"); schema_in = talloc_get_type(p, struct dsdb_schema); if (!schema_in) { talloc_free(tmp_ctx); return NULL; } } if (schema_in->refresh_fn && !schema_in->refresh_in_progress) { if (!talloc_reference(tmp_ctx, schema_in)) { /* * ensure that the schema_in->refresh_in_progress * remains valid for the right amount of time */ talloc_free(tmp_ctx); return NULL; } schema_in->refresh_in_progress = true; /* This may change schema, if it needs to reload it from disk */ schema_out = schema_in->refresh_fn(schema_in->loaded_from_module, schema_in, use_global_schema); schema_in->refresh_in_progress = false; } else { schema_out = schema_in; } /* This removes the extra reference above */ talloc_free(tmp_ctx); if (!reference_ctx) { return schema_out; } else { return talloc_reference(reference_ctx, schema_out); } }
/** * Create a sub torture context */ struct torture_context *torture_context_child(struct torture_context *parent) { struct torture_context *subtorture = talloc_zero(parent, struct torture_context); if (subtorture == NULL) return NULL; subtorture->ev = talloc_reference(subtorture, parent->ev); subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx); subtorture->outputdir = talloc_reference(subtorture, parent->outputdir); subtorture->results = talloc_reference(subtorture, parent->results); return subtorture; }
/** * 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_get_keytab_container(TALLOC_CTX *mem_ctx, struct smb_krb5_context *smb_krb5_context, krb5_keytab opt_keytab, const char *keytab_name, struct keytab_container **ktc) { krb5_keytab keytab; krb5_error_code ret; if (opt_keytab) { keytab = opt_keytab; } else { ret = krb5_kt_resolve(smb_krb5_context->krb5_context, keytab_name, &keytab); if (ret) { DEBUG(1,("failed to open krb5 keytab: %s\n", smb_get_krb5_error_message( smb_krb5_context->krb5_context, ret, mem_ctx))); return ret; } } *ktc = talloc(mem_ctx, struct keytab_container); if (!*ktc) { return ENOMEM; } (*ktc)->smb_krb5_context = talloc_reference(*ktc, smb_krb5_context); (*ktc)->keytab = keytab; (*ktc)->password_based = false; talloc_set_destructor(*ktc, free_keytab_container); return 0; }
static bool test_loop(void) { void *top = talloc_new(NULL); char *parent; struct req1 { char *req2, *req3; } *req1; printf("test: loop\n# TALLOC LOOP DESTRUCTION\n"); parent = talloc_strdup(top, "parent"); req1 = talloc(parent, struct req1); req1->req2 = talloc_strdup(req1, "req2"); talloc_set_destructor(req1->req2, test_loop_destructor); req1->req3 = talloc_strdup(req1, "req3"); (void)talloc_reference(req1->req3, req1); talloc_report_full(top, stderr); talloc_free(parent); talloc_report_full(top, stderr); talloc_report_full(NULL, stderr); talloc_free(top); torture_assert("loop", loop_destructor_count == 1, "FAILED TO FIRE LOOP DESTRUCTOR\n"); loop_destructor_count = 0; printf("success: loop\n"); return true; }
_PUBLIC_ NTSTATUS auth_generate_session_info(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, struct auth_serversupplied_info *server_info, struct auth_session_info **_session_info) { struct auth_session_info *session_info; NTSTATUS nt_status; session_info = talloc(mem_ctx, struct auth_session_info); NT_STATUS_HAVE_NO_MEMORY(session_info); session_info->server_info = talloc_reference(session_info, server_info); /* unless set otherwise, the session key is the user session * key from the auth subsystem */ session_info->session_key = server_info->user_session_key; nt_status = security_token_create(session_info, event_ctx, lp_ctx, server_info->account_sid, server_info->primary_group_sid, server_info->n_domain_groups, server_info->domain_groups, server_info->authenticated, &session_info->security_token); NT_STATUS_NOT_OK_RETURN(nt_status); session_info->credentials = NULL; *_session_info = session_info; return NT_STATUS_OK; }
/* test references */ static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; printf("test: ref3 [\nPARENT REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(root, 1, "p2"); r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(p2, r1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref3", p1, 2); CHECK_BLOCKS("ref3", p2, 2); CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref3", p2, 2); CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); CHECK_SIZE("ref3", root, 0); talloc_free(root); printf("success: ref3\n"); return true; }
_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; }
/** initialise a smb2_session structure */ struct smb2_session *smb2_session_init(struct smb2_transport *transport, struct gensec_settings *settings, TALLOC_CTX *parent_ctx, bool primary) { struct smb2_session *session; NTSTATUS status; session = talloc_zero(parent_ctx, struct smb2_session); if (!session) { return NULL; } if (primary) { session->transport = talloc_steal(session, transport); } else { session->transport = talloc_reference(session, transport); } session->pid = getpid(); /* prepare a gensec context for later use */ status = gensec_client_start(session, &session->gensec, session->transport->socket->event.ctx, settings); if (!NT_STATUS_IS_OK(status)) { talloc_free(session); return NULL; } gensec_want_feature(session->gensec, GENSEC_FEATURE_SESSION_KEY); return session; }
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; }
/* a client has asked to register a unique name that someone else owns. We need to ask each of the current owners if they still want it. If they do then reject the registration, otherwise allow it */ static void wins_register_wack(struct nbt_name_socket *nbtsock, struct nbt_name_packet *packet, struct winsdb_record *rec, struct socket_address *src, enum wrepl_name_type new_type) { struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private_data, struct nbtd_interface); struct wins_server *winssrv = iface->nbtsrv->winssrv; struct nbtd_wins_wack_state *s; struct composite_context *c_req; uint32_t ttl; s = talloc_zero(nbtsock, struct nbtd_wins_wack_state); if (s == NULL) goto failed; /* package up the state variables for this wack request */ s->winssrv = winssrv; s->nbtsock = nbtsock; s->iface = iface; s->request_packet = talloc_steal(s, packet); s->rec = talloc_steal(s, rec); s->reg_address = packet->additional[0].rdata.netbios.addresses[0].ipaddr; s->new_type = new_type; s->src = src; if (talloc_reference(s, src) == NULL) goto failed; s->io.in.nbtd_server = iface->nbtsrv; s->io.in.nbt_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx); s->io.in.event_ctx = iface->nbtsrv->task->event_ctx; s->io.in.name = rec->name; s->io.in.num_addresses = winsdb_addr_list_length(rec->addresses); s->io.in.addresses = winsdb_addr_string_list(s, rec->addresses); if (s->io.in.addresses == NULL) goto failed; DLIST_ADD_END(iface->wack_queue, s, struct nbtd_wins_wack_state *); talloc_set_destructor(s, nbtd_wins_wack_state_destructor); /* * send a WACK to the client, specifying the maximum time it could * take to check with the owner, plus some slack */ ttl = 5 + 4 * winsdb_addr_list_length(rec->addresses); nbtd_wack_reply(nbtsock, packet, src, ttl); /* * send the challenge to the old addresses */ c_req = wins_challenge_send(s, &s->io); if (c_req == NULL) goto failed; c_req->async.fn = wack_wins_challenge_handler; c_req->async.private_data = s; return; failed: talloc_free(s); nbtd_name_registration_reply(nbtsock, packet, src, NBT_RCODE_SVR); }
static krb5_error_code parse_principal(TALLOC_CTX *parent_ctx, const char *princ_string, struct smb_krb5_context *smb_krb5_context, krb5_principal *princ, const char **error_string) { int ret; struct principal_container *mem_ctx; if (princ_string == NULL) { *princ = NULL; return 0; } ret = krb5_parse_name(smb_krb5_context->krb5_context, princ_string, princ); if (ret) { (*error_string) = smb_get_krb5_error_message(smb_krb5_context->krb5_context, ret, parent_ctx); return ret; } mem_ctx = talloc(parent_ctx, struct principal_container); if (!mem_ctx) { (*error_string) = error_message(ENOMEM); return ENOMEM; } /* This song-and-dance effectivly puts the principal * into talloc, so we can't loose it. */ mem_ctx->smb_krb5_context = talloc_reference(mem_ctx, smb_krb5_context); mem_ctx->principal = *princ; talloc_set_destructor(mem_ctx, free_principal); return 0; }
/** * Obtain the client principal for this credentials context. * @param cred credentials context * @retval The username set on this context. * @note Return value will never be NULL except by programmer error. */ const char *cli_credentials_get_principal(struct cli_credentials *cred, TALLOC_CTX *mem_ctx) { if (cred->machine_account_pending) { cli_credentials_set_machine_account(cred); } if (cred->principal_obtained == CRED_CALLBACK && !cred->callback_running) { cred->callback_running = True; cred->principal = cred->principal_cb(cred); cred->callback_running = False; cred->principal_obtained = CRED_SPECIFIED; } if (cred->principal_obtained < cred->username_obtained) { if (cred->domain_obtained > cred->realm_obtained) { return talloc_asprintf(mem_ctx, "%s@%s", cli_credentials_get_username(cred), cli_credentials_get_domain(cred)); } else { return talloc_asprintf(mem_ctx, "%s@%s", cli_credentials_get_username(cred), cli_credentials_get_realm(cred)); } } return talloc_reference(mem_ctx, cred->principal); }
/* queue a datagram for send */ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock, struct nbt_dgram_packet *packet, struct socket_address *dest) { struct nbt_dgram_request *req; NTSTATUS status = NT_STATUS_NO_MEMORY; enum ndr_err_code ndr_err; req = talloc(dgmsock, struct nbt_dgram_request); if (req == NULL) goto failed; req->dest = dest; if (talloc_reference(req, dest) == NULL) goto failed; ndr_err = ndr_push_struct_blob(&req->encoded, req, packet, (ndr_push_flags_fn_t)ndr_push_nbt_dgram_packet); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { status = ndr_map_error2ntstatus(ndr_err); goto failed; } DLIST_ADD_END(dgmsock->send_queue, req); TEVENT_FD_WRITEABLE(dgmsock->fde); return NT_STATUS_OK; failed: talloc_free(req); return status; }
/* initialise a nbt_dgram_socket. The event_ctx is optional, if provided then operations will use that event context */ struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct smb_iconv_convenience *iconv_convenience) { struct nbt_dgram_socket *dgmsock; NTSTATUS status; dgmsock = talloc(mem_ctx, struct nbt_dgram_socket); if (dgmsock == NULL) goto failed; dgmsock->event_ctx = talloc_reference(dgmsock, event_ctx); if (dgmsock->event_ctx == NULL) goto failed; status = socket_create("ip", SOCKET_TYPE_DGRAM, &dgmsock->sock, 0); if (!NT_STATUS_IS_OK(status)) goto failed; socket_set_option(dgmsock->sock, "SO_BROADCAST", "1"); talloc_steal(dgmsock, dgmsock->sock); dgmsock->fde = event_add_fd(dgmsock->event_ctx, dgmsock, socket_get_fd(dgmsock->sock), 0, dgm_socket_handler, dgmsock); dgmsock->send_queue = NULL; dgmsock->incoming.handler = NULL; dgmsock->mailslot_handlers = NULL; dgmsock->iconv_convenience = iconv_convenience; return dgmsock; failed: talloc_free(dgmsock); return NULL; }
krb5_error_code principal_from_credentials(TALLOC_CTX *parent_ctx, struct cli_credentials *credentials, struct smb_krb5_context *smb_krb5_context, krb5_principal *princ) { krb5_error_code ret; const char *princ_string; struct principal_container *mem_ctx = talloc(parent_ctx, struct principal_container); if (!mem_ctx) { return ENOMEM; } princ_string = cli_credentials_get_principal(credentials, mem_ctx); /* A NULL here has meaning, as the gssapi server case will * then use the principal from the client */ if (!princ_string) { talloc_free(mem_ctx); princ = NULL; return 0; } ret = krb5_parse_name(smb_krb5_context->krb5_context, princ_string, princ); if (ret == 0) { /* This song-and-dance effectivly puts the principal * into talloc, so we can't loose it. */ mem_ctx->smb_krb5_context = talloc_reference(mem_ctx, smb_krb5_context); mem_ctx->principal = *princ; talloc_set_destructor(mem_ctx, free_principal); } return ret; }
/* wrapped connection to a ldb database to close just talloc_free() the returned ldb_context TODO: We need an error_string parameter */ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *url, struct auth_session_info *session_info, struct cli_credentials *credentials, unsigned int flags) { struct ldb_context *ldb; int ret; ldb = ldb_wrap_find(url, ev, lp_ctx, session_info, credentials, flags); if (ldb != NULL) return talloc_reference(mem_ctx, ldb); ldb = samba_ldb_init(mem_ctx, ev, lp_ctx, session_info, credentials); if (ldb == NULL) return NULL; ret = samba_ldb_connect(ldb, lp_ctx, url, flags); if (ret != LDB_SUCCESS) { talloc_free(ldb); return NULL; } if (!ldb_wrap_add(url, ev, lp_ctx, session_info, credentials, flags, ldb)) { talloc_free(ldb); return NULL; } DEBUG(3,("ldb_wrap open of %s\n", url)); return ldb; }
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; }
static WERROR rpc_get_predefined_key(struct registry_context *ctx, uint32_t hkey_type, struct registry_key **k) { int n; struct rpc_key *mykeydata; struct rpc_registry_context *rctx = talloc_get_type(ctx, struct rpc_registry_context); *k = NULL; for(n = 0; known_hives[n].hkey; n++) { if(known_hives[n].hkey == hkey_type) break; } if (known_hives[n].open == NULL) { DEBUG(1, ("No such hive %d\n", hkey_type)); return WERR_NO_MORE_ITEMS; } mykeydata = talloc_zero(ctx, struct rpc_key); mykeydata->key.context = ctx; mykeydata->pipe = talloc_reference(mykeydata, rctx->pipe); mykeydata->num_values = -1; mykeydata->num_subkeys = -1; *k = (struct registry_key *)mykeydata; return known_hives[n].open(mykeydata->pipe, mykeydata, &(mykeydata->pol)); }
/** Start the GENSEC system, returning a context pointer. @param mem_ctx The parent TALLOC memory context. @param gensec_security Returned GENSEC context pointer. @note The mem_ctx is only a parent and may be NULL. @note, the auth context is moved to be a child of the @ gensec_security return */ static NTSTATUS gensec_start(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct gensec_settings *settings, struct auth_context *auth_context, struct gensec_security **gensec_security) { if (ev == NULL) { DEBUG(0, ("No event context available!\n")); return NT_STATUS_INTERNAL_ERROR; } (*gensec_security) = talloc(mem_ctx, struct gensec_security); NT_STATUS_HAVE_NO_MEMORY(*gensec_security); (*gensec_security)->ops = NULL; (*gensec_security)->local_addr = NULL; (*gensec_security)->remote_addr = NULL; (*gensec_security)->private_data = NULL; ZERO_STRUCT((*gensec_security)->target); (*gensec_security)->subcontext = false; (*gensec_security)->want_features = 0; (*gensec_security)->event_ctx = ev; SMB_ASSERT(settings->lp_ctx != NULL); (*gensec_security)->settings = talloc_reference(*gensec_security, settings); (*gensec_security)->auth_context = talloc_steal(*gensec_security, auth_context); return NT_STATUS_OK; }
/* initialise a wrepl_socket. The event_ctx is optional, if provided then operations will use that event context */ struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx, struct smb_iconv_convenience *iconv_convenience) { struct wrepl_socket *wrepl_socket; NTSTATUS status; wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket); if (!wrepl_socket) return NULL; wrepl_socket->event.ctx = talloc_reference(wrepl_socket, event_ctx); if (!wrepl_socket->event.ctx) goto failed; wrepl_socket->iconv_convenience = iconv_convenience; status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0); if (!NT_STATUS_IS_OK(status)) goto failed; talloc_steal(wrepl_socket, wrepl_socket->sock); wrepl_socket->request_timeout = WREPL_SOCKET_REQUEST_TIMEOUT; talloc_set_destructor(wrepl_socket, wrepl_socket_destructor); return wrepl_socket; failed: talloc_free(wrepl_socket); return NULL; }
/* initialise a dcerpc connection. the event context is optional */ static struct dcerpc_connection *dcerpc_connection_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct smb_iconv_convenience *ic) { struct dcerpc_connection *c; c = talloc_zero(mem_ctx, struct dcerpc_connection); if (!c) { return NULL; } c->iconv_convenience = talloc_reference(c, ic); c->event_ctx = ev; if (c->event_ctx == NULL) { talloc_free(c); return NULL; } c->call_id = 1; c->security_state.auth_info = NULL; c->security_state.session_key = dcerpc_generic_session_key; c->security_state.generic_state = NULL; c->binding_string = NULL; c->flags = 0; c->srv_max_xmit_frag = 0; c->srv_max_recv_frag = 0; c->pending = NULL; talloc_set_destructor(c, dcerpc_connection_destructor); return c; }
static WERROR rpc_query_key(TALLOC_CTX *mem_ctx, const struct registry_key *k) { struct winreg_QueryInfoKey r; struct rpc_key *mykeydata = talloc_get_type(k, struct rpc_key); struct winreg_String classname; NTSTATUS status; classname.name = NULL; ZERO_STRUCT(r); r.in.handle = &mykeydata->pol; r.in.classname = &classname; r.out.classname = &classname; r.out.num_subkeys = &mykeydata->num_subkeys; r.out.max_subkeylen = &mykeydata->max_subkeylen; r.out.max_classlen = &mykeydata->max_classlen; r.out.num_values = &mykeydata->num_values; r.out.max_valnamelen = &mykeydata->max_valnamelen; r.out.max_valbufsize = &mykeydata->max_valbufsize; r.out.secdescsize = &mykeydata->secdescsize; r.out.last_changed_time = &mykeydata->last_changed_time; status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("QueryInfoKey failed - %s\n", nt_errstr(status))); return ntstatus_to_werror(status); } mykeydata->classname = talloc_reference(mem_ctx, r.out.classname->name); return r.out.result; }