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>
30 int main(int argc, char **argv)
32 char *host, service_address[256], *file, *rfile, buf[256];
33 int code, i, count = 0;
36 initialize_sms_error_table();
37 initialize_krb_error_table();
44 sprintf(service_address, "%s:%s", host, SERVICE_NAME);
45 conn = start_server_connection(service_address, "");
46 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");
56 for (i = 2; i < argc; i++)
58 if (argv[i][0] != '-')
67 fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
68 send_file(file, rfile, 0);
75 fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
77 send_file(file, rfile, 1);
83 strcpy(buf, "/tmp/moira-updateXXXXX");
85 fprintf(stderr, "Sending instructions %s to %s as %s\n",
87 send_file(file, buf, 0);
95 fprintf(stderr, "Sending instructions %s to %s as %s\n",
97 send_file(file, buf, 0);
100 fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
103 com_err(whoami, code, "executing");
109 fprintf(stderr, "Executing instructions %s on %s\n", file, host);
110 code = execute(file);
112 com_err(whoami, code, "executing");
121 conn = sever_connection(conn);
127 fprintf(stderr, "Usage: test host [commands...]\n");
128 fprintf(stderr, " Commands are:\n");
129 fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
130 fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
131 fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
132 fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
133 fprintf(stderr, "\t-x\t\texecutes last instructions\n");
134 fprintf(stderr, "\t-X file\t\texecutes file\n");