Clarify the short description of --chmod.
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index 337aa83..72e0859 100644 (file)
--- a/util.c
+++ b/util.c
@@ -92,7 +92,7 @@ int fd_pair(int fd[2])
 
 void print_child_argv(char **cmd)
 {
-       rprintf(FINFO, "opening connection using ");
+       rprintf(FCLIENT, "opening connection using ");
        for (; *cmd; cmd++) {
                /* Look for characters that ought to be quoted.  This
                * is not a great quoting algorithm, but it's
@@ -101,23 +101,23 @@ void print_child_argv(char **cmd)
                           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                           "0123456789"
                           ",.-_=+@/") != strlen(*cmd)) {
-                       rprintf(FINFO, "\"%s\" ", *cmd);
+                       rprintf(FCLIENT, "\"%s\" ", *cmd);
                } else {
-                       rprintf(FINFO, "%s ", *cmd);
+                       rprintf(FCLIENT, "%s ", *cmd);
                }
        }
-       rprintf(FINFO, "\n");
+       rprintf(FCLIENT, "\n");
 }
 
 void out_of_memory(char *str)
 {
-       rprintf(FERROR, "ERROR: out of memory in %s\n", str);
+       rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
 void overflow_exit(char *str)
 {
-       rprintf(FERROR, "ERROR: buffer overflow in %s\n", str);
+       rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
@@ -922,7 +922,8 @@ void die_on_unsafe_path(char *path, int strip_filename)
                if ((p = strchr(p, '/')) != NULL)
                        *p = '\0';
                if (safe_stat(path, &st) < 0) {
-                       *p++ = '/';
+                       if (p)
+                               *p = '/';
                        goto done;
                }
                if (S_ISLNK(st.st_mode)) {
@@ -943,7 +944,7 @@ void die_on_unsafe_path(char *path, int strip_filename)
 /* Like chdir(), but it keeps track of the current directory (in the
  * global "curr_dir"), and ensures that the path size doesn't overflow.
  * Also cleans the path using the clean_fname() function. */
-int push_dir(char *dir)
+int push_dir(char *dir, int set_path_only)
 {
        static int initialised;
        unsigned int len;
@@ -964,7 +965,7 @@ int push_dir(char *dir)
        if ((*dir == '/' ? len : curr_dir_len + 1 + len) >= sizeof curr_dir)
                return 0;
 
-       if (chdir(dir))
+       if (!set_path_only && chdir(dir))
                return 0;
 
        if (*dir == '/') {
@@ -1021,7 +1022,7 @@ char *full_fname(const char *fn)
        if (*fn == '/')
                p1 = p2 = "";
        else {
-               p1 = curr_dir;
+               p1 = curr_dir + module_dirlen;
                for (p2 = p1; *p2 == '/'; p2++) {}
                if (*p2)
                        p2 = "/";
@@ -1030,17 +1031,11 @@ char *full_fname(const char *fn)
                m1 = " (in ";
                m2 = lp_name(module_id);
                m3 = ")";
-               if (p1 == curr_dir) {
-                       if (!lp_use_chroot(module_id)) {
-                               char *p = lp_path(module_id);
-                               if (*p != '/' || p[1])
-                                       p1 += strlen(p);
-                       }
-               }
        } else
                m1 = m2 = m3 = "";
 
-       asprintf(&result, "\"%s%s%s\"%s%s%s", p1, p2, fn, m1, m2, m3);
+       if (asprintf(&result, "\"%s%s%s\"%s%s%s", p1, p2, fn, m1, m2, m3) <= 0)
+               out_of_memory("full_fname");
 
        return result;
 }
@@ -1066,13 +1061,11 @@ char *partial_dir_fname(const char *fname)
        if ((int)pathjoin(t, sz, partial_dir, fn) >= sz)
                return NULL;
        if (server_filter_list.head) {
-               static int len;
-               if (!len)
-                       len = strlen(partial_dir);
-               t[len] = '\0';
+               t = strrchr(partial_fname, '/');
+               *t = '\0';
                if (check_filter(&server_filter_list, partial_fname, 1) < 0)
                        return NULL;
-               t[len] = '/';
+               *t = '/';
                if (check_filter(&server_filter_list, partial_fname, 0) < 0)
                        return NULL;
        }
@@ -1098,6 +1091,8 @@ int handle_partial_dir(const char *fname, int create)
        if (create) {
                STRUCT_STAT st;
                int statret = do_lstat(dir, &st);
+               if (sanitize_paths && *partial_dir != '/')
+                       die_on_unsafe_path(dir, 1); /* lstat handles last element */
                if (statret == 0 && !S_ISDIR(st.st_mode)) {
                        if (do_unlink(dir) < 0)
                                return 0;