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