1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3: client: Add new utility function client_clean_name().

Correctly canonicalizes a remote pathname removing '..'
elements before sending to a remote server. '..' elements
work in SMB1 pathnames, but not in SMB2.

Not yet used.

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Jeremy Allison 2017-10-21 00:08:08 +00:00
parent 65442e1714
commit d4d9d1941b
2 changed files with 32 additions and 0 deletions

View File

@ -345,6 +345,37 @@ static void normalize_name(char *newdir)
}
}
/****************************************************************************
Local name cleanup before sending to server. SMB1 allows relative pathnames,
but SMB2 does not, so we need to resolve them locally.
****************************************************************************/
char *client_clean_name(TALLOC_CTX *ctx, const char *name)
{
char *newname = NULL;
if (name == NULL) {
return NULL;
}
/* First ensure any path separators are correct. */
newname = talloc_strdup(ctx, name);
if (newname == NULL) {
return NULL;
}
normalize_name(newname);
/* Now remove any relative (..) path components. */
if (cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
newname = unix_clean_name(ctx, newname);
} else {
newname = clean_name(ctx, newname);
}
if (newname == NULL) {
return NULL;
}
return newname;
}
/****************************************************************************
Change directory - inner section.
****************************************************************************/

View File

@ -35,6 +35,7 @@ enum {
const char *client_get_cur_dir(void);
const char *client_set_cur_dir(const char *newdir);
char *client_clean_name(TALLOC_CTX *ctx, const char *name);
NTSTATUS do_list(const char *mask,
uint16_t attribute,
NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,