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