From baf9b78d47079b81cf33682ee481cf6e30ed89e9 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Thu, 21 Feb 2013 12:31:37 -0700 Subject: s3-winbindd: Use common helper function for connecting to ADS Reviewed-by: Andrew Bartlett --- source3/winbindd/idmap_ad.c | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) (limited to 'source3/winbindd/idmap_ad.c') diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c index 0e00a340bf..5b9c3774f6 100644 --- a/source3/winbindd/idmap_ad.c +++ b/source3/winbindd/idmap_ad.c @@ -58,13 +58,8 @@ struct idmap_ad_context { static ADS_STATUS ad_idmap_cached_connection_internal(struct idmap_domain *dom) { - ADS_STRUCT *ads; - ADS_STATUS status; - fstring dc_name; - struct sockaddr_storage dc_ip; struct idmap_ad_context *ctx; - char *ldap_server = NULL; - char *realm = NULL; + char *ldap_server, *realm, *password; struct winbindd_domain *wb_dom; DEBUG(10, ("ad_idmap_cached_connection: called for domain '%s'\n", @@ -77,9 +72,6 @@ static ADS_STATUS ad_idmap_cached_connection_internal(struct idmap_domain *dom) return ADS_SUCCESS; } - /* we don't want this to affect the users ccache */ - setenv("KRB5CCNAME", WINBIND_CCACHE_NAME, 1); - /* * At this point we only have the NetBIOS domain name. * Check if we can get server nam and realm from SAF cache @@ -99,35 +91,12 @@ static ADS_STATUS ad_idmap_cached_connection_internal(struct idmap_domain *dom) realm = wb_dom->alt_name; } - if ( (ads = ads_init(realm, dom->name, ldap_server)) == NULL ) { - DEBUG(1,("ads_init failed\n")); - return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); - } - /* the machine acct password might have change - fetch it every time */ - SAFE_FREE(ads->auth.password); - ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); - - SAFE_FREE(ads->auth.realm); - ads->auth.realm = SMB_STRDUP(lp_realm()); - - /* setup server affinity */ - - get_dc_name(dom->name, realm, dc_name, &dc_ip ); - - status = ads_connect(ads); - if (!ADS_ERR_OK(status)) { - DEBUG(1, ("ad_idmap_cached_connection_internal: failed to " - "connect to AD\n")); - ads_destroy(&ads); - return status; - } - - ads->is_mine = False; - - ctx->ads = ads; + password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); + realm = SMB_STRDUP(lp_realm()); - return ADS_SUCCESS; + return ads_cached_connection_connect(&ctx->ads, realm, dom->name, + ldap_server, password, realm, 0); } /************************************************************************ -- cgit