static void py_ads_dealloc(ADS* self)
{
- ads_destroy(&(self->ads_ptr));
+ TALLOC_FREE(self->ads_ptr);
Py_CLEAR(self->py_creds);
Py_TYPE(self)->tp_free((PyObject*)self);
}
/* in case __init__ is called more than once */
if (self->ads_ptr) {
- ads_destroy(&self->ads_ptr);
- self->ads_ptr = NULL;
+ TALLOC_FREE(self->ads_ptr);
}
/* always succeeds or crashes */
- self->ads_ptr = ads_init(realm, workgroup, ldap_server, ADS_SASL_PLAIN);
+ self->ads_ptr = ads_init(pytalloc_get_mem_ctx(args),
+ realm,
+ workgroup,
+ ldap_server,
+ ADS_SASL_PLAIN);
return 0;
}
dc = strip_hostname(info->dc_unc);
- ads = ads_init(info->domain_name,
+ ads = ads_init(tmp_ctx,
+ info->domain_name,
info->domain_name,
dc,
ADS_SASL_PLAIN);
ads_status = ads_connect_user_creds(ads);
if (!ADS_ERR_OK(ads_status)) {
- ads_destroy(&ads);
ret = WERR_NERR_DEFAULTJOINREQUIRED;
goto out;
}
ads_status = ads_get_joinable_ous(ads, ctx, &p, &s);
if (!ADS_ERR_OK(ads_status)) {
- ads_destroy(&ads);
ret = WERR_NERR_DEFAULTJOINREQUIRED;
goto out;
}
*r->out.ous = discard_const_p(const char *, p);
*r->out.ou_count = s;
- ads_destroy(&ads);
-
ret = WERR_OK;
out:
TALLOC_FREE(tmp_ctx);
char *ads_build_path(const char *realm, const char *sep, const char *field, int reverse);
char *ads_build_dn(const char *realm);
char *ads_build_domain(const char *dn);
-ADS_STRUCT *ads_init(const char *realm,
+ADS_STRUCT *ads_init(TALLOC_CTX *mem_ctx,
+ const char *realm,
const char *workgroup,
const char *ldap_server,
enum ads_sasl_state_e sasl_state);
bool ads_set_sasl_wrap_flags(ADS_STRUCT *ads, unsigned flags);
-void ads_destroy(ADS_STRUCT **ads);
/* The following definitions come from libads/disp_sec.c */
/*
free the memory used by the ADS structure initialized with 'ads_init(...)'
*/
-void ads_destroy(ADS_STRUCT **ads)
+static void ads_destroy(ADS_STRUCT **ads)
{
if (ads && *ads) {
- bool is_mine;
-
- is_mine = (*ads)->is_mine;
#ifdef HAVE_LDAP
ads_disconnect(*ads);
#endif
SAFE_FREE((*ads)->config.client_site_name);
SAFE_FREE((*ads)->config.schema_path);
SAFE_FREE((*ads)->config.config_path);
-
- ZERO_STRUCTP(*ads);
-#ifdef HAVE_LDAP
- ads_zero_ldap(*ads);
-#endif
-
- if ( is_mine )
- SAFE_FREE(*ads);
}
}
+static int ads_destructor(ADS_STRUCT *ads)
+{
+ ads_destroy(&ads);
+ return 0;
+}
+
/*
initialise a ADS_STRUCT, ready for some ads_ ops
*/
-ADS_STRUCT *ads_init(const char *realm,
+ADS_STRUCT *ads_init(TALLOC_CTX *mem_ctx,
+ const char *realm,
const char *workgroup,
const char *ldap_server,
enum ads_sasl_state_e sasl_state)
{
- ADS_STRUCT *ads;
+ ADS_STRUCT *ads = NULL;
int wrap_flags;
- ads = SMB_XMALLOC_P(ADS_STRUCT);
- ZERO_STRUCTP(ads);
+ ads = talloc_zero(mem_ctx, ADS_STRUCT);
+ if (ads == NULL) {
+ return NULL;
+ }
+ talloc_set_destructor(ads, ads_destructor);
+
#ifdef HAVE_LDAP
ads_zero_ldap(ads);
#endif
* to ads_find_dc() in the reuse case.
*
* If a caller wants a clean ADS_STRUCT they
- * will re-initialize by calling ads_init(), or
- * call ads_destroy() both of which ensures
+ * will TALLOC_FREE it and allocate a new one
+ * by calling ads_init(), which ensures
* ads->ldap.ss is a properly zero'ed out valid IP
* address.
*/
* through ads_find_dc() again we want to avoid repeating.
*/
if (is_zero_addr(&ads->ldap.ss)) {
- ads_s = ads_init(ads->server.realm,
+ ads_s = ads_init(tmp_ctx,
+ ads->server.realm,
ads->server.workgroup,
ads->server.ldap_server,
ADS_SASL_PLAIN );
status = ADS_SUCCESS;
done:
- /* free any temporary ads connections */
- if ( ads_s != ads ) {
- ads_destroy( &ads_s );
- }
TALLOC_FREE(tmp_ctx);
return status;
* through ads_find_dc() again we want to avoid repeating.
*/
if (is_zero_addr(&ads->ldap.ss)) {
- ads_s = ads_init(ads->server.realm,
+ ads_s = ads_init(tmp_ctx,
+ ads->server.realm,
ads->server.workgroup,
ads->server.ldap_server,
ADS_SASL_PLAIN );
ads_msgfree(ads_s, res);
done:
- /* free any temporary ads connections */
- if ( ads_s != ads ) {
- ads_destroy( &ads_s );
- }
TALLOC_FREE(tmp_ctx);
return status;
status = ads_connect(ads);
if (!ADS_ERR_OK(status)) {
- bool orig_is_mine = ads->is_mine;
-
DEBUG(1,("ads_search_retry: failed to reconnect (%s)\n",
ads_errstr(status)));
/*
* from being freed here as we don't own it and
* callers depend on it being around.
*/
- ads->is_mine = false;
- ads_destroy(&ads);
- ads->is_mine = orig_is_mine;
+ ads_disconnect(ads);
SAFE_FREE(bp);
return status;
}
char *cp;
enum credentials_use_kerberos krb5_state;
- my_ads = ads_init(dns_domain_name,
+ my_ads = ads_init(tmp_ctx,
+ dns_domain_name,
netbios_domain_name,
dc_name,
ADS_SASL_SEAL);
SAFE_FREE(my_ads->auth.realm);
my_ads->auth.realm = smb_xstrdup(cp);
if (!strupper_m(my_ads->auth.realm)) {
- ads_destroy(&my_ads);
status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
goto out;
}
status = ads_connect_user_creds(my_ads);
if (!ADS_ERR_OK(status)) {
- ads_destroy(&my_ads);
goto out;
}
- *ads = my_ads;
+ *ads = talloc_move(mem_ctx, &my_ads);
status = ADS_SUCCESS;
out:
username,
password,
ccname,
- mem_ctx,
+ r,
&r->in.ads);
if (!ADS_ERR_OK(status)) {
libnet_join_set_error_string(mem_ctx, r,
r->in.admin_account,
r->in.admin_password,
NULL,
- mem_ctx,
+ r,
&r->in.ads);
if (!ADS_ERR_OK(status)) {
libnet_unjoin_set_error_string(mem_ctx, r,
r->in.ads->auth.ccache_name = NULL;
}
- ads_destroy(&r->in.ads);
+ TALLOC_FREE(r->in.ads);
status = libnet_join_connect_ads_machine(mem_ctx, r);
if (!ADS_ERR_OK(status)) {
static int libnet_destroy_JoinCtx(struct libnet_JoinCtx *r)
{
- if (r->in.ads) {
- ads_destroy(&r->in.ads);
- }
+ TALLOC_FREE(r->in.ads);
return 0;
}
static int libnet_destroy_UnjoinCtx(struct libnet_UnjoinCtx *r)
{
- if (r->in.ads) {
- ads_destroy(&r->in.ads);
- }
+ TALLOC_FREE(r->in.ads);
return 0;
}
krb5_free_context(ctx->context);
}
- if (ctx->ads) {
- ads_destroy(&ctx->ads);
- }
+ TALLOC_FREE(ctx->ads);
TALLOC_FREE(ctx);
/* Try this 3 times then give up. */
for( i =0 ; i < 3; i++) {
- ads = ads_init(realm, domain, NULL, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx, realm, domain, NULL, ADS_SASL_PLAIN);
if (!ads) {
ok = false;
goto out;
#endif
if (!ads->config.realm) {
- ads_destroy(&ads);
ok = false;
goto out;
}
if (stored_sitename_changed(realm, sitename)) {
sitename = sitename_fetch(tmp_ctx, realm);
- ads_destroy(&ads);
+ TALLOC_FREE(ads);
/* Ensure we don't cache the DC we just connected to. */
namecache_delete(realm, 0x1C);
namecache_delete(domain, 0x1C);
if (i == 3) {
DEBUG(1,("ads_dc_name: sitename (now \"%s\") keeps changing ???\n",
sitename ? sitename : ""));
- ads_destroy(&ads);
ok = false;
goto out;
}
fstrcpy(srv_name, ads->config.ldap_server_name);
if (!strupper_m(srv_name)) {
- ads_destroy(&ads);
ok = false;
goto out;
}
#else
zero_sockaddr(dc_ss);
#endif
- ads_destroy(&ads);
-
print_sockaddr(addr, sizeof(addr), dc_ss);
DEBUG(4,("ads_dc_name: using server='%s' IP=%s\n",
srv_name, addr));
return WERR_NOT_ENOUGH_MEMORY;
}
- ads = ads_init(lp_realm(), lp_workgroup(), NULL, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx,
+ lp_realm(),
+ lp_workgroup(),
+ NULL,
+ ADS_SASL_PLAIN);
if (ads == NULL) {
result = WERR_RPC_S_SERVER_UNAVAILABLE;
goto out;
result = nt_printer_guid_retrieve_internal(ads, printer_dn, pguid);
out:
TALLOC_FREE(tmp_ctx);
- ads_destroy(&ads);
ads_kdestroy("MEMORY:prtpub_cache");
unsetenv(KRB5_ENV_CCNAME);
if (old_krb5ccname != NULL) {
TALLOC_FREE(sinfo2);
- ads = ads_init(lp_realm(), lp_workgroup(), NULL, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx,
+ lp_realm(),
+ lp_workgroup(),
+ NULL,
+ ADS_SASL_PLAIN);
if (!ads) {
DEBUG(3, ("ads_init() failed\n"));
win_rc = WERR_RPC_S_SERVER_UNAVAILABLE;
}
done:
- ads_destroy(&ads);
ads_kdestroy("MEMORY:prtpub_cache");
unsetenv(KRB5_ENV_CCNAME);
if (old_krb5ccname) {
ADS_STRUCT *ads = NULL;
int snum;
int n_services = lp_numservices();
- TALLOC_CTX *tmp_ctx = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
struct auth_session_info *session_info = NULL;
struct spoolss_PrinterInfo2 *pinfo2;
NTSTATUS status;
WERROR result;
char *old_krb5ccname = NULL;
- tmp_ctx = talloc_new(NULL);
- if (!tmp_ctx) return WERR_NOT_ENOUGH_MEMORY;
-
- ads = ads_init(lp_realm(), lp_workgroup(), NULL, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx,
+ lp_realm(),
+ lp_workgroup(),
+ NULL,
+ ADS_SASL_PLAIN);
if (!ads) {
DEBUG(3, ("ads_init() failed\n"));
TALLOC_FREE(tmp_ctx);
result = WERR_OK;
done:
- ads_destroy(&ads);
ads_kdestroy("MEMORY:prtpub_cache");
unsetenv(KRB5_ENV_CCNAME);
if (old_krb5ccname) {
ret = net_ads_cldap_netlogon(c, ads);
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
realm = assume_own_realm(c);
}
- ads = ads_init(realm,
- c->opt_target_workgroup,
- c->opt_host,
- ADS_SASL_PLAIN);
+ ads = ads_init(mem_ctx,
+ realm,
+ c->opt_target_workgroup,
+ c->opt_host,
+ ADS_SASL_PLAIN);
+ if (ads == NULL) {
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
if (!c->opt_user_name) {
c->opt_user_name = "administrator";
if (!c->opt_password && need_password && !c->opt_machine_pass) {
c->opt_password = net_prompt_pass(c, c->opt_user_name);
if (!c->opt_password) {
- ads_destroy(&ads);
+ TALLOC_FREE(ads);
return ADS_ERROR(LDAP_NO_MEMORY);
}
}
SAFE_FREE(ads->auth.realm);
ads->auth.realm = smb_xstrdup(cp);
if (!strupper_m(ads->auth.realm)) {
- ads_destroy(&ads);
+ TALLOC_FREE(ads);
return ADS_ERROR(LDAP_NO_MEMORY);
}
}
if (NT_STATUS_EQUAL(ads_ntstatus(status),
NT_STATUS_NO_LOGON_SERVERS)) {
DEBUG(0,("ads_connect: %s\n", ads_errstr(status)));
- ads_destroy(&ads);
+ TALLOC_FREE(ads);
return status;
}
second_time = true;
goto retry;
} else {
- ads_destroy(&ads);
+ TALLOC_FREE(ads);
return status;
}
}
namecache_delete(ads->server.realm, 0x1C);
namecache_delete(ads->server.workgroup, 0x1C);
- ads_destroy(&ads);
- ads = NULL;
+ TALLOC_FREE(ads);
goto retry_connect;
}
}
- *ads_ret = ads;
+ *ads_ret = talloc_move(mem_ctx, &ads);
return status;
}
ADS_STATUS status;
int ret = -1;
- ads = ads_init(realm, workgroup, host, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx, realm, workgroup, host, ADS_SASL_PLAIN);
if (ads == NULL) {
goto out;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
done:
ads_msgfree(ads, res);
- ads_destroy(&ads);
SAFE_FREE(ou_str);
TALLOC_FREE(tmp_ctx);
return rc;
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
SAFE_FREE(ou_str);
TALLOC_FREE(tmp_ctx);
return ret;
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
status = ADS_ERROR_NT(NT_STATUS_OK);
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return status;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
talloc_destroy(tmp_ctx);
return ret;
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
/* use the realm so we can eventually change passwords for users
in realms other than default */
- ads = ads_init(realm, c->opt_workgroup, c->opt_host, ADS_SASL_PLAIN);
+ ads = ads_init(tmp_ctx,
+ realm,
+ c->opt_workgroup,
+ c->opt_host,
+ ADS_SASL_PLAIN);
if (ads == NULL) {
goto out;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = ads_keytab_flush(ads);
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret |= ads_keytab_add_entry(ads, argv[i], update_ads);
}
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = ads_keytab_create_default(ads);
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = ok ? 0 : -1;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = ok ? 0 : -1;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = ok ? 0 : -1;
out:
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
out:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ret = 0;
done:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
done:
ads_msgfree(ads, res);
- ads_destroy(&ads);
TALLOC_FREE(tmp_ctx);
return ret;
}
ads_msgfree(ads, res);
TALLOC_FREE(mem_ctx);
- ads_destroy(&ads);
return 0;
}
ads_msgfree(ads, res);
talloc_destroy(mem_ctx);
- ads_destroy(&ads);
return 0;
}
out:
talloc_destroy(mem_ctx);
- ads_destroy(&ads);
return 0;
}
out:
talloc_destroy(mem_ctx);
- ads_destroy(&ads);
return 0;
}
out:
talloc_destroy(mem_ctx);
- ads_destroy(&ads);
return 0;
}
out:
talloc_destroy(mem_ctx);
- ads_destroy(&ads);
return 0;
}
* kinit with the machine password to do dns update.
*/
- ads_dns = ads_init(lp_realm(), NULL, r->in.dc_name, ADS_SASL_PLAIN);
-
+ ads_dns = ads_init(ctx,
+ lp_realm(),
+ NULL,
+ r->in.dc_name,
+ ADS_SASL_PLAIN);
if (ads_dns == NULL) {
d_fprintf(stderr, _("DNS update failed: out of memory!\n"));
goto done;
}
done:
- ads_destroy(&ads_dns);
+ TALLOC_FREE(ads_dns);
#endif
return;
static int idmap_rfc2307_context_destructor(struct idmap_rfc2307_context *ctx)
{
- if (ctx->ads != NULL) {
- /* we own this ADS_STRUCT so make sure it goes away */
- ctx->ads->is_mine = True;
- ads_destroy( &ctx->ads );
- ctx->ads = NULL;
- }
+ TALLOC_FREE(ctx->ads);
if (ctx->smbldap_state != NULL) {
smbldap_free_struct(&ctx->smbldap_state);
} else {
/* we own this ADS_STRUCT so make sure it goes away */
DEBUG(7,("Deleting expired krb5 credential cache\n"));
- ads->is_mine = True;
- ads_destroy( &ads );
+ TALLOC_FREE(ads);
ads_kdestroy(WINBIND_CCACHE_NAME);
*adsp = NULL;
}
/* we don't want this to affect the users ccache */
setenv("KRB5CCNAME", WINBIND_CCACHE_NAME, 1);
- ads = ads_init(target_realm,
+ ads = ads_init(tmp_ctx,
+ target_realm,
target_dom_name,
ldap_server,
ADS_SASL_SEAL);
ads->auth.realm = SMB_STRDUP(auth_realm);
if (!strupper_m(ads->auth.realm)) {
- ads_destroy(&ads);
status = ADS_ERROR_NT(NT_STATUS_INTERNAL_ERROR);
goto out;
}
if (!ADS_ERR_OK(status)) {
DEBUG(1,("ads_connect for domain %s failed: %s\n",
target_dom_name, ads_errstr(status)));
- ads_destroy(&ads);
goto out;
}
- /* set the flag that says we don't own the memory even
- though we do so that ads_destroy() won't destroy the
- structure we pass back by reference */
-
- ads->is_mine = False;
-
- *adsp = ads;
+ *adsp = talloc_move(mem_ctx, &ads);
out:
TALLOC_FREE(tmp_ctx);
return status;
print_sockaddr(addr, sizeof(addr), &sa->u.ss);
- ads = ads_init(domain->alt_name,
+ ads = ads_init(tmp_ctx,
+ domain->alt_name,
domain->name,
addr,
ADS_SASL_PLAIN);
*namep = talloc_move(mem_ctx, &name);
out:
- ads_destroy( &ads );
-
TALLOC_FREE(tmp_ctx);
return ADS_ERR_OK(ads_status) ? true : false;