]> andersk Git - moira.git/blame - clients/mrtest/mrtest.c
Found possible reason why full membership edits weren't happening;
[moira.git] / clients / mrtest / mrtest.c
CommitLineData
6e6374cb 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
c801de4c 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
6e6374cb 9 *
6e6374cb 10 */
11
12#ifndef lint
13static char *rcsid_test_c = "$Header$";
14#endif lint
15
c801de4c 16#include <mit-copyright.h>
6e6374cb 17#include <stdio.h>
39de499f 18#include <sys/types.h>
58b825a4 19#include <sys/file.h>
20#include <ctype.h>
8defc06b 21#include <moira.h>
6e6374cb 22#include <ss.h>
23
24int ss;
58b825a4 25int recursion = 0;
da971797 26extern ss_request_table moira_test;
59af7b90 27extern int sending_version_no;
e091f2f5 28int count;
6e6374cb 29
6e6374cb 30main(argc, argv)
31 int argc;
32 char **argv;
6e6374cb 33{
34 int status;
35 char *whoami;
36
6e6374cb 37 whoami = argv[0];
6e6374cb 38
39 init_ss_err_tbl();
365b5cce 40 initialize_sms_error_table();
41 initialize_krb_error_table();
6e6374cb 42
da971797 43 ss = ss_create_invocation("moira", "2.0", (char *)NULL,
44 &moira_test, &status);
6e6374cb 45 if (status != 0) {
46 com_err(whoami, status, "Unable to create invocation");
47 exit(1);
48 }
2c031a2a 49 if (argc > 1) {
50 argv++;
51 ss_execute_command(ss, argv);
52 }
6e6374cb 53 ss_listen(ss, &status);
54 if (status != 0) {
55 com_err(whoami, status, 0);
56 exit(1);
57 }
a4b41593 58 exit(0);
6e6374cb 59}
60
61test_noop()
62{
8defc06b 63 int status = mr_noop();
972d0244 64 if (status) ss_perror(ss, status, "");
6e6374cb 65}
66
59af7b90 67test_new()
68{
8defc06b 69 sending_version_no = MR_VERSION_2;
59af7b90 70}
71
72test_old()
73{
8defc06b 74 sending_version_no = MR_VERSION_1;
59af7b90 75}
76
011e0a54 77test_connect(argc, argv)
78int argc;
79char *argv[];
6e6374cb 80{
1b93a421 81 char *server = "", *index();
011e0a54 82 int status;
83
94551bbc 84 if (argc > 1) {
85 server = argv[1];
94551bbc 86 }
8defc06b 87 status = mr_connect(server);
972d0244 88 if (status) ss_perror(ss, status, "");
6e6374cb 89}
90
91test_disconnect()
92{
8defc06b 93 int status = mr_disconnect();
972d0244 94 if (status) ss_perror(ss, status, "");
6e6374cb 95}
96
66848930 97test_host()
98{
99 char host[BUFSIZ];
100 int status;
101
102 bzero(host, sizeof(host));
103
8defc06b 104 if (status = mr_host(host, sizeof(host) - 1))
972d0244 105 ss_perror(ss, status, "");
66848930 106 else
107 printf("You are connected to host %s\n", host);
108}
109
6e6374cb 110test_auth()
111{
59af7b90 112 int status;
113
8defc06b 114 status = mr_auth("mrtest");
972d0244 115 if (status) ss_perror(ss, status, "");
6e6374cb 116}
117
58b825a4 118test_script(argc, argv)
119int argc;
120char *argv[];
121{
122 FILE *inp;
123 char input[BUFSIZ], *cp, *index();
124 int status, oldstdout, oldstderr;
125
126 if (recursion > 8) {
127 ss_perror(ss, 0, "too many levels deep in script files\n");
128 return;
129 }
130
131 if (argc < 2) {
132 ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
133 return;
134 }
135
136 inp = fopen(argv[1], "r");
137 if (inp == NULL) {
bddd8492 138 sprintf(input, "Cannot open input file %s", argv[1]);
139 ss_perror(ss, 0, input);
58b825a4 140 return;
141 }
142
143 if (argc == 3) {
144 printf("Redirecting output to %s\n", argv[2]);
145 fflush(stdout);
146 oldstdout = dup(1);
147 close(1);
148 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
149 if (status != 1) {
150 close(status);
151 dup2(oldstdout, 1);
152 argc = 2;
bddd8492 153 sprintf(input, "Unable to redirect output to %s\n", argv[2]);
154 ss_perror(ss, errno, input);
58b825a4 155 } else {
156 fflush(stderr);
157 oldstderr = dup(2);
158 close(2);
159 dup2(1, 2);
160 }
161 }
162
163 recursion++;
164
165 for(;;) {
166 if (fgets(input, BUFSIZ, inp) == NULL)
167 break;
168 if ((cp = index(input, '\n')) != (char *)NULL)
169 *cp = 0;
6a592314 170 if (input[0] == 0) {
171 printf("\n");
172 continue;
173 }
58b825a4 174 if (input[0] == '%') {
175 for (cp = &input[1]; *cp && isspace(*cp); cp++);
176 printf("Comment: %s\n", cp);
177 continue;
178 }
179 printf("Executing: %s\n", input);
180 ss_execute_line(ss, input, &status);
181 if (status == SS_ET_COMMAND_NOT_FOUND) {
182 printf("Bad command: %s\n", input);
183 }
184 }
185
186 recursion--;
187
188 fclose(inp);
189 if (argc == 3) {
190 fflush(stdout);
191 close(1);
192 dup2(oldstdout, 1);
193 close(oldstdout);
194 fflush(stderr);
195 close(2);
196 dup2(oldstderr, 2);
197 close(oldstderr);
198 }
199}
200
6e6374cb 201char *concat(str1, str2)
202 char *str1, *str2;
203{
204 char *rtn;
205 extern char *malloc();
206
207 if (!str1) {
208 int len = strlen(str2) + 1 ;
209 rtn = malloc(len);
210 bcopy(str2, rtn, len);
211 } else {
212 int len1 = strlen(str1);
213 int len2 = strlen(str2) + 1;
214 rtn = malloc(len1+len2);
215 bcopy(str1, rtn, len1);
216 bcopy(str2, rtn+len1, len2);
217 }
218 return rtn;
219}
220
6e6374cb 221
222
223print_reply(argc, argv)
224 int argc;
225 char **argv;
226{
227 int i;
228 for (i = 0; i < argc; i++) {
229 if (i != 0) printf(", ");
230 printf("%s", argv[i]);
231 }
232 printf("\n");
233 count++;
8defc06b 234 return(MR_CONT);
6e6374cb 235}
236
237test_query(argc, argv)
238 int argc;
239 char **argv;
240{
241 int status;
242 if (argc < 2) {
243 ss_perror(ss, 0, "Usage: query handle [ args ... ]");
244 return;
245 }
59af7b90 246
6e6374cb 247 count = 0;
8defc06b 248 status = mr_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
303cb414 249 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
972d0244 250 if (status) ss_perror(ss, status, "");
6e6374cb 251}
252
253test_access(argc, argv)
254 int argc;
255 char **argv;
256{
257 int status;
258 if (argc < 2) {
259 ss_perror(ss, 0, "Usage: access handle [ args ... ]");
260 return;
261 }
8defc06b 262 status = mr_access(argv[1], argc-2, argv+2);
972d0244 263 if (status) ss_perror(ss, status, "");
6e6374cb 264}
fc3ac28e 265
266
267test_dcm(argc, argv)
268 int argc;
269 char **argv;
270{
271 int status;
272
8defc06b 273 if (status = mr_do_update())
fc3ac28e 274 ss_perror(ss, status, " while triggering dcm");
275}
093b57b1 276
277
278test_motd(argc, argv)
279 int argc;
280 char **argv;
281{
282 int status;
283 char *motd;
284
8defc06b 285 if (status = mr_motd(&motd))
093b57b1 286 ss_perror(ss, status, " while getting motd");
287 if (motd)
288 printf("%s\n", motd);
289 else
290 printf("No message of the day.\n");
291}
This page took 0.12931 seconds and 5 git commands to generate.