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