]>
Commit | Line | Data |
---|---|---|
d8e20246 | 1 | /* $Header$ |
2 | * | |
3 | * Test client for update_server protocol. | |
5eaef520 | 4 | * |
d8e20246 | 5 | * Reads commands from the command line: |
6 | * test host [commands...] | |
7 | * -s file file sends file to host | |
ca63c94e | 8 | * -S file file sends encrypted file to host |
d8e20246 | 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> | |
7b48c9f9 | 16 | #include <string.h> |
d8e20246 | 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> | |
d8e20246 | 23 | #include <moira.h> |
24 | #include <moira_site.h> | |
25 | #include <krb.h> | |
26 | ||
27 | CONNECTION conn; | |
28 | char *whoami; | |
29 | ||
5eaef520 | 30 | int main(int argc, char **argv) |
d8e20246 | 31 | { |
5eaef520 | 32 | char *host, service_address[256], *file, *rfile, buf[256]; |
33 | int code, i, count = 0; | |
d8e20246 | 34 | |
5eaef520 | 35 | whoami = argv[0]; |
36 | initialize_sms_error_table(); | |
37 | initialize_krb_error_table(); | |
38 | gdb_init(); | |
d8e20246 | 39 | |
5eaef520 | 40 | if (argc < 2) |
41 | usage(); | |
42 | host = argv[1]; | |
d8e20246 | 43 | |
5eaef520 | 44 | sprintf(service_address, "%s:%s", host, SERVICE_NAME); |
45 | conn = start_server_connection(service_address, ""); | |
46 | if (!conn || (connection_status(conn) == CON_STOPPED)) | |
47 | { | |
48 | com_err(whoami, connection_errno(conn), | |
49 | " can't connect to update %s", service_address); | |
50 | return MR_CANT_CONNECT; | |
d8e20246 | 51 | } |
5eaef520 | 52 | code = send_auth(host); |
53 | if (code) | |
54 | com_err(whoami, code, " authorization attempt failed"); | |
d8e20246 | 55 | |
5eaef520 | 56 | for (i = 2; i < argc; i++) |
57 | { | |
58 | if (argv[i][0] != '-') | |
59 | usage(); | |
60 | switch (argv[i][1]) | |
61 | { | |
d8e20246 | 62 | case 's': |
5eaef520 | 63 | if (i + 2 >= argc) |
64 | usage(); | |
65 | file = argv[++i]; | |
66 | rfile = argv[++i]; | |
67 | fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile); | |
68 | send_file(file, rfile, 0); | |
69 | break; | |
ca63c94e | 70 | case 'S': |
5eaef520 | 71 | if (i + 2 >= argc) |
72 | usage(); | |
73 | file = argv[++i]; | |
74 | rfile = argv[++i]; | |
75 | fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", | |
76 | file, host, rfile); | |
77 | send_file(file, rfile, 1); | |
78 | break; | |
d8e20246 | 79 | case 'i': |
5eaef520 | 80 | if (i + 1 >= argc) |
81 | usage(); | |
82 | file = argv[++i]; | |
83 | strcpy(buf, "/tmp/moira-updateXXXXX"); | |
84 | mktemp(buf); | |
85 | fprintf(stderr, "Sending instructions %s to %s as %s\n", | |
86 | file, host, buf); | |
87 | send_file(file, buf, 0); | |
88 | break; | |
d8e20246 | 89 | case 'I': |
5eaef520 | 90 | if (i + 2 >= argc) |
91 | usage(); | |
92 | file = argv[++i]; | |
93 | rfile = argv[++i]; | |
94 | strcpy(buf, rfile); | |
95 | fprintf(stderr, "Sending instructions %s to %s as %s\n", | |
96 | file, host, buf); | |
97 | send_file(file, buf, 0); | |
98 | break; | |
d8e20246 | 99 | case 'x': |
5eaef520 | 100 | fprintf(stderr, "Executing instructions %s on %s\n", buf, host); |
101 | code = execute(buf); | |
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); | |
110 | code = execute(file); | |
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 | } | |
5eaef520 | 120 | send_quit(); |
121 | conn = sever_connection(conn); | |
122 | exit(code); | |
d8e20246 | 123 | } |
124 | ||
5eaef520 | 125 | 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 | } |