svn commit: samba r19528 - in branches: SAMBA_3_0/source/libads SAMBA_3_0/source/utils SAMBA_3_0_23/source/libads SAMBA_3_0_23/source/utils SAMBA_3_0_24/source/libads SAMBA_3_0_24/source/utils

gd at samba.org gd at samba.org
Wed Nov 1 11:19:34 GMT 2006


Author: gd
Date: 2006-11-01 11:19:33 +0000 (Wed, 01 Nov 2006)
New Revision: 19528

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19528

Log:
Fix container handling for "net ads user" and "net ads group" functions
along with some memleaks.

Guenther

Modified:
   branches/SAMBA_3_0/source/libads/ldap.c
   branches/SAMBA_3_0/source/utils/net_ads.c
   branches/SAMBA_3_0_23/source/libads/ldap.c
   branches/SAMBA_3_0_23/source/utils/net_ads.c
   branches/SAMBA_3_0_24/source/libads/ldap.c
   branches/SAMBA_3_0_24/source/utils/net_ads.c


Changeset:
Modified: branches/SAMBA_3_0/source/libads/ldap.c
===================================================================
--- branches/SAMBA_3_0/source/libads/ldap.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0/source/libads/ldap.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -1299,6 +1299,7 @@
 	SAFE_FREE(base);
 
 	if (ads_count_replies(ads, res) != 1) {
+		ads_msgfree(ads, res);
 		return NULL;
 	}
 
@@ -1314,7 +1315,7 @@
 
 	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 @@
 		free(s);
 	}
 
+	ads_msgfree(ads, res);
 	ads_memfree(ads, wkn_dn);
 	ldap_value_free(wkn_dn_exp);
 	ldap_value_free(bind_dn_exp);

Modified: branches/SAMBA_3_0/source/utils/net_ads.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_ads.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0/source/utils/net_ads.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -446,6 +446,7 @@
 	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 @@
 		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 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -654,6 +658,7 @@
 	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 @@
 		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 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -1123,8 +1131,10 @@
 	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 @@
 		}
 	}
 
+	SAFE_FREE( ou_str );
 	SAFE_FREE( dn );
 
 	return rc;

Modified: branches/SAMBA_3_0_23/source/libads/ldap.c
===================================================================
--- branches/SAMBA_3_0_23/source/libads/ldap.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0_23/source/libads/ldap.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -1223,6 +1223,7 @@
 	SAFE_FREE(base);
 
 	if (ads_count_replies(ads, res) != 1) {
+		ads_msgfree(ads, res);
 		return NULL;
 	}
 
@@ -1238,7 +1239,7 @@
 
 	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;
@@ -1247,6 +1248,7 @@
 		free(s);
 	}
 
+	ads_msgfree(ads, res);
 	ads_memfree(ads, wkn_dn);
 	ldap_value_free(wkn_dn_exp);
 	ldap_value_free(bind_dn_exp);

Modified: branches/SAMBA_3_0_23/source/utils/net_ads.c
===================================================================
--- branches/SAMBA_3_0_23/source/utils/net_ads.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0_23/source/utils/net_ads.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -409,6 +409,7 @@
 	char *upn, *userdn;
 	void *res=NULL;
 	int rc = -1;
+	char *ou_str = NULL;
 
 	if (argc < 1) return net_ads_user_usage(argc, argv);
 	
@@ -428,11 +429,13 @@
 		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],
@@ -473,6 +476,7 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -617,6 +621,7 @@
 	ADS_STATUS status;
 	void *res=NULL;
 	int rc = -1;
+	char *ou_str = NULL;
 
 	if (argc < 1) {
 		return net_ads_group_usage(argc, argv);
@@ -638,11 +643,13 @@
 		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]);
@@ -656,6 +663,7 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -1067,8 +1075,10 @@
 	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, (void**)&res, dn, NULL);
 	ads_msgfree(ads, res);
@@ -1083,6 +1093,7 @@
 		}
 	}
 
+	SAFE_FREE( ou_str );
 	SAFE_FREE( dn );
 
 	return rc;

Modified: branches/SAMBA_3_0_24/source/libads/ldap.c
===================================================================
--- branches/SAMBA_3_0_24/source/libads/ldap.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0_24/source/libads/ldap.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -1291,6 +1291,7 @@
 	SAFE_FREE(base);
 
 	if (ads_count_replies(ads, res) != 1) {
+		ads_msgfree(ads, res);
 		return NULL;
 	}
 
@@ -1306,7 +1307,7 @@
 
 	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;
@@ -1315,6 +1316,7 @@
 		free(s);
 	}
 
+	ads_msgfree(ads, res);
 	ads_memfree(ads, wkn_dn);
 	ldap_value_free(wkn_dn_exp);
 	ldap_value_free(bind_dn_exp);

Modified: branches/SAMBA_3_0_24/source/utils/net_ads.c
===================================================================
--- branches/SAMBA_3_0_24/source/utils/net_ads.c	2006-11-01 11:08:05 UTC (rev 19527)
+++ branches/SAMBA_3_0_24/source/utils/net_ads.c	2006-11-01 11:19:33 UTC (rev 19528)
@@ -433,6 +433,7 @@
 	char *upn, *userdn;
 	void *res=NULL;
 	int rc = -1;
+	char *ou_str = NULL;
 
 	if (argc < 1) return net_ads_user_usage(argc, argv);
 	
@@ -452,11 +453,13 @@
 		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],
@@ -497,6 +500,7 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -638,6 +642,7 @@
 	ADS_STATUS status;
 	void *res=NULL;
 	int rc = -1;
+	char *ou_str = NULL;
 
 	if (argc < 1) {
 		return net_ads_group_usage(argc, argv);
@@ -659,11 +664,13 @@
 		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]);
@@ -677,6 +684,7 @@
 	if (res)
 		ads_msgfree(ads, res);
 	ads_destroy(&ads);
+	SAFE_FREE(ou_str);
 	return rc;
 }
 
@@ -1104,8 +1112,10 @@
 	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, (void **)&res, dn, NULL);
 	ads_msgfree(ads, res);
@@ -1120,6 +1130,7 @@
 		}
 	}
 
+	SAFE_FREE( ou_str );
 	SAFE_FREE( dn );
 
 	return rc;



More information about the samba-cvs mailing list