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