5 /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /* For copying and distribution information, please see the file */
7 /* <mit-copyright.h>. */
10 static char *rcsid_send_file_c = "$Header$";
13 #include <mit-copyright.h>
26 extern CONNECTION conn;
29 extern C_Block session;
33 * (already sent) pathname file_size checksum
34 * <<< (int)code can we send it?
40 * >>> data (last block)
41 * <<< 0 (on final write, close, sync, checksum)
45 * 1 on error (file not found, etc)
49 send_file(pathname, target_path, encrypt)
54 int n, fd, code, n_to_send, i;
56 unsigned char dst[UPDATE_BUFSIZ + 8], *src;
58 des_key_schedule sched;
62 fd = open(pathname, O_RDONLY, 0);
64 com_err(whoami, errno, "unable to open %s for read", pathname);
67 if (fstat(fd, &statb)) {
68 com_err(whoami, errno, "unable to stat %s", pathname);
72 n_to_send = statb.st_size;
74 string_alloc(&data, UPDATE_BUFSIZ);
75 sprintf(STRING_DATA(data), "XFER_00%c %d %d %s",
76 (encrypt ? '3' : '2'), n_to_send,
77 checksum_file(pathname), target_path);
78 code = send_object(conn, (char *)&data, STRING_T);
80 com_err(whoami, code, " sending XFER request");
84 code = receive_object(conn, (char *)&n, INTEGER_T);
86 com_err(whoami, code, " getting reply from XFER request");
91 com_err(whoami, n, " transfer request (XFER) rejected");
96 code = receive_object(conn, (char *)&n, INTEGER_T);
98 com_err(whoami, connection_errno(conn), ": lost connection");
103 com_err(whoami, n, " from remote server: can't update %s",
111 printf("Session key %02x %02x %02x %02x %02x %02x %02x %02x\n",
112 session[0], session[1], session[2], session[3],
113 session[4], session[5], session[6], session[7]);
115 des_key_sched(session, sched);
116 bcopy(session, ivec, sizeof(ivec));
119 while (n_to_send > 0) {
121 printf("n_to_send = %d\n", n_to_send);
123 n = read(fd, STRING_DATA(data), UPDATE_BUFSIZ);
125 com_err(whoami, errno, " reading %s for transmission", pathname);
129 MAX_STRING_SIZE(data) = n;
131 src = (unsigned char *)STRING_DATA(data);
135 des_pcbc_encrypt(dst, src, n, sched, ivec, 0);
136 /* save vector to continue chaining */
137 for (i = 0; i < 8; i++)
138 ivec[i] = dst[n - 8 + i] ^ src[n - 8 + i];
139 /* round up to multiple of 8 */
140 data.length = (data.length + 7) & 0xfffffff8;
142 code = send_object(conn, (char *)&data, STRING_T);
144 com_err(whoami, connection_errno(conn), " transmitting file %s",
150 code = receive_object(conn, (char *)&n, INTEGER_T);
152 com_err(whoami, connection_errno(conn),
153 " awaiting ACK remote server during transmission of %s",
159 com_err(whoami, n, " from remote server during transmission of %s",
165 if (statb.st_size == 0) {
166 code = receive_object(conn, (char *)&n, INTEGER_T);
168 com_err(whoami, connection_errno(conn),
169 " awaiting ACK remote server after transmission of %s",
175 com_err(whoami, n, " from remote server after transmission of %s",