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