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>
24 #include <moira_site.h>
34 char *host, service_address[256], *file, *rfile, buf[256];
38 initialize_sms_error_table();
39 initialize_krb_error_table();
42 if (argc < 2) usage();
45 sprintf(service_address, "%s:%s", host, SERVICE_NAME);
46 conn = start_server_connection(service_address, "");
47 if (!conn || (connection_status(conn) == CON_STOPPED)) {
48 com_err(whoami, connection_errno(conn),
49 " can't connect to update %s", service_address);
50 return(MR_CANT_CONNECT);
52 code = send_auth(host);
54 com_err(whoami, code, " authorization attempt failed");
57 for (i = 2; i < argc; i++) {
58 if (argv[i][0] != '-') usage();
61 if (i+2 >= argc) usage();
64 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
65 send_file(file, rfile, 0);
68 if (i+2 >= argc) usage();
71 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile);
72 send_file(file, rfile, 1);
75 if (i+1 >= argc) usage();
77 strcpy(buf, "/tmp/moira-updateXXXXX");
79 fprintf(stderr, "Sending instructions %s to %s as %s\n",
81 send_file(file, buf, 0);
84 if (i+2 >= argc) usage();
88 fprintf(stderr, "Sending instructions %s to %s as %s\n",
90 send_file(file, buf, 0);
93 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
95 if (code) com_err(whoami, code, "executing");
98 if (i+1 >= argc) usage();
100 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
101 code = execute(file);
102 if (code) com_err(whoami, code, "executing");
111 conn = sever_connection(conn);
117 fprintf(stderr, "Usage: test host [commands...]\n");
118 fprintf(stderr, " Commands are:\n");
119 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
120 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
121 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
122 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
123 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
124 fprintf(stderr, "\t-X file\t\texecutes file\n");