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