View | Details | Raw Unified | Return to bug 34429
Collapse All | Expand All

(-)a/source3/modules/vfs_dfs_samba4.c (+8 lines)
 Lines 106-111    Link Here 
106
{
106
{
107
	struct dfs_samba4_handle_data *data;
107
	struct dfs_samba4_handle_data *data;
108
	NTSTATUS status;
108
	NTSTATUS status;
109
	const char *preferred_DC = NULL;
109
110
110
	SMB_VFS_HANDLE_GET_DATA(handle, data,
111
	SMB_VFS_HANDLE_GET_DATA(handle, data,
111
				struct dfs_samba4_handle_data,
112
				struct dfs_samba4_handle_data,
 Lines 115-122    Link Here 
115
		   r->in.req.servername,
116
		   r->in.req.servername,
116
		   (unsigned int)strlen_m(r->in.req.servername)*2));
117
		   (unsigned int)strlen_m(r->in.req.servername)*2));
117
118
119
	if (lp_parm_bool(SNUM(handle->conn), "dfs_samba4", "preferLogonDC", false)) {
120
		preferred_DC = handle->conn->session_info->info->logon_server;
121
		DEBUG(8, ("dfs_samba4: Preferred DC: %s\n",
122
			   preferred_DC));
123
	}
124
118
	status = dfs_server_ad_get_referrals(data->lp_ctx,
125
	status = dfs_server_ad_get_referrals(data->lp_ctx,
119
					     data->sam_ctx,
126
					     data->sam_ctx,
127
					     preferred_DC,
120
					     handle->conn->sconn->remote_address,
128
					     handle->conn->sconn->remote_address,
121
					     r);
129
					     r);
122
	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
130
	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
(-)a/dfs_server/dfs_server_ad.c (-4 / +77 lines)
 Lines 261-267    Link Here 
261
/*
293
/*
262
  get all DCs
294
  get all DCs
263
 */
295
 */
264
static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
296
static NTSTATUS get_dcs(TALLOC_CTX *ctx,
297
			struct loadparm_context *lp_ctx,
298
			struct ldb_context *ldb,
299
			const char *logon_server,
265
			const char *searched_site, bool need_fqdn,
300
			const char *searched_site, bool need_fqdn,
266
			struct dc_set ***pset_list, uint32_t flags)
301
			struct dc_set ***pset_list, uint32_t flags)
267
{
302
{
 Lines 285-290    Link Here 
285
	subctx = talloc_new(ctx);
320
	subctx = talloc_new(ctx);
286
	NT_STATUS_HAVE_NO_MEMORY(subctx);
321
	NT_STATUS_HAVE_NO_MEMORY(subctx);
287
322
323
	if (logon_server != NULL) {
324
325
		DEBUG(2,(__location__ ": dfs_server_ad: get_dcs realloc\n"));
326
		set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+2);
327
		DEBUG(2,(__location__ ": dfs_server_ad: get_dcs realloc done\n"));
328
		if (set_list == NULL) {
329
			TALLOC_FREE(subctx);
330
			return NT_STATUS_NO_MEMORY;
331
		}
332
		set_list[current_pos] = talloc(set_list, struct dc_set);
333
		if (set_list[current_pos] == NULL) {
334
			TALLOC_FREE(subctx);
335
			return NT_STATUS_NO_MEMORY;
336
		}
337
		set_list[current_pos]->names = NULL;
338
		set_list[current_pos]->count = 0;
339
340
		set_list[current_pos+1] = NULL;
341
342
		DEBUG(2,(__location__ ": dfs_server_ad: get_dcs realloc names\n"));
343
		set_list[current_pos]->names = talloc_realloc(set_list, set_list[current_pos]->names, const char *, 1);
344
		DEBUG(2,(__location__ ": dfs_server_ad: get_dcs realloc names done\n"));
345
		if (set_list[current_pos]->names == NULL) {
346
			return NT_STATUS_NO_MEMORY;
347
		}
348
349
		if (need_fqdn) {
350
			struct ldb_result *r;
351
			struct ldb_dn *domaindn = ldb_get_default_basedn(ldb);
352
			static const char *attrs[] = { "dNSHostName", NULL };
353
			const char *searchfilter = talloc_asprintf(subctx, "(&(objectClass=computer)(sAMAccountName=%s$))", logon_server);
354
355
			ret = ldb_search(ldb, subctx, &r, domaindn, LDB_SCOPE_SUBTREE, attrs, searchfilter);
356
			if (ret != LDB_SUCCESS) {
357
				DEBUG(2,(__location__ ": Search for computer %s failed - %s\n",
358
					 logon_server, ldb_errstring(ldb)));
359
				talloc_free(subctx);
360
				return NT_STATUS_INTERNAL_ERROR;
361
			}
362
363
			const char *dns = ldb_msg_find_attr_as_string(r->msgs[0], "dNSHostName", NULL);
364
			if (dns == NULL) {
365
				DEBUG(2,(__location__ ": dNSHostName missing on %s\n",
366
					 ldb_dn_get_linearized(r->msgs[0]->dn)));
367
				talloc_free(subctx);
368
				talloc_free(r);
369
				return NT_STATUS_INTERNAL_ERROR;
370
			}
371
372
			set_list[current_pos]->names[0] = talloc_strdup(set_list, dns);
373
			if (set_list[current_pos]->names[0] == NULL) {
374
				talloc_free(subctx);
375
				talloc_free(r);
376
				return NT_STATUS_NO_MEMORY;
377
			}
378
			talloc_free(r);
379
		} else {
380
			set_list[current_pos]->names[0] = talloc_strdup(set_list, logon_server);
381
			if (set_list[current_pos]->names[0] == NULL) {
382
				talloc_free(subctx);
383
				return NT_STATUS_NO_MEMORY;
384
			}
385
		}
386
387
		set_list[current_pos]->count = 1;
388
		current_pos++;
389
	}
390
288
	configdn = ldb_get_config_basedn(ldb);
391
	configdn = ldb_get_config_basedn(ldb);
289
392
290
	/* Let's search for the Site container */
393
	/* Let's search for the Site container */
 Lines 556-562    Link Here 
556
676
557
	site_name = samdb_client_site_name(sam_ctx, r, client_str, NULL);
677
	site_name = samdb_client_site_name(sam_ctx, r, client_str, NULL);
558
678
559
	status = get_dcs(r, sam_ctx, site_name, need_fqdn, &set, 0);
679
	status = get_dcs(r, lp_ctx, sam_ctx, NULL, site_name, need_fqdn, &set, 0);
560
	if (!NT_STATUS_IS_OK(status)) {
680
	if (!NT_STATUS_IS_OK(status)) {
561
		DEBUG(3,("Unable to get list of DCs - %s\n",
681
		DEBUG(3,("Unable to get list of DCs - %s\n",
562
			 nt_errstr(status)));
682
			 nt_errstr(status)));
 Lines 629-634    Link Here 
629
static NTSTATUS dosysvol_referral(struct loadparm_context *lp_ctx,
749
static NTSTATUS dosysvol_referral(struct loadparm_context *lp_ctx,
630
				  struct ldb_context *sam_ctx,
750
				  struct ldb_context *sam_ctx,
631
				  const struct tsocket_address *client,
751
				  const struct tsocket_address *client,
752
				  const char *logon_server,
632
				  struct dfs_GetDFSReferral *r,
753
				  struct dfs_GetDFSReferral *r,
633
				  const char *domain_name,
754
				  const char *domain_name,
634
				  const char *dfs_name)
755
				  const char *dfs_name)
 Lines 667-673    Link Here 
667
788
668
	site_name = samdb_client_site_name(sam_ctx, r, client_str, NULL);
789
	site_name = samdb_client_site_name(sam_ctx, r, client_str, NULL);
669
790
670
	status = get_dcs(r, sam_ctx, site_name, need_fqdn, &set, 0);
791
	status = get_dcs(r, lp_ctx, sam_ctx, logon_server, site_name, need_fqdn, &set, 0);
671
	if (!NT_STATUS_IS_OK(status)) {
792
	if (!NT_STATUS_IS_OK(status)) {
672
		DEBUG(3,("Unable to get list of DCs - %s\n",
793
		DEBUG(3,("Unable to get list of DCs - %s\n",
673
			 nt_errstr(status)));
794
			 nt_errstr(status)));
 Lines 741-746    Link Here 
741
*/
862
*/
742
NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
863
NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
743
				     struct ldb_context *sam_ctx,
864
				     struct ldb_context *sam_ctx,
865
				     const char *logon_server,
744
				     const struct tsocket_address *client,
866
				     const struct tsocket_address *client,
745
				     struct dfs_GetDFSReferral *r)
867
				     struct dfs_GetDFSReferral *r)
746
{
868
{
 Lines 889-895    Link Here 
889
	 */
1011
	 */
890
	if (strcasecmp(dfs_name, "sysvol") == 0 ||
1012
	if (strcasecmp(dfs_name, "sysvol") == 0 ||
891
	    strcasecmp(dfs_name, "netlogon") == 0) {
1013
	    strcasecmp(dfs_name, "netlogon") == 0) {
892
		return dosysvol_referral(lp_ctx, sam_ctx, client, r,
1014
		return dosysvol_referral(lp_ctx, sam_ctx, client, logon_server, r,
893
					 server_name, dfs_name);
1015
					 server_name, dfs_name);
894
	}
1016
	}
895
1017
(-)a/dfs_server/dfs_server_ad.h (+1 lines)
 Lines 19-23    Link Here 
19
19
20
NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
20
NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
21
				     struct ldb_context *sam_ctx,
21
				     struct ldb_context *sam_ctx,
22
				     const char *logon_server,
22
				     const struct tsocket_address *client,
23
				     const struct tsocket_address *client,
23
				     struct dfs_GetDFSReferral *r);
24
				     struct dfs_GetDFSReferral *r);

Return to bug 34429