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