2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* compatability routines for older rsync protocol versions */
26 extern int csum_length;
28 extern int preserve_links;
29 extern int preserve_perms;
30 extern int preserve_devices;
31 extern int preserve_uid;
32 extern int preserve_gid;
33 extern int preserve_times;
34 extern int always_checksum;
35 extern int checksum_seed;
38 extern int remote_version;
40 void (*send_file_entry)(struct file_struct *file,int f) = NULL;
41 void (*receive_file_entry)(struct file_struct *file,
42 unsigned char flags,int f) = NULL;
45 void send_file_entry_v10(struct file_struct *file,int f)
48 static mode_t last_mode=0;
49 static dev_t last_rdev=0;
50 static uid_t last_uid=0;
51 static gid_t last_gid=0;
52 static char lastdir[MAXPATHLEN]="";
64 if (file->mode == last_mode) flags |= SAME_MODE;
65 if (file->rdev == last_rdev) flags |= SAME_RDEV;
66 if (file->uid == last_uid) flags |= SAME_UID;
67 if (file->gid == last_gid) flags |= SAME_GID;
69 if (strncmp(file->name,lastdir,strlen(lastdir)) == 0) {
71 p = file->name + strlen(lastdir);
78 write_byte(f,strlen(p));
80 write_int(f,strlen(p));
81 write_buf(f,p,strlen(p));
82 write_int(f,(int)file->modtime);
83 write_int(f,(int)file->length);
84 if (!(flags & SAME_MODE))
85 write_int(f,(int)file->mode);
86 if (preserve_uid && !(flags & SAME_UID))
87 write_int(f,(int)file->uid);
88 if (preserve_gid && !(flags & SAME_GID))
89 write_int(f,(int)file->gid);
90 if (preserve_devices && IS_DEVICE(file->mode) && !(flags & SAME_RDEV))
91 write_int(f,(int)file->rdev);
94 if (preserve_links && S_ISLNK(file->mode)) {
95 write_int(f,strlen(file->link));
96 write_buf(f,file->link,strlen(file->link));
100 if (always_checksum) {
101 write_buf(f,file->sum,csum_length);
104 last_mode = file->mode;
105 last_rdev = file->rdev;
106 last_uid = file->uid;
107 last_gid = file->gid;
108 p = strrchr(file->name,'/');
110 int l = (int)(p - file->name) + 1;
111 strncpy(lastdir,file->name,l);
120 void receive_file_entry_v10(struct file_struct *file,
121 unsigned char flags,int f)
123 static mode_t last_mode=0;
124 static dev_t last_rdev=0;
125 static uid_t last_uid=0;
126 static gid_t last_gid=0;
127 static char lastdir[MAXPATHLEN]="";
131 if (flags & SAME_DIR) {
133 l2 = strlen(lastdir);
139 file->name = (char *)malloc(l1+l2+1);
140 if (!file->name) out_of_memory("receive_file_entry");
142 strncpy(file->name,lastdir,l2);
143 read_buf(f,file->name+l2,l1);
144 file->name[l1+l2] = 0;
146 file->modtime = (time_t)read_int(f);
147 file->length = (off_t)read_int(f);
148 file->mode = (flags & SAME_MODE) ? last_mode : (mode_t)read_int(f);
150 file->uid = (flags & SAME_UID) ? last_uid : (uid_t)read_int(f);
152 file->gid = (flags & SAME_GID) ? last_gid : (gid_t)read_int(f);
153 if (preserve_devices && IS_DEVICE(file->mode))
154 file->rdev = (flags & SAME_RDEV) ? last_rdev : (dev_t)read_int(f);
157 if (preserve_links && S_ISLNK(file->mode)) {
159 file->link = (char *)malloc(l+1);
160 if (!file->link) out_of_memory("receive_file_entry");
161 read_buf(f,file->link,l);
167 read_buf(f,file->sum,csum_length);
169 last_mode = file->mode;
170 last_rdev = file->rdev;
171 last_uid = file->uid;
172 last_gid = file->gid;
173 p = strrchr(file->name,'/');
175 int l = (int)(p - file->name) + 1;
176 strncpy(lastdir,file->name,l);
186 void setup_protocol(int f_out,int f_in)
189 remote_version = read_int(f_in);
190 write_int(f_out,PROTOCOL_VERSION);
193 write_int(f_out,PROTOCOL_VERSION);
195 remote_version = read_int(f_in);
198 if (remote_version < MIN_PROTOCOL_VERSION ||
199 remote_version > MAX_PROTOCOL_VERSION) {
200 fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
204 if (remote_version == 10) {
205 send_file_entry = send_file_entry_v10;
206 receive_file_entry = receive_file_entry_v10;
208 send_file_entry = send_file_entry_v11;
209 receive_file_entry = receive_file_entry_v11;
212 if (remote_version >= 12) {
214 checksum_seed = time(NULL);
215 write_int(f_out,checksum_seed);
217 checksum_seed = read_int(f_in);