diff options
author | Günther Deschner <gd@samba.org> | 2006-11-01 11:19:33 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:15:41 -0500 |
commit | 31a63ab19f2a1f717db90d1164a8b696c625e739 (patch) | |
tree | d6a7639047c0bbe6180a1c2e6412a44e9a2f42a2 /source3/utils | |
parent | 4e0f560f609f1d79f1821f20a16f8c50eaae7b3e (diff) | |
download | samba-31a63ab19f2a1f717db90d1164a8b696c625e739.tar.gz samba-31a63ab19f2a1f717db90d1164a8b696c625e739.tar.bz2 samba-31a63ab19f2a1f717db90d1164a8b696c625e739.zip |
r19528: Fix container handling for "net ads user" and "net ads group" functions
along with some memleaks.
Guenther
(This used to be commit 4bad52c5b3a983418d4216a2c3f5e04926e37e94)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_ads.c | 27 |
1 files changed, 19 insertions, 8 deletions
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; |