1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-25 17:57:42 +03:00

s3: smbd: msdfs: Factor out the code to create a msdfs:referral,list into a separate function.

This will allow it to be called from other places once the get/set_msdfs
calls are moved into being first class VFS functions.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Dec 16 15:32:08 UTC 2019 on sn-devel-184
This commit is contained in:
Jeremy Allison 2019-12-13 11:48:05 -08:00 committed by Ralph Boehme
parent cc1ec0a9f1
commit af2d54bfce
2 changed files with 68 additions and 27 deletions

View File

@ -1357,38 +1357,38 @@ static bool junction_to_local_path_tos(const struct junction_map *jucn,
return True;
}
bool create_msdfs_link(const struct junction_map *jucn)
{
TALLOC_CTX *frame = talloc_stackframe();
char *path = NULL;
char *msdfs_link = NULL;
connection_struct *conn;
size_t i = 0;
bool insert_comma = False;
bool ret = False;
struct smb_filename *smb_fname = NULL;
bool ok;
int retval;
/*
* Create a msdfs string in Samba format we can store
* in a filesystem object (currently a symlink).
*/
ok = junction_to_local_path_tos(jucn, &path, &conn);
if (!ok) {
TALLOC_FREE(frame);
return False;
}
char *msdfs_link_string(TALLOC_CTX *ctx,
const struct referral *reflist,
size_t referral_count)
{
char *refpath = NULL;
bool insert_comma = false;
char *msdfs_link = NULL;
size_t i;
/* Form the msdfs_link contents */
msdfs_link = talloc_strdup(conn, "msdfs:");
if (!msdfs_link) {
goto out;
msdfs_link = talloc_strdup(ctx, "msdfs:");
if (msdfs_link == NULL) {
goto err;
}
for(i=0; i<jucn->referral_count; i++) {
char *refpath = jucn->referral_list[i].alternate_path;
for( i= 0; i < referral_count; i++) {
refpath = talloc_strdup(ctx, reflist[i].alternate_path);
if (refpath == NULL) {
goto err;
}
/* Alternate paths always use Windows separators. */
trim_char(refpath, '\\', '\\');
if(*refpath == '\0') {
if (*refpath == '\0') {
if (i == 0) {
insert_comma = False;
insert_comma = false;
}
continue;
}
@ -1402,12 +1402,49 @@ bool create_msdfs_link(const struct junction_map *jucn)
refpath);
}
if (!msdfs_link) {
goto out;
if (msdfs_link == NULL) {
goto err;
}
if (!insert_comma) {
insert_comma = True;
insert_comma = true;
}
TALLOC_FREE(refpath);
}
return msdfs_link;
err:
TALLOC_FREE(refpath);
TALLOC_FREE(msdfs_link);
return NULL;
}
bool create_msdfs_link(const struct junction_map *jucn)
{
TALLOC_CTX *frame = talloc_stackframe();
char *path = NULL;
char *msdfs_link = NULL;
connection_struct *conn;
bool ret = False;
struct smb_filename *smb_fname = NULL;
bool ok;
int retval;
ok = junction_to_local_path_tos(jucn, &path, &conn);
if (!ok) {
TALLOC_FREE(frame);
return False;
}
/* Form the msdfs_link contents */
msdfs_link = msdfs_link_string(frame,
jucn->referral_list,
jucn->referral_count);
if (msdfs_link == NULL) {
goto out;
}
DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n",

View File

@ -486,6 +486,10 @@ bool create_junction(TALLOC_CTX *ctx,
const char *dfs_path,
bool allow_broken_path,
struct junction_map *jucn);
struct referral;
char *msdfs_link_string(TALLOC_CTX *ctx,
const struct referral *reflist,
size_t referral_count);
bool create_msdfs_link(const struct junction_map *jucn);
bool remove_msdfs_link(const struct junction_map *jucn);
struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx, size_t *p_num_jn);