]>
Commit | Line | Data |
---|---|---|
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 | ||
d8e20246 | 14 | #include <stdio.h> |
7ac48069 | 15 | #include <stdlib.h> |
16 | ||
d8e20246 | 17 | #include <gdb.h> |
7ac48069 | 18 | |
19 | void usage(void); | |
d8e20246 | 20 | |
21 | CONNECTION conn; | |
22 | char *whoami; | |
23 | ||
5eaef520 | 24 | int main(int argc, char **argv) |
d8e20246 | 25 | { |
5eaef520 | 26 | char *host, service_address[256], *file, *rfile, buf[256]; |
7ac48069 | 27 | int code, i; |
d8e20246 | 28 | |
5eaef520 | 29 | whoami = argv[0]; |
30 | initialize_sms_error_table(); | |
31 | initialize_krb_error_table(); | |
32 | gdb_init(); | |
d8e20246 | 33 | |
5eaef520 | 34 | if (argc < 2) |
35 | usage(); | |
36 | host = argv[1]; | |
d8e20246 | 37 | |
5eaef520 | 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; | |
d8e20246 | 45 | } |
5eaef520 | 46 | code = send_auth(host); |
47 | if (code) | |
48 | com_err(whoami, code, " authorization attempt failed"); | |
d8e20246 | 49 | |
5eaef520 | 50 | for (i = 2; i < argc; i++) |
51 | { | |
52 | if (argv[i][0] != '-') | |
53 | usage(); | |
54 | switch (argv[i][1]) | |
55 | { | |
d8e20246 | 56 | case 's': |
5eaef520 | 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; | |
ca63c94e | 64 | case 'S': |
5eaef520 | 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; | |
d8e20246 | 73 | case 'i': |
5eaef520 | 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; | |
d8e20246 | 83 | case 'I': |
5eaef520 | 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; | |
d8e20246 | 93 | case 'x': |
5eaef520 | 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; | |
d8e20246 | 99 | case 'X': |
5eaef520 | 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; | |
d8e20246 | 108 | case 'n': |
5eaef520 | 109 | break; |
d8e20246 | 110 | default: |
5eaef520 | 111 | usage(); |
d8e20246 | 112 | } |
113 | } | |
5eaef520 | 114 | send_quit(); |
115 | conn = sever_connection(conn); | |
116 | exit(code); | |
d8e20246 | 117 | } |
118 | ||
7ac48069 | 119 | void usage(void) |
d8e20246 | 120 | { |
5eaef520 | 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); | |
d8e20246 | 130 | } |