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