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