From a33704c50b9536b30a2fc4cbecf878ca4fd535e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Thu, 22 Aug 2013 15:39:08 +0200 Subject: [PATCH 1/4] s3-winbindd: remove pointless variable assigment, see the strdup below. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/winbindd/winbindd_ads.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index 1e45ad9..5e6bb92 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -101,7 +101,6 @@ static ADS_STATUS ads_cached_connection_connect(ADS_STRUCT **adsp, ads->auth.renewable = renewable; ads->auth.password = password; - ads->auth.realm = realm; ads->auth.realm = SMB_STRDUP(realm); if (!strupper_m(ads->auth.realm)) { -- 1.8.3.1 From e484cd91f432e50d2a6cd6541e88a4afcbee810b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 23 Aug 2013 12:33:53 +0200 Subject: [PATCH 2/4] s3-winbindd: Fix memory leak in ads_cached_connection(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/winbindd/winbindd_ads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index 5e6bb92..924bc83 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -220,7 +220,7 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) domain->name, NULL, password, realm, WINBINDD_PAM_AUTH_KRB5_RENEW_TIME); - + SAFE_FREE(realm); if (!ADS_ERR_OK(status)) { /* if we get ECONNREFUSED then it might be a NT4 -- 1.8.3.1 From 98983886b08b6d227c897b3a9e477cf4e2f8b8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Thu, 22 Aug 2013 16:36:27 +0200 Subject: [PATCH 3/4] s3-winbindd: Fix winbind on DC crash with trusted AD domains. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/winbindd/winbindd_ads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index 924bc83..d6eb4b4 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -193,7 +193,7 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) NULL ) ) { return NULL; } - realm = NULL; + realm = SMB_STRDUP(domain->alt_name); } else { struct winbindd_domain *our_domain = domain; -- 1.8.3.1 From 41baddaf970fefa047937755991c7129bef2e89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 23 Aug 2013 14:56:17 +0200 Subject: [PATCH 4/4] s3-winbindd: make sure also the idmap code can deal with trusted domains. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/winbindd/winbindd_ads.c | 43 +++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index d6eb4b4..2ef207f 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -136,6 +136,7 @@ ADS_STATUS ads_idmap_cached_connection(ADS_STRUCT **adsp, const char *dom_name) { char *ldap_server, *realm, *password; struct winbindd_domain *wb_dom; + ADS_STATUS status; ads_cached_connection_reuse(adsp); if (*adsp != NULL) { @@ -151,22 +152,44 @@ ADS_STATUS ads_idmap_cached_connection(ADS_STRUCT **adsp, const char *dom_name) DEBUG(10, ("ldap_server from saf cache: '%s'\n", ldap_server ? ldap_server : "")); - wb_dom = find_domain_from_name_noinit(dom_name); + wb_dom = find_domain_from_name(dom_name); if (wb_dom == NULL) { DEBUG(10, ("could not find domain '%s'\n", dom_name)); - realm = NULL; - } else { - DEBUG(10, ("find_domain_from_name_noinit found realm '%s' for " + return ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL); + } + + DEBUG(10, ("find_domain_from_name found realm '%s' for " " domain '%s'\n", wb_dom->alt_name, dom_name)); - realm = wb_dom->alt_name; + + if (IS_DC) { + if (!pdb_get_trusteddom_pw(dom_name, &password, NULL, NULL)) { + return ADS_ERROR_NT(NT_STATUS_NO_SUCH_DOMAIN); + } + realm = SMB_STRDUP(wb_dom->alt_name); + } else { + struct winbindd_domain *our_domain = wb_dom; + + password = secrets_fetch_machine_password(lp_workgroup(), NULL, + NULL); + /* always give preference to the alt_name in our + primary domain if possible */ + + if (!wb_dom->primary) { + our_domain = find_our_domain(); + } + + if (our_domain->alt_name != NULL) { + realm = SMB_STRDUP(our_domain->alt_name); + } else { + realm = SMB_STRDUP(lp_realm()); + } } - /* the machine acct password might have change - fetch it every time */ - password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); - realm = SMB_STRDUP(lp_realm()); + status = ads_cached_connection_connect(adsp, realm, dom_name, ldap_server, + password, realm, 0); + SAFE_FREE(realm); - return ads_cached_connection_connect(adsp, realm, dom_name, ldap_server, - password, realm, 0); + return status; } /* -- 1.8.3.1