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