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