]> andersk Git - moira.git/blame - update/update_test.c
use krb_get_phost, not local routine; don't try to kinit again
[moira.git] / update / update_test.c
CommitLineData
d8e20246 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 * -i file sends instruction file to host
9 * -x file executes instructions
10 * -n nop
11 */
12
13#include <mit-copyright.h>
14#include <stdio.h>
15#include <strings.h>
16#include <gdb.h>
17#include <sys/param.h>
18#include <sys/wait.h>
19#include <sys/socket.h>
20#include <update.h>
21#include <errno.h>
22#include <dcm.h>
23#include <moira.h>
24#include <moira_site.h>
25#include <krb.h>
26
27CONNECTION conn;
28char *whoami;
29
30
31main(argc, argv)
32int argc;
33char **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);
67 break;
68 case 'i':
69 if (i+1 >= argc) usage();
70 file = argv[++i];
71 strcpy(buf, "/tmp/moira-updateXXXXX");
72 mktemp(buf);
73 fprintf(stderr, "Sending instructions %s to %s as %s\n",
74 file, host, buf);
75 send_file(file, buf);
76 break;
77 case 'I':
78 if (i+2 >= argc) usage();
79 file = argv[++i];
80 rfile = argv[++i];
81 strcpy(buf, rfile);
82 fprintf(stderr, "Sending instructions %s to %s as %s\n",
83 file, host, buf);
84 send_file(file, buf);
85 break;
86 case 'x':
87 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
88 code = execute(buf);
89 if (code) com_err(whoami, code, "executing");
90 break;
91 case 'X':
92 if (i+1 >= argc) usage();
93 file = argv[++i];
94 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
95 code = execute(file);
96 if (code) com_err(whoami, code, "executing");
97 break;
98 case 'n':
99 break;
100 default:
101 usage();
102 }
103 }
104 send_quit();
105 conn = sever_connection(conn);
106 exit(code);
107}
108
109usage()
110{
111 fprintf(stderr, "Usage: test host [commands...]\n");
112 fprintf(stderr, " Commands are:\n");
113 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
114 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
115 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
116 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
117 fprintf(stderr, "\t-X file\t\texecutes file\n");
118 exit(1);
119}
120
121static
122send_auth(host_name)
123char *host_name;
124{
125 KTEXT_ST ticket_st;
126 KTEXT ticket = &ticket_st;
127 STRING data;
128 register int code;
129 int response;
130
131 code = get_mr_update_ticket(host_name, ticket);
132 if (code) {
133 return(code);
134 }
135 STRING_DATA(data) = "AUTH_001";
136 MAX_STRING_SIZE(data) = 9;
137 code = send_object(conn, (char *)&data, STRING_T);
138 if (code) {
139 return(connection_errno(conn));
140 }
141 code = receive_object(conn, (char *)&response, INTEGER_T);
142 if (code) {
143 return(connection_errno(conn));
144 }
145 if (response) {
146 return(response);
147 }
148 STRING_DATA(data) = (char *)ticket->dat;
149 MAX_STRING_SIZE(data) = ticket->length;
150 code = send_object(conn, (char *)&data, STRING_T);
151 if (code) {
152 return(connection_errno(conn));
153 }
154 code = receive_object(conn, (char *)&response, INTEGER_T);
155 if (code) {
156 return(connection_errno(conn));
157 }
158 if (response) {
159 com_err(whoami, response, "Permission to connect denied");
160 return(response);
161 }
162 return(MR_SUCCESS);
163}
164
165static
166execute(path)
167 char *path;
168{
169 int response;
170 STRING data;
171 register int code;
172
173 string_alloc(&data, BUFSIZ);
174 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
175 code = send_object(conn, (char *)&data, STRING_T);
176 if (code)
177 return(connection_errno(conn));
178 code = receive_object(conn, (char *)&response, INTEGER_T);
179 if (code)
180 return(connection_errno(conn));
181 if (response)
182 return(response);
183 return(MR_SUCCESS);
184}
185
186send_quit()
187{
188 STRING str;
189 if (!conn)
190 return;
191 string_alloc(&str, 5);
192 (void) strcpy(STRING_DATA(str), "quit");
193 (void) send_object(conn, (char *)&str, STRING_T);
194 string_free(&str);
195}
This page took 0.110301 seconds and 5 git commands to generate.