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