]> andersk Git - moira.git/blame - update/update_test.c
Command line printer manipulation client, and build goo.
[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
991417e4 42 code = mr_send_krb5_auth(conn, host);
43 if (code)
44 code = mr_send_auth(conn, host);
5eaef520 45 if (code)
85330553 46 com_err(whoami, code, "attempting authorization");
d8e20246 47
5eaef520 48 for (i = 2; i < argc; i++)
49 {
50 if (argv[i][0] != '-')
51 usage();
52 switch (argv[i][1])
53 {
d8e20246 54 case 's':
5eaef520 55 if (i + 2 >= argc)
56 usage();
57 file = argv[++i];
58 rfile = argv[++i];
59 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
4e3b3c65 60 mr_send_file(conn, file, rfile, 0);
5eaef520 61 break;
ca63c94e 62 case 'S':
5eaef520 63 if (i + 2 >= argc)
64 usage();
65 file = argv[++i];
66 rfile = argv[++i];
67 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
68 file, host, rfile);
4e3b3c65 69 mr_send_file(conn, file, rfile, 1);
5eaef520 70 break;
d8e20246 71 case 'i':
5eaef520 72 if (i + 1 >= argc)
73 usage();
74 file = argv[++i];
85330553 75 ibuf = strdup("/tmp/moira-updateXXXXX");
76 if (!ibuf)
77 {
78 com_err(whoami, ENOMEM, "sending instructions");
79 exit(1);
80 }
81 mktemp(ibuf);
5eaef520 82 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 83 file, host, ibuf);
4e3b3c65 84 mr_send_file(conn, file, ibuf, 0);
5eaef520 85 break;
d8e20246 86 case 'I':
5eaef520 87 if (i + 2 >= argc)
88 usage();
89 file = argv[++i];
85330553 90 ibuf = argv[++i];
91 strcpy(ibuf, rfile);
5eaef520 92 fprintf(stderr, "Sending instructions %s to %s as %s\n",
85330553 93 file, host, ibuf);
4e3b3c65 94 mr_send_file(conn, file, ibuf, 0);
5eaef520 95 break;
d8e20246 96 case 'x':
85330553 97 if (!ibuf)
98 {
99 fprintf(stderr, "No instructions sent.");
100 usage();
101 }
102 fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
4e3b3c65 103 code = mr_execute(conn, ibuf);
5eaef520 104 if (code)
105 com_err(whoami, code, "executing");
106 break;
d8e20246 107 case 'X':
5eaef520 108 if (i + 1 >= argc)
109 usage();
110 file = argv[++i];
111 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
4e3b3c65 112 code = mr_execute(conn, file);
5eaef520 113 if (code)
114 com_err(whoami, code, "executing");
115 break;
d8e20246 116 case 'n':
5eaef520 117 break;
d8e20246 118 default:
5eaef520 119 usage();
d8e20246 120 }
121 }
4e3b3c65 122 mr_send_quit(conn);
85330553 123 close(conn);
5eaef520 124 exit(code);
d8e20246 125}
126
7ac48069 127void usage(void)
d8e20246 128{
5eaef520 129 fprintf(stderr, "Usage: test host [commands...]\n");
130 fprintf(stderr, " Commands are:\n");
131 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
132 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
133 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
134 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
135 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
136 fprintf(stderr, "\t-X file\t\texecutes file\n");
137 exit(1);
d8e20246 138}
This page took 0.122309 seconds and 5 git commands to generate.