]> andersk Git - moira.git/blob - update/update_test.c
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / update / update_test.c
1 /* $Id$
2  *
3  * Test client for update_server protocol.
4  *
5  * Copyright 1992-1998 by the Massachusetts Institute of Technology.
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <update.h>
13
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include <gdb.h>
18
19 void usage(void);
20
21 CONNECTION conn;
22 char *whoami;
23
24 int main(int argc, char **argv)
25 {
26   char *host, service_address[256], *file, *rfile, buf[256];
27   int code, i;
28
29   whoami = argv[0];
30   initialize_sms_error_table();
31   initialize_krb_error_table();
32   gdb_init();
33
34   if (argc < 2)
35     usage();
36   host = argv[1];
37
38   sprintf(service_address, "%s:%s", host, SERVICE_NAME);
39   conn = start_server_connection(service_address, "");
40   if (!conn || (connection_status(conn) == CON_STOPPED))
41     {
42       com_err(whoami, connection_errno(conn),
43               " can't connect to update %s", service_address);
44       return MR_CANT_CONNECT;
45     }
46   code = send_auth(host);
47   if (code)
48     com_err(whoami, code, " authorization attempt failed");
49
50   for (i = 2; i < argc; i++)
51     {
52       if (argv[i][0] != '-')
53         usage();
54       switch (argv[i][1])
55         {
56         case 's':
57           if (i + 2 >= argc)
58             usage();
59           file = argv[++i];
60           rfile = argv[++i];
61           fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
62           send_file(file, rfile, 0);
63           break;
64         case 'S':
65           if (i + 2 >= argc)
66             usage();
67           file = argv[++i];
68           rfile = argv[++i];
69           fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
70                   file, host, rfile);
71           send_file(file, rfile, 1);
72           break;
73         case 'i':
74           if (i + 1 >= argc)
75             usage();
76           file = argv[++i];
77           strcpy(buf, "/tmp/moira-updateXXXXX");
78           mktemp(buf);
79           fprintf(stderr, "Sending instructions %s to %s as %s\n",
80                   file, host, buf);
81           send_file(file, buf, 0);
82           break;
83         case 'I':
84           if (i + 2 >= argc)
85             usage();
86           file = argv[++i];
87           rfile = argv[++i];
88           strcpy(buf, rfile);
89           fprintf(stderr, "Sending instructions %s to %s as %s\n",
90                   file, host, buf);
91           send_file(file, buf, 0);
92           break;
93         case 'x':
94           fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
95           code = execute(buf);
96           if (code)
97             com_err(whoami, code, "executing");
98           break;
99         case 'X':
100           if (i + 1 >= argc)
101             usage();
102           file = argv[++i];
103           fprintf(stderr, "Executing instructions %s on %s\n", file, host);
104           code = execute(file);
105           if (code)
106             com_err(whoami, code, "executing");
107           break;
108         case 'n':
109           break;
110         default:
111           usage();
112         }
113     }
114   send_quit();
115   conn = sever_connection(conn);
116   exit(code);
117 }
118
119 void usage(void)
120 {
121   fprintf(stderr, "Usage: test host [commands...]\n");
122   fprintf(stderr, "  Commands are:\n");
123   fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
124   fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
125   fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
126   fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
127   fprintf(stderr, "\t-x\t\texecutes last instructions\n");
128   fprintf(stderr, "\t-X file\t\texecutes file\n");
129   exit(1);
130 }
This page took 0.047953 seconds and 5 git commands to generate.