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