diff options
author | Andreas Schneider <asn@samba.org> | 2019-08-13 16:30:07 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2019-10-16 12:15:53 +0000 |
commit | ddd4a6af621799c4d7e38373733ec1bb1c168a9e (patch) | |
tree | b3da6f65d5dc3604c0b63a98d06573dd974993a7 | |
parent | 399598138815c38ea992c97a3a65b82fb849c6f4 (diff) | |
download | samba-ddd4a6af621799c4d7e38373733ec1bb1c168a9e.tar.gz |
s3:libads: Cleanup error code paths in ads_create_machine_acct()
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
(cherry picked from commit 8ed993789f93624b7b60dd5314fe5472e69e903a)
-rw-r--r-- | source3/libads/ldap.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 7bdda4b1768..e492d0688a5 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -2092,11 +2092,12 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, uint32_t etype_list) { ADS_STATUS ret; - char *samAccountName, *controlstr; - TALLOC_CTX *ctx; + char *samAccountName = NULL; + char *controlstr = NULL; + TALLOC_CTX *ctx = NULL; ADS_MODLIST mods; char *machine_escaped = NULL; - char *new_dn; + char *new_dn = NULL; const char *objectClass[] = {"top", "person", "organizationalPerson", "user", "computer", NULL}; LDAPMessage *res = NULL; @@ -2110,13 +2111,14 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, return ret; } - if (!(ctx = talloc_init("ads_add_machine_acct"))) + ctx = talloc_init("ads_add_machine_acct"); + if (ctx == NULL) { return ADS_ERROR(LDAP_NO_MEMORY); - - ret = ADS_ERROR(LDAP_NO_MEMORY); + } machine_escaped = escape_rdn_val_string_alloc(machine_name); - if (!machine_escaped) { + if (machine_escaped == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); goto done; } @@ -2131,17 +2133,26 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, ads_msgfree(ads, res); new_dn = talloc_asprintf(ctx, "cn=%s,%s", machine_escaped, org_unit); - samAccountName = talloc_asprintf(ctx, "%s$", machine_name); + if (new_dn == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); + goto done; + } - if ( !new_dn || !samAccountName ) { + samAccountName = talloc_asprintf(ctx, "%s$", machine_name); + if (samAccountName == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); goto done; } - if (!(controlstr = talloc_asprintf(ctx, "%u", acct_control))) { + controlstr = talloc_asprintf(ctx, "%u", acct_control); + if (controlstr == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); goto done; } - if (!(mods = ads_init_mods(ctx))) { + mods = ads_init_mods(ctx); + if (mods == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); goto done; } @@ -2155,6 +2166,7 @@ ADS_STATUS ads_create_machine_acct(ADS_STRUCT *ads, etype_list_str = talloc_asprintf(ctx, "%d", (int)etype_list); if (etype_list_str == NULL) { + ret = ADS_ERROR(LDAP_NO_MEMORY); goto done; } ads_mod_str(ctx, &mods, "msDS-SupportedEncryptionTypes", |