PyErr_SetString(PyExc_RuntimeError, "Uninitialized");
return NULL;
}
- SAFE_FREE(self->ads_ptr->auth.user_name);
+ TALLOC_FREE(self->ads_ptr->auth.user_name);
TALLOC_FREE(self->ads_ptr->auth.password);
TALLOC_FREE(self->ads_ptr->auth.realm);
if (self->cli_creds) {
- self->ads_ptr->auth.user_name =
- SMB_STRDUP(cli_credentials_get_username(self->cli_creds));
+ self->ads_ptr->auth.user_name = talloc_strdup(self->ads_ptr,
+ cli_credentials_get_username(self->cli_creds));
+ if (self->ads_ptr->auth.user_name == NULL) {
+ PyErr_NoMemory();
+ goto err;
+ }
self->ads_ptr->auth.password = talloc_strdup(self->ads_ptr,
cli_credentials_get_password(self->cli_creds));
if (self->ads_ptr->auth.password == NULL) {
status = ads_connect_user_creds(self->ads_ptr);
} else {
char *passwd = NULL;
- int ret;
+
if (!secrets_init()) {
PyErr_SetString(PyExc_RuntimeError,
"secrets_init() failed");
goto err;
}
- ret = asprintf(&(self->ads_ptr->auth.user_name), "%s$",
- lp_netbios_name());
- if (ret == -1) {
+ self->ads_ptr->auth.user_name = talloc_asprintf(self->ads_ptr,
+ "%s$",
+ lp_netbios_name());
+ if (self->ads_ptr->auth.user_name == NULL) {
PyErr_NoMemory();
goto err;
}
goto out;
}
- SAFE_FREE(ads->auth.user_name);
+ TALLOC_FREE(ads->auth.user_name);
if (r->in.account) {
- ads->auth.user_name = SMB_STRDUP(r->in.account);
+ ads->auth.user_name = talloc_strdup(ads, r->in.account);
+ if (ads->auth.user_name == NULL) {
+ ret = WERR_NOT_ENOUGH_MEMORY;
+ goto out;
+ }
} else {
const char *username = NULL;
libnetapi_get_username(ctx, &username);
if (username != NULL) {
- ads->auth.user_name = SMB_STRDUP(username);
+ ads->auth.user_name = talloc_strdup(ads, username);
+ if (ads->auth.user_name == NULL) {
+ ret = WERR_NOT_ENOUGH_MEMORY;
+ goto out;
+ }
}
}
#ifdef HAVE_LDAP
ads_disconnect(*ads);
#endif
- SAFE_FREE((*ads)->auth.user_name);
SAFE_FREE((*ads)->auth.kdc_server);
SAFE_FREE((*ads)->auth.ccache_name);
if (!ads->auth.user_name) {
/* Must use the userPrincipalName value here or sAMAccountName
and not servicePrincipalName; found by Guenther Deschner */
-
- if (asprintf(&ads->auth.user_name, "%s$", lp_netbios_name() ) == -1) {
- DEBUG(0,("ads_connect: asprintf fail.\n"));
- ads->auth.user_name = NULL;
+ ads->auth.user_name = talloc_asprintf(ads,
+ "%s$",
+ lp_netbios_name());
+ if (ads->auth.user_name == NULL) {
+ DBG_ERR("talloc_asprintf failed\n");
+ status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ goto out;
}
}
}
if (user_name) {
- SAFE_FREE(my_ads->auth.user_name);
- my_ads->auth.user_name = SMB_STRDUP(user_name);
+ TALLOC_FREE(my_ads->auth.user_name);
+ my_ads->auth.user_name = talloc_strdup(my_ads, user_name);
+ if (my_ads->auth.user_name == NULL) {
+ status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ goto out;
+ }
if ((cp = strchr_m(my_ads->auth.user_name, '@'))!=0) {
*cp++ = '\0';
TALLOC_FREE(my_ads->auth.realm);
}
}
- SAFE_FREE(ads->auth.user_name);
- ads->auth.user_name = smb_xstrdup(c->opt_user_name);
+ TALLOC_FREE(ads->auth.user_name);
+ ads->auth.user_name = talloc_strdup(ads, c->opt_user_name);
+ if (ads->auth.user_name == NULL) {
+ TALLOC_FREE(ads);
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
ads->auth.flags |= auth_flags;
use_in_memory_ccache();
- ret = asprintf(&ads_dns->auth.user_name, "%s$", lp_netbios_name());
- if (ret == -1) {
+ ads_dns->auth.user_name = talloc_asprintf(ads_dns,
+ "%s$",
+ lp_netbios_name());
+ if (ads_dns->auth.user_name == NULL) {
d_fprintf(stderr, _("DNS update failed: out of memory\n"));
goto done;
}