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>
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, 0);
69 if (i+2 >= argc) usage();
72 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile);
73 send_file(file, rfile, 1);
76 if (i+1 >= argc) usage();
78 strcpy(buf, "/tmp/moira-updateXXXXX");
80 fprintf(stderr, "Sending instructions %s to %s as %s\n",
82 send_file(file, buf, 0);
85 if (i+2 >= argc) usage();
89 fprintf(stderr, "Sending instructions %s to %s as %s\n",
91 send_file(file, buf, 0);
94 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
96 if (code) com_err(whoami, code, "executing");
99 if (i+1 >= argc) usage();
101 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
102 code = execute(file);
103 if (code) com_err(whoami, code, "executing");
112 conn = sever_connection(conn);
118 fprintf(stderr, "Usage: test host [commands...]\n");
119 fprintf(stderr, " Commands are:\n");
120 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
121 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
122 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
123 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
124 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
125 fprintf(stderr, "\t-X file\t\texecutes file\n");