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