]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/conf.c
Changing the printer-is-shared value for a remote queue did not produce an
[thirdparty/cups.git] / scheduler / conf.c
1 /*
2 * "$Id$"
3 *
4 * Configuration routines for the CUPS scheduler.
5 *
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
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/".
14 */
15
16 /*
17 * Include necessary headers...
18 */
19
20 #include "cupsd.h"
21 #include <stdarg.h>
22 #include <grp.h>
23 #include <sys/utsname.h>
24 #ifdef HAVE_ASL_H
25 # include <asl.h>
26 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
27 # define SD_JOURNAL_SUPPRESS_LOCATION
28 # include <systemd/sd-journal.h>
29 #endif /* HAVE_ASL_H */
30 #include <syslog.h>
31
32 #ifdef HAVE_LIBPAPER
33 # include <paper.h>
34 #endif /* HAVE_LIBPAPER */
35
36
37 /*
38 * Possibly missing network definitions...
39 */
40
41 #ifndef INADDR_NONE
42 # define INADDR_NONE 0xffffffff
43 #endif /* !INADDR_NONE */
44
45
46 /*
47 * Configuration variable structure...
48 */
49
50 typedef enum
51 {
52 CUPSD_VARTYPE_INTEGER, /* Integer option */
53 CUPSD_VARTYPE_TIME, /* Time interval option */
54 CUPSD_VARTYPE_STRING, /* String option */
55 CUPSD_VARTYPE_BOOLEAN, /* Boolean option */
56 CUPSD_VARTYPE_PATHNAME, /* File/directory name option */
57 CUPSD_VARTYPE_PERM /* File/directory permissions */
58 } cupsd_vartype_t;
59
60 typedef struct
61 {
62 const char *name; /* Name of variable */
63 void *ptr; /* Pointer to variable */
64 cupsd_vartype_t type; /* Type (int, string, address) */
65 } cupsd_var_t;
66
67
68 /*
69 * Local globals...
70 */
71
72 static const cupsd_var_t cupsd_vars[] =
73 {
74 { "AutoPurgeJobs", &JobAutoPurge, CUPSD_VARTYPE_BOOLEAN },
75 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
76 { "BrowseDNSSDSubTypes", &DNSSDSubTypes, CUPSD_VARTYPE_STRING },
77 #endif /* HAVE_DNSSD || HAVE_AVAHI */
78 { "BrowseWebIF", &BrowseWebIF, CUPSD_VARTYPE_BOOLEAN },
79 { "Browsing", &Browsing, CUPSD_VARTYPE_BOOLEAN },
80 { "Classification", &Classification, CUPSD_VARTYPE_STRING },
81 { "ClassifyOverride", &ClassifyOverride, CUPSD_VARTYPE_BOOLEAN },
82 { "DefaultLanguage", &DefaultLanguage, CUPSD_VARTYPE_STRING },
83 { "DefaultLeaseDuration", &DefaultLeaseDuration, CUPSD_VARTYPE_TIME },
84 { "DefaultPaperSize", &DefaultPaperSize, CUPSD_VARTYPE_STRING },
85 { "DefaultPolicy", &DefaultPolicy, CUPSD_VARTYPE_STRING },
86 { "DefaultShared", &DefaultShared, CUPSD_VARTYPE_BOOLEAN },
87 { "DirtyCleanInterval", &DirtyCleanInterval, CUPSD_VARTYPE_TIME },
88 { "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING },
89 { "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER },
90 { "FilterNice", &FilterNice, CUPSD_VARTYPE_INTEGER },
91 #ifdef HAVE_GSSAPI
92 { "GSSServiceName", &GSSServiceName, CUPSD_VARTYPE_STRING },
93 #endif /* HAVE_GSSAPI */
94 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
95 { "IdleExitTimeout", &IdleExitTimeout, CUPSD_VARTYPE_TIME },
96 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
97 { "JobKillDelay", &JobKillDelay, CUPSD_VARTYPE_TIME },
98 { "JobRetryLimit", &JobRetryLimit, CUPSD_VARTYPE_INTEGER },
99 { "JobRetryInterval", &JobRetryInterval, CUPSD_VARTYPE_TIME },
100 { "KeepAliveTimeout", &KeepAliveTimeout, CUPSD_VARTYPE_TIME },
101 { "KeepAlive", &KeepAlive, CUPSD_VARTYPE_BOOLEAN },
102 #ifdef HAVE_LAUNCHD
103 { "LaunchdTimeout", &IdleExitTimeout, CUPSD_VARTYPE_TIME },
104 #endif /* HAVE_LAUNCHD */
105 { "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
106 { "ListenBackLog", &ListenBackLog, CUPSD_VARTYPE_INTEGER },
107 { "LogDebugHistory", &LogDebugHistory, CUPSD_VARTYPE_INTEGER },
108 { "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER },
109 { "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER },
110 { "MaxClientsPerHost", &MaxClientsPerHost, CUPSD_VARTYPE_INTEGER },
111 { "MaxCopies", &MaxCopies, CUPSD_VARTYPE_INTEGER },
112 { "MaxEvents", &MaxEvents, CUPSD_VARTYPE_INTEGER },
113 { "MaxHoldTime", &MaxHoldTime, CUPSD_VARTYPE_TIME },
114 { "MaxJobs", &MaxJobs, CUPSD_VARTYPE_INTEGER },
115 { "MaxJobsPerPrinter", &MaxJobsPerPrinter, CUPSD_VARTYPE_INTEGER },
116 { "MaxJobsPerUser", &MaxJobsPerUser, CUPSD_VARTYPE_INTEGER },
117 { "MaxJobTime", &MaxJobTime, CUPSD_VARTYPE_TIME },
118 { "MaxLeaseDuration", &MaxLeaseDuration, CUPSD_VARTYPE_TIME },
119 { "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_INTEGER },
120 { "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
121 { "MaxSubscriptions", &MaxSubscriptions, CUPSD_VARTYPE_INTEGER },
122 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER },
123 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER },
124 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser, CUPSD_VARTYPE_INTEGER },
125 { "MultipleOperationTimeout", &MultipleOperationTimeout, CUPSD_VARTYPE_TIME },
126 { "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_STRING },
127 { "PreserveJobFiles", &JobFiles, CUPSD_VARTYPE_TIME },
128 { "PreserveJobHistory", &JobHistory, CUPSD_VARTYPE_TIME },
129 { "ReloadTimeout", &ReloadTimeout, CUPSD_VARTYPE_TIME },
130 { "RIPCache", &RIPCache, CUPSD_VARTYPE_STRING },
131 { "RootCertDuration", &RootCertDuration, CUPSD_VARTYPE_TIME },
132 { "ServerAdmin", &ServerAdmin, CUPSD_VARTYPE_STRING },
133 { "ServerName", &ServerName, CUPSD_VARTYPE_STRING },
134 { "StrictConformance", &StrictConformance, CUPSD_VARTYPE_BOOLEAN },
135 { "Timeout", &Timeout, CUPSD_VARTYPE_TIME },
136 { "WebInterface", &WebInterface, CUPSD_VARTYPE_BOOLEAN }
137 };
138 static const cupsd_var_t cupsfiles_vars[] =
139 {
140 { "AccessLog", &AccessLog, CUPSD_VARTYPE_STRING },
141 { "CacheDir", &CacheDir, CUPSD_VARTYPE_STRING },
142 { "ConfigFilePerm", &ConfigFilePerm, CUPSD_VARTYPE_PERM },
143 { "DataDir", &DataDir, CUPSD_VARTYPE_STRING },
144 { "DocumentRoot", &DocumentRoot, CUPSD_VARTYPE_STRING },
145 { "ErrorLog", &ErrorLog, CUPSD_VARTYPE_STRING },
146 { "FileDevice", &FileDevice, CUPSD_VARTYPE_BOOLEAN },
147 { "FontPath", &FontPath, CUPSD_VARTYPE_STRING },
148 { "LogFilePerm", &LogFilePerm, CUPSD_VARTYPE_PERM },
149 { "LPDConfigFile", &LPDConfigFile, CUPSD_VARTYPE_STRING },
150 { "PageLog", &PageLog, CUPSD_VARTYPE_STRING },
151 { "Printcap", &Printcap, CUPSD_VARTYPE_STRING },
152 { "RemoteRoot", &RemoteRoot, CUPSD_VARTYPE_STRING },
153 { "RequestRoot", &RequestRoot, CUPSD_VARTYPE_STRING },
154 { "ServerBin", &ServerBin, CUPSD_VARTYPE_PATHNAME },
155 #ifdef HAVE_SSL
156 { "ServerKeychain", &ServerKeychain, CUPSD_VARTYPE_PATHNAME },
157 #endif /* HAVE_SSL */
158 { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_PATHNAME },
159 { "SMBConfigFile", &SMBConfigFile, CUPSD_VARTYPE_STRING },
160 { "StateDir", &StateDir, CUPSD_VARTYPE_STRING },
161 { "SyncOnClose", &SyncOnClose, CUPSD_VARTYPE_BOOLEAN },
162 #ifdef HAVE_AUTHORIZATION_H
163 { "SystemGroupAuthKey", &SystemGroupAuthKey, CUPSD_VARTYPE_STRING },
164 #endif /* HAVE_AUTHORIZATION_H */
165 { "TempDir", &TempDir, CUPSD_VARTYPE_PATHNAME }
166 };
167
168 static int default_auth_type = CUPSD_AUTH_AUTO;
169 /* Default AuthType, if not specified */
170
171 static const unsigned ones[4] =
172 {
173 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
174 };
175 static const unsigned zeros[4] =
176 {
177 0x00000000, 0x00000000, 0x00000000, 0x00000000
178 };
179
180
181 /*
182 * Local functions...
183 */
184
185 static http_addrlist_t *get_address(const char *value, int defport);
186 static int get_addr_and_mask(const char *value, unsigned *ip,
187 unsigned *mask);
188 static void mime_error_cb(void *ctx, const char *message);
189 static int parse_aaa(cupsd_location_t *loc, char *line,
190 char *value, int linenum);
191 static int parse_fatal_errors(const char *s);
192 static int parse_groups(const char *s);
193 static int parse_protocols(const char *s);
194 static int parse_variable(const char *filename, int linenum,
195 const char *line, const char *value,
196 size_t num_vars,
197 const cupsd_var_t *vars);
198 static int read_cupsd_conf(cups_file_t *fp);
199 static int read_cups_files_conf(cups_file_t *fp);
200 static int read_location(cups_file_t *fp, char *name, int linenum);
201 static int read_policy(cups_file_t *fp, char *name, int linenum);
202 static void set_policy_defaults(cupsd_policy_t *pol);
203
204
205 /*
206 * 'cupsdAddAlias()' - Add a host alias.
207 */
208
209 void
210 cupsdAddAlias(cups_array_t *aliases, /* I - Array of aliases */
211 const char *name) /* I - Name to add */
212 {
213 cupsd_alias_t *a; /* New alias */
214 size_t namelen; /* Length of name */
215
216
217 namelen = strlen(name);
218
219 if ((a = (cupsd_alias_t *)malloc(sizeof(cupsd_alias_t) + namelen)) == NULL)
220 return;
221
222 a->namelen = namelen;
223 memcpy(a->name, name, namelen + 1); /* OK since a->name is allocated */
224
225 cupsArrayAdd(aliases, a);
226 }
227
228
229 /*
230 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
231 */
232
233 int /* O - 0 on success, -1 on error, 1 on warning */
234 cupsdCheckPermissions(
235 const char *filename, /* I - File/directory name */
236 const char *suffix, /* I - Additional file/directory name */
237 mode_t mode, /* I - Permissions */
238 uid_t user, /* I - Owner */
239 gid_t group, /* I - Group */
240 int is_dir, /* I - 1 = directory, 0 = file */
241 int create_dir) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
242 {
243 int dir_created = 0; /* Did we create a directory? */
244 char pathname[1024]; /* File name with prefix */
245 struct stat fileinfo; /* Stat buffer */
246 int is_symlink; /* Is "filename" a symlink? */
247
248
249 /*
250 * Prepend the given root to the filename before testing it...
251 */
252
253 if (suffix)
254 {
255 snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
256 filename = pathname;
257 }
258
259 /*
260 * See if we can stat the file/directory...
261 */
262
263 if (lstat(filename, &fileinfo))
264 {
265 if (errno == ENOENT && create_dir)
266 {
267 if (create_dir > 0)
268 cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"",
269 filename);
270
271 if (mkdir(filename, mode))
272 {
273 if (create_dir > 0)
274 cupsdLogMessage(CUPSD_LOG_ERROR,
275 "Unable to create directory \"%s\" - %s", filename,
276 strerror(errno));
277 else
278 #ifdef HAVE_ASL_H
279 {
280 asl_object_t m; /* Log message */
281
282 m = asl_new(ASL_TYPE_MSG);
283 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
284 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
285 asl_release(m);
286 }
287 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
288 sd_journal_print(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
289 #else
290 syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
291 #endif /* HAVE_ASL_H */
292
293 return (-1);
294 }
295
296 dir_created = 1;
297 fileinfo.st_mode = mode | S_IFDIR;
298 }
299 else
300 return (create_dir ? -1 : 1);
301 }
302
303 if ((is_symlink = S_ISLNK(fileinfo.st_mode)) != 0)
304 {
305 if (stat(filename, &fileinfo))
306 {
307 cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is a bad symlink - %s",
308 filename, strerror(errno));
309 return (-1);
310 }
311 }
312
313 /*
314 * Make sure it's a regular file or a directory as needed...
315 */
316
317 if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
318 {
319 cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file.", filename);
320 return (-1);
321 }
322
323 if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
324 {
325 if (create_dir >= 0)
326 cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory.", filename);
327 else
328 #ifdef HAVE_ASL_H
329 {
330 asl_object_t m; /* Log message */
331
332 m = asl_new(ASL_TYPE_MSG);
333 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
334 asl_log(NULL, m, ASL_LEVEL_ERR, "\"%s\" is not a directory.", filename);
335 asl_release(m);
336 }
337 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
338 sd_journal_print(LOG_ERR, "\"%s\" is not a directory.", filename);
339 #else
340 syslog(LOG_ERR, "\"%s\" is not a directory.", filename);
341 #endif /* HAVE_ASL_H */
342
343 return (-1);
344 }
345
346 /*
347 * If the filename is a symlink, do not change permissions (STR #2937)...
348 */
349
350 if (is_symlink)
351 return (0);
352
353 /*
354 * Fix owner, group, and mode as needed...
355 */
356
357 if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
358 {
359 if (create_dir >= 0)
360 cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"",
361 filename);
362
363 if (chown(filename, user, group) && !getuid())
364 {
365 if (create_dir >= 0)
366 cupsdLogMessage(CUPSD_LOG_ERROR,
367 "Unable to change ownership of \"%s\" - %s", filename,
368 strerror(errno));
369 else
370 #ifdef HAVE_ASL_H
371 {
372 asl_object_t m; /* Log message */
373
374 m = asl_new(ASL_TYPE_MSG);
375 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
376 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
377 asl_release(m);
378 }
379 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
380 sd_journal_print(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
381 #else
382 syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
383 #endif /* HAVE_ASL_H */
384
385 return (1);
386 }
387 }
388
389 if (dir_created || (fileinfo.st_mode & 07777) != mode)
390 {
391 if (create_dir >= 0)
392 cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"",
393 filename);
394
395 if (chmod(filename, mode))
396 {
397 if (create_dir >= 0)
398 cupsdLogMessage(CUPSD_LOG_ERROR,
399 "Unable to change permissions of \"%s\" - %s", filename,
400 strerror(errno));
401 else
402 #ifdef HAVE_ASL_H
403 {
404 asl_object_t m; /* Log message */
405
406 m = asl_new(ASL_TYPE_MSG);
407 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
408 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
409 asl_release(m);
410 }
411 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
412 sd_journal_print(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
413 #else
414 syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
415 #endif /* HAVE_ASL_H */
416
417 return (1);
418 }
419 }
420
421 /*
422 * Everything is OK...
423 */
424
425 return (0);
426 }
427
428
429 /*
430 * 'cupsdDefaultAuthType()' - Get the default AuthType.
431 *
432 * When the default_auth_type is "auto", this function tries to get the GSS
433 * credentials for the server. If that succeeds we use Kerberos authentication,
434 * otherwise we do a fallback to Basic authentication against the local user
435 * accounts.
436 */
437
438 int /* O - Default AuthType value */
439 cupsdDefaultAuthType(void)
440 {
441 #ifdef HAVE_GSSAPI
442 OM_uint32 major_status, /* Major status code */
443 minor_status; /* Minor status code */
444 gss_name_t server_name; /* Server name */
445 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
446 /* Service name token */
447 char buf[1024]; /* Service name buffer */
448 #endif /* HAVE_GSSAPI */
449
450
451 /*
452 * If we have already determined the correct default AuthType, use it...
453 */
454
455 if (default_auth_type != CUPSD_AUTH_AUTO)
456 return (default_auth_type);
457
458 #ifdef HAVE_GSSAPI
459 # ifdef __APPLE__
460 /*
461 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
462 * to use it...
463 */
464
465 if (&gss_init_sec_context == NULL)
466 return (default_auth_type = CUPSD_AUTH_BASIC);
467 # endif /* __APPLE__ */
468
469 /*
470 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
471 * that fails we must use Basic...
472 */
473
474 snprintf(buf, sizeof(buf), "%s@%s", GSSServiceName, ServerName);
475
476 token.value = buf;
477 token.length = strlen(buf);
478 server_name = GSS_C_NO_NAME;
479 major_status = gss_import_name(&minor_status, &token,
480 GSS_C_NT_HOSTBASED_SERVICE,
481 &server_name);
482
483 memset(&token, 0, sizeof(token));
484
485 if (GSS_ERROR(major_status))
486 {
487 cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status,
488 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf);
489 return (default_auth_type = CUPSD_AUTH_BASIC);
490 }
491
492 major_status = gss_display_name(&minor_status, server_name, &token, NULL);
493
494 if (GSS_ERROR(major_status))
495 {
496 cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status,
497 "cupsdDefaultAuthType: gss_display_name(%s) failed",
498 buf);
499 return (default_auth_type = CUPSD_AUTH_BASIC);
500 }
501
502 cupsdLogMessage(CUPSD_LOG_DEBUG,
503 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
504 "credentials for %s...", (char *)token.value);
505
506 ServerCreds = GSS_C_NO_CREDENTIAL;
507 major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
508 GSS_C_NO_OID_SET, GSS_C_ACCEPT,
509 &ServerCreds, NULL, NULL);
510 if (GSS_ERROR(major_status))
511 {
512 cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status,
513 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
514 (char *)token.value);
515 gss_release_name(&minor_status, &server_name);
516 gss_release_buffer(&minor_status, &token);
517 return (default_auth_type = CUPSD_AUTH_BASIC);
518 }
519
520 cupsdLogMessage(CUPSD_LOG_DEBUG,
521 "cupsdDefaultAuthType: Kerberos credentials acquired "
522 "successfully for %s.", (char *)token.value);
523
524 gss_release_name(&minor_status, &server_name);
525 gss_release_buffer(&minor_status, &token);
526
527 HaveServerCreds = 1;
528
529 return (default_auth_type = CUPSD_AUTH_NEGOTIATE);
530
531 #else
532 /*
533 * No Kerberos support compiled in so just use Basic all the time...
534 */
535
536 return (default_auth_type = CUPSD_AUTH_BASIC);
537 #endif /* HAVE_GSSAPI */
538 }
539
540
541 /*
542 * 'cupsdFreeAliases()' - Free all of the alias entries.
543 */
544
545 void
546 cupsdFreeAliases(cups_array_t *aliases) /* I - Array of aliases */
547 {
548 cupsd_alias_t *a; /* Current alias */
549
550
551 for (a = (cupsd_alias_t *)cupsArrayFirst(aliases);
552 a;
553 a = (cupsd_alias_t *)cupsArrayNext(aliases))
554 free(a);
555
556 cupsArrayDelete(aliases);
557 }
558
559
560 /*
561 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
562 */
563
564 int /* O - 1 on success, 0 otherwise */
565 cupsdReadConfiguration(void)
566 {
567 int i; /* Looping var */
568 cups_file_t *fp; /* Configuration file */
569 int status; /* Return status */
570 char temp[1024], /* Temporary buffer */
571 mimedir[1024], /* MIME directory */
572 *slash; /* Directory separator */
573 cups_lang_t *language; /* Language */
574 struct passwd *user; /* Default user */
575 struct group *group; /* Default group */
576 char *old_serverroot, /* Old ServerRoot */
577 *old_requestroot; /* Old RequestRoot */
578 int old_remote_port; /* Old RemotePort */
579 const char *tmpdir; /* TMPDIR environment variable */
580 struct stat tmpinfo; /* Temporary directory info */
581 cupsd_policy_t *p; /* Policy */
582
583
584 /*
585 * Save the old root paths...
586 */
587
588 old_serverroot = NULL;
589 cupsdSetString(&old_serverroot, ServerRoot);
590 old_requestroot = NULL;
591 cupsdSetString(&old_requestroot, RequestRoot);
592
593 /*
594 * Reset the server configuration data...
595 */
596
597 cupsdDeleteAllLocations();
598
599 cupsdDeleteAllListeners();
600
601 old_remote_port = RemotePort;
602 RemotePort = 0;
603
604 /*
605 * String options...
606 */
607
608 cupsdFreeAliases(ServerAlias);
609 ServerAlias = NULL;
610
611 cupsdClearString(&ServerName);
612 cupsdClearString(&ServerAdmin);
613 cupsdSetString(&ServerBin, CUPS_SERVERBIN);
614 cupsdSetString(&RequestRoot, CUPS_REQUESTS);
615 cupsdSetString(&CacheDir, CUPS_CACHEDIR);
616 cupsdSetString(&DataDir, CUPS_DATADIR);
617 cupsdSetString(&DocumentRoot, CUPS_DOCROOT);
618 cupsdSetString(&AccessLog, CUPS_LOGDIR "/access_log");
619 cupsdClearString(&ErrorLog);
620 cupsdSetString(&PageLog, CUPS_LOGDIR "/page_log");
621 cupsdSetString(&PageLogFormat,
622 "%p %u %j %T %P %C %{job-billing} "
623 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
624 cupsdSetString(&Printcap, CUPS_DEFAULT_PRINTCAP);
625 cupsdSetString(&FontPath, CUPS_FONTPATH);
626 cupsdSetString(&RemoteRoot, "remroot");
627 cupsdSetStringf(&ServerHeader, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR,
628 CUPS_VERSION_MINOR);
629 cupsdSetString(&StateDir, CUPS_STATEDIR);
630
631 if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf"))
632 PrintcapFormat = PRINTCAP_SOLARIS;
633 else if (!strcmp(CUPS_DEFAULT_PRINTCAP,
634 "/Library/Preferences/org.cups.printers.plist"))
635 PrintcapFormat = PRINTCAP_PLIST;
636 else
637 PrintcapFormat = PRINTCAP_BSD;
638
639 strlcpy(temp, ConfigurationFile, sizeof(temp));
640 if ((slash = strrchr(temp, '/')) != NULL)
641 *slash = '\0';
642
643 cupsdSetString(&ServerRoot, temp);
644
645 cupsdClearString(&Classification);
646 ClassifyOverride = 0;
647
648 #ifdef HAVE_SSL
649 # ifdef HAVE_GNUTLS
650 cupsdSetString(&ServerKeychain, "ssl");
651 # else
652 cupsdSetString(&ServerKeychain, "/Library/Keychains/System.keychain");
653 # endif /* HAVE_GNUTLS */
654
655 _httpTLSSetOptions(0);
656 #endif /* HAVE_SSL */
657
658 language = cupsLangDefault();
659
660 if (!strcmp(language->language, "C") || !strcmp(language->language, "POSIX"))
661 cupsdSetString(&DefaultLanguage, "en");
662 else
663 cupsdSetString(&DefaultLanguage, language->language);
664
665 cupsdClearString(&DefaultPaperSize);
666
667 cupsdSetString(&RIPCache, "128m");
668
669 cupsdSetString(&TempDir, NULL);
670
671 #ifdef HAVE_GSSAPI
672 cupsdSetString(&GSSServiceName, CUPS_DEFAULT_GSSSERVICENAME);
673
674 if (HaveServerCreds)
675 {
676 OM_uint32 minor_status; /* Minor status code */
677
678 gss_release_cred(&minor_status, &ServerCreds);
679
680 HaveServerCreds = 0;
681 }
682
683 ServerCreds = GSS_C_NO_CREDENTIAL;
684 #endif /* HAVE_GSSAPI */
685
686 /*
687 * Find the default user...
688 */
689
690 if ((user = getpwnam(CUPS_DEFAULT_USER)) != NULL)
691 User = user->pw_uid;
692 else
693 {
694 /*
695 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
696 * complement number...)
697 */
698
699 User = 65534;
700 }
701
702 endpwent();
703
704 /*
705 * Find the default group...
706 */
707
708 group = getgrnam(CUPS_DEFAULT_GROUP);
709 endgrent();
710
711 if (group)
712 Group = group->gr_gid;
713 else
714 {
715 /*
716 * Fallback to group "nobody"...
717 */
718
719 group = getgrnam("nobody");
720 endgrent();
721
722 if (group)
723 Group = group->gr_gid;
724 else
725 {
726 /*
727 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
728 * complement number...)
729 */
730
731 Group = 65534;
732 }
733 }
734
735 /*
736 * Numeric options...
737 */
738
739 AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS;
740 ConfigFilePerm = CUPS_DEFAULT_CONFIG_FILE_PERM;
741 FatalErrors = parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS);
742 default_auth_type = CUPSD_AUTH_BASIC;
743 #ifdef HAVE_SSL
744 DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
745 #endif /* HAVE_SSL */
746 DirtyCleanInterval = DEFAULT_KEEPALIVE;
747 JobKillDelay = DEFAULT_TIMEOUT;
748 JobRetryLimit = 5;
749 JobRetryInterval = 300;
750 FileDevice = FALSE;
751 FilterLevel = 0;
752 FilterLimit = 0;
753 FilterNice = 0;
754 HostNameLookups = FALSE;
755 KeepAlive = TRUE;
756 KeepAliveTimeout = DEFAULT_KEEPALIVE;
757 ListenBackLog = SOMAXCONN;
758 LogDebugHistory = 200;
759 LogFilePerm = CUPS_DEFAULT_LOG_FILE_PERM;
760 LogLevel = CUPSD_LOG_WARN;
761 LogTimeFormat = CUPSD_TIME_STANDARD;
762 MaxClients = 100;
763 MaxClientsPerHost = 0;
764 MaxLogSize = 1024 * 1024;
765 MaxRequestSize = 0;
766 MultipleOperationTimeout = DEFAULT_TIMEOUT;
767 NumSystemGroups = 0;
768 ReloadTimeout = DEFAULT_KEEPALIVE;
769 RootCertDuration = 300;
770 Sandboxing = CUPSD_SANDBOXING_STRICT;
771 StrictConformance = FALSE;
772 SyncOnClose = FALSE;
773 Timeout = DEFAULT_TIMEOUT;
774 WebInterface = CUPS_DEFAULT_WEBIF;
775
776 BrowseLocalProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS);
777 BrowseWebIF = FALSE;
778 Browsing = CUPS_DEFAULT_BROWSING;
779 DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED;
780
781 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
782 cupsdSetString(&DNSSDSubTypes, "_cups,_print");
783 #endif /* HAVE_DNSSD || HAVE_AVAHI */
784
785 cupsdSetString(&LPDConfigFile, CUPS_DEFAULT_LPD_CONFIG_FILE);
786 cupsdSetString(&SMBConfigFile, CUPS_DEFAULT_SMB_CONFIG_FILE);
787
788 cupsdSetString(&ErrorPolicy, "stop-printer");
789
790 JobHistory = DEFAULT_HISTORY;
791 JobFiles = DEFAULT_FILES;
792 JobAutoPurge = 0;
793 MaxHoldTime = 0;
794 MaxJobs = 500;
795 MaxActiveJobs = 0;
796 MaxJobsPerUser = 0;
797 MaxJobsPerPrinter = 0;
798 MaxJobTime = 3 * 60 * 60; /* 3 hours */
799 MaxCopies = CUPS_DEFAULT_MAX_COPIES;
800
801 cupsdDeleteAllPolicies();
802 cupsdClearString(&DefaultPolicy);
803
804 #ifdef HAVE_AUTHORIZATION_H
805 cupsdSetString(&SystemGroupAuthKey, CUPS_DEFAULT_SYSTEM_AUTHKEY);
806 #endif /* HAVE_AUTHORIZATION_H */
807
808 MaxSubscriptions = 100;
809 MaxSubscriptionsPerJob = 0;
810 MaxSubscriptionsPerPrinter = 0;
811 MaxSubscriptionsPerUser = 0;
812 DefaultLeaseDuration = 86400;
813 MaxLeaseDuration = 0;
814
815 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
816 IdleExitTimeout = 60;
817 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
818
819 /*
820 * Setup environment variables...
821 */
822
823 cupsdInitEnv();
824
825 /*
826 * Read the cups-files.conf file...
827 */
828
829 if ((fp = cupsFileOpen(CupsFilesFile, "r")) != NULL)
830 {
831 status = read_cups_files_conf(fp);
832
833 cupsFileClose(fp);
834
835 if (!status)
836 {
837 if (TestConfigFile)
838 printf("\"%s\" contains errors.\n", CupsFilesFile);
839 else
840 #ifdef HAVE_ASL_H
841 {
842 asl_object_t m; /* Log message */
843
844 m = asl_new(ASL_TYPE_MSG);
845 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
846 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
847 asl_release(m);
848 }
849 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
850 sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
851 #else
852 syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
853 #endif /* HAVE_ASL_H */
854
855 return (0);
856 }
857 }
858 else if (errno == ENOENT)
859 cupsdLogMessage(CUPSD_LOG_INFO, "No %s, using defaults.", CupsFilesFile);
860 else
861 {
862 #ifdef HAVE_ASL_H
863 asl_object_t m; /* Log message */
864
865 m = asl_new(ASL_TYPE_MSG);
866 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
867 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
868 asl_release(m);
869
870 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
871 sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
872 #else
873 syslog(LOG_LPR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
874 #endif /* HAVE_ASL_H */
875
876 return (0);
877 }
878
879 if (!ErrorLog)
880 cupsdSetString(&ErrorLog, CUPS_LOGDIR "/error_log");
881
882 /*
883 * Read the cupsd.conf file...
884 */
885
886 if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
887 {
888 #ifdef HAVE_ASL_H
889 asl_object_t m; /* Log message */
890
891 m = asl_new(ASL_TYPE_MSG);
892 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
893 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
894 asl_release(m);
895 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
896 sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
897 #else
898 syslog(LOG_LPR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
899 #endif /* HAVE_ASL_H */
900
901 return (0);
902 }
903
904 status = read_cupsd_conf(fp);
905
906 cupsFileClose(fp);
907
908 if (!status)
909 {
910 if (TestConfigFile)
911 printf("\"%s\" contains errors.\n", ConfigurationFile);
912 else
913 #ifdef HAVE_ASL_H
914 {
915 asl_object_t m; /* Log message */
916
917 m = asl_new(ASL_TYPE_MSG);
918 asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
919 asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
920 asl_release(m);
921 }
922 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
923 sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
924 #else
925 syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
926 #endif /* HAVE_ASL_H */
927
928 return (0);
929 }
930
931 RunUser = getuid();
932
933 cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
934 RemotePort ? "enabled" : "disabled");
935
936 if (!RemotePort)
937 BrowseLocalProtocols = 0; /* Disable sharing - no remote access */
938
939 /*
940 * See if the ServerName is an IP address...
941 */
942
943 if (ServerName)
944 {
945 if (!ServerAlias)
946 ServerAlias = cupsArrayNew(NULL, NULL);
947
948 cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", ServerName);
949 }
950 else
951 {
952 if (gethostname(temp, sizeof(temp)))
953 {
954 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s",
955 strerror(errno));
956 strlcpy(temp, "localhost", sizeof(temp));
957 }
958
959 cupsdSetString(&ServerName, temp);
960
961 if (!ServerAlias)
962 ServerAlias = cupsArrayNew(NULL, NULL);
963
964 cupsdAddAlias(ServerAlias, temp);
965 cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp);
966
967 if (HostNameLookups || RemotePort)
968 {
969 struct hostent *host; /* Host entry to get FQDN */
970
971 if ((host = gethostbyname(temp)) != NULL)
972 {
973 if (_cups_strcasecmp(temp, host->h_name))
974 {
975 cupsdSetString(&ServerName, host->h_name);
976 cupsdAddAlias(ServerAlias, host->h_name);
977 cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s",
978 host->h_name);
979 }
980
981 if (host->h_aliases)
982 {
983 for (i = 0; host->h_aliases[i]; i ++)
984 if (_cups_strcasecmp(temp, host->h_aliases[i]))
985 {
986 cupsdAddAlias(ServerAlias, host->h_aliases[i]);
987 cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s",
988 host->h_aliases[i]);
989 }
990 }
991 }
992 }
993
994 /*
995 * Make sure we have the base hostname added as an alias, too!
996 */
997
998 if ((slash = strchr(temp, '.')) != NULL)
999 {
1000 *slash = '\0';
1001 cupsdAddAlias(ServerAlias, temp);
1002 cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp);
1003 }
1004 }
1005
1006 for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
1007
1008 ServerNameIsIP = !*slash;
1009
1010 /*
1011 * Make sure ServerAdmin is initialized...
1012 */
1013
1014 if (!ServerAdmin)
1015 cupsdSetStringf(&ServerAdmin, "root@%s", ServerName);
1016
1017 /*
1018 * Use the default system group if none was supplied in cupsd.conf...
1019 */
1020
1021 if (NumSystemGroups == 0)
1022 {
1023 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS))
1024 {
1025 /*
1026 * Find the group associated with GID 0...
1027 */
1028
1029 group = getgrgid(0);
1030 endgrent();
1031
1032 if (group != NULL)
1033 cupsdSetString(&SystemGroups[0], group->gr_name);
1034 else
1035 cupsdSetString(&SystemGroups[0], "unknown");
1036
1037 SystemGroupIDs[0] = 0;
1038 NumSystemGroups = 1;
1039 }
1040 }
1041
1042 /*
1043 * Make sure ConfigFilePerm and LogFilePerm have sane values...
1044 */
1045
1046 ConfigFilePerm &= 0664;
1047 LogFilePerm &= 0664;
1048
1049 /*
1050 * Open the system log for cupsd if necessary...
1051 */
1052
1053 if (!LogStderr)
1054 {
1055 if (!strcmp(AccessLog, "stderr"))
1056 cupsdSetString(&AccessLog, "syslog");
1057
1058 if (!strcmp(ErrorLog, "stderr"))
1059 cupsdSetString(&ErrorLog, "syslog");
1060
1061 if (!strcmp(PageLog, "stderr"))
1062 cupsdSetString(&PageLog, "syslog");
1063 }
1064
1065 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1066 if (!strcmp(AccessLog, "syslog") ||
1067 !strcmp(ErrorLog, "syslog") ||
1068 !strcmp(PageLog, "syslog"))
1069 openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR);
1070 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1071
1072 /*
1073 * Make sure each of the log files exists and gets rotated as necessary...
1074 */
1075
1076 if (strcmp(AccessLog, "syslog"))
1077 cupsdCheckLogFile(&AccessFile, AccessLog);
1078
1079 if (strcmp(ErrorLog, "syslog"))
1080 cupsdCheckLogFile(&ErrorFile, ErrorLog);
1081
1082 if (strcmp(PageLog, "syslog"))
1083 cupsdCheckLogFile(&PageFile, PageLog);
1084
1085 /*
1086 * Log the configuration file that was used...
1087 */
1088
1089 cupsdLogMessage(CUPSD_LOG_INFO, "Loaded configuration file \"%s\"",
1090 ConfigurationFile);
1091
1092 /*
1093 * Validate the Group and SystemGroup settings - they cannot be the same,
1094 * otherwise the CGI programs will be able to authenticate as root without
1095 * a password!
1096 */
1097
1098 if (!RunUser)
1099 {
1100 for (i = 0; i < NumSystemGroups; i ++)
1101 if (Group == SystemGroupIDs[i])
1102 break;
1103
1104 if (i < NumSystemGroups)
1105 {
1106 /*
1107 * Log the error and reset the group to a safe value...
1108 */
1109
1110 cupsdLogMessage(CUPSD_LOG_ERROR,
1111 "Group and SystemGroup cannot use the same groups.");
1112 if (FatalErrors & (CUPSD_FATAL_CONFIG | CUPSD_FATAL_PERMISSIONS))
1113 return (0);
1114
1115 cupsdLogMessage(CUPSD_LOG_INFO, "Resetting Group to \"nobody\"...");
1116
1117 group = getgrnam("nobody");
1118 endgrent();
1119
1120 if (group != NULL)
1121 Group = group->gr_gid;
1122 else
1123 {
1124 /*
1125 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1126 * complement number...)
1127 */
1128
1129 Group = 65534;
1130 }
1131 }
1132 }
1133
1134 /*
1135 * Check that we have at least one listen/port line; if not, report this
1136 * as an error and exit!
1137 */
1138
1139 if (cupsArrayCount(Listeners) == 0)
1140 {
1141 /*
1142 * No listeners!
1143 */
1144
1145 cupsdLogMessage(CUPSD_LOG_EMERG,
1146 "No valid Listen or Port lines were found in the "
1147 "configuration file.");
1148
1149 /*
1150 * Commit suicide...
1151 */
1152
1153 cupsdEndProcess(getpid(), 0);
1154 }
1155
1156 /*
1157 * Set the default locale using the language and charset...
1158 */
1159
1160 cupsdSetStringf(&DefaultLocale, "%s.UTF-8", DefaultLanguage);
1161
1162 /*
1163 * Update all relative filenames to include the full path from ServerRoot...
1164 */
1165
1166 if (DocumentRoot[0] != '/')
1167 cupsdSetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot);
1168
1169 if (RequestRoot[0] != '/')
1170 cupsdSetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot);
1171
1172 if (ServerBin[0] != '/')
1173 cupsdSetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin);
1174
1175 if (StateDir[0] != '/')
1176 cupsdSetStringf(&StateDir, "%s/%s", ServerRoot, StateDir);
1177
1178 if (CacheDir[0] != '/')
1179 cupsdSetStringf(&CacheDir, "%s/%s", ServerRoot, CacheDir);
1180
1181 #ifdef HAVE_SSL
1182 if (ServerKeychain[0] != '/')
1183 cupsdSetStringf(&ServerKeychain, "%s/%s", ServerRoot, ServerKeychain);
1184
1185 cupsdLogMessage(CUPSD_LOG_DEBUG, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain, ServerName);
1186 cupsSetServerCredentials(ServerKeychain, ServerName, 1);
1187 #endif /* HAVE_SSL */
1188
1189 /*
1190 * Make sure that directories and config files are owned and
1191 * writable by the user and group in the cupsd.conf file...
1192 */
1193
1194 snprintf(temp, sizeof(temp), "%s/rss", CacheDir);
1195
1196 if ((cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser,
1197 Group, 1, 1) < 0 ||
1198 cupsdCheckPermissions(CacheDir, NULL, 0770, RunUser,
1199 Group, 1, 1) < 0 ||
1200 cupsdCheckPermissions(temp, NULL, 0775, RunUser,
1201 Group, 1, 1) < 0 ||
1202 cupsdCheckPermissions(StateDir, NULL, 0755, RunUser,
1203 Group, 1, 1) < 0 ||
1204 cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
1205 SystemGroupIDs[0], 1, 1) < 0 ||
1206 cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser,
1207 Group, 1, 0) < 0 ||
1208 cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser,
1209 Group, 1, 1) < 0 ||
1210 cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser,
1211 Group, 1, 0) < 0 ||
1212 cupsdCheckPermissions(ConfigurationFile, NULL, ConfigFilePerm, RunUser,
1213 Group, 0, 0) < 0 ||
1214 cupsdCheckPermissions(CupsFilesFile, NULL, ConfigFilePerm, RunUser,
1215 Group, 0, 0) < 0 ||
1216 cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser,
1217 Group, 0, 0) < 0 ||
1218 cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser,
1219 Group, 0, 0) < 0 ||
1220 cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User,
1221 Group, 0, 0) < 0) &&
1222 (FatalErrors & CUPSD_FATAL_PERMISSIONS))
1223 return (0);
1224
1225 /*
1226 * Update TempDir to the default if it hasn't been set already...
1227 */
1228
1229 #ifdef __APPLE__
1230 if (TempDir && !RunUser &&
1231 (!strncmp(TempDir, "/private/tmp", 12) || !strncmp(TempDir, "/tmp", 4)))
1232 {
1233 cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot use %s for TempDir.", TempDir);
1234 cupsdClearString(&TempDir);
1235 }
1236 #endif /* __APPLE__ */
1237
1238 if (!TempDir)
1239 {
1240 #ifdef __APPLE__
1241 if ((tmpdir = getenv("TMPDIR")) != NULL &&
1242 strncmp(tmpdir, "/private/tmp", 12) && strncmp(tmpdir, "/tmp", 4))
1243 #else
1244 if ((tmpdir = getenv("TMPDIR")) != NULL)
1245 #endif /* __APPLE__ */
1246 {
1247 /*
1248 * TMPDIR is defined, see if it is OK for us to use...
1249 */
1250
1251 if (stat(tmpdir, &tmpinfo))
1252 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s",
1253 tmpdir, strerror(errno));
1254 else if (!S_ISDIR(tmpinfo.st_mode))
1255 cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory.",
1256 tmpdir);
1257 else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) &&
1258 (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) &&
1259 !(tmpinfo.st_mode & S_IWOTH))
1260 cupsdLogMessage(CUPSD_LOG_ERROR,
1261 "TMPDIR (%s) has the wrong permissions.", tmpdir);
1262 else
1263 cupsdSetString(&TempDir, tmpdir);
1264 }
1265 }
1266
1267 if (!TempDir)
1268 {
1269 cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...",
1270 RequestRoot);
1271 cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot);
1272 }
1273
1274 setenv("TMPDIR", TempDir, 1);
1275
1276 /*
1277 * Make sure the temporary directory has the right permissions...
1278 */
1279
1280 if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) ||
1281 access(TempDir, 0))
1282 {
1283 /*
1284 * Update ownership and permissions if the CUPS temp directory
1285 * is under the spool directory or does not exist...
1286 */
1287
1288 if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 &&
1289 (FatalErrors & CUPSD_FATAL_PERMISSIONS))
1290 return (0);
1291 }
1292
1293 /*
1294 * Update environment variables...
1295 */
1296
1297 cupsdUpdateEnv();
1298
1299 /*
1300 * Validate the default error policy...
1301 */
1302
1303 if (strcmp(ErrorPolicy, "retry-current-job") &&
1304 strcmp(ErrorPolicy, "abort-job") &&
1305 strcmp(ErrorPolicy, "retry-job") &&
1306 strcmp(ErrorPolicy, "stop-printer"))
1307 {
1308 cupsdLogMessage(CUPSD_LOG_ALERT, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy);
1309 cupsdSetString(&ErrorPolicy, "stop-printer");
1310 }
1311
1312 /*
1313 * Update default paper size setting as needed...
1314 */
1315
1316 if (!DefaultPaperSize)
1317 {
1318 #ifdef HAVE_LIBPAPER
1319 char *paper_result; /* Paper size name from libpaper */
1320
1321 if ((paper_result = systempapername()) != NULL)
1322 cupsdSetString(&DefaultPaperSize, paper_result);
1323 else
1324 #endif /* HAVE_LIBPAPER */
1325 if (!DefaultLanguage ||
1326 !_cups_strcasecmp(DefaultLanguage, "C") ||
1327 !_cups_strcasecmp(DefaultLanguage, "POSIX") ||
1328 !_cups_strcasecmp(DefaultLanguage, "en") ||
1329 !_cups_strncasecmp(DefaultLanguage, "en.", 3) ||
1330 !_cups_strncasecmp(DefaultLanguage, "en_US", 5) ||
1331 !_cups_strncasecmp(DefaultLanguage, "en_CA", 5) ||
1332 !_cups_strncasecmp(DefaultLanguage, "fr_CA", 5))
1333 {
1334 /*
1335 * These are the only locales that will default to "letter" size...
1336 */
1337
1338 cupsdSetString(&DefaultPaperSize, "Letter");
1339 }
1340 else
1341 cupsdSetString(&DefaultPaperSize, "A4");
1342 }
1343
1344 /*
1345 * Update classification setting as needed...
1346 */
1347
1348 if (Classification && !_cups_strcasecmp(Classification, "none"))
1349 cupsdClearString(&Classification);
1350
1351 if (Classification)
1352 cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
1353
1354 /*
1355 * Check the MaxClients setting, and then allocate memory for it...
1356 */
1357
1358 if (MaxClients > (MaxFDs / 3) || MaxClients <= 0)
1359 {
1360 if (MaxClients > 0)
1361 cupsdLogMessage(CUPSD_LOG_INFO,
1362 "MaxClients limited to 1/3 (%d) of the file descriptor "
1363 "limit (%d)...",
1364 MaxFDs / 3, MaxFDs);
1365
1366 MaxClients = MaxFDs / 3;
1367 }
1368
1369 cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
1370 MaxClients);
1371
1372 /*
1373 * Check the MaxActiveJobs setting; limit to 1/3 the available
1374 * file descriptors, since we need a pipe for each job...
1375 */
1376
1377 if (MaxActiveJobs > (MaxFDs / 3))
1378 MaxActiveJobs = MaxFDs / 3;
1379
1380 /*
1381 * Update the MaxClientsPerHost value, as needed...
1382 */
1383
1384 if (MaxClientsPerHost <= 0)
1385 MaxClientsPerHost = MaxClients;
1386
1387 if (MaxClientsPerHost > MaxClients)
1388 MaxClientsPerHost = MaxClients;
1389
1390 cupsdLogMessage(CUPSD_LOG_INFO,
1391 "Allowing up to %d client connections per host.",
1392 MaxClientsPerHost);
1393
1394 /*
1395 * Update the default policy, as needed...
1396 */
1397
1398 if (DefaultPolicy)
1399 DefaultPolicyPtr = cupsdFindPolicy(DefaultPolicy);
1400 else
1401 DefaultPolicyPtr = NULL;
1402
1403 if (!DefaultPolicyPtr)
1404 {
1405 cupsd_location_t *po; /* New policy operation */
1406
1407
1408 if (DefaultPolicy)
1409 cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found.",
1410 DefaultPolicy);
1411
1412 cupsdSetString(&DefaultPolicy, "default");
1413
1414 if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL)
1415 cupsdLogMessage(CUPSD_LOG_INFO,
1416 "Using policy \"default\" as the default.");
1417 else
1418 {
1419 cupsdLogMessage(CUPSD_LOG_INFO,
1420 "Creating CUPS default administrative policy:");
1421
1422 DefaultPolicyPtr = p = cupsdAddPolicy("default");
1423
1424 cupsdLogMessage(CUPSD_LOG_INFO, "<Policy default>");
1425
1426 cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateAccess default");
1427 cupsdAddString(&(p->job_access), "@OWNER");
1428 cupsdAddString(&(p->job_access), "@SYSTEM");
1429
1430 cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateValues default");
1431 cupsdAddString(&(p->job_attrs), "job-name");
1432 cupsdAddString(&(p->job_attrs), "job-originating-host-name");
1433 cupsdAddString(&(p->job_attrs), "job-originating-user-name");
1434 cupsdAddString(&(p->job_attrs), "phone");
1435
1436 cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateAccess default");
1437 cupsdAddString(&(p->sub_access), "@OWNER");
1438 cupsdAddString(&(p->sub_access), "@SYSTEM");
1439
1440 cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateValues default");
1441 cupsdAddString(&(p->job_attrs), "notify-events");
1442 cupsdAddString(&(p->job_attrs), "notify-pull-method");
1443 cupsdAddString(&(p->job_attrs), "notify-recipient-uri");
1444 cupsdAddString(&(p->job_attrs), "notify-subscriber-user-name");
1445 cupsdAddString(&(p->job_attrs), "notify-user-data");
1446
1447 cupsdLogMessage(CUPSD_LOG_INFO,
1448 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1449 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1450
1451 po = cupsdAddPolicyOp(p, NULL, IPP_CREATE_JOB);
1452 po->order_type = CUPSD_AUTH_ALLOW;
1453
1454 cupsdAddPolicyOp(p, po, IPP_PRINT_JOB);
1455 cupsdAddPolicyOp(p, po, IPP_PRINT_URI);
1456 cupsdAddPolicyOp(p, po, IPP_VALIDATE_JOB);
1457
1458 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1459
1460 cupsdLogMessage(CUPSD_LOG_INFO,
1461 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1462 "Release-Job Restart-Job Purge-Jobs "
1463 "Set-Job-Attributes Create-Job-Subscription "
1464 "Renew-Subscription Cancel-Subscription "
1465 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1466 "Suspend-Current-Job Resume-Job "
1467 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1468 "CUPS-Authenticate-Job CUPS-Get-Document>");
1469 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1470
1471 po = cupsdAddPolicyOp(p, NULL, IPP_SEND_DOCUMENT);
1472 po->order_type = CUPSD_AUTH_ALLOW;
1473 po->level = CUPSD_AUTH_USER;
1474
1475 cupsdAddName(po, "@OWNER");
1476 cupsdAddName(po, "@SYSTEM");
1477 cupsdLogMessage(CUPSD_LOG_INFO, "Require user @OWNER @SYSTEM");
1478
1479 cupsdAddPolicyOp(p, po, IPP_SEND_URI);
1480 cupsdAddPolicyOp(p, po, IPP_CANCEL_JOB);
1481 cupsdAddPolicyOp(p, po, IPP_HOLD_JOB);
1482 cupsdAddPolicyOp(p, po, IPP_RELEASE_JOB);
1483 cupsdAddPolicyOp(p, po, IPP_RESTART_JOB);
1484 cupsdAddPolicyOp(p, po, IPP_PURGE_JOBS);
1485 cupsdAddPolicyOp(p, po, IPP_SET_JOB_ATTRIBUTES);
1486 cupsdAddPolicyOp(p, po, IPP_CREATE_JOB_SUBSCRIPTION);
1487 cupsdAddPolicyOp(p, po, IPP_RENEW_SUBSCRIPTION);
1488 cupsdAddPolicyOp(p, po, IPP_CANCEL_SUBSCRIPTION);
1489 cupsdAddPolicyOp(p, po, IPP_GET_NOTIFICATIONS);
1490 cupsdAddPolicyOp(p, po, IPP_REPROCESS_JOB);
1491 cupsdAddPolicyOp(p, po, IPP_CANCEL_CURRENT_JOB);
1492 cupsdAddPolicyOp(p, po, IPP_SUSPEND_CURRENT_JOB);
1493 cupsdAddPolicyOp(p, po, IPP_RESUME_JOB);
1494 cupsdAddPolicyOp(p, po, IPP_CANCEL_MY_JOBS);
1495 cupsdAddPolicyOp(p, po, IPP_CLOSE_JOB);
1496 cupsdAddPolicyOp(p, po, CUPS_MOVE_JOB);
1497 cupsdAddPolicyOp(p, po, CUPS_AUTHENTICATE_JOB);
1498 cupsdAddPolicyOp(p, po, CUPS_GET_DOCUMENT);
1499
1500 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1501
1502 cupsdLogMessage(CUPSD_LOG_INFO,
1503 "<Limit Pause-Printer Resume-Printer "
1504 "Set-Printer-Attributes Enable-Printer "
1505 "Disable-Printer Pause-Printer-After-Current-Job "
1506 "Hold-New-Jobs Release-Held-New-Jobs "
1507 "Deactivate-Printer Activate-Printer Restart-Printer "
1508 "Shutdown-Printer Startup-Printer Promote-Job "
1509 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1510 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1511 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1512 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1513 cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Default");
1514
1515 po = cupsdAddPolicyOp(p, NULL, IPP_PAUSE_PRINTER);
1516 po->order_type = CUPSD_AUTH_ALLOW;
1517 po->type = CUPSD_AUTH_DEFAULT;
1518 po->level = CUPSD_AUTH_USER;
1519
1520 cupsdAddName(po, "@SYSTEM");
1521 cupsdLogMessage(CUPSD_LOG_INFO, "Require user @SYSTEM");
1522
1523 cupsdAddPolicyOp(p, po, IPP_RESUME_PRINTER);
1524 cupsdAddPolicyOp(p, po, IPP_SET_PRINTER_ATTRIBUTES);
1525 cupsdAddPolicyOp(p, po, IPP_ENABLE_PRINTER);
1526 cupsdAddPolicyOp(p, po, IPP_DISABLE_PRINTER);
1527 cupsdAddPolicyOp(p, po, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB);
1528 cupsdAddPolicyOp(p, po, IPP_HOLD_NEW_JOBS);
1529 cupsdAddPolicyOp(p, po, IPP_RELEASE_HELD_NEW_JOBS);
1530 cupsdAddPolicyOp(p, po, IPP_DEACTIVATE_PRINTER);
1531 cupsdAddPolicyOp(p, po, IPP_ACTIVATE_PRINTER);
1532 cupsdAddPolicyOp(p, po, IPP_RESTART_PRINTER);
1533 cupsdAddPolicyOp(p, po, IPP_SHUTDOWN_PRINTER);
1534 cupsdAddPolicyOp(p, po, IPP_STARTUP_PRINTER);
1535 cupsdAddPolicyOp(p, po, IPP_PROMOTE_JOB);
1536 cupsdAddPolicyOp(p, po, IPP_SCHEDULE_JOB_AFTER);
1537 cupsdAddPolicyOp(p, po, IPP_CANCEL_JOBS);
1538 cupsdAddPolicyOp(p, po, CUPS_ADD_PRINTER);
1539 cupsdAddPolicyOp(p, po, CUPS_DELETE_PRINTER);
1540 cupsdAddPolicyOp(p, po, CUPS_ADD_CLASS);
1541 cupsdAddPolicyOp(p, po, CUPS_DELETE_CLASS);
1542 cupsdAddPolicyOp(p, po, CUPS_ACCEPT_JOBS);
1543 cupsdAddPolicyOp(p, po, CUPS_REJECT_JOBS);
1544 cupsdAddPolicyOp(p, po, CUPS_SET_DEFAULT);
1545
1546 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1547
1548 cupsdLogMessage(CUPSD_LOG_INFO, "<Limit All>");
1549 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1550
1551 po = cupsdAddPolicyOp(p, NULL, IPP_ANY_OPERATION);
1552 po->order_type = CUPSD_AUTH_ALLOW;
1553
1554 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1555 cupsdLogMessage(CUPSD_LOG_INFO, "</Policy>");
1556 }
1557 }
1558
1559 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d",
1560 cupsArrayCount(Policies));
1561 for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
1562 p;
1563 i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
1564 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1565 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i, p->name);
1566
1567 /*
1568 * If we are doing a full reload or the server root has changed, flush
1569 * the jobs, printers, etc. and start from scratch...
1570 */
1571
1572 if (NeedReload == RELOAD_ALL ||
1573 old_remote_port != RemotePort ||
1574 !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) ||
1575 !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot))
1576 {
1577 mime_type_t *type; /* Current type */
1578 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE];
1579 /* MIME type name */
1580
1581
1582 cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required.");
1583
1584 /*
1585 * Free all memory...
1586 */
1587
1588 cupsdDeleteAllSubscriptions();
1589 cupsdFreeAllJobs();
1590 cupsdDeleteAllPrinters();
1591
1592 DefaultPrinter = NULL;
1593
1594 if (MimeDatabase != NULL)
1595 mimeDelete(MimeDatabase);
1596
1597 if (NumMimeTypes)
1598 {
1599 for (i = 0; i < NumMimeTypes; i ++)
1600 _cupsStrFree(MimeTypes[i]);
1601
1602 free(MimeTypes);
1603 }
1604
1605 /*
1606 * Read the MIME type and conversion database...
1607 */
1608
1609 snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
1610 snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
1611
1612 MimeDatabase = mimeNew();
1613 mimeSetErrorCallback(MimeDatabase, mime_error_cb, NULL);
1614
1615 MimeDatabase = mimeLoadTypes(MimeDatabase, mimedir);
1616 MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
1617 MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
1618 MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
1619
1620 if (!MimeDatabase)
1621 {
1622 cupsdLogMessage(CUPSD_LOG_EMERG,
1623 "Unable to load MIME database from \"%s\" or \"%s\".",
1624 mimedir, ServerRoot);
1625 if (FatalErrors & CUPSD_FATAL_CONFIG)
1626 return (0);
1627 }
1628
1629 cupsdLogMessage(CUPSD_LOG_INFO,
1630 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1631 "%d filters...", mimedir, ServerRoot,
1632 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
1633
1634 /*
1635 * Create a list of MIME types for the document-format-supported
1636 * attribute...
1637 */
1638
1639 NumMimeTypes = mimeNumTypes(MimeDatabase);
1640 if (!mimeType(MimeDatabase, "application", "octet-stream"))
1641 NumMimeTypes ++;
1642
1643 if ((MimeTypes = calloc((size_t)NumMimeTypes, sizeof(const char *))) == NULL)
1644 {
1645 cupsdLogMessage(CUPSD_LOG_ERROR,
1646 "Unable to allocate memory for %d MIME types.",
1647 NumMimeTypes);
1648 NumMimeTypes = 0;
1649 }
1650 else
1651 {
1652 for (i = 0, type = mimeFirstType(MimeDatabase);
1653 type;
1654 i ++, type = mimeNextType(MimeDatabase))
1655 {
1656 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
1657
1658 MimeTypes[i] = _cupsStrAlloc(mimetype);
1659 }
1660
1661 if (i < NumMimeTypes)
1662 MimeTypes[i] = _cupsStrAlloc("application/octet-stream");
1663 }
1664
1665 if (LogLevel == CUPSD_LOG_DEBUG2)
1666 {
1667 mime_filter_t *filter; /* Current filter */
1668
1669
1670 for (type = mimeFirstType(MimeDatabase);
1671 type;
1672 type = mimeNextType(MimeDatabase))
1673 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s",
1674 type->super, type->type);
1675
1676 for (filter = mimeFirstFilter(MimeDatabase);
1677 filter;
1678 filter = mimeNextFilter(MimeDatabase))
1679 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1680 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1681 filter->src->super, filter->src->type,
1682 filter->dst->super, filter->dst->type,
1683 filter->cost, filter->filter);
1684 }
1685
1686 /*
1687 * Load banners...
1688 */
1689
1690 snprintf(temp, sizeof(temp), "%s/banners", DataDir);
1691 cupsdLoadBanners(temp);
1692
1693 /*
1694 * Load printers and classes...
1695 */
1696
1697 cupsdLoadAllPrinters();
1698 cupsdLoadAllClasses();
1699
1700 cupsdCreateCommonData();
1701
1702 /*
1703 * Update the printcap file as needed...
1704 */
1705
1706 if (Printcap && *Printcap && access(Printcap, 0))
1707 cupsdWritePrintcap();
1708
1709 /*
1710 * Load queued jobs...
1711 */
1712
1713 cupsdLoadAllJobs();
1714
1715 /*
1716 * Load subscriptions...
1717 */
1718
1719 cupsdLoadAllSubscriptions();
1720
1721 cupsdLogMessage(CUPSD_LOG_INFO, "Full reload complete.");
1722 }
1723 else
1724 {
1725 /*
1726 * Not a full reload, so recreate the common printer attributes...
1727 */
1728
1729 cupsdCreateCommonData();
1730
1731 /*
1732 * Update all jobs as needed...
1733 */
1734
1735 cupsdUpdateJobs();
1736
1737 /*
1738 * Update all printers as needed...
1739 */
1740
1741 cupsdUpdatePrinters();
1742 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
1743
1744 cupsdLogMessage(CUPSD_LOG_INFO, "Partial reload complete.");
1745 }
1746
1747 /*
1748 * Reset the reload state...
1749 */
1750
1751 NeedReload = RELOAD_NONE;
1752
1753 cupsdClearString(&old_serverroot);
1754 cupsdClearString(&old_requestroot);
1755
1756 return (1);
1757 }
1758
1759
1760 /*
1761 * 'get_address()' - Get an address + port number from a line.
1762 */
1763
1764 static http_addrlist_t * /* O - Pointer to list if address good, NULL if bad */
1765 get_address(const char *value, /* I - Value string */
1766 int defport) /* I - Default port */
1767 {
1768 char buffer[1024], /* Hostname + port number buffer */
1769 defpname[255], /* Default port name */
1770 *hostname, /* Hostname or IP */
1771 *portname; /* Port number or name */
1772 http_addrlist_t *addrlist; /* Address list */
1773
1774
1775 /*
1776 * Check for an empty value...
1777 */
1778
1779 if (!*value)
1780 {
1781 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad (empty) address.");
1782 return (NULL);
1783 }
1784
1785 /*
1786 * Grab a hostname and port number; if there is no colon and the port name
1787 * is only digits, then we have a port number by itself...
1788 */
1789
1790 strlcpy(buffer, value, sizeof(buffer));
1791
1792 if ((portname = strrchr(buffer, ':')) != NULL && !strchr(portname, ']'))
1793 {
1794 *portname++ = '\0';
1795 hostname = buffer;
1796 }
1797 else
1798 {
1799 for (portname = buffer; isdigit(*portname & 255); portname ++);
1800
1801 if (*portname)
1802 {
1803 /*
1804 * Use the default port...
1805 */
1806
1807 sprintf(defpname, "%d", defport);
1808 portname = defpname;
1809 hostname = buffer;
1810 }
1811 else
1812 {
1813 /*
1814 * The buffer contains just a port number...
1815 */
1816
1817 portname = buffer;
1818 hostname = NULL;
1819 }
1820 }
1821
1822 if (hostname && !strcmp(hostname, "*"))
1823 hostname = NULL;
1824
1825 /*
1826 * Now lookup the address using httpAddrGetList()...
1827 */
1828
1829 if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
1830 cupsdLogMessage(CUPSD_LOG_ERROR, "Hostname lookup for \"%s\" failed.",
1831 hostname ? hostname : "(nil)");
1832
1833 return (addrlist);
1834 }
1835
1836
1837 /*
1838 * 'get_addr_and_mask()' - Get an IP address and netmask.
1839 */
1840
1841 static int /* O - 1 on success, 0 on failure */
1842 get_addr_and_mask(const char *value, /* I - String from config file */
1843 unsigned *ip, /* O - Address value */
1844 unsigned *mask) /* O - Mask value */
1845 {
1846 int i, j, /* Looping vars */
1847 family, /* Address family */
1848 ipcount; /* Count of fields in address */
1849 unsigned ipval; /* Value */
1850 const char *maskval, /* Pointer to start of mask value */
1851 *ptr, /* Pointer into value */
1852 *ptr2; /* ... */
1853
1854
1855 /*
1856 * Get the address...
1857 */
1858
1859 ip[0] = ip[1] = ip[2] = ip[3] = 0x00000000;
1860 mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff;
1861
1862 if ((maskval = strchr(value, '/')) != NULL)
1863 maskval ++;
1864 else
1865 maskval = value + strlen(value);
1866
1867 #ifdef AF_INET6
1868 /*
1869 * Check for an IPv6 address...
1870 */
1871
1872 if (*value == '[')
1873 {
1874 /*
1875 * Parse hexadecimal IPv6/IPv4 address...
1876 */
1877
1878 family = AF_INET6;
1879
1880 for (i = 0, ptr = value + 1; *ptr && i < 8; i ++)
1881 {
1882 if (*ptr == ']')
1883 break;
1884 else if (!strncmp(ptr, "::", 2))
1885 {
1886 for (ptr2 = strchr(ptr + 2, ':'), j = 0;
1887 ptr2;
1888 ptr2 = strchr(ptr2 + 1, ':'), j ++);
1889
1890 i = 6 - j;
1891 ptr += 2;
1892 }
1893 else if (isdigit(*ptr & 255) && strchr(ptr + 1, '.') && i >= 6)
1894 {
1895 /*
1896 * Read IPv4 dotted quad...
1897 */
1898
1899 unsigned val[4] = { 0, 0, 0, 0 };
1900 /* IPv4 address values */
1901
1902 ipcount = sscanf(ptr, "%u.%u.%u.%u", val + 0, val + 1, val + 2,
1903 val + 3);
1904
1905 /*
1906 * Range check the IP numbers...
1907 */
1908
1909 for (i = 0; i < ipcount; i ++)
1910 if (val[i] > 255)
1911 return (0);
1912
1913 /*
1914 * Merge everything into a 32-bit IPv4 address in ip[3]...
1915 */
1916
1917 ip[3] = ((((((unsigned)val[0] << 8) | (unsigned)val[1]) << 8) |
1918 (unsigned)val[2]) << 8) | (unsigned)val[3];
1919
1920 if (ipcount < 4)
1921 mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
1922
1923 /*
1924 * If the leading words are all 0's then this is an IPv4 address...
1925 */
1926
1927 if (!val[0] && !val[1] && !val[2])
1928 family = AF_INET;
1929
1930 while (isdigit(*ptr & 255) || *ptr == '.')
1931 ptr ++;
1932 break;
1933 }
1934 else if (isxdigit(*ptr & 255))
1935 {
1936 ipval = strtoul(ptr, (char **)&ptr, 16);
1937
1938 if (*ptr == ':' && ptr[1] != ':')
1939 ptr ++;
1940
1941 if (ipval > 0xffff)
1942 return (0);
1943
1944 if (i & 1)
1945 ip[i / 2] |= ipval;
1946 else
1947 ip[i / 2] |= ipval << 16;
1948 }
1949 else
1950 return (0);
1951 }
1952
1953 if (*ptr != ']')
1954 return (0);
1955
1956 ptr ++;
1957
1958 if (*ptr && *ptr != '/')
1959 return (0);
1960 }
1961 else
1962 #endif /* AF_INET6 */
1963 {
1964 /*
1965 * Parse dotted-decimal IPv4 address...
1966 */
1967
1968 unsigned val[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1969
1970
1971 family = AF_INET;
1972 ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3);
1973
1974 /*
1975 * Range check the IP numbers...
1976 */
1977
1978 for (i = 0; i < ipcount; i ++)
1979 if (val[i] > 255)
1980 return (0);
1981
1982 /*
1983 * Merge everything into a 32-bit IPv4 address in ip[3]...
1984 */
1985
1986 ip[3] = ((((((unsigned)val[0] << 8) | (unsigned)val[1]) << 8) |
1987 (unsigned)val[2]) << 8) | (unsigned)val[3];
1988
1989 if (ipcount < 4)
1990 mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
1991 }
1992
1993 if (*maskval)
1994 {
1995 /*
1996 * Get the netmask value(s)...
1997 */
1998
1999 memset(mask, 0, sizeof(unsigned) * 4);
2000
2001 if (strchr(maskval, '.'))
2002 {
2003 /*
2004 * Get dotted-decimal mask...
2005 */
2006
2007 if (family != AF_INET)
2008 return (0);
2009
2010 if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2,
2011 mask + 3) != 4)
2012 return (0);
2013
2014 mask[3] |= (((((unsigned)mask[0] << 8) | (unsigned)mask[1]) << 8) |
2015 (unsigned)mask[2]) << 8;
2016 mask[0] = mask[1] = mask[2] = 0;
2017 }
2018 else
2019 {
2020 /*
2021 * Get address/bits format...
2022 */
2023
2024 i = atoi(maskval);
2025
2026 #ifdef AF_INET6
2027 if (family == AF_INET6)
2028 {
2029 if (i > 128)
2030 return (0);
2031
2032 i = 128 - i;
2033
2034 if (i <= 96)
2035 mask[0] = 0xffffffff;
2036 else
2037 mask[0] = (0xffffffff << (i - 96)) & 0xffffffff;
2038
2039 if (i <= 64)
2040 mask[1] = 0xffffffff;
2041 else if (i >= 96)
2042 mask[1] = 0;
2043 else
2044 mask[1] = (0xffffffff << (i - 64)) & 0xffffffff;
2045
2046 if (i <= 32)
2047 mask[2] = 0xffffffff;
2048 else if (i >= 64)
2049 mask[2] = 0;
2050 else
2051 mask[2] = (0xffffffff << (i - 32)) & 0xffffffff;
2052
2053 if (i == 0)
2054 mask[3] = 0xffffffff;
2055 else if (i >= 32)
2056 mask[3] = 0;
2057 else
2058 mask[3] = (0xffffffff << i) & 0xffffffff;
2059 }
2060 else
2061 #endif /* AF_INET6 */
2062 {
2063 if (i > 32)
2064 return (0);
2065
2066 mask[0] = 0xffffffff;
2067 mask[1] = 0xffffffff;
2068 mask[2] = 0xffffffff;
2069
2070 if (i < 32)
2071 mask[3] = (0xffffffff << (32 - i)) & 0xffffffff;
2072 else
2073 mask[3] = 0xffffffff;
2074 }
2075 }
2076 }
2077
2078 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2079 "get_addr_and_mask(value=\"%s\", "
2080 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2081 value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2],
2082 mask[3]);
2083
2084 /*
2085 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2086 */
2087
2088 if ((ip[0] & ~mask[0]) != 0 ||
2089 (ip[1] & ~mask[1]) != 0 ||
2090 (ip[2] & ~mask[2]) != 0 ||
2091 (ip[3] & ~mask[3]) != 0)
2092 return (0);
2093
2094 return (1);
2095 }
2096
2097
2098 /*
2099 * 'mime_error_cb()' - Log a MIME error.
2100 */
2101
2102 static void
2103 mime_error_cb(void *ctx, /* I - Context pointer (unused) */
2104 const char *message) /* I - Message */
2105 {
2106 (void)ctx;
2107
2108 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", message);
2109 }
2110
2111
2112 /*
2113 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2114 */
2115
2116 static int /* O - 1 on success, 0 on failure */
2117 parse_aaa(cupsd_location_t *loc, /* I - Location */
2118 char *line, /* I - Line from file */
2119 char *value, /* I - Start of value data */
2120 int linenum) /* I - Current line number */
2121 {
2122 char *valptr; /* Pointer into value */
2123 unsigned ip[4], /* IP address components */
2124 mask[4]; /* IP netmask components */
2125
2126
2127 if (!_cups_strcasecmp(line, "Encryption"))
2128 {
2129 /*
2130 * "Encryption xxx" - set required encryption level...
2131 */
2132
2133 if (!_cups_strcasecmp(value, "never"))
2134 loc->encryption = HTTP_ENCRYPT_NEVER;
2135 else if (!_cups_strcasecmp(value, "always"))
2136 {
2137 cupsdLogMessage(CUPSD_LOG_ERROR,
2138 "Encryption value \"%s\" on line %d of %s is invalid in this "
2139 "context. Using \"required\" instead.", value, linenum, ConfigurationFile);
2140
2141 loc->encryption = HTTP_ENCRYPT_REQUIRED;
2142 }
2143 else if (!_cups_strcasecmp(value, "required"))
2144 loc->encryption = HTTP_ENCRYPT_REQUIRED;
2145 else if (!_cups_strcasecmp(value, "ifrequested"))
2146 loc->encryption = HTTP_ENCRYPT_IF_REQUESTED;
2147 else
2148 {
2149 cupsdLogMessage(CUPSD_LOG_ERROR,
2150 "Unknown Encryption value %s on line %d of %s.", value, linenum, ConfigurationFile);
2151 return (0);
2152 }
2153 }
2154 else if (!_cups_strcasecmp(line, "Order"))
2155 {
2156 /*
2157 * "Order Deny,Allow" or "Order Allow,Deny"...
2158 */
2159
2160 if (!_cups_strncasecmp(value, "deny", 4))
2161 loc->order_type = CUPSD_AUTH_ALLOW;
2162 else if (!_cups_strncasecmp(value, "allow", 5))
2163 loc->order_type = CUPSD_AUTH_DENY;
2164 else
2165 {
2166 cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown Order value %s on line %d of %s.",
2167 value, linenum, ConfigurationFile);
2168 return (0);
2169 }
2170 }
2171 else if (!_cups_strcasecmp(line, "Allow") || !_cups_strcasecmp(line, "Deny"))
2172 {
2173 /*
2174 * Allow [From] host/ip...
2175 * Deny [From] host/ip...
2176 */
2177
2178 while (*value)
2179 {
2180 if (!_cups_strncasecmp(value, "from", 4))
2181 {
2182 /*
2183 * Strip leading "from"...
2184 */
2185
2186 value += 4;
2187
2188 while (_cups_isspace(*value))
2189 value ++;
2190
2191 if (!*value)
2192 break;
2193 }
2194
2195 /*
2196 * Find the end of the value...
2197 */
2198
2199 for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++);
2200
2201 while (_cups_isspace(*valptr))
2202 *valptr++ = '\0';
2203
2204 /*
2205 * Figure out what form the allow/deny address takes:
2206 *
2207 * All
2208 * None
2209 * *.domain.com
2210 * .domain.com
2211 * host.domain.com
2212 * nnn.*
2213 * nnn.nnn.*
2214 * nnn.nnn.nnn.*
2215 * nnn.nnn.nnn.nnn
2216 * nnn.nnn.nnn.nnn/mm
2217 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2218 */
2219
2220 if (!_cups_strcasecmp(value, "all"))
2221 {
2222 /*
2223 * All hosts...
2224 */
2225
2226 if (!_cups_strcasecmp(line, "Allow"))
2227 cupsdAddIPMask(&(loc->allow), zeros, zeros);
2228 else
2229 cupsdAddIPMask(&(loc->deny), zeros, zeros);
2230 }
2231 else if (!_cups_strcasecmp(value, "none"))
2232 {
2233 /*
2234 * No hosts...
2235 */
2236
2237 if (!_cups_strcasecmp(line, "Allow"))
2238 cupsdAddIPMask(&(loc->allow), ones, zeros);
2239 else
2240 cupsdAddIPMask(&(loc->deny), ones, zeros);
2241 }
2242 #ifdef AF_INET6
2243 else if (value[0] == '*' || value[0] == '.' ||
2244 (!isdigit(value[0] & 255) && value[0] != '['))
2245 #else
2246 else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
2247 #endif /* AF_INET6 */
2248 {
2249 /*
2250 * Host or domain name...
2251 */
2252
2253 if (value[0] == '*')
2254 value ++;
2255
2256 if (!_cups_strcasecmp(line, "Allow"))
2257 cupsdAddNameMask(&(loc->allow), value);
2258 else
2259 cupsdAddNameMask(&(loc->deny), value);
2260 }
2261 else
2262 {
2263 /*
2264 * One of many IP address forms...
2265 */
2266
2267 if (!get_addr_and_mask(value, ip, mask))
2268 {
2269 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d of %s.",
2270 value, linenum, ConfigurationFile);
2271 return (0);
2272 }
2273
2274 if (!_cups_strcasecmp(line, "Allow"))
2275 cupsdAddIPMask(&(loc->allow), ip, mask);
2276 else
2277 cupsdAddIPMask(&(loc->deny), ip, mask);
2278 }
2279
2280 /*
2281 * Advance to next value...
2282 */
2283
2284 value = valptr;
2285 }
2286 }
2287 else if (!_cups_strcasecmp(line, "AuthType"))
2288 {
2289 /*
2290 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2291 */
2292
2293 if (!_cups_strcasecmp(value, "none"))
2294 {
2295 loc->type = CUPSD_AUTH_NONE;
2296 loc->level = CUPSD_AUTH_ANON;
2297 }
2298 else if (!_cups_strcasecmp(value, "basic"))
2299 {
2300 loc->type = CUPSD_AUTH_BASIC;
2301
2302 if (loc->level == CUPSD_AUTH_ANON)
2303 loc->level = CUPSD_AUTH_USER;
2304 }
2305 else if (!_cups_strcasecmp(value, "default"))
2306 {
2307 loc->type = CUPSD_AUTH_DEFAULT;
2308
2309 if (loc->level == CUPSD_AUTH_ANON)
2310 loc->level = CUPSD_AUTH_USER;
2311 }
2312 #ifdef HAVE_GSSAPI
2313 else if (!_cups_strcasecmp(value, "negotiate"))
2314 {
2315 loc->type = CUPSD_AUTH_NEGOTIATE;
2316
2317 if (loc->level == CUPSD_AUTH_ANON)
2318 loc->level = CUPSD_AUTH_USER;
2319 }
2320 #endif /* HAVE_GSSAPI */
2321 else
2322 {
2323 cupsdLogMessage(CUPSD_LOG_WARN,
2324 "Unknown authorization type %s on line %d of %s.",
2325 value, linenum, ConfigurationFile);
2326 return (0);
2327 }
2328 }
2329 else if (!_cups_strcasecmp(line, "AuthClass"))
2330 {
2331 /*
2332 * AuthClass anonymous, user, system, group
2333 */
2334
2335 if (!_cups_strcasecmp(value, "anonymous"))
2336 {
2337 loc->type = CUPSD_AUTH_NONE;
2338 loc->level = CUPSD_AUTH_ANON;
2339
2340 cupsdLogMessage(CUPSD_LOG_WARN,
2341 "\"AuthClass %s\" is deprecated; consider removing "
2342 "it from line %d.",
2343 value, linenum);
2344 }
2345 else if (!_cups_strcasecmp(value, "user"))
2346 {
2347 loc->level = CUPSD_AUTH_USER;
2348
2349 cupsdLogMessage(CUPSD_LOG_WARN,
2350 "\"AuthClass %s\" is deprecated; consider using "
2351 "\"Require valid-user\" on line %d of %s.",
2352 value, linenum, ConfigurationFile);
2353 }
2354 else if (!_cups_strcasecmp(value, "group"))
2355 {
2356 loc->level = CUPSD_AUTH_GROUP;
2357
2358 cupsdLogMessage(CUPSD_LOG_WARN,
2359 "\"AuthClass %s\" is deprecated; consider using "
2360 "\"Require user @groupname\" on line %d of %s.",
2361 value, linenum, ConfigurationFile);
2362 }
2363 else if (!_cups_strcasecmp(value, "system"))
2364 {
2365 loc->level = CUPSD_AUTH_GROUP;
2366
2367 cupsdAddName(loc, "@SYSTEM");
2368
2369 cupsdLogMessage(CUPSD_LOG_WARN,
2370 "\"AuthClass %s\" is deprecated; consider using "
2371 "\"Require user @SYSTEM\" on line %d of %s.",
2372 value, linenum, ConfigurationFile);
2373 }
2374 else
2375 {
2376 cupsdLogMessage(CUPSD_LOG_WARN,
2377 "Unknown authorization class %s on line %d of %s.",
2378 value, linenum, ConfigurationFile);
2379 return (0);
2380 }
2381 }
2382 else if (!_cups_strcasecmp(line, "AuthGroupName"))
2383 {
2384 cupsdAddName(loc, value);
2385
2386 cupsdLogMessage(CUPSD_LOG_WARN,
2387 "\"AuthGroupName %s\" directive is deprecated; consider "
2388 "using \"Require user @%s\" on line %d of %s.",
2389 value, value, linenum, ConfigurationFile);
2390 }
2391 else if (!_cups_strcasecmp(line, "Require"))
2392 {
2393 /*
2394 * Apache synonym for AuthClass and AuthGroupName...
2395 *
2396 * Get initial word:
2397 *
2398 * Require valid-user
2399 * Require group names
2400 * Require user names
2401 */
2402
2403 for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++);
2404
2405 if (*valptr)
2406 *valptr++ = '\0';
2407
2408 if (!_cups_strcasecmp(value, "valid-user") ||
2409 !_cups_strcasecmp(value, "user"))
2410 loc->level = CUPSD_AUTH_USER;
2411 else if (!_cups_strcasecmp(value, "group"))
2412 loc->level = CUPSD_AUTH_GROUP;
2413 else
2414 {
2415 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Require type %s on line %d of %s.",
2416 value, linenum, ConfigurationFile);
2417 return (0);
2418 }
2419
2420 /*
2421 * Get the list of names from the line...
2422 */
2423
2424 for (value = valptr; *value;)
2425 {
2426 while (_cups_isspace(*value))
2427 value ++;
2428
2429 #ifdef HAVE_AUTHORIZATION_H
2430 if (!strncmp(value, "@AUTHKEY(", 9))
2431 {
2432 /*
2433 * Grab "@AUTHKEY(name)" value...
2434 */
2435
2436 for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++);
2437
2438 if (*valptr)
2439 *valptr++ = '\0';
2440 }
2441 else
2442 #endif /* HAVE_AUTHORIZATION_H */
2443 if (*value == '\"' || *value == '\'')
2444 {
2445 /*
2446 * Grab quoted name...
2447 */
2448
2449 for (valptr = value + 1; *valptr != *value && *valptr; valptr ++);
2450
2451 value ++;
2452 }
2453 else
2454 {
2455 /*
2456 * Grab literal name.
2457 */
2458
2459 for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++);
2460 }
2461
2462 if (*valptr)
2463 *valptr++ = '\0';
2464
2465 cupsdAddName(loc, value);
2466
2467 for (value = valptr; _cups_isspace(*value); value ++);
2468 }
2469 }
2470 else if (!_cups_strcasecmp(line, "Satisfy"))
2471 {
2472 if (!_cups_strcasecmp(value, "all"))
2473 loc->satisfy = CUPSD_AUTH_SATISFY_ALL;
2474 else if (!_cups_strcasecmp(value, "any"))
2475 loc->satisfy = CUPSD_AUTH_SATISFY_ANY;
2476 else
2477 {
2478 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Satisfy value %s on line %d of %s.",
2479 value, linenum, ConfigurationFile);
2480 return (0);
2481 }
2482 }
2483 else
2484 return (0);
2485
2486 return (1);
2487 }
2488
2489
2490 /*
2491 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2492 */
2493
2494 static int /* O - FatalErrors bits */
2495 parse_fatal_errors(const char *s) /* I - FatalErrors string */
2496 {
2497 int fatal; /* FatalErrors bits */
2498 char value[1024], /* Value string */
2499 *valstart, /* Pointer into value */
2500 *valend; /* End of value */
2501
2502
2503 /*
2504 * Empty FatalErrors line yields NULL pointer...
2505 */
2506
2507 if (!s)
2508 return (CUPSD_FATAL_NONE);
2509
2510 /*
2511 * Loop through the value string,...
2512 */
2513
2514 strlcpy(value, s, sizeof(value));
2515
2516 fatal = CUPSD_FATAL_NONE;
2517
2518 for (valstart = value; *valstart;)
2519 {
2520 /*
2521 * Get the current space/comma-delimited kind name...
2522 */
2523
2524 for (valend = valstart; *valend; valend ++)
2525 if (_cups_isspace(*valend) || *valend == ',')
2526 break;
2527
2528 if (*valend)
2529 *valend++ = '\0';
2530
2531 /*
2532 * Add the error to the bitmask...
2533 */
2534
2535 if (!_cups_strcasecmp(valstart, "all"))
2536 fatal = CUPSD_FATAL_ALL;
2537 else if (!_cups_strcasecmp(valstart, "browse"))
2538 fatal |= CUPSD_FATAL_BROWSE;
2539 else if (!_cups_strcasecmp(valstart, "-browse"))
2540 fatal &= ~CUPSD_FATAL_BROWSE;
2541 else if (!_cups_strcasecmp(valstart, "config"))
2542 fatal |= CUPSD_FATAL_CONFIG;
2543 else if (!_cups_strcasecmp(valstart, "-config"))
2544 fatal &= ~CUPSD_FATAL_CONFIG;
2545 else if (!_cups_strcasecmp(valstart, "listen"))
2546 fatal |= CUPSD_FATAL_LISTEN;
2547 else if (!_cups_strcasecmp(valstart, "-listen"))
2548 fatal &= ~CUPSD_FATAL_LISTEN;
2549 else if (!_cups_strcasecmp(valstart, "log"))
2550 fatal |= CUPSD_FATAL_LOG;
2551 else if (!_cups_strcasecmp(valstart, "-log"))
2552 fatal &= ~CUPSD_FATAL_LOG;
2553 else if (!_cups_strcasecmp(valstart, "permissions"))
2554 fatal |= CUPSD_FATAL_PERMISSIONS;
2555 else if (!_cups_strcasecmp(valstart, "-permissions"))
2556 fatal &= ~CUPSD_FATAL_PERMISSIONS;
2557 else if (_cups_strcasecmp(valstart, "none"))
2558 cupsdLogMessage(CUPSD_LOG_ERROR,
2559 "Unknown FatalErrors kind \"%s\" ignored.", valstart);
2560
2561 for (valstart = valend; *valstart; valstart ++)
2562 if (!_cups_isspace(*valstart) || *valstart != ',')
2563 break;
2564 }
2565
2566 return (fatal);
2567 }
2568
2569
2570 /*
2571 * 'parse_groups()' - Parse system group names in a string.
2572 */
2573
2574 static int /* O - 1 on success, 0 on failure */
2575 parse_groups(const char *s) /* I - Space-delimited groups */
2576 {
2577 int status; /* Return status */
2578 char value[1024], /* Value string */
2579 *valstart, /* Pointer into value */
2580 *valend, /* End of value */
2581 quote; /* Quote character */
2582 struct group *group; /* Group */
2583
2584
2585 /*
2586 * Make a copy of the string and parse out the groups...
2587 */
2588
2589 strlcpy(value, s, sizeof(value));
2590
2591 status = 1;
2592 valstart = value;
2593
2594 while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS)
2595 {
2596 if (*valstart == '\'' || *valstart == '\"')
2597 {
2598 /*
2599 * Scan quoted name...
2600 */
2601
2602 quote = *valstart++;
2603
2604 for (valend = valstart; *valend; valend ++)
2605 if (*valend == quote)
2606 break;
2607 }
2608 else
2609 {
2610 /*
2611 * Scan space or comma-delimited name...
2612 */
2613
2614 for (valend = valstart; *valend; valend ++)
2615 if (_cups_isspace(*valend) || *valend == ',')
2616 break;
2617 }
2618
2619 if (*valend)
2620 *valend++ = '\0';
2621
2622 group = getgrnam(valstart);
2623 if (group)
2624 {
2625 cupsdSetString(SystemGroups + NumSystemGroups, valstart);
2626 SystemGroupIDs[NumSystemGroups] = group->gr_gid;
2627
2628 NumSystemGroups ++;
2629 }
2630 else
2631 status = 0;
2632
2633 endgrent();
2634
2635 valstart = valend;
2636
2637 while (*valstart == ',' || _cups_isspace(*valstart))
2638 valstart ++;
2639 }
2640
2641 return (status);
2642 }
2643
2644
2645 /*
2646 * 'parse_protocols()' - Parse browse protocols in a string.
2647 */
2648
2649 static int /* O - Browse protocol bits */
2650 parse_protocols(const char *s) /* I - Space-delimited protocols */
2651 {
2652 int protocols; /* Browse protocol bits */
2653 char value[1024], /* Value string */
2654 *valstart, /* Pointer into value */
2655 *valend; /* End of value */
2656
2657
2658 /*
2659 * Empty protocol line yields NULL pointer...
2660 */
2661
2662 if (!s)
2663 return (0);
2664
2665 /*
2666 * Loop through the value string,...
2667 */
2668
2669 strlcpy(value, s, sizeof(value));
2670
2671 protocols = 0;
2672
2673 for (valstart = value; *valstart;)
2674 {
2675 /*
2676 * Get the current space/comma-delimited protocol name...
2677 */
2678
2679 for (valend = valstart; *valend; valend ++)
2680 if (_cups_isspace(*valend) || *valend == ',')
2681 break;
2682
2683 if (*valend)
2684 *valend++ = '\0';
2685
2686 /*
2687 * Add the protocol to the bitmask...
2688 */
2689
2690 if (!_cups_strcasecmp(valstart, "dnssd") ||
2691 !_cups_strcasecmp(valstart, "dns-sd") ||
2692 !_cups_strcasecmp(valstart, "bonjour"))
2693 protocols |= BROWSE_DNSSD;
2694 else if (!_cups_strcasecmp(valstart, "all"))
2695 protocols |= BROWSE_ALL;
2696 else if (_cups_strcasecmp(valstart, "none"))
2697 cupsdLogMessage(CUPSD_LOG_ERROR,
2698 "Unknown browse protocol \"%s\" ignored.", valstart);
2699
2700 for (valstart = valend; *valstart; valstart ++)
2701 if (!_cups_isspace(*valstart) || *valstart != ',')
2702 break;
2703 }
2704
2705 return (protocols);
2706 }
2707
2708
2709 /*
2710 * 'parse_variable()' - Parse a variable line.
2711 */
2712
2713 static int /* O - 1 on success, 0 on failure */
2714 parse_variable(
2715 const char *filename, /* I - Name of configuration file */
2716 int linenum, /* I - Line in configuration file */
2717 const char *line, /* I - Line from configuration file */
2718 const char *value, /* I - Value from configuration file */
2719 size_t num_vars, /* I - Number of variables */
2720 const cupsd_var_t *vars) /* I - Variables */
2721 {
2722 size_t i; /* Looping var */
2723 const cupsd_var_t *var; /* Variables */
2724 char temp[1024]; /* Temporary string */
2725
2726
2727 for (i = num_vars, var = vars; i > 0; i --, var ++)
2728 if (!_cups_strcasecmp(line, var->name))
2729 break;
2730
2731 if (i == 0)
2732 {
2733 /*
2734 * Unknown directive! Output an error message and continue...
2735 */
2736
2737 if (!value)
2738 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d of %s.",
2739 line, linenum, filename);
2740 else
2741 cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d of %s.",
2742 line, linenum, filename);
2743
2744 return (0);
2745 }
2746
2747 switch (var->type)
2748 {
2749 case CUPSD_VARTYPE_INTEGER :
2750 if (!value)
2751 {
2752 cupsdLogMessage(CUPSD_LOG_ERROR,
2753 "Missing integer value for %s on line %d of %s.",
2754 line, linenum, filename);
2755 return (0);
2756 }
2757 else if (!isdigit(*value & 255))
2758 {
2759 cupsdLogMessage(CUPSD_LOG_ERROR,
2760 "Bad integer value for %s on line %d of %s.",
2761 line, linenum, filename);
2762 return (0);
2763 }
2764 else
2765 {
2766 int n; /* Number */
2767 char *units; /* Units */
2768
2769 n = strtol(value, &units, 0);
2770
2771 if (units && *units)
2772 {
2773 if (tolower(units[0] & 255) == 'g')
2774 n *= 1024 * 1024 * 1024;
2775 else if (tolower(units[0] & 255) == 'm')
2776 n *= 1024 * 1024;
2777 else if (tolower(units[0] & 255) == 'k')
2778 n *= 1024;
2779 else if (tolower(units[0] & 255) == 't')
2780 n *= 262144;
2781 else
2782 {
2783 cupsdLogMessage(CUPSD_LOG_ERROR,
2784 "Unknown integer value for %s on line %d of %s.",
2785 line, linenum, filename);
2786 return (0);
2787 }
2788 }
2789
2790 if (n < 0)
2791 {
2792 cupsdLogMessage(CUPSD_LOG_ERROR,
2793 "Bad negative integer value for %s on line %d of "
2794 "%s.", line, linenum, filename);
2795 return (0);
2796 }
2797 else
2798 {
2799 *((int *)var->ptr) = n;
2800 }
2801 }
2802 break;
2803
2804 case CUPSD_VARTYPE_PERM :
2805 if (!value)
2806 {
2807 cupsdLogMessage(CUPSD_LOG_ERROR,
2808 "Missing permissions value for %s on line %d of %s.",
2809 line, linenum, filename);
2810 return (0);
2811 }
2812 else if (!isdigit(*value & 255))
2813 {
2814 /* TODO: Add chmod UGO syntax support */
2815 cupsdLogMessage(CUPSD_LOG_ERROR,
2816 "Bad permissions value for %s on line %d of %s.",
2817 line, linenum, filename);
2818 return (0);
2819 }
2820 else
2821 {
2822 int n = strtol(value, NULL, 8);
2823 /* Permissions value */
2824
2825 if (n < 0)
2826 {
2827 cupsdLogMessage(CUPSD_LOG_ERROR,
2828 "Bad negative permissions value for %s on line %d of "
2829 "%s.", line, linenum, filename);
2830 return (0);
2831 }
2832 else
2833 {
2834 *((mode_t *)var->ptr) = (mode_t)n;
2835 }
2836 }
2837 break;
2838
2839 case CUPSD_VARTYPE_TIME :
2840 if (!value)
2841 {
2842 cupsdLogMessage(CUPSD_LOG_ERROR,
2843 "Missing time interval value for %s on line %d of "
2844 "%s.", line, linenum, filename);
2845 return (0);
2846 }
2847 else if (!_cups_strncasecmp(line, "PreserveJob", 11) &&
2848 (!_cups_strcasecmp(value, "true") ||
2849 !_cups_strcasecmp(value, "on") ||
2850 !_cups_strcasecmp(value, "enabled") ||
2851 !_cups_strcasecmp(value, "yes")))
2852 {
2853 *((int *)var->ptr) = INT_MAX;
2854 }
2855 else if (!_cups_strcasecmp(value, "false") ||
2856 !_cups_strcasecmp(value, "off") ||
2857 !_cups_strcasecmp(value, "disabled") ||
2858 !_cups_strcasecmp(value, "no"))
2859 {
2860 *((int *)var->ptr) = 0;
2861 }
2862 else if (!isdigit(*value & 255))
2863 {
2864 cupsdLogMessage(CUPSD_LOG_ERROR,
2865 "Unknown time interval value for %s on line %d of "
2866 "%s.", line, linenum, filename);
2867 return (0);
2868 }
2869 else
2870 {
2871 double n; /* Number */
2872 char *units; /* Units */
2873
2874 n = strtod(value, &units);
2875
2876 if (units && *units)
2877 {
2878 if (tolower(units[0] & 255) == 'w')
2879 n *= 7 * 24 * 60 * 60;
2880 else if (tolower(units[0] & 255) == 'd')
2881 n *= 24 * 60 * 60;
2882 else if (tolower(units[0] & 255) == 'h')
2883 n *= 60 * 60;
2884 else if (tolower(units[0] & 255) == 'm')
2885 n *= 60;
2886 else
2887 {
2888 cupsdLogMessage(CUPSD_LOG_ERROR,
2889 "Unknown time interval value for %s on line "
2890 "%d of %s.", line, linenum, filename);
2891 return (0);
2892 }
2893 }
2894
2895 if (n < 0.0 || n > INT_MAX)
2896 {
2897 cupsdLogMessage(CUPSD_LOG_ERROR,
2898 "Bad time value for %s on line %d of %s.",
2899 line, linenum, filename);
2900 return (0);
2901 }
2902 else
2903 {
2904 *((int *)var->ptr) = (int)n;
2905 }
2906 }
2907 break;
2908
2909 case CUPSD_VARTYPE_BOOLEAN :
2910 if (!value)
2911 {
2912 cupsdLogMessage(CUPSD_LOG_ERROR,
2913 "Missing boolean value for %s on line %d of %s.",
2914 line, linenum, filename);
2915 return (0);
2916 }
2917 else if (!_cups_strcasecmp(value, "true") ||
2918 !_cups_strcasecmp(value, "on") ||
2919 !_cups_strcasecmp(value, "enabled") ||
2920 !_cups_strcasecmp(value, "yes") ||
2921 atoi(value) != 0)
2922 {
2923 *((int *)var->ptr) = TRUE;
2924 }
2925 else if (!_cups_strcasecmp(value, "false") ||
2926 !_cups_strcasecmp(value, "off") ||
2927 !_cups_strcasecmp(value, "disabled") ||
2928 !_cups_strcasecmp(value, "no") ||
2929 !_cups_strcasecmp(value, "0"))
2930 {
2931 *((int *)var->ptr) = FALSE;
2932 }
2933 else
2934 {
2935 cupsdLogMessage(CUPSD_LOG_ERROR,
2936 "Unknown boolean value %s on line %d of %s.",
2937 value, linenum, filename);
2938 return (0);
2939 }
2940 break;
2941
2942 case CUPSD_VARTYPE_PATHNAME :
2943 if (!value)
2944 {
2945 cupsdLogMessage(CUPSD_LOG_ERROR,
2946 "Missing pathname value for %s on line %d of %s.",
2947 line, linenum, filename);
2948 return (0);
2949 }
2950
2951 if (value[0] == '/')
2952 strlcpy(temp, value, sizeof(temp));
2953 else
2954 snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, value);
2955
2956 if (access(temp, 0))
2957 {
2958 cupsdLogMessage(CUPSD_LOG_ERROR,
2959 "File or directory for \"%s %s\" on line %d of %s "
2960 "does not exist.", line, value, linenum, filename);
2961 return (0);
2962 }
2963
2964 cupsdSetString((char **)var->ptr, temp);
2965 break;
2966
2967 case CUPSD_VARTYPE_STRING :
2968 cupsdSetString((char **)var->ptr, value);
2969 break;
2970 }
2971
2972 return (1);
2973 }
2974
2975
2976 /*
2977 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2978 */
2979
2980 static int /* O - 1 on success, 0 on failure */
2981 read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
2982 {
2983 int linenum; /* Current line number */
2984 char line[HTTP_MAX_BUFFER],
2985 /* Line from file */
2986 temp[HTTP_MAX_BUFFER],
2987 /* Temporary buffer for value */
2988 *value, /* Pointer to value */
2989 *valueptr; /* Pointer into value */
2990 int valuelen; /* Length of value */
2991 http_addrlist_t *addrlist, /* Address list */
2992 *addr; /* Current address */
2993 cups_file_t *incfile; /* Include file */
2994 char incname[1024]; /* Include filename */
2995
2996
2997 /*
2998 * Loop through each line in the file...
2999 */
3000
3001 linenum = 0;
3002
3003 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3004 {
3005 /*
3006 * Decode the directive...
3007 */
3008
3009 if (!_cups_strcasecmp(line, "Include") && value)
3010 {
3011 /*
3012 * Include filename
3013 */
3014
3015 if (value[0] == '/')
3016 strlcpy(incname, value, sizeof(incname));
3017 else
3018 snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value);
3019
3020 if ((incfile = cupsFileOpen(incname, "rb")) == NULL)
3021 cupsdLogMessage(CUPSD_LOG_ERROR,
3022 "Unable to include config file \"%s\" - %s",
3023 incname, strerror(errno));
3024 else
3025 {
3026 read_cupsd_conf(incfile);
3027 cupsFileClose(incfile);
3028 }
3029 }
3030 else if (!_cups_strcasecmp(line, "<Location") && value)
3031 {
3032 /*
3033 * <Location path>
3034 */
3035
3036 linenum = read_location(fp, value, linenum);
3037 if (linenum == 0)
3038 return (0);
3039 }
3040 else if (!_cups_strcasecmp(line, "<Policy") && value)
3041 {
3042 /*
3043 * <Policy name>
3044 */
3045
3046 linenum = read_policy(fp, value, linenum);
3047 if (linenum == 0)
3048 return (0);
3049 }
3050 else if (!_cups_strcasecmp(line, "FaxRetryInterval") && value)
3051 {
3052 JobRetryInterval = atoi(value);
3053 cupsdLogMessage(CUPSD_LOG_WARN,
3054 "FaxRetryInterval is deprecated; use "
3055 "JobRetryInterval on line %d of %s.", linenum, ConfigurationFile);
3056 }
3057 else if (!_cups_strcasecmp(line, "FaxRetryLimit") && value)
3058 {
3059 JobRetryLimit = atoi(value);
3060 cupsdLogMessage(CUPSD_LOG_WARN,
3061 "FaxRetryLimit is deprecated; use "
3062 "JobRetryLimit on line %d of %s.", linenum, ConfigurationFile);
3063 }
3064 #ifdef HAVE_SSL
3065 else if (!_cups_strcasecmp(line, "SSLOptions"))
3066 {
3067 /*
3068 * SSLOptions [AllowRC4] [AllowSSL3] [None]
3069 */
3070
3071 int options = 0; /* SSL/TLS options */
3072
3073 if (value)
3074 {
3075 char *start, /* Start of option */
3076 *end; /* End of option */
3077
3078 for (start = value; *start; start = end)
3079 {
3080 /*
3081 * Find end of keyword...
3082 */
3083
3084 end = start;
3085 while (*end && !_cups_isspace(*end))
3086 end ++;
3087
3088 if (*end)
3089 *end++ = '\0';
3090
3091 /*
3092 * Compare...
3093 */
3094
3095 if (!_cups_strcasecmp(start, "AllowRC4"))
3096 options |= _HTTP_TLS_ALLOW_RC4;
3097 else if (!_cups_strcasecmp(start, "AllowSSL3"))
3098 options |= _HTTP_TLS_ALLOW_SSL3;
3099 else if (!_cups_strcasecmp(start, "None"))
3100 options = 0;
3101 else if (_cups_strcasecmp(start, "NoEmptyFragments"))
3102 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown SSL option %s at line %d.", start, linenum);
3103 }
3104 }
3105
3106 _httpTLSSetOptions(options);
3107 }
3108 #endif /* HAVE_SSL */
3109 else if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen")
3110 #ifdef HAVE_SSL
3111 || !_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen")
3112 #endif /* HAVE_SSL */
3113 ) && value)
3114 {
3115 /*
3116 * Add listening address(es) to the list...
3117 */
3118
3119 cupsd_listener_t *lis; /* New listeners array */
3120
3121
3122 /*
3123 * Get the address list...
3124 */
3125
3126 addrlist = get_address(value, IPP_PORT);
3127
3128 if (!addrlist)
3129 {
3130 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad %s address %s at line %d.", line,
3131 value, linenum);
3132 continue;
3133 }
3134
3135 /*
3136 * Add each address...
3137 */
3138
3139 for (addr = addrlist; addr; addr = addr->next)
3140 {
3141 /*
3142 * See if this address is already present...
3143 */
3144
3145 for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
3146 lis;
3147 lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
3148 if (httpAddrEqual(&(addr->addr), &(lis->address)) &&
3149 httpAddrPort(&(addr->addr)) == httpAddrPort(&(lis->address)))
3150 break;
3151
3152 if (lis)
3153 {
3154 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
3155 if (!lis->on_demand)
3156 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
3157 {
3158 httpAddrString(&lis->address, temp, sizeof(temp));
3159 cupsdLogMessage(CUPSD_LOG_WARN,
3160 "Duplicate listen address \"%s\" ignored.", temp);
3161 }
3162
3163 continue;
3164 }
3165
3166 /*
3167 * Allocate another listener...
3168 */
3169
3170 if (!Listeners)
3171 Listeners = cupsArrayNew(NULL, NULL);
3172
3173 if (!Listeners)
3174 {
3175 cupsdLogMessage(CUPSD_LOG_ERROR,
3176 "Unable to allocate %s at line %d - %s.",
3177 line, linenum, strerror(errno));
3178 break;
3179 }
3180
3181 if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
3182 {
3183 cupsdLogMessage(CUPSD_LOG_ERROR,
3184 "Unable to allocate %s at line %d - %s.",
3185 line, linenum, strerror(errno));
3186 break;
3187 }
3188
3189 cupsArrayAdd(Listeners, lis);
3190
3191 /*
3192 * Copy the current address and log it...
3193 */
3194
3195 memcpy(&(lis->address), &(addr->addr), sizeof(lis->address));
3196 lis->fd = -1;
3197
3198 #ifdef HAVE_SSL
3199 if (!_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen"))
3200 lis->encryption = HTTP_ENCRYPT_ALWAYS;
3201 #endif /* HAVE_SSL */
3202
3203 httpAddrString(&lis->address, temp, sizeof(temp));
3204
3205 #ifdef AF_LOCAL
3206 if (lis->address.addr.sa_family == AF_LOCAL)
3207 cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s (Domain)", temp);
3208 else
3209 #endif /* AF_LOCAL */
3210 cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv%d)", temp,
3211 httpAddrPort(&(lis->address)),
3212 httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6);
3213
3214 if (!httpAddrLocalhost(&(lis->address)))
3215 RemotePort = httpAddrPort(&(lis->address));
3216 }
3217
3218 /*
3219 * Free the list...
3220 */
3221
3222 httpAddrFreeList(addrlist);
3223 }
3224 else if (!_cups_strcasecmp(line, "BrowseProtocols") ||
3225 !_cups_strcasecmp(line, "BrowseLocalProtocols"))
3226 {
3227 /*
3228 * "BrowseProtocols name [... name]"
3229 * "BrowseLocalProtocols name [... name]"
3230 */
3231
3232 int protocols = parse_protocols(value);
3233
3234 if (protocols < 0)
3235 {
3236 cupsdLogMessage(CUPSD_LOG_ERROR,
3237 "Unknown browse protocol \"%s\" on line %d of %s.",
3238 value, linenum, ConfigurationFile);
3239 break;
3240 }
3241
3242 BrowseLocalProtocols = protocols;
3243 }
3244 else if (!_cups_strcasecmp(line, "DefaultAuthType") && value)
3245 {
3246 /*
3247 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3248 */
3249
3250 if (!_cups_strcasecmp(value, "none"))
3251 default_auth_type = CUPSD_AUTH_NONE;
3252 else if (!_cups_strcasecmp(value, "basic"))
3253 default_auth_type = CUPSD_AUTH_BASIC;
3254 #ifdef HAVE_GSSAPI
3255 else if (!_cups_strcasecmp(value, "negotiate"))
3256 default_auth_type = CUPSD_AUTH_NEGOTIATE;
3257 #endif /* HAVE_GSSAPI */
3258 else if (!_cups_strcasecmp(value, "auto"))
3259 default_auth_type = CUPSD_AUTH_AUTO;
3260 else
3261 {
3262 cupsdLogMessage(CUPSD_LOG_WARN,
3263 "Unknown default authorization type %s on line %d of %s.",
3264 value, linenum, ConfigurationFile);
3265 if (FatalErrors & CUPSD_FATAL_CONFIG)
3266 return (0);
3267 }
3268 }
3269 #ifdef HAVE_SSL
3270 else if (!_cups_strcasecmp(line, "DefaultEncryption"))
3271 {
3272 /*
3273 * DefaultEncryption {Never,IfRequested,Required}
3274 */
3275
3276 if (!value || !_cups_strcasecmp(value, "never"))
3277 DefaultEncryption = HTTP_ENCRYPT_NEVER;
3278 else if (!_cups_strcasecmp(value, "required"))
3279 DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
3280 else if (!_cups_strcasecmp(value, "ifrequested"))
3281 DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED;
3282 else
3283 {
3284 cupsdLogMessage(CUPSD_LOG_WARN,
3285 "Unknown default encryption %s on line %d of %s.",
3286 value, linenum, ConfigurationFile);
3287 if (FatalErrors & CUPSD_FATAL_CONFIG)
3288 return (0);
3289 }
3290 }
3291 #endif /* HAVE_SSL */
3292 else if (!_cups_strcasecmp(line, "HostNameLookups") && value)
3293 {
3294 /*
3295 * Do hostname lookups?
3296 */
3297
3298 if (!_cups_strcasecmp(value, "off") || !_cups_strcasecmp(value, "no") ||
3299 !_cups_strcasecmp(value, "false"))
3300 HostNameLookups = 0;
3301 else if (!_cups_strcasecmp(value, "on") || !_cups_strcasecmp(value, "yes") ||
3302 !_cups_strcasecmp(value, "true"))
3303 HostNameLookups = 1;
3304 else if (!_cups_strcasecmp(value, "double"))
3305 HostNameLookups = 2;
3306 else
3307 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown HostNameLookups %s on line %d of %s.",
3308 value, linenum, ConfigurationFile);
3309 }
3310 else if (!_cups_strcasecmp(line, "AccessLogLevel") && value)
3311 {
3312 /*
3313 * Amount of logging to do to access log...
3314 */
3315
3316 if (!_cups_strcasecmp(value, "all"))
3317 AccessLogLevel = CUPSD_ACCESSLOG_ALL;
3318 else if (!_cups_strcasecmp(value, "actions"))
3319 AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS;
3320 else if (!_cups_strcasecmp(value, "config"))
3321 AccessLogLevel = CUPSD_ACCESSLOG_CONFIG;
3322 else if (!_cups_strcasecmp(value, "none"))
3323 AccessLogLevel = CUPSD_ACCESSLOG_NONE;
3324 else
3325 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown AccessLogLevel %s on line %d of %s.",
3326 value, linenum, ConfigurationFile);
3327 }
3328 else if (!_cups_strcasecmp(line, "LogLevel") && value)
3329 {
3330 /*
3331 * Amount of logging to do to error log...
3332 */
3333
3334 if (!_cups_strcasecmp(value, "debug2"))
3335 LogLevel = CUPSD_LOG_DEBUG2;
3336 else if (!_cups_strcasecmp(value, "debug"))
3337 LogLevel = CUPSD_LOG_DEBUG;
3338 else if (!_cups_strcasecmp(value, "info"))
3339 LogLevel = CUPSD_LOG_INFO;
3340 else if (!_cups_strcasecmp(value, "notice"))
3341 LogLevel = CUPSD_LOG_NOTICE;
3342 else if (!_cups_strcasecmp(value, "warn"))
3343 LogLevel = CUPSD_LOG_WARN;
3344 else if (!_cups_strcasecmp(value, "error"))
3345 LogLevel = CUPSD_LOG_ERROR;
3346 else if (!_cups_strcasecmp(value, "crit"))
3347 LogLevel = CUPSD_LOG_CRIT;
3348 else if (!_cups_strcasecmp(value, "alert"))
3349 LogLevel = CUPSD_LOG_ALERT;
3350 else if (!_cups_strcasecmp(value, "emerg"))
3351 LogLevel = CUPSD_LOG_EMERG;
3352 else if (!_cups_strcasecmp(value, "none"))
3353 LogLevel = CUPSD_LOG_NONE;
3354 else
3355 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogLevel %s on line %d of %s.",
3356 value, linenum, ConfigurationFile);
3357 }
3358 else if (!_cups_strcasecmp(line, "LogTimeFormat") && value)
3359 {
3360 /*
3361 * Amount of logging to do to error log...
3362 */
3363
3364 if (!_cups_strcasecmp(value, "standard"))
3365 LogTimeFormat = CUPSD_TIME_STANDARD;
3366 else if (!_cups_strcasecmp(value, "usecs"))
3367 LogTimeFormat = CUPSD_TIME_USECS;
3368 else
3369 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogTimeFormat %s on line %d of %s.",
3370 value, linenum, ConfigurationFile);
3371 }
3372 else if (!_cups_strcasecmp(line, "ServerTokens") && value)
3373 {
3374 /*
3375 * Set the string used for the Server header...
3376 */
3377
3378 struct utsname plat; /* Platform info */
3379
3380
3381 uname(&plat);
3382
3383 if (!_cups_strcasecmp(value, "ProductOnly"))
3384 cupsdSetString(&ServerHeader, "CUPS IPP");
3385 else if (!_cups_strcasecmp(value, "Major"))
3386 cupsdSetStringf(&ServerHeader, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR);
3387 else if (!_cups_strcasecmp(value, "Minor"))
3388 cupsdSetStringf(&ServerHeader, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR,
3389 CUPS_VERSION_MINOR);
3390 else if (!_cups_strcasecmp(value, "Minimal"))
3391 cupsdSetString(&ServerHeader, CUPS_MINIMAL " IPP/2.1");
3392 else if (!_cups_strcasecmp(value, "OS"))
3393 cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s %s) IPP/2.1",
3394 plat.sysname, plat.release);
3395 else if (!_cups_strcasecmp(value, "Full"))
3396 cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s %s; %s) IPP/2.1",
3397 plat.sysname, plat.release, plat.machine);
3398 else if (!_cups_strcasecmp(value, "None"))
3399 cupsdClearString(&ServerHeader);
3400 else
3401 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown ServerTokens %s on line %d of %s.",
3402 value, linenum, ConfigurationFile);
3403 }
3404 else if (!_cups_strcasecmp(line, "PassEnv") && value)
3405 {
3406 /*
3407 * PassEnv variable [... variable]
3408 */
3409
3410 for (; *value;)
3411 {
3412 for (valuelen = 0; value[valuelen]; valuelen ++)
3413 if (_cups_isspace(value[valuelen]) || value[valuelen] == ',')
3414 break;
3415
3416 if (value[valuelen])
3417 {
3418 value[valuelen] = '\0';
3419 valuelen ++;
3420 }
3421
3422 cupsdSetEnv(value, NULL);
3423
3424 for (value += valuelen; *value; value ++)
3425 if (!_cups_isspace(*value) || *value != ',')
3426 break;
3427 }
3428 }
3429 else if (!_cups_strcasecmp(line, "ServerAlias") && value)
3430 {
3431 /*
3432 * ServerAlias name [... name]
3433 */
3434
3435 if (!ServerAlias)
3436 ServerAlias = cupsArrayNew(NULL, NULL);
3437
3438 for (; *value;)
3439 {
3440 for (valuelen = 0; value[valuelen]; valuelen ++)
3441 if (_cups_isspace(value[valuelen]) || value[valuelen] == ',')
3442 break;
3443
3444 if (value[valuelen])
3445 {
3446 value[valuelen] = '\0';
3447 valuelen ++;
3448 }
3449
3450 cupsdAddAlias(ServerAlias, value);
3451
3452 for (value += valuelen; *value; value ++)
3453 if (!_cups_isspace(*value) || *value != ',')
3454 break;
3455 }
3456 }
3457 else if (!_cups_strcasecmp(line, "SetEnv") && value)
3458 {
3459 /*
3460 * SetEnv variable value
3461 */
3462
3463 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
3464
3465 if (*valueptr)
3466 {
3467 /*
3468 * Found a value...
3469 */
3470
3471 while (isspace(*valueptr & 255))
3472 *valueptr++ = '\0';
3473
3474 cupsdSetEnv(value, valueptr);
3475 }
3476 else
3477 cupsdLogMessage(CUPSD_LOG_ERROR,
3478 "Missing value for SetEnv directive on line %d of %s.",
3479 linenum, ConfigurationFile);
3480 }
3481 else if (!_cups_strcasecmp(line, "AccessLog") ||
3482 !_cups_strcasecmp(line, "CacheDir") ||
3483 !_cups_strcasecmp(line, "ConfigFilePerm") ||
3484 !_cups_strcasecmp(line, "DataDir") ||
3485 !_cups_strcasecmp(line, "DocumentRoot") ||
3486 !_cups_strcasecmp(line, "ErrorLog") ||
3487 !_cups_strcasecmp(line, "FatalErrors") ||
3488 !_cups_strcasecmp(line, "FileDevice") ||
3489 !_cups_strcasecmp(line, "FontPath") ||
3490 !_cups_strcasecmp(line, "Group") ||
3491 !_cups_strcasecmp(line, "LogFilePerm") ||
3492 !_cups_strcasecmp(line, "LPDConfigFile") ||
3493 !_cups_strcasecmp(line, "PageLog") ||
3494 !_cups_strcasecmp(line, "Printcap") ||
3495 !_cups_strcasecmp(line, "PrintcapFormat") ||
3496 !_cups_strcasecmp(line, "RemoteRoot") ||
3497 !_cups_strcasecmp(line, "RequestRoot") ||
3498 !_cups_strcasecmp(line, "ServerBin") ||
3499 !_cups_strcasecmp(line, "ServerCertificate") ||
3500 !_cups_strcasecmp(line, "ServerKey") ||
3501 !_cups_strcasecmp(line, "ServerKeychain") ||
3502 !_cups_strcasecmp(line, "ServerRoot") ||
3503 !_cups_strcasecmp(line, "SMBConfigFile") ||
3504 !_cups_strcasecmp(line, "StateDir") ||
3505 !_cups_strcasecmp(line, "SystemGroup") ||
3506 !_cups_strcasecmp(line, "SystemGroupAuthKey") ||
3507 !_cups_strcasecmp(line, "TempDir") ||
3508 !_cups_strcasecmp(line, "User"))
3509 {
3510 cupsdLogMessage(CUPSD_LOG_INFO,
3511 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3512 "this will become an error in a future release.",
3513 line, value ? " " : "", value ? value : "", linenum,
3514 ConfigurationFile, CupsFilesFile);
3515 }
3516 else
3517 parse_variable(ConfigurationFile, linenum, line, value,
3518 sizeof(cupsd_vars) / sizeof(cupsd_vars[0]), cupsd_vars);
3519 }
3520
3521 return (1);
3522 }
3523
3524
3525 /*
3526 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3527 */
3528
3529 static int /* O - 1 on success, 0 on failure */
3530 read_cups_files_conf(cups_file_t *fp) /* I - File to read from */
3531 {
3532 int linenum; /* Current line number */
3533 char line[HTTP_MAX_BUFFER], /* Line from file */
3534 *value; /* Value from line */
3535 struct group *group; /* Group */
3536
3537
3538 /*
3539 * Loop through each line in the file...
3540 */
3541
3542 linenum = 0;
3543
3544 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3545 {
3546 if (!_cups_strcasecmp(line, "FatalErrors"))
3547 FatalErrors = parse_fatal_errors(value);
3548 else if (!_cups_strcasecmp(line, "Group") && value)
3549 {
3550 /*
3551 * Group ID to run as...
3552 */
3553
3554 if (isdigit(value[0]))
3555 Group = (gid_t)atoi(value);
3556 else
3557 {
3558 endgrent();
3559 group = getgrnam(value);
3560
3561 if (group != NULL)
3562 Group = group->gr_gid;
3563 else
3564 {
3565 cupsdLogMessage(CUPSD_LOG_ERROR,
3566 "Unknown Group \"%s\" on line %d of %s.", value,
3567 linenum, CupsFilesFile);
3568 if (FatalErrors & CUPSD_FATAL_CONFIG)
3569 return (0);
3570 }
3571 }
3572 }
3573 else if (!_cups_strcasecmp(line, "PrintcapFormat") && value)
3574 {
3575 /*
3576 * Format of printcap file?
3577 */
3578
3579 if (!_cups_strcasecmp(value, "bsd"))
3580 PrintcapFormat = PRINTCAP_BSD;
3581 else if (!_cups_strcasecmp(value, "plist"))
3582 PrintcapFormat = PRINTCAP_PLIST;
3583 else if (!_cups_strcasecmp(value, "solaris"))
3584 PrintcapFormat = PRINTCAP_SOLARIS;
3585 else
3586 {
3587 cupsdLogMessage(CUPSD_LOG_ERROR,
3588 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3589 value, linenum, CupsFilesFile);
3590 if (FatalErrors & CUPSD_FATAL_CONFIG)
3591 return (0);
3592 }
3593 }
3594 else if (!_cups_strcasecmp(line, "Sandboxing") && value)
3595 {
3596 /*
3597 * Level of sandboxing?
3598 */
3599
3600 if (!_cups_strcasecmp(value, "off") && getuid())
3601 {
3602 Sandboxing = CUPSD_SANDBOXING_OFF;
3603 cupsdLogMessage(CUPSD_LOG_WARN, "Disabling sandboxing is not recommended (line %d of %s)", linenum, CupsFilesFile);
3604 }
3605 else if (!_cups_strcasecmp(value, "relaxed"))
3606 Sandboxing = CUPSD_SANDBOXING_RELAXED;
3607 else if (!_cups_strcasecmp(value, "strict"))
3608 Sandboxing = CUPSD_SANDBOXING_STRICT;
3609 else
3610 {
3611 cupsdLogMessage(CUPSD_LOG_ERROR,
3612 "Unknown Sandboxing \"%s\" on line %d of %s.",
3613 value, linenum, CupsFilesFile);
3614 if (FatalErrors & CUPSD_FATAL_CONFIG)
3615 return (0);
3616 }
3617 }
3618 else if (!_cups_strcasecmp(line, "SystemGroup") && value)
3619 {
3620 /*
3621 * SystemGroup (admin) group(s)...
3622 */
3623
3624 if (!parse_groups(value))
3625 {
3626 cupsdLogMessage(CUPSD_LOG_ERROR,
3627 "Unknown SystemGroup \"%s\" on line %d of %s.", value,
3628 linenum, CupsFilesFile);
3629 if (FatalErrors & CUPSD_FATAL_CONFIG)
3630 return (0);
3631 }
3632 }
3633 else if (!_cups_strcasecmp(line, "User") && value)
3634 {
3635 /*
3636 * User ID to run as...
3637 */
3638
3639 if (isdigit(value[0] & 255))
3640 {
3641 int uid = atoi(value);
3642
3643 if (!uid)
3644 {
3645 cupsdLogMessage(CUPSD_LOG_ERROR,
3646 "Will not use User 0 as specified on line %d of %s "
3647 "for security reasons. You must use a non-"
3648 "privileged account instead.",
3649 linenum, CupsFilesFile);
3650 if (FatalErrors & CUPSD_FATAL_CONFIG)
3651 return (0);
3652 }
3653 else
3654 User = (uid_t)atoi(value);
3655 }
3656 else
3657 {
3658 struct passwd *p; /* Password information */
3659
3660 endpwent();
3661 p = getpwnam(value);
3662
3663 if (p)
3664 {
3665 if (!p->pw_uid)
3666 {
3667 cupsdLogMessage(CUPSD_LOG_ERROR,
3668 "Will not use User %s (UID=0) as specified on line "
3669 "%d of %s for security reasons. You must use a "
3670 "non-privileged account instead.",
3671 value, linenum, CupsFilesFile);
3672 if (FatalErrors & CUPSD_FATAL_CONFIG)
3673 return (0);
3674 }
3675 else
3676 User = p->pw_uid;
3677 }
3678 else
3679 {
3680 cupsdLogMessage(CUPSD_LOG_ERROR,
3681 "Unknown User \"%s\" on line %d of %s.",
3682 value, linenum, CupsFilesFile);
3683 if (FatalErrors & CUPSD_FATAL_CONFIG)
3684 return (0);
3685 }
3686 }
3687 }
3688 else if (!_cups_strcasecmp(line, "ServerCertificate") ||
3689 !_cups_strcasecmp(line, "ServerKey"))
3690 {
3691 cupsdLogMessage(CUPSD_LOG_INFO,
3692 "The \"%s\" directive on line %d of %s is no longer "
3693 "supported; this will become an error in a future "
3694 "release.",
3695 line, linenum, CupsFilesFile);
3696 }
3697 else if (!parse_variable(CupsFilesFile, linenum, line, value,
3698 sizeof(cupsfiles_vars) / sizeof(cupsfiles_vars[0]),
3699 cupsfiles_vars) &&
3700 (FatalErrors & CUPSD_FATAL_CONFIG))
3701 return (0);
3702 }
3703
3704 return (1);
3705 }
3706
3707
3708 /*
3709 * 'read_location()' - Read a <Location path> definition.
3710 */
3711
3712 static int /* O - New line number or 0 on error */
3713 read_location(cups_file_t *fp, /* I - Configuration file */
3714 char *location, /* I - Location name/path */
3715 int linenum) /* I - Current line number */
3716 {
3717 cupsd_location_t *loc, /* New location */
3718 *parent; /* Parent location */
3719 char line[HTTP_MAX_BUFFER],
3720 /* Line buffer */
3721 *value, /* Value for directive */
3722 *valptr; /* Pointer into value */
3723
3724
3725 if ((parent = cupsdFindLocation(location)) != NULL)
3726 cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Location %s> on line %d of %s.",
3727 location, linenum, ConfigurationFile);
3728 else if ((parent = cupsdNewLocation(location)) == NULL)
3729 return (0);
3730 else
3731 {
3732 cupsdAddLocation(parent);
3733
3734 parent->limit = CUPSD_AUTH_LIMIT_ALL;
3735 }
3736
3737 loc = parent;
3738
3739 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3740 {
3741 /*
3742 * Decode the directive...
3743 */
3744
3745 if (!_cups_strcasecmp(line, "</Location>"))
3746 return (linenum);
3747 else if (!_cups_strcasecmp(line, "<Limit") ||
3748 !_cups_strcasecmp(line, "<LimitExcept"))
3749 {
3750 if (!value)
3751 {
3752 cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d of %s.", linenum, ConfigurationFile);
3753 if (FatalErrors & CUPSD_FATAL_CONFIG)
3754 return (0);
3755 else
3756 continue;
3757 }
3758
3759 if ((loc = cupsdCopyLocation(parent)) == NULL)
3760 return (0);
3761
3762 cupsdAddLocation(loc);
3763
3764 loc->limit = 0;
3765 while (*value)
3766 {
3767 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3768
3769 if (*valptr)
3770 *valptr++ = '\0';
3771
3772 if (!strcmp(value, "ALL"))
3773 loc->limit = CUPSD_AUTH_LIMIT_ALL;
3774 else if (!strcmp(value, "GET"))
3775 loc->limit |= CUPSD_AUTH_LIMIT_GET;
3776 else if (!strcmp(value, "HEAD"))
3777 loc->limit |= CUPSD_AUTH_LIMIT_HEAD;
3778 else if (!strcmp(value, "OPTIONS"))
3779 loc->limit |= CUPSD_AUTH_LIMIT_OPTIONS;
3780 else if (!strcmp(value, "POST"))
3781 loc->limit |= CUPSD_AUTH_LIMIT_POST;
3782 else if (!strcmp(value, "PUT"))
3783 loc->limit |= CUPSD_AUTH_LIMIT_PUT;
3784 else if (!strcmp(value, "TRACE"))
3785 loc->limit |= CUPSD_AUTH_LIMIT_TRACE;
3786 else
3787 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown request type %s on line %d of %s.",
3788 value, linenum, ConfigurationFile);
3789
3790 for (value = valptr; isspace(*value & 255); value ++);
3791 }
3792
3793 if (!_cups_strcasecmp(line, "<LimitExcept"))
3794 loc->limit = CUPSD_AUTH_LIMIT_ALL ^ loc->limit;
3795
3796 parent->limit &= ~loc->limit;
3797 }
3798 else if (!_cups_strcasecmp(line, "</Limit>") ||
3799 !_cups_strcasecmp(line, "</LimitExcept>"))
3800 loc = parent;
3801 else if (!value)
3802 {
3803 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d of %s.", linenum, ConfigurationFile);
3804 if (FatalErrors & CUPSD_FATAL_CONFIG)
3805 return (0);
3806 }
3807 else if (!parse_aaa(loc, line, value, linenum))
3808 {
3809 cupsdLogMessage(CUPSD_LOG_ERROR,
3810 "Unknown Location directive %s on line %d of %s.",
3811 line, linenum, ConfigurationFile);
3812 if (FatalErrors & CUPSD_FATAL_CONFIG)
3813 return (0);
3814 }
3815 }
3816
3817 cupsdLogMessage(CUPSD_LOG_ERROR,
3818 "Unexpected end-of-file at line %d while reading location.",
3819 linenum);
3820
3821 return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
3822 }
3823
3824
3825 /*
3826 * 'read_policy()' - Read a <Policy name> definition.
3827 */
3828
3829 static int /* O - New line number or 0 on error */
3830 read_policy(cups_file_t *fp, /* I - Configuration file */
3831 char *policy, /* I - Location name/path */
3832 int linenum) /* I - Current line number */
3833 {
3834 int i; /* Looping var */
3835 cupsd_policy_t *pol; /* Policy */
3836 cupsd_location_t *op; /* Policy operation */
3837 int num_ops; /* Number of IPP operations */
3838 ipp_op_t ops[100]; /* Operations */
3839 char line[HTTP_MAX_BUFFER],
3840 /* Line buffer */
3841 *value, /* Value for directive */
3842 *valptr; /* Pointer into value */
3843
3844
3845 /*
3846 * Create the policy...
3847 */
3848
3849 if ((pol = cupsdFindPolicy(policy)) != NULL)
3850 cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Policy %s> on line %d of %s.",
3851 policy, linenum, ConfigurationFile);
3852 else if ((pol = cupsdAddPolicy(policy)) == NULL)
3853 return (0);
3854
3855 /*
3856 * Read from the file...
3857 */
3858
3859 op = NULL;
3860 num_ops = 0;
3861
3862 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3863 {
3864 /*
3865 * Decode the directive...
3866 */
3867
3868 if (!_cups_strcasecmp(line, "</Policy>"))
3869 {
3870 if (op)
3871 cupsdLogMessage(CUPSD_LOG_WARN,
3872 "Missing </Limit> before </Policy> on line %d of %s.",
3873 linenum, ConfigurationFile);
3874
3875 set_policy_defaults(pol);
3876
3877 return (linenum);
3878 }
3879 else if (!_cups_strcasecmp(line, "<Limit") && !op)
3880 {
3881 if (!value)
3882 {
3883 cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d of %s.", linenum, ConfigurationFile);
3884 if (FatalErrors & CUPSD_FATAL_CONFIG)
3885 return (0);
3886 else
3887 continue;
3888 }
3889
3890 /*
3891 * Scan for IPP operation names...
3892 */
3893
3894 num_ops = 0;
3895
3896 while (*value)
3897 {
3898 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3899
3900 if (*valptr)
3901 *valptr++ = '\0';
3902
3903 if (num_ops < (int)(sizeof(ops) / sizeof(ops[0])))
3904 {
3905 if (!_cups_strcasecmp(value, "All"))
3906 ops[num_ops] = IPP_ANY_OPERATION;
3907 else if ((ops[num_ops] = ippOpValue(value)) == IPP_BAD_OPERATION)
3908 cupsdLogMessage(CUPSD_LOG_ERROR,
3909 "Bad IPP operation name \"%s\" on line %d of %s.",
3910 value, linenum, ConfigurationFile);
3911 else
3912 num_ops ++;
3913 }
3914 else
3915 cupsdLogMessage(CUPSD_LOG_ERROR,
3916 "Too many operations listed on line %d of %s.",
3917 linenum, ConfigurationFile);
3918
3919 for (value = valptr; isspace(*value & 255); value ++);
3920 }
3921
3922 /*
3923 * If none are specified, apply the policy to all operations...
3924 */
3925
3926 if (num_ops == 0)
3927 {
3928 ops[0] = IPP_ANY_OPERATION;
3929 num_ops = 1;
3930 }
3931
3932 /*
3933 * Add a new policy for the first operation...
3934 */
3935
3936 op = cupsdAddPolicyOp(pol, NULL, ops[0]);
3937 }
3938 else if (!_cups_strcasecmp(line, "</Limit>") && op)
3939 {
3940 /*
3941 * Finish the current operation limit...
3942 */
3943
3944 if (num_ops > 1)
3945 {
3946 /*
3947 * Copy the policy to the other operations...
3948 */
3949
3950 for (i = 1; i < num_ops; i ++)
3951 cupsdAddPolicyOp(pol, op, ops[i]);
3952 }
3953
3954 op = NULL;
3955 }
3956 else if (!value)
3957 {
3958 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d of %s.", linenum, ConfigurationFile);
3959 if (FatalErrors & CUPSD_FATAL_CONFIG)
3960 return (0);
3961 }
3962 else if (!_cups_strcasecmp(line, "JobPrivateAccess") ||
3963 !_cups_strcasecmp(line, "JobPrivateValues") ||
3964 !_cups_strcasecmp(line, "SubscriptionPrivateAccess") ||
3965 !_cups_strcasecmp(line, "SubscriptionPrivateValues"))
3966 {
3967 if (op)
3968 {
3969 cupsdLogMessage(CUPSD_LOG_ERROR,
3970 "%s directive must appear outside <Limit>...</Limit> "
3971 "on line %d of %s.", line, linenum, ConfigurationFile);
3972 if (FatalErrors & CUPSD_FATAL_CONFIG)
3973 return (0);
3974 }
3975 else
3976 {
3977 /*
3978 * Pull out whitespace-delimited values...
3979 */
3980
3981 while (*value)
3982 {
3983 /*
3984 * Find the end of the current value...
3985 */
3986
3987 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3988
3989 if (*valptr)
3990 *valptr++ = '\0';
3991
3992 /*
3993 * Save it appropriately...
3994 */
3995
3996 if (!_cups_strcasecmp(line, "JobPrivateAccess"))
3997 {
3998 /*
3999 * JobPrivateAccess {all|default|user/group list|@@ACL}
4000 */
4001
4002 if (!_cups_strcasecmp(value, "default"))
4003 {
4004 cupsdAddString(&(pol->job_access), "@OWNER");
4005 cupsdAddString(&(pol->job_access), "@SYSTEM");
4006 }
4007 else
4008 cupsdAddString(&(pol->job_access), value);
4009 }
4010 else if (!_cups_strcasecmp(line, "JobPrivateValues"))
4011 {
4012 /*
4013 * JobPrivateValues {all|none|default|attribute list}
4014 */
4015
4016 if (!_cups_strcasecmp(value, "default"))
4017 {
4018 cupsdAddString(&(pol->job_attrs), "job-name");
4019 cupsdAddString(&(pol->job_attrs), "job-originating-host-name");
4020 cupsdAddString(&(pol->job_attrs), "job-originating-user-name");
4021 cupsdAddString(&(pol->job_attrs), "phone");
4022 }
4023 else
4024 cupsdAddString(&(pol->job_attrs), value);
4025 }
4026 else if (!_cups_strcasecmp(line, "SubscriptionPrivateAccess"))
4027 {
4028 /*
4029 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
4030 */
4031
4032 if (!_cups_strcasecmp(value, "default"))
4033 {
4034 cupsdAddString(&(pol->sub_access), "@OWNER");
4035 cupsdAddString(&(pol->sub_access), "@SYSTEM");
4036 }
4037 else
4038 cupsdAddString(&(pol->sub_access), value);
4039 }
4040 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
4041 {
4042 /*
4043 * SubscriptionPrivateValues {all|none|default|attribute list}
4044 */
4045
4046 if (!_cups_strcasecmp(value, "default"))
4047 {
4048 cupsdAddString(&(pol->sub_attrs), "notify-events");
4049 cupsdAddString(&(pol->sub_attrs), "notify-pull-method");
4050 cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri");
4051 cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name");
4052 cupsdAddString(&(pol->sub_attrs), "notify-user-data");
4053 }
4054 else
4055 cupsdAddString(&(pol->sub_attrs), value);
4056 }
4057
4058 /*
4059 * Find the next string on the line...
4060 */
4061
4062 for (value = valptr; isspace(*value & 255); value ++);
4063 }
4064 }
4065 }
4066 else if (!op)
4067 {
4068 cupsdLogMessage(CUPSD_LOG_ERROR,
4069 "Missing <Limit ops> directive before %s on line %d of %s.",
4070 line, linenum, ConfigurationFile);
4071 if (FatalErrors & CUPSD_FATAL_CONFIG)
4072 return (0);
4073 }
4074 else if (!parse_aaa(op, line, value, linenum))
4075 {
4076 cupsdLogMessage(CUPSD_LOG_ERROR,
4077 "Unknown Policy Limit directive %s on line %d of %s.",
4078 line, linenum, ConfigurationFile);
4079
4080 if (FatalErrors & CUPSD_FATAL_CONFIG)
4081 return (0);
4082 }
4083 }
4084
4085 cupsdLogMessage(CUPSD_LOG_ERROR,
4086 "Unexpected end-of-file at line %d while reading policy "
4087 "\"%s\".", linenum, policy);
4088
4089 return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
4090 }
4091
4092
4093 /*
4094 * 'set_policy_defaults()' - Set default policy values as needed.
4095 */
4096
4097 static void
4098 set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
4099 {
4100 cupsd_location_t *op; /* Policy operation */
4101
4102
4103 /*
4104 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4105 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4106 * upgrades do not introduce new security issues...
4107 *
4108 * CUPS STR #4659: Allow a lone <Limit All> policy.
4109 */
4110
4111 if (cupsArrayCount(pol->ops) > 1)
4112 {
4113 if ((op = cupsdFindPolicyOp(pol, IPP_VALIDATE_JOB)) == NULL ||
4114 op->op == IPP_ANY_OPERATION)
4115 {
4116 if ((op = cupsdFindPolicyOp(pol, IPP_PRINT_JOB)) != NULL &&
4117 op->op != IPP_ANY_OPERATION)
4118 {
4119 /*
4120 * Add a new limit for Validate-Job using the Print-Job limit as a
4121 * template...
4122 */
4123
4124 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol->name);
4125
4126 cupsdAddPolicyOp(pol, op, IPP_VALIDATE_JOB);
4127 }
4128 else
4129 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol->name);
4130 }
4131
4132 if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_JOBS)) == NULL ||
4133 op->op == IPP_ANY_OPERATION)
4134 {
4135 if ((op = cupsdFindPolicyOp(pol, IPP_PAUSE_PRINTER)) != NULL &&
4136 op->op != IPP_ANY_OPERATION)
4137 {
4138 /*
4139 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4140 * template...
4141 */
4142
4143 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol->name);
4144
4145 cupsdAddPolicyOp(pol, op, IPP_CANCEL_JOBS);
4146 }
4147 else
4148 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol->name);
4149 }
4150
4151 if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_MY_JOBS)) == NULL ||
4152 op->op == IPP_ANY_OPERATION)
4153 {
4154 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
4155 op->op != IPP_ANY_OPERATION)
4156 {
4157 /*
4158 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4159 * a template...
4160 */
4161
4162 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol->name);
4163
4164 cupsdAddPolicyOp(pol, op, IPP_CANCEL_MY_JOBS);
4165 }
4166 else
4167 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol->name);
4168 }
4169
4170 if ((op = cupsdFindPolicyOp(pol, IPP_CLOSE_JOB)) == NULL ||
4171 op->op == IPP_ANY_OPERATION)
4172 {
4173 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
4174 op->op != IPP_ANY_OPERATION)
4175 {
4176 /*
4177 * Add a new limit for Close-Job using the Send-Document limit as a
4178 * template...
4179 */
4180
4181 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol->name);
4182
4183 cupsdAddPolicyOp(pol, op, IPP_CLOSE_JOB);
4184 }
4185 else
4186 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Close-Job defined in policy %s and no suitable template found.", pol->name);
4187 }
4188
4189 if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL ||
4190 op->op == IPP_ANY_OPERATION)
4191 {
4192 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
4193 op->op != IPP_ANY_OPERATION)
4194 {
4195 /*
4196 * Add a new limit for CUPS-Get-Document using the Send-Document
4197 * limit as a template...
4198 */
4199
4200 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol->name);
4201
4202 cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT);
4203 }
4204 else
4205 cupsdLogMessage(CUPSD_LOG_WARN, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol->name);
4206 }
4207 }
4208
4209 /*
4210 * Verify we have JobPrivateAccess, JobPrivateValues,
4211 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4212 */
4213
4214 if (!pol->job_access)
4215 {
4216 cupsdLogMessage(CUPSD_LOG_WARN, "No JobPrivateAccess defined in policy %s - using defaults.", pol->name);
4217 cupsdAddString(&(pol->job_access), "@OWNER");
4218 cupsdAddString(&(pol->job_access), "@SYSTEM");
4219 }
4220
4221 if (!pol->job_attrs)
4222 {
4223 cupsdLogMessage(CUPSD_LOG_WARN, "No JobPrivateValues defined in policy %s - using defaults.", pol->name);
4224 cupsdAddString(&(pol->job_attrs), "job-name");
4225 cupsdAddString(&(pol->job_attrs), "job-originating-host-name");
4226 cupsdAddString(&(pol->job_attrs), "job-originating-user-name");
4227 cupsdAddString(&(pol->job_attrs), "phone");
4228 }
4229
4230 if (!pol->sub_access)
4231 {
4232 cupsdLogMessage(CUPSD_LOG_WARN, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol->name);
4233 cupsdAddString(&(pol->sub_access), "@OWNER");
4234 cupsdAddString(&(pol->sub_access), "@SYSTEM");
4235 }
4236
4237 if (!pol->sub_attrs)
4238 {
4239 cupsdLogMessage(CUPSD_LOG_WARN, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol->name);
4240 cupsdAddString(&(pol->sub_attrs), "notify-events");
4241 cupsdAddString(&(pol->sub_attrs), "notify-pull-method");
4242 cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri");
4243 cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name");
4244 cupsdAddString(&(pol->sub_attrs), "notify-user-data");
4245 }
4246 }
4247
4248
4249 /*
4250 * End of "$Id$".
4251 */