]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: client: Add new utility function client_clean_name().
authorJeremy Allison <jra@samba.org>
Sat, 21 Oct 2017 00:08:08 +0000 (00:08 +0000)
committerKarolin Seeger <kseeger@samba.org>
Thu, 2 Nov 2017 12:01:21 +0000 (13:01 +0100)
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>
(cherry picked from commit d4d9d1941bdac9993968c34cf928c645e4152fd3)

source3/client/client.c
source3/client/client_proto.h

index f808c9cf2c94b4d0e1e3cbacda457ec4e89ba11d..7ac87299b5f1e6cbf829dd8a19d2d1cf5242f24e 100644 (file)
@@ -348,6 +348,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.
 ****************************************************************************/
index d3d40363f20cd524e98dfdd8664c9a71a23d43f4..38f13aa0adc85bb26dffe79fea5ef5c97144f9a9 100644 (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 *,