mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
MSDFS referral shuffling
Shuffle MSDFS referral list in smbd in accordance with [MS-DFSC] 3.2.1.1 When parsing an MSDFS symlink, the names are shuffled with a Fisher-Yates algorithm. Signed-off-by: Robin McCorkell <rmccorkell@karoshi.org.uk> Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
200d0bc3a8
commit
13c9774662
16
docs-xml/smbdotconf/vfs/msdfsshufflereferrals.xml
Normal file
16
docs-xml/smbdotconf/vfs/msdfsshufflereferrals.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<samba:parameter name="msdfs shuffle referrals"
|
||||
context="S"
|
||||
type="boolean"
|
||||
xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
|
||||
<description>
|
||||
<para>If set to <constant>yes</constant>, Samba will shuffle
|
||||
Dfs referrals for a given Dfs link if multiple are available,
|
||||
allowing for load balancing across clients. For more information
|
||||
on setting up a Dfs tree on Samba, refer to the MSDFS chapter in
|
||||
the Samba3-HOWTO book.</para>
|
||||
</description>
|
||||
|
||||
<related>host msdfs</related>
|
||||
<related>msdfs root</related>
|
||||
<value type="default">no</value>
|
||||
</samba:parameter>
|
@ -3941,6 +3941,15 @@ struct parm_struct parm_table[] = {
|
||||
.enum_list = NULL,
|
||||
.flags = FLAG_ADVANCED | FLAG_SHARE,
|
||||
},
|
||||
{
|
||||
.label = "msdfs shuffle referrals",
|
||||
.type = P_BOOL,
|
||||
.p_class = P_LOCAL,
|
||||
.offset = LOCAL_VAR(msdfs_shuffle_referrals),
|
||||
.special = NULL,
|
||||
.enum_list = NULL,
|
||||
.flags = FLAG_ADVANCED | FLAG_SHARE,
|
||||
},
|
||||
{
|
||||
.label = "host msdfs",
|
||||
.type = P_BOOL,
|
||||
|
@ -222,6 +222,7 @@ static struct loadparm_service sDefault =
|
||||
.inherit_acls = false,
|
||||
.inherit_owner = false,
|
||||
.msdfs_root = false,
|
||||
.msdfs_shuffle_referrals = false,
|
||||
.use_client_driver = false,
|
||||
.default_devmode = true,
|
||||
.force_printername = false,
|
||||
|
@ -4,6 +4,7 @@
|
||||
MSDFS services for Samba
|
||||
Copyright (C) Shirish Kalele 2000
|
||||
Copyright (C) Jeremy Allison 2007
|
||||
Copyright (C) Robin McCorkell 2015
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -428,6 +429,22 @@ NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx,
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
static void shuffle_strlist(char **list, int count)
|
||||
{
|
||||
int i, r;
|
||||
char *tmp;
|
||||
|
||||
srandom(time(NULL));
|
||||
|
||||
for (i = count; i > 1; i--) {
|
||||
r = random() % i;
|
||||
|
||||
tmp = list[i-1];
|
||||
list[i-1] = list[r];
|
||||
list[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
Parse the contents of a symlink to verify if it is an msdfs referral
|
||||
A valid referral is of the form:
|
||||
@ -448,6 +465,7 @@ NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx,
|
||||
**********************************************************************/
|
||||
|
||||
static bool parse_msdfs_symlink(TALLOC_CTX *ctx,
|
||||
int snum,
|
||||
const char *target,
|
||||
struct referral **preflist,
|
||||
int *refcount)
|
||||
@ -480,6 +498,11 @@ static bool parse_msdfs_symlink(TALLOC_CTX *ctx,
|
||||
count++;
|
||||
}
|
||||
|
||||
/* shuffle alternate paths */
|
||||
if (lp_msdfs_shuffle_referrals(snum)) {
|
||||
shuffle_strlist(alt_path, count);
|
||||
}
|
||||
|
||||
DEBUG(10,("parse_msdfs_symlink: count=%d\n", count));
|
||||
|
||||
if (count) {
|
||||
@ -1007,7 +1030,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
if (!parse_msdfs_symlink(ctx, tmp, &ref, &refcount)) {
|
||||
if (!parse_msdfs_symlink(ctx, snum, tmp, &ref, &refcount)) {
|
||||
TALLOC_FREE(tmp);
|
||||
TALLOC_FREE(pdp);
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
@ -1056,7 +1079,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
|
||||
}
|
||||
|
||||
/* We know this is a valid dfs link. Parse the targetpath. */
|
||||
if (!parse_msdfs_symlink(ctx, targetpath,
|
||||
if (!parse_msdfs_symlink(ctx, snum, targetpath,
|
||||
&jucn->referral_list,
|
||||
&jucn->referral_count)) {
|
||||
DEBUG(3,("get_referred_path: failed to parse symlink "
|
||||
@ -1517,7 +1540,7 @@ static int form_junctions(TALLOC_CTX *ctx,
|
||||
conn,
|
||||
dname, &link_target,
|
||||
NULL)) {
|
||||
if (parse_msdfs_symlink(ctx,
|
||||
if (parse_msdfs_symlink(ctx, snum,
|
||||
link_target,
|
||||
&jucn[cnt].referral_list,
|
||||
&jucn[cnt].referral_count)) {
|
||||
|
Loading…
Reference in New Issue
Block a user