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