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