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 * -i file sends instruction file to host
9 * -x file executes instructions
13 #include <mit-copyright.h>
17 #include <sys/param.h>
19 #include <sys/socket.h>
24 #include <moira_site.h>
35 char *host, service_address[256], *file, *rfile, buf[256];
39 initialize_sms_error_table();
40 initialize_krb_error_table();
43 if (argc < 2) usage();
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);
53 code = send_auth(host);
55 com_err(whoami, code, " authorization attempt failed");
58 for (i = 2; i < argc; i++) {
59 if (argv[i][0] != '-') usage();
62 if (i+2 >= argc) usage();
65 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
66 send_file(file, rfile);
69 if (i+1 >= argc) usage();
71 strcpy(buf, "/tmp/moira-updateXXXXX");
73 fprintf(stderr, "Sending instructions %s to %s as %s\n",
78 if (i+2 >= argc) usage();
82 fprintf(stderr, "Sending instructions %s to %s as %s\n",
87 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
89 if (code) com_err(whoami, code, "executing");
92 if (i+1 >= argc) usage();
94 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
96 if (code) com_err(whoami, code, "executing");
105 conn = sever_connection(conn);
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");
126 KTEXT ticket = &ticket_st;
131 code = get_mr_update_ticket(host_name, ticket);
135 STRING_DATA(data) = "AUTH_001";
136 MAX_STRING_SIZE(data) = 9;
137 code = send_object(conn, (char *)&data, STRING_T);
139 return(connection_errno(conn));
141 code = receive_object(conn, (char *)&response, INTEGER_T);
143 return(connection_errno(conn));
148 STRING_DATA(data) = (char *)ticket->dat;
149 MAX_STRING_SIZE(data) = ticket->length;
150 code = send_object(conn, (char *)&data, STRING_T);
152 return(connection_errno(conn));
154 code = receive_object(conn, (char *)&response, INTEGER_T);
156 return(connection_errno(conn));
159 com_err(whoami, response, "Permission to connect denied");
173 string_alloc(&data, BUFSIZ);
174 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
175 code = send_object(conn, (char *)&data, STRING_T);
177 return(connection_errno(conn));
178 code = receive_object(conn, (char *)&response, INTEGER_T);
180 return(connection_errno(conn));
191 string_alloc(&str, 5);
192 (void) strcpy(STRING_DATA(str), "quit");
193 (void) send_object(conn, (char *)&str, STRING_T);