From 8d1e7fb88aeb1ac5e166a73ebe8d8781d7f48468 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 14 Nov 2013 12:23:15 -0800 Subject: [PATCH] cpdup - Add another way to prevent host:path misintepretation * Allow a local file or directory name to be prefixed with localhost: to prevent colons in the filename from being misinterpreted as a remote-host specification. This is in addition to the nominal absolute-path method to prevent misinterpretation (a '/' occuring before any ':' prevents misinterpretation of the ':' as a remote-host specification) --- bin/cpdup/cpdup.1 | 8 ++++++++ bin/cpdup/cpdup.c | 17 ++++++++++++----- bin/cpdup/misc.c | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/cpdup/cpdup.1 b/bin/cpdup/cpdup.1 index 075aca8f93..f3d3a30949 100644 --- a/bin/cpdup/cpdup.1 +++ b/bin/cpdup/cpdup.1 @@ -278,6 +278,14 @@ while denotes the directory .Ql foo:bar on the local machine. +.Pp +.Nm +also supports a +.Ql localhost: +prefix which is silently discarded but prevents any colons in the remainder +of the path from being interpreted as a host:path form. +this form can be used with relative filenames when you do not want colons in +the filename to be misinterpreted. .Sh DIAGNOSTICS The .Nm diff --git a/bin/cpdup/cpdup.c b/bin/cpdup/cpdup.c index f3b8a83cea..2ad8391b76 100644 --- a/bin/cpdup/cpdup.c +++ b/bin/cpdup/cpdup.c @@ -111,7 +111,7 @@ static void ResetList(List *list); static Node *IterateList(List *list, Node *node, int n); static int AddList(List *list, const char *name, int n, struct stat *st); static int getbool(const char *str); -static char *SplitRemote(char *path); +static char *SplitRemote(char **pathp); static int ChgrpAllowed(gid_t g); static int OwnerMatch(struct stat *st1, struct stat *st2); #ifdef _ST_FLAGS_PRESENT_ @@ -309,7 +309,7 @@ main(int ac, char **av) * Extract the source and/or/neither target [user@]host and * make any required connections. */ - if (src && (ptr = SplitRemote(src)) != NULL) { + if (src && (ptr = SplitRemote(&src)) != NULL) { SrcHost.host = src; src = ptr; if (UseMD5Opt) @@ -319,7 +319,7 @@ main(int ac, char **av) } else if (ReadOnlyOpt) fatal("The -R option is only supported for remote sources"); - if (dst && (ptr = SplitRemote(dst)) != NULL) { + if (dst && (ptr = SplitRemote(&dst)) != NULL) { DstHost.host = dst; dst = ptr; if (UseFSMIDOpt) @@ -428,15 +428,22 @@ getbool(const char *str) * If a remote path is detected, the colon is replaced with a null byte, * and the return value is a pointer to the next character. * Otherwise NULL is returned. + * + * A path prefix of localhost is the same as a locally specified file or + * directory path, but prevents any further interpretation of the path + * as being a remote hostname (for paths that have colons in them). */ static char * -SplitRemote(char *path) +SplitRemote(char **pathp) { int cindex; + char *path = *pathp; if (path[(cindex = strcspn(path, ":/"))] == ':') { path[cindex++] = 0; - return (path + cindex); + if (strcmp(path, "localhost") != 0) + return (path + cindex); + *pathp = path + cindex; } return (NULL); } diff --git a/bin/cpdup/misc.c b/bin/cpdup/misc.c index 1bc7bfdd6a..692d70c4e0 100644 --- a/bin/cpdup/misc.c +++ b/bin/cpdup/misc.c @@ -200,7 +200,7 @@ fatal(const char *ctl, ...) " -VV same as -V but ignore mtime entirely\n" " -x use .cpignore as exclusion file\n" " -X file specify exclusion file\n" - " Version 1.18 by Matt Dillon, Dima Ruban, & Oliver Fromme\n" + " Version 1.19 by Matt Dillon, Dima Ruban, & Oliver Fromme\n" ); exit(0); } else { -- 2.41.0