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