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