]> andersk Git - moira.git/blob - update/xfer_003.c
78069983f2d9f2c9ffc4d23b90de766498ae75e8
[moira.git] / update / xfer_003.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988, 1992 by the Massachusetts Institute of Technology.
6  *  For copying and distribution information, please see the file
7  *  <mit-copyright.h>.
8  */
9
10 #ifndef lint
11 static char *rcsid_xfer_002_c = "$Header$";
12 #endif
13
14 #include <mit-copyright.h>
15 #include <stdio.h>
16 #include <gdb.h>
17 #include <ctype.h>
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include <string.h>
21 #include <moira.h>
22
23 extern CONNECTION conn;
24 extern char buf[BUFSIZ];
25
26 extern int code, errno;
27
28 extern int have_authorization, have_file, done;
29
30 /*
31  *
32  * syntax:
33  * >>> (STRING)"xfer_003" filesize checksum pathname
34  * <<< (int)0
35  * >>> (STRING)data
36  * <<< (int)code
37  * >>> (STRING)data
38  * <<< (int)code
39  * ...
40  * >>> (STRING)data     (last data block)
41  * <<< (int)code        (from read, write, checksum verify)
42  *
43  * function:
44  *      perform initial preparations and receive file as
45  * a single string, storing it into <pathname>.moira_update.
46  * this version of transfer encrypts the file being transferred.
47  */
48
49 int xfer_003(char *str)
50 {
51   int file_size;
52   int checksum;
53   char *pathname;
54
55   str += 8;
56   while (*str == ' ')
57     str++;
58   if (!*str)
59     {
60     failure:
61       reject_call(MR_ARGS);
62       return 0;
63     }
64   file_size = atoi(str);
65   while (isdigit(*str))
66     str++;
67   while (*str == ' ')
68     str++;
69   checksum = atoi(str);
70   while (isdigit(*str))
71     str++;
72   while (*str == ' ')
73     str++;
74   if (*str != '/')
75     goto failure;
76   pathname = str;
77   if (!have_authorization)
78     {
79       reject_call(MR_PERM);
80       return 0;
81     }
82   if (done)                     /* re-initialize data */
83     initialize();
84   code = send_ok();
85   if (code)
86     lose("sending ok for file xfer (2)");
87   code = get_file(pathname, file_size, checksum, 0444, 1);
88   if (!code)
89     {
90       char buf[BUFSIZ];
91       have_file = 1;
92       strcpy(buf, "transferred file ");
93       strcat(buf, pathname);
94       mr_log_info(buf);
95     }
96   return 0;
97 }
This page took 0.031438 seconds and 3 git commands to generate.