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