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