]>
Commit | Line | Data |
---|---|---|
1 | /* $Id$ | |
2 | * | |
3 | * This is the file printer.c for the Moira Client, which allows users | |
4 | * to quickly and easily maintain most parts of the Moira database. | |
5 | * It Contains: Functions for handling the printers. | |
6 | * | |
7 | * Created: 8/16/88 | |
8 | * By: Theodore Y. Ts'o | |
9 | * | |
10 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. | |
11 | * For copying and distribution information, please see the file | |
12 | * <mit-copyright.h>. | |
13 | */ | |
14 | ||
15 | #include <mit-copyright.h> | |
16 | #include <moira.h> | |
17 | #include <moira_site.h> | |
18 | #include "defs.h" | |
19 | #include "f_defs.h" | |
20 | #include "globals.h" | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | ||
26 | RCSID("$Header$"); | |
27 | ||
28 | void RealDeletePrn(char **info, Bool one_item); | |
29 | void ChangePrn(char **info, Bool one_item); | |
30 | void ChangePrintSrvLoop(char **info, Bool one); | |
31 | extern int GetAliasValue(int argc, char **argv, void *retval); | |
32 | int StoreHWAddr(int argc, char **argv, void *retval); | |
33 | ||
34 | static char *PrintPrintSrvInfo(char **info); | |
35 | static char **SetPrintSrvDefaults(char **info, char *name); | |
36 | static char **AskPrintSrvInfo(char **info); | |
37 | ||
38 | #define BY_NAME 0 | |
39 | #define BY_ETHERNET 1 | |
40 | #define BY_HOSTNAME 2 | |
41 | #define BY_RM 3 | |
42 | #define BY_LOCATION 4 | |
43 | #define BY_CONTACT 5 | |
44 | ||
45 | #define DEFAULT_LOGHOST "WSLOGGER.MIT.EDU" | |
46 | ||
47 | int StoreHWAddr(int argc, char **argv, void *retval) | |
48 | { | |
49 | char **p = retval; | |
50 | *p = strdup(argv[0]); | |
51 | return MR_CONT; | |
52 | } | |
53 | ||
54 | /* Function Name: SetDefaults | |
55 | * Description: sets the default values for filesystem additions. | |
56 | * Arguments: info - an array of char pointers to recieve defaults. | |
57 | * Returns: char ** (this array, now filled). | |
58 | */ | |
59 | ||
60 | static char **SetDefaults(char **info, char *name) | |
61 | { | |
62 | info[PRN_NAME] = strdup(name); | |
63 | info[PRN_TYPE] = strdup("PRIVATE"); | |
64 | info[PRN_HWTYPE] = strdup("HP"); | |
65 | info[PRN_DUPLEXNAME] = strdup(""); | |
66 | info[PRN_HOSTNAME] = strdup(name); | |
67 | info[PRN_LOGHOST] = strdup(DEFAULT_LOGHOST); | |
68 | info[PRN_RM] = strdup("[ANY]"); | |
69 | info[PRN_RP] = strdup(name); | |
70 | info[PRN_RQ] = strdup("[NONE]"); | |
71 | info[PRN_KA] = strdup("0"); | |
72 | info[PRN_PC] = strdup("10"); | |
73 | info[PRN_AC] = strdup("[none]"); | |
74 | info[PRN_LPC_ACL] = strdup("[none]"); | |
75 | info[PRN_BANNER] = strdup("1"); | |
76 | info[PRN_LOCATION] = strdup(""); | |
77 | info[PRN_CONTACT] = strdup(""); | |
78 | info[PRN_MODTIME] = info[PRN_MODBY] = info[PRN_MODWITH] = NULL; | |
79 | ||
80 | info[PRN_END] = NULL; | |
81 | return info; | |
82 | } | |
83 | ||
84 | /* Function Name: GetPrnInfo | |
85 | * Description: Stores the info in a queue. | |
86 | * Arguments: name - name of the item to get information on. | |
87 | * Returns: a pointer to the first element in the queue or null | |
88 | * if printer not found. | |
89 | */ | |
90 | ||
91 | static struct mqelem *GetPrnInfo(char *name, int how) | |
92 | { | |
93 | int stat; | |
94 | struct mqelem *elem = NULL; | |
95 | ||
96 | switch (how) | |
97 | { | |
98 | case BY_NAME: | |
99 | stat = do_mr_query("get_printer", 1, &name, StoreInfo, &elem); | |
100 | if (stat == MR_NO_MATCH) | |
101 | { | |
102 | stat = do_mr_query("get_printer_by_duplexname", 1, &name, | |
103 | StoreInfo, &elem); | |
104 | } | |
105 | break; | |
106 | case BY_ETHERNET: | |
107 | stat = do_mr_query("get_printer_by_ethernet", 1, &name, | |
108 | StoreInfo, &elem); | |
109 | break; | |
110 | case BY_HOSTNAME: | |
111 | name = canonicalize_hostname(strdup(name)); | |
112 | stat = do_mr_query("get_printer_by_hostname", 1, &name, | |
113 | StoreInfo, &elem); | |
114 | free(name); | |
115 | break; | |
116 | case BY_RM: | |
117 | name = canonicalize_hostname(strdup(name)); | |
118 | stat = do_mr_query("get_printer_by_rm", 1, &name, | |
119 | StoreInfo, &elem); | |
120 | free(name); | |
121 | break; | |
122 | case BY_LOCATION: | |
123 | stat = do_mr_query("get_printer_by_location", 1, &name, | |
124 | StoreInfo, &elem); | |
125 | break; | |
126 | case BY_CONTACT: | |
127 | stat = do_mr_query("get_printer_by_contact", 1, &name, | |
128 | StoreInfo, &elem); | |
129 | break; | |
130 | } | |
131 | ||
132 | if (stat) | |
133 | { | |
134 | com_err(program_name, stat, " in GetPrnInfo"); | |
135 | return NULL; | |
136 | } | |
137 | return QueueTop(elem); | |
138 | } | |
139 | ||
140 | /* Function Name: PrintPrnInfo | |
141 | * Description: Yet another specialized print function. | |
142 | * Arguments: info - all info about this Printer. | |
143 | * Returns: printer name | |
144 | */ | |
145 | ||
146 | static char *PrintPrnInfo(char **info) | |
147 | { | |
148 | char buf[BUFSIZ], *hwaddr; | |
149 | int status, banner = atoi(info[PRN_BANNER]); | |
150 | ||
151 | if (!info) /* If no informaion */ | |
152 | { | |
153 | Put_message("PrintPrnInfo called with null info!"); | |
154 | return NULL; | |
155 | } | |
156 | Put_message(""); | |
157 | sprintf(buf, "Printer: %-18s Duplex queue: %-18s", info[PRN_NAME], | |
158 | *info[PRN_DUPLEXNAME] ? info[PRN_DUPLEXNAME] : "[none]"); | |
159 | Put_message(buf); | |
160 | sprintf(buf, "Type: %-10s Hardware type: %-10s Hardware address: ", | |
161 | info[PRN_TYPE], info[PRN_HWTYPE]); | |
162 | status = do_mr_query("get_host_hwaddr", 1, &info[PRN_HOSTNAME], | |
163 | StoreHWAddr, &hwaddr); | |
164 | if (status == MR_SUCCESS) | |
165 | { | |
166 | strcat(buf, hwaddr); | |
167 | free(hwaddr); | |
168 | } | |
169 | else | |
170 | strcat(buf, "none"); | |
171 | Put_message(buf); | |
172 | sprintf(buf, "Printer hostname: %s", info[PRN_HOSTNAME]); | |
173 | Put_message(buf); | |
174 | sprintf(buf, "Printer log host: %s", info[PRN_LOGHOST]); | |
175 | Put_message(buf); | |
176 | sprintf(buf, "Spool host: %s", info[PRN_RM]); | |
177 | Put_message(buf); | |
178 | sprintf(buf, "Remote Printer Name: %-38s Banner page: %s", info[PRN_RP], | |
179 | banner ? ( banner == PRN_BANNER_FIRST ? "Yes" : "Last" ) : "No"); | |
180 | Put_message(buf); | |
181 | sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s", | |
182 | atoi(info[PRN_KA]) ? "yes" : "no", info[PRN_PC], info[PRN_RQ]); | |
183 | Put_message(buf); | |
184 | sprintf(buf, "Restrict list: %-23s LPC ACL: %-23s", | |
185 | info[PRN_AC], info[PRN_LPC_ACL]); | |
186 | Put_message(buf); | |
187 | sprintf(buf, "Location: %s", info[PRN_LOCATION]); | |
188 | Put_message(buf); | |
189 | sprintf(buf, "Contact: %s", info[PRN_CONTACT]); | |
190 | Put_message(buf); | |
191 | sprintf(buf, MOD_FORMAT, info[PRN_MODBY], info[PRN_MODTIME], | |
192 | info[PRN_MODWITH]); | |
193 | Put_message(buf); | |
194 | ||
195 | return info[PRN_NAME]; | |
196 | } | |
197 | ||
198 | /* Function Name: AskPrnInfo. | |
199 | * Description: This function askes the user for information about a | |
200 | * printer and saves it into a structure. | |
201 | * Arguments: info - a pointer the the structure to put the | |
202 | * info into. | |
203 | * Returns: none. | |
204 | */ | |
205 | ||
206 | static char **AskPrnInfo(char **info) | |
207 | { | |
208 | char temp_buf[BUFSIZ]; | |
209 | char *args[3], *lpc_acl; | |
210 | int status; | |
211 | ||
212 | Put_message(""); | |
213 | sprintf(temp_buf, "Printer entry for %s.", info[PRN_NAME]); | |
214 | Put_message(temp_buf); | |
215 | Put_message(""); | |
216 | ||
217 | if (GetTypeFromUser("Type of Printer", "printertype", &info[PRN_TYPE]) == | |
218 | SUB_ERROR) | |
219 | return NULL; | |
220 | if (GetTypeFromUser("Hardware Type", "printerhwtype", &info[PRN_HWTYPE]) == | |
221 | SUB_ERROR) | |
222 | return NULL; | |
223 | if (GetValueFromUser("Duplex spool name", &info[PRN_DUPLEXNAME]) == | |
224 | SUB_ERROR) | |
225 | return NULL; | |
226 | if (GetValueFromUser("Printer hostname (or [none])", &info[PRN_HOSTNAME]) == | |
227 | SUB_ERROR) | |
228 | return NULL; | |
229 | info[PRN_HOSTNAME] = canonicalize_hostname(info[PRN_HOSTNAME]); | |
230 | if (GetValueFromUser("Log host", &info[PRN_LOGHOST]) == SUB_ERROR) | |
231 | return NULL; | |
232 | info[PRN_LOGHOST] = canonicalize_hostname(info[PRN_LOGHOST]); | |
233 | if (GetValueFromUser("Spool host (or [any])", &info[PRN_RM]) == SUB_ERROR) | |
234 | return NULL; | |
235 | info[PRN_RM] = canonicalize_hostname(info[PRN_RM]); | |
236 | if (GetValueFromUser("Remote printer name", &info[PRN_RP]) == SUB_ERROR) | |
237 | return NULL; | |
238 | if (GetValueFromUser("Quota server", &info[PRN_RQ]) == SUB_ERROR) | |
239 | return NULL; | |
240 | info[PRN_RQ] = canonicalize_hostname(info[PRN_RQ]); | |
241 | if (GetYesNoValueFromUser("Kerberos authenticated", &info[PRN_KA]) == | |
242 | SUB_ERROR) | |
243 | return NULL; | |
244 | if (GetValueFromUser("Price per page", &info[PRN_PC]) == SUB_ERROR) | |
245 | return NULL; | |
246 | if (GetValueFromUser("Restrict list", &info[PRN_AC]) == SUB_ERROR) | |
247 | return NULL; | |
248 | args[0] = info[PRN_TYPE]; | |
249 | args[1] = "LPC_ACL"; | |
250 | args[2] = "*"; | |
251 | status = do_mr_query("get_alias", 3, args, GetAliasValue, &lpc_acl); | |
252 | if (status == MR_SUCCESS) | |
253 | { | |
254 | free(info[PRN_LPC_ACL]); | |
255 | info[PRN_LPC_ACL] = lpc_acl; | |
256 | } | |
257 | if (GetValueFromUser("LPC ACL", &info[PRN_LPC_ACL]) == SUB_ERROR) | |
258 | return NULL; | |
259 | if (GetYesNoValueFromUser("Banner page", &info[PRN_BANNER]) == SUB_ERROR) | |
260 | return NULL; | |
261 | if (GetValueFromUser("Location", &info[PRN_LOCATION]) == SUB_ERROR) | |
262 | return NULL; | |
263 | if (GetValueFromUser("Contact", &info[PRN_CONTACT]) == SUB_ERROR) | |
264 | return NULL; | |
265 | ||
266 | FreeAndClear(&info[PRN_MODTIME], TRUE); | |
267 | FreeAndClear(&info[PRN_MODBY], TRUE); | |
268 | FreeAndClear(&info[PRN_MODWITH], TRUE); | |
269 | ||
270 | return info; | |
271 | } | |
272 | ||
273 | /* ---------------- Printer Menu ------------------ */ | |
274 | ||
275 | /* Function Name: GetPrn | |
276 | * Description: Get Printer information | |
277 | * Arguments: argc, argv - name of printer in argv[1]. | |
278 | * Returns: DM_NORMAL. | |
279 | */ | |
280 | ||
281 | int GetPrn(int argc, char **argv) | |
282 | { | |
283 | struct mqelem *top; | |
284 | ||
285 | top = GetPrnInfo(argv[1], BY_NAME); /* get info. */ | |
286 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
287 | FreeQueue(top); /* clean the queue. */ | |
288 | return DM_NORMAL; | |
289 | } | |
290 | ||
291 | int GetPrnByEthernet(int argc, char **argv) | |
292 | { | |
293 | struct mqelem *top; | |
294 | ||
295 | top = GetPrnInfo(argv[1], BY_ETHERNET); /* get info. */ | |
296 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
297 | FreeQueue(top); /* clean the queue. */ | |
298 | return DM_NORMAL; | |
299 | } | |
300 | ||
301 | int GetPrnByHostname(int argc, char **argv) | |
302 | { | |
303 | struct mqelem *top; | |
304 | ||
305 | top = GetPrnInfo(argv[1], BY_HOSTNAME); /* get info. */ | |
306 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
307 | FreeQueue(top); /* clean the queue. */ | |
308 | return DM_NORMAL; | |
309 | } | |
310 | ||
311 | int GetPrnByRM(int argc, char **argv) | |
312 | { | |
313 | struct mqelem *top; | |
314 | ||
315 | top = GetPrnInfo(argv[1], BY_RM); /* get info. */ | |
316 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
317 | FreeQueue(top); /* clean the queue. */ | |
318 | return DM_NORMAL; | |
319 | } | |
320 | ||
321 | int GetPrnByLocation(int argc, char **argv) | |
322 | { | |
323 | struct mqelem *top; | |
324 | ||
325 | top = GetPrnInfo(argv[1], BY_LOCATION); /* get info. */ | |
326 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
327 | FreeQueue(top); /* clean the queue. */ | |
328 | return DM_NORMAL; | |
329 | } | |
330 | ||
331 | int GetPrnByContact(int argc, char **argv) | |
332 | { | |
333 | struct mqelem *top; | |
334 | ||
335 | top = GetPrnInfo(argv[1], BY_CONTACT); /* get info. */ | |
336 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
337 | FreeQueue(top); /* clean the queue. */ | |
338 | return DM_NORMAL; | |
339 | } | |
340 | ||
341 | ||
342 | /* Function Name: RealDeletePrn | |
343 | * Description: Does the real deletion work. | |
344 | * Arguments: info - array of char *'s containing all useful info. | |
345 | * one_item - a Boolean that is true if only one item | |
346 | * in queue that dumped us here. | |
347 | * Returns: none. | |
348 | */ | |
349 | ||
350 | void RealDeletePrn(char **info, Bool one_item) | |
351 | { | |
352 | int stat; | |
353 | ||
354 | if ((stat = do_mr_query("delete_printer", 1, &info[PRN_NAME], NULL, NULL))) | |
355 | com_err(program_name, stat, " printer not deleted."); | |
356 | else | |
357 | Put_message("Printer deleted."); | |
358 | } | |
359 | ||
360 | /* Function Name: DeletePrn | |
361 | * Description: Delete a printer given its name. | |
362 | * Arguments: argc, argv - argv[1] is the name of the printer. | |
363 | * Returns: none. | |
364 | */ | |
365 | ||
366 | int DeletePrn(int argc, char **argv) | |
367 | { | |
368 | struct mqelem *elem = GetPrnInfo(argv[1], BY_NAME); | |
369 | QueryLoop(elem, PrintPrnInfo, RealDeletePrn, "Delete Printer"); | |
370 | ||
371 | FreeQueue(elem); | |
372 | return DM_NORMAL; | |
373 | } | |
374 | ||
375 | /* Function Name: AddPrn | |
376 | * Description: Add a printer | |
377 | * Arguments: arc, argv - name of printer in argv[1]. | |
378 | * Returns: DM_NORMAL. | |
379 | */ | |
380 | ||
381 | int AddPrn(int argc, char **argv) | |
382 | { | |
383 | char *info[MAX_ARGS_SIZE], **args; | |
384 | int stat; | |
385 | ||
386 | if (!ValidName(argv[1])) | |
387 | return DM_NORMAL; | |
388 | ||
389 | if (!(stat = do_mr_query("get_printer", 1, argv + 1, NULL, NULL)) || | |
390 | !(stat = do_mr_query("get_printer_by_duplexname", 1, argv + 1, | |
391 | NULL, NULL))) | |
392 | { | |
393 | Put_message ("A Printer by that name already exists."); | |
394 | return DM_NORMAL; | |
395 | } | |
396 | else if (stat != MR_NO_MATCH) | |
397 | { | |
398 | com_err(program_name, stat, " in AddPrn"); | |
399 | return DM_NORMAL; | |
400 | } | |
401 | ||
402 | args = AskPrnInfo(SetDefaults(info, argv[1])); | |
403 | if (!args) | |
404 | { | |
405 | Put_message("Aborted."); | |
406 | return DM_NORMAL; | |
407 | } | |
408 | ||
409 | if ((stat = do_mr_query("add_printer", CountArgs(args), args, NULL, NULL))) | |
410 | com_err(program_name, stat, " in AddPrn"); | |
411 | ||
412 | if (stat == MR_SUCCESS && strcasecmp(info[PRN_HOSTNAME], "[NONE]")) | |
413 | UpdateHWAddr(2, &info[PRN_HOSTNAME - 1]); | |
414 | ||
415 | FreeInfo(info); | |
416 | return DM_NORMAL; | |
417 | } | |
418 | ||
419 | ||
420 | /* Function Name: ChangePrn | |
421 | * Description: Do the work of changing a Prn | |
422 | * Arguments: argc, argv - printcap info | |
423 | * Returns: | |
424 | */ | |
425 | ||
426 | void ChangePrn(char **info, Bool one_item) | |
427 | { | |
428 | int stat; | |
429 | char **oldinfo; | |
430 | ||
431 | oldinfo = CopyInfo(info); | |
432 | if (!AskPrnInfo(info)) | |
433 | return; | |
434 | if ((stat = do_mr_query("delete_printer", 1, &info[PRN_NAME], NULL, NULL))) | |
435 | { | |
436 | com_err(program_name, stat, " printer not updated."); | |
437 | return; | |
438 | } | |
439 | if ((stat = do_mr_query("add_printer", CountArgs(info), info, NULL, NULL))) | |
440 | { | |
441 | com_err(program_name, stat, " in ChngPrn"); | |
442 | if ((stat = do_mr_query("add_printer", CountArgs(oldinfo) - 3, | |
443 | oldinfo, NULL, NULL))) | |
444 | com_err(program_name, stat, " while attempting to put old info back"); | |
445 | } | |
446 | FreeInfo(oldinfo); | |
447 | return; | |
448 | } | |
449 | ||
450 | ||
451 | /* Function Name: ChngPrn | |
452 | * Description: Update the printcap information | |
453 | * Arguments: argc, argv - name of printer in argv[1]. | |
454 | * Returns: DM_NORMAL. | |
455 | */ | |
456 | ||
457 | int ChngPrn(int argc, char **argv) | |
458 | { | |
459 | struct mqelem *elem = GetPrnInfo(argv[1], BY_NAME); | |
460 | QueryLoop(elem, NullPrint, ChangePrn, "Change the printer"); | |
461 | FreeQueue(elem); | |
462 | return DM_NORMAL; | |
463 | } | |
464 | ||
465 | ||
466 | int UpdateHWAddr(int argc, char **argv) | |
467 | { | |
468 | int stat; | |
469 | char *name, *hwaddr, *s, *d, *uargv[2]; | |
470 | ||
471 | name = canonicalize_hostname(strdup(argv[1])); | |
472 | stat = do_mr_query("get_host_hwaddr", 1, &name, StoreHWAddr, &hwaddr); | |
473 | if (stat != MR_SUCCESS) | |
474 | { | |
475 | free(name); | |
476 | com_err(program_name, stat, " checking host ethernet address"); | |
477 | return DM_NORMAL; | |
478 | } | |
479 | ||
480 | if (GetValueFromUser("Hardware ethernet address", &hwaddr) == SUB_ERROR) | |
481 | { | |
482 | free(name); | |
483 | return DM_NORMAL; | |
484 | } | |
485 | ||
486 | s = d = hwaddr; | |
487 | do | |
488 | { | |
489 | if (*s != ':') | |
490 | *d++ = *s; | |
491 | } | |
492 | while (*s++); | |
493 | ||
494 | uargv[0] = name; | |
495 | uargv[1] = hwaddr; | |
496 | if ((stat = do_mr_query("update_host_hwaddr", 2, uargv, NULL, NULL))) | |
497 | com_err(program_name, stat, " updating ethernet address."); | |
498 | ||
499 | free(name); | |
500 | free(hwaddr); | |
501 | return DM_NORMAL; | |
502 | } | |
503 | ||
504 | ||
505 | int GetPrintSrv(int argc, char **argv) | |
506 | { | |
507 | int stat; | |
508 | struct mqelem *elem = NULL, *top; | |
509 | char *name; | |
510 | ||
511 | name = canonicalize_hostname(strdup(argv[1])); | |
512 | stat = do_mr_query("get_print_server", 1, &name, StoreInfo, &elem); | |
513 | if (stat) | |
514 | { | |
515 | com_err(program_name, stat, " in GetPrintSrv"); | |
516 | return DM_NORMAL; | |
517 | } | |
518 | ||
519 | top = QueueTop(elem); | |
520 | Loop(top, (void (*)(char **)) PrintPrintSrvInfo); | |
521 | FreeQueue(top); /* clean the queue. */ | |
522 | return DM_NORMAL; | |
523 | } | |
524 | ||
525 | static char *PrintPrintSrvInfo(char **info) | |
526 | { | |
527 | char buf[BUFSIZ]; | |
528 | ||
529 | if (!info) /* If no informaion */ | |
530 | { | |
531 | Put_message("PrintPrintSrvInfo called with null info!"); | |
532 | return NULL; | |
533 | } | |
534 | Put_message(""); | |
535 | sprintf(buf, "Hostname: %s", info[PRINTSERVER_HOST]); | |
536 | Put_message(buf); | |
537 | sprintf(buf, "Kind: %-10s Printer Types: %s", info[PRINTSERVER_KIND], | |
538 | info[PRINTSERVER_TYPES]); | |
539 | Put_message(buf); | |
540 | if (!strcmp(info[PRINTSERVER_OWNER_TYPE], "NONE")) | |
541 | sprintf(buf, "Owner: %-25s", info[PRINTSERVER_OWNER_TYPE]); | |
542 | else | |
543 | { | |
544 | sprintf(buf, "Owner: %s %-*s", info[PRINTSERVER_OWNER_TYPE], | |
545 | 24 - strlen(info[PRINTSERVER_OWNER_TYPE]), | |
546 | info[PRINTSERVER_OWNER_NAME]); | |
547 | } | |
548 | strcat(buf, "LPC ACL: "); | |
549 | strcat(buf, info[PRINTSERVER_LPC_ACL]); | |
550 | Put_message(buf); | |
551 | sprintf(buf, MOD_FORMAT, info[PRINTSERVER_MODBY], info[PRINTSERVER_MODTIME], | |
552 | info[PRINTSERVER_MODWITH]); | |
553 | Put_message(buf); | |
554 | ||
555 | return info[PRINTSERVER_HOST]; | |
556 | } | |
557 | ||
558 | static char **SetPrintSrvDefaults(char **info, char *name) | |
559 | { | |
560 | info[PRINTSERVER_HOST] = strdup(name); | |
561 | info[PRINTSERVER_KIND] = strdup("ATHENA"); | |
562 | info[PRINTSERVER_TYPES] = strdup("PRIVATE"); | |
563 | info[PRINTSERVER_OWNER_TYPE] = strdup("NONE"); | |
564 | info[PRINTSERVER_OWNER_NAME] = strdup(""); | |
565 | info[PRINTSERVER_LPC_ACL] = strdup("[none]"); | |
566 | info[PRINTSERVER_MODTIME] = info[PRINTSERVER_MODBY] = | |
567 | info[PRINTSERVER_MODWITH] = NULL; | |
568 | ||
569 | info[PRINTSERVER_END] = NULL; | |
570 | return info; | |
571 | } | |
572 | ||
573 | static char **AskPrintSrvInfo(char **info) | |
574 | { | |
575 | char buf[BUFSIZ]; | |
576 | ||
577 | Put_message(""); | |
578 | sprintf(buf, "Print Server entry for %s.", info[PRINTSERVER_HOST]); | |
579 | Put_message(buf); | |
580 | Put_message(""); | |
581 | ||
582 | if (GetTypeFromUser("Kind of LPD", "lpd_kind", &info[PRINTSERVER_KIND]) == | |
583 | SUB_ERROR) | |
584 | return NULL; | |
585 | if (GetValueFromUser("Printer types", &info[PRINTSERVER_TYPES]) == SUB_ERROR) | |
586 | return NULL; | |
587 | if (GetTypeFromUser("Owner type", "ace_type", &info[PRINTSERVER_OWNER_TYPE]) | |
588 | == SUB_ERROR) | |
589 | return NULL; | |
590 | if (strcmp(info[PRINTSERVER_OWNER_TYPE], "NONE") && | |
591 | GetValueFromUser("Owner Name", &info[PRINTSERVER_OWNER_NAME]) == | |
592 | SUB_ERROR) | |
593 | return NULL; | |
594 | if (GetValueFromUser("LPC ACL", &info[PRINTSERVER_LPC_ACL]) == SUB_ERROR) | |
595 | return NULL; | |
596 | ||
597 | FreeAndClear(&info[PRINTSERVER_MODTIME], TRUE); | |
598 | FreeAndClear(&info[PRINTSERVER_MODBY], TRUE); | |
599 | FreeAndClear(&info[PRINTSERVER_MODWITH], TRUE); | |
600 | ||
601 | return info; | |
602 | } | |
603 | ||
604 | int AddPrintSrv(int argc, char **argv) | |
605 | { | |
606 | char *info[MAX_ARGS_SIZE], **args, *name; | |
607 | int stat; | |
608 | ||
609 | name = canonicalize_hostname(strdup(argv[1])); | |
610 | ||
611 | if (!(stat = do_mr_query("get_print_server", 1, &name, NULL, NULL))) | |
612 | { | |
613 | Put_message ("A print server record for that host already exists."); | |
614 | free(name); | |
615 | return DM_NORMAL; | |
616 | } | |
617 | else if (stat != MR_NO_MATCH) | |
618 | { | |
619 | com_err(program_name, stat, " in AddPrintSrv"); | |
620 | free(name); | |
621 | return DM_NORMAL; | |
622 | } | |
623 | ||
624 | args = AskPrintSrvInfo(SetPrintSrvDefaults(info, name)); | |
625 | free(name); | |
626 | if (!args) | |
627 | { | |
628 | Put_message("Aborted."); | |
629 | return DM_NORMAL; | |
630 | } | |
631 | ||
632 | if ((stat = do_mr_query("add_print_server", CountArgs(args), | |
633 | args, NULL, NULL))) | |
634 | com_err(program_name, stat, " in AddPrintSrv"); | |
635 | ||
636 | FreeInfo(info); | |
637 | return DM_NORMAL; | |
638 | } | |
639 | ||
640 | int ChangePrintSrv(int argc, char **argv) | |
641 | { | |
642 | char *name; | |
643 | struct mqelem *elem = NULL; | |
644 | int stat; | |
645 | ||
646 | name = canonicalize_hostname(strdup(argv[1])); | |
647 | if ((stat = do_mr_query("get_print_server", 1, &name, StoreInfo, &elem))) | |
648 | { | |
649 | free(name); | |
650 | com_err(program_name, stat, " in ChangePrintSrv"); | |
651 | return DM_NORMAL; | |
652 | } | |
653 | free(name); | |
654 | ||
655 | QueryLoop(elem, NullPrint, ChangePrintSrvLoop, "Change the print server"); | |
656 | FreeQueue(elem); | |
657 | return DM_NORMAL; | |
658 | } | |
659 | ||
660 | void ChangePrintSrvLoop(char **info, Bool one) | |
661 | { | |
662 | int stat; | |
663 | ||
664 | if (!AskPrintSrvInfo(info)) | |
665 | return; | |
666 | ||
667 | if ((stat = do_mr_query("update_print_server", CountArgs(info), | |
668 | info, NULL, NULL))) | |
669 | com_err(program_name, stat, " in ChangePrintSrv"); | |
670 | ||
671 | FreeInfo(info); | |
672 | return; | |
673 | } | |
674 | ||
675 | int DelPrintSrv(int argc, char **argv) | |
676 | { | |
677 | int stat; | |
678 | char *name; | |
679 | ||
680 | name = canonicalize_hostname(strdup(argv[1])); | |
681 | ||
682 | if ((stat = do_mr_query("delete_print_server", 1, &name, NULL, NULL))) | |
683 | com_err(program_name, stat, " while deleting print server"); | |
684 | free(name); | |
685 | return DM_NORMAL; | |
686 | } |