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