MCPcopy Create free account
hub / github.com/RsyncProject/rsync / exchange_protocols

Function exchange_protocols

clientserver.c:152–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152static int exchange_protocols(int f_in, int f_out, char *buf, size_t bufsiz, int am_client)
153{
154 int remote_sub = -1;
155 int our_sub = get_subprotocol_version();
156
157 output_daemon_greeting(f_out, am_client);
158 if (!am_client) {
159 char *motd = lp_motd_file();
160 if (motd && *motd) {
161 FILE *f = fopen(motd, "r");
162 while (f && !feof(f)) {
163 int len = fread(buf, 1, bufsiz - 1, f);
164 if (len > 0)
165 write_buf(f_out, buf, len);
166 }
167 if (f)
168 fclose(f);
169 write_sbuf(f_out, "\n");
170 }
171 }
172
173 /* This strips the \n. */
174 if (!read_line_old(f_in, buf, bufsiz, 0)) {
175 if (am_client)
176 rprintf(FERROR, "rsync: did not see server greeting\n");
177 return -1;
178 }
179
180 if (sscanf(buf, "@RSYNCD: %d.%d", &remote_protocol, &remote_sub) < 1) {
181 if (am_client)
182 rprintf(FERROR, "rsync: server sent \"%s\" rather than greeting\n", buf);
183 else
184 io_printf(f_out, "@ERROR: protocol startup error\n");
185 return -1;
186 }
187
188 if (remote_sub < 0) {
189 if (remote_protocol >= 30) {
190 if (am_client)
191 rprintf(FERROR, "rsync: the server omitted the subprotocol value: %s\n", buf);
192 else
193 io_printf(f_out, "@ERROR: your client omitted the subprotocol value: %s\n", buf);
194 return -1;
195 }
196 remote_sub = 0;
197 }
198
199 daemon_auth_choices = strchr(buf + 9, ' ');
200 if (daemon_auth_choices) {
201 char *cp;
202 daemon_auth_choices = strdup(daemon_auth_choices + 1);
203 if ((cp = strchr(daemon_auth_choices, '\n')) != NULL)
204 *cp = '\0';
205 } else if (remote_protocol > 31) {
206 if (am_client)
207 rprintf(FERROR, "rsync: the server omitted the digest name list: %s\n", buf);
208 else
209 io_printf(f_out, "@ERROR: your client omitted the digest name list: %s\n", buf);

Callers 2

start_inband_exchangeFunction · 0.85
start_daemonFunction · 0.85

Calls 7

get_subprotocol_versionFunction · 0.85
output_daemon_greetingFunction · 0.85
write_bufFunction · 0.85
write_sbufFunction · 0.85
read_line_oldFunction · 0.85
io_printfFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected