source: trunk/third/moira/update/update_test.c @ 24319

Revision 24319, 3.3 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1/* $Id: update_test.c 3956 2010-01-05 20:56:56Z zacheiss $
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
19RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/update/update_test.c $ $Id: update_test.c 3956 2010-01-05 20:56:56Z zacheiss $");
20
21void usage(void);
22
23char *whoami;
24
25int main(int argc, char **argv)
26{
27  char *host, *file, *rfile, *ibuf = NULL;
28  int code, i, count = 0, conn;
29
30  whoami = argv[0];
31  mr_init();
32
33  if (argc < 2)
34    usage();
35  host = argv[1];
36
37  conn = mr_connect_internal(host, SERVICE_NAME);
38  if (!conn)
39    {
40      com_err(whoami, errno, ": can't connect to %s:%s", host, SERVICE_NAME);
41      exit(1);
42    }
43
44  code = mr_send_krb5_auth(conn, host);
45  if (code)
46    code = mr_send_auth(conn, host);
47  if (code)
48    com_err(whoami, code, "attempting authorization");
49
50  for (i = 2; i < argc; i++)
51    {
52      if (argv[i][0] != '-')
53        usage();
54      switch (argv[i][1])
55        {
56        case 's':
57          if (i + 2 >= argc)
58            usage();
59          file = argv[++i];
60          rfile = argv[++i];
61          fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile);
62          mr_send_file(conn, file, rfile, 0);
63          break;
64        case 'S':
65          if (i + 2 >= argc)
66            usage();
67          file = argv[++i];
68          rfile = argv[++i];
69          fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n",
70                  file, host, rfile);
71          mr_send_file(conn, file, rfile, 1);
72          break;
73        case 'i':
74          if (i + 1 >= argc)
75            usage();
76          file = argv[++i];
77          ibuf = strdup("/tmp/moira-updateXXXXX");
78          if (!ibuf)
79            {
80              com_err(whoami, ENOMEM, "sending instructions");
81              exit(1);
82            }
83          mkstemp(ibuf);
84          fprintf(stderr, "Sending instructions %s to %s as %s\n",
85                  file, host, ibuf);
86          mr_send_file(conn, file, ibuf, 0);
87          break;
88        case 'I':
89          if (i + 2 >= argc)
90            usage();
91          file = argv[++i];
92          ibuf = argv[++i];
93          strcpy(ibuf, rfile);
94          fprintf(stderr, "Sending instructions %s to %s as %s\n",
95                  file, host, ibuf);
96          mr_send_file(conn, file, ibuf, 0);
97          break;
98        case 'x':
99          if (!ibuf)
100            {
101              fprintf(stderr, "No instructions sent.");
102              usage();
103            }
104          fprintf(stderr, "Executing instructions %s on %s\n", ibuf, host);
105          code = mr_execute(conn, ibuf);
106          if (code)
107            com_err(whoami, code, "executing");
108          break;
109        case 'X':
110          if (i + 1 >= argc)
111            usage();
112          file = argv[++i];
113          fprintf(stderr, "Executing instructions %s on %s\n", file, host);
114          code = mr_execute(conn, file);
115          if (code)
116            com_err(whoami, code, "executing");
117          break;
118        case 'n':
119          break;
120        default:
121          usage();
122        }
123    }
124  mr_send_quit(conn);
125  close(conn);
126  exit(code);
127}
128
129void usage(void)
130{
131  fprintf(stderr, "Usage: test host [commands...]\n");
132  fprintf(stderr, "  Commands are:\n");
133  fprintf(stderr, "\t-s srcfile dstfile\tsends file\n");
134  fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n");
135  fprintf(stderr, "\t-i srcfile\t\tsends instructions\n");
136  fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n");
137  fprintf(stderr, "\t-x\t\texecutes last instructions\n");
138  fprintf(stderr, "\t-X file\t\texecutes file\n");
139  exit(1);
140}
Note: See TracBrowser for help on using the repository browser.