6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_test_c = "$Header$";
16 #include <mit-copyright.h>
18 #include <sys/types.h>
28 extern int sending_version_no;
43 initialize_sms_error_table();
44 initialize_krb_error_table();
49 if(!fgets(cmdbuf,BUFSIZ,stdin)) break;
62 argc=parse(cmdbuf, argv);
64 if(!strcmp(argv[0],"noop"))
66 else if(!strcmp(argv[0],"connect") || !strcmp(argv[0],"c"))
67 test_connect(argc, argv);
68 else if(!strcmp(argv[0],"disconnect") || !strcmp(argv[0],"d"))
70 else if(!strcmp(argv[0],"host"))
72 else if(!strcmp(argv[0],"new") || !strcmp(argv[0],"2"))
74 else if(!strcmp(argv[0],"old") || !strcmp(argv[0],"1"))
76 else if(!strcmp(argv[0],"motd"))
78 else if(!strcmp(argv[0],"query") || !strcmp(argv[0],"qy"))
79 test_query(argc, argv);
80 else if(!strcmp(argv[0],"auth") || !strcmp(argv[0],"a"))
81 test_auth(argc, argv);
82 else if(!strcmp(argv[0],"access"))
83 test_access(argc, argv);
84 else if(!strcmp(argv[0],"dcm"))
86 else if(!strcmp(argv[0],"script") || !strcmp(argv[0],"s"))
87 test_script(argc, argv);
88 else if(!strcmp(argv[0],"list_requests") ||
89 !strcmp(argv[0],"lr") || !strcmp(argv[0],"?"))
91 else if(!strcmp(argv[0],"quit") || !strcmp(argv[0],"Q"))
93 else fprintf(stderr, "moira: Unknown request \"%s\"."
94 "Type \"?\" for a request list.\n", argv[0]);
99 char *buf, *argv[MAXARGS];
104 for(p=buf, argc=0, argv[0]=buf; *p && *p!='\n'; p++) {
107 /* skip to close-quote, copying back over open-quote */
109 if(!*p || *p=='\n') {
110 fprintf(stderr, "moira: Unbalanced quotes in command line\n");
114 if(*++p!='"' && (*p<'0' || *p>'9')) {
115 fprintf(stderr, "moira: Bad use of \\\n");
117 } else if (*p!='"') {
118 num=(*p-'0')*64 + (*++p-'0')*8 + (*++p-'0');
124 if(p==d+1) {*d='\0'; p++;}
125 else while(p>=d) *p--=' ';
127 if(*p==' ' || *p=='\t') {
128 /* skip whitespace */
129 for(*p++='\0'; *p==' ' || *p=='\t'; p++);
130 if(*p && *p!='\n') argv[++argc]=p--;
133 if(*p=='\n') *p='\0';
139 int status = mr_noop();
140 if (status) com_err("moira (noop)", status, "");
145 sending_version_no = MR_VERSION_2;
150 sending_version_no = MR_VERSION_1;
153 test_connect(argc, argv)
163 status = mr_connect(server);
164 if (status) com_err("moira (connect)", status, "");
169 int status = mr_disconnect();
170 if (status) com_err("moira (disconnect)", status, "");
178 memset(host, 0, sizeof(host));
180 if (status = mr_host(host, sizeof(host) - 1))
181 com_err("moira (host)", status, "");
183 printf("You are connected to host %s\n", host);
186 test_auth(argc, argv)
192 status = mr_auth("mrtest");
193 if (status) com_err("moira (auth)", status, "");
196 test_script(argc, argv)
201 char input[BUFSIZ], *cp;
202 int status, oldstdout, oldstderr;
205 com_err("moira (script)", 0, "too many levels deep in script files\n");
210 com_err("moira (script)", 0, "Usage: script input_file [ output_file ]");
214 inp = fopen(argv[1], "r");
216 sprintf(input, "Cannot open input file %s", argv[1]);
217 com_err("moira (script)", 0, input);
222 printf("Redirecting output to %s\n", argv[2]);
226 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
231 sprintf(input, "Unable to redirect output to %s\n", argv[2]);
232 com_err("moira (script)", errno, input);
244 if (fgets(input, BUFSIZ, inp) == NULL)
246 if ((cp = strchr(input, '\n')) != (char *)NULL)
252 if (input[0] == '%') {
253 for (cp = &input[1]; *cp && isspace(*cp); cp++);
254 printf("Comment: %s\n", cp);
257 printf("Executing: %s\n", input);
276 print_reply(argc, argv)
281 for (i = 0; i < argc; i++) {
282 if (i != 0) printf(", ");
283 printf("%s", argv[i]);
290 test_query(argc, argv)
296 com_err("moira (query)", 0, "Usage: query handle [ args ... ]");
301 status = mr_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
302 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
303 if (status) com_err("moira (query)", status, "");
306 test_access(argc, argv)
312 com_err("moira (access)", 0, "Usage: access handle [ args ... ]");
315 status = mr_access(argv[1], argc-2, argv+2);
316 if (status) com_err("moira (access)", status, "");
326 if (status = mr_do_update())
327 com_err("moira (dcm)", status, " while triggering dcm");
331 test_motd(argc, argv)
338 if (status = mr_motd(&motd))
339 com_err("moira (motd)", status, " while getting motd");
341 printf("%s\n", motd);
343 printf("No message of the day.\n");
348 printf("Available moira requests:\n");
350 printf("noop\t\t\tAsk Moira to do nothing\n");
351 printf("connect, c\t\tConnect to Moira server\n");
352 printf("disconnect, d\t\tDisconnect from server\n");
353 printf("host\t\t\tIdentify the server host\n");
354 printf("new, 2\t\t\tUse new protocol\n");
355 printf("old, 1\t\t\tUse old protocol\n");
356 printf("motd, m\t\t\tGet the Message of the Day\n");
357 printf("query, qy\t\tMake a query.\n");
358 printf("auth, a\t\t\tAuthenticate to Moira.\n");
359 printf("access\t\t\tCheck access to a Moira query.\n");
360 printf("dcm\t\t\tTrigger the DCM\n");
361 printf("script, s\t\tRead commands from a script.\n");
362 printf("list_requests, lr, ?\tList available commands.\n");
363 printf("quit, Q\t\t\tLeave the subsystem.\n");