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