1 /* $NetBSD: pcnfsd_test.c,v 1.2 1995/07/25 22:21:01 gwr Exp $ */
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 */
12 char spooldirbuff
[256];
13 char filenamebuff
[256];
14 char last_id
[32] = "";
16 void free_pr_list_item();
17 void free_pr_queue_item();
31 char *transport
= "udp";
33 if((argc
< 6) || (argc
> 7)) {
34 fprintf(stderr
, "usage: %s server host printer user password [transport]\n",
47 cl
= clnt_create(server
, PCNFSDPROG
, PCNFSDVERS
, transport
);
49 clnt_pcreateerror(server
);
52 cl2
= clnt_create(server
, PCNFSDPROG
, PCNFSDV2
, transport
);
54 clnt_pcreateerror(server
);
60 test_v2_auth(host_name
, user_name
, passwd
);
61 bad("Invalid password");
62 test_v2_auth(host_name
, user_name
, "bogus");
66 test_v2_init(host_name
, printer
);
68 test_v2_start(host_name
, printer
, user_name
, "foo", "foo");
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");
74 test_v2_queue(printer
, user_name
, FALSE
);
76 bad("Cancelling job with bad username");
77 test_v2_cancel(host_name
, printer
, "nosuchuser", last_id
);
79 test_v2_cancel(host_name
, printer
, user_name
, last_id
);
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
);
86 test_v2_queue(printer
, user_name
, TRUE
);
87 bad("Checking queue on invalid printer");
88 test_v2_queue("nosuchprinter", user_name
, TRUE
);
90 test_v2_stat(printer
);
91 bad("Checking status of invalid printer");
92 test_v2_stat("nosuchprinter");
108 *s2
++ = (*s1
^ zchar
) & 0x7f;
123 a
.vers
= "Sun Microsystems PCNFSD test subsystem V1";
125 printf("\ninvoking pr_info_2\n");
127 rp
= pcnfsd2_info_2(&a
, cl2
);
130 clnt_perror(cl2
, server
);
134 printf("results: vers = '%s', cm = '%s'\n",
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
++);
143 /* free up allocated strings */
146 if(rp
->facilities
.facilities_val
)
147 free(rp
->facilities
.facilities_val
);
154 test_v2_auth(host_name
, user_name
, pwrd
)
166 scramble(user_name
, uname
);
168 a
.system
= host_name
;
172 printf("\ninvoking pr_auth_2\n");
174 rp
= pcnfsd2_auth_2(&a
, cl2
);
177 clnt_perror(cl2
, server
);
181 if(rp
->stat
== AUTH_RES_FAIL
)
182 printf("results: stat = AUTH_RES_FAIL\n");
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
++);
194 /* free up allocated strings */
197 if(rp
->gids
.gids_val
)
198 free(rp
->gids
.gids_val
);
205 test_v2_init(host_name
, printer
)
210 v2_pr_init_results
*rp
;
212 a
.system
= host_name
;
215 printf("\ninvoking pr_init_2\n");
217 rp
= pcnfsd2_pr_init_2(&a
, cl2
);
220 clnt_perror(cl2
, server
);
223 printf("results: stat = %d, dir = '%s', cm = '%s'\n",
224 rp
->stat
, rp
->dir
, rp
->cm
);
225 strlcpy(spooldirbuff
, rp
->dir
, sizeof(spooldirbuff
));
226 /* free up allocated strings */
235 test_v2_start(host_name
, printer
, user_name
, tag1
, tag2
)
243 v2_pr_start_results
*rp
;
245 printf("\ntesting start print v2\n");
247 if(strcmp(server
, "localhost")) {
248 printf("sorry - can only test start print on 'localhost'\n");
252 snprintf(filenamebuff
, sizeof(filenamebuff
), "%s/%s",
255 fp
= fopen(filenamebuff
, "w");
257 perror("creating test file");
260 (void)fputs("foo bar bletch\n", fp
);
263 a
.system
= host_name
;
271 printf("\ninvoking pr_start_2\n");
273 rp
= pcnfsd2_pr_start_2(&a
, cl2
);
276 clnt_perror(cl2
, server
);
279 printf("results: stat = %d, jobid = '%s', cm = '%s'\n",
280 rp
->stat
, rp
->id
, rp
->cm
);
281 if(rp
->stat
== PS_RES_OK
)
282 strlcpy(last_id
, rp
->id
, sizeof(last_id
));
283 /* free up allocated strings */
292 test_v2_cancel(host_name
, printer
, user_name
, id
)
299 v2_pr_cancel_results
*rp
;
300 printf("\ntesting cancel print v2\n");
302 a
.system
= host_name
;
308 printf("\ninvoking pr_cancel_2 for job %s on printer %s\n",
311 rp
= pcnfsd2_pr_cancel_2(&a
, cl2
);
314 clnt_perror(cl2
, server
);
317 printf("results: stat = %d, cm = '%s'\n",
319 /* free up allocated strings */
327 v2_pr_list_results
*rp
;
331 printf("\ninvoking pr_list_2\n");
333 rp
= pcnfsd2_pr_list_2(&a
, cl2
);
336 clnt_perror(cl2
, server
);
339 printf("results: cm = '%s', printerlist:\n", rp
->cm
);
342 printf(" name '%s' ", curr
->pn
);
343 if(strlen(curr
->remhost
))
344 printf("remote: srvr '%s', name '%s'",
348 printf("local device = '%s'", curr
->device
);
349 printf(", cm = '%s'\n", curr
->cm
);
350 curr
= curr
->pr_next
;
352 printf("end of list\n");
353 /* free up allocated strings */
357 printf("freeing results\n");
358 free_pr_list_item(rp
->printers
);
365 free_pr_list_item(curr
)
377 free_pr_list_item(curr
->pr_next
); /* recurse */
383 test_v2_queue(printer
, user_name
, private)
388 struct v2_pr_queue_args a
;
389 v2_pr_queue_results
*rp
;
395 a
.just_mine
= private;
398 printf("\ninvoking pr_queue_2 (just_mine = %d)\n", private);
400 rp
= pcnfsd2_pr_queue_2(&a
, cl2
);
403 clnt_perror(cl2
, server
);
406 printf("results: stat = %d, qlen = %d, qshown = %d cm = '%s', queue:\n",
407 rp
->stat
, rp
->qlen
, rp
->qshown
, rp
->cm
);
410 printf("rank = %2d, id = '%s', size = '%s', status = '%s'\n",
415 printf(" user = '%s', file = '%s', cm = '%s'\n",
419 curr
= curr
->pr_next
;
421 printf("end of list\n");
422 /* free up allocated strings */
426 printf("freeing results\n");
427 free_pr_queue_item(rp
->jobs
);
435 free_pr_queue_item(curr
)
453 free_pr_queue_item(curr
->pr_next
); /* recurse */
459 test_v2_stat(printer
)
463 v2_pr_status_results
*rp
;
465 printf("\ntesting status print v2\n");
470 printf("\ninvoking pr_status_2\n");
472 rp
= pcnfsd2_pr_status_2(&a
, cl2
);
475 clnt_perror(cl2
, server
);
478 printf("results: stat = %d, cm = '%s'\n",
480 if(rp
->stat
== PI_RES_OK
) {
481 printf("avail = %s, ", (rp
->avail
? "YES" : "NO"));
482 printf("printing = %s, ", (rp
->printing
? "YES" : "NO"));
483 printf("needs_operator = %s, ", (rp
->needs_operator
? "YES" : "NO"));
484 printf("qlen = %d, status = '%s'\n", rp
->qlen
, rp
->status
);
486 /* free up allocated strings */
494 struct mapreq_arg_item
* make_mapreq_entry(t
, i
, n
, next
)
498 struct mapreq_arg_item
*next
;
500 struct mapreq_arg_item
*x
;
501 x
= (struct mapreq_arg_item
*)malloc(sizeof(struct mapreq_arg_item
));
503 fprintf(stderr
, "out of memory\n");
508 x
->name
= (n
? n
: "");
509 x
->mapreq_next
= next
;
516 v2_mapid_results
*rp
;
517 struct mapreq_res_item
*rip
;
520 a
.req_list
= make_mapreq_entry(MAP_REQ_UID
, 906, NULL
,
521 make_mapreq_entry(MAP_REQ_GID
, 1, NULL
,
522 make_mapreq_entry(MAP_REQ_UNAME
, 0, "root",
523 make_mapreq_entry(MAP_REQ_GNAME
, 0, "wheel",
524 make_mapreq_entry(MAP_REQ_UNAME
, 0, "bogus", NULL
)))));
526 printf("\ninvoking pr_mapid_2\n");
527 rp
= pcnfsd2_mapid_2(&a
, cl2
);
530 clnt_perror(cl2
, server
);
533 printf("results: cm = '%s', result list %s\n",
534 rp
->cm
, rp
->res_list
? "follows" : "omitted");
537 printf("request type = %d, status = %d, id = %d, name = '%s'\n",
538 rip
->req
, rip
->stat
, rip
->id
,
539 (rip
->name
? rip
->name
: "(NULL)"));
540 rip
= rip
->mapreq_next
;
542 /* XXX should free up results */
554 printf("********************************************************\n");
555 printf("********************************************************\n");
556 printf("** The following test is expected to SUCCEED **\n");
557 printf("********************************************************\n");
558 printf("********************************************************\n");
566 printf("********************************************************\n");
567 printf("********************************************************\n");
568 printf("** The following test is expected to FAIL **\n");
569 printf("** Reason: **\n");
570 printf("** %50s **\n", reason
);
571 printf("********************************************************\n");
572 printf("********************************************************\n");