X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/d030233def34a2a9e0def097c0a87f5fdc481051..0ee6ca9800ef1f044a235804f07ab25f1e46e19d:/flist.c diff --git a/flist.c b/flist.c index 11473dc0..a9354b9c 100644 --- a/flist.c +++ b/flist.c @@ -62,10 +62,13 @@ extern struct file_list *the_file_list; extern char curr_dir[MAXPATHLEN]; +extern struct chmod_mode_struct *chmod_modes; + extern struct filter_list_struct filter_list; extern struct filter_list_struct server_filter_list; int io_error; +int checksum_len; dev_t filesystem_dev; /* used to implement -x */ static char empty_sum[MD4_SUM_LENGTH]; @@ -82,6 +85,7 @@ void init_flist(void) /* Figure out how big the file_struct is without trailing padding */ file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags; + checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH; } static int show_filelist_p(void) @@ -139,14 +143,14 @@ static void list_file_entry(struct file_struct *f) rprintf(FINFO, "%s %11.0f %s %s -> %s\n", perms, (double)f->length, timestring(f->modtime), - safe_fname(f_name(f)), safe_fname(f->u.link)); + f_name(f), f->u.link); } else #endif { rprintf(FINFO, "%s %11.0f %s %s\n", perms, (double)f->length, timestring(f->modtime), - safe_fname(f_name(f))); + f_name(f)); } } @@ -179,7 +183,7 @@ static int readlink_stat(const char *path, STRUCT_STAT *buffer, char *linkbuf) if (copy_unsafe_links && unsafe_symlink(linkbuf, path)) { if (verbose > 1) { rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n", - safe_fname(path), safe_fname(linkbuf)); + path, linkbuf); } return do_stat(path, buffer); } @@ -473,14 +477,13 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags) if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) { char *sum; - int slen = protocol_version < 21 ? 2 : MD4_SUM_LENGTH; if (S_ISREG(mode)) sum = file->u.sum; else { /* Prior to 28, we sent a useless set of nulls. */ sum = empty_sum; } - write_buf(f, sum, slen); + write_buf(f, sum, checksum_len); } strlcpy(lastname, fname, MAXPATHLEN); @@ -531,7 +534,7 @@ static struct file_struct *receive_file_entry(struct file_list *flist, if (l2 >= MAXPATHLEN - l1) { rprintf(FERROR, "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n", - flags, l1, l2, safe_fname(lastname)); + flags, l1, l2, lastname); overflow_exit("receive_file_entry"); } @@ -696,7 +699,6 @@ static struct file_struct *receive_file_entry(struct file_list *flist, if (always_checksum && (sum_len || protocol_version < 28)) { char *sum; - int slen = protocol_version < 21 ? 2 : MD4_SUM_LENGTH; if (sum_len) { file->u.sum = sum = bp; /*bp += sum_len;*/ @@ -704,7 +706,7 @@ static struct file_struct *receive_file_entry(struct file_list *flist, /* Prior to 28, we get a useless set of nulls. */ sum = empty_sum; } - read_buf(f, sum, slen); + read_buf(f, sum, checksum_len); } if (!preserve_perms) { @@ -750,8 +752,7 @@ struct file_struct *make_file(char *fname, struct file_list *flist, if (strlcpy(thisname, fname, sizeof thisname) >= sizeof thisname - flist_dir_len) { - rprintf(FINFO, "skipping overly long name: %s\n", - safe_fname(fname)); + rprintf(FINFO, "skipping overly long name: %s\n", fname); return NULL; } clean_fname(thisname, 0); @@ -796,7 +797,7 @@ struct file_struct *make_file(char *fname, struct file_list *flist, goto skip_filters; if (S_ISDIR(st.st_mode) && !xfer_dirs) { - rprintf(FINFO, "skipping directory %s\n", safe_fname(thisname)); + rprintf(FINFO, "skipping directory %s\n", thisname); return NULL; } @@ -818,11 +819,11 @@ struct file_struct *make_file(char *fname, struct file_list *flist, return NULL; } -skip_filters: + skip_filters: if (verbose > 2) { rprintf(FINFO, "[%s] make_file(%s,*,%d)\n", - who_am_i(), safe_fname(thisname), filter_level); + who_am_i(), thisname, filter_level); } if ((basename = strrchr(thisname, '/')) != NULL) { @@ -846,7 +847,8 @@ skip_filters: linkname_len = 0; #endif - sum_len = always_checksum && S_ISREG(st.st_mode) ? MD4_SUM_LENGTH : 0; + sum_len = always_checksum && am_sender && S_ISREG(st.st_mode) + ? MD4_SUM_LENGTH : 0; alloc_len = file_struct_len + dirname_len + basename_len + linkname_len + sum_len; @@ -865,7 +867,10 @@ skip_filters: file->flags = flags; file->modtime = st.st_mtime; file->length = st.st_size; - file->mode = st.st_mode; + if (chmod_modes && am_sender && (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))) + file->mode = tweak_mode(st.st_mode, chmod_modes); + else + file->mode = st.st_mode; file->uid = st.st_uid; file->gid = st.st_gid; @@ -968,9 +973,10 @@ static struct file_struct *send_file_name(int f, struct file_list *flist, } static void send_if_directory(int f, struct file_list *flist, - struct file_struct *file) + struct file_struct *file, + char *fbuf, unsigned int ol) { - char fbuf[MAXPATHLEN]; + char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/'); if (S_ISDIR(file->mode) && !(file->flags & FLAG_MOUNT_POINT) && f_name_to(file, fbuf)) { @@ -987,6 +993,9 @@ static void send_if_directory(int f, struct file_list *flist, save_filters = push_local_filters(fbuf, len); send_directory(f, flist, fbuf, len); pop_local_filters(save_filters); + fbuf[ol] = '\0'; + if (is_dot_dir) + fbuf[ol-1] = '.'; } } @@ -1021,14 +1030,14 @@ static void send_directory(int f, struct file_list *flist, if (dname[0] == '.' && (dname[1] == '\0' || (dname[1] == '.' && dname[2] == '\0'))) continue; - if (strlcpy(p, dname, remainder) < remainder) - send_file_name(f, flist, fbuf, 0); - else { + if (strlcpy(p, dname, remainder) >= remainder) { io_error |= IOERR_GENERAL; rprintf(FINFO, "cannot send long-named file %s\n", full_fname(fbuf)); } + + send_file_name(f, flist, fbuf, 0); } fbuf[len] = '\0'; @@ -1043,13 +1052,13 @@ static void send_directory(int f, struct file_list *flist, if (recurse) { int i, end = flist->count - 1; for (i = start; i <= end; i++) - send_if_directory(f, flist, flist->files[i]); + send_if_directory(f, flist, flist->files[i], fbuf, len); } } struct file_list *send_file_list(int f, int argc, char *argv[]) { - int l; + int len; STRUCT_STAT st; char *p, *dir, olddir[sizeof curr_dir]; char lastpath[MAXPATHLEN] = ""; @@ -1077,57 +1086,56 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) } while (1) { - char fname2[MAXPATHLEN]; - char *fname = fname2; + char fbuf[MAXPATHLEN]; + char *fn; int is_dot_dir; if (use_ff_fd) { - if (read_filesfrom_line(filesfrom_fd, fname) == 0) + if (read_filesfrom_line(filesfrom_fd, fbuf) == 0) break; - sanitize_path(fname, fname, "", 0); + sanitize_path(fbuf, fbuf, "", 0); } else { if (argc-- == 0) break; - strlcpy(fname, *argv++, MAXPATHLEN); + strlcpy(fbuf, *argv++, MAXPATHLEN); if (sanitize_paths) - sanitize_path(fname, fname, "", 0); + sanitize_path(fbuf, fbuf, "", 0); } - l = strlen(fname); - if (!l || fname[l - 1] == '/') { - if (l == 2 && fname[0] == '.') { + len = strlen(fbuf); + if (!len || fbuf[len - 1] == '/') { + if (len == 2 && fbuf[0] == '.') { /* Turn "./" into just "." rather than "./." */ - fname[1] = '\0'; + fbuf[1] = '\0'; } else { - if (l + 1 >= MAXPATHLEN) + if (len + 1 >= MAXPATHLEN) overflow_exit("send_file_list"); - fname[l++] = '.'; - fname[l] = '\0'; + fbuf[len++] = '.'; + fbuf[len] = '\0'; } is_dot_dir = 1; - } else if (l > 1 && fname[l-1] == '.' && fname[l-2] == '.' - && (l == 2 || fname[l-3] == '/')) { - if (l + 2 >= MAXPATHLEN) + } else if (len > 1 && fbuf[len-1] == '.' && fbuf[len-2] == '.' + && (len == 2 || fbuf[len-3] == '/')) { + if (len + 2 >= MAXPATHLEN) overflow_exit("send_file_list"); - fname[l++] = '/'; - fname[l++] = '.'; - fname[l] = '\0'; + fbuf[len++] = '/'; + fbuf[len++] = '.'; + fbuf[len] = '\0'; is_dot_dir = 1; } else { - is_dot_dir = fname[l-1] == '.' - && (l == 1 || fname[l-2] == '/'); + is_dot_dir = fbuf[len-1] == '.' + && (len == 1 || fbuf[len-2] == '/'); } - if (link_stat(fname, &st, keep_dirlinks) != 0) { + if (link_stat(fbuf, &st, keep_dirlinks) != 0) { io_error |= IOERR_GENERAL; rsyserr(FERROR, errno, "link_stat %s failed", - full_fname(fname)); + full_fname(fbuf)); continue; } if (S_ISDIR(st.st_mode) && !xfer_dirs) { - rprintf(FINFO, "skipping directory %s\n", - safe_fname(fname)); + rprintf(FINFO, "skipping directory %s\n", fbuf); continue; } @@ -1135,26 +1143,32 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) olddir[0] = '\0'; if (!relative_paths) { - p = strrchr(fname, '/'); + p = strrchr(fbuf, '/'); if (p) { *p = '\0'; - if (p == fname) + if (p == fbuf) dir = "/"; else - dir = fname; - fname = p + 1; - } - } else if ((p = strstr(fname, "/./")) != NULL) { + dir = fbuf; + len -= p - fbuf + 1; + fn = p + 1; + } else + fn = fbuf; + } else if ((p = strstr(fbuf, "/./")) != NULL) { *p = '\0'; - if (p == fname) + if (p == fbuf) dir = "/"; else - dir = fname; - fname = p + 3; - } + dir = fbuf; + len -= p - fbuf + 3; + fn = p + 3; + } else + fn = fbuf; - if (!*fname) - fname = "."; + if (!*fn) { + len = 1; + fn = "."; + } if (dir && *dir) { static char *lastdir; @@ -1178,17 +1192,19 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) } } - if (implied_dirs && (p=strrchr(fname,'/')) && p != fname) { + if (fn != fbuf) + memmove(fbuf, fn, len + 1); + + if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) { /* Send the implied directories at the start of the * source spec, so we get their permissions right. */ - char *lp = lastpath, *fn = fname, *slash = fname; + char *lp = lastpath, *slash = fbuf; *p = '\0'; /* Skip any initial directories in our path that we * have in common with lastpath. */ - while (*fn && *lp == *fn) { + for (fn = fbuf; *fn && *lp == *fn; lp++, fn++) { if (*fn == '/') slash = fn; - lp++, fn++; } *p = '/'; if (fn != p || (*lp && *lp != '/')) { @@ -1198,13 +1214,13 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) xfer_dirs = 1; while ((slash = strchr(slash+1, '/')) != 0) { *slash = '\0'; - send_file_name(f, flist, fname, 0); + send_file_name(f, flist, fbuf, 0); *slash = '/'; } copy_links = save_copy_links; xfer_dirs = save_xfer_dirs; *p = '\0'; - strlcpy(lastpath, fname, sizeof lastpath); + strlcpy(lastpath, fbuf, sizeof lastpath); *p = '/'; } } @@ -1214,10 +1230,10 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) if (recurse || (xfer_dirs && is_dot_dir)) { struct file_struct *file; - if ((file = send_file_name(f, flist, fname, XMIT_TOP_DIR))) - send_if_directory(f, flist, file); + if ((file = send_file_name(f, flist, fbuf, XMIT_TOP_DIR))) + send_if_directory(f, flist, file, fbuf, len); } else - send_file_name(f, flist, fname, 0); + send_file_name(f, flist, fbuf, 0); if (olddir[0]) { flist_dir = NULL; @@ -1296,7 +1312,6 @@ struct file_list *recv_file_list(int f) if (!flist->files) goto oom; - while ((flags = read_byte(f)) != 0) { struct file_struct *file; @@ -1313,10 +1328,8 @@ struct file_list *recv_file_list(int f) maybe_emit_filelist_progress(flist->count); - if (verbose > 2) { - rprintf(FINFO, "recv_file_name(%s)\n", - safe_fname(f_name(file))); - } + if (verbose > 2) + rprintf(FINFO, "recv_file_name(%s)\n", f_name(file)); } receive_file_entry(NULL, 0, 0); /* Signal that we're done. */ @@ -1357,7 +1370,7 @@ struct file_list *recv_file_list(int f) return flist; -oom: + oom: out_of_memory("recv_file_list"); return NULL; /* not reached */ } @@ -1507,7 +1520,7 @@ static void clean_flist(struct file_list *flist, int strip_root, int no_dups) if (verbose > 1 && !am_server) { rprintf(FINFO, "removing duplicate name %s from file list (%d)\n", - safe_fname(f_name(file)), drop); + f_name(file), drop); } /* Make sure that if we unduplicate '.', that we don't * lose track of a user-specified top directory. */ @@ -1571,7 +1584,7 @@ static void output_flist(struct file_list *flist) sprintf(depthbuf, "%d", file->dir.depth); rprintf(FINFO, "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n", who, i, am_sender ? NS(file->dir.root) : depthbuf, - file->dirname ? safe_fname(file->dirname) : "", + file->dirname ? file->dirname : "", file->dirname ? "/" : "", NS(file->basename), S_ISDIR(file->mode) ? "/" : "", (int)file->mode, (double)file->length, uidbuf, gidbuf, file->flags); @@ -1740,6 +1753,7 @@ char *f_name_to(struct file_struct *f, char *fbuf) strcpy(fbuf + len + 1, f->basename); } else strcpy(fbuf, f->basename); + return fbuf; }