]> andersk Git - moira.git/blob - update/update_test.c
Remove code from update_test that was duplicated in client.c
[moira.git] / update / update_test.c
1 /* $Header$
2  *
3  * Test client for update_server protocol.
4  * 
5  * Reads commands from the command line:
6  * test host [commands...]
7  *      -s file file    sends file to host
8  *      -S file file    sends encrypted file to host
9  *      -i file         sends instruction file to host
10  *      -x file         executes instructions
11  *      -n              nop
12  */
13
14 #include <mit-copyright.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <gdb.h>
18 #include <sys/param.h>
19 #include <sys/wait.h>
20 #include <sys/socket.h>
21 #include <update.h>
22 #include <errno.h>
23 #include <dcm.h>
24 #include <moira.h>
25 #include <moira_site.h>
26 #include <krb.h>
27
28 CONNECTION conn;
29 char *whoami;
30
31 main(argc, argv)
32 int argc;
33 char **argv;
34 {
35     char *host, service_address[256], *file, *rfile, buf[256];
36     int code, i, count=0;
37
38     whoami = argv[0];
39     initialize_sms_error_table();
40     initialize_krb_error_table();
41     gdb_init();
42
43     if (argc < 2) usage();
44     host = argv[1];
45
46     sprintf(service_address, "%s:%s", host, SERVICE_NAME);
47     conn = start_server_connection(service_address, "");
48     if (!conn || (connection_status(conn) == CON_STOPPED)) {
49         com_err(whoami, connection_errno(conn),
50                 " can't connect to update %s", service_address);
51         return(MR_CANT_CONNECT);
52     }
53     code = send_auth(host);
54     if (code) {
55         com_err(whoami, code, " authorization attempt failed");
56     }
57
58     for (i = 2; i < argc; i++) {
59         if (argv[i][0] != '-') usage();
60         switch (argv[i][1]) {
61         case 's':
62             if (i+2 >= argc) usage();
63             file = argv[++i];
64             rfile = argv[++i];
65             fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
66             send_file(file, rfile, 0);
67             break;
68         case 'S':
69             if (i+2 >= argc) usage();
70             file = argv[++i];
71             rfile = argv[++i];
72             fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile);
73             send_file(file, rfile, 1);
74             break;
75         case 'i':
76             if (i+1 >= argc) usage();
77             file = argv[++i];
78             strcpy(buf, "/tmp/moira-updateXXXXX");
79             mktemp(buf);
80             fprintf(stderr, "Sending instructions %s to %s as %s\n",
81                     file, host, buf);
82             send_file(file, buf, 0);
83             break;
84         case 'I':
85             if (i+2 >= argc) 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) com_err(whoami, code, "executing");
97             break;
98         case 'X':
99             if (i+1 >= argc) usage();
100             file = argv[++i];
101             fprintf(stderr, "Executing instructions %s on %s\n", file, host);
102             code = execute(file);
103             if (code) com_err(whoami, code, "executing");
104             break;
105         case 'n':
106             break;
107         default:
108             usage();
109         }
110     }
111     send_quit();
112     conn = sever_connection(conn);
113     exit(code);
114 }
115
116 usage()
117 {
118     fprintf(stderr, "Usage: test host [commands...]\n");
119     fprintf(stderr, "  Commands are:\n");
120     fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
121     fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
122     fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
123     fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
124     fprintf(stderr, "\t-x\t\texecutes last instructions\n");
125     fprintf(stderr, "\t-X file\t\texecutes file\n");
126     exit(1);
127 }
This page took 0.045946 seconds and 5 git commands to generate.