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