1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

s3: smbd: Remove use of 'struct dfs_path'. Not needed for a (hostname, servicename, path) tuple.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15144

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Jeremy Allison 2022-08-10 11:17:49 -07:00
parent 2df8a8ab87
commit f92711f000

View File

@ -62,24 +62,20 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
connection_struct *conn, connection_struct *conn,
const char *pathname, const char *pathname,
bool allow_broken_path, bool allow_broken_path,
struct dfs_path *pdp) /* MUST BE TALLOCED */ char **_hostname,
char **_servicename,
char **_remaining_path)
{ {
const struct loadparm_substitution *lp_sub = const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution(); loadparm_s3_global_substitution();
char *pathname_local; char *hostname = NULL;
char *p; char *pathname_local = NULL;
char *servicename; char *p = NULL;
char *eos_ptr; char *servicename = NULL;
char *reqpath = NULL;
char *eos_ptr = NULL;
ZERO_STRUCTP(pdp); pathname_local = talloc_strdup(ctx, pathname);
/*
* This is the only talloc we should need to do
* on the struct dfs_path. All the pointers inside
* it should point to offsets within this string.
*/
pathname_local = talloc_strdup(pdp, pathname);
if (pathname_local == NULL) { if (pathname_local == NULL) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
@ -109,8 +105,8 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
* to cope with known broken SMB1 clients. * to cope with known broken SMB1 clients.
*/ */
pdp->hostname = eos_ptr; /* "" */ hostname = eos_ptr; /* "" */
pdp->servicename = eos_ptr; /* "" */ servicename = eos_ptr; /* "" */
DBG_ERR("trying to convert %s to a local path\n", p); DBG_ERR("trying to convert %s to a local path\n", p);
goto local_path; goto local_path;
@ -134,17 +130,17 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
* Try and convert to a local path. * Try and convert to a local path.
*/ */
pdp->hostname = eos_ptr; /* "" */ hostname = eos_ptr; /* "" */
pdp->servicename = eos_ptr; /* "" */ servicename = eos_ptr; /* "" */
p = pathname_local; p = pathname_local;
DBG_ERR("trying to convert %s to a local path\n", p); DBG_ERR("trying to convert %s to a local path\n", p);
goto local_path; goto local_path;
} }
*p = '\0'; *p = '\0';
pdp->hostname = pathname_local; hostname = pathname_local;
DBG_DEBUG("hostname: %s\n",pdp->hostname); DBG_DEBUG("hostname: %s\n", hostname);
/* Parse out servicename. */ /* Parse out servicename. */
servicename = p+1; servicename = p+1;
@ -165,9 +161,6 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
* Try and convert to a local path. * Try and convert to a local path.
*/ */
pdp->hostname = eos_ptr; /* "" */
pdp->servicename = eos_ptr; /* "" */
/* Repair the path - replace the sepchar's /* Repair the path - replace the sepchar's
we nulled out */ we nulled out */
servicename--; servicename--;
@ -176,20 +169,23 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
*p = '/'; *p = '/';
} }
hostname = eos_ptr; /* "" */
servicename = eos_ptr; /* "" */
p = pathname_local; p = pathname_local;
DBG_ERR("trying to convert %s to a local path\n", DBG_ERR("trying to convert %s to a local path\n",
pathname_local); pathname_local);
goto local_path; goto local_path;
} }
pdp->servicename = servicename; servicename = servicename;
DBG_DEBUG("servicename: %s\n", pdp->servicename); DBG_DEBUG("servicename: %s\n", servicename);
if(p == NULL) { if(p == NULL) {
/* Client sent self referral \server\share. */ /* Client sent self referral \server\share. */
pdp->reqpath = eos_ptr; /* "" */ reqpath = eos_ptr; /* "" */
return NT_STATUS_OK; goto out;
} }
p++; p++;
@ -202,8 +198,31 @@ static NTSTATUS parse_dfs_path(TALLOC_CTX *ctx,
* '/' separators. * '/' separators.
*/ */
pdp->reqpath = p; reqpath = p;
DBG_DEBUG("rest of the path: %s\n", pdp->reqpath);
out:
DBG_DEBUG("rest of the path: %s\n", reqpath);
if (_hostname != NULL) {
*_hostname = talloc_strdup(ctx, hostname);
if (*_hostname == NULL) {
return NT_STATUS_NO_MEMORY;
}
}
if (_servicename != NULL) {
*_servicename = talloc_strdup(ctx, servicename);
if (*_servicename == NULL) {
return NT_STATUS_NO_MEMORY;
}
}
if (_remaining_path != NULL) {
*_remaining_path = talloc_strdup(ctx, reqpath);
if (*_remaining_path == NULL) {
return NT_STATUS_NO_MEMORY;
}
}
TALLOC_FREE(pathname_local);
return NT_STATUS_OK; return NT_STATUS_OK;
} }
@ -663,8 +682,7 @@ bool is_msdfs_link(struct files_struct *dirfsp,
static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx,
connection_struct *conn, connection_struct *conn,
const char *dfspath, /* Incoming complete dfs path */ const char *dfspath, /* Incoming complete dfs path */
const struct dfs_path *pdp, /* Parsed out const char *reqpath, /* Parsed out remaining path. */
server+share+extrapath. */
uint32_t ucf_flags, uint32_t ucf_flags,
NTTIME *_twrp, NTTIME *_twrp,
size_t *consumedcntp, size_t *consumedcntp,
@ -681,7 +699,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx,
components). */ components). */
DEBUG(10,("dfs_path_lookup: Conn path = %s reqpath = %s\n", DEBUG(10,("dfs_path_lookup: Conn path = %s reqpath = %s\n",
conn->connectpath, pdp->reqpath)); conn->connectpath, reqpath));
/* /*
* Note the unix path conversion here we're doing we * Note the unix path conversion here we're doing we
@ -690,7 +708,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx,
* unix_convert later in the codepath. * unix_convert later in the codepath.
*/ */
status = unix_convert(ctx, conn, pdp->reqpath, 0, &smb_fname, status = unix_convert(ctx, conn, reqpath, 0, &smb_fname,
ucf_flags); ucf_flags);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
@ -864,25 +882,23 @@ NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
{ {
const struct loadparm_substitution *lp_sub = const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution(); loadparm_s3_global_substitution();
char *hostname = NULL;
char *servicename = NULL;
char *reqpath = NULL;
NTSTATUS status; NTSTATUS status;
struct dfs_path *pdp = talloc(ctx, struct dfs_path);
if (!pdp) {
return NT_STATUS_NO_MEMORY;
}
status = parse_dfs_path(ctx, status = parse_dfs_path(ctx,
conn, conn,
path_in, path_in,
allow_broken_path, allow_broken_path,
pdp); &hostname,
&servicename,
&reqpath);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(pdp);
return status; return status;
} }
if (pdp->reqpath[0] == '\0') { if (reqpath[0] == '\0') {
TALLOC_FREE(pdp);
*pp_path_out = talloc_strdup(ctx, ""); *pp_path_out = talloc_strdup(ctx, "");
if (!*pp_path_out) { if (!*pp_path_out) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
@ -895,8 +911,7 @@ NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
path and return OK */ path and return OK */
if (!lp_msdfs_root(SNUM(conn))) { if (!lp_msdfs_root(SNUM(conn))) {
*pp_path_out = talloc_strdup(ctx, pdp->reqpath); *pp_path_out = talloc_strdup(ctx, reqpath);
TALLOC_FREE(pdp);
if (!*pp_path_out) { if (!*pp_path_out) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
@ -906,30 +921,27 @@ NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
/* If it looked like a local path (zero hostname/servicename) /* If it looked like a local path (zero hostname/servicename)
* just treat as a tcon-relative path. */ * just treat as a tcon-relative path. */
if (pdp->hostname[0] == '\0' && pdp->servicename[0] == '\0') { if (hostname[0] == '\0' && servicename[0] == '\0') {
*pp_path_out = talloc_strdup(ctx, pdp->reqpath); *pp_path_out = talloc_strdup(ctx, reqpath);
TALLOC_FREE(pdp);
if (!*pp_path_out) { if (!*pp_path_out) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
return NT_STATUS_OK; return NT_STATUS_OK;
} }
if (!( strequal(pdp->servicename, lp_servicename(talloc_tos(), lp_sub, SNUM(conn))) if (!( strequal(servicename, lp_servicename(talloc_tos(), lp_sub, SNUM(conn)))
|| (strequal(pdp->servicename, HOMES_NAME) || (strequal(servicename, HOMES_NAME)
&& strequal(lp_servicename(talloc_tos(), lp_sub, SNUM(conn)), && strequal(lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
conn->session_info->unix_info->sanitized_username) )) ) { conn->session_info->unix_info->sanitized_username) )) ) {
/* The given sharename doesn't match this connection. */ /* The given sharename doesn't match this connection. */
TALLOC_FREE(pdp);
return NT_STATUS_OBJECT_PATH_NOT_FOUND; return NT_STATUS_OBJECT_PATH_NOT_FOUND;
} }
status = dfs_path_lookup(ctx, status = dfs_path_lookup(ctx,
conn, conn,
path_in, path_in,
pdp, reqpath,
ucf_flags, ucf_flags,
_twrp, /* twrp. */ _twrp, /* twrp. */
NULL, /* size_t *consumedcntp */ NULL, /* size_t *consumedcntp */
@ -949,8 +961,7 @@ NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
DEBUG(3,("dfs_redirect: Not redirecting %s.\n", path_in)); DEBUG(3,("dfs_redirect: Not redirecting %s.\n", path_in));
/* Form non-dfs tcon-relative path */ /* Form non-dfs tcon-relative path */
*pp_path_out = talloc_strdup(ctx, pdp->reqpath); *pp_path_out = talloc_strdup(ctx, reqpath);
TALLOC_FREE(pdp);
if (!*pp_path_out) { if (!*pp_path_out) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
@ -1013,14 +1024,10 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
loadparm_s3_global_substitution(); loadparm_s3_global_substitution();
struct conn_struct_tos *c = NULL; struct conn_struct_tos *c = NULL;
struct connection_struct *conn = NULL; struct connection_struct *conn = NULL;
char *servicename = NULL;
char *reqpath = NULL;
int snum; int snum;
NTSTATUS status = NT_STATUS_NOT_FOUND; NTSTATUS status = NT_STATUS_NOT_FOUND;
struct dfs_path *pdp = talloc_zero(frame, struct dfs_path);
if (!pdp) {
TALLOC_FREE(frame);
return NT_STATUS_NO_MEMORY;
}
*self_referralp = False; *self_referralp = False;
@ -1028,14 +1035,16 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
NULL, NULL,
dfs_path, dfs_path,
allow_broken_path, allow_broken_path,
pdp); NULL,
&servicename,
&reqpath);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return status; return status;
} }
jucn->service_name = talloc_strdup(ctx, pdp->servicename); jucn->service_name = talloc_strdup(ctx, servicename);
jucn->volume_name = talloc_strdup(ctx, pdp->reqpath); jucn->volume_name = talloc_strdup(ctx, reqpath);
if (!jucn->service_name || !jucn->volume_name) { if (!jucn->service_name || !jucn->volume_name) {
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
@ -1064,7 +1073,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
if (!lp_msdfs_root(snum) && (*lp_msdfs_proxy(talloc_tos(), lp_sub, snum) == '\0')) { if (!lp_msdfs_root(snum) && (*lp_msdfs_proxy(talloc_tos(), lp_sub, snum) == '\0')) {
DEBUG(3,("get_referred_path: |%s| in dfs path %s is not " DEBUG(3,("get_referred_path: |%s| in dfs path %s is not "
"a dfs root.\n", "a dfs root.\n",
pdp->servicename, dfs_path)); servicename, dfs_path));
TALLOC_FREE(frame); TALLOC_FREE(frame);
return NT_STATUS_NOT_FOUND; return NT_STATUS_NOT_FOUND;
} }
@ -1077,7 +1086,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
* user). Cope with this. * user). Cope with this.
*/ */
if (pdp->reqpath[0] == '\0') { if (reqpath[0] == '\0') {
char *tmp; char *tmp;
struct referral *ref; struct referral *ref;
size_t refcount; size_t refcount;
@ -1158,7 +1167,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
status = dfs_path_lookup(ctx, status = dfs_path_lookup(ctx,
conn, conn,
dfs_path, dfs_path,
pdp, reqpath,
0, /* ucf_flags */ 0, /* ucf_flags */
NULL, NULL,
consumedcntp, consumedcntp,
@ -1271,45 +1280,43 @@ bool create_junction(TALLOC_CTX *ctx,
const struct loadparm_substitution *lp_sub = const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution(); loadparm_s3_global_substitution();
int snum; int snum;
struct dfs_path *pdp = talloc(ctx,struct dfs_path); char *hostname = NULL;
char *servicename = NULL;
char *reqpath = NULL;
NTSTATUS status; NTSTATUS status;
if (!pdp) {
return False;
}
status = parse_dfs_path(ctx, status = parse_dfs_path(ctx,
NULL, NULL,
dfs_path, dfs_path,
allow_broken_path, allow_broken_path,
pdp); &hostname,
&servicename,
&reqpath);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
return False; return False;
} }
/* check if path is dfs : validate first token */ /* check if path is dfs : validate first token */
if (!is_myname_or_ipaddr(pdp->hostname)) { if (!is_myname_or_ipaddr(hostname)) {
DEBUG(4,("create_junction: Invalid hostname %s " DEBUG(4,("create_junction: Invalid hostname %s "
"in dfs path %s\n", "in dfs path %s\n",
pdp->hostname, dfs_path)); hostname, dfs_path));
TALLOC_FREE(pdp);
return False; return False;
} }
/* Check for a non-DFS share */ /* Check for a non-DFS share */
snum = lp_servicenumber(pdp->servicename); snum = lp_servicenumber(servicename);
if(snum < 0 || !lp_msdfs_root(snum)) { if(snum < 0 || !lp_msdfs_root(snum)) {
DEBUG(4,("create_junction: %s is not an msdfs root.\n", DEBUG(4,("create_junction: %s is not an msdfs root.\n",
pdp->servicename)); servicename));
TALLOC_FREE(pdp);
return False; return False;
} }
jucn->service_name = talloc_strdup(ctx, pdp->servicename); jucn->service_name = talloc_strdup(ctx, servicename);
jucn->volume_name = talloc_strdup(ctx, pdp->reqpath); jucn->volume_name = talloc_strdup(ctx, reqpath);
jucn->comment = lp_comment(ctx, lp_sub, snum); jucn->comment = lp_comment(ctx, lp_sub, snum);
TALLOC_FREE(pdp);
if (!jucn->service_name || !jucn->volume_name || ! jucn->comment) { if (!jucn->service_name || !jucn->volume_name || ! jucn->comment) {
return False; return False;
} }