3 * Test client for update_server protocol.
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
14 #include <mit-copyright.h>
18 #include <sys/param.h>
20 #include <sys/socket.h>
25 #include <moira_site.h>
36 char *host, service_address[256], *file, *rfile, buf[256];
40 initialize_sms_error_table();
41 initialize_krb_error_table();
44 if (argc < 2) usage();
47 sprintf(service_address, "%s:%s", host, SERVICE_NAME);
48 conn = start_server_connection(service_address, "");
49 if (!conn || (connection_status(conn) == CON_STOPPED)) {
50 com_err(whoami, connection_errno(conn),
51 " can't connect to update %s", service_address);
52 return(MR_CANT_CONNECT);
54 code = send_auth(host);
56 com_err(whoami, code, " authorization attempt failed");
59 for (i = 2; i < argc; i++) {
60 if (argv[i][0] != '-') usage();
63 if (i+2 >= argc) usage();
66 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
67 send_file(file, rfile, 0);
70 if (i+2 >= argc) usage();
73 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile);
74 send_file(file, rfile, 1);
77 if (i+1 >= argc) usage();
79 strcpy(buf, "/tmp/moira-updateXXXXX");
81 fprintf(stderr, "Sending instructions %s to %s as %s\n",
83 send_file(file, buf, 0);
86 if (i+2 >= argc) usage();
90 fprintf(stderr, "Sending instructions %s to %s as %s\n",
92 send_file(file, buf, 0);
95 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
97 if (code) com_err(whoami, code, "executing");
100 if (i+1 >= argc) usage();
102 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
103 code = execute(file);
104 if (code) com_err(whoami, code, "executing");
113 conn = sever_connection(conn);
119 fprintf(stderr, "Usage: test host [commands...]\n");
120 fprintf(stderr, " Commands are:\n");
121 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
122 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
123 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
124 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
125 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
126 fprintf(stderr, "\t-X file\t\texecutes file\n");
135 KTEXT ticket = &ticket_st;
140 code = get_mr_update_ticket(host_name, ticket);
144 STRING_DATA(data) = "AUTH_001";
145 MAX_STRING_SIZE(data) = 9;
146 code = send_object(conn, (char *)&data, STRING_T);
148 return(connection_errno(conn));
150 code = receive_object(conn, (char *)&response, INTEGER_T);
152 return(connection_errno(conn));
157 STRING_DATA(data) = (char *)ticket->dat;
158 MAX_STRING_SIZE(data) = ticket->length;
159 code = send_object(conn, (char *)&data, STRING_T);
161 return(connection_errno(conn));
163 code = receive_object(conn, (char *)&response, INTEGER_T);
165 return(connection_errno(conn));
168 com_err(whoami, response, "Permission to connect denied");
182 string_alloc(&data, BUFSIZ);
183 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
184 code = send_object(conn, (char *)&data, STRING_T);
186 return(connection_errno(conn));
187 code = receive_object(conn, (char *)&response, INTEGER_T);
189 return(connection_errno(conn));
200 string_alloc(&str, 5);
201 (void) strcpy(STRING_DATA(str), "quit");
202 (void) send_object(conn, (char *)&str, STRING_T);