]> andersk Git - moira.git/blob - update/update_test.c
Command line printer manipulation client, and build goo.
[moira.git] / update / update_test.c
1 /* $Id$
2  *
3  * Test client for update_server protocol.
4  *
5  * Copyright 1992-1998 by the Massachusetts Institute of Technology.
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <update.h>
13
14 #include <errno.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 void usage(void);
20
21 char *whoami;
22
23 int main(int argc, char **argv)
24 {
25   char *host, *file, *rfile, *ibuf = NULL;
26   int code, i, count = 0, conn;
27
28   whoami = argv[0];
29   mr_init();
30
31   if (argc < 2)
32     usage();
33   host = argv[1];
34
35   conn = mr_connect_internal(host, SERVICE_NAME);
36   if (!conn)
37     {
38       com_err(whoami, errno, ": can't connect to %s:%s", host, SERVICE_NAME);
39       exit(1);
40     }
41
42   code = mr_send_krb5_auth(conn, host);
43   if (code)
44     code = mr_send_auth(conn, host);
45   if (code)
46     com_err(whoami, code, "attempting authorization");
47
48   for (i = 2; i < argc; i++)
49     {
50       if (argv[i][0] != '-')
51         usage();
52       switch (argv[i][1])
53         {
54         case 's':
55           if (i + 2 >= argc)
56             usage();
57           file = argv[++i];
58           rfile = argv[++i];
59           fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
60           mr_send_file(conn, file, rfile, 0);
61           break;
62         case 'S':
63           if (i + 2 >= argc)
64             usage();
65           file = argv[++i];
66           rfile = argv[++i];
67           fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
68                   file, host, rfile);
69           mr_send_file(conn, file, rfile, 1);
70           break;
71         case 'i':
72           if (i + 1 >= argc)
73             usage();
74           file = argv[++i];
75           ibuf = strdup("/tmp/moira-updateXXXXX");
76           if (!ibuf)
77             {
78               com_err(whoami, ENOMEM, "sending instructions");
79               exit(1);
80             }
81           mktemp(ibuf);
82           fprintf(stderr, "Sending instructions %s to %s as %s\n",
83                   file, host, ibuf);
84           mr_send_file(conn, file, ibuf, 0);
85           break;
86         case 'I':
87           if (i + 2 >= argc)
88             usage();
89           file = argv[++i];
90           ibuf = argv[++i];
91           strcpy(ibuf, rfile);
92           fprintf(stderr, "Sending instructions %s to %s as %s\n",
93                   file, host, ibuf);
94           mr_send_file(conn, file, ibuf, 0);
95           break;
96         case 'x':
97           if (!ibuf)
98             {
99               fprintf(stderr, "No instructions sent.");
100               usage();
101             }
102           fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
103           code = mr_execute(conn, ibuf);
104           if (code)
105             com_err(whoami, code, "executing");
106           break;
107         case 'X':
108           if (i + 1 >= argc)
109             usage();
110           file = argv[++i];
111           fprintf(stderr, "Executing instructions %s on %s\n", file, host);
112           code = mr_execute(conn, file);
113           if (code)
114             com_err(whoami, code, "executing");
115           break;
116         case 'n':
117           break;
118         default:
119           usage();
120         }
121     }
122   mr_send_quit(conn);
123   close(conn);
124   exit(code);
125 }
126
127 void usage(void)
128 {
129   fprintf(stderr, "Usage: test host [commands...]\n");
130   fprintf(stderr, "  Commands are:\n");
131   fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
132   fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
133   fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
134   fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
135   fprintf(stderr, "\t-x\t\texecutes last instructions\n");
136   fprintf(stderr, "\t-X file\t\texecutes file\n");
137   exit(1);
138 }
This page took 0.62435 seconds and 5 git commands to generate.