]>
Commit | Line | Data |
---|---|---|
1 | #if (!defined(lint) && !defined(SABER)) | |
2 | static char rcsid_module_c[] = "$Header$"; | |
3 | #endif lint | |
4 | ||
5 | /* This is the file printer.c for the MOIRA Client, which allows a nieve | |
6 | * user to quickly and easily maintain most parts of the MOIRA database. | |
7 | * It Contains: Functions for handling the printers. | |
8 | * | |
9 | * Created: 8/16/88 | |
10 | * By: Theodore Y. Ts'o | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
16 | * Copyright 1988 by the Massachusetts Institute of Technology. | |
17 | * | |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <strings.h> | |
24 | #include <ctype.h> | |
25 | #include <moira.h> | |
26 | #include <moira_site.h> | |
27 | #include <menu.h> | |
28 | ||
29 | #include "mit-copyright.h" | |
30 | #include "defs.h" | |
31 | #include "f_defs.h" | |
32 | #include "globals.h" | |
33 | ||
34 | #define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU" | |
35 | ||
36 | /* Function Name: SetDefaults | |
37 | * Description: sets the default values for filesystem additions. | |
38 | * Arguments: info - an array of char pointers to recieve defaults. | |
39 | * Returns: char ** (this array, now filled). | |
40 | */ | |
41 | ||
42 | static char ** | |
43 | SetDefaults(info, name) | |
44 | char ** info; | |
45 | char * name; | |
46 | { | |
47 | char spool_dir[256]; | |
48 | ||
49 | strcpy(spool_dir, "/usr/spool/printer/"); | |
50 | strcat(spool_dir, name); | |
51 | ||
52 | info[PCAP_NAME] = Strsave(name); | |
53 | info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE); | |
54 | info[PCAP_SPOOL_DIR] = Strsave(spool_dir); | |
55 | info[PCAP_RPRINTER] = Strsave(name); | |
56 | info[PCAP_QSERVER] = Strsave("\\[NONE\\]"); | |
57 | info[PCAP_AUTH] = Strsave("1"); | |
58 | info[PCAP_PRICE] = Strsave("10"); | |
59 | info[PCAP_COMMENTS] = Strsave(""); | |
60 | info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL; | |
61 | ||
62 | info[PCAP_END] = NULL; | |
63 | return(info); | |
64 | } | |
65 | ||
66 | /* Function Name: GetPcapInfo | |
67 | * Description: Stores the info in a queue. | |
68 | * Arguments: name - name of the item to get information on. | |
69 | * Returns: a pointer to the first element in the queue or null | |
70 | * if printer not found. | |
71 | */ | |
72 | ||
73 | static struct qelem * | |
74 | GetPcapInfo(name) | |
75 | char *name; | |
76 | ||
77 | { | |
78 | int stat; | |
79 | struct qelem *elem = NULL; | |
80 | ||
81 | if ( (stat = do_mr_query("get_printcap_entry", 1, &name, | |
82 | StoreInfo, (char *)&elem)) != 0) { | |
83 | com_err(program_name, stat, " in GetPcapInfo"); | |
84 | return(NULL); | |
85 | } | |
86 | return(QueueTop(elem)); | |
87 | } | |
88 | ||
89 | /* Function Name: PrintPcapInfo | |
90 | * Description: Yet another specialized print function. | |
91 | * Arguments: info - all info about this Printer. | |
92 | * Returns: none | |
93 | */ | |
94 | ||
95 | static void | |
96 | PrintPcapInfo(info) | |
97 | char ** info; | |
98 | { | |
99 | char buf[BUFSIZ]; | |
100 | ||
101 | if (!info) { /* If no informaion */ | |
102 | Put_message("PrintPcapInfo called with null info!"); | |
103 | return; | |
104 | } | |
105 | sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME], | |
106 | info[PCAP_SPOOL_HOST]); | |
107 | Put_message(buf); | |
108 | sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s", | |
109 | info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]); | |
110 | Put_message(buf); | |
111 | sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s", | |
112 | atoi(info[PCAP_AUTH]) ? "yes" : "no", | |
113 | info[PCAP_PRICE], info[PCAP_QSERVER]); | |
114 | Put_message(buf); | |
115 | sprintf(buf, "Comments: %s", info[PCAP_COMMENTS]); | |
116 | Put_message(buf); | |
117 | sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME], | |
118 | info[PCAP_MODWITH]); | |
119 | Put_message(buf); | |
120 | } | |
121 | ||
122 | /* Function Name: AskPcapInfo. | |
123 | * Description: This function askes the user for information about a | |
124 | * printer and saves it into a structure. | |
125 | * Arguments: info - a pointer the the structure to put the | |
126 | * info into. | |
127 | * Returns: none. | |
128 | */ | |
129 | ||
130 | static char ** | |
131 | AskPcapInfo(info) | |
132 | char ** info; | |
133 | { | |
134 | char temp_buf[BUFSIZ]; | |
135 | ||
136 | Put_message(""); | |
137 | sprintf(temp_buf, "Printcap entry for %s.", | |
138 | info[PCAP_NAME]); | |
139 | Put_message(temp_buf); | |
140 | Put_message(""); | |
141 | ||
142 | if (GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]) == SUB_ERROR) | |
143 | return(NULL); | |
144 | info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]); | |
145 | if (GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]) == | |
146 | SUB_ERROR) | |
147 | return(NULL); | |
148 | if (GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]) == | |
149 | SUB_ERROR) | |
150 | return(NULL); | |
151 | if (!strcmp(info[PCAP_QSERVER], "[NONE]")) { | |
152 | free(info[PCAP_QSERVER]); | |
153 | info[PCAP_QSERVER] = strsave("\\[NONE\\]"); | |
154 | } | |
155 | if (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) == | |
156 | SUB_ERROR) | |
157 | return(NULL); | |
158 | info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]); | |
159 | if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) == | |
160 | SUB_ERROR) | |
161 | return(NULL); | |
162 | if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR) | |
163 | return(NULL); | |
164 | if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR) | |
165 | return(NULL); | |
166 | ||
167 | FreeAndClear(&info[PCAP_MODTIME], TRUE); | |
168 | FreeAndClear(&info[PCAP_MODBY], TRUE); | |
169 | FreeAndClear(&info[PCAP_MODWITH], TRUE); | |
170 | ||
171 | return(info); | |
172 | } | |
173 | ||
174 | /* ---------------- Printer Menu ------------------ */ | |
175 | ||
176 | /* Function Name: GetPcap | |
177 | * Description: Get Printcap information | |
178 | * Arguments: argc, argv - name of filsys in argv[1]. | |
179 | * Returns: DM_NORMAL. | |
180 | */ | |
181 | ||
182 | /* ARGSUSED */ | |
183 | int | |
184 | GetPcap(argc, argv) | |
185 | int argc; | |
186 | char **argv; | |
187 | { | |
188 | struct qelem *top; | |
189 | ||
190 | top = GetPcapInfo(argv[1]); /* get info. */ | |
191 | Loop(top, (void *) PrintPcapInfo); | |
192 | FreeQueue(top); /* clean the queue. */ | |
193 | return (DM_NORMAL); | |
194 | } | |
195 | ||
196 | /* Function Name: RealDeletePcap | |
197 | * Description: Does the real deletion work. | |
198 | * Arguments: info - array of char *'s containing all useful info. | |
199 | * one_item - a Boolean that is true if only one item | |
200 | * in queue that dumped us here. | |
201 | * Returns: none. | |
202 | */ | |
203 | ||
204 | void | |
205 | RealDeletePcap(info, one_item) | |
206 | char ** info; | |
207 | Bool one_item; | |
208 | { | |
209 | int stat; | |
210 | ||
211 | if ( (stat = do_mr_query("delete_printcap_entry", 1, | |
212 | &info[PCAP_NAME], Scream, NULL)) != 0) | |
213 | com_err(program_name, stat, " printcap entry not deleted."); | |
214 | else | |
215 | Put_message("Printcap entry deleted."); | |
216 | } | |
217 | ||
218 | /* Function Name: DeletePcap | |
219 | * Description: Delete a printcap entry given its name. | |
220 | * Arguments: argc, argv - argv[1] is the name of the printer. | |
221 | * Returns: none. | |
222 | */ | |
223 | ||
224 | /* ARGSUSED */ | |
225 | ||
226 | int | |
227 | DeletePcap(argc, argv) | |
228 | int argc; | |
229 | char **argv; | |
230 | { | |
231 | struct qelem *elem = GetPcapInfo(argv[1]); | |
232 | QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer"); | |
233 | ||
234 | FreeQueue(elem); | |
235 | return (DM_NORMAL); | |
236 | } | |
237 | ||
238 | /* Function Name: AddPcap | |
239 | * Description: Add a printcap entry | |
240 | * Arguments: arc, argv - name of printer in argv[1]. | |
241 | * Returns: DM_NORMAL. | |
242 | */ | |
243 | ||
244 | /* ARGSUSED */ | |
245 | int | |
246 | AddPcap(argc, argv) | |
247 | char **argv; | |
248 | int argc; | |
249 | { | |
250 | char *info[MAX_ARGS_SIZE], **args; | |
251 | int stat; | |
252 | ||
253 | if ( !ValidName(argv[1]) ) | |
254 | return(DM_NORMAL); | |
255 | ||
256 | if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1, | |
257 | NullFunc, NULL)) == 0) { | |
258 | Put_message ("A Printer by that name already exists."); | |
259 | return(DM_NORMAL); | |
260 | } else if (stat != MR_NO_MATCH) { | |
261 | com_err(program_name, stat, " in AddPcap"); | |
262 | return(DM_NORMAL); | |
263 | } | |
264 | ||
265 | args = AskPcapInfo(SetDefaults(info, argv[1])); | |
266 | if (args == NULL) { | |
267 | Put_message("Aborted."); | |
268 | return(DM_NORMAL); | |
269 | } | |
270 | ||
271 | if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args, | |
272 | NullFunc, NULL)) != 0) | |
273 | com_err(program_name, stat, " in AddPcap"); | |
274 | ||
275 | FreeInfo(info); | |
276 | return (DM_NORMAL); | |
277 | } | |
278 | ||
279 | ||
280 | /* Function Name: ChangePcap | |
281 | * Description: Do the work of changing a pcap | |
282 | * Arguments: argc, argv - printcap info | |
283 | * Returns: | |
284 | */ | |
285 | ||
286 | int | |
287 | ChangePcap(info, one_item) | |
288 | char **info; | |
289 | Bool one_item; | |
290 | { | |
291 | int stat; | |
292 | char **oldinfo; | |
293 | ||
294 | oldinfo = CopyInfo(info); | |
295 | if (AskPcapInfo(info) == NULL) | |
296 | return(DM_QUIT); | |
297 | if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME], | |
298 | Scream, NULL)) != 0) { | |
299 | com_err(program_name, stat, " printcap entry not deleted."); | |
300 | return(DM_NORMAL); | |
301 | } | |
302 | if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info, | |
303 | NullFunc, NULL)) != 0) { | |
304 | com_err(program_name, stat, " in ChngPcap"); | |
305 | if ((stat = do_mr_query("add_printcap_entry", CountArgs(oldinfo) - 3, | |
306 | oldinfo, NullFunc, NULL)) != 0) | |
307 | com_err(program_name, stat, " while attempting to put old info back"); | |
308 | } | |
309 | FreeInfo(oldinfo); | |
310 | return(DM_NORMAL); | |
311 | } | |
312 | ||
313 | ||
314 | /* Function Name: ChngPcap | |
315 | * Description: Update the printcap information | |
316 | * Arguments: argc, argv - name of printer in argv[1]. | |
317 | * Returns: DM_NORMAL. | |
318 | */ | |
319 | ||
320 | int | |
321 | ChngPcap(argc, argv) | |
322 | int argc; | |
323 | char **argv; | |
324 | { | |
325 | struct qelem *elem = GetPcapInfo(argv[1]); | |
326 | QueryLoop(elem, NullPrint, ChangePcap, "Change the printer"); | |
327 | FreeQueue(elem); | |
328 | return(DM_NORMAL); | |
329 | } | |
330 | ||
331 | ||
332 | /* Function Name: SetPdDefaults | |
333 | * Description: sets the default values for palladium additions. | |
334 | * Arguments: info - an array of char pointers to recieve defaults. | |
335 | * Returns: char ** (this array, now filled). | |
336 | */ | |
337 | ||
338 | static char ** | |
339 | SetPdDefaults(info, name) | |
340 | char ** info; | |
341 | char * name; | |
342 | { | |
343 | info[PD_NAME] = Strsave(name); | |
344 | info[PD_IDENT] = Strsave("10000"); | |
345 | info[PD_HOST] = Strsave(DEFAULT_MACHINE); | |
346 | info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL; | |
347 | ||
348 | info[PD_END] = NULL; | |
349 | return(info); | |
350 | } | |
351 | ||
352 | /* Function Name: AskPalladiumInfo. | |
353 | * Description: This function askes the user for information about a | |
354 | * printer and saves it into a structure. | |
355 | * Arguments: info - a pointer the the structure to put the | |
356 | * info into. | |
357 | * Returns: none. | |
358 | */ | |
359 | ||
360 | static char ** | |
361 | AskPalladiumInfo(info) | |
362 | char ** info; | |
363 | { | |
364 | char temp_buf[BUFSIZ]; | |
365 | ||
366 | Put_message(""); | |
367 | sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", | |
368 | info[PD_NAME]); | |
369 | Put_message(temp_buf); | |
370 | Put_message(""); | |
371 | ||
372 | if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR) | |
373 | return(NULL); | |
374 | if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) == | |
375 | SUB_ERROR) | |
376 | return(NULL); | |
377 | info[PD_HOST] = canonicalize_hostname(info[PD_HOST]); | |
378 | ||
379 | FreeAndClear(&info[PD_MODTIME], TRUE); | |
380 | FreeAndClear(&info[PD_MODBY], TRUE); | |
381 | FreeAndClear(&info[PD_MODWITH], TRUE); | |
382 | ||
383 | return(info); | |
384 | } | |
385 | ||
386 | ||
387 | /* Function Name: PrintPalladiumInfo | |
388 | * Description: Yet another specialized print function. | |
389 | * Arguments: info - all info about this Printer. | |
390 | * Returns: none | |
391 | */ | |
392 | ||
393 | static void | |
394 | PrintPalladiumInfo(info) | |
395 | char ** info; | |
396 | { | |
397 | char buf[BUFSIZ]; | |
398 | ||
399 | if (!info) { /* If no informaion */ | |
400 | Put_message("PrintPalladiumInfo called with null info!"); | |
401 | return; | |
402 | } | |
403 | ||
404 | sprintf(buf, "Name: %-24s Program #: %s Host: %s", | |
405 | info[PD_NAME], info[PD_IDENT], info[PD_HOST]); | |
406 | Put_message(buf); | |
407 | sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME], | |
408 | info[PD_MODWITH]); | |
409 | Put_message(buf); | |
410 | } | |
411 | ||
412 | ||
413 | static struct qelem * | |
414 | GetPalladiumInfo(name) | |
415 | char *name; | |
416 | { | |
417 | int status; | |
418 | struct qelem *elem = NULL; | |
419 | ||
420 | if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem)) | |
421 | != 0) { | |
422 | com_err(program_name, status, " in GetPalladiumInfo"); | |
423 | return(NULL); | |
424 | } | |
425 | return(QueueTop(elem)); | |
426 | } | |
427 | ||
428 | ||
429 | int ChangePalladium(info, one_item) | |
430 | char **info; | |
431 | Bool one_item; | |
432 | { | |
433 | int status; | |
434 | ||
435 | if (AskPalladiumInfo(info) == NULL) | |
436 | return(DM_QUIT); | |
437 | if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME], | |
438 | Scream, NULL)) != 0) { | |
439 | com_err(program_name, status, " palladium entry not deleted."); | |
440 | return(DM_NORMAL); | |
441 | } | |
442 | if ((status = do_mr_query("add_palladium", CountArgs(info), info, | |
443 | NullFunc, NULL)) != 0) | |
444 | com_err(program_name, status, " in ChngPalladium"); | |
445 | return(DM_NORMAL); | |
446 | } | |
447 | ||
448 | ||
449 | /* Function Name: RealDeletePalladium | |
450 | * Description: Does the real deletion work. | |
451 | * Arguments: info - array of char *'s containing all useful info. | |
452 | * one_item - a Boolean that is true if only one item | |
453 | * in queue that dumped us here. | |
454 | * Returns: none. | |
455 | */ | |
456 | ||
457 | void | |
458 | RealDeletePalladium(info, one_item) | |
459 | char ** info; | |
460 | Bool one_item; | |
461 | { | |
462 | int stat; | |
463 | ||
464 | if ( (stat = do_mr_query("delete_palladium", 1, | |
465 | &info[PD_NAME], Scream, NULL)) != 0) | |
466 | com_err(program_name, stat, " palladium entry not deleted."); | |
467 | else | |
468 | Put_message("Palladium entry deleted."); | |
469 | } | |
470 | ||
471 | ||
472 | int GetPalladium(argc, argv) | |
473 | int argc; | |
474 | char **argv; | |
475 | { | |
476 | struct qelem *top; | |
477 | ||
478 | top = GetPalladiumInfo(argv[1]); | |
479 | Loop(top, PrintPalladiumInfo); | |
480 | FreeQueue(top); | |
481 | return(DM_NORMAL); | |
482 | } | |
483 | ||
484 | ||
485 | int AddPalladium(argc, argv) | |
486 | int argc; | |
487 | char **argv; | |
488 | { | |
489 | char *info[MAX_ARGS_SIZE], **args; | |
490 | int status; | |
491 | ||
492 | if (!ValidName(argv[1])) | |
493 | return(DM_NORMAL); | |
494 | ||
495 | if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL)) | |
496 | == 0) { | |
497 | Put_message("A server or supervisor by that name already exists."); | |
498 | return(DM_NORMAL); | |
499 | } else if (status != MR_NO_MATCH) { | |
500 | com_err(program_name, status, " in AddPalladium"); | |
501 | return(DM_NORMAL); | |
502 | } | |
503 | ||
504 | args = AskPalladiumInfo(SetPdDefaults(info, argv[1])); | |
505 | if (args == NULL) { | |
506 | Put_message("Aborted."); | |
507 | return(DM_NORMAL); | |
508 | } | |
509 | ||
510 | if ((status = do_mr_query("add_palladium", CountArgs(args), args, | |
511 | Scream, NULL)) != 0) | |
512 | com_err(program_name, status, " in AddPalladium"); | |
513 | ||
514 | FreeInfo(info); | |
515 | return(DM_NORMAL); | |
516 | } | |
517 | ||
518 | ||
519 | int ChngPalladium(argc, argv) | |
520 | int argc; | |
521 | char **argv; | |
522 | { | |
523 | struct qelem *elem = GetPalladiumInfo(argv[1]); | |
524 | QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor"); | |
525 | FreeQueue(elem); | |
526 | return(DM_NORMAL); | |
527 | } | |
528 | ||
529 | ||
530 | int DeletePalladium(argc, argv) | |
531 | int argc; | |
532 | char **argv; | |
533 | { | |
534 | struct qelem *elem = GetPalladiumInfo(argv[1]); | |
535 | QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor"); | |
536 | FreeQueue(elem); | |
537 | return(DM_NORMAL); | |
538 | } | |
539 | ||
540 | int ShowPalladiumAlias(argc, argv) | |
541 | int argc; | |
542 | char **argv; | |
543 | { | |
544 | struct qelem *elem = NULL; | |
545 | char *qargv[3], buf[BUFSIZ]; | |
546 | int status; | |
547 | ||
548 | qargv[0] = argv[1]; | |
549 | qargv[1] = "PALLADIUM"; | |
550 | qargv[2] = argv[2]; | |
551 | if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) { | |
552 | com_err(program_name, status, " in ShowPalladiumAlias"); | |
553 | return(DM_NORMAL); | |
554 | } | |
555 | elem = QueueTop(elem); | |
556 | Put_message(""); | |
557 | while (elem != NULL) { | |
558 | char **info = (char **) elem->q_data; | |
559 | sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]); | |
560 | Put_message(buf); | |
561 | elem = elem->q_forw; | |
562 | } | |
563 | ||
564 | FreeQueue(QueueTop(elem)); | |
565 | return(DM_NORMAL); | |
566 | } | |
567 | ||
568 | int AddPalladiumAlias(argc, argv) | |
569 | int argc; | |
570 | char **argv; | |
571 | { | |
572 | int status; | |
573 | char *qargv[3]; | |
574 | ||
575 | qargv[0] = argv[1]; | |
576 | qargv[1] = "PALLADIUM"; | |
577 | qargv[2] = argv[2]; | |
578 | if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0) | |
579 | com_err(program_name, status, " in AddPalladiumAlias"); | |
580 | return(DM_NORMAL); | |
581 | } | |
582 | ||
583 | int DeletePalladiumAlias(argc, argv) | |
584 | int argc; | |
585 | char **argv; | |
586 | { | |
587 | int status; | |
588 | char *qargv[3]; | |
589 | ||
590 | qargv[0] = argv[1]; | |
591 | qargv[1] = "PALLADIUM"; | |
592 | qargv[2] = argv[2]; | |
593 | if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0) | |
594 | com_err(program_name, status, " in DeletePalladiumAlias"); | |
595 | return(DM_NORMAL); | |
596 | } |