2 * "$Id: adminutil.c 5878 2006-08-24 15:55:42Z mike $"
4 * Administration utility API definitions for the Common UNIX Printing
7 * MANY OF THE FUNCTIONS IN THIS HEADER ARE PRIVATE AND SUBJECT TO
8 * CHANGE AT ANY TIME. USE AT YOUR OWN RISK.
10 * Copyright 2001-2006 by Easy Software Products.
12 * These coded instructions, statements, and computer programs are the
13 * property of Easy Software Products and are protected by Federal
14 * copyright law. Distribution and use rights are outlined in the file
15 * "LICENSE.txt" which should have been included with this file. If this
16 * file is missing or damaged please contact Easy Software Products
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636 USA
24 * Voice: (301) 373-9600
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
28 * This file is subject to the Apple OS-Developed Software exception.
32 * cupsAdminCreateWindowsPPD() - Create the Windows PPD file for a printer.
33 * cupsAdminExportSamba() - Export a printer to Samba.
34 * _cupsAdminGetServerSettings() - Get settings from the server.
35 * _cupsAdminSetServerSettings() - Set settings on the server.
36 * do_samba_command() - Do a SAMBA command.
37 * get_cupsd_conf() - Get the current cupsd.conf file.
38 * invalidate_cupsd_cache() - Invalidate the cached cupsd.conf settings.
39 * write_option() - Write a CUPS option to a PPD file.
43 * Include necessary headers...
46 #include "adminutil.h"
60 static int do_samba_command(const char *command
,
62 const char *subcommand
,
65 static http_status_t
get_cupsd_conf(http_t
*http
, _cups_globals_t
*cg
,
66 time_t last_update
, char *name
,
67 int namelen
, int *remote
);
68 static void invalidate_cupsd_cache(_cups_globals_t
*cg
);
69 static void write_option(cups_file_t
*dstfp
, int order
,
70 const char *name
, const char *text
,
72 ipp_attribute_t
*suppattr
,
73 ipp_attribute_t
*defattr
, int defval
,
78 * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
81 char * /* O - PPD file or NULL */
82 cupsAdminCreateWindowsPPD(
83 http_t
*http
, /* I - Connection to server */
84 const char *dest
, /* I - Printer or class */
85 char *buffer
, /* I - Filename buffer */
86 int bufsize
) /* I - Size of filename buffer */
88 const char *src
; /* Source PPD filename */
89 cups_file_t
*srcfp
, /* Source PPD file */
90 *dstfp
; /* Destination PPD file */
91 ipp_t
*request
, /* IPP request */
92 *response
; /* IPP response */
93 ipp_attribute_t
*suppattr
, /* IPP -supported attribute */
94 *defattr
; /* IPP -default attribute */
95 cups_lang_t
*language
; /* Current language */
96 char line
[256], /* Line from PPD file */
97 junk
[256], /* Extra junk to throw away */
98 *ptr
, /* Pointer into line */
99 uri
[1024], /* Printer URI */
100 option
[41], /* Option */
101 choice
[41]; /* Choice */
102 int jcloption
, /* In a JCL option? */
103 linenum
; /* Current line number */
104 time_t curtime
; /* Current time */
105 struct tm
*curdate
; /* Current date */
106 static const char * const pattrs
[] = /* Printer attributes we want */
108 "job-hold-until-supported",
109 "job-hold-until-default",
110 "job-sheets-supported",
111 "job-sheets-default",
112 "job-priority-supported",
113 "job-priority-default"
118 * Range check the input...
124 if (!http
|| !dest
|| !buffer
|| bufsize
< 2)
128 * Get the PPD file...
131 if ((src
= cupsGetPPD2(http
, dest
)) == NULL
)
135 * Get the supported banner pages, etc. for the printer...
138 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
140 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
141 "localhost", 0, "/printers/%s", dest
);
142 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
143 "printer-uri", NULL
, uri
);
145 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
146 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
150 * Do the request and get back a response...
153 response
= cupsDoRequest(http
, request
, "/");
154 if (!response
|| cupsLastError() > IPP_OK_CONFLICT
)
161 * Open the original PPD file...
164 if ((srcfp
= cupsFileOpen(src
, "rb")) == NULL
)
168 * Create a temporary output file using the destination buffer...
171 if ((dstfp
= cupsTempFile2(buffer
, bufsize
)) == NULL
)
173 cupsFileClose(srcfp
);
181 * Write a new header explaining that this isn't the original PPD...
184 cupsFilePuts(dstfp
, "*PPD-Adobe: \"4.3\"\n");
186 curtime
= time(NULL
);
187 curdate
= gmtime(&curtime
);
189 cupsFilePrintf(dstfp
, "*%% Modified on %04d%02d%02d%02d%02d%02d+0000 "
190 "for CUPS Windows Driver\n",
191 curdate
->tm_year
+ 1900, curdate
->tm_mon
+ 1, curdate
->tm_mday
,
192 curdate
->tm_hour
, curdate
->tm_min
, curdate
->tm_sec
);
195 * Read the existing PPD file, converting all PJL commands to CUPS
196 * job ticket comments...
201 language
= cupsLangDefault();
203 while (cupsFileGets(srcfp
, line
, sizeof(line
)))
207 if (!strncmp(line
, "*PPD-Adobe:", 11))
210 * Already wrote the PPD header...
215 else if (!strncmp(line
, "*JCLBegin:", 10) ||
216 !strncmp(line
, "*JCLToPSInterpreter:", 20) ||
217 !strncmp(line
, "*JCLEnd:", 8) ||
218 !strncmp(line
, "*Protocols:", 11))
221 * Don't use existing JCL keywords; we'll create our own, below...
224 cupsFilePrintf(dstfp
, "*%% Commented out for CUPS Windows Driver...\n"
225 "*%%%s\n", line
+ 1);
228 else if (!strncmp(line
, "*JCLOpenUI", 10))
231 cupsFilePrintf(dstfp
, "%s\n", line
);
233 else if (!strncmp(line
, "*JCLCloseUI", 11))
236 cupsFilePrintf(dstfp
, "%s\n", line
);
238 else if (jcloption
&&
239 strncmp(line
, "*End", 4) &&
240 strncmp(line
, "*Default", 8) &&
241 strncmp(line
, "*OrderDependency", 16))
243 if ((ptr
= strchr(line
, ':')) == NULL
)
245 snprintf(line
, sizeof(line
),
246 _cupsLangString(language
, _("Missing value on line %d!\n")),
248 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR
, line
);
250 cupsFileClose(srcfp
);
251 cupsFileClose(dstfp
);
261 if ((ptr
= strchr(ptr
, '\"')) == NULL
)
263 snprintf(line
, sizeof(line
),
264 _cupsLangString(language
,
265 _("Missing double quote on line %d!\n")),
267 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR
, line
);
269 cupsFileClose(srcfp
);
270 cupsFileClose(dstfp
);
280 if (sscanf(line
, "*%40s%*[ \t]%40[^/]", option
, choice
) != 2)
282 snprintf(line
, sizeof(line
),
283 _cupsLangString(language
,
284 _("Bad option + choice on line %d!\n")),
286 _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR
, line
);
288 cupsFileClose(srcfp
);
289 cupsFileClose(dstfp
);
299 if (strchr(ptr
+ 1, '\"') == NULL
)
305 while (cupsFileGets(srcfp
, junk
, sizeof(junk
)) != NULL
)
309 if (!strncmp(junk
, "*End", 4))
314 snprintf(ptr
+ 1, sizeof(line
) - (ptr
- line
+ 1),
315 "%%cupsJobTicket: %s=%s\n\"\n*End", option
, choice
);
317 cupsFilePrintf(dstfp
, "*%% Changed for CUPS Windows Driver...\n%s\n",
321 cupsFilePrintf(dstfp
, "%s\n", line
);
324 cupsFileClose(srcfp
);
328 * Now add the CUPS-specific attributes and options...
331 cupsFilePuts(dstfp
, "\n*% CUPS Job Ticket support and options...\n");
332 cupsFilePuts(dstfp
, "*Protocols: PJL\n");
333 cupsFilePuts(dstfp
, "*JCLBegin: \"%!PS-Adobe-3.0<0A>\"\n");
334 cupsFilePuts(dstfp
, "*JCLToPSInterpreter: \"\"\n");
335 cupsFilePuts(dstfp
, "*JCLEnd: \"\"\n");
337 cupsFilePuts(dstfp
, "\n*OpenGroup: CUPS/CUPS Options\n\n");
339 if ((defattr
= ippFindAttribute(response
, "job-hold-until-default",
340 IPP_TAG_ZERO
)) != NULL
&&
341 (suppattr
= ippFindAttribute(response
, "job-hold-until-supported",
342 IPP_TAG_ZERO
)) != NULL
)
343 write_option(dstfp
, 10, "cupsJobHoldUntil", "Hold Until", "job-hold-until",
344 suppattr
, defattr
, 0, 1);
346 if ((defattr
= ippFindAttribute(response
, "job-priority-default",
347 IPP_TAG_INTEGER
)) != NULL
&&
348 (suppattr
= ippFindAttribute(response
, "job-priority-supported",
349 IPP_TAG_RANGE
)) != NULL
)
350 write_option(dstfp
, 11, "cupsJobPriority", "Priority", "job-priority",
351 suppattr
, defattr
, 0, 1);
353 if ((defattr
= ippFindAttribute(response
, "job-sheets-default",
354 IPP_TAG_ZERO
)) != NULL
&&
355 (suppattr
= ippFindAttribute(response
, "job-sheets-supported",
356 IPP_TAG_ZERO
)) != NULL
)
358 write_option(dstfp
, 20, "cupsJobSheetsStart", "Start Banner",
359 "job-sheets", suppattr
, defattr
, 0, 2);
360 write_option(dstfp
, 21, "cupsJobSheetsEnd", "End Banner",
361 "job-sheets", suppattr
, defattr
, 1, 2);
364 cupsFilePuts(dstfp
, "*CloseGroup: CUPS\n");
365 cupsFileClose(dstfp
);
374 * 'cupsAdminExportSamba()' - Export a printer to Samba.
377 int /* O - 1 on success, 0 on failure */
378 cupsAdminExportSamba(
379 const char *dest
, /* I - Destination to export */
380 const char *ppd
, /* I - PPD file */
381 const char *samba_server
, /* I - Samba server */
382 const char *samba_user
, /* I - Samba username */
383 const char *samba_password
, /* I - Samba password */
384 FILE *logfile
) /* I - Log file, if any */
386 int status
; /* Status of Samba commands */
387 int have_drivers
; /* Have drivers? */
388 char file
[1024], /* File to test for */
389 authfile
[1024], /* Temporary authentication file */
390 address
[1024], /* Address for command */
391 subcmd
[1024], /* Sub-command */
392 message
[1024]; /* Error message */
393 cups_file_t
*fp
; /* Authentication file */
394 cups_lang_t
*language
; /* Current language */
395 _cups_globals_t
*cg
= _cupsGlobals();
400 * Range check input...
403 if (!dest
|| !ppd
|| !samba_server
|| !samba_user
|| !samba_password
)
405 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
410 * Create a temporary authentication file for Samba...
413 if ((fp
= cupsTempFile2(authfile
, sizeof(authfile
))) == NULL
)
415 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
419 cupsFilePrintf(fp
, "username = %s\n", samba_user
);
420 cupsFilePrintf(fp
, "password = %s\n", samba_password
);
424 * See which drivers are available; the new CUPS v6 and Adobe drivers
425 * depend on the Windows 2k PS driver, so copy that driver first:
436 language
= cupsLangDefault();
438 snprintf(file
, sizeof(file
), "%s/drivers/pscript5.dll", cg
->cups_datadir
);
439 if (!access(file
, 0))
444 * Windows 2k driver is installed; do the smbclient commands needed
445 * to copy the Win2k drivers over...
448 snprintf(address
, sizeof(address
), "//%s/print$", samba_server
);
450 snprintf(subcmd
, sizeof(subcmd
),
452 "put %s W32X86/%s.ppd;"
453 "put %s/drivers/ps5ui.dll W32X86/ps5ui.dll;"
454 "put %s/drivers/pscript.hlp W32X86/pscript.hlp;"
455 "put %s/drivers/pscript.ntf W32X86/pscript.ntf;"
456 "put %s/drivers/pscript5.dll W32X86/pscript5.dll",
457 ppd
, dest
, cg
->cups_datadir
, cg
->cups_datadir
,
458 cg
->cups_datadir
, cg
->cups_datadir
);
460 if ((status
= do_samba_command("smbclient", address
, subcmd
,
461 authfile
, logfile
)) != 0)
463 snprintf(message
, sizeof(message
),
464 _cupsLangString(language
,
465 _("Unable to copy Windows 2000 printer "
466 "driver files (%d)!")), status
);
468 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
471 _cupsLangPrintf(logfile
, "%s\n", message
);
479 * See if we also have the CUPS driver files; if so, use them!
482 snprintf(file
, sizeof(file
), "%s/drivers/cupsps6.dll", cg
->cups_datadir
);
483 if (!access(file
, 0))
486 * Copy the CUPS driver files over...
489 snprintf(subcmd
, sizeof(subcmd
),
490 "put %s/drivers/cups6.ini W32X86/cups6.ini;"
491 "put %s/drivers/cupsps6.dll W32X86/cupsps6.dll;"
492 "put %s/drivers/cupsui6.dll W32X86/cupsui6.dll",
493 cg
->cups_datadir
, cg
->cups_datadir
, cg
->cups_datadir
);
495 if ((status
= do_samba_command("smbclient", address
, subcmd
,
496 authfile
, logfile
)) != 0)
498 snprintf(message
, sizeof(message
),
499 _cupsLangString(language
,
500 _("Unable to copy CUPS printer driver "
501 "files (%d)!")), status
);
503 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
506 _cupsLangPrintf(logfile
, "%s\n", message
);
514 * Do the rpcclient command needed for the CUPS drivers...
517 snprintf(subcmd
, sizeof(subcmd
),
518 "adddriver \"Windows NT x86\" \"%s:"
519 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
520 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
521 "cups6.ini,cupsps6.dll,cupsui6.dll\"",
527 * Don't have the CUPS drivers, so just use the standard Windows
531 snprintf(subcmd
, sizeof(subcmd
),
532 "adddriver \"Windows NT x86\" \"%s:"
533 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
534 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
538 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
539 authfile
, logfile
)) != 0)
541 snprintf(message
, sizeof(message
),
542 _cupsLangString(language
,
543 _("Unable to install Windows 2000 printer "
544 "driver files (%d)!")), status
);
546 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
549 _cupsLangPrintf(logfile
, "%s\n", message
);
557 snprintf(file
, sizeof(file
), "%s/drivers/ADOBEPS4.DRV", cg
->cups_datadir
);
558 if (!access(file
, 0))
563 * Do the smbclient commands needed for the Adobe Win9x drivers...
566 snprintf(address
, sizeof(address
), "//%s/print$", samba_server
);
568 snprintf(subcmd
, sizeof(subcmd
),
570 "put %s WIN40/%s.PPD;"
571 "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
572 "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
573 "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
574 "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
575 "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
576 ppd
, dest
, cg
->cups_datadir
, cg
->cups_datadir
,
577 cg
->cups_datadir
, cg
->cups_datadir
, cg
->cups_datadir
);
579 if ((status
= do_samba_command("smbclient", address
, subcmd
,
580 authfile
, logfile
)) != 0)
582 snprintf(message
, sizeof(message
),
583 _cupsLangString(language
,
584 _("Unable to copy Windows 9x printer "
585 "driver files (%d)!")), status
);
587 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
590 _cupsLangPrintf(logfile
, "%s\n", message
);
598 * Do the rpcclient commands needed for the Adobe Win9x drivers...
601 snprintf(subcmd
, sizeof(subcmd
),
602 "adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:"
603 "ADOBEPS4.HLP:PSMON.DLL:RAW:"
604 "ADOBEPS4.DRV,%s.PPD,ADOBEPS4.HLP,PSMON.DLL,ADFONTS.MFM,"
608 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
609 authfile
, logfile
)) != 0)
611 snprintf(message
, sizeof(message
),
612 _cupsLangString(language
,
613 _("Unable to install Windows 9x printer "
614 "driver files (%d)!")), status
);
616 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
619 _cupsLangPrintf(logfile
, "%s\n", message
);
627 if (logfile
&& !(have_drivers
& 1))
631 _cupsLangString(language
,
632 _("No Windows printer drivers are installed!")),
636 _cupsLangString(language
,
637 _("Warning, no Windows 2000 printer drivers "
641 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
642 _cupsLangPrintf(logfile
, "%s\n", message
);
645 if (have_drivers
== 0)
649 * Finally, associate the drivers we just added with the queue...
652 snprintf(subcmd
, sizeof(subcmd
), "setdriver %s %s", dest
, dest
);
654 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
655 authfile
, logfile
)) != 0)
657 snprintf(message
, sizeof(message
),
658 _cupsLangString(language
,
659 _("Unable to set Windows printer driver (%d)!\n")),
662 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
665 _cupsLangPrintf(logfile
, "%s\n", message
);
679 * '_cupsAdminGetServerSettings()' - Get settings from the server.
681 * The returned settings should be freed with cupsFreeOptions() when
682 * you are done with them.
687 int /* O - 1 on success, 0 on failure */
688 _cupsAdminGetServerSettings(
689 http_t
*http
, /* I - Connection to server */
690 int *num_settings
, /* O - Number of settings */
691 cups_option_t
**settings
) /* O - Settings */
693 int i
; /* Looping var */
694 cups_file_t
*cupsd
; /* cupsd.conf file */
695 char cupsdconf
[1024]; /* cupsd.conf filename */
696 int remote
; /* Remote cupsd.conf file? */
697 http_status_t status
; /* Status of getting cupsd.conf */
698 char line
[1024], /* Line from cupsd.conf file */
699 *value
; /* Value on line */
700 cups_option_t
*setting
; /* Current setting */
701 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
705 * Range check input...
708 if (!http
|| !num_settings
|| !settings
)
710 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
725 * Get the cupsd.conf file...
728 if ((status
= get_cupsd_conf(http
, cg
, cg
->cupsd_update
, cupsdconf
,
729 sizeof(cupsdconf
), &remote
)) == HTTP_OK
)
731 if ((cupsd
= cupsFileOpen(cupsdconf
, "r")) == NULL
)
733 char message
[1024]; /* Message string */
736 snprintf(message
, sizeof(message
),
737 _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
738 cupsdconf
, strerror(errno
));
739 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
748 * Read the file, keeping track of what settings are enabled...
751 int remote_access
= 0, /* Remote access allowed? */
752 remote_admin
= 0, /* Remote administration allowed? */
753 browsing
= 1, /* Browsing enabled? */
754 browse_allow
= 1, /* Browse address set? */
755 browse_address
= 0, /* Browse address set? */
756 cancel_policy
= 1, /* Cancel-job policy set? */
757 debug_logging
= 0; /* LogLevel debug set? */
758 int linenum
= 0, /* Line number in file */
759 in_location
= 0, /* In a location section? */
760 in_policy
= 0, /* In a policy section? */
761 in_cancel_job
= 0, /* In a cancel-job section? */
762 in_admin_location
= 0; /* In the /admin location? */
765 invalidate_cupsd_cache(cg
);
767 cg
->cupsd_update
= time(NULL
);
768 httpGetHostname(http
, cg
->cupsd_hostname
, sizeof(cg
->cupsd_hostname
));
770 while (cupsFileGetConf(cupsd
, line
, sizeof(line
), &value
, &linenum
))
775 if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
777 char *port
; /* Pointer to port number, if any */
780 if ((port
= strrchr(value
, ':')) != NULL
)
782 else if (isdigit(*value
& 255))
785 * Listen on a port number implies remote access...
792 if (strcasecmp(value
, "localhost") && strcmp(value
, "127.0.0.1")
795 #endif /* AF_LOCAL */
797 && strcmp(value
, "::1")
798 #endif /* AF_INET6 */
802 else if (!strcasecmp(line
, "Browsing"))
804 browsing
= !strcasecmp(value
, "yes") || !strcasecmp(value
, "on") ||
805 !strcasecmp(value
, "true");
807 else if (!strcasecmp(line
, "BrowseAddress"))
811 else if (!strcasecmp(line
, "BrowseAllow"))
815 else if (!strcasecmp(line
, "BrowseOrder"))
817 browse_allow
= !strncasecmp(value
, "deny,", 5);
819 else if (!strcasecmp(line
, "LogLevel"))
821 debug_logging
= !strncasecmp(value
, "debug", 5);
823 else if (!strcasecmp(line
, "<Policy") && !strcasecmp(value
, "default"))
827 else if (!strcasecmp(line
, "</Policy>"))
831 else if (!strcasecmp(line
, "<Limit") && in_policy
)
834 * See if the policy limit is for the Cancel-Job operation...
837 char *valptr
; /* Pointer into value */
842 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
847 if (!strcasecmp(value
, "cancel-job") || !strcasecmp(value
, "all"))
853 for (value
= valptr
; isspace(*value
& 255); value
++);
856 else if (!strcasecmp(line
, "</Limit>"))
860 else if (!strcasecmp(line
, "Require") && in_cancel_job
)
864 else if (!strcasecmp(line
, "<Location"))
866 in_admin_location
= !strcasecmp(value
, "/admin");
869 else if (!strcasecmp(line
, "</Location>"))
871 in_admin_location
= 0;
874 else if (!strcasecmp(line
, "Allow") && in_admin_location
&&
875 strcasecmp(value
, "localhost") && strcasecmp(value
, "127.0.0.1")
878 #endif /* AF_LOCAL */
880 && strcmp(value
, "::1")
881 #endif /* AF_INET6 */
886 else if (line
[0] != '<' && !in_location
&& !in_policy
)
887 cg
->cupsd_num_settings
= cupsAddOption(line
, value
,
888 cg
->cupsd_num_settings
,
889 &(cg
->cupsd_settings
));
892 cupsFileClose(cupsd
);
894 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
,
895 debug_logging
? "1" : "0",
896 cg
->cupsd_num_settings
,
897 &(cg
->cupsd_settings
));
899 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
,
900 (remote_access
&& remote_admin
) ?
902 cg
->cupsd_num_settings
,
903 &(cg
->cupsd_settings
));
905 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS
,
906 (browsing
&& browse_allow
) ?
908 cg
->cupsd_num_settings
,
909 &(cg
->cupsd_settings
));
911 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
,
912 (remote_access
&& browsing
&&
913 browse_address
) ? "1" : "0",
914 cg
->cupsd_num_settings
,
915 &(cg
->cupsd_settings
));
917 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
,
918 cancel_policy
? "1" : "0",
919 cg
->cupsd_num_settings
,
920 &(cg
->cupsd_settings
));
922 else if (status
!= HTTP_NOT_MODIFIED
)
923 invalidate_cupsd_cache(cg
);
926 * Remove any temporary files and copy the settings array...
932 for (i
= cg
->cupsd_num_settings
, setting
= cg
->cupsd_settings
;
935 *num_settings
= cupsAddOption(setting
->name
, setting
->value
,
936 *num_settings
, settings
);
938 return (cg
->cupsd_num_settings
> 0);
943 * '_cupsAdminSetServerSettings()' - Set settings on the server.
948 int /* O - 1 on success, 0 on failure */
949 _cupsAdminSetServerSettings(
950 http_t
*http
, /* I - Connection to server */
951 int num_settings
, /* I - Number of settings */
952 cups_option_t
*settings
) /* I - Settings */
954 int i
; /* Looping var */
955 http_status_t status
; /* GET/PUT status */
956 cups_file_t
*cupsd
; /* cupsd.conf file */
957 char cupsdconf
[1024]; /* cupsd.conf filename */
958 int remote
; /* Remote cupsd.conf file? */
959 char tempfile
[1024]; /* Temporary new cupsd.conf */
960 cups_file_t
*temp
; /* Temporary file */
961 char line
[1024], /* Line from cupsd.conf file */
962 *value
; /* Value on line */
963 int linenum
, /* Line number in file */
964 in_location
, /* In a location section? */
965 in_policy
, /* In a policy section? */
966 in_default_policy
, /* In the default policy section? */
967 in_cancel_job
, /* In a cancel-job section? */
968 in_admin_location
, /* In the /admin location? */
969 in_conf_location
, /* In the /admin/conf location? */
970 in_root_location
; /* In the / location? */
971 const char *val
; /* Setting value */
972 int remote_printers
, /* Show remote printers */
973 share_printers
, /* Share local printers */
974 remote_admin
, /* Remote administration allowed? */
975 user_cancel_any
, /* Cancel-job policy set? */
976 debug_logging
; /* LogLevel debug set? */
977 int wrote_port_listen
, /* Wrote the port/listen lines? */
978 wrote_browsing
, /* Wrote the browsing lines? */
979 wrote_policy
, /* Wrote the policy? */
980 wrote_loglevel
, /* Wrote the LogLevel line? */
981 wrote_admin_location
, /* Wrote the /admin location? */
982 wrote_conf_location
, /* Wrote the /admin/conf location? */
983 wrote_root_location
; /* Wrote the / location? */
984 int indent
; /* Indentation */
985 int cupsd_num_settings
; /* New number of settings */
986 cups_option_t
*cupsd_settings
, /* New settings */
987 *setting
; /* Current setting */
988 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
992 * Range check input...
995 if (!http
|| !num_settings
|| !settings
)
997 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
1003 * Get the cupsd.conf file...
1006 if ((status
= get_cupsd_conf(http
, cg
, 0, cupsdconf
, sizeof(cupsdconf
),
1007 &remote
)) == HTTP_OK
)
1009 if ((cupsd
= cupsFileOpen(cupsdconf
, "r")) == NULL
)
1011 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1019 * Get basic settings...
1022 if ((val
= cupsGetOption(CUPS_SERVER_DEBUG_LOGGING
, num_settings
,
1024 debug_logging
= atoi(val
);
1028 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_ADMIN
, num_settings
,
1030 remote_admin
= atoi(val
);
1034 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS
, num_settings
,
1036 remote_printers
= atoi(val
);
1038 remote_printers
= 1;
1040 if ((val
= cupsGetOption(CUPS_SERVER_SHARE_PRINTERS
, num_settings
,
1042 share_printers
= atoi(val
);
1046 if ((val
= cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY
, num_settings
,
1048 user_cancel_any
= atoi(val
);
1050 user_cancel_any
= 0;
1053 * Create a temporary file for the new cupsd.conf file...
1056 if ((temp
= cupsTempFile2(tempfile
, sizeof(tempfile
))) == NULL
)
1058 cupsFileClose(cupsd
);
1063 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1068 * Copy the old file to the new, making changes along the way...
1071 cupsd_num_settings
= 0;
1072 in_admin_location
= 0;
1074 in_conf_location
= 0;
1075 in_default_policy
= 0;
1078 in_root_location
= 0;
1080 wrote_admin_location
= 0;
1082 wrote_conf_location
= 0;
1085 wrote_port_listen
= 0;
1086 wrote_root_location
= 0;
1089 while (cupsFileGetConf(cupsd
, line
, sizeof(line
), &value
, &linenum
))
1091 if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1093 if (!wrote_port_listen
)
1095 wrote_port_listen
= 1;
1097 if (share_printers
|| remote_admin
)
1099 cupsFilePuts(temp
, "# Allow remote access\n");
1100 cupsFilePrintf(temp
, "Port %d\n", ippPort());
1104 cupsFilePuts(temp
, "# Only listen for connections from the local "
1106 cupsFilePrintf(temp
, "Listen localhost:%d\n", ippPort());
1109 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1110 if (!access(CUPS_DEFAULT_DOMAINSOCKET
, 0))
1111 cupsFilePuts(temp
, "Listen " CUPS_DEFAULT_DOMAINSOCKET
"\n");
1112 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1115 else if (!strcasecmp(line
, "Browsing") ||
1116 !strcasecmp(line
, "BrowseAddress") ||
1117 !strcasecmp(line
, "BrowseAllow") ||
1118 !strcasecmp(line
, "BrowseDeny") ||
1119 !strcasecmp(line
, "BrowseOrder"))
1121 if (!wrote_browsing
)
1125 if (remote_printers
|| share_printers
)
1127 if (remote_printers
&& share_printers
)
1129 "# Enable printer sharing and shared printers.\n");
1130 else if (remote_printers
)
1132 "# Show shared printers on the local network.\n");
1135 "# Share local printers on the local network.\n");
1137 cupsFilePuts(temp
, "Browsing On\n");
1138 cupsFilePuts(temp
, "BrowseOrder allow,deny\n");
1140 if (remote_printers
)
1141 cupsFilePuts(temp
, "BrowseAllow @LOCAL\n");
1144 cupsFilePuts(temp
, "BrowseAddress @LOCAL\n");
1149 "# Disable printer sharing and shared printers.\n");
1150 cupsFilePuts(temp
, "Browsing Off\n");
1154 else if (!strcasecmp(line
, "LogLevel"))
1161 "# Show troubleshooting information in error_log.\n");
1162 cupsFilePuts(temp
, "LogLevel debug\n");
1166 cupsFilePuts(temp
, "# Show general information in error_log.\n");
1167 cupsFilePuts(temp
, "LogLevel info\n");
1170 else if (!strcasecmp(line
, "<Policy"))
1172 in_default_policy
= !strcasecmp(value
, "default");
1175 cupsFilePrintf(temp
, "%s %s>\n", line
, value
);
1178 else if (!strcasecmp(line
, "</Policy>"))
1181 if (!wrote_policy
&& in_default_policy
)
1185 if (!user_cancel_any
)
1186 cupsFilePuts(temp
, " # Only the owner or an administrator can "
1188 " <Limit Cancel-Job>\n"
1189 " Order deny,allow\n"
1196 in_default_policy
= 0;
1198 cupsFilePuts(temp
, "</Policy>\n");
1200 else if (!strcasecmp(line
, "<Location"))
1204 if (!strcmp(value
, "/admin"))
1205 in_admin_location
= 1;
1206 if (!strcmp(value
, "/admin/conf"))
1207 in_conf_location
= 1;
1208 else if (!strcmp(value
, "/"))
1209 in_root_location
= 1;
1211 cupsFilePrintf(temp
, "%s %s>\n", line
, value
);
1213 else if (!strcasecmp(line
, "</Location>"))
1217 if (in_admin_location
)
1219 wrote_admin_location
= 1;
1222 cupsFilePuts(temp
, " # Allow remote administration...\n");
1224 cupsFilePuts(temp
, " # Restrict access to the admin pages...\n");
1226 cupsFilePuts(temp
, " Order allow,deny\n");
1229 cupsFilePuts(temp
, " Allow @LOCAL\n");
1231 cupsFilePuts(temp
, " Allow localhost\n");
1233 else if (in_conf_location
)
1235 wrote_conf_location
= 1;
1238 cupsFilePuts(temp
, " # Allow remote access to the configuration "
1241 cupsFilePuts(temp
, " # Restrict access to the configuration "
1244 cupsFilePuts(temp
, " Order allow,deny\n");
1247 cupsFilePuts(temp
, " Allow @LOCAL\n");
1249 cupsFilePuts(temp
, " Allow localhost\n");
1251 else if (in_root_location
)
1253 wrote_root_location
= 1;
1255 if (remote_admin
&& share_printers
)
1256 cupsFilePuts(temp
, " # Allow shared printing and remote "
1257 "administration...\n");
1258 else if (remote_admin
)
1259 cupsFilePuts(temp
, " # Allow remote administration...\n");
1260 else if (share_printers
)
1261 cupsFilePuts(temp
, " # Allow shared printing...\n");
1263 cupsFilePuts(temp
, " # Restrict access to the server...\n");
1265 cupsFilePuts(temp
, " Order allow,deny\n");
1267 if (remote_admin
|| share_printers
)
1268 cupsFilePuts(temp
, " Allow @LOCAL\n");
1270 cupsFilePuts(temp
, " Allow localhost\n");
1273 in_admin_location
= 0;
1274 in_conf_location
= 0;
1275 in_root_location
= 0;
1277 cupsFilePuts(temp
, "</Location>\n");
1279 else if (!strcasecmp(line
, "<Limit") && in_default_policy
)
1282 * See if the policy limit is for the Cancel-Job operation...
1285 char *valptr
; /* Pointer into value */
1290 if (!strcasecmp(value
, "cancel-job"))
1293 * Don't write anything for this limit section...
1300 cupsFilePrintf(temp
, " %s", line
);
1304 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1309 if (!strcasecmp(value
, "cancel-job"))
1312 * Write everything except for this definition...
1318 cupsFilePrintf(temp
, " %s", value
);
1320 for (value
= valptr
; isspace(*value
& 255); value
++);
1323 cupsFilePuts(temp
, ">\n");
1326 else if (!strcasecmp(line
, "</Limit>") && in_cancel_job
)
1330 if (in_cancel_job
== 1)
1331 cupsFilePuts(temp
, " </Limit>\n");
1335 if (!user_cancel_any
)
1336 cupsFilePuts(temp
, " # Only the owner or an administrator can cancel "
1338 " <Limit Cancel-Job>\n"
1339 " Order deny,allow\n"
1340 " Require user @OWNER @SYSTEM\n"
1345 else if ((in_admin_location
|| in_conf_location
|| in_root_location
) &&
1346 (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny") ||
1347 !strcasecmp(line
, "Order")))
1349 else if (in_cancel_job
== 2)
1351 else if (!strcasecmp(line
, "<Limit") && value
)
1352 cupsFilePrintf(temp
, " %s %s>\n", line
, value
);
1353 else if (line
[0] == '<')
1357 cupsFilePrintf(temp
, "%*s%s %s>\n", indent
, "", line
, value
);
1365 cupsFilePrintf(temp
, "%*s%s\n", indent
, "", line
);
1368 else if (!in_policy
&& !in_location
&&
1369 (val
= cupsGetOption(line
, num_settings
, settings
)) != NULL
&&
1370 !cupsGetOption(line
, cupsd_num_settings
, cupsd_settings
))
1373 * Add this directive to the list of directives we have written...
1376 cupsd_num_settings
= cupsAddOption(line
, value
, cupsd_num_settings
,
1380 * Write the new value in its place, without indentation since we
1381 * only support setting root directives, not in sections...
1384 cupsFilePrintf(temp
, "%s %s\n", line
, value
);
1388 if (!in_policy
&& !in_location
)
1391 * Record the non-policy, non-location directives that we find
1392 * in the server settings, since we cache this info and record it
1393 * in _cupsAdminGetServerSettings()...
1396 cupsd_num_settings
= cupsAddOption(line
, value
, cupsd_num_settings
,
1400 cupsFilePrintf(temp
, "%*s%s %s\n", indent
, "", line
, value
);
1403 cupsFilePrintf(temp
, "%*s%s\n", indent
, "", line
);
1407 * Write any missing info...
1410 if (!wrote_browsing
)
1412 if (remote_printers
|| share_printers
)
1414 if (remote_printers
&& share_printers
)
1415 cupsFilePuts(temp
, "# Enable printer sharing and shared printers.\n");
1416 else if (remote_printers
)
1417 cupsFilePuts(temp
, "# Show shared printers on the local network.\n");
1419 cupsFilePuts(temp
, "# Share local printers on the local network.\n");
1421 cupsFilePuts(temp
, "Browsing On\n");
1422 cupsFilePuts(temp
, "BrowseOrder allow,deny\n");
1424 if (remote_printers
)
1425 cupsFilePuts(temp
, "BrowseAllow @LOCAL\n");
1428 cupsFilePuts(temp
, "BrowseAddress @LOCAL\n");
1432 cupsFilePuts(temp
, "# Disable printer sharing and shared printers.\n");
1433 cupsFilePuts(temp
, "Browsing Off\n");
1437 if (!wrote_loglevel
)
1441 cupsFilePuts(temp
, "# Show troubleshooting information in error_log.\n");
1442 cupsFilePuts(temp
, "LogLevel debug\n");
1446 cupsFilePuts(temp
, "# Show general information in error_log.\n");
1447 cupsFilePuts(temp
, "LogLevel info\n");
1451 if (!wrote_port_listen
)
1453 if (share_printers
|| remote_admin
)
1455 cupsFilePuts(temp
, "# Allow remote access\n");
1456 cupsFilePrintf(temp
, "Port %d\n", ippPort());
1461 "# Only listen for connections from the local machine.\n");
1462 cupsFilePrintf(temp
, "Listen localhost:%d\n", ippPort());
1465 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1466 if (!access(CUPS_DEFAULT_DOMAINSOCKET
, 0))
1467 cupsFilePuts(temp
, "Listen " CUPS_DEFAULT_DOMAINSOCKET
"\n");
1468 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1471 if (!wrote_root_location
)
1473 if (remote_admin
&& share_printers
)
1475 "# Allow shared printing and remote administration...\n");
1476 else if (remote_admin
)
1477 cupsFilePuts(temp
, "# Allow remote administration...\n");
1478 else if (share_printers
)
1479 cupsFilePuts(temp
, "# Allow shared printing...\n");
1481 cupsFilePuts(temp
, "# Restrict access to the server...\n");
1483 cupsFilePuts(temp
, "<Location />\n"
1484 " Order allow,deny\n");
1486 if (remote_admin
|| share_printers
)
1487 cupsFilePuts(temp
, " Allow @LOCAL\n");
1489 cupsFilePuts(temp
, " Allow localhost\n");
1491 cupsFilePuts(temp
, "</Location>\n");
1494 if (!wrote_admin_location
)
1497 cupsFilePuts(temp
, "# Allow remote administration...\n");
1499 cupsFilePuts(temp
, "# Restrict access to the admin pages...\n");
1501 cupsFilePuts(temp
, "<Location /admin>\n"
1502 " Order allow,deny\n");
1505 cupsFilePuts(temp
, " Allow @LOCAL\n");
1507 cupsFilePuts(temp
, " Allow localhost\n");
1509 cupsFilePuts(temp
, "</Location>\n");
1512 if (!wrote_conf_location
)
1516 "# Allow remote access to the configuration files...\n");
1518 cupsFilePuts(temp
, "# Restrict access to the configuration files...\n");
1520 cupsFilePuts(temp
, "<Location /admin/conf>\n"
1522 " Require user @SYSTEM\n"
1523 " Order allow,deny\n");
1526 cupsFilePuts(temp
, " Allow @LOCAL\n");
1528 cupsFilePuts(temp
, " Allow localhost\n");
1530 cupsFilePuts(temp
, "</Location>\n");
1535 cupsFilePuts(temp
, "<Policy default>\n"
1536 " # Job-related operations must be done by the owner "
1537 "or an adminstrator...\n"
1538 " <Limit Send-Document Send-URI Hold-Job Release-Job "
1539 "Restart-Job Purge-Jobs Set-Job-Attributes "
1540 "Create-Job-Subscription Renew-Subscription "
1541 "Cancel-Subscription Get-Notifications Reprocess-Job "
1542 "Cancel-Current-Job Suspend-Current-Job Resume-Job "
1544 " Require user @OWNER @SYSTEM\n"
1545 " Order deny,allow\n"
1547 " # All administration operations require an "
1548 "adminstrator to authenticate...\n"
1549 " <Limit Pause-Printer Resume-Printer "
1550 "Set-Printer-Attributes Enable-Printer "
1551 "Disable-Printer Pause-Printer-After-Current-Job "
1552 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
1553 "Activate-Printer Restart-Printer Shutdown-Printer "
1554 "Startup-Printer Promote-Job Schedule-Job-After "
1555 "CUPS-Add-Printer CUPS-Delete-Printer "
1556 "CUPS-Add-Class CUPS-Delete-Class "
1557 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
1558 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>\n"
1560 " Require user @SYSTEM\n"
1561 " Order deny,allow\n"
1564 if (!user_cancel_any
)
1565 cupsFilePuts(temp
, " # Only the owner or an administrator can cancel "
1567 " <Limit Cancel-Job>\n"
1568 " Require user @OWNER @SYSTEM\n"
1569 " Order deny,allow\n"
1572 cupsFilePuts(temp
, " <Limit All>\n"
1573 " Order deny,allow\n"
1578 for (i
= num_settings
, setting
= settings
; i
> 0; i
--, setting
++)
1579 if (setting
->name
[0] != '_' &&
1580 !cupsGetOption(setting
->name
, cupsd_num_settings
, cupsd_settings
))
1583 * Add this directive to the list of directives we have written...
1586 cupsd_num_settings
= cupsAddOption(setting
->name
, setting
->value
,
1587 cupsd_num_settings
, &cupsd_settings
);
1590 * Write the new value in its place, without indentation since we
1591 * only support setting root directives, not in sections...
1594 cupsFilePrintf(temp
, "%s %s\n", setting
->name
, setting
->value
);
1597 cupsFileClose(cupsd
);
1598 cupsFileClose(temp
);
1601 * Upload the configuration file to the server...
1604 status
= cupsPutFile(http
, "/admin/conf/cupsd.conf", tempfile
);
1606 if (status
== HTTP_CREATED
)
1609 * Updated OK, add the basic settings...
1612 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
,
1613 debug_logging
? "1" : "0",
1614 cupsd_num_settings
, &cupsd_settings
);
1615 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
,
1616 remote_admin
? "1" : "0",
1617 cupsd_num_settings
, &cupsd_settings
);
1618 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS
,
1619 remote_printers
? "1" : "0",
1620 cupsd_num_settings
, &cupsd_settings
);
1621 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
,
1622 share_printers
? "1" : "0",
1623 cupsd_num_settings
, &cupsd_settings
);
1624 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
,
1625 user_cancel_any
? "1" : "0",
1626 cupsd_num_settings
, &cupsd_settings
);
1629 * Save the new values...
1632 invalidate_cupsd_cache(cg
);
1634 cg
->cupsd_num_settings
= cupsd_num_settings
;
1635 cg
->cupsd_settings
= cupsd_settings
;
1636 cg
->cupsd_update
= time(NULL
);
1638 httpGetHostname(http
, cg
->cupsd_hostname
, sizeof(cg
->cupsd_hostname
));
1641 cupsFreeOptions(cupsd_num_settings
, cupsd_settings
);
1644 * Remote our temp files and return...
1652 return (status
== HTTP_CREATED
);
1657 * 'do_samba_command()' - Do a SAMBA command.
1660 static int /* O - Status of command */
1661 do_samba_command(const char *command
, /* I - Command to run */
1662 const char *address
, /* I - Address for command */
1663 const char *subcmd
, /* I - Sub-command */
1664 const char *authfile
, /* I - Samba authentication file */
1665 FILE *logfile
) /* I - Optional log file */
1667 int status
; /* Status of command */
1668 int pid
; /* Process ID of child */
1672 _cupsLangPrintf(logfile
,
1673 _("Running command: %s %s -N -A %s -c \'%s\'\n"),
1674 command
, address
, authfile
, subcmd
);
1676 if ((pid
= fork()) == 0)
1679 * Child goes here, redirect stdin/out/err and execute the command...
1683 open("/dev/null", O_RDONLY
);
1688 dup(fileno(logfile
));
1690 open("/dev/null", O_WRONLY
);
1695 execlp(command
, command
, address
, "-N", "-A", authfile
, "-c", subcmd
,
1704 _cupsLangPrintf(logfile
, _("Unable to run \"%s\": %s\n"),
1705 command
, strerror(errno
));
1710 * Wait for the process to complete...
1713 while (wait(&status
) != pid
);
1717 _cupsLangPuts(logfile
, "\n");
1719 DEBUG_printf(("status=%d\n", status
));
1721 if (WIFEXITED(status
))
1722 return (WEXITSTATUS(status
));
1724 return (-WTERMSIG(status
));
1729 * 'get_cupsd_conf()' - Get the current cupsd.conf file.
1732 static http_status_t
/* O - Status of request */
1734 http_t
*http
, /* I - Connection to server */
1735 _cups_globals_t
*cg
, /* I - Global data */
1736 time_t last_update
, /* I - Last update time for file */
1737 char *name
, /* I - Filename buffer */
1738 int namesize
, /* I - Size of filename buffer */
1739 int *remote
) /* O - Remote file? */
1741 int fd
; /* Temporary file descriptor */
1742 struct stat info
; /* cupsd.conf file information */
1743 http_status_t status
; /* Status of getting cupsd.conf */
1744 char host
[HTTP_MAX_HOST
]; /* Hostname for connection */
1748 * See if we already have the data we need...
1751 httpGetHostname(http
, host
, sizeof(host
));
1753 if (strcasecmp(cg
->cupsd_hostname
, host
))
1754 invalidate_cupsd_cache(cg
);
1756 snprintf(name
, namesize
, "%s/cupsd.conf", cg
->cups_serverroot
);
1759 if (!strcasecmp(host
, "localhost") && !access(name
, R_OK
))
1762 * Read the local file rather than using HTTP...
1765 if (stat(name
, &info
))
1767 char message
[1024]; /* Message string */
1770 snprintf(message
, sizeof(message
),
1771 _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
1772 name
, strerror(errno
));
1773 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
1777 return (HTTP_SERVER_ERROR
);
1779 else if (last_update
&& info
.st_mtime
<= last_update
)
1780 status
= HTTP_NOT_MODIFIED
;
1787 * Read cupsd.conf via a HTTP GET request...
1790 if ((fd
= cupsTempFd(name
, namesize
)) < 0)
1794 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1796 invalidate_cupsd_cache(cg
);
1798 return (HTTP_SERVER_ERROR
);
1803 httpClearFields(http
);
1806 httpSetField(http
, HTTP_FIELD_IF_MODIFIED_SINCE
,
1807 httpGetDateString(last_update
));
1809 status
= cupsGetFd(http
, "/admin/conf/cupsd.conf", fd
);
1813 if (status
!= HTTP_OK
)
1825 * 'invalidate_cupsd_cache()' - Invalidate the cached cupsd.conf settings.
1829 invalidate_cupsd_cache(
1830 _cups_globals_t
*cg
) /* I - Global data */
1832 cupsFreeOptions(cg
->cupsd_num_settings
, cg
->cupsd_settings
);
1834 cg
->cupsd_hostname
[0] = '\0';
1835 cg
->cupsd_update
= 0;
1836 cg
->cupsd_num_settings
= 0;
1837 cg
->cupsd_settings
= NULL
;
1842 * 'write_option()' - Write a CUPS option to a PPD file.
1846 write_option(cups_file_t
*dstfp
, /* I - PPD file */
1847 int order
, /* I - Order dependency */
1848 const char *name
, /* I - Option name */
1849 const char *text
, /* I - Option text */
1850 const char *attrname
, /* I - Attribute name */
1851 ipp_attribute_t
*suppattr
, /* I - IPP -supported attribute */
1852 ipp_attribute_t
*defattr
, /* I - IPP -default attribute */
1853 int defval
, /* I - Default value number */
1854 int valcount
) /* I - Number of values */
1856 int i
; /* Looping var */
1859 cupsFilePrintf(dstfp
, "*JCLOpenUI *%s/%s: PickOne\n"
1860 "*OrderDependency: %d JCLSetup *%s\n",
1861 name
, text
, order
, name
);
1863 if (defattr
->value_tag
== IPP_TAG_INTEGER
)
1866 * Do numeric options with a range or list...
1869 cupsFilePrintf(dstfp
, "*Default%s: %d\n", name
,
1870 defattr
->values
[defval
].integer
);
1872 if (suppattr
->value_tag
== IPP_TAG_RANGE
)
1875 * List each number in the range...
1878 for (i
= suppattr
->values
[0].range
.lower
;
1879 i
<= suppattr
->values
[0].range
.upper
;
1882 cupsFilePrintf(dstfp
, "*%s %d: \"", name
, i
);
1885 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\n\"\n*End\n",
1887 else if (defval
== 0)
1888 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\"\n", attrname
, i
);
1889 else if (defval
< (valcount
- 1))
1890 cupsFilePrintf(dstfp
, ",%d\"\n", i
);
1892 cupsFilePrintf(dstfp
, ",%d\n\"\n*End\n", i
);
1898 * List explicit numbers...
1901 for (i
= 0; i
< suppattr
->num_values
; i
++)
1903 cupsFilePrintf(dstfp
, "*%s %d: \"", name
, suppattr
->values
[i
].integer
);
1906 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\n\"\n*End\n", attrname
,
1907 suppattr
->values
[i
].integer
);
1908 else if (defval
== 0)
1909 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\"\n", attrname
,
1910 suppattr
->values
[i
].integer
);
1911 else if (defval
< (valcount
- 1))
1912 cupsFilePrintf(dstfp
, ",%d\"\n", suppattr
->values
[i
].integer
);
1914 cupsFilePrintf(dstfp
, ",%d\n\"\n*End\n", suppattr
->values
[i
].integer
);
1921 * Do text options with a list...
1924 cupsFilePrintf(dstfp
, "*Default%s: %s\n", name
,
1925 defattr
->values
[defval
].string
.text
);
1927 for (i
= 0; i
< suppattr
->num_values
; i
++)
1929 cupsFilePrintf(dstfp
, "*%s %s: \"", name
,
1930 suppattr
->values
[i
].string
.text
);
1933 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%s\n\"\n*End\n", attrname
,
1934 suppattr
->values
[i
].string
.text
);
1935 else if (defval
== 0)
1936 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%s\"\n", attrname
,
1937 suppattr
->values
[i
].string
.text
);
1938 else if (defval
< (valcount
- 1))
1939 cupsFilePrintf(dstfp
, ",%s\"\n", suppattr
->values
[i
].string
.text
);
1941 cupsFilePrintf(dstfp
, ",%s\n\"\n*End\n",
1942 suppattr
->values
[i
].string
.text
);
1946 cupsFilePrintf(dstfp
, "*JCLCloseUI: *%s\n\n", name
);
1951 * End of "$Id: adminutil.c 5878 2006-08-24 15:55:42Z mike $".