pcnfsd_test.c revision 1.2 1 /* $NetBSD: pcnfsd_test.c,v 1.2 1995/07/25 22:21:01 gwr Exp $ */
2
3 /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_test.c 1.2 92/01/27 18:00:39 SMI */
4 #include <stdio.h>
5 #include <rpc/rpc.h>
6 #include <malloc.h>
7 #include "pcnfsd.h"
8
9 CLIENT *cl;
10 CLIENT *cl2;
11 char *server;
12 char spooldirbuff[256];
13 char filenamebuff[256];
14 char last_id[32] = "";
15
16 void free_pr_list_item();
17 void free_pr_queue_item();
18 void good();
19 void bad();
20
21
22 main(argc, argv)
23 int argc;
24 char *argv[];
25 {
26
27 char *host_name;
28 char *printer;
29 char *user_name;
30 char *passwd;
31 char *transport = "udp";
32
33 if((argc < 6) || (argc > 7)) {
34 fprintf(stderr, "usage: %s server host printer user password [transport]\n",
35 argv[0]);
36 exit(1);
37 }
38
39 server = argv[1];
40 host_name = argv[2];
41 printer = argv[3];
42 user_name = argv[4];
43 passwd = argv[5];
44 if (argc == 7)
45 transport = argv[6];
46
47 cl = clnt_create(server, PCNFSDPROG, PCNFSDVERS, transport);
48 if(cl == NULL) {
49 clnt_pcreateerror(server);
50 exit(1);
51 }
52 cl2 = clnt_create(server, PCNFSDPROG, PCNFSDV2, transport);
53 if(cl2 == NULL) {
54 clnt_pcreateerror(server);
55 exit(1);
56 }
57 good();
58 test_v2_info();
59 good();
60 test_v2_auth(host_name, user_name, passwd);
61 bad("Invalid password");
62 test_v2_auth(host_name, user_name, "bogus");
63 good();
64 test_v2_list();
65 good();
66 test_v2_init(host_name, printer);
67 good();
68 test_v2_start(host_name, printer, user_name, "foo", "foo");
69 good();
70 test_v2_start(host_name, printer, user_name, "bar", "bar");
71 bad("No such file to print");
72 test_v2_start(host_name, printer, user_name, "bletch", "gack");
73 good();
74 test_v2_queue(printer, user_name, FALSE);
75 if(strlen(last_id)) {
76 bad("Cancelling job with bad username");
77 test_v2_cancel(host_name, printer, "nosuchuser", last_id);
78 good();
79 test_v2_cancel(host_name, printer, user_name, last_id);
80 }
81 bad("Cancelling unknown job");
82 test_v2_cancel(host_name, printer, user_name, "99999");
83 bad("Cancelling job on invalid printer");
84 test_v2_cancel(host_name, "nosuchprinter", user_name, last_id);
85 good();
86 test_v2_queue(printer, user_name, TRUE);
87 bad("Checking queue on invalid printer");
88 test_v2_queue("nosuchprinter", user_name, TRUE);
89 good();
90 test_v2_stat(printer);
91 bad("Checking status of invalid printer");
92 test_v2_stat("nosuchprinter");
93 good();
94 test_v2_map();
95 exit(0);
96 /*NOTREACHED*/
97 }
98
99 #define zchar 0x5b
100
101 void
102 scramble(s1, s2)
103 char *s1;
104 char *s2;
105 {
106 while (*s1)
107 {
108 *s2++ = (*s1 ^ zchar) & 0x7f;
109 s1++;
110 }
111 *s2 = 0;
112 }
113
114
115
116 test_v2_info()
117 {
118 v2_info_args a;
119 v2_info_results *rp;
120 int *gp;
121 int i;
122
123 a.vers = "Sun Microsystems PCNFSD test subsystem V1";
124 a.cm = "-";
125 printf("\ninvoking pr_info_2\n");
126
127 rp = pcnfsd2_info_2(&a, cl2);
128
129 if(rp == NULL) {
130 clnt_perror(cl2, server);
131 return(1);
132 }
133
134 printf("results: vers = '%s', cm = '%s'\n",
135 rp->vers, rp->cm);
136 printf("facilities_len = %d\n", rp->facilities.facilities_len);
137 if (rp->facilities.facilities_len) {
138 gp = rp->facilities.facilities_val;
139 for(i = 0; i < rp->facilities.facilities_len; i++)
140 printf(" procedure %2d: %6d\n", i, *gp++);
141 printf("\n");
142 }
143 /* free up allocated strings */
144 if(rp->cm)
145 free(rp->cm);
146 if(rp->facilities.facilities_val)
147 free(rp->facilities.facilities_val);
148 if(rp->vers)
149 free(rp->vers);
150
151 return(0);
152 }
153
154 test_v2_auth(host_name, user_name , pwrd)
155 char *host_name;
156 char *user_name;
157 char *pwrd;
158 {
159 v2_auth_args a;
160 v2_auth_results *rp;
161 char uname[32];
162 char pw[64];
163 u_int *gp;
164 int i;
165
166 scramble(user_name, uname);
167 scramble(pwrd, pw);
168 a.system = host_name;
169 a.id = uname;
170 a.pw = pw;
171 a.cm = "-";
172 printf("\ninvoking pr_auth_2\n");
173
174 rp = pcnfsd2_auth_2(&a, cl2);
175
176 if(rp == NULL) {
177 clnt_perror(cl2, server);
178 return(1);
179 }
180
181 if(rp->stat == AUTH_RES_FAIL)
182 printf("results: stat = AUTH_RES_FAIL\n");
183 else {
184 printf("results: stat = %d, uid = %u, gid = %u,\n homedir= '%s', cm = '%s'\n",
185 rp->stat, rp->uid, rp->gid, rp->home, rp->cm);
186 printf("gids_len = %d", rp->gids.gids_len);
187 if (rp->gids.gids_len) {
188 gp = rp->gids.gids_val;
189 for(i = 0; i < rp->gids.gids_len; i++)
190 printf(" %u", *gp++);
191 printf("\n");
192 }
193 }
194 /* free up allocated strings */
195 if(rp->cm)
196 free(rp->cm);
197 if(rp->gids.gids_val)
198 free(rp->gids.gids_val);
199 if(rp->home)
200 free(rp->home);
201
202 return(0);
203 }
204
205 test_v2_init(host_name, printer)
206 char *host_name;
207 char *printer;
208 {
209 v2_pr_init_args a;
210 v2_pr_init_results *rp;
211
212 a.system = host_name;
213 a.pn = printer;
214 a.cm = "-";
215 printf("\ninvoking pr_init_2\n");
216
217 rp = pcnfsd2_pr_init_2(&a, cl2);
218
219 if(rp == NULL) {
220 clnt_perror(cl2, server);
221 return(1);
222 }
223 printf("results: stat = %d, dir = '%s', cm = '%s'\n",
224 rp->stat, rp->dir, rp->cm);
225 strcpy(spooldirbuff, rp->dir);
226 /* free up allocated strings */
227 if(rp->cm)
228 free(rp->cm);
229 if(rp->dir)
230 free(rp->dir);
231 return(0);
232 }
233
234
235 test_v2_start(host_name, printer, user_name, tag1, tag2)
236 char *host_name;
237 char *printer;
238 char *user_name;
239 char *tag1;
240 char *tag2;
241 {
242 v2_pr_start_args a;
243 v2_pr_start_results *rp;
244 FILE *fp;
245 printf("\ntesting start print v2\n");
246
247 if(strcmp(server, "localhost")) {
248 printf("sorry - can only test start print on 'localhost'\n");
249 return(1);
250 }
251
252 sprintf(filenamebuff, "%s/%s", spooldirbuff, tag1);
253
254 fp = fopen(filenamebuff, "w");
255 if(fp == NULL) {
256 perror("creating test file");
257 return(1);
258 }
259 (void)fputs("foo bar bletch\n", fp);
260 (void)fclose(fp);
261
262 a.system = host_name;
263 a.pn = printer;
264 a.user = user_name;
265 a.file = tag2;
266 a.opts = "xxxx";
267 a.copies = 1;
268 a.cm = "-";
269
270 printf("\ninvoking pr_start_2\n");
271
272 rp = pcnfsd2_pr_start_2(&a, cl2);
273
274 if(rp == NULL) {
275 clnt_perror(cl2, server);
276 return(1);
277 }
278 printf("results: stat = %d, jobid = '%s', cm = '%s'\n",
279 rp->stat, rp->id, rp->cm);
280 if(rp->stat == PS_RES_OK)
281 strcpy(last_id, rp->id);
282 /* free up allocated strings */
283 if(rp->cm)
284 free(rp->cm);
285 if(rp->id)
286 free(rp->id);
287 return(0);
288 }
289
290
291 test_v2_cancel(host_name, printer, user_name, id)
292 char *host_name;
293 char *printer;
294 char *user_name;
295 char *id;
296 {
297 v2_pr_cancel_args a;
298 v2_pr_cancel_results *rp;
299 printf("\ntesting cancel print v2\n");
300
301 a.system = host_name;
302 a.pn = printer;
303 a.user = user_name;
304 a.id = id;
305 a.cm = "-";
306
307 printf("\ninvoking pr_cancel_2 for job %s on printer %s\n",
308 id, printer);
309
310 rp = pcnfsd2_pr_cancel_2(&a, cl2);
311
312 if(rp == NULL) {
313 clnt_perror(cl2, server);
314 return(1);
315 }
316 printf("results: stat = %d, cm = '%s'\n",
317 rp->stat, rp->cm);
318 /* free up allocated strings */
319 if(rp->cm)
320 free(rp->cm);
321 return(0);
322 }
323 test_v2_list()
324 {
325 char a;
326 v2_pr_list_results *rp;
327 pr_list curr;
328
329
330 printf("\ninvoking pr_list_2\n");
331
332 rp = pcnfsd2_pr_list_2(&a, cl2);
333
334 if(rp == NULL) {
335 clnt_perror(cl2, server);
336 return(1);
337 }
338 printf("results: cm = '%s', printerlist:\n", rp->cm);
339 curr = rp->printers;
340 while(curr) {
341 printf(" name '%s' ", curr->pn);
342 if(strlen(curr->remhost))
343 printf("remote: srvr '%s', name '%s'",
344 curr->remhost,
345 curr->device);
346 else
347 printf("local device = '%s'", curr->device);
348 printf(", cm = '%s'\n", curr->cm);
349 curr = curr->pr_next;
350 }
351 printf("end of list\n");
352 /* free up allocated strings */
353 if(rp->cm)
354 free(rp->cm);
355 if(rp->printers) {
356 printf("freeing results\n");
357 free_pr_list_item(rp->printers);
358 }
359 return(0);
360 }
361
362
363 void
364 free_pr_list_item(curr)
365 pr_list curr;
366 {
367 if(curr->pn)
368 free(curr->pn);
369 if(curr->remhost)
370 free(curr->remhost);
371 if(curr->device)
372 free(curr->device);
373 if(curr->cm)
374 free(curr->cm);
375 if(curr->pr_next)
376 free_pr_list_item(curr->pr_next); /* recurse */
377 free(curr);
378 }
379
380
381
382 test_v2_queue(printer, user_name, private)
383 char *printer;
384 char *user_name;
385 int private;
386 {
387 struct v2_pr_queue_args a;
388 v2_pr_queue_results *rp;
389 pr_queue curr;
390
391 a.pn = printer;
392 a.system = "foo";
393 a.user = user_name;
394 a.just_mine = private;
395 a.cm = "no";
396
397 printf("\ninvoking pr_queue_2 (just_mine = %d)\n", private);
398
399 rp = pcnfsd2_pr_queue_2(&a, cl2);
400
401 if(rp == NULL) {
402 clnt_perror(cl2, server);
403 return(1);
404 }
405 printf("results: stat = %d, qlen = %d, qshown = %d cm = '%s', queue:\n",
406 rp->stat, rp->qlen, rp->qshown, rp->cm);
407 curr = rp->jobs;
408 while(curr) {
409 printf("rank = %2d, id = '%s', size = '%s', status = '%s'\n",
410 curr->position,
411 curr->id,
412 curr->size,
413 curr->status);
414 printf(" user = '%s', file = '%s', cm = '%s'\n",
415 curr->user,
416 curr->file,
417 curr->cm);
418 curr = curr->pr_next;
419 }
420 printf("end of list\n");
421 /* free up allocated strings */
422 if(rp->cm)
423 free(rp->cm);
424 if(rp->jobs) {
425 printf("freeing results\n");
426 free_pr_queue_item(rp->jobs);
427 }
428 return(0);
429 }
430
431
432
433 void
434 free_pr_queue_item(curr)
435 pr_queue curr;
436 {
437 if(curr->id)
438 free(curr->id);
439 if(curr->size)
440 free(curr->size);
441 if(curr->status)
442 free(curr->status);
443 if(curr->system)
444 free(curr->system);
445 if(curr->user)
446 free(curr->user);
447 if(curr->file)
448 free(curr->file);
449 if(curr->cm)
450 free(curr->cm);
451 if(curr->pr_next)
452 free_pr_queue_item(curr->pr_next); /* recurse */
453 free(curr);
454 }
455
456
457
458 test_v2_stat(printer)
459 char *printer;
460 {
461 v2_pr_status_args a;
462 v2_pr_status_results *rp;
463
464 printf("\ntesting status print v2\n");
465
466 a.pn = printer;
467 a.cm = "-";
468
469 printf("\ninvoking pr_status_2\n");
470
471 rp = pcnfsd2_pr_status_2(&a, cl2);
472
473 if(rp == NULL) {
474 clnt_perror(cl2, server);
475 return(1);
476 }
477 printf("results: stat = %d, cm = '%s'\n",
478 rp->stat, rp->cm);
479 if(rp->stat == PI_RES_OK) {
480 printf("avail = %s, ", (rp->avail ? "YES" : "NO"));
481 printf("printing = %s, ", (rp->printing ? "YES" : "NO"));
482 printf("needs_operator = %s, ", (rp->needs_operator ? "YES" : "NO"));
483 printf("qlen = %d, status = '%s'\n", rp->qlen, rp->status);
484 }
485 /* free up allocated strings */
486 if(rp->cm)
487 free(rp->cm);
488 if(rp->status)
489 free(rp->status);
490 return(0);
491 }
492
493 struct mapreq_arg_item * make_mapreq_entry(t, i, n, next)
494 mapreq t;
495 int i;
496 char *n;
497 struct mapreq_arg_item *next;
498 {
499 struct mapreq_arg_item *x;
500 x = (struct mapreq_arg_item *)malloc(sizeof(struct mapreq_arg_item));
501 if(x == NULL) {
502 fprintf(stderr, "out of memory\n");
503 exit(123);
504 }
505 x->req = t;
506 x->id = i;
507 x->name = (n ? n : "");
508 x->mapreq_next = next;
509 return(x);
510 }
511
512 test_v2_map()
513 {
514 v2_mapid_args a;
515 v2_mapid_results *rp;
516 struct mapreq_res_item *rip;
517
518 a.cm = "-";
519 a.req_list = make_mapreq_entry(MAP_REQ_UID, 906, NULL,
520 make_mapreq_entry(MAP_REQ_GID, 1, NULL,
521 make_mapreq_entry(MAP_REQ_UNAME, 0, "root",
522 make_mapreq_entry(MAP_REQ_GNAME, 0, "wheel",
523 make_mapreq_entry(MAP_REQ_UNAME, 0, "bogus", NULL)))));
524
525 printf("\ninvoking pr_mapid_2\n");
526 rp = pcnfsd2_mapid_2(&a, cl2);
527
528 if(rp == NULL) {
529 clnt_perror(cl2, server);
530 return(1);
531 }
532 printf("results: cm = '%s', result list %s\n",
533 rp->cm, rp->res_list ? "follows" : "omitted");
534 rip = rp->res_list;
535 while(rip) {
536 printf("request type = %d, status = %d, id = %d, name = '%s'\n",
537 rip->req, rip->stat, rip->id,
538 (rip->name ? rip->name : "(NULL)"));
539 rip = rip->mapreq_next;
540 }
541 /* XXX should free up results */
542
543
544
545 return(0);
546 }
547
548
549 void
550 good()
551 {
552 printf("\n");
553 printf("********************************************************\n");
554 printf("********************************************************\n");
555 printf("** The following test is expected to SUCCEED **\n");
556 printf("********************************************************\n");
557 printf("********************************************************\n");
558 }
559
560 void
561 bad(reason)
562 char *reason;
563 {
564 printf("\n");
565 printf("********************************************************\n");
566 printf("********************************************************\n");
567 printf("** The following test is expected to FAIL **\n");
568 printf("** Reason: **\n");
569 printf("** %50s **\n", reason);
570 printf("********************************************************\n");
571 printf("********************************************************\n");
572 }
573