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