summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/libads/ldap.c4
-rw-r--r--source3/utils/net_ads.c27
2 files changed, 22 insertions, 9 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 6fbae51179..1e726f5e55 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -1299,6 +1299,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
SAFE_FREE(base);
if (ads_count_replies(ads, res) != 1) {
+ ads_msgfree(ads, res);
return NULL;
}
@@ -1314,7 +1315,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
new_ln = wkn_ln - bind_ln;
- ret = wkn_dn_exp[0];
+ ret = SMB_STRDUP(wkn_dn_exp[0]);
for (i=1; i < new_ln; i++) {
char *s;
@@ -1323,6 +1324,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
free(s);
}
+ ads_msgfree(ads, res);
ads_memfree(ads, wkn_dn);
ldap_value_free(wkn_dn_exp);
ldap_value_free(bind_dn_exp);
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index 060114f548..377bfa22b7 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -446,6 +446,7 @@ static int ads_user_add(int argc, const char **argv)
char *upn, *userdn;
LDAPMessage *res=NULL;
int rc = -1;
+ char *ou_str = NULL;
if (argc < 1) return net_ads_user_usage(argc, argv);
@@ -465,11 +466,13 @@ static int ads_user_add(int argc, const char **argv)
goto done;
}
- if (opt_container == NULL) {
- opt_container = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
+ if (opt_container) {
+ ou_str = SMB_STRDUP(opt_container);
+ } else {
+ ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
}
- status = ads_add_user_acct(ads, argv[0], opt_container, opt_comment);
+ status = ads_add_user_acct(ads, argv[0], ou_str, opt_comment);
if (!ADS_ERR_OK(status)) {
d_fprintf(stderr, "Could not add user %s: %s\n", argv[0],
@@ -510,6 +513,7 @@ static int ads_user_add(int argc, const char **argv)
if (res)
ads_msgfree(ads, res);
ads_destroy(&ads);
+ SAFE_FREE(ou_str);
return rc;
}
@@ -654,6 +658,7 @@ static int ads_group_add(int argc, const char **argv)
ADS_STATUS status;
LDAPMessage *res=NULL;
int rc = -1;
+ char *ou_str = NULL;
if (argc < 1) {
return net_ads_group_usage(argc, argv);
@@ -675,11 +680,13 @@ static int ads_group_add(int argc, const char **argv)
goto done;
}
- if (opt_container == NULL) {
- opt_container = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
+ if (opt_container) {
+ ou_str = SMB_STRDUP(opt_container);
+ } else {
+ ou_str = ads_default_ou_string(ads, WELL_KNOWN_GUID_USERS);
}
- status = ads_add_group_acct(ads, argv[0], opt_container, opt_comment);
+ status = ads_add_group_acct(ads, argv[0], ou_str, opt_comment);
if (ADS_ERR_OK(status)) {
d_printf("Group %s added\n", argv[0]);
@@ -693,6 +700,7 @@ static int ads_group_add(int argc, const char **argv)
if (res)
ads_msgfree(ads, res);
ads_destroy(&ads);
+ SAFE_FREE(ou_str);
return rc;
}
@@ -1123,8 +1131,10 @@ static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou )
LDAPMessage *res = NULL;
ou_str = ads_ou_string(ads, ou);
- asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path);
- free(ou_str);
+ if ((asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path)) == -1) {
+ SAFE_FREE(ou_str);
+ return ADS_ERROR(LDAP_NO_MEMORY);
+ }
rc = ads_search_dn(ads, &res, dn, NULL);
ads_msgfree(ads, res);
@@ -1139,6 +1149,7 @@ static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou )
}
}
+ SAFE_FREE( ou_str );
SAFE_FREE( dn );
return rc;