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