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