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