]>
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, Bool name) | |
207 | { | |
208 | char temp_buf[BUFSIZ]; | |
209 | char *args[3], *lpc_acl, *newname; | |
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 (name) | |
218 | { | |
219 | while (1) | |
220 | { | |
221 | newname = strdup(info[PRN_NAME]); | |
222 | if (GetValueFromUser("The new name for this printer? ", &newname) == | |
223 | SUB_ERROR) | |
224 | return NULL; | |
225 | if (ValidName(newname)) | |
226 | break; | |
227 | } | |
228 | } | |
229 | if (GetTypeFromUser("Type of Printer", "printertype", &info[PRN_TYPE]) == | |
230 | SUB_ERROR) | |
231 | return NULL; | |
232 | if (GetTypeFromUser("Hardware Type", "printerhwtype", &info[PRN_HWTYPE]) == | |
233 | SUB_ERROR) | |
234 | return NULL; | |
235 | if (GetValueFromUser("Duplex spool name", &info[PRN_DUPLEXNAME]) == | |
236 | SUB_ERROR) | |
237 | return NULL; | |
238 | if (GetValueFromUser("Printer hostname (or [none])", &info[PRN_HOSTNAME]) == | |
239 | SUB_ERROR) | |
240 | return NULL; | |
241 | info[PRN_HOSTNAME] = canonicalize_hostname(info[PRN_HOSTNAME]); | |
242 | if (GetValueFromUser("Log host", &info[PRN_LOGHOST]) == SUB_ERROR) | |
243 | return NULL; | |
244 | info[PRN_LOGHOST] = canonicalize_hostname(info[PRN_LOGHOST]); | |
245 | if (GetValueFromUser("Spool host (or [any])", &info[PRN_RM]) == SUB_ERROR) | |
246 | return NULL; | |
247 | info[PRN_RM] = canonicalize_hostname(info[PRN_RM]); | |
248 | if (GetValueFromUser("Remote printer name", &info[PRN_RP]) == SUB_ERROR) | |
249 | return NULL; | |
250 | if (GetValueFromUser("Quota server", &info[PRN_RQ]) == SUB_ERROR) | |
251 | return NULL; | |
252 | info[PRN_RQ] = canonicalize_hostname(info[PRN_RQ]); | |
253 | if (GetYesNoValueFromUser("Kerberos authenticated", &info[PRN_KA]) == | |
254 | SUB_ERROR) | |
255 | return NULL; | |
256 | if (GetValueFromUser("Price per page", &info[PRN_PC]) == SUB_ERROR) | |
257 | return NULL; | |
258 | if (GetValueFromUser("Restrict list", &info[PRN_AC]) == SUB_ERROR) | |
259 | return NULL; | |
260 | args[0] = info[PRN_TYPE]; | |
261 | args[1] = "LPC_ACL"; | |
262 | args[2] = "*"; | |
263 | status = do_mr_query("get_alias", 3, args, GetAliasValue, &lpc_acl); | |
264 | if (status == MR_SUCCESS) | |
265 | { | |
266 | free(info[PRN_LPC_ACL]); | |
267 | info[PRN_LPC_ACL] = lpc_acl; | |
268 | } | |
269 | if (GetValueFromUser("LPC ACL", &info[PRN_LPC_ACL]) == SUB_ERROR) | |
270 | return NULL; | |
271 | if (GetYesNoValueFromUser("Banner page", &info[PRN_BANNER]) == SUB_ERROR) | |
272 | return NULL; | |
273 | if (GetValueFromUser("Location", &info[PRN_LOCATION]) == SUB_ERROR) | |
274 | return NULL; | |
275 | if (GetValueFromUser("Contact", &info[PRN_CONTACT]) == SUB_ERROR) | |
276 | return NULL; | |
277 | ||
278 | FreeAndClear(&info[PRN_MODTIME], TRUE); | |
279 | FreeAndClear(&info[PRN_MODBY], TRUE); | |
280 | FreeAndClear(&info[PRN_MODWITH], TRUE); | |
281 | ||
282 | if (name) | |
283 | SlipInNewName(info, newname); | |
284 | ||
285 | return info; | |
286 | } | |
287 | ||
288 | /* ---------------- Printer Menu ------------------ */ | |
289 | ||
290 | /* Function Name: GetPrn | |
291 | * Description: Get Printer information | |
292 | * Arguments: argc, argv - name of printer in argv[1]. | |
293 | * Returns: DM_NORMAL. | |
294 | */ | |
295 | ||
296 | int GetPrn(int argc, char **argv) | |
297 | { | |
298 | struct mqelem *top; | |
299 | ||
300 | top = GetPrnInfo(argv[1], BY_NAME); /* get info. */ | |
301 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
302 | FreeQueue(top); /* clean the queue. */ | |
303 | return DM_NORMAL; | |
304 | } | |
305 | ||
306 | int GetPrnByEthernet(int argc, char **argv) | |
307 | { | |
308 | struct mqelem *top; | |
309 | ||
310 | top = GetPrnInfo(argv[1], BY_ETHERNET); /* get info. */ | |
311 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
312 | FreeQueue(top); /* clean the queue. */ | |
313 | return DM_NORMAL; | |
314 | } | |
315 | ||
316 | int GetPrnByHostname(int argc, char **argv) | |
317 | { | |
318 | struct mqelem *top; | |
319 | ||
320 | top = GetPrnInfo(argv[1], BY_HOSTNAME); /* get info. */ | |
321 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
322 | FreeQueue(top); /* clean the queue. */ | |
323 | return DM_NORMAL; | |
324 | } | |
325 | ||
326 | int GetPrnByRM(int argc, char **argv) | |
327 | { | |
328 | struct mqelem *top; | |
329 | ||
330 | top = GetPrnInfo(argv[1], BY_RM); /* get info. */ | |
331 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
332 | FreeQueue(top); /* clean the queue. */ | |
333 | return DM_NORMAL; | |
334 | } | |
335 | ||
336 | int GetPrnByLocation(int argc, char **argv) | |
337 | { | |
338 | struct mqelem *top; | |
339 | ||
340 | top = GetPrnInfo(argv[1], BY_LOCATION); /* get info. */ | |
341 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
342 | FreeQueue(top); /* clean the queue. */ | |
343 | return DM_NORMAL; | |
344 | } | |
345 | ||
346 | int GetPrnByContact(int argc, char **argv) | |
347 | { | |
348 | struct mqelem *top; | |
349 | ||
350 | top = GetPrnInfo(argv[1], BY_CONTACT); /* get info. */ | |
351 | Loop(top, (void (*)(char **)) PrintPrnInfo); | |
352 | FreeQueue(top); /* clean the queue. */ | |
353 | return DM_NORMAL; | |
354 | } | |
355 | ||
356 | ||
357 | /* Function Name: RealDeletePrn | |
358 | * Description: Does the real deletion work. | |
359 | * Arguments: info - array of char *'s containing all useful info. | |
360 | * one_item - a Boolean that is true if only one item | |
361 | * in queue that dumped us here. | |
362 | * Returns: none. | |
363 | */ | |
364 | ||
365 | void RealDeletePrn(char **info, Bool one_item) | |
366 | { | |
367 | int stat; | |
368 | ||
369 | if ((stat = do_mr_query("delete_printer", 1, &info[PRN_NAME], NULL, NULL))) | |
370 | com_err(program_name, stat, " printer not deleted."); | |
371 | else | |
372 | Put_message("Printer deleted."); | |
373 | } | |
374 | ||
375 | /* Function Name: DeletePrn | |
376 | * Description: Delete a printer given its name. | |
377 | * Arguments: argc, argv - argv[1] is the name of the printer. | |
378 | * Returns: none. | |
379 | */ | |
380 | ||
381 | int DeletePrn(int argc, char **argv) | |
382 | { | |
383 | struct mqelem *elem = GetPrnInfo(argv[1], BY_NAME); | |
384 | QueryLoop(elem, PrintPrnInfo, RealDeletePrn, "Delete Printer"); | |
385 | ||
386 | FreeQueue(elem); | |
387 | return DM_NORMAL; | |
388 | } | |
389 | ||
390 | /* Function Name: AddPrn | |
391 | * Description: Add a printer | |
392 | * Arguments: arc, argv - name of printer in argv[1]. | |
393 | * Returns: DM_NORMAL. | |
394 | */ | |
395 | ||
396 | int AddPrn(int argc, char **argv) | |
397 | { | |
398 | char *info[MAX_ARGS_SIZE], **args; | |
399 | int stat; | |
400 | ||
401 | if (!ValidName(argv[1])) | |
402 | return DM_NORMAL; | |
403 | ||
404 | if (!(stat = do_mr_query("get_printer", 1, argv + 1, NULL, NULL)) || | |
405 | !(stat = do_mr_query("get_printer_by_duplexname", 1, argv + 1, | |
406 | NULL, NULL))) | |
407 | { | |
408 | Put_message ("A Printer by that name already exists."); | |
409 | return DM_NORMAL; | |
410 | } | |
411 | else if (stat != MR_NO_MATCH) | |
412 | { | |
413 | com_err(program_name, stat, " in AddPrn"); | |
414 | return DM_NORMAL; | |
415 | } | |
416 | ||
417 | args = AskPrnInfo(SetDefaults(info, argv[1]), FALSE); | |
418 | if (!args) | |
419 | { | |
420 | Put_message("Aborted."); | |
421 | return DM_NORMAL; | |
422 | } | |
423 | ||
424 | if ((stat = do_mr_query("add_printer", CountArgs(args), args, NULL, NULL))) | |
425 | com_err(program_name, stat, " in AddPrn"); | |
426 | ||
427 | if (stat == MR_SUCCESS && strcasecmp(info[PRN_HOSTNAME], "[NONE]")) | |
428 | UpdateHWAddr(2, &info[PRN_HOSTNAME - 1]); | |
429 | ||
430 | FreeInfo(info); | |
431 | return DM_NORMAL; | |
432 | } | |
433 | ||
434 | ||
435 | /* Function Name: ChangePrn | |
436 | * Description: Do the work of changing a Prn | |
437 | * Arguments: argc, argv - printcap info | |
438 | * Returns: | |
439 | */ | |
440 | ||
441 | void ChangePrn(char **info, Bool one_item) | |
442 | { | |
443 | int stat; | |
444 | ||
445 | if (!AskPrnInfo(info, TRUE)) | |
446 | { | |
447 | Put_message("Aborted."); | |
448 | return; | |
449 | } | |
450 | if ((stat = do_mr_query("update_printer", CountArgs(info), info, NULL, NULL))) | |
451 | com_err(program_name, stat, " in ChngPrn"); | |
452 | else | |
453 | Put_message("Printer successfully updated."); | |
454 | } | |
455 | ||
456 | ||
457 | /* Function Name: ChngPrn | |
458 | * Description: Update the printcap information | |
459 | * Arguments: argc, argv - name of printer in argv[1]. | |
460 | * Returns: DM_NORMAL. | |
461 | */ | |
462 | ||
463 | int ChngPrn(int argc, char **argv) | |
464 | { | |
465 | struct mqelem *elem = GetPrnInfo(argv[1], BY_NAME); | |
466 | QueryLoop(elem, NullPrint, ChangePrn, "Change the printer"); | |
467 | FreeQueue(elem); | |
468 | return DM_NORMAL; | |
469 | } | |
470 | ||
471 | ||
472 | int UpdateHWAddr(int argc, char **argv) | |
473 | { | |
474 | int stat; | |
475 | char *name, *hwaddr, *s, *d, *uargv[2]; | |
476 | ||
477 | name = canonicalize_hostname(strdup(argv[1])); | |
478 | stat = do_mr_query("get_host_hwaddr", 1, &name, StoreHWAddr, &hwaddr); | |
479 | if (stat != MR_SUCCESS) | |
480 | { | |
481 | free(name); | |
482 | com_err(program_name, stat, " checking host ethernet address"); | |
483 | return DM_NORMAL; | |
484 | } | |
485 | ||
486 | if (GetValueFromUser("Hardware ethernet address", &hwaddr) == SUB_ERROR) | |
487 | { | |
488 | free(name); | |
489 | return DM_NORMAL; | |
490 | } | |
491 | ||
492 | s = d = hwaddr; | |
493 | do | |
494 | { | |
495 | if (*s != ':') | |
496 | *d++ = *s; | |
497 | } | |
498 | while (*s++); | |
499 | ||
500 | uargv[0] = name; | |
501 | uargv[1] = hwaddr; | |
502 | if ((stat = do_mr_query("update_host_hwaddr", 2, uargv, NULL, NULL))) | |
503 | com_err(program_name, stat, " updating ethernet address."); | |
504 | ||
505 | free(name); | |
506 | free(hwaddr); | |
507 | return DM_NORMAL; | |
508 | } | |
509 | ||
510 | ||
511 | int GetPrintSrv(int argc, char **argv) | |
512 | { | |
513 | int stat; | |
514 | struct mqelem *elem = NULL, *top; | |
515 | char *name; | |
516 | ||
517 | name = canonicalize_hostname(strdup(argv[1])); | |
518 | stat = do_mr_query("get_print_server", 1, &name, StoreInfo, &elem); | |
519 | if (stat) | |
520 | { | |
521 | com_err(program_name, stat, " in GetPrintSrv"); | |
522 | return DM_NORMAL; | |
523 | } | |
524 | ||
525 | top = QueueTop(elem); | |
526 | Loop(top, (void (*)(char **)) PrintPrintSrvInfo); | |
527 | FreeQueue(top); /* clean the queue. */ | |
528 | return DM_NORMAL; | |
529 | } | |
530 | ||
531 | static char *PrintPrintSrvInfo(char **info) | |
532 | { | |
533 | char buf[BUFSIZ]; | |
534 | ||
535 | if (!info) /* If no informaion */ | |
536 | { | |
537 | Put_message("PrintPrintSrvInfo called with null info!"); | |
538 | return NULL; | |
539 | } | |
540 | Put_message(""); | |
541 | sprintf(buf, "Hostname: %s", info[PRINTSERVER_HOST]); | |
542 | Put_message(buf); | |
543 | sprintf(buf, "Kind: %-10s Printer Types: %s", info[PRINTSERVER_KIND], | |
544 | info[PRINTSERVER_TYPES]); | |
545 | Put_message(buf); | |
546 | if (!strcmp(info[PRINTSERVER_OWNER_TYPE], "NONE")) | |
547 | sprintf(buf, "Owner: %-25s", info[PRINTSERVER_OWNER_TYPE]); | |
548 | else | |
549 | { | |
550 | sprintf(buf, "Owner: %s %-*s", info[PRINTSERVER_OWNER_TYPE], | |
551 | 24 - strlen(info[PRINTSERVER_OWNER_TYPE]), | |
552 | info[PRINTSERVER_OWNER_NAME]); | |
553 | } | |
554 | strcat(buf, "LPC ACL: "); | |
555 | strcat(buf, info[PRINTSERVER_LPC_ACL]); | |
556 | Put_message(buf); | |
557 | sprintf(buf, MOD_FORMAT, info[PRINTSERVER_MODBY], info[PRINTSERVER_MODTIME], | |
558 | info[PRINTSERVER_MODWITH]); | |
559 | Put_message(buf); | |
560 | ||
561 | return info[PRINTSERVER_HOST]; | |
562 | } | |
563 | ||
564 | static char **SetPrintSrvDefaults(char **info, char *name) | |
565 | { | |
566 | info[PRINTSERVER_HOST] = strdup(name); | |
567 | info[PRINTSERVER_KIND] = strdup("ATHENA"); | |
568 | info[PRINTSERVER_TYPES] = strdup("PRIVATE"); | |
569 | info[PRINTSERVER_OWNER_TYPE] = strdup("NONE"); | |
570 | info[PRINTSERVER_OWNER_NAME] = strdup(""); | |
571 | info[PRINTSERVER_LPC_ACL] = strdup("[none]"); | |
572 | info[PRINTSERVER_MODTIME] = info[PRINTSERVER_MODBY] = | |
573 | info[PRINTSERVER_MODWITH] = NULL; | |
574 | ||
575 | info[PRINTSERVER_END] = NULL; | |
576 | return info; | |
577 | } | |
578 | ||
579 | static char **AskPrintSrvInfo(char **info) | |
580 | { | |
581 | char buf[BUFSIZ]; | |
582 | ||
583 | Put_message(""); | |
584 | sprintf(buf, "Print Server entry for %s.", info[PRINTSERVER_HOST]); | |
585 | Put_message(buf); | |
586 | Put_message(""); | |
587 | ||
588 | if (GetTypeFromUser("Kind of LPD", "lpd_kind", &info[PRINTSERVER_KIND]) == | |
589 | SUB_ERROR) | |
590 | return NULL; | |
591 | if (GetValueFromUser("Printer types", &info[PRINTSERVER_TYPES]) == SUB_ERROR) | |
592 | return NULL; | |
593 | if (GetTypeFromUser("Owner type", "ace_type", &info[PRINTSERVER_OWNER_TYPE]) | |
594 | == SUB_ERROR) | |
595 | return NULL; | |
596 | if (strcmp(info[PRINTSERVER_OWNER_TYPE], "NONE") && | |
597 | GetValueFromUser("Owner Name", &info[PRINTSERVER_OWNER_NAME]) == | |
598 | SUB_ERROR) | |
599 | return NULL; | |
600 | if (GetValueFromUser("LPC ACL", &info[PRINTSERVER_LPC_ACL]) == SUB_ERROR) | |
601 | return NULL; | |
602 | ||
603 | FreeAndClear(&info[PRINTSERVER_MODTIME], TRUE); | |
604 | FreeAndClear(&info[PRINTSERVER_MODBY], TRUE); | |
605 | FreeAndClear(&info[PRINTSERVER_MODWITH], TRUE); | |
606 | ||
607 | return info; | |
608 | } | |
609 | ||
610 | int AddPrintSrv(int argc, char **argv) | |
611 | { | |
612 | char *info[MAX_ARGS_SIZE], **args, *name; | |
613 | int stat; | |
614 | ||
615 | name = canonicalize_hostname(strdup(argv[1])); | |
616 | ||
617 | if (!(stat = do_mr_query("get_print_server", 1, &name, NULL, NULL))) | |
618 | { | |
619 | Put_message ("A print server record for that host already exists."); | |
620 | free(name); | |
621 | return DM_NORMAL; | |
622 | } | |
623 | else if (stat != MR_NO_MATCH) | |
624 | { | |
625 | com_err(program_name, stat, " in AddPrintSrv"); | |
626 | free(name); | |
627 | return DM_NORMAL; | |
628 | } | |
629 | ||
630 | args = AskPrintSrvInfo(SetPrintSrvDefaults(info, name)); | |
631 | free(name); | |
632 | if (!args) | |
633 | { | |
634 | Put_message("Aborted."); | |
635 | return DM_NORMAL; | |
636 | } | |
637 | ||
638 | if ((stat = do_mr_query("add_print_server", CountArgs(args), | |
639 | args, NULL, NULL))) | |
640 | com_err(program_name, stat, " in AddPrintSrv"); | |
641 | ||
642 | FreeInfo(info); | |
643 | return DM_NORMAL; | |
644 | } | |
645 | ||
646 | int ChangePrintSrv(int argc, char **argv) | |
647 | { | |
648 | char *name; | |
649 | struct mqelem *elem = NULL; | |
650 | int stat; | |
651 | ||
652 | name = canonicalize_hostname(strdup(argv[1])); | |
653 | if ((stat = do_mr_query("get_print_server", 1, &name, StoreInfo, &elem))) | |
654 | { | |
655 | free(name); | |
656 | com_err(program_name, stat, " in ChangePrintSrv"); | |
657 | return DM_NORMAL; | |
658 | } | |
659 | free(name); | |
660 | ||
661 | QueryLoop(elem, NullPrint, ChangePrintSrvLoop, "Change the print server"); | |
662 | FreeQueue(elem); | |
663 | return DM_NORMAL; | |
664 | } | |
665 | ||
666 | void ChangePrintSrvLoop(char **info, Bool one) | |
667 | { | |
668 | int stat; | |
669 | ||
670 | if (!AskPrintSrvInfo(info)) | |
671 | return; | |
672 | ||
673 | if ((stat = do_mr_query("update_print_server", CountArgs(info), | |
674 | info, NULL, NULL))) | |
675 | com_err(program_name, stat, " in ChangePrintSrv"); | |
676 | ||
677 | FreeInfo(info); | |
678 | return; | |
679 | } | |
680 | ||
681 | int DelPrintSrv(int argc, char **argv) | |
682 | { | |
683 | int stat; | |
684 | char *name; | |
685 | ||
686 | name = canonicalize_hostname(strdup(argv[1])); | |
687 | ||
688 | if ((stat = do_mr_query("delete_print_server", 1, &name, NULL, NULL))) | |
689 | com_err(program_name, stat, " while deleting print server"); | |
690 | free(name); | |
691 | return DM_NORMAL; | |
692 | } |