]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/conf.c
Merge changes from CUPS 1.6svn-r10112.
[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 if ((tmpdir = getenv("TMPDIR")) != NULL)
949 {
950 /*
951 * TMPDIR is defined, see if it is OK for us to use...
952 */
953
954 if (stat(tmpdir, &tmpinfo))
955 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s",
956 tmpdir, strerror(errno));
957 else if (!S_ISDIR(tmpinfo.st_mode))
958 cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory.",
959 tmpdir);
960 else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) &&
961 (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) &&
962 !(tmpinfo.st_mode & S_IWOTH))
963 cupsdLogMessage(CUPSD_LOG_ERROR,
964 "TMPDIR (%s) has the wrong permissions.", tmpdir);
965 else
966 cupsdSetString(&TempDir, tmpdir);
967 }
968
969 if (!TempDir)
970 {
971 cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...",
972 RequestRoot);
973 cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot);
974 }
975 }
976
977 /*
978 * Make sure the temporary directory has the right permissions...
979 */
980
981 if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) ||
982 access(TempDir, 0))
983 {
984 /*
985 * Update ownership and permissions if the CUPS temp directory
986 * is under the spool directory or does not exist...
987 */
988
989 if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 &&
990 (FatalErrors & CUPSD_FATAL_PERMISSIONS))
991 return (0);
992 }
993
994 /*
995 * Update environment variables...
996 */
997
998 cupsdUpdateEnv();
999
1000 /*
1001 * Update default paper size setting as needed...
1002 */
1003
1004 if (!DefaultPaperSize)
1005 {
1006 #ifdef HAVE_LIBPAPER
1007 char *paper_result; /* Paper size name from libpaper */
1008
1009 if ((paper_result = systempapername()) != NULL)
1010 cupsdSetString(&DefaultPaperSize, paper_result);
1011 else
1012 #endif /* HAVE_LIBPAPER */
1013 if (!DefaultLanguage ||
1014 !_cups_strcasecmp(DefaultLanguage, "C") ||
1015 !_cups_strcasecmp(DefaultLanguage, "POSIX") ||
1016 !_cups_strcasecmp(DefaultLanguage, "en") ||
1017 !_cups_strncasecmp(DefaultLanguage, "en.", 3) ||
1018 !_cups_strncasecmp(DefaultLanguage, "en_US", 5) ||
1019 !_cups_strncasecmp(DefaultLanguage, "en_CA", 5) ||
1020 !_cups_strncasecmp(DefaultLanguage, "fr_CA", 5))
1021 {
1022 /*
1023 * These are the only locales that will default to "letter" size...
1024 */
1025
1026 cupsdSetString(&DefaultPaperSize, "Letter");
1027 }
1028 else
1029 cupsdSetString(&DefaultPaperSize, "A4");
1030 }
1031
1032 /*
1033 * Update classification setting as needed...
1034 */
1035
1036 if (Classification && !_cups_strcasecmp(Classification, "none"))
1037 cupsdClearString(&Classification);
1038
1039 if (Classification)
1040 cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
1041
1042 /*
1043 * Check the MaxClients setting, and then allocate memory for it...
1044 */
1045
1046 if (MaxClients > (MaxFDs / 3) || MaxClients <= 0)
1047 {
1048 if (MaxClients > 0)
1049 cupsdLogMessage(CUPSD_LOG_INFO,
1050 "MaxClients limited to 1/3 (%d) of the file descriptor "
1051 "limit (%d)...",
1052 MaxFDs / 3, MaxFDs);
1053
1054 MaxClients = MaxFDs / 3;
1055 }
1056
1057 cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
1058 MaxClients);
1059
1060 /*
1061 * Check the MaxActiveJobs setting; limit to 1/3 the available
1062 * file descriptors, since we need a pipe for each job...
1063 */
1064
1065 if (MaxActiveJobs > (MaxFDs / 3))
1066 MaxActiveJobs = MaxFDs / 3;
1067
1068 /*
1069 * Update the MaxClientsPerHost value, as needed...
1070 */
1071
1072 if (MaxClientsPerHost <= 0)
1073 MaxClientsPerHost = MaxClients;
1074
1075 if (MaxClientsPerHost > MaxClients)
1076 MaxClientsPerHost = MaxClients;
1077
1078 cupsdLogMessage(CUPSD_LOG_INFO,
1079 "Allowing up to %d client connections per host.",
1080 MaxClientsPerHost);
1081
1082 /*
1083 * Update the default policy, as needed...
1084 */
1085
1086 if (DefaultPolicy)
1087 DefaultPolicyPtr = cupsdFindPolicy(DefaultPolicy);
1088 else
1089 DefaultPolicyPtr = NULL;
1090
1091 if (!DefaultPolicyPtr)
1092 {
1093 cupsd_location_t *po; /* New policy operation */
1094
1095
1096 if (DefaultPolicy)
1097 cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found.",
1098 DefaultPolicy);
1099
1100 cupsdSetString(&DefaultPolicy, "default");
1101
1102 if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL)
1103 cupsdLogMessage(CUPSD_LOG_INFO,
1104 "Using policy \"default\" as the default.");
1105 else
1106 {
1107 cupsdLogMessage(CUPSD_LOG_INFO,
1108 "Creating CUPS default administrative policy:");
1109
1110 DefaultPolicyPtr = p = cupsdAddPolicy("default");
1111
1112 cupsdLogMessage(CUPSD_LOG_INFO, "<Policy default>");
1113
1114 cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateAccess default");
1115 cupsdAddString(&(p->job_access), "@OWNER");
1116 cupsdAddString(&(p->job_access), "@SYSTEM");
1117
1118 cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateValues default");
1119 cupsdAddString(&(p->job_attrs), "job-name");
1120 cupsdAddString(&(p->job_attrs), "job-originating-host-name");
1121 cupsdAddString(&(p->job_attrs), "job-originating-user-name");
1122
1123 cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateAccess default");
1124 cupsdAddString(&(p->sub_access), "@OWNER");
1125 cupsdAddString(&(p->sub_access), "@SYSTEM");
1126
1127 cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateValues default");
1128 cupsdAddString(&(p->job_attrs), "notify-events");
1129 cupsdAddString(&(p->job_attrs), "notify-pull-method");
1130 cupsdAddString(&(p->job_attrs), "notify-recipient-uri");
1131 cupsdAddString(&(p->job_attrs), "notify-subscriber-user-name");
1132 cupsdAddString(&(p->job_attrs), "notify-user-data");
1133
1134 cupsdLogMessage(CUPSD_LOG_INFO,
1135 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1136 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1137
1138 po = cupsdAddPolicyOp(p, NULL, IPP_CREATE_JOB);
1139 po->order_type = CUPSD_AUTH_ALLOW;
1140
1141 cupsdAddPolicyOp(p, po, IPP_PRINT_JOB);
1142 cupsdAddPolicyOp(p, po, IPP_PRINT_URI);
1143 cupsdAddPolicyOp(p, po, IPP_VALIDATE_JOB);
1144
1145 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1146
1147 cupsdLogMessage(CUPSD_LOG_INFO,
1148 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1149 "Release-Job Restart-Job Purge-Jobs "
1150 "Set-Job-Attributes Create-Job-Subscription "
1151 "Renew-Subscription Cancel-Subscription "
1152 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1153 "Suspend-Current-Job Resume-Job "
1154 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1155 "CUPS-Authenticate-Job CUPS-Get-Document>");
1156 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1157
1158 po = cupsdAddPolicyOp(p, NULL, IPP_SEND_DOCUMENT);
1159 po->order_type = CUPSD_AUTH_ALLOW;
1160 po->level = CUPSD_AUTH_USER;
1161
1162 cupsdAddName(po, "@OWNER");
1163 cupsdAddName(po, "@SYSTEM");
1164 cupsdLogMessage(CUPSD_LOG_INFO, "Require user @OWNER @SYSTEM");
1165
1166 cupsdAddPolicyOp(p, po, IPP_SEND_URI);
1167 cupsdAddPolicyOp(p, po, IPP_CANCEL_JOB);
1168 cupsdAddPolicyOp(p, po, IPP_HOLD_JOB);
1169 cupsdAddPolicyOp(p, po, IPP_RELEASE_JOB);
1170 cupsdAddPolicyOp(p, po, IPP_RESTART_JOB);
1171 cupsdAddPolicyOp(p, po, IPP_PURGE_JOBS);
1172 cupsdAddPolicyOp(p, po, IPP_SET_JOB_ATTRIBUTES);
1173 cupsdAddPolicyOp(p, po, IPP_CREATE_JOB_SUBSCRIPTION);
1174 cupsdAddPolicyOp(p, po, IPP_RENEW_SUBSCRIPTION);
1175 cupsdAddPolicyOp(p, po, IPP_CANCEL_SUBSCRIPTION);
1176 cupsdAddPolicyOp(p, po, IPP_GET_NOTIFICATIONS);
1177 cupsdAddPolicyOp(p, po, IPP_REPROCESS_JOB);
1178 cupsdAddPolicyOp(p, po, IPP_CANCEL_CURRENT_JOB);
1179 cupsdAddPolicyOp(p, po, IPP_SUSPEND_CURRENT_JOB);
1180 cupsdAddPolicyOp(p, po, IPP_RESUME_JOB);
1181 cupsdAddPolicyOp(p, po, IPP_CANCEL_MY_JOBS);
1182 cupsdAddPolicyOp(p, po, IPP_CLOSE_JOB);
1183 cupsdAddPolicyOp(p, po, CUPS_MOVE_JOB);
1184 cupsdAddPolicyOp(p, po, CUPS_AUTHENTICATE_JOB);
1185 cupsdAddPolicyOp(p, po, CUPS_GET_DOCUMENT);
1186
1187 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1188
1189 cupsdLogMessage(CUPSD_LOG_INFO,
1190 "<Limit Pause-Printer Resume-Printer "
1191 "Set-Printer-Attributes Enable-Printer "
1192 "Disable-Printer Pause-Printer-After-Current-Job "
1193 "Hold-New-Jobs Release-Held-New-Jobs "
1194 "Deactivate-Printer Activate-Printer Restart-Printer "
1195 "Shutdown-Printer Startup-Printer Promote-Job "
1196 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1197 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1198 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1199 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1200 cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Default");
1201
1202 po = cupsdAddPolicyOp(p, NULL, IPP_PAUSE_PRINTER);
1203 po->order_type = CUPSD_AUTH_ALLOW;
1204 po->type = CUPSD_AUTH_DEFAULT;
1205 po->level = CUPSD_AUTH_USER;
1206
1207 cupsdAddName(po, "@SYSTEM");
1208 cupsdLogMessage(CUPSD_LOG_INFO, "Require user @SYSTEM");
1209
1210 cupsdAddPolicyOp(p, po, IPP_RESUME_PRINTER);
1211 cupsdAddPolicyOp(p, po, IPP_SET_PRINTER_ATTRIBUTES);
1212 cupsdAddPolicyOp(p, po, IPP_ENABLE_PRINTER);
1213 cupsdAddPolicyOp(p, po, IPP_DISABLE_PRINTER);
1214 cupsdAddPolicyOp(p, po, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB);
1215 cupsdAddPolicyOp(p, po, IPP_HOLD_NEW_JOBS);
1216 cupsdAddPolicyOp(p, po, IPP_RELEASE_HELD_NEW_JOBS);
1217 cupsdAddPolicyOp(p, po, IPP_DEACTIVATE_PRINTER);
1218 cupsdAddPolicyOp(p, po, IPP_ACTIVATE_PRINTER);
1219 cupsdAddPolicyOp(p, po, IPP_RESTART_PRINTER);
1220 cupsdAddPolicyOp(p, po, IPP_SHUTDOWN_PRINTER);
1221 cupsdAddPolicyOp(p, po, IPP_STARTUP_PRINTER);
1222 cupsdAddPolicyOp(p, po, IPP_PROMOTE_JOB);
1223 cupsdAddPolicyOp(p, po, IPP_SCHEDULE_JOB_AFTER);
1224 cupsdAddPolicyOp(p, po, IPP_CANCEL_JOBS);
1225 cupsdAddPolicyOp(p, po, CUPS_ADD_PRINTER);
1226 cupsdAddPolicyOp(p, po, CUPS_DELETE_PRINTER);
1227 cupsdAddPolicyOp(p, po, CUPS_ADD_CLASS);
1228 cupsdAddPolicyOp(p, po, CUPS_DELETE_CLASS);
1229 cupsdAddPolicyOp(p, po, CUPS_ACCEPT_JOBS);
1230 cupsdAddPolicyOp(p, po, CUPS_REJECT_JOBS);
1231 cupsdAddPolicyOp(p, po, CUPS_SET_DEFAULT);
1232
1233 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1234
1235 cupsdLogMessage(CUPSD_LOG_INFO, "<Limit All>");
1236 cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
1237
1238 po = cupsdAddPolicyOp(p, NULL, IPP_ANY_OPERATION);
1239 po->order_type = CUPSD_AUTH_ALLOW;
1240
1241 cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
1242 cupsdLogMessage(CUPSD_LOG_INFO, "</Policy>");
1243 }
1244 }
1245
1246 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d",
1247 cupsArrayCount(Policies));
1248 for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
1249 p;
1250 i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
1251 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1252 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i, p->name);
1253
1254 /*
1255 * If we are doing a full reload or the server root has changed, flush
1256 * the jobs, printers, etc. and start from scratch...
1257 */
1258
1259 if (NeedReload == RELOAD_ALL ||
1260 old_remote_port != RemotePort ||
1261 !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) ||
1262 !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot))
1263 {
1264 mime_type_t *type; /* Current type */
1265 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE];
1266 /* MIME type name */
1267
1268
1269 cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required.");
1270
1271 /*
1272 * Free all memory...
1273 */
1274
1275 cupsdDeleteAllSubscriptions();
1276 cupsdFreeAllJobs();
1277 cupsdDeleteAllPrinters();
1278
1279 DefaultPrinter = NULL;
1280
1281 if (MimeDatabase != NULL)
1282 mimeDelete(MimeDatabase);
1283
1284 if (NumMimeTypes)
1285 {
1286 for (i = 0; i < NumMimeTypes; i ++)
1287 _cupsStrFree(MimeTypes[i]);
1288
1289 free(MimeTypes);
1290 }
1291
1292 /*
1293 * Read the MIME type and conversion database...
1294 */
1295
1296 snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
1297 snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
1298
1299 MimeDatabase = mimeNew();
1300 mimeSetErrorCallback(MimeDatabase, mime_error_cb, NULL);
1301
1302 MimeDatabase = mimeLoadTypes(MimeDatabase, mimedir);
1303 MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
1304 MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
1305 MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
1306
1307 if (!MimeDatabase)
1308 {
1309 cupsdLogMessage(CUPSD_LOG_EMERG,
1310 "Unable to load MIME database from \"%s\" or \"%s\".",
1311 mimedir, ServerRoot);
1312 if (FatalErrors & CUPSD_FATAL_CONFIG)
1313 return (0);
1314 }
1315
1316 cupsdLogMessage(CUPSD_LOG_INFO,
1317 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1318 "%d filters...", mimedir, ServerRoot,
1319 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
1320
1321 /*
1322 * Create a list of MIME types for the document-format-supported
1323 * attribute...
1324 */
1325
1326 NumMimeTypes = mimeNumTypes(MimeDatabase);
1327 if (!mimeType(MimeDatabase, "application", "octet-stream"))
1328 NumMimeTypes ++;
1329
1330 if ((MimeTypes = calloc(NumMimeTypes, sizeof(const char *))) == NULL)
1331 {
1332 cupsdLogMessage(CUPSD_LOG_ERROR,
1333 "Unable to allocate memory for %d MIME types.",
1334 NumMimeTypes);
1335 NumMimeTypes = 0;
1336 }
1337 else
1338 {
1339 for (i = 0, type = mimeFirstType(MimeDatabase);
1340 type;
1341 i ++, type = mimeNextType(MimeDatabase))
1342 {
1343 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
1344
1345 MimeTypes[i] = _cupsStrAlloc(mimetype);
1346 }
1347
1348 if (i < NumMimeTypes)
1349 MimeTypes[i] = _cupsStrAlloc("application/octet-stream");
1350 }
1351
1352 if (LogLevel == CUPSD_LOG_DEBUG2)
1353 {
1354 mime_filter_t *filter; /* Current filter */
1355
1356
1357 for (type = mimeFirstType(MimeDatabase);
1358 type;
1359 type = mimeNextType(MimeDatabase))
1360 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s",
1361 type->super, type->type);
1362
1363 for (filter = mimeFirstFilter(MimeDatabase);
1364 filter;
1365 filter = mimeNextFilter(MimeDatabase))
1366 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1367 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1368 filter->src->super, filter->src->type,
1369 filter->dst->super, filter->dst->type,
1370 filter->cost, filter->filter);
1371 }
1372
1373 /*
1374 * Load banners...
1375 */
1376
1377 snprintf(temp, sizeof(temp), "%s/banners", DataDir);
1378 cupsdLoadBanners(temp);
1379
1380 /*
1381 * Load printers and classes...
1382 */
1383
1384 cupsdLoadAllPrinters();
1385 cupsdLoadAllClasses();
1386
1387 cupsdCreateCommonData();
1388
1389 /*
1390 * Update the printcap file as needed...
1391 */
1392
1393 if (Printcap && *Printcap && access(Printcap, 0))
1394 cupsdWritePrintcap();
1395
1396 /*
1397 * Load queued jobs...
1398 */
1399
1400 cupsdLoadAllJobs();
1401
1402 /*
1403 * Load subscriptions...
1404 */
1405
1406 cupsdLoadAllSubscriptions();
1407
1408 cupsdLogMessage(CUPSD_LOG_INFO, "Full reload complete.");
1409 }
1410 else
1411 {
1412 /*
1413 * Not a full reload, so recreate the common printer attributes...
1414 */
1415
1416 cupsdCreateCommonData();
1417
1418 /*
1419 * Update all printers as needed...
1420 */
1421
1422 cupsdUpdatePrinters();
1423 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
1424
1425 cupsdLogMessage(CUPSD_LOG_INFO, "Partial reload complete.");
1426 }
1427
1428 /*
1429 * Reset the reload state...
1430 */
1431
1432 NeedReload = RELOAD_NONE;
1433
1434 cupsdClearString(&old_serverroot);
1435 cupsdClearString(&old_requestroot);
1436
1437 return (1);
1438 }
1439
1440
1441 /*
1442 * 'get_address()' - Get an address + port number from a line.
1443 */
1444
1445 static http_addrlist_t * /* O - Pointer to list if address good, NULL if bad */
1446 get_address(const char *value, /* I - Value string */
1447 int defport) /* I - Default port */
1448 {
1449 char buffer[1024], /* Hostname + port number buffer */
1450 defpname[255], /* Default port name */
1451 *hostname, /* Hostname or IP */
1452 *portname; /* Port number or name */
1453 http_addrlist_t *addrlist; /* Address list */
1454
1455
1456 /*
1457 * Check for an empty value...
1458 */
1459
1460 if (!*value)
1461 {
1462 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad (empty) address.");
1463 return (NULL);
1464 }
1465
1466 /*
1467 * Grab a hostname and port number; if there is no colon and the port name
1468 * is only digits, then we have a port number by itself...
1469 */
1470
1471 strlcpy(buffer, value, sizeof(buffer));
1472
1473 if ((portname = strrchr(buffer, ':')) != NULL && !strchr(portname, ']'))
1474 {
1475 *portname++ = '\0';
1476 hostname = buffer;
1477 }
1478 else
1479 {
1480 for (portname = buffer; isdigit(*portname & 255); portname ++);
1481
1482 if (*portname)
1483 {
1484 /*
1485 * Use the default port...
1486 */
1487
1488 sprintf(defpname, "%d", defport);
1489 portname = defpname;
1490 hostname = buffer;
1491 }
1492 else
1493 {
1494 /*
1495 * The buffer contains just a port number...
1496 */
1497
1498 portname = buffer;
1499 hostname = NULL;
1500 }
1501 }
1502
1503 if (hostname && !strcmp(hostname, "*"))
1504 hostname = NULL;
1505
1506 /*
1507 * Now lookup the address using httpAddrGetList()...
1508 */
1509
1510 if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
1511 cupsdLogMessage(CUPSD_LOG_ERROR, "Hostname lookup for \"%s\" failed.",
1512 hostname ? hostname : "(nil)");
1513
1514 return (addrlist);
1515 }
1516
1517
1518 /*
1519 * 'get_addr_and_mask()' - Get an IP address and netmask.
1520 */
1521
1522 static int /* O - 1 on success, 0 on failure */
1523 get_addr_and_mask(const char *value, /* I - String from config file */
1524 unsigned *ip, /* O - Address value */
1525 unsigned *mask) /* O - Mask value */
1526 {
1527 int i, j, /* Looping vars */
1528 family, /* Address family */
1529 ipcount; /* Count of fields in address */
1530 unsigned ipval; /* Value */
1531 const char *maskval, /* Pointer to start of mask value */
1532 *ptr, /* Pointer into value */
1533 *ptr2; /* ... */
1534
1535
1536 /*
1537 * Get the address...
1538 */
1539
1540 ip[0] = ip[1] = ip[2] = ip[3] = 0x00000000;
1541 mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff;
1542
1543 if ((maskval = strchr(value, '/')) != NULL)
1544 maskval ++;
1545 else
1546 maskval = value + strlen(value);
1547
1548 #ifdef AF_INET6
1549 /*
1550 * Check for an IPv6 address...
1551 */
1552
1553 if (*value == '[')
1554 {
1555 /*
1556 * Parse hexadecimal IPv6/IPv4 address...
1557 */
1558
1559 family = AF_INET6;
1560
1561 for (i = 0, ptr = value + 1; *ptr && i < 8; i ++)
1562 {
1563 if (*ptr == ']')
1564 break;
1565 else if (!strncmp(ptr, "::", 2))
1566 {
1567 for (ptr2 = strchr(ptr + 2, ':'), j = 0;
1568 ptr2;
1569 ptr2 = strchr(ptr2 + 1, ':'), j ++);
1570
1571 i = 6 - j;
1572 ptr += 2;
1573 }
1574 else if (isdigit(*ptr & 255) && strchr(ptr + 1, '.') && i >= 6)
1575 {
1576 /*
1577 * Read IPv4 dotted quad...
1578 */
1579
1580 unsigned val[4] = { 0, 0, 0, 0 };
1581 /* IPv4 address values */
1582
1583 ipcount = sscanf(ptr, "%u.%u.%u.%u", val + 0, val + 1, val + 2,
1584 val + 3);
1585
1586 /*
1587 * Range check the IP numbers...
1588 */
1589
1590 for (i = 0; i < ipcount; i ++)
1591 if (val[i] > 255)
1592 return (0);
1593
1594 /*
1595 * Merge everything into a 32-bit IPv4 address in ip[3]...
1596 */
1597
1598 ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3];
1599
1600 if (ipcount < 4)
1601 mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
1602
1603 /*
1604 * If the leading words are all 0's then this is an IPv4 address...
1605 */
1606
1607 if (!val[0] && !val[1] && !val[2])
1608 family = AF_INET;
1609
1610 while (isdigit(*ptr & 255) || *ptr == '.')
1611 ptr ++;
1612 break;
1613 }
1614 else if (isxdigit(*ptr & 255))
1615 {
1616 ipval = strtoul(ptr, (char **)&ptr, 16);
1617
1618 if (*ptr == ':' && ptr[1] != ':')
1619 ptr ++;
1620
1621 if (ipval > 0xffff)
1622 return (0);
1623
1624 if (i & 1)
1625 ip[i / 2] |= ipval;
1626 else
1627 ip[i / 2] |= ipval << 16;
1628 }
1629 else
1630 return (0);
1631 }
1632
1633 if (*ptr != ']')
1634 return (0);
1635
1636 ptr ++;
1637
1638 if (*ptr && *ptr != '/')
1639 return (0);
1640 }
1641 else
1642 #endif /* AF_INET6 */
1643 {
1644 /*
1645 * Parse dotted-decimal IPv4 address...
1646 */
1647
1648 unsigned val[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1649
1650
1651 family = AF_INET;
1652 ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3);
1653
1654 /*
1655 * Range check the IP numbers...
1656 */
1657
1658 for (i = 0; i < ipcount; i ++)
1659 if (val[i] > 255)
1660 return (0);
1661
1662 /*
1663 * Merge everything into a 32-bit IPv4 address in ip[3]...
1664 */
1665
1666 ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3];
1667
1668 if (ipcount < 4)
1669 mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
1670 }
1671
1672 if (*maskval)
1673 {
1674 /*
1675 * Get the netmask value(s)...
1676 */
1677
1678 memset(mask, 0, sizeof(unsigned) * 4);
1679
1680 if (strchr(maskval, '.'))
1681 {
1682 /*
1683 * Get dotted-decimal mask...
1684 */
1685
1686 if (family != AF_INET)
1687 return (0);
1688
1689 if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2,
1690 mask + 3) != 4)
1691 return (0);
1692
1693 mask[3] |= ((((mask[0] << 8) | mask[1]) << 8) | mask[2]) << 8;
1694 mask[0] = mask[1] = mask[2] = 0;
1695 }
1696 else
1697 {
1698 /*
1699 * Get address/bits format...
1700 */
1701
1702 i = atoi(maskval);
1703
1704 #ifdef AF_INET6
1705 if (family == AF_INET6)
1706 {
1707 if (i > 128)
1708 return (0);
1709
1710 i = 128 - i;
1711
1712 if (i <= 96)
1713 mask[0] = 0xffffffff;
1714 else
1715 mask[0] = (0xffffffff << (i - 96)) & 0xffffffff;
1716
1717 if (i <= 64)
1718 mask[1] = 0xffffffff;
1719 else if (i >= 96)
1720 mask[1] = 0;
1721 else
1722 mask[1] = (0xffffffff << (i - 64)) & 0xffffffff;
1723
1724 if (i <= 32)
1725 mask[2] = 0xffffffff;
1726 else if (i >= 64)
1727 mask[2] = 0;
1728 else
1729 mask[2] = (0xffffffff << (i - 32)) & 0xffffffff;
1730
1731 if (i == 0)
1732 mask[3] = 0xffffffff;
1733 else if (i >= 32)
1734 mask[3] = 0;
1735 else
1736 mask[3] = (0xffffffff << i) & 0xffffffff;
1737 }
1738 else
1739 #endif /* AF_INET6 */
1740 {
1741 if (i > 32)
1742 return (0);
1743
1744 mask[0] = 0xffffffff;
1745 mask[1] = 0xffffffff;
1746 mask[2] = 0xffffffff;
1747
1748 if (i < 32)
1749 mask[3] = (0xffffffff << (32 - i)) & 0xffffffff;
1750 else
1751 mask[3] = 0xffffffff;
1752 }
1753 }
1754 }
1755
1756 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1757 "get_addr_and_mask(value=\"%s\", "
1758 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1759 value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2],
1760 mask[3]);
1761
1762 /*
1763 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1764 */
1765
1766 if ((ip[0] & ~mask[0]) != 0 ||
1767 (ip[1] & ~mask[1]) != 0 ||
1768 (ip[2] & ~mask[2]) != 0 ||
1769 (ip[3] & ~mask[3]) != 0)
1770 return (0);
1771
1772 return (1);
1773 }
1774
1775
1776 /*
1777 * 'mime_error_cb()' - Log a MIME error.
1778 */
1779
1780 static void
1781 mime_error_cb(void *ctx, /* I - Context pointer (unused) */
1782 const char *message) /* I - Message */
1783 {
1784 (void)ctx;
1785
1786 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", message);
1787 }
1788
1789
1790 /*
1791 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1792 */
1793
1794 static int /* O - 1 on success, 0 on failure */
1795 parse_aaa(cupsd_location_t *loc, /* I - Location */
1796 char *line, /* I - Line from file */
1797 char *value, /* I - Start of value data */
1798 int linenum) /* I - Current line number */
1799 {
1800 char *valptr; /* Pointer into value */
1801 unsigned ip[4], /* IP address components */
1802 mask[4]; /* IP netmask components */
1803
1804
1805 if (!_cups_strcasecmp(line, "Encryption"))
1806 {
1807 /*
1808 * "Encryption xxx" - set required encryption level...
1809 */
1810
1811 if (!_cups_strcasecmp(value, "never"))
1812 loc->encryption = HTTP_ENCRYPT_NEVER;
1813 else if (!_cups_strcasecmp(value, "always"))
1814 {
1815 cupsdLogMessage(CUPSD_LOG_ERROR,
1816 "Encryption value \"%s\" on line %d is invalid in this "
1817 "context. Using \"required\" instead.", value, linenum);
1818
1819 loc->encryption = HTTP_ENCRYPT_REQUIRED;
1820 }
1821 else if (!_cups_strcasecmp(value, "required"))
1822 loc->encryption = HTTP_ENCRYPT_REQUIRED;
1823 else if (!_cups_strcasecmp(value, "ifrequested"))
1824 loc->encryption = HTTP_ENCRYPT_IF_REQUESTED;
1825 else
1826 {
1827 cupsdLogMessage(CUPSD_LOG_ERROR,
1828 "Unknown Encryption value %s on line %d.", value, linenum);
1829 return (0);
1830 }
1831 }
1832 else if (!_cups_strcasecmp(line, "Order"))
1833 {
1834 /*
1835 * "Order Deny,Allow" or "Order Allow,Deny"...
1836 */
1837
1838 if (!_cups_strncasecmp(value, "deny", 4))
1839 loc->order_type = CUPSD_AUTH_ALLOW;
1840 else if (!_cups_strncasecmp(value, "allow", 5))
1841 loc->order_type = CUPSD_AUTH_DENY;
1842 else
1843 {
1844 cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown Order value %s on line %d.",
1845 value, linenum);
1846 return (0);
1847 }
1848 }
1849 else if (!_cups_strcasecmp(line, "Allow") || !_cups_strcasecmp(line, "Deny"))
1850 {
1851 /*
1852 * Allow [From] host/ip...
1853 * Deny [From] host/ip...
1854 */
1855
1856 while (*value)
1857 {
1858 if (!_cups_strncasecmp(value, "from", 4))
1859 {
1860 /*
1861 * Strip leading "from"...
1862 */
1863
1864 value += 4;
1865
1866 while (_cups_isspace(*value))
1867 value ++;
1868
1869 if (!*value)
1870 break;
1871 }
1872
1873 /*
1874 * Find the end of the value...
1875 */
1876
1877 for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++);
1878
1879 while (_cups_isspace(*valptr))
1880 *valptr++ = '\0';
1881
1882 /*
1883 * Figure out what form the allow/deny address takes:
1884 *
1885 * All
1886 * None
1887 * *.domain.com
1888 * .domain.com
1889 * host.domain.com
1890 * nnn.*
1891 * nnn.nnn.*
1892 * nnn.nnn.nnn.*
1893 * nnn.nnn.nnn.nnn
1894 * nnn.nnn.nnn.nnn/mm
1895 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1896 */
1897
1898 if (!_cups_strcasecmp(value, "all"))
1899 {
1900 /*
1901 * All hosts...
1902 */
1903
1904 if (!_cups_strcasecmp(line, "Allow"))
1905 cupsdAddIPMask(&(loc->allow), zeros, zeros);
1906 else
1907 cupsdAddIPMask(&(loc->deny), zeros, zeros);
1908 }
1909 else if (!_cups_strcasecmp(value, "none"))
1910 {
1911 /*
1912 * No hosts...
1913 */
1914
1915 if (!_cups_strcasecmp(line, "Allow"))
1916 cupsdAddIPMask(&(loc->allow), ones, zeros);
1917 else
1918 cupsdAddIPMask(&(loc->deny), ones, zeros);
1919 }
1920 #ifdef AF_INET6
1921 else if (value[0] == '*' || value[0] == '.' ||
1922 (!isdigit(value[0] & 255) && value[0] != '['))
1923 #else
1924 else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
1925 #endif /* AF_INET6 */
1926 {
1927 /*
1928 * Host or domain name...
1929 */
1930
1931 if (value[0] == '*')
1932 value ++;
1933
1934 if (!_cups_strcasecmp(line, "Allow"))
1935 cupsdAddNameMask(&(loc->allow), value);
1936 else
1937 cupsdAddNameMask(&(loc->deny), value);
1938 }
1939 else
1940 {
1941 /*
1942 * One of many IP address forms...
1943 */
1944
1945 if (!get_addr_and_mask(value, ip, mask))
1946 {
1947 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
1948 value, linenum);
1949 return (0);
1950 }
1951
1952 if (!_cups_strcasecmp(line, "Allow"))
1953 cupsdAddIPMask(&(loc->allow), ip, mask);
1954 else
1955 cupsdAddIPMask(&(loc->deny), ip, mask);
1956 }
1957
1958 /*
1959 * Advance to next value...
1960 */
1961
1962 value = valptr;
1963 }
1964 }
1965 else if (!_cups_strcasecmp(line, "AuthType"))
1966 {
1967 /*
1968 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1969 */
1970
1971 if (!_cups_strcasecmp(value, "none"))
1972 {
1973 loc->type = CUPSD_AUTH_NONE;
1974 loc->level = CUPSD_AUTH_ANON;
1975 }
1976 else if (!_cups_strcasecmp(value, "basic"))
1977 {
1978 loc->type = CUPSD_AUTH_BASIC;
1979
1980 if (loc->level == CUPSD_AUTH_ANON)
1981 loc->level = CUPSD_AUTH_USER;
1982 }
1983 else if (!_cups_strcasecmp(value, "digest"))
1984 {
1985 loc->type = CUPSD_AUTH_DIGEST;
1986
1987 if (loc->level == CUPSD_AUTH_ANON)
1988 loc->level = CUPSD_AUTH_USER;
1989 }
1990 else if (!_cups_strcasecmp(value, "basicdigest"))
1991 {
1992 loc->type = CUPSD_AUTH_BASICDIGEST;
1993
1994 if (loc->level == CUPSD_AUTH_ANON)
1995 loc->level = CUPSD_AUTH_USER;
1996 }
1997 else if (!_cups_strcasecmp(value, "default"))
1998 {
1999 loc->type = CUPSD_AUTH_DEFAULT;
2000
2001 if (loc->level == CUPSD_AUTH_ANON)
2002 loc->level = CUPSD_AUTH_USER;
2003 }
2004 #ifdef HAVE_GSSAPI
2005 else if (!_cups_strcasecmp(value, "negotiate"))
2006 {
2007 loc->type = CUPSD_AUTH_NEGOTIATE;
2008
2009 if (loc->level == CUPSD_AUTH_ANON)
2010 loc->level = CUPSD_AUTH_USER;
2011 }
2012 #endif /* HAVE_GSSAPI */
2013 else
2014 {
2015 cupsdLogMessage(CUPSD_LOG_WARN,
2016 "Unknown authorization type %s on line %d.",
2017 value, linenum);
2018 return (0);
2019 }
2020 }
2021 else if (!_cups_strcasecmp(line, "AuthClass"))
2022 {
2023 /*
2024 * AuthClass anonymous, user, system, group
2025 */
2026
2027 if (!_cups_strcasecmp(value, "anonymous"))
2028 {
2029 loc->type = CUPSD_AUTH_NONE;
2030 loc->level = CUPSD_AUTH_ANON;
2031
2032 cupsdLogMessage(CUPSD_LOG_WARN,
2033 "\"AuthClass %s\" is deprecated; consider removing "
2034 "it from line %d.",
2035 value, linenum);
2036 }
2037 else if (!_cups_strcasecmp(value, "user"))
2038 {
2039 loc->level = CUPSD_AUTH_USER;
2040
2041 cupsdLogMessage(CUPSD_LOG_WARN,
2042 "\"AuthClass %s\" is deprecated; consider using "
2043 "\"Require valid-user\" on line %d.",
2044 value, linenum);
2045 }
2046 else if (!_cups_strcasecmp(value, "group"))
2047 {
2048 loc->level = CUPSD_AUTH_GROUP;
2049
2050 cupsdLogMessage(CUPSD_LOG_WARN,
2051 "\"AuthClass %s\" is deprecated; consider using "
2052 "\"Require user @groupname\" on line %d.",
2053 value, linenum);
2054 }
2055 else if (!_cups_strcasecmp(value, "system"))
2056 {
2057 loc->level = CUPSD_AUTH_GROUP;
2058
2059 cupsdAddName(loc, "@SYSTEM");
2060
2061 cupsdLogMessage(CUPSD_LOG_WARN,
2062 "\"AuthClass %s\" is deprecated; consider using "
2063 "\"Require user @SYSTEM\" on line %d.",
2064 value, linenum);
2065 }
2066 else
2067 {
2068 cupsdLogMessage(CUPSD_LOG_WARN,
2069 "Unknown authorization class %s on line %d.",
2070 value, linenum);
2071 return (0);
2072 }
2073 }
2074 else if (!_cups_strcasecmp(line, "AuthGroupName"))
2075 {
2076 cupsdAddName(loc, value);
2077
2078 cupsdLogMessage(CUPSD_LOG_WARN,
2079 "\"AuthGroupName %s\" directive is deprecated; consider "
2080 "using \"Require user @%s\" on line %d.",
2081 value, value, linenum);
2082 }
2083 else if (!_cups_strcasecmp(line, "Require"))
2084 {
2085 /*
2086 * Apache synonym for AuthClass and AuthGroupName...
2087 *
2088 * Get initial word:
2089 *
2090 * Require valid-user
2091 * Require group names
2092 * Require user names
2093 */
2094
2095 for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++);
2096
2097 if (*valptr)
2098 *valptr++ = '\0';
2099
2100 if (!_cups_strcasecmp(value, "valid-user") ||
2101 !_cups_strcasecmp(value, "user"))
2102 loc->level = CUPSD_AUTH_USER;
2103 else if (!_cups_strcasecmp(value, "group"))
2104 loc->level = CUPSD_AUTH_GROUP;
2105 else
2106 {
2107 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Require type %s on line %d.",
2108 value, linenum);
2109 return (0);
2110 }
2111
2112 /*
2113 * Get the list of names from the line...
2114 */
2115
2116 for (value = valptr; *value;)
2117 {
2118 while (_cups_isspace(*value))
2119 value ++;
2120
2121 #ifdef HAVE_AUTHORIZATION_H
2122 if (!strncmp(value, "@AUTHKEY(", 9))
2123 {
2124 /*
2125 * Grab "@AUTHKEY(name)" value...
2126 */
2127
2128 for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++);
2129
2130 if (*valptr)
2131 *valptr++ = '\0';
2132 }
2133 else
2134 #endif /* HAVE_AUTHORIZATION_H */
2135 if (*value == '\"' || *value == '\'')
2136 {
2137 /*
2138 * Grab quoted name...
2139 */
2140
2141 for (valptr = value + 1; *valptr != *value && *valptr; valptr ++);
2142
2143 value ++;
2144 }
2145 else
2146 {
2147 /*
2148 * Grab literal name.
2149 */
2150
2151 for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++);
2152 }
2153
2154 if (*valptr)
2155 *valptr++ = '\0';
2156
2157 cupsdAddName(loc, value);
2158
2159 for (value = valptr; _cups_isspace(*value); value ++);
2160 }
2161 }
2162 else if (!_cups_strcasecmp(line, "Satisfy"))
2163 {
2164 if (!_cups_strcasecmp(value, "all"))
2165 loc->satisfy = CUPSD_AUTH_SATISFY_ALL;
2166 else if (!_cups_strcasecmp(value, "any"))
2167 loc->satisfy = CUPSD_AUTH_SATISFY_ANY;
2168 else
2169 {
2170 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Satisfy value %s on line %d.",
2171 value, linenum);
2172 return (0);
2173 }
2174 }
2175 else
2176 return (0);
2177
2178 return (1);
2179 }
2180
2181
2182 /*
2183 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2184 */
2185
2186 static int /* O - FatalErrors bits */
2187 parse_fatal_errors(const char *s) /* I - FatalErrors string */
2188 {
2189 int fatal; /* FatalErrors bits */
2190 char value[1024], /* Value string */
2191 *valstart, /* Pointer into value */
2192 *valend; /* End of value */
2193
2194
2195 /*
2196 * Empty FatalErrors line yields NULL pointer...
2197 */
2198
2199 if (!s)
2200 return (CUPSD_FATAL_NONE);
2201
2202 /*
2203 * Loop through the value string,...
2204 */
2205
2206 strlcpy(value, s, sizeof(value));
2207
2208 fatal = CUPSD_FATAL_NONE;
2209
2210 for (valstart = value; *valstart;)
2211 {
2212 /*
2213 * Get the current space/comma-delimited kind name...
2214 */
2215
2216 for (valend = valstart; *valend; valend ++)
2217 if (_cups_isspace(*valend) || *valend == ',')
2218 break;
2219
2220 if (*valend)
2221 *valend++ = '\0';
2222
2223 /*
2224 * Add the error to the bitmask...
2225 */
2226
2227 if (!_cups_strcasecmp(valstart, "all"))
2228 fatal = CUPSD_FATAL_ALL;
2229 else if (!_cups_strcasecmp(valstart, "browse"))
2230 fatal |= CUPSD_FATAL_BROWSE;
2231 else if (!_cups_strcasecmp(valstart, "-browse"))
2232 fatal &= ~CUPSD_FATAL_BROWSE;
2233 else if (!_cups_strcasecmp(valstart, "config"))
2234 fatal |= CUPSD_FATAL_CONFIG;
2235 else if (!_cups_strcasecmp(valstart, "-config"))
2236 fatal &= ~CUPSD_FATAL_CONFIG;
2237 else if (!_cups_strcasecmp(valstart, "listen"))
2238 fatal |= CUPSD_FATAL_LISTEN;
2239 else if (!_cups_strcasecmp(valstart, "-listen"))
2240 fatal &= ~CUPSD_FATAL_LISTEN;
2241 else if (!_cups_strcasecmp(valstart, "log"))
2242 fatal |= CUPSD_FATAL_LOG;
2243 else if (!_cups_strcasecmp(valstart, "-log"))
2244 fatal &= ~CUPSD_FATAL_LOG;
2245 else if (!_cups_strcasecmp(valstart, "permissions"))
2246 fatal |= CUPSD_FATAL_PERMISSIONS;
2247 else if (!_cups_strcasecmp(valstart, "-permissions"))
2248 fatal &= ~CUPSD_FATAL_PERMISSIONS;
2249 else if (_cups_strcasecmp(valstart, "none"))
2250 cupsdLogMessage(CUPSD_LOG_ERROR,
2251 "Unknown FatalErrors kind \"%s\" ignored.", valstart);
2252
2253 for (valstart = valend; *valstart; valstart ++)
2254 if (!_cups_isspace(*valstart) || *valstart != ',')
2255 break;
2256 }
2257
2258 return (fatal);
2259 }
2260
2261
2262 /*
2263 * 'parse_groups()' - Parse system group names in a string.
2264 */
2265
2266 static int /* O - 1 on success, 0 on failure */
2267 parse_groups(const char *s) /* I - Space-delimited groups */
2268 {
2269 int status; /* Return status */
2270 char value[1024], /* Value string */
2271 *valstart, /* Pointer into value */
2272 *valend, /* End of value */
2273 quote; /* Quote character */
2274 struct group *group; /* Group */
2275
2276
2277 /*
2278 * Make a copy of the string and parse out the groups...
2279 */
2280
2281 strlcpy(value, s, sizeof(value));
2282
2283 status = 1;
2284 valstart = value;
2285
2286 while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS)
2287 {
2288 if (*valstart == '\'' || *valstart == '\"')
2289 {
2290 /*
2291 * Scan quoted name...
2292 */
2293
2294 quote = *valstart++;
2295
2296 for (valend = valstart; *valend; valend ++)
2297 if (*valend == quote)
2298 break;
2299 }
2300 else
2301 {
2302 /*
2303 * Scan space or comma-delimited name...
2304 */
2305
2306 for (valend = valstart; *valend; valend ++)
2307 if (_cups_isspace(*valend) || *valend == ',')
2308 break;
2309 }
2310
2311 if (*valend)
2312 *valend++ = '\0';
2313
2314 group = getgrnam(valstart);
2315 if (group)
2316 {
2317 cupsdSetString(SystemGroups + NumSystemGroups, valstart);
2318 SystemGroupIDs[NumSystemGroups] = group->gr_gid;
2319
2320 NumSystemGroups ++;
2321 }
2322 else
2323 status = 0;
2324
2325 endgrent();
2326
2327 valstart = valend;
2328
2329 while (*valstart == ',' || _cups_isspace(*valstart))
2330 valstart ++;
2331 }
2332
2333 return (status);
2334 }
2335
2336
2337 /*
2338 * 'parse_protocols()' - Parse browse protocols in a string.
2339 */
2340
2341 static int /* O - Browse protocol bits */
2342 parse_protocols(const char *s) /* I - Space-delimited protocols */
2343 {
2344 int protocols; /* Browse protocol bits */
2345 char value[1024], /* Value string */
2346 *valstart, /* Pointer into value */
2347 *valend; /* End of value */
2348
2349
2350 /*
2351 * Empty protocol line yields NULL pointer...
2352 */
2353
2354 if (!s)
2355 return (0);
2356
2357 /*
2358 * Loop through the value string,...
2359 */
2360
2361 strlcpy(value, s, sizeof(value));
2362
2363 protocols = 0;
2364
2365 for (valstart = value; *valstart;)
2366 {
2367 /*
2368 * Get the current space/comma-delimited protocol name...
2369 */
2370
2371 for (valend = valstart; *valend; valend ++)
2372 if (_cups_isspace(*valend) || *valend == ',')
2373 break;
2374
2375 if (*valend)
2376 *valend++ = '\0';
2377
2378 /*
2379 * Add the protocol to the bitmask...
2380 */
2381
2382 if (!_cups_strcasecmp(valstart, "dnssd") ||
2383 !_cups_strcasecmp(valstart, "dns-sd") ||
2384 !_cups_strcasecmp(valstart, "bonjour"))
2385 protocols |= BROWSE_DNSSD;
2386 else if (!_cups_strcasecmp(valstart, "all"))
2387 protocols |= BROWSE_ALL;
2388 else if (_cups_strcasecmp(valstart, "none"))
2389 cupsdLogMessage(CUPSD_LOG_ERROR,
2390 "Unknown browse protocol \"%s\" ignored.", valstart);
2391
2392 for (valstart = valend; *valstart; valstart ++)
2393 if (!_cups_isspace(*valstart) || *valstart != ',')
2394 break;
2395 }
2396
2397 return (protocols);
2398 }
2399
2400
2401 /*
2402 * 'read_configuration()' - Read a configuration file.
2403 */
2404
2405 static int /* O - 1 on success, 0 on failure */
2406 read_configuration(cups_file_t *fp) /* I - File to read from */
2407 {
2408 int i; /* Looping var */
2409 int linenum; /* Current line number */
2410 char line[HTTP_MAX_BUFFER],
2411 /* Line from file */
2412 temp[HTTP_MAX_BUFFER],
2413 /* Temporary buffer for value */
2414 *value, /* Pointer to value */
2415 *valueptr; /* Pointer into value */
2416 int valuelen; /* Length of value */
2417 cupsd_var_t const *var; /* Current variable */
2418 http_addrlist_t *addrlist, /* Address list */
2419 *addr; /* Current address */
2420 cups_file_t *incfile; /* Include file */
2421 char incname[1024]; /* Include filename */
2422 struct group *group; /* Group */
2423
2424
2425 /*
2426 * Loop through each line in the file...
2427 */
2428
2429 linenum = 0;
2430
2431 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
2432 {
2433 /*
2434 * Decode the directive...
2435 */
2436
2437 if (!_cups_strcasecmp(line, "Include") && value)
2438 {
2439 /*
2440 * Include filename
2441 */
2442
2443 if (value[0] == '/')
2444 strlcpy(incname, value, sizeof(incname));
2445 else
2446 snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value);
2447
2448 if ((incfile = cupsFileOpen(incname, "rb")) == NULL)
2449 cupsdLogMessage(CUPSD_LOG_ERROR,
2450 "Unable to include config file \"%s\" - %s",
2451 incname, strerror(errno));
2452 else
2453 {
2454 read_configuration(incfile);
2455 cupsFileClose(incfile);
2456 }
2457 }
2458 else if (!_cups_strcasecmp(line, "<Location") && value)
2459 {
2460 /*
2461 * <Location path>
2462 */
2463
2464 linenum = read_location(fp, value, linenum);
2465 if (linenum == 0)
2466 return (0);
2467 }
2468 else if (!_cups_strcasecmp(line, "<Policy") && value)
2469 {
2470 /*
2471 * <Policy name>
2472 */
2473
2474 linenum = read_policy(fp, value, linenum);
2475 if (linenum == 0)
2476 return (0);
2477 }
2478 else if (!_cups_strcasecmp(line, "FatalErrors"))
2479 FatalErrors = parse_fatal_errors(value);
2480 else if (!_cups_strcasecmp(line, "FaxRetryInterval") && value)
2481 {
2482 JobRetryInterval = atoi(value);
2483 cupsdLogMessage(CUPSD_LOG_WARN,
2484 "FaxRetryInterval is deprecated; use "
2485 "JobRetryInterval on line %d.", linenum);
2486 }
2487 else if (!_cups_strcasecmp(line, "FaxRetryLimit") && value)
2488 {
2489 JobRetryLimit = atoi(value);
2490 cupsdLogMessage(CUPSD_LOG_WARN,
2491 "FaxRetryLimit is deprecated; use "
2492 "JobRetryLimit on line %d.", linenum);
2493 }
2494 else if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen")
2495 #ifdef HAVE_SSL
2496 || !_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen")
2497 #endif /* HAVE_SSL */
2498 ) && value)
2499 {
2500 /*
2501 * Add listening address(es) to the list...
2502 */
2503
2504 cupsd_listener_t *lis; /* New listeners array */
2505
2506
2507 /*
2508 * Get the address list...
2509 */
2510
2511 addrlist = get_address(value, IPP_PORT);
2512
2513 if (!addrlist)
2514 {
2515 cupsdLogMessage(CUPSD_LOG_ERROR, "Bad %s address %s at line %d.", line,
2516 value, linenum);
2517 continue;
2518 }
2519
2520 /*
2521 * Add each address...
2522 */
2523
2524 for (addr = addrlist; addr; addr = addr->next)
2525 {
2526 /*
2527 * See if this address is already present...
2528 */
2529
2530 for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
2531 lis;
2532 lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
2533 if (httpAddrEqual(&(addr->addr), &(lis->address)) &&
2534 _httpAddrPort(&(addr->addr)) == _httpAddrPort(&(lis->address)))
2535 break;
2536
2537 if (lis)
2538 {
2539 httpAddrString(&lis->address, temp, sizeof(temp));
2540 cupsdLogMessage(CUPSD_LOG_WARN,
2541 "Duplicate listen address \"%s\" ignored.", temp);
2542 continue;
2543 }
2544
2545 /*
2546 * Allocate another listener...
2547 */
2548
2549 if (!Listeners)
2550 Listeners = cupsArrayNew(NULL, NULL);
2551
2552 if (!Listeners)
2553 {
2554 cupsdLogMessage(CUPSD_LOG_ERROR,
2555 "Unable to allocate %s at line %d - %s.",
2556 line, linenum, strerror(errno));
2557 break;
2558 }
2559
2560 if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
2561 {
2562 cupsdLogMessage(CUPSD_LOG_ERROR,
2563 "Unable to allocate %s at line %d - %s.",
2564 line, linenum, strerror(errno));
2565 break;
2566 }
2567
2568 cupsArrayAdd(Listeners, lis);
2569
2570 /*
2571 * Copy the current address and log it...
2572 */
2573
2574 memcpy(&(lis->address), &(addr->addr), sizeof(lis->address));
2575 lis->fd = -1;
2576
2577 #ifdef HAVE_SSL
2578 if (!_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen"))
2579 lis->encryption = HTTP_ENCRYPT_ALWAYS;
2580 #endif /* HAVE_SSL */
2581
2582 httpAddrString(&lis->address, temp, sizeof(temp));
2583
2584 #ifdef AF_LOCAL
2585 if (lis->address.addr.sa_family == AF_LOCAL)
2586 cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s (Domain)", temp);
2587 else
2588 #endif /* AF_LOCAL */
2589 cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv%d)", temp,
2590 _httpAddrPort(&(lis->address)),
2591 _httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6);
2592
2593 if (!httpAddrLocalhost(&(lis->address)))
2594 RemotePort = _httpAddrPort(&(lis->address));
2595 }
2596
2597 /*
2598 * Free the list...
2599 */
2600
2601 httpAddrFreeList(addrlist);
2602 }
2603 else if (!_cups_strcasecmp(line, "BrowseProtocols") ||
2604 !_cups_strcasecmp(line, "BrowseLocalProtocols"))
2605 {
2606 /*
2607 * "BrowseProtocols name [... name]"
2608 * "BrowseLocalProtocols name [... name]"
2609 */
2610
2611 int protocols = parse_protocols(value);
2612
2613 if (protocols < 0)
2614 {
2615 cupsdLogMessage(CUPSD_LOG_ERROR,
2616 "Unknown browse protocol \"%s\" on line %d.",
2617 value, linenum);
2618 break;
2619 }
2620
2621 BrowseLocalProtocols = protocols;
2622 }
2623 else if (!_cups_strcasecmp(line, "DefaultAuthType") && value)
2624 {
2625 /*
2626 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2627 */
2628
2629 if (!_cups_strcasecmp(value, "none"))
2630 DefaultAuthType = CUPSD_AUTH_NONE;
2631 else if (!_cups_strcasecmp(value, "basic"))
2632 DefaultAuthType = CUPSD_AUTH_BASIC;
2633 else if (!_cups_strcasecmp(value, "digest"))
2634 DefaultAuthType = CUPSD_AUTH_DIGEST;
2635 else if (!_cups_strcasecmp(value, "basicdigest"))
2636 DefaultAuthType = CUPSD_AUTH_BASICDIGEST;
2637 #ifdef HAVE_GSSAPI
2638 else if (!_cups_strcasecmp(value, "negotiate"))
2639 DefaultAuthType = CUPSD_AUTH_NEGOTIATE;
2640 #endif /* HAVE_GSSAPI */
2641 else
2642 {
2643 cupsdLogMessage(CUPSD_LOG_WARN,
2644 "Unknown default authorization type %s on line %d.",
2645 value, linenum);
2646 if (FatalErrors & CUPSD_FATAL_CONFIG)
2647 return (0);
2648 }
2649 }
2650 #ifdef HAVE_SSL
2651 else if (!_cups_strcasecmp(line, "DefaultEncryption"))
2652 {
2653 /*
2654 * DefaultEncryption {Never,IfRequested,Required}
2655 */
2656
2657 if (!value || !_cups_strcasecmp(value, "never"))
2658 DefaultEncryption = HTTP_ENCRYPT_NEVER;
2659 else if (!_cups_strcasecmp(value, "required"))
2660 DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
2661 else if (!_cups_strcasecmp(value, "ifrequested"))
2662 DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED;
2663 else
2664 {
2665 cupsdLogMessage(CUPSD_LOG_WARN,
2666 "Unknown default encryption %s on line %d.",
2667 value, linenum);
2668 if (FatalErrors & CUPSD_FATAL_CONFIG)
2669 return (0);
2670 }
2671 }
2672 #endif /* HAVE_SSL */
2673 else if (!_cups_strcasecmp(line, "User") && value)
2674 {
2675 /*
2676 * User ID to run as...
2677 */
2678
2679 if (isdigit(value[0] & 255))
2680 {
2681 int uid = atoi(value);
2682
2683 if (!uid)
2684 cupsdLogMessage(CUPSD_LOG_ERROR,
2685 "Will not use User 0 as specified on line %d "
2686 "for security reasons. You must use a non-"
2687 "privileged account instead.",
2688 linenum);
2689 else
2690 User = atoi(value);
2691 }
2692 else
2693 {
2694 struct passwd *p; /* Password information */
2695
2696 endpwent();
2697 p = getpwnam(value);
2698
2699 if (p)
2700 {
2701 if (!p->pw_uid)
2702 cupsdLogMessage(CUPSD_LOG_ERROR,
2703 "Will not use User %s (UID=0) as specified on line "
2704 "%d for security reasons. You must use a non-"
2705 "privileged account instead.",
2706 value, linenum);
2707 else
2708 User = p->pw_uid;
2709 }
2710 else
2711 cupsdLogMessage(CUPSD_LOG_ERROR,
2712 "Unknown User \"%s\" on line %d, ignoring.",
2713 value, linenum);
2714 }
2715 }
2716 else if (!_cups_strcasecmp(line, "Group") && value)
2717 {
2718 /*
2719 * Group ID to run as...
2720 */
2721
2722 if (isdigit(value[0]))
2723 Group = atoi(value);
2724 else
2725 {
2726 endgrent();
2727 group = getgrnam(value);
2728
2729 if (group != NULL)
2730 Group = group->gr_gid;
2731 else
2732 cupsdLogMessage(CUPSD_LOG_ERROR,
2733 "Unknown Group \"%s\" on line %d, ignoring.",
2734 value, linenum);
2735 }
2736 }
2737 else if (!_cups_strcasecmp(line, "SystemGroup") && value)
2738 {
2739 /*
2740 * SystemGroup (admin) group(s)...
2741 */
2742
2743 if (!parse_groups(value))
2744 cupsdLogMessage(CUPSD_LOG_ERROR,
2745 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2746 value, linenum);
2747 }
2748 else if (!_cups_strcasecmp(line, "HostNameLookups") && value)
2749 {
2750 /*
2751 * Do hostname lookups?
2752 */
2753
2754 if (!_cups_strcasecmp(value, "off") || !_cups_strcasecmp(value, "no") ||
2755 !_cups_strcasecmp(value, "false"))
2756 HostNameLookups = 0;
2757 else if (!_cups_strcasecmp(value, "on") || !_cups_strcasecmp(value, "yes") ||
2758 !_cups_strcasecmp(value, "true"))
2759 HostNameLookups = 1;
2760 else if (!_cups_strcasecmp(value, "double"))
2761 HostNameLookups = 2;
2762 else
2763 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown HostNameLookups %s on line %d.",
2764 value, linenum);
2765 }
2766 else if (!_cups_strcasecmp(line, "AccessLogLevel") && value)
2767 {
2768 /*
2769 * Amount of logging to do to access log...
2770 */
2771
2772 if (!_cups_strcasecmp(value, "all"))
2773 AccessLogLevel = CUPSD_ACCESSLOG_ALL;
2774 else if (!_cups_strcasecmp(value, "actions"))
2775 AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS;
2776 else if (!_cups_strcasecmp(value, "config"))
2777 AccessLogLevel = CUPSD_ACCESSLOG_CONFIG;
2778 else
2779 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown AccessLogLevel %s on line %d.",
2780 value, linenum);
2781 }
2782 else if (!_cups_strcasecmp(line, "LogLevel") && value)
2783 {
2784 /*
2785 * Amount of logging to do to error log...
2786 */
2787
2788 if (!_cups_strcasecmp(value, "debug2"))
2789 LogLevel = CUPSD_LOG_DEBUG2;
2790 else if (!_cups_strcasecmp(value, "debug"))
2791 LogLevel = CUPSD_LOG_DEBUG;
2792 else if (!_cups_strcasecmp(value, "info"))
2793 LogLevel = CUPSD_LOG_INFO;
2794 else if (!_cups_strcasecmp(value, "notice"))
2795 LogLevel = CUPSD_LOG_NOTICE;
2796 else if (!_cups_strcasecmp(value, "warn"))
2797 LogLevel = CUPSD_LOG_WARN;
2798 else if (!_cups_strcasecmp(value, "error"))
2799 LogLevel = CUPSD_LOG_ERROR;
2800 else if (!_cups_strcasecmp(value, "crit"))
2801 LogLevel = CUPSD_LOG_CRIT;
2802 else if (!_cups_strcasecmp(value, "alert"))
2803 LogLevel = CUPSD_LOG_ALERT;
2804 else if (!_cups_strcasecmp(value, "emerg"))
2805 LogLevel = CUPSD_LOG_EMERG;
2806 else if (!_cups_strcasecmp(value, "none"))
2807 LogLevel = CUPSD_LOG_NONE;
2808 else
2809 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogLevel %s on line %d.",
2810 value, linenum);
2811 }
2812 else if (!_cups_strcasecmp(line, "LogTimeFormat") && value)
2813 {
2814 /*
2815 * Amount of logging to do to error log...
2816 */
2817
2818 if (!_cups_strcasecmp(value, "standard"))
2819 LogTimeFormat = CUPSD_TIME_STANDARD;
2820 else if (!_cups_strcasecmp(value, "usecs"))
2821 LogTimeFormat = CUPSD_TIME_USECS;
2822 else
2823 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogTimeFormat %s on line %d.",
2824 value, linenum);
2825 }
2826 else if (!_cups_strcasecmp(line, "PrintcapFormat") && value)
2827 {
2828 /*
2829 * Format of printcap file?
2830 */
2831
2832 if (!_cups_strcasecmp(value, "bsd"))
2833 PrintcapFormat = PRINTCAP_BSD;
2834 else if (!_cups_strcasecmp(value, "plist"))
2835 PrintcapFormat = PRINTCAP_PLIST;
2836 else if (!_cups_strcasecmp(value, "solaris"))
2837 PrintcapFormat = PRINTCAP_SOLARIS;
2838 else
2839 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown PrintcapFormat %s on line %d.",
2840 value, linenum);
2841 }
2842 else if (!_cups_strcasecmp(line, "ServerTokens") && value)
2843 {
2844 /*
2845 * Set the string used for the Server header...
2846 */
2847
2848 struct utsname plat; /* Platform info */
2849
2850
2851 uname(&plat);
2852
2853 if (!_cups_strcasecmp(value, "ProductOnly"))
2854 cupsdSetString(&ServerHeader, "CUPS");
2855 else if (!_cups_strcasecmp(value, "Major"))
2856 cupsdSetStringf(&ServerHeader, "CUPS/%d", CUPS_VERSION_MAJOR);
2857 else if (!_cups_strcasecmp(value, "Minor"))
2858 cupsdSetStringf(&ServerHeader, "CUPS/%d.%d", CUPS_VERSION_MAJOR,
2859 CUPS_VERSION_MINOR);
2860 else if (!_cups_strcasecmp(value, "Minimal"))
2861 cupsdSetString(&ServerHeader, CUPS_MINIMAL);
2862 else if (!_cups_strcasecmp(value, "OS"))
2863 cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s)", plat.sysname);
2864 else if (!_cups_strcasecmp(value, "Full"))
2865 cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s) IPP/2.1",
2866 plat.sysname);
2867 else if (!_cups_strcasecmp(value, "None"))
2868 cupsdClearString(&ServerHeader);
2869 else
2870 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown ServerTokens %s on line %d.",
2871 value, linenum);
2872 }
2873 else if (!_cups_strcasecmp(line, "PassEnv") && value)
2874 {
2875 /*
2876 * PassEnv variable [... variable]
2877 */
2878
2879 for (; *value;)
2880 {
2881 for (valuelen = 0; value[valuelen]; valuelen ++)
2882 if (_cups_isspace(value[valuelen]) || value[valuelen] == ',')
2883 break;
2884
2885 if (value[valuelen])
2886 {
2887 value[valuelen] = '\0';
2888 valuelen ++;
2889 }
2890
2891 cupsdSetEnv(value, NULL);
2892
2893 for (value += valuelen; *value; value ++)
2894 if (!_cups_isspace(*value) || *value != ',')
2895 break;
2896 }
2897 }
2898 else if (!_cups_strcasecmp(line, "ServerAlias") && value)
2899 {
2900 /*
2901 * ServerAlias name [... name]
2902 */
2903
2904 if (!ServerAlias)
2905 ServerAlias = cupsArrayNew(NULL, NULL);
2906
2907 for (; *value;)
2908 {
2909 for (valuelen = 0; value[valuelen]; valuelen ++)
2910 if (_cups_isspace(value[valuelen]) || value[valuelen] == ',')
2911 break;
2912
2913 if (value[valuelen])
2914 {
2915 value[valuelen] = '\0';
2916 valuelen ++;
2917 }
2918
2919 cupsdAddAlias(ServerAlias, value);
2920
2921 for (value += valuelen; *value; value ++)
2922 if (!_cups_isspace(*value) || *value != ',')
2923 break;
2924 }
2925 }
2926 else if (!_cups_strcasecmp(line, "SetEnv") && value)
2927 {
2928 /*
2929 * SetEnv variable value
2930 */
2931
2932 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
2933
2934 if (*valueptr)
2935 {
2936 /*
2937 * Found a value...
2938 */
2939
2940 while (isspace(*valueptr & 255))
2941 *valueptr++ = '\0';
2942
2943 cupsdSetEnv(value, valueptr);
2944 }
2945 else
2946 cupsdLogMessage(CUPSD_LOG_ERROR,
2947 "Missing value for SetEnv directive on line %d.",
2948 linenum);
2949 }
2950 #ifdef HAVE_SSL
2951 else if (!_cups_strcasecmp(line, "SSLOptions"))
2952 {
2953 /*
2954 * SSLOptions options
2955 */
2956
2957 if (!value || !_cups_strcasecmp(value, "none"))
2958 SSLOptions = CUPSD_SSL_NONE;
2959 else if (!_cups_strcasecmp(value, "noemptyfragments"))
2960 SSLOptions = CUPSD_SSL_NOEMPTY;
2961 else
2962 cupsdLogMessage(CUPSD_LOG_ERROR,
2963 "Unknown value \"%s\" for SSLOptions directive on "
2964 "line %d.", value, linenum);
2965 }
2966 #endif /* HAVE_SSL */
2967 else
2968 {
2969 /*
2970 * Find a simple variable in the list...
2971 */
2972
2973 for (i = NUM_VARS, var = variables; i > 0; i --, var ++)
2974 if (!_cups_strcasecmp(line, var->name))
2975 break;
2976
2977 if (i == 0)
2978 {
2979 /*
2980 * Unknown directive! Output an error message and continue...
2981 */
2982
2983 if (!value)
2984 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d.",
2985 line, linenum);
2986 else
2987 cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d.",
2988 line, linenum);
2989 continue;
2990 }
2991
2992 switch (var->type)
2993 {
2994 case CUPSD_VARTYPE_INTEGER :
2995 if (!value)
2996 cupsdLogMessage(CUPSD_LOG_ERROR,
2997 "Missing integer value for %s on line %d.",
2998 line, linenum);
2999 else
3000 {
3001 int n; /* Number */
3002 char *units; /* Units */
3003
3004
3005 n = strtol(value, &units, 0);
3006
3007 if (units && *units)
3008 {
3009 if (tolower(units[0] & 255) == 'g')
3010 n *= 1024 * 1024 * 1024;
3011 else if (tolower(units[0] & 255) == 'm')
3012 n *= 1024 * 1024;
3013 else if (tolower(units[0] & 255) == 'k')
3014 n *= 1024;
3015 else if (tolower(units[0] & 255) == 't')
3016 n *= 262144;
3017 }
3018
3019 if (n < 0)
3020 cupsdLogMessage(CUPSD_LOG_ERROR,
3021 "Bad negative integer value for %s on line %d.",
3022 line, linenum);
3023 else
3024 *((int *)var->ptr) = n;
3025 }
3026 break;
3027
3028 case CUPSD_VARTYPE_BOOLEAN :
3029 if (!value)
3030 cupsdLogMessage(CUPSD_LOG_ERROR,
3031 "Missing boolean value for %s on line %d.",
3032 line, linenum);
3033 else if (!_cups_strcasecmp(value, "true") ||
3034 !_cups_strcasecmp(value, "on") ||
3035 !_cups_strcasecmp(value, "enabled") ||
3036 !_cups_strcasecmp(value, "yes") ||
3037 atoi(value) != 0)
3038 *((int *)var->ptr) = TRUE;
3039 else if (!_cups_strcasecmp(value, "false") ||
3040 !_cups_strcasecmp(value, "off") ||
3041 !_cups_strcasecmp(value, "disabled") ||
3042 !_cups_strcasecmp(value, "no") ||
3043 !_cups_strcasecmp(value, "0"))
3044 *((int *)var->ptr) = FALSE;
3045 else
3046 cupsdLogMessage(CUPSD_LOG_ERROR,
3047 "Unknown boolean value %s on line %d.",
3048 value, linenum);
3049 break;
3050
3051 case CUPSD_VARTYPE_PATHNAME :
3052 if (!value)
3053 {
3054 cupsdLogMessage(CUPSD_LOG_ERROR,
3055 "Missing pathname value for %s on line %d.",
3056 line, linenum);
3057 break;
3058 }
3059
3060 if (value[0] == '/')
3061 strlcpy(temp, value, sizeof(temp));
3062 else
3063 snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, value);
3064
3065 if (access(temp, 0))
3066 {
3067 cupsdLogMessage(CUPSD_LOG_ERROR,
3068 "File or directory for \"%s %s\" on line %d "
3069 "does not exist.", line, value, linenum);
3070 break;
3071 }
3072
3073 case CUPSD_VARTYPE_STRING :
3074 cupsdSetString((char **)var->ptr, value);
3075 break;
3076 }
3077 }
3078 }
3079
3080 return (1);
3081 }
3082
3083
3084 /*
3085 * 'read_location()' - Read a <Location path> definition.
3086 */
3087
3088 static int /* O - New line number or 0 on error */
3089 read_location(cups_file_t *fp, /* I - Configuration file */
3090 char *location, /* I - Location name/path */
3091 int linenum) /* I - Current line number */
3092 {
3093 cupsd_location_t *loc, /* New location */
3094 *parent; /* Parent location */
3095 char line[HTTP_MAX_BUFFER],
3096 /* Line buffer */
3097 *value, /* Value for directive */
3098 *valptr; /* Pointer into value */
3099
3100
3101 if ((parent = cupsdFindLocation(location)) != NULL)
3102 cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Location %s> on line %d.",
3103 location, linenum);
3104 else if ((parent = cupsdNewLocation(location)) == NULL)
3105 return (0);
3106 else
3107 {
3108 cupsdAddLocation(parent);
3109
3110 parent->limit = CUPSD_AUTH_LIMIT_ALL;
3111 }
3112
3113 loc = parent;
3114
3115 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3116 {
3117 /*
3118 * Decode the directive...
3119 */
3120
3121 if (!_cups_strcasecmp(line, "</Location>"))
3122 return (linenum);
3123 else if (!_cups_strcasecmp(line, "<Limit") ||
3124 !_cups_strcasecmp(line, "<LimitExcept"))
3125 {
3126 if (!value)
3127 {
3128 cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
3129 if (FatalErrors & CUPSD_FATAL_CONFIG)
3130 return (0);
3131 else
3132 continue;
3133 }
3134
3135 if ((loc = cupsdCopyLocation(parent)) == NULL)
3136 return (0);
3137
3138 cupsdAddLocation(loc);
3139
3140 loc->limit = 0;
3141 while (*value)
3142 {
3143 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3144
3145 if (*valptr)
3146 *valptr++ = '\0';
3147
3148 if (!strcmp(value, "ALL"))
3149 loc->limit = CUPSD_AUTH_LIMIT_ALL;
3150 else if (!strcmp(value, "GET"))
3151 loc->limit |= CUPSD_AUTH_LIMIT_GET;
3152 else if (!strcmp(value, "HEAD"))
3153 loc->limit |= CUPSD_AUTH_LIMIT_HEAD;
3154 else if (!strcmp(value, "OPTIONS"))
3155 loc->limit |= CUPSD_AUTH_LIMIT_OPTIONS;
3156 else if (!strcmp(value, "POST"))
3157 loc->limit |= CUPSD_AUTH_LIMIT_POST;
3158 else if (!strcmp(value, "PUT"))
3159 loc->limit |= CUPSD_AUTH_LIMIT_PUT;
3160 else if (!strcmp(value, "TRACE"))
3161 loc->limit |= CUPSD_AUTH_LIMIT_TRACE;
3162 else
3163 cupsdLogMessage(CUPSD_LOG_WARN, "Unknown request type %s on line %d.",
3164 value, linenum);
3165
3166 for (value = valptr; isspace(*value & 255); value ++);
3167 }
3168
3169 if (!_cups_strcasecmp(line, "<LimitExcept"))
3170 loc->limit = CUPSD_AUTH_LIMIT_ALL ^ loc->limit;
3171
3172 parent->limit &= ~loc->limit;
3173 }
3174 else if (!_cups_strcasecmp(line, "</Limit>") ||
3175 !_cups_strcasecmp(line, "</LimitExcept>"))
3176 loc = parent;
3177 else if (!value)
3178 {
3179 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d.", linenum);
3180 if (FatalErrors & CUPSD_FATAL_CONFIG)
3181 return (0);
3182 }
3183 else if (!parse_aaa(loc, line, value, linenum))
3184 {
3185 cupsdLogMessage(CUPSD_LOG_ERROR,
3186 "Unknown Location directive %s on line %d.",
3187 line, linenum);
3188 if (FatalErrors & CUPSD_FATAL_CONFIG)
3189 return (0);
3190 }
3191 }
3192
3193 cupsdLogMessage(CUPSD_LOG_ERROR,
3194 "Unexpected end-of-file at line %d while reading location.",
3195 linenum);
3196
3197 return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
3198 }
3199
3200
3201 /*
3202 * 'read_policy()' - Read a <Policy name> definition.
3203 */
3204
3205 static int /* O - New line number or 0 on error */
3206 read_policy(cups_file_t *fp, /* I - Configuration file */
3207 char *policy, /* I - Location name/path */
3208 int linenum) /* I - Current line number */
3209 {
3210 int i; /* Looping var */
3211 cupsd_policy_t *pol; /* Policy */
3212 cupsd_location_t *op; /* Policy operation */
3213 int num_ops; /* Number of IPP operations */
3214 ipp_op_t ops[100]; /* Operations */
3215 char line[HTTP_MAX_BUFFER],
3216 /* Line buffer */
3217 *value, /* Value for directive */
3218 *valptr; /* Pointer into value */
3219
3220
3221 /*
3222 * Create the policy...
3223 */
3224
3225 if ((pol = cupsdFindPolicy(policy)) != NULL)
3226 cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Policy %s> on line %d.",
3227 policy, linenum);
3228 else if ((pol = cupsdAddPolicy(policy)) == NULL)
3229 return (0);
3230
3231 /*
3232 * Read from the file...
3233 */
3234
3235 op = NULL;
3236 num_ops = 0;
3237
3238 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
3239 {
3240 /*
3241 * Decode the directive...
3242 */
3243
3244 if (!_cups_strcasecmp(line, "</Policy>"))
3245 {
3246 if (op)
3247 cupsdLogMessage(CUPSD_LOG_WARN,
3248 "Missing </Limit> before </Policy> on line %d.",
3249 linenum);
3250
3251 set_policy_defaults(pol);
3252
3253 return (linenum);
3254 }
3255 else if (!_cups_strcasecmp(line, "<Limit") && !op)
3256 {
3257 if (!value)
3258 {
3259 cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
3260 if (FatalErrors & CUPSD_FATAL_CONFIG)
3261 return (0);
3262 else
3263 continue;
3264 }
3265
3266 /*
3267 * Scan for IPP operation names...
3268 */
3269
3270 num_ops = 0;
3271
3272 while (*value)
3273 {
3274 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3275
3276 if (*valptr)
3277 *valptr++ = '\0';
3278
3279 if (num_ops < (int)(sizeof(ops) / sizeof(ops[0])))
3280 {
3281 if (!_cups_strcasecmp(value, "All"))
3282 ops[num_ops] = IPP_ANY_OPERATION;
3283 else if ((ops[num_ops] = ippOpValue(value)) == IPP_BAD_OPERATION)
3284 cupsdLogMessage(CUPSD_LOG_ERROR,
3285 "Bad IPP operation name \"%s\" on line %d.",
3286 value, linenum);
3287 else
3288 num_ops ++;
3289 }
3290 else
3291 cupsdLogMessage(CUPSD_LOG_ERROR,
3292 "Too many operations listed on line %d.",
3293 linenum);
3294
3295 for (value = valptr; isspace(*value & 255); value ++);
3296 }
3297
3298 /*
3299 * If none are specified, apply the policy to all operations...
3300 */
3301
3302 if (num_ops == 0)
3303 {
3304 ops[0] = IPP_ANY_OPERATION;
3305 num_ops = 1;
3306 }
3307
3308 /*
3309 * Add a new policy for the first operation...
3310 */
3311
3312 op = cupsdAddPolicyOp(pol, NULL, ops[0]);
3313 }
3314 else if (!_cups_strcasecmp(line, "</Limit>") && op)
3315 {
3316 /*
3317 * Finish the current operation limit...
3318 */
3319
3320 if (num_ops > 1)
3321 {
3322 /*
3323 * Copy the policy to the other operations...
3324 */
3325
3326 for (i = 1; i < num_ops; i ++)
3327 cupsdAddPolicyOp(pol, op, ops[i]);
3328 }
3329
3330 op = NULL;
3331 }
3332 else if (!value)
3333 {
3334 cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d.", linenum);
3335 if (FatalErrors & CUPSD_FATAL_CONFIG)
3336 return (0);
3337 }
3338 else if (!_cups_strcasecmp(line, "JobPrivateAccess") ||
3339 !_cups_strcasecmp(line, "JobPrivateValues") ||
3340 !_cups_strcasecmp(line, "SubscriptionPrivateAccess") ||
3341 !_cups_strcasecmp(line, "SubscriptionPrivateValues"))
3342 {
3343 if (op)
3344 {
3345 cupsdLogMessage(CUPSD_LOG_ERROR,
3346 "%s directive must appear outside <Limit>...</Limit> "
3347 "on line %d.", line, linenum);
3348 if (FatalErrors & CUPSD_FATAL_CONFIG)
3349 return (0);
3350 }
3351 else
3352 {
3353 /*
3354 * Pull out whitespace-delimited values...
3355 */
3356
3357 while (*value)
3358 {
3359 /*
3360 * Find the end of the current value...
3361 */
3362
3363 for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
3364
3365 if (*valptr)
3366 *valptr++ = '\0';
3367
3368 /*
3369 * Save it appropriately...
3370 */
3371
3372 if (!_cups_strcasecmp(line, "JobPrivateAccess"))
3373 {
3374 /*
3375 * JobPrivateAccess {all|default|user/group list|@@ACL}
3376 */
3377
3378 if (!_cups_strcasecmp(value, "default"))
3379 {
3380 cupsdAddString(&(pol->job_access), "@OWNER");
3381 cupsdAddString(&(pol->job_access), "@SYSTEM");
3382 }
3383 else
3384 cupsdAddString(&(pol->job_access), value);
3385 }
3386 else if (!_cups_strcasecmp(line, "JobPrivateValues"))
3387 {
3388 /*
3389 * JobPrivateValues {all|none|default|attribute list}
3390 */
3391
3392 if (!_cups_strcasecmp(value, "default"))
3393 {
3394 cupsdAddString(&(pol->job_attrs), "job-name");
3395 cupsdAddString(&(pol->job_attrs), "job-originating-host-name");
3396 cupsdAddString(&(pol->job_attrs), "job-originating-user-name");
3397 }
3398 else
3399 cupsdAddString(&(pol->job_attrs), value);
3400 }
3401 else if (!_cups_strcasecmp(line, "SubscriptionPrivateAccess"))
3402 {
3403 /*
3404 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3405 */
3406
3407 if (!_cups_strcasecmp(value, "default"))
3408 {
3409 cupsdAddString(&(pol->sub_access), "@OWNER");
3410 cupsdAddString(&(pol->sub_access), "@SYSTEM");
3411 }
3412 else
3413 cupsdAddString(&(pol->sub_access), value);
3414 }
3415 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3416 {
3417 /*
3418 * SubscriptionPrivateValues {all|none|default|attribute list}
3419 */
3420
3421 if (!_cups_strcasecmp(value, "default"))
3422 {
3423 cupsdAddString(&(pol->sub_attrs), "notify-events");
3424 cupsdAddString(&(pol->sub_attrs), "notify-pull-method");
3425 cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri");
3426 cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name");
3427 cupsdAddString(&(pol->sub_attrs), "notify-user-data");
3428 }
3429 else
3430 cupsdAddString(&(pol->sub_attrs), value);
3431 }
3432
3433 /*
3434 * Find the next string on the line...
3435 */
3436
3437 for (value = valptr; isspace(*value & 255); value ++);
3438 }
3439 }
3440 }
3441 else if (!op)
3442 {
3443 cupsdLogMessage(CUPSD_LOG_ERROR,
3444 "Missing <Limit ops> directive before %s on line %d.",
3445 line, linenum);
3446 if (FatalErrors & CUPSD_FATAL_CONFIG)
3447 return (0);
3448 }
3449 else if (!parse_aaa(op, line, value, linenum))
3450 {
3451 cupsdLogMessage(CUPSD_LOG_ERROR,
3452 "Unknown Policy Limit directive %s on line %d.",
3453 line, linenum);
3454
3455 if (FatalErrors & CUPSD_FATAL_CONFIG)
3456 return (0);
3457 }
3458 }
3459
3460 cupsdLogMessage(CUPSD_LOG_ERROR,
3461 "Unexpected end-of-file at line %d while reading policy "
3462 "\"%s\".", linenum, policy);
3463
3464 return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
3465 }
3466
3467
3468 /*
3469 * 'set_policy_defaults()' - Set default policy values as needed.
3470 */
3471
3472 static void
3473 set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
3474 {
3475 cupsd_location_t *op; /* Policy operation */
3476
3477
3478 /*
3479 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3480 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3481 * upgrades do not introduce new security issues...
3482 */
3483
3484 if ((op = cupsdFindPolicyOp(pol, IPP_VALIDATE_JOB)) == NULL ||
3485 op->op == IPP_ANY_OPERATION)
3486 {
3487 if ((op = cupsdFindPolicyOp(pol, IPP_PRINT_JOB)) != NULL &&
3488 op->op != IPP_ANY_OPERATION)
3489 {
3490 /*
3491 * Add a new limit for Validate-Job using the Print-Job limit as a
3492 * template...
3493 */
3494
3495 cupsdLogMessage(CUPSD_LOG_WARN,
3496 "No limit for Validate-Job defined in policy %s "
3497 "- using Print-Job's policy.", pol->name);
3498
3499 cupsdAddPolicyOp(pol, op, IPP_VALIDATE_JOB);
3500 }
3501 else
3502 cupsdLogMessage(CUPSD_LOG_WARN,
3503 "No limit for Validate-Job defined in policy %s "
3504 "and no suitable template found.", pol->name);
3505 }
3506
3507 if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_JOBS)) == NULL ||
3508 op->op == IPP_ANY_OPERATION)
3509 {
3510 if ((op = cupsdFindPolicyOp(pol, IPP_PAUSE_PRINTER)) != NULL &&
3511 op->op != IPP_ANY_OPERATION)
3512 {
3513 /*
3514 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3515 * template...
3516 */
3517
3518 cupsdLogMessage(CUPSD_LOG_WARN,
3519 "No limit for Cancel-Jobs defined in policy %s "
3520 "- using Pause-Printer's policy.", pol->name);
3521
3522 cupsdAddPolicyOp(pol, op, IPP_CANCEL_JOBS);
3523 }
3524 else
3525 cupsdLogMessage(CUPSD_LOG_WARN,
3526 "No limit for Cancel-Jobs defined in policy %s "
3527 "and no suitable template found.", pol->name);
3528 }
3529
3530 if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_MY_JOBS)) == NULL ||
3531 op->op == IPP_ANY_OPERATION)
3532 {
3533 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
3534 op->op != IPP_ANY_OPERATION)
3535 {
3536 /*
3537 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3538 * a template...
3539 */
3540
3541 cupsdLogMessage(CUPSD_LOG_WARN,
3542 "No limit for Cancel-My-Jobs defined in policy %s "
3543 "- using Send-Document's policy.", pol->name);
3544
3545 cupsdAddPolicyOp(pol, op, IPP_CANCEL_MY_JOBS);
3546 }
3547 else
3548 cupsdLogMessage(CUPSD_LOG_WARN,
3549 "No limit for Cancel-My-Jobs defined in policy %s "
3550 "and no suitable template found.", pol->name);
3551 }
3552
3553 if ((op = cupsdFindPolicyOp(pol, IPP_CLOSE_JOB)) == NULL ||
3554 op->op == IPP_ANY_OPERATION)
3555 {
3556 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
3557 op->op != IPP_ANY_OPERATION)
3558 {
3559 /*
3560 * Add a new limit for Close-Job using the Send-Document limit as a
3561 * template...
3562 */
3563
3564 cupsdLogMessage(CUPSD_LOG_WARN,
3565 "No limit for Close-Job defined in policy %s "
3566 "- using Send-Document's policy.", pol->name);
3567
3568 cupsdAddPolicyOp(pol, op, IPP_CLOSE_JOB);
3569 }
3570 else
3571 cupsdLogMessage(CUPSD_LOG_WARN,
3572 "No limit for Close-Job defined in policy %s "
3573 "and no suitable template found.", pol->name);
3574 }
3575
3576 if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL ||
3577 op->op == IPP_ANY_OPERATION)
3578 {
3579 if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
3580 op->op != IPP_ANY_OPERATION)
3581 {
3582 /*
3583 * Add a new limit for CUPS-Get-Document using the Send-Document
3584 * limit as a template...
3585 */
3586
3587 cupsdLogMessage(CUPSD_LOG_WARN,
3588 "No limit for CUPS-Get-Document defined in policy %s "
3589 "- using Send-Document's policy.", pol->name);
3590
3591 cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT);
3592 }
3593 else
3594 cupsdLogMessage(CUPSD_LOG_WARN,
3595 "No limit for CUPS-Get-Document defined in policy %s "
3596 "and no suitable template found.", pol->name);
3597 }
3598
3599 /*
3600 * Verify we have JobPrivateAccess, JobPrivateValues,
3601 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3602 */
3603
3604 if (!pol->job_access)
3605 {
3606 cupsdLogMessage(CUPSD_LOG_WARN,
3607 "No JobPrivateAccess defined in policy %s "
3608 "- using defaults.", pol->name);
3609 cupsdAddString(&(pol->job_access), "@OWNER");
3610 cupsdAddString(&(pol->job_access), "@SYSTEM");
3611 }
3612
3613 if (!pol->job_attrs)
3614 {
3615 cupsdLogMessage(CUPSD_LOG_WARN,
3616 "No JobPrivateValues defined in policy %s "
3617 "- using defaults.", pol->name);
3618 cupsdAddString(&(pol->job_attrs), "job-name");
3619 cupsdAddString(&(pol->job_attrs), "job-originating-host-name");
3620 cupsdAddString(&(pol->job_attrs), "job-originating-user-name");
3621 }
3622
3623 if (!pol->sub_access)
3624 {
3625 cupsdLogMessage(CUPSD_LOG_WARN,
3626 "No SubscriptionPrivateAccess defined in policy %s "
3627 "- using defaults.", pol->name);
3628 cupsdAddString(&(pol->sub_access), "@OWNER");
3629 cupsdAddString(&(pol->sub_access), "@SYSTEM");
3630 }
3631
3632 if (!pol->sub_attrs)
3633 {
3634 cupsdLogMessage(CUPSD_LOG_WARN,
3635 "No SubscriptionPrivateValues defined in policy %s "
3636 "- using defaults.", pol->name);
3637 cupsdAddString(&(pol->sub_attrs), "notify-events");
3638 cupsdAddString(&(pol->sub_attrs), "notify-pull-method");
3639 cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri");
3640 cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name");
3641 cupsdAddString(&(pol->sub_attrs), "notify-user-data");
3642 }
3643 }
3644
3645
3646 /*
3647 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".
3648 */