]> andersk Git - moira.git/blame - update/update_test.c
KEYFILE is no longer a compile-time constant in krb5's krb4 compat
[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>
ea0caf4a 17#include <string.h>
7ac48069 18
7ac48069 19void usage(void);
d8e20246 20
d8e20246 21char *whoami;
22
5eaef520 23int main(int argc, char **argv)
d8e20246 24{
85330553 25 char *host, *file, *rfile, *ibuf = NULL;
26 int code, i, count = 0, conn;
d8e20246 27
5eaef520 28 whoami = argv[0];
85330553 29 mr_init();
d8e20246 30
5eaef520 31 if (argc < 2)
32 usage();
33 host = argv[1];
d8e20246 34
85330553 35 conn = mr_connect_internal(host, SERVICE_NAME);
36 if (!conn)
5eaef520 37 {
85330553 38 com_err(whoami, errno, ": can't connect to %s:%s", host, SERVICE_NAME);
39 exit(1);
d8e20246 40 }
85330553 41
42 code = send_auth(conn, host);
5eaef520 43 if (code)
85330553 44 com_err(whoami, code, "attempting authorization");
d8e20246 45
5eaef520 46 for (i = 2; i < argc; i++)
47 {
48 if (argv[i][0] != '-')
49 usage();
50 switch (argv[i][1])
51 {
d8e20246 52 case 's':
5eaef520 53 if (i + 2 >= argc)
54 usage();
55 file = argv[++i];
56 rfile = argv[++i];
57 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
85330553 58 send_file(conn, file, rfile, 0);
5eaef520 59 break;
ca63c94e 60 case 'S':
5eaef520 61 if (i + 2 >= argc)
62 usage();
63 file = argv[++i];
64 rfile = argv[++i];
65 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
66 file, host, rfile);
85330553 67 send_file(conn, file, rfile, 1);
5eaef520 68 break;
d8e20246 69 case 'i':
5eaef520 70 if (i + 1 >= argc)
71 usage();
72 file = argv[++i];
85330553 73 ibuf = strdup("/tmp/moira-updateXXXXX");
74 if (!ibuf)
75 {
76 com_err(whoami, ENOMEM, "sending instructions");
77 exit(1);
78 }
79 mktemp(ibuf);
5eaef520 80 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 81 file, host, ibuf);
82 send_file(conn, file, ibuf, 0);
5eaef520 83 break;
d8e20246 84 case 'I':
5eaef520 85 if (i + 2 >= argc)
86 usage();
87 file = argv[++i];
85330553 88 ibuf = argv[++i];
89 strcpy(ibuf, rfile);
5eaef520 90 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 91 file, host, ibuf);
92 send_file(conn, file, ibuf, 0);
5eaef520 93 break;
d8e20246 94 case 'x':
85330553 95 if (!ibuf)
96 {
97 fprintf(stderr, "No instructions sent.");
98 usage();
99 }
100 fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
101 code = execute(conn, ibuf);
5eaef520 102 if (code)
103 com_err(whoami, code, "executing");
104 break;
d8e20246 105 case 'X':
5eaef520 106 if (i + 1 >= argc)
107 usage();
108 file = argv[++i];
109 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
85330553 110 code = execute(conn, file);
5eaef520 111 if (code)
112 com_err(whoami, code, "executing");
113 break;
d8e20246 114 case 'n':
5eaef520 115 break;
d8e20246 116 default:
5eaef520 117 usage();
d8e20246 118 }
119 }
85330553 120 send_quit(conn);
121 close(conn);
5eaef520 122 exit(code);
d8e20246 123}
124
7ac48069 125void usage(void)
d8e20246 126{
5eaef520 127 fprintf(stderr, "Usage: test host [commands...]\n");
128 fprintf(stderr, " Commands are:\n");
129 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
130 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
131 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
132 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
133 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
134 fprintf(stderr, "\t-X file\t\texecutes file\n");
135 exit(1);
d8e20246 136}
This page took 1.186558 seconds and 5 git commands to generate.