2 * "$Id: adminutil.c 5240 2006-03-07 21:55:29Z 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 *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
)) < 0)
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"
228 else if (!strncmp(line
, "*JCLOpenUI", 10))
231 cupsFilePuts(dstfp
, line
);
233 else if (!strncmp(line
, "*JCLCloseUI", 11))
236 cupsFilePuts(dstfp
, 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\n", option
, choice
);
317 cupsFilePrintf(dstfp
, "*%% Changed for CUPS Windows Driver...\n%s", line
);
320 cupsFilePuts(dstfp
, line
);
323 cupsFileClose(srcfp
);
327 * Now add the CUPS-specific attributes and options...
330 cupsFilePuts(dstfp
, "\n*% CUPS Job Ticket support and options...\n");
331 cupsFilePuts(dstfp
, "*Protocols: PJL\n");
332 cupsFilePuts(dstfp
, "*JCLBegin: \"%!PS-Adobe-3.0<0A>\"\n");
333 cupsFilePuts(dstfp
, "*JCLToPSInterpreter: \"\"\n");
334 cupsFilePuts(dstfp
, "*JCLEnd: \"\"\n");
336 cupsFilePuts(dstfp
, "\n*OpenGroup: CUPS/CUPS Options\n\n");
338 if ((defattr
= ippFindAttribute(response
, "job-hold-until-default",
339 IPP_TAG_ZERO
)) != NULL
&&
340 (suppattr
= ippFindAttribute(response
, "job-hold-until-supported",
341 IPP_TAG_ZERO
)) != NULL
)
342 write_option(dstfp
, 10, "cupsJobHoldUntil", "Hold Until", "job-hold-until",
343 suppattr
, defattr
, 0, 1);
345 if ((defattr
= ippFindAttribute(response
, "job-priority-default",
346 IPP_TAG_INTEGER
)) != NULL
&&
347 (suppattr
= ippFindAttribute(response
, "job-priority-supported",
348 IPP_TAG_RANGE
)) != NULL
)
349 write_option(dstfp
, 11, "cupsJobPriority", "Priority", "job-priority",
350 suppattr
, defattr
, 0, 1);
352 if ((defattr
= ippFindAttribute(response
, "job-sheets-default",
353 IPP_TAG_ZERO
)) != NULL
&&
354 (suppattr
= ippFindAttribute(response
, "job-sheets-supported",
355 IPP_TAG_ZERO
)) != NULL
)
357 write_option(dstfp
, 20, "cupsJobSheetsStart", "Start Banner",
358 "job-sheets", suppattr
, defattr
, 0, 2);
359 write_option(dstfp
, 21, "cupsJobSheetsEnd", "End Banner",
360 "job-sheets", suppattr
, defattr
, 1, 2);
363 cupsFilePuts(dstfp
, "*CloseGroup: CUPS\n");
364 cupsFileClose(dstfp
);
373 * 'cupsAdminExportSamba()' - Export a printer to Samba.
376 int /* O - 1 on success, 0 on failure */
377 cupsAdminExportSamba(
378 const char *dest
, /* I - Destination to export */
379 const char *ppd
, /* I - PPD file */
380 const char *samba_server
, /* I - Samba server */
381 const char *samba_user
, /* I - Samba username */
382 const char *samba_password
, /* I - Samba password */
383 FILE *logfile
) /* I - Log file, if any */
385 int status
; /* Status of smbclient/rpcclient commands */
386 int have_drivers
; /* Have drivers? */
387 char file
[1024], /* File to test for */
388 authfile
[1024], /* Temporary authentication file */
389 address
[1024], /* Address for command */
390 subcmd
[1024], /* Sub-command */
391 message
[1024]; /* Error message */
392 cups_file_t
*fp
; /* Authentication file */
393 cups_lang_t
*language
; /* Current language */
394 _cups_globals_t
*cg
= _cupsGlobals();
399 * Range check input...
402 if (!dest
|| !ppd
|| !samba_server
|| !samba_user
|| !samba_password
)
404 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
409 * Create a temporary authentication file for Samba...
412 if ((fp
= cupsTempFile2(authfile
, sizeof(authfile
))) == NULL
)
414 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
418 cupsFilePrintf(fp
, "username = %s\n", samba_user
);
419 cupsFilePrintf(fp
, "password = %s\n", samba_password
);
423 * See which drivers are available; the new CUPS v6 and Adobe drivers
424 * depend on the Windows 2k PS driver, so copy that driver first:
435 language
= cupsLangDefault();
437 snprintf(file
, sizeof(file
), "%s/drivers/pscript5.dll", cg
->cups_datadir
);
438 if (!access(file
, 0))
443 * Windows 2k driver is installed; do the smbclient commands needed
444 * to copy the Win2k drivers over...
447 snprintf(address
, sizeof(address
), "//%s/print$", samba_server
);
449 snprintf(subcmd
, sizeof(subcmd
),
451 "put %s W32X86/%s.ppd;"
452 "put %s/drivers/ps5ui.dll W32X86/ps5ui.dll;"
453 "put %s/drivers/pscript.hlp W32X86/pscript.hlp;"
454 "put %s/drivers/pscript.ntf W32X86/pscript.ntf;"
455 "put %s/drivers/pscript5.dll W32X86/pscript5.dll",
456 ppd
, dest
, cg
->cups_datadir
, cg
->cups_datadir
,
457 cg
->cups_datadir
, cg
->cups_datadir
);
459 if ((status
= do_samba_command("smbclient", address
, subcmd
,
460 authfile
, logfile
)) != 0)
462 snprintf(message
, sizeof(message
),
463 _cupsLangString(language
,
464 _("Unable to copy Windows 2000 printer "
465 "driver files (%d)!")), status
);
467 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
470 _cupsLangPrintf(logfile
, "%s\n", message
);
478 * See if we also have the CUPS driver files; if so, use them!
481 snprintf(file
, sizeof(file
), "%s/drivers/cupsps6.dll", cg
->cups_datadir
);
482 if (!access(file
, 0))
485 * Copy the CUPS driver files over...
488 snprintf(subcmd
, sizeof(subcmd
),
489 "put %s/drivers/cups6.ini W32X86/cups6.ini;"
490 "put %s/drivers/cupsps6.dll W32X86/cupsps6.dll;"
491 "put %s/drivers/cupsui6.dll W32X86/cupsui6.dll",
492 cg
->cups_datadir
, cg
->cups_datadir
, cg
->cups_datadir
);
494 if ((status
= do_samba_command("smbclient", address
, subcmd
,
495 authfile
, logfile
)) != 0)
497 snprintf(message
, sizeof(message
),
498 _cupsLangString(language
,
499 _("Unable to copy CUPS printer driver "
500 "files (%d)!")), status
);
502 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
505 _cupsLangPrintf(logfile
, "%s\n", message
);
513 * Do the rpcclient command needed for the CUPS drivers...
516 snprintf(subcmd
, sizeof(subcmd
),
517 "adddriver \"Windows NT x86\" \"%s:"
518 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
519 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
520 "cups6.ini,cupsps6.dll,cupsui6.dll\"",
526 * Don't have the CUPS drivers, so just use the standard Windows
530 snprintf(subcmd
, sizeof(subcmd
),
531 "adddriver \"Windows NT x86\" \"%s:"
532 "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
533 "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
537 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
538 authfile
, logfile
)) != 0)
540 snprintf(message
, sizeof(message
),
541 _cupsLangString(language
,
542 _("Unable to install Windows 2000 printer "
543 "driver files (%d)!")), status
);
545 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
548 _cupsLangPrintf(logfile
, "%s\n", message
);
556 snprintf(file
, sizeof(file
), "%s/drivers/ADOBEPS4.DRV", cg
->cups_datadir
);
557 if (!access(file
, 0))
562 * Do the smbclient commands needed for the Adobe Win9x drivers...
565 snprintf(address
, sizeof(address
), "//%s/print$", samba_server
);
567 snprintf(subcmd
, sizeof(subcmd
),
569 "put %s WIN40/%s.PPD;"
570 "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
571 "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
572 "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
573 "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
574 "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
575 ppd
, dest
, cg
->cups_datadir
, cg
->cups_datadir
,
576 cg
->cups_datadir
, cg
->cups_datadir
, cg
->cups_datadir
);
578 if ((status
= do_samba_command("smbclient", address
, subcmd
,
579 authfile
, logfile
)) != 0)
581 snprintf(message
, sizeof(message
),
582 _cupsLangString(language
,
583 _("Unable to copy Windows 9x printer "
584 "driver files (%d)!")), status
);
586 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
589 _cupsLangPrintf(logfile
, "%s\n", message
);
597 * Do the rpcclient commands needed for the Adobe Win9x drivers...
600 snprintf(subcmd
, sizeof(subcmd
),
601 "adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:"
602 "ADOBEPS4.HLP:PSMON.DLL:RAW:"
603 "ADOBEPS4.DRV,%s.PPD,ADOBEPS4.HLP,PSMON.DLL,ADFONTS.MFM,"
607 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
608 authfile
, logfile
)) != 0)
610 snprintf(message
, sizeof(message
),
611 _cupsLangString(language
,
612 _("Unable to install Windows 9x printer "
613 "driver files (%d)!")), status
);
615 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
618 _cupsLangPrintf(logfile
, "%s\n", message
);
626 if (logfile
&& !(have_drivers
& 1))
630 _cupsLangString(language
,
631 _("No Windows printer drivers are installed!")),
635 _cupsLangString(language
,
636 _("Warning, no Windows 2000 printer drivers "
640 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
641 _cupsLangPrintf(logfile
, "%s\n", message
);
644 if (have_drivers
== 0)
648 * Finally, associate the drivers we just added with the queue...
651 snprintf(subcmd
, sizeof(subcmd
), "setdriver %s %s", dest
, dest
);
653 if ((status
= do_samba_command("rpcclient", samba_server
, subcmd
,
654 authfile
, logfile
)) != 0)
656 snprintf(message
, sizeof(message
),
657 _cupsLangString(language
,
658 _("Unable to set Windows printer driver (%d)!\n")),
661 _cupsSetError(IPP_INTERNAL_ERROR
, message
);
664 _cupsLangPrintf(logfile
, "%s\n", message
);
678 * '_cupsAdminGetServerSettings()' - Get settings from the server.
680 * The returned settings should be freed with cupsFreeOptions() when
681 * you are done with them.
686 int /* O - 1 on success, 0 on failure */
687 _cupsAdminGetServerSettings(
688 http_t
*http
, /* I - Connection to server */
689 int *num_settings
, /* O - Number of settings */
690 cups_option_t
**settings
) /* O - Settings */
692 int i
; /* Looping var */
693 cups_file_t
*cupsd
; /* cupsd.conf file */
694 char cupsdconf
[1024]; /* cupsd.conf filename */
695 int remote
; /* Remote cupsd.conf file? */
696 http_status_t status
; /* Status of getting cupsd.conf */
697 char line
[1024], /* Line from cupsd.conf file */
698 *value
; /* Value on line */
699 cups_option_t
*setting
; /* Current setting */
700 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
704 * Range check input...
707 if (!http
|| !num_settings
|| !settings
)
709 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
724 * Get the cupsd.conf file...
727 if ((status
= get_cupsd_conf(http
, cg
, cg
->cupsd_update
, cupsdconf
,
728 sizeof(cupsdconf
), &remote
)) == HTTP_OK
)
730 if ((cupsd
= cupsFileOpen(cupsdconf
, "r")) == NULL
)
731 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
739 * Read the file, keeping track of what settings are enabled...
742 int remote_access
= 0, /* Remote access allowed? */
743 remote_admin
= 0, /* Remote administration allowed? */
744 browsing
= 1, /* Browsing enabled? */
745 browse_allow
= 1, /* Browse address set? */
746 browse_address
= 0, /* Browse address set? */
747 cancel_policy
= 1, /* Cancel-job policy set? */
748 debug_logging
= 0; /* LogLevel debug set? */
749 int linenum
= 0, /* Line number in file */
750 in_location
= 0, /* In a location section? */
751 in_policy
= 0, /* In a policy section? */
752 in_cancel_job
= 0, /* In a cancel-job section? */
753 in_admin_location
= 0; /* In the /admin location? */
756 invalidate_cupsd_cache(cg
);
758 cg
->cupsd_update
= time(NULL
);
759 httpGetHostname(http
, cg
->cupsd_hostname
, sizeof(cg
->cupsd_hostname
));
761 while (cupsFileGetConf(cupsd
, line
, sizeof(line
), &value
, &linenum
))
766 if (!strcasecmp(line
, "Port"))
770 else if (!strcasecmp(line
, "Listen"))
772 char *port
; /* Pointer to port number, if any */
775 if ((port
= strrchr(value
, ':')) != NULL
)
778 if (strcasecmp(value
, "localhost") && strcmp(value
, "127.0.0.1"))
781 else if (!strcasecmp(line
, "Browsing"))
783 browsing
= !strcasecmp(value
, "yes") || !strcasecmp(value
, "on") ||
784 !strcasecmp(value
, "true");
786 else if (!strcasecmp(line
, "BrowseAddress"))
790 else if (!strcasecmp(line
, "BrowseAllow"))
794 else if (!strcasecmp(line
, "BrowseOrder"))
796 browse_allow
= !strncasecmp(value
, "deny,", 5);
798 else if (!strcasecmp(line
, "LogLevel"))
800 debug_logging
= !strncasecmp(value
, "debug", 5);
802 else if (!strcasecmp(line
, "<Policy") && !strcasecmp(value
, "default"))
806 else if (!strcasecmp(line
, "</Policy>"))
810 else if (!strcasecmp(line
, "<Limit") && in_policy
)
813 * See if the policy limit is for the Cancel-Job operation...
816 char *valptr
; /* Pointer into value */
821 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
826 if (!strcasecmp(value
, "cancel-job") || !strcasecmp(value
, "all"))
832 for (value
= valptr
; isspace(*value
& 255); value
++);
835 else if (!strcasecmp(line
, "</Limit>"))
839 else if (!strcasecmp(line
, "Require") && in_cancel_job
)
843 else if (!strcasecmp(line
, "<Location"))
845 in_admin_location
= !strcasecmp(value
, "/admin");
848 else if (!strcasecmp(line
, "</Location>"))
850 in_admin_location
= 0;
853 else if (!strcasecmp(line
, "Allow") && in_admin_location
&&
854 strcasecmp(value
, "localhost") && strcasecmp(value
, "127.0.0.1"))
858 else if (line
[0] != '<' && !in_location
&& !in_policy
)
859 cg
->cupsd_num_settings
= cupsAddOption(line
, value
,
860 cg
->cupsd_num_settings
,
861 &(cg
->cupsd_settings
));
864 cupsFileClose(cupsd
);
866 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
,
867 debug_logging
? "1" : "0",
868 cg
->cupsd_num_settings
,
869 &(cg
->cupsd_settings
));
871 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
,
872 (remote_access
&& remote_admin
) ?
874 cg
->cupsd_num_settings
,
875 &(cg
->cupsd_settings
));
877 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS
,
878 (browsing
&& browse_allow
) ?
880 cg
->cupsd_num_settings
,
881 &(cg
->cupsd_settings
));
883 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
,
884 (remote_access
&& browsing
&&
885 browse_address
) ? "1" : "0",
886 cg
->cupsd_num_settings
,
887 &(cg
->cupsd_settings
));
889 cg
->cupsd_num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
,
890 cancel_policy
? "1" : "0",
891 cg
->cupsd_num_settings
,
892 &(cg
->cupsd_settings
));
894 else if (status
!= HTTP_NOT_MODIFIED
)
895 invalidate_cupsd_cache(cg
);
898 * Remove any temporary files and copy the settings array...
904 for (i
= cg
->cupsd_num_settings
, setting
= cg
->cupsd_settings
;
907 *num_settings
= cupsAddOption(setting
->name
, setting
->value
,
908 *num_settings
, settings
);
910 return (cg
->cupsd_num_settings
> 0);
915 * '_cupsAdminSetServerSettings()' - Set settings on the server.
920 int /* O - 1 on success, 0 on failure */
921 _cupsAdminSetServerSettings(
922 http_t
*http
, /* I - Connection to server */
923 int num_settings
, /* I - Number of settings */
924 cups_option_t
*settings
) /* I - Settings */
926 int i
; /* Looping var */
927 http_status_t status
; /* GET/PUT status */
928 cups_file_t
*cupsd
; /* cupsd.conf file */
929 char cupsdconf
[1024]; /* cupsd.conf filename */
930 int remote
; /* Remote cupsd.conf file? */
931 char tempfile
[1024]; /* Temporary new cupsd.conf */
932 cups_file_t
*temp
; /* Temporary file */
933 char line
[1024], /* Line from cupsd.conf file */
934 *value
; /* Value on line */
935 int linenum
, /* Line number in file */
936 in_location
, /* In a location section? */
937 in_policy
, /* In a policy section? */
938 in_default_policy
, /* In the default policy section? */
939 in_cancel_job
, /* In a cancel-job section? */
940 in_admin_location
, /* In the /admin location? */
941 in_conf_location
, /* In the /admin/conf location? */
942 in_root_location
; /* In the / location? */
943 const char *val
; /* Setting value */
944 int remote_printers
, /* Show remote printers */
945 share_printers
, /* Share local printers */
946 remote_admin
, /* Remote administration allowed? */
947 user_cancel_any
, /* Cancel-job policy set? */
948 debug_logging
; /* LogLevel debug set? */
949 int wrote_port_listen
, /* Wrote the port/listen lines? */
950 wrote_browsing
, /* Wrote the browsing lines? */
951 wrote_policy
, /* Wrote the policy? */
952 wrote_loglevel
, /* Wrote the LogLevel line? */
953 wrote_admin_location
, /* Wrote the /admin location? */
954 wrote_conf_location
, /* Wrote the /admin/conf location? */
955 wrote_root_location
; /* Wrote the / location? */
956 int indent
; /* Indentation */
957 int cupsd_num_settings
; /* New number of settings */
958 cups_option_t
*cupsd_settings
, /* New settings */
959 *setting
; /* Current setting */
960 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
964 * Range check input...
967 if (!http
|| !num_settings
|| !settings
)
969 _cupsSetError(IPP_INTERNAL_ERROR
, NULL
);
975 * Get the cupsd.conf file...
978 if ((status
= get_cupsd_conf(http
, cg
, 0, cupsdconf
, sizeof(cupsdconf
),
979 &remote
)) == HTTP_OK
)
981 if ((cupsd
= cupsFileOpen(cupsdconf
, "r")) == NULL
)
983 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
991 * Get basic settings...
994 if ((val
= cupsGetOption(CUPS_SERVER_DEBUG_LOGGING
, num_settings
,
996 debug_logging
= atoi(val
);
1000 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_ADMIN
, num_settings
,
1002 remote_admin
= atoi(val
);
1006 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS
, num_settings
,
1008 remote_printers
= atoi(val
);
1010 remote_printers
= 1;
1012 if ((val
= cupsGetOption(CUPS_SERVER_SHARE_PRINTERS
, num_settings
,
1014 share_printers
= atoi(val
);
1018 if ((val
= cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY
, num_settings
,
1020 user_cancel_any
= atoi(val
);
1022 user_cancel_any
= 0;
1025 * Create a temporary file for the new cupsd.conf file...
1028 if ((temp
= cupsTempFile2(tempfile
, sizeof(tempfile
))) == NULL
)
1030 cupsFileClose(cupsd
);
1035 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1040 * Copy the old file to the new, making changes along the way...
1043 cupsd_num_settings
= 0;
1044 in_admin_location
= 0;
1046 in_conf_location
= 0;
1047 in_default_policy
= 0;
1050 in_root_location
= 0;
1052 wrote_admin_location
= 0;
1054 wrote_conf_location
= 0;
1057 wrote_port_listen
= 0;
1058 wrote_root_location
= 0;
1061 while (cupsFileGetConf(cupsd
, line
, sizeof(line
), &value
, &linenum
))
1063 if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1065 if (!wrote_port_listen
)
1067 wrote_port_listen
= 1;
1069 if (share_printers
|| remote_admin
)
1071 cupsFilePuts(temp
, "# Allow remote access\n");
1072 cupsFilePrintf(temp
, "Port %d\n", ippPort());
1076 cupsFilePuts(temp
, "# Only listen for connections from the local machine.\n");
1077 cupsFilePrintf(temp
, "Listen 127.0.0.1:%d\n", ippPort());
1080 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1081 if (!access(CUPS_DEFAULT_DOMAINSOCKET
, 0))
1082 cupsFilePuts(temp
, "Listen " CUPS_DEFAULT_DOMAINSOCKET
"\n");
1083 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1086 else if (!strcasecmp(line
, "Browsing") ||
1087 !strcasecmp(line
, "BrowseAddress") ||
1088 !strcasecmp(line
, "BrowseAllow") ||
1089 !strcasecmp(line
, "BrowseDeny") ||
1090 !strcasecmp(line
, "BrowseOrder"))
1092 if (!wrote_browsing
)
1096 if (remote_printers
|| share_printers
)
1098 if (remote_printers
&& share_printers
)
1099 cupsFilePuts(temp
, "# Enable printer sharing and shared printers.\n");
1100 else if (remote_printers
)
1101 cupsFilePuts(temp
, "# Show shared printers on the local network.\n");
1103 cupsFilePuts(temp
, "# Share local printers on the local network.\n");
1105 cupsFilePuts(temp
, "Browsing On\n");
1106 cupsFilePuts(temp
, "BrowseOrder allow,deny\n");
1108 if (remote_printers
)
1109 cupsFilePuts(temp
, "BrowseAllow @LOCAL\n");
1112 cupsFilePuts(temp
, "BrowseAddress @LOCAL\n");
1116 cupsFilePuts(temp
, "# Disable printer sharing and shared printers.\n");
1117 cupsFilePuts(temp
, "Browsing Off\n");
1121 else if (!strcasecmp(line
, "LogLevel"))
1127 cupsFilePuts(temp
, "# Show troubleshooting information in error_log.\n");
1128 cupsFilePuts(temp
, "LogLevel debug\n");
1132 cupsFilePuts(temp
, "# Show general information in error_log.\n");
1133 cupsFilePuts(temp
, "LogLevel info\n");
1136 else if (!strcasecmp(line
, "<Policy"))
1138 in_default_policy
= !strcasecmp(value
, "default");
1141 cupsFilePrintf(temp
, "%s %s>\n", line
, value
);
1144 else if (!strcasecmp(line
, "</Policy>"))
1147 if (!wrote_policy
&& in_default_policy
)
1151 if (!user_cancel_any
)
1152 cupsFilePuts(temp
, " # Only the owner or an administrator can cancel a job...\n"
1153 " <Limit Cancel-Job>\n"
1154 " Order deny,allow\n"
1161 in_default_policy
= 0;
1163 cupsFilePuts(temp
, "</Policy>\n");
1165 else if (!strcasecmp(line
, "<Location"))
1169 if (!strcmp(value
, "/admin"))
1170 in_admin_location
= 1;
1171 if (!strcmp(value
, "/admin/conf"))
1172 in_conf_location
= 1;
1173 else if (!strcmp(value
, "/"))
1174 in_root_location
= 1;
1176 cupsFilePrintf(temp
, "%s %s>\n", line
, value
);
1178 else if (!strcasecmp(line
, "</Location>"))
1182 if (in_admin_location
)
1184 wrote_admin_location
= 1;
1187 cupsFilePuts(temp
, " # Allow remote administration...\n");
1189 cupsFilePuts(temp
, " # Restrict access to the admin pages...\n");
1191 cupsFilePuts(temp
, " Order allow,deny\n");
1194 cupsFilePuts(temp
, " Allow @LOCAL\n");
1196 cupsFilePuts(temp
, " Allow localhost\n");
1198 else if (in_conf_location
)
1200 wrote_conf_location
= 1;
1203 cupsFilePuts(temp
, " # Allow remote access to the configuration files...\n");
1205 cupsFilePuts(temp
, " # Restrict access to the configuration files...\n");
1207 cupsFilePuts(temp
, " Order allow,deny\n");
1210 cupsFilePuts(temp
, " Allow @LOCAL\n");
1212 cupsFilePuts(temp
, " Allow localhost\n");
1214 else if (in_root_location
)
1216 wrote_root_location
= 1;
1218 if (remote_admin
&& share_printers
)
1219 cupsFilePuts(temp
, " # Allow shared printing and remote administration...\n");
1220 else if (remote_admin
)
1221 cupsFilePuts(temp
, " # Allow remote administration...\n");
1222 else if (share_printers
)
1223 cupsFilePuts(temp
, " # Allow shared printing...\n");
1225 cupsFilePuts(temp
, " # Restrict access to the server...\n");
1227 cupsFilePuts(temp
, " Order allow,deny\n");
1229 if (remote_admin
|| share_printers
)
1230 cupsFilePuts(temp
, " Allow @LOCAL\n");
1232 cupsFilePuts(temp
, " Allow localhost\n");
1235 in_admin_location
= 0;
1236 in_conf_location
= 0;
1237 in_root_location
= 0;
1239 cupsFilePuts(temp
, "</Location>\n");
1241 else if (!strcasecmp(line
, "<Limit") && in_default_policy
)
1244 * See if the policy limit is for the Cancel-Job operation...
1247 char *valptr
; /* Pointer into value */
1252 if (!strcasecmp(value
, "cancel-job"))
1255 * Don't write anything for this limit section...
1262 cupsFilePrintf(temp
, " %s", line
);
1266 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1271 if (!strcasecmp(value
, "cancel-job"))
1274 * Write everything except for this definition...
1280 cupsFilePrintf(temp
, " %s", value
);
1282 for (value
= valptr
; isspace(*value
& 255); value
++);
1285 cupsFilePuts(temp
, ">\n");
1288 else if (!strcasecmp(line
, "</Limit>") && in_cancel_job
)
1292 if (in_cancel_job
== 1)
1293 cupsFilePuts(temp
, " </Limit>\n");
1297 if (!user_cancel_any
)
1298 cupsFilePuts(temp
, " # Only the owner or an administrator can cancel a job...\n"
1299 " <Limit Cancel-Job>\n"
1300 " Order deny,allow\n"
1301 " Require user @OWNER @SYSTEM\n"
1306 else if ((in_admin_location
|| in_conf_location
|| in_root_location
) &&
1307 (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny") ||
1308 !strcasecmp(line
, "Order")))
1310 else if (in_cancel_job
== 2)
1312 else if (!strcasecmp(line
, "<Limit") && value
)
1313 cupsFilePrintf(temp
, " %s %s>\n", line
, value
);
1314 else if (line
[0] == '<')
1318 cupsFilePrintf(temp
, "%*s%s %s>\n", indent
, "", line
, value
);
1326 cupsFilePrintf(temp
, "%*s%s\n", indent
, "", line
);
1329 else if (!in_policy
&& !in_location
&&
1330 (val
= cupsGetOption(line
, num_settings
, settings
)) != NULL
&&
1331 !cupsGetOption(line
, cupsd_num_settings
, cupsd_settings
))
1334 * Add this directive to the list of directives we have written...
1337 cupsd_num_settings
= cupsAddOption(line
, value
, cupsd_num_settings
,
1341 * Write the new value in its place, without indentation since we
1342 * only support setting root directives, not in sections...
1345 cupsFilePrintf(temp
, "%s %s\n", line
, value
);
1349 if (!in_policy
&& !in_location
)
1352 * Record the non-policy, non-location directives that we find
1353 * in the server settings, since we cache this info and record it
1354 * in _cupsAdminGetServerSettings()...
1357 cupsd_num_settings
= cupsAddOption(line
, value
, cupsd_num_settings
,
1361 cupsFilePrintf(temp
, "%*s%s %s\n", indent
, "", line
, value
);
1364 cupsFilePrintf(temp
, "%*s%s\n", indent
, "", line
);
1368 * Write any missing info...
1371 if (!wrote_browsing
)
1373 if (remote_printers
|| share_printers
)
1375 if (remote_printers
&& share_printers
)
1376 cupsFilePuts(temp
, "# Enable printer sharing and shared printers.\n");
1377 else if (remote_printers
)
1378 cupsFilePuts(temp
, "# Show shared printers on the local network.\n");
1380 cupsFilePuts(temp
, "# Share local printers on the local network.\n");
1382 cupsFilePuts(temp
, "Browsing On\n");
1383 cupsFilePuts(temp
, "BrowseOrder allow,deny\n");
1385 if (remote_printers
)
1386 cupsFilePuts(temp
, "BrowseAllow @LOCAL\n");
1389 cupsFilePuts(temp
, "BrowseAddress @LOCAL\n");
1393 cupsFilePuts(temp
, "# Disable printer sharing and shared printers.\n");
1394 cupsFilePuts(temp
, "Browsing Off\n");
1398 if (!wrote_loglevel
)
1402 cupsFilePuts(temp
, "# Show troubleshooting information in error_log.\n");
1403 cupsFilePuts(temp
, "LogLevel debug\n");
1407 cupsFilePuts(temp
, "# Show general information in error_log.\n");
1408 cupsFilePuts(temp
, "LogLevel info\n");
1412 if (!wrote_port_listen
)
1414 if (share_printers
|| remote_admin
)
1416 cupsFilePuts(temp
, "# Allow remote access\n");
1417 cupsFilePrintf(temp
, "Port %d\n", ippPort());
1421 cupsFilePuts(temp
, "# Only listen for connections from the local machine.\n");
1422 cupsFilePrintf(temp
, "Listen 127.0.0.1:%d\n", ippPort());
1425 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1426 if (!access(CUPS_DEFAULT_DOMAINSOCKET
, 0))
1427 cupsFilePuts(temp
, "Listen " CUPS_DEFAULT_DOMAINSOCKET
"\n");
1428 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1431 if (!wrote_root_location
)
1433 if (remote_admin
&& share_printers
)
1434 cupsFilePuts(temp
, "# Allow shared printing and remote administration...\n");
1435 else if (remote_admin
)
1436 cupsFilePuts(temp
, "# Allow remote administration...\n");
1437 else if (share_printers
)
1438 cupsFilePuts(temp
, "# Allow shared printing...\n");
1440 cupsFilePuts(temp
, "# Restrict access to the server...\n");
1442 cupsFilePuts(temp
, "<Location />\n"
1443 " Order allow,deny\n");
1445 if (remote_admin
|| share_printers
)
1446 cupsFilePuts(temp
, " Allow @LOCAL\n");
1448 cupsFilePuts(temp
, " Allow localhost\n");
1450 cupsFilePuts(temp
, "</Location>\n");
1453 if (!wrote_admin_location
)
1456 cupsFilePuts(temp
, "# Allow remote administration...\n");
1458 cupsFilePuts(temp
, "# Restrict access to the admin pages...\n");
1460 cupsFilePuts(temp
, "<Location /admin>\n"
1461 " Order allow,deny\n");
1464 cupsFilePuts(temp
, " Allow @LOCAL\n");
1466 cupsFilePuts(temp
, " Allow localhost\n");
1468 cupsFilePuts(temp
, "</Location>\n");
1471 if (!wrote_conf_location
)
1474 cupsFilePuts(temp
, "# Allow remote access to the configuration files...\n");
1476 cupsFilePuts(temp
, "# Restrict access to the configuration files...\n");
1478 cupsFilePuts(temp
, "<Location /admin/conf>\n"
1480 " Require user @SYSTEM\n"
1481 " Order allow,deny\n");
1484 cupsFilePuts(temp
, " Allow @LOCAL\n");
1486 cupsFilePuts(temp
, " Allow localhost\n");
1488 cupsFilePuts(temp
, "</Location>\n");
1493 cupsFilePuts(temp
, "<Policy default>\n"
1494 " # Job-related operations must be done by the owner or an adminstrator...\n"
1495 " <Limit Send-Document Send-URI Hold-Job Release-Job "
1496 "Restart-Job Purge-Jobs Set-Job-Attributes "
1497 "Create-Job-Subscription Renew-Subscription "
1498 "Cancel-Subscription Get-Notifications Reprocess-Job "
1499 "Cancel-Current-Job Suspend-Current-Job Resume-Job "
1501 " Require user @OWNER @SYSTEM\n"
1502 " Order deny,allow\n"
1504 " # All administration operations require an adminstrator to authenticate...\n"
1505 " <Limit Pause-Printer Resume-Printer "
1506 "Set-Printer-Attributes Enable-Printer "
1507 "Disable-Printer Pause-Printer-After-Current-Job "
1508 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
1509 "Activate-Printer Restart-Printer Shutdown-Printer "
1510 "Startup-Printer Promote-Job Schedule-Job-After "
1511 "CUPS-Add-Printer CUPS-Delete-Printer "
1512 "CUPS-Add-Class CUPS-Delete-Class "
1513 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
1514 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>\n"
1516 " Require user @SYSTEM\n"
1517 " Order deny,allow\n"
1520 if (!user_cancel_any
)
1521 cupsFilePuts(temp
, " # Only the owner or an administrator can cancel a job...\n"
1522 " <Limit Cancel-Job>\n"
1523 " Require user @OWNER @SYSTEM\n"
1524 " Order deny,allow\n"
1527 cupsFilePuts(temp
, " <Limit All>\n"
1528 " Order deny,allow\n"
1533 for (i
= num_settings
, setting
= settings
; i
> 0; i
--, setting
++)
1534 if (setting
->name
[0] != '_' &&
1535 !cupsGetOption(setting
->name
, cupsd_num_settings
, cupsd_settings
))
1538 * Add this directive to the list of directives we have written...
1541 cupsd_num_settings
= cupsAddOption(setting
->name
, setting
->value
,
1542 cupsd_num_settings
, &cupsd_settings
);
1545 * Write the new value in its place, without indentation since we
1546 * only support setting root directives, not in sections...
1549 cupsFilePrintf(temp
, "%s %s\n", setting
->name
, setting
->value
);
1552 cupsFileClose(cupsd
);
1553 cupsFileClose(temp
);
1556 * Upload the configuration file to the server...
1559 status
= cupsPutFile(http
, "/admin/conf/cupsd.conf", tempfile
);
1561 if (status
== HTTP_CREATED
)
1564 * Updated OK, add the basic settings...
1567 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
,
1568 debug_logging
? "1" : "0",
1569 cupsd_num_settings
, &cupsd_settings
);
1570 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
,
1571 remote_admin
? "1" : "0",
1572 cupsd_num_settings
, &cupsd_settings
);
1573 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS
,
1574 remote_printers
? "1" : "0",
1575 cupsd_num_settings
, &cupsd_settings
);
1576 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
,
1577 share_printers
? "1" : "0",
1578 cupsd_num_settings
, &cupsd_settings
);
1579 cupsd_num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
,
1580 user_cancel_any
? "1" : "0",
1581 cupsd_num_settings
, &cupsd_settings
);
1584 * Save the new values...
1587 invalidate_cupsd_cache(cg
);
1589 cg
->cupsd_num_settings
= cupsd_num_settings
;
1590 cg
->cupsd_settings
= cupsd_settings
;
1591 cg
->cupsd_update
= time(NULL
);
1593 httpGetHostname(http
, cg
->cupsd_hostname
, sizeof(cg
->cupsd_hostname
));
1596 cupsFreeOptions(cupsd_num_settings
, cupsd_settings
);
1599 * Remote our temp files and return...
1607 return (status
== HTTP_CREATED
);
1612 * 'do_samba_command()' - Do a SAMBA command.
1615 static int /* O - Status of command */
1616 do_samba_command(const char *command
, /* I - Command to run */
1617 const char *address
, /* I - Address for command */
1618 const char *subcmd
, /* I - Sub-command */
1619 const char *authfile
, /* I - Samba authentication file */
1620 FILE *logfile
) /* I - Optional log file */
1622 int status
; /* Status of command */
1623 int pid
; /* Process ID of child */
1627 _cupsLangPrintf(logfile
,
1628 _("Running command: %s %s -N -A %s -c \'%s\'\n"),
1629 command
, address
, authfile
, subcmd
);
1631 if ((pid
= fork()) == 0)
1634 * Child goes here, redirect stdin/out/err and execute the command...
1638 open("/dev/null", O_RDONLY
);
1643 dup(fileno(logfile
));
1645 open("/dev/null", O_WRONLY
);
1650 execlp(command
, command
, address
, "-N", "-A", authfile
, "-c", subcmd
,
1658 _cupsLangPrintf(stderr
, _("cupsaddsmb: Unable to run \"%s\": %s\n"),
1659 command
, strerror(errno
));
1664 * Wait for the process to complete...
1667 while (wait(&status
) != pid
);
1671 _cupsLangPuts(logfile
, "\n");
1673 DEBUG_printf(("status=%d\n", status
));
1675 if (WIFEXITED(status
))
1676 return (WEXITSTATUS(status
));
1678 return (-WTERMSIG(status
));
1683 * 'get_cupsd_conf()' - Get the current cupsd.conf file.
1686 static http_status_t
/* O - Status of request */
1688 http_t
*http
, /* I - Connection to server */
1689 _cups_globals_t
*cg
, /* I - Global data */
1690 time_t last_update
, /* I - Last update time for file */
1691 char *name
, /* I - Filename buffer */
1692 int namesize
, /* I - Size of filename buffer */
1693 int *remote
) /* O - Remote file? */
1695 int fd
; /* Temporary file descriptor */
1696 struct stat info
; /* cupsd.conf file information */
1697 http_status_t status
; /* Status of getting cupsd.conf */
1698 char host
[HTTP_MAX_HOST
]; /* Hostname for connection */
1702 * See if we already have the data we need...
1705 httpGetHostname(http
, host
, sizeof(host
));
1707 if (strcasecmp(cg
->cupsd_hostname
, host
))
1708 invalidate_cupsd_cache(cg
);
1710 snprintf(name
, namesize
, "%s/cupsd.conf", cg
->cups_serverroot
);
1713 if (!strcasecmp(host
, "localhost") && !access(name
, R_OK
))
1716 * Read the local file rather than using HTTP...
1719 if (stat(name
, &info
))
1723 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1725 return (HTTP_SERVER_ERROR
);
1727 else if (last_update
&& info
.st_mtime
<= last_update
)
1728 status
= HTTP_NOT_MODIFIED
;
1735 * Read cupsd.conf via a HTTP GET request...
1738 if ((fd
= cupsTempFd(name
, sizeof(name
))) < 0)
1742 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(errno
));
1744 invalidate_cupsd_cache(cg
);
1746 return (HTTP_SERVER_ERROR
);
1751 httpClearFields(http
);
1754 httpSetField(http
, HTTP_FIELD_IF_MODIFIED_SINCE
,
1755 httpGetDateString(last_update
));
1757 status
= cupsGetFd(http
, "/admin/conf/cupsd.conf", fd
);
1761 if (status
!= HTTP_OK
)
1773 * 'invalidate_cupsd_cache()' - Invalidate the cached cupsd.conf settings.
1777 invalidate_cupsd_cache(
1778 _cups_globals_t
*cg
) /* I - Global data */
1780 cupsFreeOptions(cg
->cupsd_num_settings
, cg
->cupsd_settings
);
1782 cg
->cupsd_hostname
[0] = '\0';
1783 cg
->cupsd_update
= 0;
1784 cg
->cupsd_num_settings
= 0;
1785 cg
->cupsd_settings
= NULL
;
1790 * 'write_option()' - Write a CUPS option to a PPD file.
1794 write_option(cups_file_t
*dstfp
, /* I - PPD file */
1795 int order
, /* I - Order dependency */
1796 const char *name
, /* I - Option name */
1797 const char *text
, /* I - Option text */
1798 const char *attrname
, /* I - Attribute name */
1799 ipp_attribute_t
*suppattr
, /* I - IPP -supported attribute */
1800 ipp_attribute_t
*defattr
, /* I - IPP -default attribute */
1801 int defval
, /* I - Default value number */
1802 int valcount
) /* I - Number of values */
1804 int i
; /* Looping var */
1807 cupsFilePrintf(dstfp
, "*JCLOpenUI *%s/%s: PickOne\n"
1808 "*OrderDependency: %d JCLSetup *%s\n",
1809 name
, text
, order
, name
);
1811 if (defattr
->value_tag
== IPP_TAG_INTEGER
)
1814 * Do numeric options with a range or list...
1817 cupsFilePrintf(dstfp
, "*Default%s: %d\n", name
,
1818 defattr
->values
[defval
].integer
);
1820 if (suppattr
->value_tag
== IPP_TAG_RANGE
)
1823 * List each number in the range...
1826 for (i
= suppattr
->values
[0].range
.lower
;
1827 i
<= suppattr
->values
[0].range
.upper
;
1830 cupsFilePrintf(dstfp
, "*%s %d: \"", name
, i
);
1833 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\n\"\n*End\n",
1835 else if (defval
== 0)
1836 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\"\n", attrname
, i
);
1837 else if (defval
< (valcount
- 1))
1838 cupsFilePrintf(dstfp
, ",%d\"\n", i
);
1840 cupsFilePrintf(dstfp
, ",%d\n\"\n*End\n", i
);
1846 * List explicit numbers...
1849 for (i
= 0; i
< suppattr
->num_values
; i
++)
1851 cupsFilePrintf(dstfp
, "*%s %d: \"", name
, suppattr
->values
[i
].integer
);
1854 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\n\"\n*End\n", attrname
,
1855 suppattr
->values
[i
].integer
);
1856 else if (defval
== 0)
1857 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%d\"\n", attrname
,
1858 suppattr
->values
[i
].integer
);
1859 else if (defval
< (valcount
- 1))
1860 cupsFilePrintf(dstfp
, ",%d\"\n", suppattr
->values
[i
].integer
);
1862 cupsFilePrintf(dstfp
, ",%d\n\"\n*End\n", suppattr
->values
[i
].integer
);
1869 * Do text options with a list...
1872 cupsFilePrintf(dstfp
, "*Default%s: %s\n", name
,
1873 defattr
->values
[defval
].string
.text
);
1875 for (i
= 0; i
< suppattr
->num_values
; i
++)
1877 cupsFilePrintf(dstfp
, "*%s %s: \"", name
,
1878 suppattr
->values
[i
].string
.text
);
1881 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%s\n\"\n*End\n", attrname
,
1882 suppattr
->values
[i
].string
.text
);
1883 else if (defval
== 0)
1884 cupsFilePrintf(dstfp
, "%%cupsJobTicket: %s=%s\"\n", attrname
,
1885 suppattr
->values
[i
].string
.text
);
1886 else if (defval
< (valcount
- 1))
1887 cupsFilePrintf(dstfp
, ",%s\"\n", suppattr
->values
[i
].string
.text
);
1889 cupsFilePrintf(dstfp
, ",%s\n\"\n*End\n",
1890 suppattr
->values
[i
].string
.text
);
1894 cupsFilePrintf(dstfp
, "*JCLCloseUI: *%s\n\n", name
);
1899 * End of "$Id: adminutil.c 5240 2006-03-07 21:55:29Z mike $".