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