]>
Commit | Line | Data |
---|---|---|
cc5b487a | 1 | #if (!defined(lint) && !defined(SABER)) |
2 | static char rcsid_module_c[] = "$Header$"; | |
3 | #endif lint | |
4 | ||
8defc06b | 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. | |
cc5b487a | 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> | |
8defc06b | 25 | #include <moira.h> |
26 | #include <moira_site.h> | |
cc5b487a | 27 | #include <menu.h> |
28 | ||
29 | #include "mit-copyright.h" | |
30 | #include "defs.h" | |
31 | #include "f_defs.h" | |
32 | #include "globals.h" | |
cc5b487a | 33 | |
cc5b487a | 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); | |
dd233c2d | 56 | info[PCAP_QSERVER] = Strsave("\\[NONE\\]"); |
57 | info[PCAP_AUTH] = Strsave("1"); | |
58 | info[PCAP_PRICE] = Strsave("10"); | |
cc5b487a | 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 | ||
dd233c2d | 81 | if ( (stat = do_mr_query("get_printcap_entry", 1, &name, |
14f99d7d | 82 | StoreInfo, (char *)&elem)) != 0) { |
cc5b487a | 83 | com_err(program_name, stat, NULL); |
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); | |
dd233c2d | 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); | |
cc5b487a | 115 | sprintf(buf, "Comments: ", 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], *newname; | |
135 | ||
136 | Put_message(""); | |
137 | sprintf(temp_buf, "Printcap entry for %s.", | |
1b2e1580 | 138 | info[PCAP_NAME]); |
cc5b487a | 139 | Put_message(temp_buf); |
140 | Put_message(""); | |
141 | ||
142 | GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]); | |
2aaf43e0 | 143 | info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]); |
cc5b487a | 144 | GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]); |
145 | GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]); | |
dd233c2d | 146 | if (!strcmp(info[PCAP_QSERVER], "[NONE]")) { |
147 | free(info[PCAP_QSERVER]); | |
148 | info[PCAP_QSERVER] = strsave("\\[NONE\\]"); | |
149 | } | |
150 | GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]); | |
151 | info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]); | |
152 | GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]); | |
153 | GetValueFromUser("Price/page", &info[PCAP_PRICE]); | |
cc5b487a | 154 | GetValueFromUser("Comments", &info[PCAP_COMMENTS]); |
155 | ||
156 | FreeAndClear(&info[PCAP_MODTIME], TRUE); | |
157 | FreeAndClear(&info[PCAP_MODBY], TRUE); | |
158 | FreeAndClear(&info[PCAP_MODWITH], TRUE); | |
159 | ||
160 | return(info); | |
161 | } | |
162 | ||
163 | /* ---------------- Printer Menu ------------------ */ | |
164 | ||
165 | /* Function Name: GetPcap | |
166 | * Description: Get Printcap information | |
167 | * Arguments: argc, argv - name of filsys in argv[1]. | |
168 | * Returns: DM_NORMAL. | |
169 | */ | |
170 | ||
171 | /* ARGSUSED */ | |
172 | int | |
173 | GetPcap(argc, argv) | |
174 | int argc; | |
175 | char **argv; | |
176 | { | |
177 | struct qelem *top; | |
178 | ||
179 | top = GetPcapInfo(argv[1]); /* get info. */ | |
180 | Loop(top, (void *) PrintPcapInfo); | |
181 | FreeQueue(top); /* clean the queue. */ | |
182 | return (DM_NORMAL); | |
183 | } | |
184 | ||
185 | /* Function Name: RealDeletePcap | |
186 | * Description: Does the real deletion work. | |
187 | * Arguments: info - array of char *'s containing all useful info. | |
188 | * one_item - a Boolean that is true if only one item | |
189 | * in queue that dumped us here. | |
190 | * Returns: none. | |
191 | */ | |
192 | ||
193 | void | |
194 | RealDeletePcap(info, one_item) | |
195 | char ** info; | |
196 | Bool one_item; | |
197 | { | |
198 | int stat; | |
199 | char temp_buf[BUFSIZ]; | |
200 | ||
dd233c2d | 201 | if ( (stat = do_mr_query("delete_printcap_entry", 1, |
1b2e1580 | 202 | &info[PCAP_NAME], Scream, NULL)) != 0) |
cc5b487a | 203 | com_err(program_name, stat, " printcap entry not deleted."); |
204 | else | |
205 | Put_message("Printcap entry deleted."); | |
206 | } | |
207 | ||
208 | /* Function Name: DeletePcap | |
209 | * Description: Delete a printcap entry given its name. | |
210 | * Arguments: argc, argv - argv[1] is the name of the printer. | |
211 | * Returns: none. | |
212 | */ | |
213 | ||
214 | /* ARGSUSED */ | |
215 | ||
216 | int | |
217 | DeletePcap(argc, argv) | |
218 | int argc; | |
219 | char **argv; | |
220 | { | |
221 | struct qelem *elem = GetPcapInfo(argv[1]); | |
222 | QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer"); | |
223 | ||
224 | FreeQueue(elem); | |
225 | return (DM_NORMAL); | |
226 | } | |
227 | ||
228 | /* Function Name: AddPcap | |
229 | * Description: Add a printcap entry | |
230 | * Arguments: arc, argv - name of printer in argv[1]. | |
231 | * Returns: DM_NORMAL. | |
232 | */ | |
233 | ||
234 | /* ARGSUSED */ | |
235 | int | |
236 | AddPcap(argc, argv) | |
237 | char **argv; | |
238 | int argc; | |
239 | { | |
240 | char *info[MAX_ARGS_SIZE], **args; | |
241 | int stat; | |
242 | ||
243 | if ( !ValidName(argv[1]) ) | |
244 | return(DM_NORMAL); | |
245 | ||
dd233c2d | 246 | if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1, |
14f99d7d | 247 | NullFunc, NULL)) == 0) { |
cc5b487a | 248 | Put_message ("A Printer by that name already exists."); |
249 | return(DM_NORMAL); | |
8defc06b | 250 | } else if (stat != MR_NO_MATCH) { |
cc5b487a | 251 | com_err(program_name, stat, " in AddPcap"); |
252 | return(DM_NORMAL); | |
253 | } | |
254 | ||
255 | args = AskPcapInfo(SetDefaults(info, argv[1])); | |
256 | ||
dd233c2d | 257 | if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args, |
14f99d7d | 258 | NullFunc, NULL)) != 0) |
cc5b487a | 259 | com_err(program_name, stat, " in AddPcap"); |
260 | ||
261 | FreeInfo(info); | |
262 | return (DM_NORMAL); | |
263 | } | |
264 | ||
265 | ||
f03f1f1b | 266 | /* Function Name: ChangePcap |
267 | * Description: Do the work of changing a pcap | |
268 | * Arguments: argc, argv - printcap info | |
269 | * Returns: | |
270 | */ | |
271 | ||
272 | int | |
273 | ChangePcap(info, one_item) | |
274 | char **info; | |
275 | Bool one_item; | |
276 | { | |
277 | int stat; | |
278 | ||
dd233c2d | 279 | if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME], |
14f99d7d | 280 | Scream, NULL)) != 0) { |
f03f1f1b | 281 | com_err(program_name, stat, " printcap entry not deleted."); |
282 | return(DM_NORMAL); | |
283 | } | |
284 | AskPcapInfo(info); | |
dd233c2d | 285 | if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info, |
14f99d7d | 286 | NullFunc, NULL)) != 0) |
f03f1f1b | 287 | com_err(program_name, stat, " in ChngPcap"); |
288 | return(DM_NORMAL); | |
289 | } | |
290 | ||
291 | ||
292 | /* Function Name: ChngPcap | |
293 | * Description: Update the printcap information | |
294 | * Arguments: argc, argv - name of printer in argv[1]. | |
295 | * Returns: DM_NORMAL. | |
296 | */ | |
297 | ||
298 | int | |
299 | ChngPcap(argc, argv) | |
300 | int argc; | |
301 | char **argv; | |
302 | { | |
303 | struct qelem *elem = GetPcapInfo(argv[1]); | |
304 | QueryLoop(elem, NullPrint, ChangePcap, "Change the printer"); | |
305 | FreeQueue(elem); | |
306 | return(DM_NORMAL); | |
307 | } | |
1b2e1580 | 308 | |
309 | ||
310 | /* Function Name: SetPdDefaults | |
311 | * Description: sets the default values for palladium additions. | |
312 | * Arguments: info - an array of char pointers to recieve defaults. | |
313 | * Returns: char ** (this array, now filled). | |
314 | */ | |
315 | ||
316 | static char ** | |
317 | SetPdDefaults(info, name) | |
318 | char ** info; | |
319 | char * name; | |
320 | { | |
321 | info[PD_NAME] = Strsave(name); | |
24decb93 | 322 | info[PD_IDENT] = Strsave("10000"); |
1b2e1580 | 323 | info[PD_HOST] = Strsave(DEFAULT_MACHINE); |
324 | info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL; | |
325 | ||
326 | info[PD_END] = NULL; | |
327 | return(info); | |
328 | } | |
329 | ||
330 | /* Function Name: AskPalladiumInfo. | |
331 | * Description: This function askes the user for information about a | |
332 | * printer and saves it into a structure. | |
333 | * Arguments: info - a pointer the the structure to put the | |
334 | * info into. | |
335 | * Returns: none. | |
336 | */ | |
337 | ||
338 | static char ** | |
339 | AskPalladiumInfo(info) | |
340 | char ** info; | |
341 | { | |
342 | char temp_buf[BUFSIZ], *newname; | |
343 | ||
344 | Put_message(""); | |
24decb93 | 345 | sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", |
1b2e1580 | 346 | info[PD_NAME]); |
347 | Put_message(temp_buf); | |
348 | Put_message(""); | |
349 | ||
24decb93 | 350 | GetValueFromUser("RPC Program Number", &info[PD_IDENT]); |
351 | GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]); | |
1b2e1580 | 352 | info[PD_HOST] = canonicalize_hostname(info[PD_HOST]); |
353 | ||
354 | FreeAndClear(&info[PD_MODTIME], TRUE); | |
355 | FreeAndClear(&info[PD_MODBY], TRUE); | |
356 | FreeAndClear(&info[PD_MODWITH], TRUE); | |
357 | ||
358 | return(info); | |
359 | } | |
360 | ||
361 | ||
362 | /* Function Name: PrintPalladiumInfo | |
363 | * Description: Yet another specialized print function. | |
364 | * Arguments: info - all info about this Printer. | |
365 | * Returns: none | |
366 | */ | |
367 | ||
368 | static void | |
369 | PrintPalladiumInfo(info) | |
370 | char ** info; | |
371 | { | |
372 | char buf[BUFSIZ]; | |
373 | ||
374 | if (!info) { /* If no informaion */ | |
375 | Put_message("PrintPalladiumInfo called with null info!"); | |
376 | return; | |
377 | } | |
378 | ||
24decb93 | 379 | sprintf(buf, "Name: %-24s Program #: %s Host: %s", |
1b2e1580 | 380 | info[PD_NAME], info[PD_IDENT], info[PD_HOST]); |
381 | Put_message(buf); | |
382 | sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME], | |
383 | info[PD_MODWITH]); | |
384 | Put_message(buf); | |
385 | } | |
386 | ||
387 | ||
388 | static struct qelem * | |
389 | GetPalladiumInfo(name) | |
390 | char *name; | |
391 | { | |
392 | int status; | |
393 | struct qelem *elem = NULL; | |
394 | ||
8defc06b | 395 | if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem)) |
1b2e1580 | 396 | != 0) { |
397 | com_err(program_name, status, NULL); | |
398 | return(NULL); | |
399 | } | |
400 | return(QueueTop(elem)); | |
401 | } | |
402 | ||
403 | ||
404 | int ChangePalladium(info, one_item) | |
405 | char **info; | |
406 | Bool one_item; | |
407 | { | |
408 | int status; | |
409 | ||
8defc06b | 410 | if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME], |
1b2e1580 | 411 | Scream, NULL)) != 0) { |
412 | com_err(program_name, status, " palladium entry not deleted."); | |
413 | return(DM_NORMAL); | |
414 | } | |
415 | AskPalladiumInfo(info); | |
8defc06b | 416 | if ((status = do_mr_query("add_palladium", CountArgs(info), info, |
1b2e1580 | 417 | NullFunc, NULL)) != 0) |
418 | com_err(program_name, status, " in ChngPalladium"); | |
419 | return(DM_NORMAL); | |
420 | } | |
421 | ||
422 | ||
423 | /* Function Name: RealDeletePalladium | |
424 | * Description: Does the real deletion work. | |
425 | * Arguments: info - array of char *'s containing all useful info. | |
426 | * one_item - a Boolean that is true if only one item | |
427 | * in queue that dumped us here. | |
428 | * Returns: none. | |
429 | */ | |
430 | ||
431 | void | |
432 | RealDeletePalladium(info, one_item) | |
433 | char ** info; | |
434 | Bool one_item; | |
435 | { | |
436 | int stat; | |
437 | char temp_buf[BUFSIZ]; | |
438 | ||
8defc06b | 439 | if ( (stat = do_mr_query("delete_palladium", 1, |
1b2e1580 | 440 | &info[PD_NAME], Scream, NULL)) != 0) |
441 | com_err(program_name, stat, " palladium entry not deleted."); | |
442 | else | |
443 | Put_message("Palladium entry deleted."); | |
444 | } | |
445 | ||
446 | ||
447 | int GetPalladium(argc, argv) | |
448 | int argc; | |
449 | char **argv; | |
450 | { | |
451 | struct qelem *elem, *top; | |
452 | char buf[BUFSIZ]; | |
453 | ||
454 | top = GetPalladiumInfo(argv[1]); | |
455 | Loop(top, PrintPalladiumInfo); | |
456 | FreeQueue(top); | |
457 | return(DM_NORMAL); | |
458 | } | |
459 | ||
460 | ||
461 | int AddPalladium(argc, argv) | |
462 | int argc; | |
463 | char **argv; | |
464 | { | |
465 | char *info[MAX_ARGS_SIZE], **args; | |
466 | int status; | |
467 | ||
468 | if (!ValidName(argv[1])) | |
469 | return(DM_NORMAL); | |
470 | ||
8defc06b | 471 | if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL)) |
1b2e1580 | 472 | == 0) { |
24decb93 | 473 | Put_message("A server or supervisor by that name already exists."); |
1b2e1580 | 474 | return(DM_NORMAL); |
8defc06b | 475 | } else if (status != MR_NO_MATCH) { |
1b2e1580 | 476 | com_err(program_name, status, " in AddPalladium"); |
477 | return(DM_NORMAL); | |
478 | } | |
479 | ||
480 | args = AskPalladiumInfo(SetPdDefaults(info, argv[1])); | |
481 | ||
8defc06b | 482 | if ((status = do_mr_query("add_palladium", CountArgs(args), args, |
1b2e1580 | 483 | Scream, NULL)) != 0) |
484 | com_err(program_name, status, " in AddPalladium"); | |
485 | ||
486 | FreeInfo(info); | |
487 | return(DM_NORMAL); | |
488 | } | |
489 | ||
490 | ||
491 | int ChngPalladium(argc, argv) | |
492 | int argc; | |
493 | char **argv; | |
494 | { | |
495 | struct qelem *elem = GetPalladiumInfo(argv[1]); | |
24decb93 | 496 | QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor"); |
1b2e1580 | 497 | FreeQueue(elem); |
498 | return(DM_NORMAL); | |
499 | } | |
500 | ||
501 | ||
502 | int DeletePalladium(argc, argv) | |
503 | int argc; | |
504 | char **argv; | |
505 | { | |
506 | struct qelem *elem = GetPalladiumInfo(argv[1]); | |
24decb93 | 507 | QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor"); |
1b2e1580 | 508 | FreeQueue(elem); |
509 | return(DM_NORMAL); | |
510 | } | |
511 | ||
512 | int ShowPalladiumAlias(argc, argv) | |
513 | int argc; | |
514 | char **argv; | |
515 | { | |
516 | struct qelem *elem = NULL; | |
517 | char *qargv[3], buf[BUFSIZ]; | |
518 | int status; | |
519 | ||
520 | qargv[0] = argv[1]; | |
521 | qargv[1] = "PALLADIUM"; | |
522 | qargv[2] = argv[2]; | |
8defc06b | 523 | if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) { |
1b2e1580 | 524 | com_err(program_name, status, " in ShowPalladiumAlias"); |
525 | return(DM_NORMAL); | |
526 | } | |
527 | elem = QueueTop(elem); | |
528 | Put_message(""); | |
529 | while (elem != NULL) { | |
530 | char **info = (char **) elem->q_data; | |
24decb93 | 531 | sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]); |
1b2e1580 | 532 | Put_message(buf); |
533 | elem = elem->q_forw; | |
534 | } | |
535 | ||
536 | FreeQueue(QueueTop(elem)); | |
537 | return(DM_NORMAL); | |
538 | } | |
539 | ||
540 | int AddPalladiumAlias(argc, argv) | |
541 | int argc; | |
542 | char **argv; | |
543 | { | |
544 | int status; | |
545 | char *qargv[3]; | |
546 | ||
547 | qargv[0] = argv[1]; | |
548 | qargv[1] = "PALLADIUM"; | |
549 | qargv[2] = argv[2]; | |
8defc06b | 550 | if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0) |
1b2e1580 | 551 | com_err(program_name, status, " in AddPalladiumAlias"); |
552 | return(DM_NORMAL); | |
553 | } | |
554 | ||
555 | int DeletePalladiumAlias(argc, argv) | |
556 | int argc; | |
557 | char **argv; | |
558 | { | |
559 | int status; | |
560 | char *qargv[3]; | |
561 | ||
562 | qargv[0] = argv[1]; | |
563 | qargv[1] = "PALLADIUM"; | |
564 | qargv[2] = argv[2]; | |
8defc06b | 565 | if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0) |
1b2e1580 | 566 | com_err(program_name, status, " in DeletePalladiumAlias"); |
567 | return(DM_NORMAL); | |
568 | } |