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