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