]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/adminutil.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / adminutil.c
1 /*
2 * "$Id: adminutil.c 6361 2007-03-19 16:01:28Z mike $"
3 *
4 * Administration utility API definitions for the Common UNIX Printing
5 * System (CUPS).
6 *
7 * Copyright 2001-2007 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
14 * at:
15 *
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
20 *
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 *
25 * This file is subject to the Apple OS-Developed Software exception.
26 *
27 * Contents:
28 *
29 * cupsAdminCreateWindowsPPD() - Create the Windows PPD file for a printer.
30 * cupsAdminExportSamba() - Export a printer to Samba.
31 * cupsAdminGetServerSettings() - Get settings from the server.
32 * _cupsAdminGetServerSettings() - Get settings from the server (private).
33 * cupsAdminSetServerSettings() - Set settings on the server.
34 * _cupsAdminSetServerSettings() - Set settings on the server (private).
35 * do_samba_command() - Do a SAMBA command.
36 * get_cupsd_conf() - Get the current cupsd.conf file.
37 * invalidate_cupsd_cache() - Invalidate the cached cupsd.conf settings.
38 * write_option() - Write a CUPS option to a PPD file.
39 */
40
41 /*
42 * Include necessary headers...
43 */
44
45 #include "adminutil.h"
46 #include "globals.h"
47 #include "debug.h"
48 #include <errno.h>
49 #include <fcntl.h>
50 #include <sys/stat.h>
51 #ifdef WIN32
52 #else
53 # include <unistd.h>
54 # include <sys/wait.h>
55 #endif /* WIN32 */
56
57
58 /*
59 * Local functions...
60 */
61
62 static int do_samba_command(const char *command,
63 const char *address,
64 const char *subcommand,
65 const char *authfile,
66 FILE *logfile);
67 static http_status_t get_cupsd_conf(http_t *http, _cups_globals_t *cg,
68 time_t last_update, char *name,
69 int namelen, int *remote);
70 static void invalidate_cupsd_cache(_cups_globals_t *cg);
71 static void write_option(cups_file_t *dstfp, int order,
72 const char *name, const char *text,
73 const char *attrname,
74 ipp_attribute_t *suppattr,
75 ipp_attribute_t *defattr, int defval,
76 int valcount);
77
78
79 /*
80 * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
81 */
82
83 char * /* O - PPD file or NULL */
84 cupsAdminCreateWindowsPPD(
85 http_t *http, /* I - Connection to server */
86 const char *dest, /* I - Printer or class */
87 char *buffer, /* I - Filename buffer */
88 int bufsize) /* I - Size of filename buffer */
89 {
90 const char *src; /* Source PPD filename */
91 cups_file_t *srcfp, /* Source PPD file */
92 *dstfp; /* Destination PPD file */
93 ipp_t *request, /* IPP request */
94 *response; /* IPP response */
95 ipp_attribute_t *suppattr, /* IPP -supported attribute */
96 *defattr; /* IPP -default attribute */
97 cups_lang_t *language; /* Current language */
98 char line[256], /* Line from PPD file */
99 junk[256], /* Extra junk to throw away */
100 *ptr, /* Pointer into line */
101 uri[1024], /* Printer URI */
102 option[41], /* Option */
103 choice[41]; /* Choice */
104 int jcloption, /* In a JCL option? */
105 linenum; /* Current line number */
106 time_t curtime; /* Current time */
107 struct tm *curdate; /* Current date */
108 static const char * const pattrs[] = /* Printer attributes we want */
109 {
110 "job-hold-until-supported",
111 "job-hold-until-default",
112 "job-sheets-supported",
113 "job-sheets-default",
114 "job-priority-supported",
115 "job-priority-default"
116 };
117
118
119 /*
120 * Range check the input...
121 */
122
123 if (buffer)
124 *buffer = '\0';
125
126 if (!http || !dest || !buffer || bufsize < 2)
127 return (NULL);
128
129 /*
130 * Get the PPD file...
131 */
132
133 if ((src = cupsGetPPD2(http, dest)) == NULL)
134 return (NULL);
135
136 /*
137 * Get the supported banner pages, etc. for the printer...
138 */
139
140 request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
141
142 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
143 "localhost", 0, "/printers/%s", dest);
144 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
145 "printer-uri", NULL, uri);
146
147 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
148 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]),
149 NULL, pattrs);
150
151 /*
152 * Do the request and get back a response...
153 */
154
155 response = cupsDoRequest(http, request, "/");
156 if (!response || cupsLastError() > IPP_OK_CONFLICT)
157 {
158 unlink(src);
159 return (NULL);
160 }
161
162 /*
163 * Open the original PPD file...
164 */
165
166 if ((srcfp = cupsFileOpen(src, "rb")) == NULL)
167 return (NULL);
168
169 /*
170 * Create a temporary output file using the destination buffer...
171 */
172
173 if ((dstfp = cupsTempFile2(buffer, bufsize)) == NULL)
174 {
175 cupsFileClose(srcfp);
176
177 unlink(src);
178
179 return (NULL);
180 }
181
182 /*
183 * Write a new header explaining that this isn't the original PPD...
184 */
185
186 cupsFilePuts(dstfp, "*PPD-Adobe: \"4.3\"\n");
187
188 curtime = time(NULL);
189 curdate = gmtime(&curtime);
190
191 cupsFilePrintf(dstfp, "*%% Modified on %04d%02d%02d%02d%02d%02d+0000 "
192 "for CUPS Windows Driver\n",
193 curdate->tm_year + 1900, curdate->tm_mon + 1, curdate->tm_mday,
194 curdate->tm_hour, curdate->tm_min, curdate->tm_sec);
195
196 /*
197 * Read the existing PPD file, converting all PJL commands to CUPS
198 * job ticket comments...
199 */
200
201 jcloption = 0;
202 linenum = 0;
203 language = cupsLangDefault();
204
205 while (cupsFileGets(srcfp, line, sizeof(line)))
206 {
207 linenum ++;
208
209 if (!strncmp(line, "*PPD-Adobe:", 11))
210 {
211 /*
212 * Already wrote the PPD header...
213 */
214
215 continue;
216 }
217 else if (!strncmp(line, "*JCLBegin:", 10) ||
218 !strncmp(line, "*JCLToPSInterpreter:", 20) ||
219 !strncmp(line, "*JCLEnd:", 8) ||
220 !strncmp(line, "*Protocols:", 11))
221 {
222 /*
223 * Don't use existing JCL keywords; we'll create our own, below...
224 */
225
226 cupsFilePrintf(dstfp, "*%% Commented out for CUPS Windows Driver...\n"
227 "*%%%s\n", line + 1);
228 continue;
229 }
230 else if (!strncmp(line, "*JCLOpenUI", 10))
231 {
232 jcloption = 1;
233 cupsFilePrintf(dstfp, "%s\n", line);
234 }
235 else if (!strncmp(line, "*JCLCloseUI", 11))
236 {
237 jcloption = 0;
238 cupsFilePrintf(dstfp, "%s\n", line);
239 }
240 else if (jcloption &&
241 strncmp(line, "*End", 4) &&
242 strncmp(line, "*Default", 8) &&
243 strncmp(line, "*OrderDependency", 16))
244 {
245 if ((ptr = strchr(line, ':')) == NULL)
246 {
247 snprintf(line, sizeof(line),
248 _cupsLangString(language, _("Missing value on line %d!")),
249 linenum);
250 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
251
252 cupsFileClose(srcfp);
253 cupsFileClose(dstfp);
254
255 unlink(src);
256 unlink(buffer);
257
258 *buffer = '\0';
259
260 return (NULL);
261 }
262
263 if ((ptr = strchr(ptr, '\"')) == NULL)
264 {
265 snprintf(line, sizeof(line),
266 _cupsLangString(language,
267 _("Missing double quote on line %d!")),
268 linenum);
269 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
270
271 cupsFileClose(srcfp);
272 cupsFileClose(dstfp);
273
274 unlink(src);
275 unlink(buffer);
276
277 *buffer = '\0';
278
279 return (NULL);
280 }
281
282 if (sscanf(line, "*%40s%*[ \t]%40[^/]", option, choice) != 2)
283 {
284 snprintf(line, sizeof(line),
285 _cupsLangString(language,
286 _("Bad option + choice on line %d!")),
287 linenum);
288 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
289
290 cupsFileClose(srcfp);
291 cupsFileClose(dstfp);
292
293 unlink(src);
294 unlink(buffer);
295
296 *buffer = '\0';
297
298 return (NULL);
299 }
300
301 if (strchr(ptr + 1, '\"') == NULL)
302 {
303 /*
304 * Skip remaining...
305 */
306
307 while (cupsFileGets(srcfp, junk, sizeof(junk)) != NULL)
308 {
309 linenum ++;
310
311 if (!strncmp(junk, "*End", 4))
312 break;
313 }
314 }
315
316 snprintf(ptr + 1, sizeof(line) - (ptr - line + 1),
317 "%%cupsJobTicket: %s=%s\n\"\n*End", option, choice);
318
319 cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s\n",
320 line);
321 }
322 else
323 cupsFilePrintf(dstfp, "%s\n", line);
324 }
325
326 cupsFileClose(srcfp);
327 unlink(src);
328
329 if (linenum == 0)
330 {
331 snprintf(line, sizeof(line),
332 _cupsLangString(language, _("Empty PPD file!")),
333 linenum);
334 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
335
336 cupsFileClose(dstfp);
337 unlink(buffer);
338
339 *buffer = '\0';
340
341 return (NULL);
342 }
343
344 /*
345 * Now add the CUPS-specific attributes and options...
346 */
347
348 cupsFilePuts(dstfp, "\n*% CUPS Job Ticket support and options...\n");
349 cupsFilePuts(dstfp, "*Protocols: PJL\n");
350 cupsFilePuts(dstfp, "*JCLBegin: \"%!PS-Adobe-3.0<0A>\"\n");
351 cupsFilePuts(dstfp, "*JCLToPSInterpreter: \"\"\n");
352 cupsFilePuts(dstfp, "*JCLEnd: \"\"\n");
353
354 cupsFilePuts(dstfp, "\n*OpenGroup: CUPS/CUPS Options\n\n");
355
356 if ((defattr = ippFindAttribute(response, "job-hold-until-default",
357 IPP_TAG_ZERO)) != NULL &&
358 (suppattr = ippFindAttribute(response, "job-hold-until-supported",
359 IPP_TAG_ZERO)) != NULL)
360 write_option(dstfp, 10, "cupsJobHoldUntil", "Hold Until", "job-hold-until",
361 suppattr, defattr, 0, 1);
362
363 if ((defattr = ippFindAttribute(response, "job-priority-default",
364 IPP_TAG_INTEGER)) != NULL &&
365 (suppattr = ippFindAttribute(response, "job-priority-supported",
366 IPP_TAG_RANGE)) != NULL)
367 write_option(dstfp, 11, "cupsJobPriority", "Priority", "job-priority",
368 suppattr, defattr, 0, 1);
369
370 if ((defattr = ippFindAttribute(response, "job-sheets-default",
371 IPP_TAG_ZERO)) != NULL &&
372 (suppattr = ippFindAttribute(response, "job-sheets-supported",
373 IPP_TAG_ZERO)) != NULL)
374 {
375 write_option(dstfp, 20, "cupsJobSheetsStart", "Start Banner",
376 "job-sheets", suppattr, defattr, 0, 2);
377 write_option(dstfp, 21, "cupsJobSheetsEnd", "End Banner",
378 "job-sheets", suppattr, defattr, 1, 2);
379 }
380
381 cupsFilePuts(dstfp, "*CloseGroup: CUPS\n");
382 cupsFileClose(dstfp);
383
384 ippDelete(response);
385
386 return (buffer);
387 }
388
389
390 /*
391 * 'cupsAdminExportSamba()' - Export a printer to Samba.
392 */
393
394 int /* O - 1 on success, 0 on failure */
395 cupsAdminExportSamba(
396 const char *dest, /* I - Destination to export */
397 const char *ppd, /* I - PPD file */
398 const char *samba_server, /* I - Samba server */
399 const char *samba_user, /* I - Samba username */
400 const char *samba_password, /* I - Samba password */
401 FILE *logfile) /* I - Log file, if any */
402 {
403 int status; /* Status of Samba commands */
404 int have_drivers; /* Have drivers? */
405 char file[1024], /* File to test for */
406 authfile[1024], /* Temporary authentication file */
407 address[1024], /* Address for command */
408 subcmd[1024], /* Sub-command */
409 message[1024]; /* Error message */
410 cups_file_t *fp; /* Authentication file */
411 cups_lang_t *language; /* Current language */
412 _cups_globals_t *cg = _cupsGlobals();
413 /* Global data */
414
415
416 /*
417 * Range check input...
418 */
419
420 if (!dest || !ppd || !samba_server || !samba_user || !samba_password)
421 {
422 _cupsSetError(IPP_INTERNAL_ERROR, NULL);
423 return (0);
424 }
425
426 /*
427 * Create a temporary authentication file for Samba...
428 */
429
430 if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL)
431 {
432 _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
433 return (0);
434 }
435
436 cupsFilePrintf(fp, "username = %s\n", samba_user);
437 cupsFilePrintf(fp, "password = %s\n", samba_password);
438 cupsFileClose(fp);
439
440 /*
441 * See which drivers are available; the new CUPS v6 and Adobe drivers
442 * depend on the Windows 2k PS driver, so copy that driver first:
443 *
444 * Files:
445 *
446 * ps5ui.dll
447 * pscript.hlp
448 * pscript.ntf
449 * pscript5.dll
450 */
451
452 have_drivers = 0;
453 language = cupsLangDefault();
454
455 snprintf(file, sizeof(file), "%s/drivers/pscript5.dll", cg->cups_datadir);
456 if (!access(file, 0))
457 {
458 have_drivers |= 1;
459
460 /*
461 * Windows 2k driver is installed; do the smbclient commands needed
462 * to copy the Win2k drivers over...
463 */
464
465 snprintf(address, sizeof(address), "//%s/print$", samba_server);
466
467 snprintf(subcmd, sizeof(subcmd),
468 "mkdir W32X86;"
469 "put %s W32X86/%s.ppd;"
470 "put %s/drivers/ps5ui.dll W32X86/ps5ui.dll;"
471 "put %s/drivers/pscript.hlp W32X86/pscript.hlp;"
472 "put %s/drivers/pscript.ntf W32X86/pscript.ntf;"
473 "put %s/drivers/pscript5.dll W32X86/pscript5.dll",
474 ppd, dest, cg->cups_datadir, cg->cups_datadir,
475 cg->cups_datadir, cg->cups_datadir);
476
477 if ((status = do_samba_command("smbclient", address, subcmd,
478 authfile, logfile)) != 0)
479 {
480 snprintf(message, sizeof(message),
481 _cupsLangString(language,
482 _("Unable to copy Windows 2000 printer "
483 "driver files (%d)!")), status);
484
485 _cupsSetError(IPP_INTERNAL_ERROR, message);
486
487 if (logfile)
488 _cupsLangPrintf(logfile, "%s\n", message);
489
490 unlink(authfile);
491
492 return (0);
493 }
494
495 /*
496 * See if we also have the CUPS driver files; if so, use them!
497 */
498
499 snprintf(file, sizeof(file), "%s/drivers/cupsps6.dll", cg->cups_datadir);
500 if (!access(file, 0))
501 {
502 /*
503 * Copy the CUPS driver files over...
504 */
505
506 snprintf(subcmd, sizeof(subcmd),
507 "put %s/drivers/cups6.ini W32X86/cups6.ini;"
508 "put %s/drivers/cupsps6.dll W32X86/cupsps6.dll;"
509 "put %s/drivers/cupsui6.dll W32X86/cupsui6.dll",
510 cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
511
512 if ((status = do_samba_command("smbclient", address, subcmd,
513 authfile, logfile)) != 0)
514 {
515 snprintf(message, sizeof(message),
516 _cupsLangString(language,
517 _("Unable to copy CUPS printer driver "
518 "files (%d)!")), status);
519
520 _cupsSetError(IPP_INTERNAL_ERROR, message);
521
522 if (logfile)
523 _cupsLangPrintf(logfile, "%s\n", message);
524
525 unlink(authfile);
526
527 return (0);
528 }
529
530 /*
531 * Do the rpcclient command needed for the CUPS drivers...
532 */
533
534 snprintf(subcmd, sizeof(subcmd),
535 "adddriver \"Windows NT x86\" \"%s:"
536 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
537 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
538 "cups6.ini,cupsps6.dll,cupsui6.dll\"",
539 dest, dest, dest);
540 }
541 else
542 {
543 /*
544 * Don't have the CUPS drivers, so just use the standard Windows
545 * drivers...
546 */
547
548 snprintf(subcmd, sizeof(subcmd),
549 "adddriver \"Windows NT x86\" \"%s:"
550 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
551 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
552 dest, dest, dest);
553 }
554
555 if ((status = do_samba_command("rpcclient", samba_server, subcmd,
556 authfile, logfile)) != 0)
557 {
558 snprintf(message, sizeof(message),
559 _cupsLangString(language,
560 _("Unable to install Windows 2000 printer "
561 "driver files (%d)!")), status);
562
563 _cupsSetError(IPP_INTERNAL_ERROR, message);
564
565 if (logfile)
566 _cupsLangPrintf(logfile, "%s\n", message);
567
568 unlink(authfile);
569
570 return (0);
571 }
572 }
573
574 snprintf(file, sizeof(file), "%s/drivers/ADOBEPS4.DRV", cg->cups_datadir);
575 if (!access(file, 0))
576 {
577 have_drivers |= 2;
578
579 /*
580 * Do the smbclient commands needed for the Adobe Win9x drivers...
581 */
582
583 snprintf(address, sizeof(address), "//%s/print$", samba_server);
584
585 snprintf(subcmd, sizeof(subcmd),
586 "mkdir WIN40;"
587 "put %s WIN40/%s.PPD;"
588 "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
589 "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
590 "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
591 "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
592 "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
593 ppd, dest, cg->cups_datadir, cg->cups_datadir,
594 cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
595
596 if ((status = do_samba_command("smbclient", address, subcmd,
597 authfile, logfile)) != 0)
598 {
599 snprintf(message, sizeof(message),
600 _cupsLangString(language,
601 _("Unable to copy Windows 9x printer "
602 "driver files (%d)!")), status);
603
604 _cupsSetError(IPP_INTERNAL_ERROR, message);
605
606 if (logfile)
607 _cupsLangPrintf(logfile, "%s\n", message);
608
609 unlink(authfile);
610
611 return (0);
612 }
613
614 /*
615 * Do the rpcclient commands needed for the Adobe Win9x drivers...
616 */
617
618 snprintf(subcmd, sizeof(subcmd),
619 "adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:"
620 "ADOBEPS4.HLP:PSMON.DLL:RAW:"
621 "ADOBEPS4.DRV,%s.PPD,ADOBEPS4.HLP,PSMON.DLL,ADFONTS.MFM,"
622 "ICONLIB.DLL\"",
623 dest, dest, dest);
624
625 if ((status = do_samba_command("rpcclient", samba_server, subcmd,
626 authfile, logfile)) != 0)
627 {
628 snprintf(message, sizeof(message),
629 _cupsLangString(language,
630 _("Unable to install Windows 9x printer "
631 "driver files (%d)!")), status);
632
633 _cupsSetError(IPP_INTERNAL_ERROR, message);
634
635 if (logfile)
636 _cupsLangPrintf(logfile, "%s\n", message);
637
638 unlink(authfile);
639
640 return (0);
641 }
642 }
643
644 if (logfile && !(have_drivers & 1))
645 {
646 if (!have_drivers)
647 strlcpy(message,
648 _cupsLangString(language,
649 _("No Windows printer drivers are installed!")),
650 sizeof(message));
651 else
652 strlcpy(message,
653 _cupsLangString(language,
654 _("Warning, no Windows 2000 printer drivers "
655 "are installed!")),
656 sizeof(message));
657
658 _cupsSetError(IPP_INTERNAL_ERROR, message);
659 _cupsLangPrintf(logfile, "%s\n", message);
660 }
661
662 if (have_drivers == 0)
663 return (0);
664
665 /*
666 * Finally, associate the drivers we just added with the queue...
667 */
668
669 snprintf(subcmd, sizeof(subcmd), "setdriver %s %s", dest, dest);
670
671 if ((status = do_samba_command("rpcclient", samba_server, subcmd,
672 authfile, logfile)) != 0)
673 {
674 snprintf(message, sizeof(message),
675 _cupsLangString(language,
676 _("Unable to set Windows printer driver (%d)!")),
677 status);
678
679 _cupsSetError(IPP_INTERNAL_ERROR, message);
680
681 if (logfile)
682 _cupsLangPrintf(logfile, "%s\n", message);
683
684 unlink(authfile);
685
686 return (0);
687 }
688
689 unlink(authfile);
690
691 return (1);
692 }
693
694
695 /*
696 * 'cupsAdminGetServerSettings()' - Get settings from the server.
697 *
698 * The returned settings should be freed with cupsFreeOptions() when
699 * you are done with them.
700 *
701 * @since CUPS 1.3@
702 */
703
704 int /* O - 1 on success, 0 on failure */
705 cupsAdminGetServerSettings(
706 http_t *http, /* I - Connection to server */
707 int *num_settings, /* O - Number of settings */
708 cups_option_t **settings) /* O - Settings */
709 {
710 return (_cupsAdminGetServerSettings(http, num_settings, settings));
711 }
712
713
714 /*
715 * '_cupsAdminGetServerSettings()' - Get settings from the server.
716 *
717 * The returned settings should be freed with cupsFreeOptions() when
718 * you are done with them.
719 *
720 * @since CUPS 1.2@
721 */
722
723 int /* O - 1 on success, 0 on failure */
724 _cupsAdminGetServerSettings(
725 http_t *http, /* I - Connection to server */
726 int *num_settings, /* O - Number of settings */
727 cups_option_t **settings) /* O - Settings */
728 {
729 int i; /* Looping var */
730 cups_file_t *cupsd; /* cupsd.conf file */
731 char cupsdconf[1024]; /* cupsd.conf filename */
732 int remote; /* Remote cupsd.conf file? */
733 http_status_t status; /* Status of getting cupsd.conf */
734 char line[1024], /* Line from cupsd.conf file */
735 *value; /* Value on line */
736 cups_option_t *setting; /* Current setting */
737 _cups_globals_t *cg = _cupsGlobals(); /* Global data */
738
739
740 /*
741 * Range check input...
742 */
743
744 if (!http || !num_settings || !settings)
745 {
746 _cupsSetError(IPP_INTERNAL_ERROR, NULL);
747
748 if (num_settings)
749 *num_settings = 0;
750
751 if (settings)
752 *settings = NULL;
753
754 return (0);
755 }
756
757 *num_settings = 0;
758 *settings = NULL;
759
760 /*
761 * Get the cupsd.conf file...
762 */
763
764 if ((status = get_cupsd_conf(http, cg, cg->cupsd_update, cupsdconf,
765 sizeof(cupsdconf), &remote)) == HTTP_OK)
766 {
767 if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
768 {
769 char message[1024]; /* Message string */
770
771
772 snprintf(message, sizeof(message),
773 _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
774 cupsdconf, strerror(errno));
775 _cupsSetError(IPP_INTERNAL_ERROR, message);
776 }
777 }
778 else
779 cupsd = NULL;
780
781 if (cupsd)
782 {
783 /*
784 * Read the file, keeping track of what settings are enabled...
785 */
786
787 int remote_access = 0, /* Remote access allowed? */
788 remote_admin = 0, /* Remote administration allowed? */
789 remote_any = 0, /* Remote access from anywhere allowed? */
790 browsing = 1, /* Browsing enabled? */
791 browse_allow = 1, /* Browse address set? */
792 browse_address = 0, /* Browse address set? */
793 cancel_policy = 1, /* Cancel-job policy set? */
794 debug_logging = 0; /* LogLevel debug set? */
795 int linenum = 0, /* Line number in file */
796 in_location = 0, /* In a location section? */
797 in_policy = 0, /* In a policy section? */
798 in_cancel_job = 0, /* In a cancel-job section? */
799 in_admin_location = 0; /* In the /admin location? */
800
801
802 invalidate_cupsd_cache(cg);
803
804 cg->cupsd_update = time(NULL);
805 httpGetHostname(http, cg->cupsd_hostname, sizeof(cg->cupsd_hostname));
806
807 while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
808 {
809 if (!value)
810 continue;
811
812 if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
813 {
814 char *port; /* Pointer to port number, if any */
815
816
817 if ((port = strrchr(value, ':')) != NULL)
818 *port = '\0';
819 else if (isdigit(*value & 255))
820 {
821 /*
822 * Listen on a port number implies remote access...
823 */
824
825 remote_access = 1;
826 continue;
827 }
828
829 if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1")
830 #ifdef AF_LOCAL
831 && *value != '/'
832 #endif /* AF_LOCAL */
833 #ifdef AF_INET6
834 && strcmp(value, "::1")
835 #endif /* AF_INET6 */
836 )
837 remote_access = 1;
838 }
839 else if (!strcasecmp(line, "Browsing"))
840 {
841 browsing = !strcasecmp(value, "yes") || !strcasecmp(value, "on") ||
842 !strcasecmp(value, "true");
843 }
844 else if (!strcasecmp(line, "BrowseAddress"))
845 {
846 browse_address = 1;
847 }
848 else if (!strcasecmp(line, "BrowseAllow"))
849 {
850 browse_allow = 1;
851 }
852 else if (!strcasecmp(line, "BrowseOrder"))
853 {
854 browse_allow = !strncasecmp(value, "deny,", 5);
855 }
856 else if (!strcasecmp(line, "LogLevel"))
857 {
858 debug_logging = !strncasecmp(value, "debug", 5);
859 }
860 else if (!strcasecmp(line, "<Policy") && !strcasecmp(value, "default"))
861 {
862 in_policy = 1;
863 }
864 else if (!strcasecmp(line, "</Policy>"))
865 {
866 in_policy = 0;
867 }
868 else if (!strcasecmp(line, "<Limit") && in_policy)
869 {
870 /*
871 * See if the policy limit is for the Cancel-Job operation...
872 */
873
874 char *valptr; /* Pointer into value */
875
876
877 while (*value)
878 {
879 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
880
881 if (*valptr)
882 *valptr++ = '\0';
883
884 if (!strcasecmp(value, "cancel-job") || !strcasecmp(value, "all"))
885 {
886 in_cancel_job = 1;
887 break;
888 }
889
890 for (value = valptr; isspace(*value & 255); value ++);
891 }
892 }
893 else if (!strcasecmp(line, "</Limit>"))
894 {
895 in_cancel_job = 0;
896 }
897 else if (!strcasecmp(line, "Require") && in_cancel_job)
898 {
899 cancel_policy = 0;
900 }
901 else if (!strcasecmp(line, "<Location"))
902 {
903 in_admin_location = !strcasecmp(value, "/admin");
904 in_location = 1;
905 }
906 else if (!strcasecmp(line, "</Location>"))
907 {
908 in_admin_location = 0;
909 in_location = 0;
910 }
911 else if (!strcasecmp(line, "Allow") && in_admin_location &&
912 strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
913 #ifdef AF_LOCAL
914 && *value != '/'
915 #endif /* AF_LOCAL */
916 #ifdef AF_INET6
917 && strcmp(value, "::1")
918 #endif /* AF_INET6 */
919 )
920 {
921 remote_admin = 1;
922
923 if (!strcasecmp(value, "all"))
924 remote_any = 1;
925 }
926 else if (line[0] != '<' && !in_location && !in_policy)
927 cg->cupsd_num_settings = cupsAddOption(line, value,
928 cg->cupsd_num_settings,
929 &(cg->cupsd_settings));
930 }
931
932 cupsFileClose(cupsd);
933
934 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
935 debug_logging ? "1" : "0",
936 cg->cupsd_num_settings,
937 &(cg->cupsd_settings));
938
939 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
940 (remote_access && remote_admin) ?
941 "1" : "0",
942 cg->cupsd_num_settings,
943 &(cg->cupsd_settings));
944
945 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY,
946 remote_any ? "1" : "0",
947 cg->cupsd_num_settings,
948 &(cg->cupsd_settings));
949
950 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
951 (browsing && browse_allow) ?
952 "1" : "0",
953 cg->cupsd_num_settings,
954 &(cg->cupsd_settings));
955
956 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
957 (remote_access && browsing &&
958 browse_address) ? "1" : "0",
959 cg->cupsd_num_settings,
960 &(cg->cupsd_settings));
961
962 cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
963 cancel_policy ? "1" : "0",
964 cg->cupsd_num_settings,
965 &(cg->cupsd_settings));
966 }
967 else if (status != HTTP_NOT_MODIFIED)
968 invalidate_cupsd_cache(cg);
969
970 /*
971 * Remove any temporary files and copy the settings array...
972 */
973
974 if (remote)
975 unlink(cupsdconf);
976
977 for (i = cg->cupsd_num_settings, setting = cg->cupsd_settings;
978 i > 0;
979 i --, setting ++)
980 *num_settings = cupsAddOption(setting->name, setting->value,
981 *num_settings, settings);
982
983 return (cg->cupsd_num_settings > 0);
984 }
985
986
987 /*
988 * 'cupsAdminSetServerSettings()' - Set settings on the server.
989 *
990 * @since CUPS 1.3@
991 */
992
993 int /* O - 1 on success, 0 on failure */
994 cupsAdminSetServerSettings(
995 http_t *http, /* I - Connection to server */
996 int num_settings, /* I - Number of settings */
997 cups_option_t *settings) /* I - Settings */
998 {
999 return (_cupsAdminSetServerSettings(http, num_settings, settings));
1000 }
1001
1002
1003 /*
1004 * '_cupsAdminSetServerSettings()' - Set settings on the server.
1005 *
1006 * @since CUPS 1.2@
1007 */
1008
1009 int /* O - 1 on success, 0 on failure */
1010 _cupsAdminSetServerSettings(
1011 http_t *http, /* I - Connection to server */
1012 int num_settings, /* I - Number of settings */
1013 cups_option_t *settings) /* I - Settings */
1014 {
1015 int i; /* Looping var */
1016 http_status_t status; /* GET/PUT status */
1017 const char *server_port_env; /* SERVER_PORT env var */
1018 int server_port; /* IPP port for server */
1019 cups_file_t *cupsd; /* cupsd.conf file */
1020 char cupsdconf[1024]; /* cupsd.conf filename */
1021 int remote; /* Remote cupsd.conf file? */
1022 char tempfile[1024]; /* Temporary new cupsd.conf */
1023 cups_file_t *temp; /* Temporary file */
1024 char line[1024], /* Line from cupsd.conf file */
1025 *value; /* Value on line */
1026 int linenum, /* Line number in file */
1027 in_location, /* In a location section? */
1028 in_policy, /* In a policy section? */
1029 in_default_policy, /* In the default policy section? */
1030 in_cancel_job, /* In a cancel-job section? */
1031 in_admin_location, /* In the /admin location? */
1032 in_conf_location, /* In the /admin/conf location? */
1033 in_root_location; /* In the / location? */
1034 const char *val; /* Setting value */
1035 int remote_printers, /* Show remote printers */
1036 share_printers, /* Share local printers */
1037 remote_admin, /* Remote administration allowed? */
1038 remote_any, /* Remote access from anywhere? */
1039 user_cancel_any, /* Cancel-job policy set? */
1040 debug_logging; /* LogLevel debug set? */
1041 int wrote_port_listen, /* Wrote the port/listen lines? */
1042 wrote_browsing, /* Wrote the browsing lines? */
1043 wrote_policy, /* Wrote the policy? */
1044 wrote_loglevel, /* Wrote the LogLevel line? */
1045 wrote_admin_location, /* Wrote the /admin location? */
1046 wrote_conf_location, /* Wrote the /admin/conf location? */
1047 wrote_root_location; /* Wrote the / location? */
1048 int indent; /* Indentation */
1049 int cupsd_num_settings; /* New number of settings */
1050 int old_remote_printers, /* Show remote printers */
1051 old_share_printers, /* Share local printers */
1052 old_remote_admin, /* Remote administration allowed? */
1053 old_user_cancel_any, /* Cancel-job policy set? */
1054 old_debug_logging; /* LogLevel debug set? */
1055 cups_option_t *cupsd_settings, /* New settings */
1056 *setting; /* Current setting */
1057 _cups_globals_t *cg = _cupsGlobals(); /* Global data */
1058
1059
1060 /*
1061 * Range check input...
1062 */
1063
1064 if (!http || !num_settings || !settings)
1065 {
1066 _cupsSetError(IPP_INTERNAL_ERROR, NULL);
1067
1068 return (0);
1069 }
1070
1071 /*
1072 * Get the cupsd.conf file...
1073 */
1074
1075 if ((status = get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
1076 &remote)) == HTTP_OK)
1077 {
1078 if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
1079 {
1080 _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
1081 return (0);
1082 }
1083 }
1084 else
1085 return (0);
1086
1087 /*
1088 * Get current settings...
1089 */
1090
1091 if (!_cupsAdminGetServerSettings(http, &cupsd_num_settings,
1092 &cupsd_settings))
1093 return (0);
1094
1095 if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, cupsd_num_settings,
1096 cupsd_settings)) != NULL)
1097 old_debug_logging = atoi(val);
1098 else
1099 old_debug_logging = 0;
1100
1101 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, cupsd_num_settings,
1102 cupsd_settings)) != NULL)
1103 old_remote_admin = atoi(val);
1104 else
1105 old_remote_admin = 0;
1106
1107 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, cupsd_num_settings,
1108 cupsd_settings)) != NULL)
1109 remote_any = atoi(val);
1110 else
1111 remote_any = 0;
1112
1113 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, cupsd_num_settings,
1114 cupsd_settings)) != NULL)
1115 old_remote_printers = atoi(val);
1116 else
1117 old_remote_printers = 1;
1118
1119 if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, cupsd_num_settings,
1120 cupsd_settings)) != NULL)
1121 old_share_printers = atoi(val);
1122 else
1123 old_share_printers = 0;
1124
1125 if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, cupsd_num_settings,
1126 cupsd_settings)) != NULL)
1127 old_user_cancel_any = atoi(val);
1128 else
1129 old_user_cancel_any = 0;
1130
1131 cupsFreeOptions(cupsd_num_settings, cupsd_settings);
1132
1133 /*
1134 * Get basic settings...
1135 */
1136
1137 if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
1138 settings)) != NULL)
1139 {
1140 debug_logging = atoi(val);
1141
1142 if (debug_logging == old_debug_logging)
1143 {
1144 /*
1145 * No change to this setting...
1146 */
1147
1148 debug_logging = -1;
1149 }
1150 }
1151 else
1152 debug_logging = -1;
1153
1154 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
1155 settings)) != NULL)
1156 remote_any = atoi(val);
1157
1158 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
1159 settings)) != NULL)
1160 {
1161 remote_admin = atoi(val);
1162
1163 if (remote_admin == old_remote_admin && remote_any < 0)
1164 {
1165 /*
1166 * No change to this setting...
1167 */
1168
1169 remote_admin = -1;
1170 }
1171 }
1172 else
1173 remote_admin = -1;
1174
1175 if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
1176 settings)) != NULL)
1177 {
1178 remote_printers = atoi(val);
1179
1180 if (remote_printers == old_remote_printers)
1181 {
1182 /*
1183 * No change to this setting...
1184 */
1185
1186 remote_printers = -1;
1187 }
1188 }
1189 else
1190 remote_printers = -1;
1191
1192 if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
1193 settings)) != NULL)
1194 {
1195 share_printers = atoi(val);
1196
1197 if (share_printers == old_share_printers && remote_any < 0)
1198 {
1199 /*
1200 * No change to this setting...
1201 */
1202
1203 share_printers = -1;
1204 }
1205 }
1206 else
1207 share_printers = -1;
1208
1209 if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
1210 settings)) != NULL)
1211 {
1212 user_cancel_any = atoi(val);
1213
1214 if (user_cancel_any == old_user_cancel_any)
1215 {
1216 /*
1217 * No change to this setting...
1218 */
1219
1220 user_cancel_any = -1;
1221 }
1222 }
1223 else
1224 user_cancel_any = -1;
1225
1226 /*
1227 * Create a temporary file for the new cupsd.conf file...
1228 */
1229
1230 if ((temp = cupsTempFile2(tempfile, sizeof(tempfile))) == NULL)
1231 {
1232 cupsFileClose(cupsd);
1233
1234 if (remote)
1235 unlink(cupsdconf);
1236
1237 _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
1238 return (0);
1239 }
1240
1241 /*
1242 * Copy the old file to the new, making changes along the way...
1243 */
1244
1245 cupsd_num_settings = 0;
1246 in_admin_location = 0;
1247 in_cancel_job = 0;
1248 in_conf_location = 0;
1249 in_default_policy = 0;
1250 in_location = 0;
1251 in_policy = 0;
1252 in_root_location = 0;
1253 linenum = 0;
1254 wrote_admin_location = 0;
1255 wrote_browsing = 0;
1256 wrote_conf_location = 0;
1257 wrote_loglevel = 0;
1258 wrote_policy = 0;
1259 wrote_port_listen = 0;
1260 wrote_root_location = 0;
1261 indent = 0;
1262
1263 if ((server_port_env = getenv("SERVER_PORT")) != NULL)
1264 {
1265 if ((server_port = atoi(server_port_env)) <= 0)
1266 server_port = ippPort();
1267 }
1268 else
1269 server_port = ippPort();
1270
1271 if (server_port <= 0)
1272 server_port = IPP_PORT;
1273
1274 while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
1275 {
1276 if ((!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")) &&
1277 (share_printers >= 0 || remote_admin >= 0))
1278 {
1279 if (!wrote_port_listen)
1280 {
1281 wrote_port_listen = 1;
1282
1283 if (share_printers > 0 || remote_admin > 0)
1284 {
1285 cupsFilePuts(temp, "# Allow remote access\n");
1286 cupsFilePrintf(temp, "Port %d\n", server_port);
1287 }
1288 else
1289 {
1290 cupsFilePuts(temp, "# Only listen for connections from the local "
1291 "machine.\n");
1292 cupsFilePrintf(temp, "Listen localhost:%d\n", server_port);
1293 }
1294
1295 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1296 if ((!value || strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)) &&
1297 !access(CUPS_DEFAULT_DOMAINSOCKET, 0))
1298 cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
1299 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1300 }
1301 else if (value && value[0] == '/'
1302 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1303 && strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)
1304 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1305 )
1306 cupsFilePrintf(temp, "Listen %s\n", value);
1307 }
1308 else if ((!strcasecmp(line, "Browsing") ||
1309 !strcasecmp(line, "BrowseAddress") ||
1310 !strcasecmp(line, "BrowseAllow") ||
1311 !strcasecmp(line, "BrowseDeny") ||
1312 !strcasecmp(line, "BrowseOrder")) &&
1313 (remote_printers >= 0 || share_printers >= 0))
1314 {
1315 if (!wrote_browsing)
1316 {
1317 wrote_browsing = 1;
1318
1319 if (remote_printers > 0 || share_printers > 0)
1320 {
1321 if (remote_printers > 0 && share_printers > 0)
1322 cupsFilePuts(temp,
1323 "# Enable printer sharing and shared printers.\n");
1324 else if (remote_printers > 0)
1325 cupsFilePuts(temp,
1326 "# Show shared printers on the local network.\n");
1327 else
1328 cupsFilePuts(temp,
1329 "# Share local printers on the local network.\n");
1330
1331 cupsFilePuts(temp, "Browsing On\n");
1332 cupsFilePuts(temp, "BrowseOrder allow,deny\n");
1333
1334 if (remote_printers > 0)
1335 cupsFilePuts(temp, "BrowseAllow all\n");
1336
1337 if (share_printers > 0)
1338 cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
1339 }
1340 else
1341 {
1342 cupsFilePuts(temp,
1343 "# Disable printer sharing and shared printers.\n");
1344 cupsFilePuts(temp, "Browsing Off\n");
1345 }
1346 }
1347 }
1348 else if (!strcasecmp(line, "LogLevel") && debug_logging >= 0)
1349 {
1350 wrote_loglevel = 1;
1351
1352 if (debug_logging)
1353 {
1354 cupsFilePuts(temp,
1355 "# Show troubleshooting information in error_log.\n");
1356 cupsFilePuts(temp, "LogLevel debug\n");
1357 }
1358 else
1359 {
1360 cupsFilePuts(temp, "# Show general information in error_log.\n");
1361 cupsFilePuts(temp, "LogLevel info\n");
1362 }
1363 }
1364 else if (!strcasecmp(line, "<Policy"))
1365 {
1366 in_default_policy = !strcasecmp(value, "default");
1367 in_policy = 1;
1368
1369 cupsFilePrintf(temp, "%s %s>\n", line, value);
1370 indent += 2;
1371 }
1372 else if (!strcasecmp(line, "</Policy>"))
1373 {
1374 indent -= 2;
1375 if (!wrote_policy && in_default_policy)
1376 {
1377 wrote_policy = 1;
1378
1379 if (!user_cancel_any)
1380 cupsFilePuts(temp, " # Only the owner or an administrator can "
1381 "cancel a job...\n"
1382 " <Limit Cancel-Job>\n"
1383 " Order deny,allow\n"
1384 " Allow @SYSTEM\n"
1385 " Allow @OWNER\n"
1386 " </Limit>\n");
1387 }
1388
1389 in_policy = 0;
1390 in_default_policy = 0;
1391
1392 cupsFilePuts(temp, "</Policy>\n");
1393 }
1394 else if (!strcasecmp(line, "<Location"))
1395 {
1396 in_location = 1;
1397 indent += 2;
1398 if (!strcmp(value, "/admin"))
1399 in_admin_location = 1;
1400 if (!strcmp(value, "/admin/conf"))
1401 in_conf_location = 1;
1402 else if (!strcmp(value, "/"))
1403 in_root_location = 1;
1404
1405 cupsFilePrintf(temp, "%s %s>\n", line, value);
1406 }
1407 else if (!strcasecmp(line, "</Location>"))
1408 {
1409 in_location = 0;
1410 indent -= 2;
1411 if (in_admin_location && remote_admin >= 0)
1412 {
1413 wrote_admin_location = 1;
1414
1415 if (remote_admin)
1416 cupsFilePuts(temp, " # Allow remote administration...\n");
1417 else if (remote_admin == 0)
1418 cupsFilePuts(temp, " # Restrict access to the admin pages...\n");
1419
1420 cupsFilePuts(temp, " Order allow,deny\n");
1421
1422 if (remote_admin)
1423 cupsFilePrintf(temp, " Allow %s\n",
1424 remote_any > 0 ? "all" : "@LOCAL");
1425 else
1426 cupsFilePuts(temp, " Allow localhost\n");
1427 }
1428 else if (in_conf_location && remote_admin >= 0)
1429 {
1430 wrote_conf_location = 1;
1431
1432 if (remote_admin)
1433 cupsFilePuts(temp, " # Allow remote access to the configuration "
1434 "files...\n");
1435 else
1436 cupsFilePuts(temp, " # Restrict access to the configuration "
1437 "files...\n");
1438
1439 cupsFilePuts(temp, " Order allow,deny\n");
1440
1441 if (remote_admin)
1442 cupsFilePrintf(temp, " Allow %s\n",
1443 remote_any > 0 ? "all" : "@LOCAL");
1444 else
1445 cupsFilePuts(temp, " Allow localhost\n");
1446 }
1447 else if (in_root_location && (remote_admin >= 0 || share_printers >= 0))
1448 {
1449 wrote_root_location = 1;
1450
1451 if (remote_admin > 0 && share_printers > 0)
1452 cupsFilePuts(temp, " # Allow shared printing and remote "
1453 "administration...\n");
1454 else if (remote_admin > 0)
1455 cupsFilePuts(temp, " # Allow remote administration...\n");
1456 else if (share_printers > 0)
1457 cupsFilePuts(temp, " # Allow shared printing...\n");
1458 else
1459 cupsFilePuts(temp, " # Restrict access to the server...\n");
1460
1461 cupsFilePuts(temp, " Order allow,deny\n");
1462
1463 if (remote_admin > 0 || share_printers > 0)
1464 cupsFilePrintf(temp, " Allow %s\n",
1465 remote_any > 0 ? "all" : "@LOCAL");
1466 else
1467 cupsFilePuts(temp, " Allow localhost\n");
1468 }
1469
1470 in_admin_location = 0;
1471 in_conf_location = 0;
1472 in_root_location = 0;
1473
1474 cupsFilePuts(temp, "</Location>\n");
1475 }
1476 else if (!strcasecmp(line, "<Limit") && in_default_policy)
1477 {
1478 /*
1479 * See if the policy limit is for the Cancel-Job operation...
1480 */
1481
1482 char *valptr; /* Pointer into value */
1483
1484
1485 indent += 2;
1486
1487 if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
1488 {
1489 /*
1490 * Don't write anything for this limit section...
1491 */
1492
1493 in_cancel_job = 2;
1494 }
1495 else
1496 {
1497 cupsFilePrintf(temp, " %s", line);
1498
1499 while (*value)
1500 {
1501 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
1502
1503 if (*valptr)
1504 *valptr++ = '\0';
1505
1506 if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
1507 {
1508 /*
1509 * Write everything except for this definition...
1510 */
1511
1512 in_cancel_job = 1;
1513 }
1514 else
1515 cupsFilePrintf(temp, " %s", value);
1516
1517 for (value = valptr; isspace(*value & 255); value ++);
1518 }
1519
1520 cupsFilePuts(temp, ">\n");
1521 }
1522 }
1523 else if (!strcasecmp(line, "</Limit>") && in_cancel_job)
1524 {
1525 indent -= 2;
1526
1527 if (in_cancel_job == 1)
1528 cupsFilePuts(temp, " </Limit>\n");
1529
1530 wrote_policy = 1;
1531
1532 if (!user_cancel_any)
1533 cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
1534 "a job...\n"
1535 " <Limit Cancel-Job>\n"
1536 " Order deny,allow\n"
1537 " Require user @OWNER @SYSTEM\n"
1538 " </Limit>\n");
1539
1540 in_cancel_job = 0;
1541 }
1542 else if ((((in_admin_location || in_conf_location || in_root_location) &&
1543 remote_admin >= 0) ||
1544 (in_root_location && share_printers >= 0)) &&
1545 (!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny") ||
1546 !strcasecmp(line, "Order")))
1547 continue;
1548 else if (in_cancel_job == 2)
1549 continue;
1550 else if (!strcasecmp(line, "<Limit") && value)
1551 cupsFilePrintf(temp, " %s %s>\n", line, value);
1552 else if (line[0] == '<')
1553 {
1554 if (value)
1555 {
1556 cupsFilePrintf(temp, "%*s%s %s>\n", indent, "", line, value);
1557 indent += 2;
1558 }
1559 else
1560 {
1561 if (line[1] == '/')
1562 indent -= 2;
1563
1564 cupsFilePrintf(temp, "%*s%s\n", indent, "", line);
1565 }
1566 }
1567 else if (!in_policy && !in_location &&
1568 (val = cupsGetOption(line, num_settings, settings)) != NULL)
1569 {
1570 /*
1571 * Replace this directive's value with the new one...
1572 */
1573
1574 cupsd_num_settings = cupsAddOption(line, val, cupsd_num_settings,
1575 &cupsd_settings);
1576
1577 /*
1578 * Write the new value in its place, without indentation since we
1579 * only support setting root directives, not in sections...
1580 */
1581
1582 cupsFilePrintf(temp, "%s %s\n", line, val);
1583 }
1584 else if (value)
1585 {
1586 if (!in_policy && !in_location)
1587 {
1588 /*
1589 * Record the non-policy, non-location directives that we find
1590 * in the server settings, since we cache this info and record it
1591 * in _cupsAdminGetServerSettings()...
1592 */
1593
1594 cupsd_num_settings = cupsAddOption(line, value, cupsd_num_settings,
1595 &cupsd_settings);
1596 }
1597
1598 cupsFilePrintf(temp, "%*s%s %s\n", indent, "", line, value);
1599 }
1600 else
1601 cupsFilePrintf(temp, "%*s%s\n", indent, "", line);
1602 }
1603
1604 /*
1605 * Write any missing info...
1606 */
1607
1608 if (!wrote_browsing && (remote_printers >= 0 || share_printers >= 0))
1609 {
1610 if (remote_printers > 0 || share_printers > 0)
1611 {
1612 if (remote_printers > 0 && share_printers > 0)
1613 cupsFilePuts(temp, "# Enable printer sharing and shared printers.\n");
1614 else if (remote_printers > 0)
1615 cupsFilePuts(temp, "# Show shared printers on the local network.\n");
1616 else
1617 cupsFilePuts(temp, "# Share local printers on the local network.\n");
1618
1619 cupsFilePuts(temp, "Browsing On\n");
1620 cupsFilePuts(temp, "BrowseOrder allow,deny\n");
1621
1622 if (remote_printers > 0)
1623 cupsFilePuts(temp, "BrowseAllow all\n");
1624
1625 if (share_printers > 0)
1626 cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
1627 }
1628 else
1629 {
1630 cupsFilePuts(temp, "# Disable printer sharing and shared printers.\n");
1631 cupsFilePuts(temp, "Browsing Off\n");
1632 }
1633 }
1634
1635 if (!wrote_loglevel && debug_logging >= 0)
1636 {
1637 if (debug_logging)
1638 {
1639 cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n");
1640 cupsFilePuts(temp, "LogLevel debug\n");
1641 }
1642 else
1643 {
1644 cupsFilePuts(temp, "# Show general information in error_log.\n");
1645 cupsFilePuts(temp, "LogLevel info\n");
1646 }
1647 }
1648
1649 if (!wrote_port_listen && (share_printers >= 0 || remote_admin >= 0))
1650 {
1651 if (share_printers > 0 || remote_admin > 0)
1652 {
1653 cupsFilePuts(temp, "# Allow remote access\n");
1654 cupsFilePrintf(temp, "Port %d\n", ippPort());
1655 }
1656 else
1657 {
1658 cupsFilePuts(temp,
1659 "# Only listen for connections from the local machine.\n");
1660 cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
1661 }
1662
1663 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1664 if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0))
1665 cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
1666 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1667 }
1668
1669 if (!wrote_root_location && (remote_admin >= 0 || share_printers >= 0))
1670 {
1671 if (remote_admin > 0 && share_printers > 0)
1672 cupsFilePuts(temp,
1673 "# Allow shared printing and remote administration...\n");
1674 else if (remote_admin > 0)
1675 cupsFilePuts(temp, "# Allow remote administration...\n");
1676 else if (share_printers > 0)
1677 cupsFilePuts(temp, "# Allow shared printing...\n");
1678 else
1679 cupsFilePuts(temp, "# Restrict access to the server...\n");
1680
1681 cupsFilePuts(temp, "<Location />\n"
1682 " Order allow,deny\n");
1683
1684 if (remote_admin > 0 || share_printers > 0)
1685 cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL");
1686 else
1687 cupsFilePuts(temp, " Allow localhost\n");
1688
1689 cupsFilePuts(temp, "</Location>\n");
1690 }
1691
1692 if (!wrote_admin_location && remote_admin >= 0)
1693 {
1694 if (remote_admin)
1695 cupsFilePuts(temp, "# Allow remote administration...\n");
1696 else
1697 cupsFilePuts(temp, "# Restrict access to the admin pages...\n");
1698
1699 cupsFilePuts(temp, "<Location /admin>\n"
1700 " Order allow,deny\n");
1701
1702 if (remote_admin)
1703 cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL");
1704 else
1705 cupsFilePuts(temp, " Allow localhost\n");
1706
1707 cupsFilePuts(temp, "</Location>\n");
1708 }
1709
1710 if (!wrote_conf_location && remote_admin >= 0)
1711 {
1712 if (remote_admin)
1713 cupsFilePuts(temp,
1714 "# Allow remote access to the configuration files...\n");
1715 else
1716 cupsFilePuts(temp, "# Restrict access to the configuration files...\n");
1717
1718 cupsFilePuts(temp, "<Location /admin/conf>\n"
1719 " AuthType Basic\n"
1720 " Require user @SYSTEM\n"
1721 " Order allow,deny\n");
1722
1723 if (remote_admin)
1724 cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL");
1725 else
1726 cupsFilePuts(temp, " Allow localhost\n");
1727
1728 cupsFilePuts(temp, "</Location>\n");
1729 }
1730
1731 if (!wrote_policy && user_cancel_any >= 0)
1732 {
1733 cupsFilePuts(temp, "<Policy default>\n"
1734 " # Job-related operations must be done by the owner "
1735 "or an adminstrator...\n"
1736 " <Limit Send-Document Send-URI Hold-Job Release-Job "
1737 "Restart-Job Purge-Jobs Set-Job-Attributes "
1738 "Create-Job-Subscription Renew-Subscription "
1739 "Cancel-Subscription Get-Notifications Reprocess-Job "
1740 "Cancel-Current-Job Suspend-Current-Job Resume-Job "
1741 "CUPS-Move-Job>\n"
1742 " Require user @OWNER @SYSTEM\n"
1743 " Order deny,allow\n"
1744 " </Limit>\n"
1745 " # All administration operations require an "
1746 "adminstrator to authenticate...\n"
1747 " <Limit Pause-Printer Resume-Printer "
1748 "Set-Printer-Attributes Enable-Printer "
1749 "Disable-Printer Pause-Printer-After-Current-Job "
1750 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
1751 "Activate-Printer Restart-Printer Shutdown-Printer "
1752 "Startup-Printer Promote-Job Schedule-Job-After "
1753 "CUPS-Add-Printer CUPS-Delete-Printer "
1754 "CUPS-Add-Class CUPS-Delete-Class "
1755 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
1756 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>\n"
1757 " AuthType Basic\n"
1758 " Require user @SYSTEM\n"
1759 " Order deny,allow\n"
1760 "</Limit>\n");
1761
1762 if (!user_cancel_any)
1763 cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
1764 "a job...\n"
1765 " <Limit Cancel-Job>\n"
1766 " Require user @OWNER @SYSTEM\n"
1767 " Order deny,allow\n"
1768 " </Limit>\n");
1769
1770 cupsFilePuts(temp, " <Limit All>\n"
1771 " Order deny,allow\n"
1772 " </Limit>\n"
1773 "</Policy>\n");
1774 }
1775
1776 for (i = num_settings, setting = settings; i > 0; i --, setting ++)
1777 if (setting->name[0] != '_' &&
1778 !cupsGetOption(setting->name, cupsd_num_settings, cupsd_settings))
1779 {
1780 /*
1781 * Add this directive to the list of directives we have written...
1782 */
1783
1784 cupsd_num_settings = cupsAddOption(setting->name, setting->value,
1785 cupsd_num_settings, &cupsd_settings);
1786
1787 /*
1788 * Write the new value, without indentation since we only support
1789 * setting root directives, not in sections...
1790 */
1791
1792 cupsFilePrintf(temp, "%s %s\n", setting->name, setting->value);
1793 }
1794
1795 cupsFileClose(cupsd);
1796 cupsFileClose(temp);
1797
1798 /*
1799 * Upload the configuration file to the server...
1800 */
1801
1802 status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
1803
1804 if (status == HTTP_CREATED)
1805 {
1806 /*
1807 * Updated OK, add the basic settings...
1808 */
1809
1810 if (debug_logging >= 0)
1811 cupsd_num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
1812 debug_logging ? "1" : "0",
1813 cupsd_num_settings, &cupsd_settings);
1814 else
1815 cupsd_num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
1816 old_debug_logging ? "1" : "0",
1817 cupsd_num_settings, &cupsd_settings);
1818
1819 if (remote_admin >= 0)
1820 cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
1821 remote_admin ? "1" : "0",
1822 cupsd_num_settings, &cupsd_settings);
1823 else
1824 cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
1825 old_remote_admin ? "1" : "0",
1826 cupsd_num_settings, &cupsd_settings);
1827
1828 cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY,
1829 remote_any ? "1" : "0",
1830 cupsd_num_settings, &cupsd_settings);
1831
1832 if (remote_printers >= 0)
1833 cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
1834 remote_printers ? "1" : "0",
1835 cupsd_num_settings, &cupsd_settings);
1836 else
1837 cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
1838 old_remote_printers ? "1" : "0",
1839 cupsd_num_settings, &cupsd_settings);
1840
1841 if (share_printers >= 0)
1842 cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
1843 share_printers ? "1" : "0",
1844 cupsd_num_settings, &cupsd_settings);
1845 else
1846 cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
1847 old_share_printers ? "1" : "0",
1848 cupsd_num_settings, &cupsd_settings);
1849
1850 if (user_cancel_any >= 0)
1851 cupsd_num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
1852 user_cancel_any ? "1" : "0",
1853 cupsd_num_settings, &cupsd_settings);
1854 else
1855 cupsd_num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
1856 old_user_cancel_any ? "1" : "0",
1857 cupsd_num_settings, &cupsd_settings);
1858
1859 /*
1860 * Save the new values...
1861 */
1862
1863 invalidate_cupsd_cache(cg);
1864
1865 cg->cupsd_num_settings = cupsd_num_settings;
1866 cg->cupsd_settings = cupsd_settings;
1867 cg->cupsd_update = time(NULL);
1868
1869 httpGetHostname(http, cg->cupsd_hostname, sizeof(cg->cupsd_hostname));
1870 }
1871 else
1872 cupsFreeOptions(cupsd_num_settings, cupsd_settings);
1873
1874 /*
1875 * Remote our temp files and return...
1876 */
1877
1878 if (remote)
1879 unlink(cupsdconf);
1880
1881 unlink(tempfile);
1882
1883 return (status == HTTP_CREATED);
1884 }
1885
1886
1887 /*
1888 * 'do_samba_command()' - Do a SAMBA command.
1889 */
1890
1891 static int /* O - Status of command */
1892 do_samba_command(const char *command, /* I - Command to run */
1893 const char *address, /* I - Address for command */
1894 const char *subcmd, /* I - Sub-command */
1895 const char *authfile, /* I - Samba authentication file */
1896 FILE *logfile) /* I - Optional log file */
1897 {
1898 #ifdef WIN32
1899 return (1); /* Always fail on Windows... */
1900
1901 #else
1902 int status; /* Status of command */
1903 int pid; /* Process ID of child */
1904
1905
1906 if (logfile)
1907 _cupsLangPrintf(logfile,
1908 _("Running command: %s %s -N -A %s -c \'%s\'\n"),
1909 command, address, authfile, subcmd);
1910
1911 if ((pid = fork()) == 0)
1912 {
1913 /*
1914 * Child goes here, redirect stdin/out/err and execute the command...
1915 */
1916
1917 close(0);
1918 open("/dev/null", O_RDONLY);
1919
1920 close(1);
1921
1922 if (logfile)
1923 dup(fileno(logfile));
1924 else
1925 open("/dev/null", O_WRONLY);
1926
1927 close(2);
1928 dup(1);
1929
1930 execlp(command, command, address, "-N", "-A", authfile, "-c", subcmd,
1931 (char *)0);
1932 exit(errno);
1933 }
1934 else if (pid < 0)
1935 {
1936 status = -1;
1937
1938 if (logfile)
1939 _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"),
1940 command, strerror(errno));
1941 }
1942 else
1943 {
1944 /*
1945 * Wait for the process to complete...
1946 */
1947
1948 while (wait(&status) != pid);
1949 }
1950
1951 if (logfile)
1952 _cupsLangPuts(logfile, "\n");
1953
1954 DEBUG_printf(("status=%d\n", status));
1955
1956 if (WIFEXITED(status))
1957 return (WEXITSTATUS(status));
1958 else
1959 return (-WTERMSIG(status));
1960 #endif /* WIN32 */
1961 }
1962
1963
1964 /*
1965 * 'get_cupsd_conf()' - Get the current cupsd.conf file.
1966 */
1967
1968 static http_status_t /* O - Status of request */
1969 get_cupsd_conf(
1970 http_t *http, /* I - Connection to server */
1971 _cups_globals_t *cg, /* I - Global data */
1972 time_t last_update, /* I - Last update time for file */
1973 char *name, /* I - Filename buffer */
1974 int namesize, /* I - Size of filename buffer */
1975 int *remote) /* O - Remote file? */
1976 {
1977 int fd; /* Temporary file descriptor */
1978 #ifndef WIN32
1979 struct stat info; /* cupsd.conf file information */
1980 #endif /* WIN32 */
1981 http_status_t status; /* Status of getting cupsd.conf */
1982 char host[HTTP_MAX_HOST]; /* Hostname for connection */
1983
1984
1985 /*
1986 * See if we already have the data we need...
1987 */
1988
1989 httpGetHostname(http, host, sizeof(host));
1990
1991 if (strcasecmp(cg->cupsd_hostname, host))
1992 invalidate_cupsd_cache(cg);
1993
1994 snprintf(name, namesize, "%s/cupsd.conf", cg->cups_serverroot);
1995 *remote = 0;
1996
1997 #ifndef WIN32
1998 if (!strcasecmp(host, "localhost") && !access(name, R_OK))
1999 {
2000 /*
2001 * Read the local file rather than using HTTP...
2002 */
2003
2004 if (stat(name, &info))
2005 {
2006 char message[1024]; /* Message string */
2007
2008
2009 snprintf(message, sizeof(message),
2010 _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
2011 name, strerror(errno));
2012 _cupsSetError(IPP_INTERNAL_ERROR, message);
2013
2014 *name = '\0';
2015
2016 return (HTTP_SERVER_ERROR);
2017 }
2018 else if (last_update && info.st_mtime <= last_update)
2019 status = HTTP_NOT_MODIFIED;
2020 else
2021 status = HTTP_OK;
2022 }
2023 else
2024 #endif /* !WIN32 */
2025 {
2026 /*
2027 * Read cupsd.conf via a HTTP GET request...
2028 */
2029
2030 if ((fd = cupsTempFd(name, namesize)) < 0)
2031 {
2032 *name = '\0';
2033
2034 _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
2035
2036 invalidate_cupsd_cache(cg);
2037
2038 return (HTTP_SERVER_ERROR);
2039 }
2040
2041 *remote = 1;
2042
2043 httpClearFields(http);
2044
2045 if (last_update)
2046 httpSetField(http, HTTP_FIELD_IF_MODIFIED_SINCE,
2047 httpGetDateString(last_update));
2048
2049 status = cupsGetFd(http, "/admin/conf/cupsd.conf", fd);
2050
2051 close(fd);
2052
2053 if (status != HTTP_OK)
2054 {
2055 unlink(name);
2056 *name = '\0';
2057 }
2058 }
2059
2060 return (status);
2061 }
2062
2063
2064 /*
2065 * 'invalidate_cupsd_cache()' - Invalidate the cached cupsd.conf settings.
2066 */
2067
2068 static void
2069 invalidate_cupsd_cache(
2070 _cups_globals_t *cg) /* I - Global data */
2071 {
2072 cupsFreeOptions(cg->cupsd_num_settings, cg->cupsd_settings);
2073
2074 cg->cupsd_hostname[0] = '\0';
2075 cg->cupsd_update = 0;
2076 cg->cupsd_num_settings = 0;
2077 cg->cupsd_settings = NULL;
2078 }
2079
2080
2081 /*
2082 * 'write_option()' - Write a CUPS option to a PPD file.
2083 */
2084
2085 static void
2086 write_option(cups_file_t *dstfp, /* I - PPD file */
2087 int order, /* I - Order dependency */
2088 const char *name, /* I - Option name */
2089 const char *text, /* I - Option text */
2090 const char *attrname, /* I - Attribute name */
2091 ipp_attribute_t *suppattr, /* I - IPP -supported attribute */
2092 ipp_attribute_t *defattr, /* I - IPP -default attribute */
2093 int defval, /* I - Default value number */
2094 int valcount) /* I - Number of values */
2095 {
2096 int i; /* Looping var */
2097
2098
2099 cupsFilePrintf(dstfp, "*JCLOpenUI *%s/%s: PickOne\n"
2100 "*OrderDependency: %d JCLSetup *%s\n",
2101 name, text, order, name);
2102
2103 if (defattr->value_tag == IPP_TAG_INTEGER)
2104 {
2105 /*
2106 * Do numeric options with a range or list...
2107 */
2108
2109 cupsFilePrintf(dstfp, "*Default%s: %d\n", name,
2110 defattr->values[defval].integer);
2111
2112 if (suppattr->value_tag == IPP_TAG_RANGE)
2113 {
2114 /*
2115 * List each number in the range...
2116 */
2117
2118 for (i = suppattr->values[0].range.lower;
2119 i <= suppattr->values[0].range.upper;
2120 i ++)
2121 {
2122 cupsFilePrintf(dstfp, "*%s %d: \"", name, i);
2123
2124 if (valcount == 1)
2125 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\n\"\n*End\n",
2126 attrname, i);
2127 else if (defval == 0)
2128 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\"\n", attrname, i);
2129 else if (defval < (valcount - 1))
2130 cupsFilePrintf(dstfp, ",%d\"\n", i);
2131 else
2132 cupsFilePrintf(dstfp, ",%d\n\"\n*End\n", i);
2133 }
2134 }
2135 else
2136 {
2137 /*
2138 * List explicit numbers...
2139 */
2140
2141 for (i = 0; i < suppattr->num_values; i ++)
2142 {
2143 cupsFilePrintf(dstfp, "*%s %d: \"", name, suppattr->values[i].integer);
2144
2145 if (valcount == 1)
2146 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\n\"\n*End\n", attrname,
2147 suppattr->values[i].integer);
2148 else if (defval == 0)
2149 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\"\n", attrname,
2150 suppattr->values[i].integer);
2151 else if (defval < (valcount - 1))
2152 cupsFilePrintf(dstfp, ",%d\"\n", suppattr->values[i].integer);
2153 else
2154 cupsFilePrintf(dstfp, ",%d\n\"\n*End\n", suppattr->values[i].integer);
2155 }
2156 }
2157 }
2158 else
2159 {
2160 /*
2161 * Do text options with a list...
2162 */
2163
2164 cupsFilePrintf(dstfp, "*Default%s: %s\n", name,
2165 defattr->values[defval].string.text);
2166
2167 for (i = 0; i < suppattr->num_values; i ++)
2168 {
2169 cupsFilePrintf(dstfp, "*%s %s: \"", name,
2170 suppattr->values[i].string.text);
2171
2172 if (valcount == 1)
2173 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%s\n\"\n*End\n", attrname,
2174 suppattr->values[i].string.text);
2175 else if (defval == 0)
2176 cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%s\"\n", attrname,
2177 suppattr->values[i].string.text);
2178 else if (defval < (valcount - 1))
2179 cupsFilePrintf(dstfp, ",%s\"\n", suppattr->values[i].string.text);
2180 else
2181 cupsFilePrintf(dstfp, ",%s\n\"\n*End\n",
2182 suppattr->values[i].string.text);
2183 }
2184 }
2185
2186 cupsFilePrintf(dstfp, "*JCLCloseUI: *%s\n\n", name);
2187 }
2188
2189
2190 /*
2191 * End of "$Id: adminutil.c 6361 2007-03-19 16:01:28Z mike $".
2192 */