]> andersk Git - moira.git/blob - update/update_test.c
Remove `delete_user_by_uid' since it's never been used in any logs we have,
[moira.git] / update / update_test.c
1 /* $Header$
2  *
3  * Test client for update_server protocol.
4  * 
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
11  *      -n              nop
12  */
13
14 #include <mit-copyright.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <gdb.h>
18 #include <sys/param.h>
19 #include <sys/wait.h>
20 #include <sys/socket.h>
21 #include <update.h>
22 #include <errno.h>
23 #include <moira.h>
24 #include <moira_site.h>
25 #include <krb.h>
26
27 CONNECTION conn;
28 char *whoami;
29
30 main(argc, argv)
31 int argc;
32 char **argv;
33 {
34     char *host, service_address[256], *file, *rfile, buf[256];
35     int code, i, count=0;
36
37     whoami = argv[0];
38     initialize_sms_error_table();
39     initialize_krb_error_table();
40     gdb_init();
41
42     if (argc < 2) usage();
43     host = argv[1];
44
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);
51     }
52     code = send_auth(host);
53     if (code) {
54         com_err(whoami, code, " authorization attempt failed");
55     }
56
57     for (i = 2; i < argc; i++) {
58         if (argv[i][0] != '-') usage();
59         switch (argv[i][1]) {
60         case 's':
61             if (i+2 >= argc) usage();
62             file = argv[++i];
63             rfile = argv[++i];
64             fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
65             send_file(file, rfile, 0);
66             break;
67         case 'S':
68             if (i+2 >= argc) usage();
69             file = argv[++i];
70             rfile = argv[++i];
71             fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile);
72             send_file(file, rfile, 1);
73             break;
74         case 'i':
75             if (i+1 >= argc) usage();
76             file = argv[++i];
77             strcpy(buf, "/tmp/moira-updateXXXXX");
78             mktemp(buf);
79             fprintf(stderr, "Sending instructions %s to %s as %s\n",
80                     file, host, buf);
81             send_file(file, buf, 0);
82             break;
83         case 'I':
84             if (i+2 >= argc) usage();
85             file = argv[++i];
86             rfile = argv[++i];
87             strcpy(buf, rfile);
88             fprintf(stderr, "Sending instructions %s to %s as %s\n",
89                     file, host, buf);
90             send_file(file, buf, 0);
91             break;
92         case 'x':
93             fprintf(stderr, "Executing instructions %s on %s\n", buf, host);
94             code = execute(buf);
95             if (code) com_err(whoami, code, "executing");
96             break;
97         case 'X':
98             if (i+1 >= argc) usage();
99             file = argv[++i];
100             fprintf(stderr, "Executing instructions %s on %s\n", file, host);
101             code = execute(file);
102             if (code) com_err(whoami, code, "executing");
103             break;
104         case 'n':
105             break;
106         default:
107             usage();
108         }
109     }
110     send_quit();
111     conn = sever_connection(conn);
112     exit(code);
113 }
114
115 usage()
116 {
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");
125     exit(1);
126 }
This page took 0.188118 seconds and 5 git commands to generate.