]> andersk Git - moira.git/blame - update/update_test.c
read() in a loop, not all at once, in case packets get split up
[moira.git] / update / update_test.c
CommitLineData
7ac48069 1/* $Id$
d8e20246 2 *
3 * Test client for update_server protocol.
5eaef520 4 *
7ac48069 5 * Copyright 1992-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
d8e20246 8 */
9
10#include <mit-copyright.h>
7ac48069 11#include <moira.h>
12#include <update.h>
13
85330553 14#include <errno.h>
d8e20246 15#include <stdio.h>
7ac48069 16#include <stdlib.h>
17
7ac48069 18void usage(void);
d8e20246 19
d8e20246 20char *whoami;
21
5eaef520 22int main(int argc, char **argv)
d8e20246 23{
85330553 24 char *host, *file, *rfile, *ibuf = NULL;
25 int code, i, count = 0, conn;
d8e20246 26
5eaef520 27 whoami = argv[0];
85330553 28 mr_init();
d8e20246 29
5eaef520 30 if (argc < 2)
31 usage();
32 host = argv[1];
d8e20246 33
85330553 34 conn = mr_connect_internal(host, SERVICE_NAME);
35 if (!conn)
5eaef520 36 {
85330553 37 com_err(whoami, errno, ": can't connect to %s:%s", host, SERVICE_NAME);
38 exit(1);
d8e20246 39 }
85330553 40
41 code = send_auth(conn, host);
5eaef520 42 if (code)
85330553 43 com_err(whoami, code, "attempting authorization");
d8e20246 44
5eaef520 45 for (i = 2; i < argc; i++)
46 {
47 if (argv[i][0] != '-')
48 usage();
49 switch (argv[i][1])
50 {
d8e20246 51 case 's':
5eaef520 52 if (i + 2 >= argc)
53 usage();
54 file = argv[++i];
55 rfile = argv[++i];
56 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
85330553 57 send_file(conn, file, rfile, 0);
5eaef520 58 break;
ca63c94e 59 case 'S':
5eaef520 60 if (i + 2 >= argc)
61 usage();
62 file = argv[++i];
63 rfile = argv[++i];
64 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
65 file, host, rfile);
85330553 66 send_file(conn, file, rfile, 1);
5eaef520 67 break;
d8e20246 68 case 'i':
5eaef520 69 if (i + 1 >= argc)
70 usage();
71 file = argv[++i];
85330553 72 ibuf = strdup("/tmp/moira-updateXXXXX");
73 if (!ibuf)
74 {
75 com_err(whoami, ENOMEM, "sending instructions");
76 exit(1);
77 }
78 mktemp(ibuf);
5eaef520 79 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 80 file, host, ibuf);
81 send_file(conn, file, ibuf, 0);
5eaef520 82 break;
d8e20246 83 case 'I':
5eaef520 84 if (i + 2 >= argc)
85 usage();
86 file = argv[++i];
85330553 87 ibuf = argv[++i];
88 strcpy(ibuf, rfile);
5eaef520 89 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 90 file, host, ibuf);
91 send_file(conn, file, ibuf, 0);
5eaef520 92 break;
d8e20246 93 case 'x':
85330553 94 if (!ibuf)
95 {
96 fprintf(stderr, "No instructions sent.");
97 usage();
98 }
99 fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
100 code = execute(conn, ibuf);
5eaef520 101 if (code)
102 com_err(whoami, code, "executing");
103 break;
d8e20246 104 case 'X':
5eaef520 105 if (i + 1 >= argc)
106 usage();
107 file = argv[++i];
108 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
85330553 109 code = execute(conn, file);
5eaef520 110 if (code)
111 com_err(whoami, code, "executing");
112 break;
d8e20246 113 case 'n':
5eaef520 114 break;
d8e20246 115 default:
5eaef520 116 usage();
d8e20246 117 }
118 }
85330553 119 send_quit(conn);
120 close(conn);
5eaef520 121 exit(code);
d8e20246 122}
123
7ac48069 124void usage(void)
d8e20246 125{
5eaef520 126 fprintf(stderr, "Usage: test host [commands...]\n");
127 fprintf(stderr, " Commands are:\n");
128 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
129 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
130 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
131 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
132 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
133 fprintf(stderr, "\t-X file\t\texecutes file\n");
134 exit(1);
d8e20246 135}
This page took 1.24699 seconds and 5 git commands to generate.