4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * ReadConfiguration() - 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.
39 * Include necessary headers...
45 #include <sys/utsname.h>
48 #ifdef HAVE_DOMAINSOCKETS
50 #endif /* HAVE_DOMAINSOCKETS */
53 # include <Security/SecureTransport.h>
54 # include <Security/SecIdentitySearch.h>
55 #endif /* HAVE_CDSASSL */
59 #endif /* HAVE_VSYSLOG */
63 * Possibly missing network definitions...
67 # define INADDR_NONE 0xffffffff
68 #endif /* !INADDR_NONE */
72 * Configuration variable structure...
77 char *name
; /* Name of variable */
78 void *ptr
; /* Pointer to variable */
79 int type
; /* Type (int, string, address) */
91 static var_t variables
[] =
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
},
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
}
161 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
164 static unsigned ones
[4] =
166 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
168 static unsigned zeros
[4] =
170 0x00000000, 0x00000000, 0x00000000, 0x00000000
174 CFArrayRef
CDSAGetServerCerts();
175 #endif /* HAVE_CDSASSL */
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
,
186 static int parse_aaa(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
);
193 * 'ReadConfiguration()' - Read the cupsd.conf file.
196 int /* O - 1 on success, 0 otherwise */
197 ReadConfiguration(void)
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
];
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 */
214 * Shutdown the server...
220 * Save the old root paths...
223 old_serverroot
= NULL
;
224 SetString(&old_serverroot
, ServerRoot
);
225 old_requestroot
= NULL
;
226 SetString(&old_requestroot
, RequestRoot
);
229 * Reset the server configuration data...
232 DeleteAllLocations();
250 for (i
= 0; i
< NumRelays
; i
++)
251 if (Relays
[i
].from
.type
== AUTH_NAME
)
252 free(Relays
[i
].from
.mask
.name
.name
);
259 if (NumListeners
> 0)
261 #ifdef HAVE_DOMAINSOCKETS
262 int i
; /* Looping var */
263 listener_t
*lis
; /* Current listening socket */
265 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
266 if (lis
->address
.sin_family
== AF_LOCAL
)
267 ClearString((char **)&lis
->address
.sin_addr
);
268 #endif /* HAVE_DOMAINSOCKETS */
279 SetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
280 SetStringf(&ServerAdmin
, "root@%s", temp
);
281 SetString(&ServerBin
, CUPS_SERVERBIN
);
282 SetString(&RequestRoot
, CUPS_REQUESTS
);
283 SetString(&CacheDir
, CUPS_CACHEDIR
);
284 SetString(&DataDir
, CUPS_DATADIR
);
285 SetString(&DocumentRoot
, CUPS_DOCROOT
);
286 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
287 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
288 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
289 SetString(&Printcap
, "/etc/printcap");
290 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
291 SetString(&FontPath
, CUPS_FONTPATH
);
292 SetString(&RemoteRoot
, "remroot");
293 SetString(&ServerHeader
, "CUPS/1.1");
294 SetString(&StateDir
, CUPS_STATEDIR
);
296 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
297 if ((slash
= strrchr(temp
, '/')) != NULL
)
300 SetString(&ServerRoot
, temp
);
302 ClearString(&Classification
);
303 ClassifyOverride
= 0;
307 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
309 SetString(&ServerCertificate
, "ssl/server.crt");
310 SetString(&ServerKey
, "ssl/server.key");
311 # endif /* HAVE_CDSASSL */
312 #endif /* HAVE_SSL */
314 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
316 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
319 SetString(&DefaultLanguage
, language
);
320 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
322 SetString(&RIPCache
, "8m");
324 if (getenv("TMPDIR") == NULL
)
325 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
327 SetString(&TempDir
, getenv("TMPDIR"));
330 * Find the default system group: "sys", "system", or "root"...
333 group
= getgrnam(CUPS_DEFAULT_GROUP
);
340 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
341 Group
= group
->gr_gid
;
350 SetString(&SystemGroups
[0], group
->gr_name
);
355 SetString(&SystemGroups
[0], "unknown");
361 * Find the default user...
364 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
365 User
= 1; /* Force to a non-priviledged account */
375 ConfigFilePerm
= 0640;
376 DefaultAuthType
= AUTH_BASIC
;
378 FaxRetryInterval
= 300;
383 HostNameLookups
= FALSE
;
384 ImplicitClasses
= TRUE
;
385 ImplicitAnyClasses
= FALSE
;
386 HideImplicitMembers
= TRUE
;
388 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
389 ListenBackLog
= SOMAXCONN
;
393 MaxClientsPerHost
= 0;
394 MaxLogSize
= 1024 * 1024;
395 MaxPrinterHistory
= 10;
398 RootCertDuration
= 300;
400 Timeout
= DEFAULT_TIMEOUT
;
402 BrowseInterval
= DEFAULT_INTERVAL
;
403 BrowsePort
= ippPort();
404 BrowseProtocols
= BROWSE_CUPS
;
405 BrowseShortNames
= TRUE
;
406 BrowseTimeout
= DEFAULT_TIMEOUT
;
409 ClearString(&BrowseLocalOptions
);
410 ClearString(&BrowseRemoteOptions
);
412 JobHistory
= DEFAULT_HISTORY
;
413 JobFiles
= DEFAULT_FILES
;
418 MaxJobsPerPrinter
= 0;
421 ClearString(&DefaultPolicy
);
424 * Read the configuration file...
427 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
430 status
= read_configuration(fp
);
443 * Use the default system group if none was supplied in cupsd.conf...
446 if (NumSystemGroups
== 0)
450 * Get the access control list for browsing...
453 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
456 * Open the system log for cupsd if necessary...
460 if (!strcmp(AccessLog
, "syslog") ||
461 !strcmp(ErrorLog
, "syslog") ||
462 !strcmp(PageLog
, "syslog"))
463 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
464 #endif /* HAVE_VSYSLOG */
467 * Log the configuration file that was used...
470 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
473 * Check that we have at least one listen/port line; if not, report this
474 * as an error and exit!
477 if (NumListeners
== 0)
483 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
489 cupsdEndProcess(getpid(), 0);
493 * Set the default locale using the language and charset...
496 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
499 * Update all relative filenames to include the full path from ServerRoot...
502 if (DocumentRoot
[0] != '/')
503 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
505 if (RequestRoot
[0] != '/')
506 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
508 if (ServerBin
[0] != '/')
509 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
511 if (StateDir
[0] != '/')
512 SetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
514 if (CacheDir
[0] != '/')
515 SetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
518 if (ServerCertificate
[0] != '/')
519 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
521 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
522 chown(ServerCertificate
, RunUser
, Group
);
523 chmod(ServerCertificate
, ConfigFilePerm
);
525 if (ServerKey
[0] != '/')
526 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
528 chown(ServerKey
, RunUser
, Group
);
529 chmod(ServerKey
, ConfigFilePerm
);
530 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
531 #endif /* HAVE_SSL */
534 * Make sure that directories and config files are owned and
535 * writable by the user and group in the cupsd.conf file...
538 chown(CacheDir
, RunUser
, Group
);
539 chmod(CacheDir
, 0775);
541 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
544 chown(temp
, RunUser
, Group
);
547 chown(StateDir
, RunUser
, Group
);
548 chmod(StateDir
, 0775);
550 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
553 chown(temp
, RunUser
, Group
);
556 chown(ServerRoot
, RunUser
, Group
);
557 chmod(ServerRoot
, 0775);
559 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
562 chown(temp
, RunUser
, Group
);
565 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
568 chown(temp
, RunUser
, Group
);
571 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
572 chown(temp
, RunUser
, Group
);
573 chmod(temp
, ConfigFilePerm
);
575 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
576 chown(temp
, RunUser
, Group
);
580 chmod(temp
, ConfigFilePerm
);
581 #endif /* __APPLE__ */
583 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
584 chown(temp
, RunUser
, Group
);
588 chmod(temp
, ConfigFilePerm
);
589 #endif /* __APPLE__ */
591 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
592 chown(temp
, User
, Group
);
596 * Make sure the request and temporary directories have the right
600 chown(RequestRoot
, RunUser
, Group
);
601 chmod(RequestRoot
, 0710);
603 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
607 * Update ownership and permissions if the CUPS temp directory
608 * is under the spool directory or does not exist...
611 if (access(TempDir
, 0))
612 mkdir(TempDir
, 01770);
614 chown(TempDir
, RunUser
, Group
);
615 chmod(TempDir
, 01770);
618 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
621 * Clean out the temporary directory...
624 cups_dir_t
*dir
; /* Temporary directory */
625 cups_dentry_t
*dent
; /* Directory entry */
626 char tempfile
[1024]; /* Temporary filename */
629 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
631 LogMessage(L_INFO
, "Cleaning out old temporary files in \"%s\"...",
634 while ((dent
= cupsDirRead(dir
)) != NULL
)
636 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
638 if (unlink(tempfile
))
639 LogMessage(L_ERROR
, "Unable to remove temporary file \"%s\" - %s",
640 tempfile
, strerror(errno
));
642 LogMessage(L_DEBUG
, "Removed temporary file \"%s\"...", tempfile
);
648 LogMessage(L_ERROR
, "Unable to open temporary directory \"%s\" - %s",
649 TempDir
, strerror(errno
));
653 * Check the MaxClients setting, and then allocate memory for it...
656 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
659 LogMessage(L_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
662 MaxClients
= MaxFDs
/ 3;
665 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
667 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
668 MaxClients
, strerror(errno
));
672 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
675 * Check the MaxActiveJobs setting; limit to 1/3 the available
676 * file descriptors, since we need a pipe for each job...
679 if (MaxActiveJobs
> (MaxFDs
/ 3))
680 MaxActiveJobs
= MaxFDs
/ 3;
682 if (Classification
&& strcasecmp(Classification
, "none") == 0)
683 ClearString(&Classification
);
686 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
689 * Update the MaxClientsPerHost value, as needed...
692 if (MaxClientsPerHost
<= 0)
693 MaxClientsPerHost
= MaxClients
;
695 if (MaxClientsPerHost
> MaxClients
)
696 MaxClientsPerHost
= MaxClients
;
698 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
702 * Update the default policy, as needed...
706 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
708 DefaultPolicyPtr
= NULL
;
710 if (!DefaultPolicyPtr
)
712 cupsd_policy_t
*p
; /* New policy */
713 location_t
*po
; /* New policy operation */
717 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
719 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
720 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
723 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
725 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
727 LogMessage(L_INFO
, "<Policy default>");
728 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
729 "Release-Job Restart-Job Purge-Jobs "
730 "Set-Job-Attributes Create-Job-Subscription "
731 "Renew-Subscription Cancel-Subscription "
732 "Get-Notifications Reprocess-Job Cancel-Current-Job "
733 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
734 LogMessage(L_INFO
, "Order Allow,Deny");
736 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
737 po
->order_type
= AUTH_DENY
;
738 po
->level
= AUTH_USER
;
740 AddName(po
, "@OWNER");
741 AddName(po
, "@SYSTEM");
742 LogMessage(L_INFO
, "Require user @OWNER @SYSTEM");
744 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
745 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
746 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
747 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
748 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
749 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
750 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
751 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
752 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
753 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
754 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
755 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
756 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
757 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
758 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
759 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
761 LogMessage(L_INFO
, "</Limit>");
763 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
764 "Set-Printer-Attributes Enable-Printer "
765 "Disable-Printer Pause-Printer-After-Current-Job "
766 "Hold-New-Jobs Release-Held-New-Jobs "
767 "Deactivate-Printer Activate-Printer Restart-Printer "
768 "Shutdown-Printer Startup-Printer Promote-Job "
769 "Schedule-Job-After CUPS-Add-Printer "
770 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
771 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
772 LogMessage(L_INFO
, "Order Allow,Deny");
773 LogMessage(L_INFO
, "AuthType Basic");
775 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
776 po
->order_type
= AUTH_DENY
;
777 po
->type
= AUTH_BASIC
;
778 po
->level
= AUTH_USER
;
780 AddName(po
, "@SYSTEM");
781 LogMessage(L_INFO
, "Require user @SYSTEM");
783 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
784 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
785 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
786 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
787 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
788 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
789 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
790 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
791 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
792 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
793 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
794 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
795 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
796 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
797 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
798 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
799 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
800 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
801 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
802 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
803 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
805 LogMessage(L_INFO
, "</Limit>");
807 LogMessage(L_INFO
, "<Limit All>");
808 LogMessage(L_INFO
, "Order Allow,Deny");
810 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
811 po
->order_type
= AUTH_DENY
;
813 LogMessage(L_INFO
, "</Limit>");
814 LogMessage(L_INFO
, "</Policy>");
819 * If we are doing a full reload or the server root has changed, flush
820 * the jobs, printers, etc. and start from scratch...
823 if (NeedReload
== RELOAD_ALL
||
824 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
825 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
827 LogMessage(L_INFO
, "Full reload is required.");
837 DefaultPrinter
= NULL
;
839 if (MimeDatabase
!= NULL
)
840 mimeDelete(MimeDatabase
);
844 for (i
= 0; i
< NumMimeTypes
; i
++)
845 free((void *)MimeTypes
[i
]);
851 * Read the MIME type and conversion database...
854 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
856 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
858 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
859 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
862 * Create a list of MIME types for the document-format-supported
866 NumMimeTypes
= MimeDatabase
->num_types
;
867 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
870 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
872 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
874 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
875 MimeDatabase
->types
[i
]->type
);
877 MimeTypes
[i
] = strdup(type
);
880 if (i
< NumMimeTypes
)
881 MimeTypes
[i
] = strdup("application/octet-stream");
887 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
891 * Load printers and classes...
900 * Load queued jobs...
905 LogMessage(L_INFO
, "Full reload complete.");
911 LogMessage(L_INFO
, "Partial reload complete.");
915 * Reset the reload state...
918 NeedReload
= RELOAD_NONE
;
920 ClearString(&old_serverroot
);
921 ClearString(&old_requestroot
);
924 * Startup the server and return...
934 * 'get_address()' - Get an address + port number from a line.
937 static int /* O - 1 if address good, 0 if bad */
938 get_address(const char *value
, /* I - Value string */
939 unsigned defaddress
, /* I - Default address */
940 int defport
, /* I - Default port */
941 int deffamily
, /* I - Default family */
942 http_addr_t
*address
) /* O - Socket address */
944 char hostname
[256], /* Hostname or IP */
945 portname
[256], /* Port number or name */
946 *ptr
; /* Pointer into hostname string */
947 struct hostent
*host
; /* Host address */
948 struct servent
*port
; /* Port number */
952 * Check for an empty value...
957 LogMessage(L_ERROR
, "Bad (empty) address!");
962 * Initialize the socket address to the defaults...
965 memset(address
, 0, sizeof(http_addr_t
));
968 if (deffamily
== AF_INET6
)
970 address
->ipv6
.sin6_family
= AF_INET6
;
971 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
972 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
973 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
974 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
975 address
->ipv6
.sin6_port
= htons(defport
);
978 #endif /* AF_INET6 */
980 address
->ipv4
.sin_family
= AF_INET
;
981 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
982 address
->ipv4
.sin_port
= htons(defport
);
987 * If the address starts with a "/", it is a domain socket...
992 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
994 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
998 address
->un
.sun_family
= AF_LOCAL
;
999 strcpy(address
->un
.sun_path
, value
);
1002 #endif /* AF_LOCAL */
1005 * Try to grab a hostname and port number...
1008 strlcpy(hostname
, value
, sizeof(hostname
));
1010 if ((ptr
= strrchr(hostname
, ':')) != NULL
)
1013 * Copy hostname and port separately...
1018 strlcpy(portname
, ptr
, sizeof(portname
));
1020 else if (isdigit(value
[0] & 255))
1027 strlcpy(portname
, value
, sizeof(portname
));
1032 * Hostname by itself...
1039 * Decode the hostname and port number as needed...
1042 if (hostname
[0] && strcmp(hostname
, "*"))
1044 if ((host
= httpGetHostByName(hostname
)) == NULL
)
1046 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
1047 hstrerror(h_errno
));
1051 httpAddrLoad(host
, defport
, 0, address
);
1054 if (portname
[0] != '\0')
1056 if (isdigit(portname
[0] & 255))
1059 if (address
->addr
.sa_family
== AF_INET6
)
1060 address
->ipv6
.sin6_port
= htons(atoi(portname
));
1062 #endif /* AF_INET6 */
1063 address
->ipv4
.sin_port
= htons(atoi(portname
));
1067 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
1069 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
1076 if (address
->addr
.sa_family
== AF_INET6
)
1077 address
->ipv6
.sin6_port
= htons(port
->s_port
);
1079 #endif /* AF_INET6 */
1080 address
->ipv4
.sin_port
= htons(port
->s_port
);
1090 * 'get_addr_and_mask()' - Get an IP address and netmask.
1093 static int /* O - 1 on success, 0 on failure */
1094 get_addr_and_mask(const char *value
, /* I - String from config file */
1095 unsigned *ip
, /* O - Address value */
1096 unsigned *mask
) /* O - Mask value */
1098 int i
, /* Looping var */
1099 family
, /* Address family */
1100 ipcount
; /* Count of fields in address */
1101 const char *maskval
, /* Pointer to start of mask value */
1102 *ptr
; /* Pointer into value */
1103 static unsigned netmasks
[4][4] = /* Standard netmasks... */
1105 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1106 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1107 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1108 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1113 * Get the address...
1116 memset(ip
, 0, sizeof(unsigned) * 4);
1118 if ((maskval
= strchr(value
, '/')) != NULL
)
1121 maskval
= value
+ strlen(value
);
1125 * Check for an IPv6 address...
1131 * Parse hexadecimal IPv6 address...
1136 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 4; i
++)
1140 else if (*ptr
== ':')
1143 ip
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1145 if (*ptr
== ':' || *ptr
== ']')
1151 if (*ptr
&& *ptr
!= '/')
1155 #endif /* AF_INET6 */
1158 * Parse dotted-decimal IPv4 address...
1162 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1164 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1165 ip
[0] = ip
[1] = ip
[2] = 0;
1171 * Get the netmask value(s)...
1174 memset(mask
, 0, sizeof(unsigned) * 4);
1177 if (maskval
[1] == '[')
1180 * Get hexadecimal mask value...
1183 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 4; i
++)
1187 else if (*ptr
== ':')
1190 mask
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1192 if (*ptr
== ':' || *ptr
== ']')
1200 #endif /* AF_INET6 */
1201 if (strchr(maskval
, '.'))
1204 * Get dotted-decimal mask...
1207 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1210 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1211 mask
[0] = mask
[1] = mask
[2] = 0;
1216 * Get address/bits format...
1222 if (family
== AF_INET6
)
1227 mask
[0] = 0xffffffff;
1229 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1232 mask
[1] = 0xffffffff;
1236 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1239 mask
[2] = 0xffffffff;
1243 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1246 mask
[3] = 0xffffffff;
1250 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1253 #endif /* AF_INET6 */
1257 mask
[0] = 0xffffffff;
1258 mask
[1] = 0xffffffff;
1259 mask
[2] = 0xffffffff;
1262 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1264 mask
[3] = 0xffffffff;
1269 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1271 LogMessage(L_DEBUG2
, "get_addr_and_mask(value=\"%s\", "
1272 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1273 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1277 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1280 if ((ip
[0] & ~mask
[0]) != 0 ||
1281 (ip
[1] & ~mask
[1]) != 0 ||
1282 (ip
[2] & ~mask
[2]) != 0 ||
1283 (ip
[3] & ~mask
[3]) != 0)
1291 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1294 static int /* O - 1 on success, 0 on failure */
1295 parse_aaa(location_t
*loc
, /* I - Location */
1296 char *line
, /* I - Line from file */
1297 char *value
, /* I - Start of value data */
1298 int linenum
) /* I - Current line number */
1300 char *valptr
; /* Pointer into value */
1301 unsigned ip
[4], /* IP address components */
1302 mask
[4]; /* IP netmask components */
1305 if (!strcasecmp(line
, "Encryption"))
1308 * "Encryption xxx" - set required encryption level...
1311 if (!strcasecmp(value
, "never"))
1312 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1313 else if (!strcasecmp(value
, "always"))
1315 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1316 "Using \"required\" instead.", value
, linenum
);
1318 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1320 else if (!strcasecmp(value
, "required"))
1321 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1322 else if (!strcasecmp(value
, "ifrequested"))
1323 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1326 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1331 else if (!strcasecmp(line
, "Order"))
1334 * "Order Deny,Allow" or "Order Allow,Deny"...
1337 if (!strncasecmp(value
, "deny", 4))
1338 loc
->order_type
= AUTH_ALLOW
;
1339 else if (!strncasecmp(value
, "allow", 5))
1340 loc
->order_type
= AUTH_DENY
;
1343 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1348 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1351 * Allow [From] host/ip...
1352 * Deny [From] host/ip...
1355 if (!strncasecmp(value
, "from", 4))
1358 * Strip leading "from"...
1363 while (isspace(*value
& 255))
1368 * Figure out what form the allow/deny address takes:
1379 * nnn.nnn.nnn.nnn/mm
1380 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1383 if (!strcasecmp(value
, "all"))
1389 if (!strcasecmp(line
, "Allow"))
1390 AllowIP(loc
, zeros
, zeros
);
1392 DenyIP(loc
, zeros
, zeros
);
1394 else if (!strcasecmp(value
, "none"))
1400 if (!strcasecmp(line
, "Allow"))
1401 AllowIP(loc
, ones
, zeros
);
1403 DenyIP(loc
, ones
, zeros
);
1405 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1408 * Host or domain name...
1411 if (value
[0] == '*')
1414 if (!strcasecmp(line
, "Allow"))
1415 AllowHost(loc
, value
);
1417 DenyHost(loc
, value
);
1422 * One of many IP address forms...
1425 if (!get_addr_and_mask(value
, ip
, mask
))
1427 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1432 if (!strcasecmp(line
, "Allow"))
1433 AllowIP(loc
, ip
, mask
);
1435 DenyIP(loc
, ip
, mask
);
1438 else if (!strcasecmp(line
, "AuthType"))
1441 * AuthType {none,basic,digest,basicdigest}
1444 if (!strcasecmp(value
, "none"))
1446 loc
->type
= AUTH_NONE
;
1447 loc
->level
= AUTH_ANON
;
1449 else if (!strcasecmp(value
, "basic"))
1451 loc
->type
= AUTH_BASIC
;
1453 if (loc
->level
== AUTH_ANON
)
1454 loc
->level
= AUTH_USER
;
1456 else if (!strcasecmp(value
, "digest"))
1458 loc
->type
= AUTH_DIGEST
;
1460 if (loc
->level
== AUTH_ANON
)
1461 loc
->level
= AUTH_USER
;
1463 else if (!strcasecmp(value
, "basicdigest"))
1465 loc
->type
= AUTH_BASICDIGEST
;
1467 if (loc
->level
== AUTH_ANON
)
1468 loc
->level
= AUTH_USER
;
1472 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1477 else if (!strcasecmp(line
, "AuthClass"))
1480 * AuthClass anonymous, user, system, group
1483 if (!strcasecmp(value
, "anonymous"))
1485 loc
->type
= AUTH_NONE
;
1486 loc
->level
= AUTH_ANON
;
1488 else if (!strcasecmp(value
, "user"))
1489 loc
->level
= AUTH_USER
;
1490 else if (!strcasecmp(value
, "group"))
1491 loc
->level
= AUTH_GROUP
;
1492 else if (!strcasecmp(value
, "system"))
1494 loc
->level
= AUTH_GROUP
;
1496 AddName(loc
, "@SYSTEM");
1500 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1505 else if (!strcasecmp(line
, "AuthGroupName"))
1506 AddName(loc
, value
);
1507 else if (!strcasecmp(line
, "Require"))
1510 * Apache synonym for AuthClass and AuthGroupName...
1514 * Require valid-user
1515 * Require group names
1516 * Require user names
1519 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1524 if (!strcasecmp(value
, "valid-user") ||
1525 !strcasecmp(value
, "user"))
1526 loc
->level
= AUTH_USER
;
1527 else if (!strcasecmp(value
, "group"))
1528 loc
->level
= AUTH_GROUP
;
1531 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1537 * Get the list of names from the line...
1540 for (value
= valptr
; *value
;)
1542 while (isspace(*value
& 255))
1545 if (*value
== '\"' || *value
== '\'')
1548 * Grab quoted name...
1551 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1558 * Grab literal name.
1561 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1567 AddName(loc
, value
);
1569 for (value
= valptr
; isspace(*value
& 255); value
++);
1572 else if (!strcasecmp(line
, "Satisfy"))
1574 if (!strcasecmp(value
, "all"))
1575 loc
->satisfy
= AUTH_SATISFY_ALL
;
1576 else if (!strcasecmp(value
, "any"))
1577 loc
->satisfy
= AUTH_SATISFY_ANY
;
1580 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1593 * 'read_configuration()' - Read a configuration file.
1596 static int /* O - 1 on success, 0 on failure */
1597 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1599 int i
; /* Looping var */
1600 int linenum
; /* Current line number */
1601 char line
[HTTP_MAX_BUFFER
], /* Line from file */
1602 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
1603 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
1604 *ptr
, /* Pointer into line/temp */
1605 *value
; /* Pointer to value */
1606 int valuelen
; /* Length of value */
1607 var_t
*var
; /* Current variable */
1608 unsigned ip
[4], /* Address value */
1609 mask
[4]; /* Netmask value */
1610 dirsvc_relay_t
*relay
; /* Relay data */
1611 dirsvc_poll_t
*poll
; /* Polling data */
1612 http_addr_t polladdr
; /* Polling address */
1613 location_t
*location
; /* Browse location */
1614 cups_file_t
*incfile
; /* Include file */
1615 char incname
[1024]; /* Include filename */
1619 * Loop through each line in the file...
1624 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1627 * Decode the directive...
1630 if (!strcasecmp(line
, "Include"))
1636 if (value
[0] == '/')
1637 strlcpy(incname
, value
, sizeof(incname
));
1639 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1641 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1642 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
1643 incname
, strerror(errno
));
1646 read_configuration(incfile
);
1647 cupsFileClose(incfile
);
1650 else if (!strcasecmp(line
, "<Location"))
1658 linenum
= read_location(fp
, value
, linenum
);
1664 LogMessage(L_ERROR
, "Syntax error on line %d.",
1669 else if (!strcasecmp(line
, "<Policy"))
1677 linenum
= read_policy(fp
, value
, linenum
);
1683 LogMessage(L_ERROR
, "Syntax error on line %d.",
1688 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1691 * Add a listening address to the list...
1694 listener_t
*lis
; /* New listeners array */
1697 if (NumListeners
== 0)
1698 lis
= malloc(2 * sizeof(listener_t
));
1700 lis
= realloc(Listeners
, (NumListeners
+ 2) * sizeof(listener_t
));
1704 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1705 line
, linenum
, strerror(errno
));
1710 lis
+= NumListeners
;
1712 memset(lis
, 0, sizeof(listener_t
));
1715 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
, &(lis
->address
)))
1717 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1718 #endif /* AF_INET6 */
1720 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1723 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1725 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1726 ntohs(lis
->address
.ipv6
.sin6_port
));
1729 if (value
[0] == '*')
1732 * Also listen on IPv4 address...
1738 memset(lis
, 0, sizeof(listener_t
));
1739 get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
,
1742 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1743 LogMessage(L_INFO
, "Listening to %s:%d (IPv4)", temp
,
1744 ntohs(lis
->address
.ipv4
.sin_port
));
1746 # endif /* ALSO_BIND_IPV4 */
1749 #endif /* AF_INET6 */
1751 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1752 ntohs(lis
->address
.ipv4
.sin_port
));
1758 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1762 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1765 * Add a listening address to the list...
1768 listener_t
*lis
; /* New listeners array */
1771 if (NumListeners
== 0)
1772 lis
= malloc(sizeof(listener_t
));
1774 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1778 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1779 line
, linenum
, strerror(errno
));
1784 lis
+= NumListeners
;
1786 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1788 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1791 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1792 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1793 ntohs(lis
->address
.ipv6
.sin6_port
));
1795 #endif /* AF_INET6 */
1796 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1797 ntohs(lis
->address
.ipv4
.sin_port
));
1798 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1802 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1805 #endif /* HAVE_SSL */
1806 else if (!strcasecmp(line
, "BrowseAddress"))
1809 * Add a browse address to the list...
1812 dirsvc_addr_t
*dira
; /* New browse address array */
1815 if (NumBrowsers
== 0)
1816 dira
= malloc(sizeof(dirsvc_addr_t
));
1818 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1822 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1823 linenum
, strerror(errno
));
1828 dira
+= NumBrowsers
;
1830 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1832 if (!strcasecmp(value
, "@LOCAL"))
1835 * Send browse data to all local interfaces...
1838 strcpy(dira
->iface
, "*");
1841 else if (!strncasecmp(value
, "@IF(", 4))
1844 * Send browse data to the named interface...
1847 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1849 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1855 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1857 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1860 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1861 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1862 ntohs(dira
->to
.ipv6
.sin6_port
));
1864 #endif /* AF_INET6 */
1865 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1866 ntohs(dira
->to
.ipv4
.sin_port
));
1871 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1874 else if (!strcasecmp(line
, "BrowseOrder"))
1877 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1880 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1881 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1883 if (location
== NULL
)
1884 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1885 else if (!strncasecmp(value
, "deny", 4))
1886 location
->order_type
= AUTH_ALLOW
;
1887 else if (!strncasecmp(value
, "allow", 5))
1888 location
->order_type
= AUTH_DENY
;
1890 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1893 else if (!strcasecmp(line
, "BrowseProtocols"))
1896 * "BrowseProtocol name [... name]"
1899 BrowseProtocols
= 0;
1903 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1904 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1907 if (value
[valuelen
])
1909 value
[valuelen
] = '\0';
1913 if (!strcasecmp(value
, "cups"))
1914 BrowseProtocols
|= BROWSE_CUPS
;
1915 else if (!strcasecmp(value
, "slp"))
1916 BrowseProtocols
|= BROWSE_SLP
;
1917 else if (!strcasecmp(value
, "ldap"))
1918 BrowseProtocols
|= BROWSE_LDAP
;
1919 else if (!strcasecmp(value
, "all"))
1920 BrowseProtocols
|= BROWSE_ALL
;
1923 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1928 for (value
+= valuelen
; *value
; value
++)
1929 if (!isspace(*value
) || *value
!= ',')
1933 else if (!strcasecmp(line
, "BrowseAllow") ||
1934 !strcasecmp(line
, "BrowseDeny"))
1937 * BrowseAllow [From] host/ip...
1938 * BrowseDeny [From] host/ip...
1941 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1942 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1944 if (location
== NULL
)
1945 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1948 if (!strncasecmp(value
, "from ", 5))
1951 * Strip leading "from"...
1956 while (isspace(*value
))
1961 * Figure out what form the allow/deny address takes:
1972 * nnn.nnn.nnn.nnn/mm
1973 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1976 if (!strcasecmp(value
, "all"))
1982 if (!strcasecmp(line
, "BrowseAllow"))
1983 AllowIP(location
, zeros
, zeros
);
1985 DenyIP(location
, zeros
, zeros
);
1987 else if (!strcasecmp(value
, "none"))
1993 if (!strcasecmp(line
, "BrowseAllow"))
1994 AllowIP(location
, ones
, zeros
);
1996 DenyIP(location
, ones
, zeros
);
1998 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2001 * Host or domain name...
2004 if (value
[0] == '*')
2007 if (!strcasecmp(line
, "BrowseAllow"))
2008 AllowHost(location
, value
);
2010 DenyHost(location
, value
);
2015 * One of many IP address forms...
2018 if (!get_addr_and_mask(value
, ip
, mask
))
2020 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2025 if (!strcasecmp(line
, "BrowseAllow"))
2026 AllowIP(location
, ip
, mask
);
2028 DenyIP(location
, ip
, mask
);
2032 else if (!strcasecmp(line
, "BrowseRelay"))
2035 * BrowseRelay [from] source [to] destination
2039 relay
= malloc(sizeof(dirsvc_relay_t
));
2041 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
2045 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
2046 linenum
, strerror(errno
));
2053 memset(relay
, 0, sizeof(dirsvc_relay_t
));
2055 if (!strncasecmp(value
, "from ", 5))
2058 * Strip leading "from"...
2063 while (isspace(*value
))
2068 * Figure out what form the from address takes:
2077 * nnn.nnn.nnn.nnn/mm
2078 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2081 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2084 * Host or domain name...
2087 if (value
[0] == '*')
2090 strlcpy(temp
, value
, sizeof(temp
));
2091 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2094 relay
->from
.type
= AUTH_NAME
;
2095 relay
->from
.mask
.name
.name
= strdup(temp
);
2096 relay
->from
.mask
.name
.length
= strlen(temp
);
2101 * One of many IP address forms...
2104 if (!get_addr_and_mask(value
, ip
, mask
))
2106 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2111 relay
->from
.type
= AUTH_IP
;
2112 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2113 sizeof(relay
->from
.mask
.ip
.address
));
2114 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2115 sizeof(relay
->from
.mask
.ip
.netmask
));
2119 * Skip value and trailing whitespace...
2122 for (; *value
; value
++)
2123 if (isspace(*value
))
2126 while (isspace(*value
))
2129 if (!strncasecmp(value
, "to ", 3))
2132 * Strip leading "to"...
2137 while (isspace(*value
))
2142 * Get "to" address and port...
2145 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
2147 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2149 if (relay
->from
.type
== AUTH_IP
)
2150 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2151 relay
->from
.mask
.ip
.address
[0],
2152 relay
->from
.mask
.ip
.address
[1],
2153 relay
->from
.mask
.ip
.address
[2],
2154 relay
->from
.mask
.ip
.address
[3],
2155 relay
->from
.mask
.ip
.netmask
[0],
2156 relay
->from
.mask
.ip
.netmask
[1],
2157 relay
->from
.mask
.ip
.netmask
[2],
2158 relay
->from
.mask
.ip
.netmask
[3]);
2160 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2163 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2164 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2165 ntohs(relay
->to
.ipv6
.sin6_port
));
2167 #endif /* AF_INET6 */
2168 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2169 ntohs(relay
->to
.ipv4
.sin_port
));
2175 if (relay
->from
.type
== AUTH_NAME
)
2176 free(relay
->from
.mask
.name
.name
);
2178 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
2181 else if (!strcasecmp(line
, "BrowsePoll"))
2184 * BrowsePoll address[:port]
2188 poll
= malloc(sizeof(dirsvc_poll_t
));
2190 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
2194 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
2195 linenum
, strerror(errno
));
2203 * Get poll address and port...
2206 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
2209 memset(poll
, 0, sizeof(dirsvc_poll_t
));
2211 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
2214 if (polladdr
.addr
.sa_family
== AF_INET6
)
2215 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
2217 #endif /* AF_INET6 */
2218 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
2220 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
2223 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
2225 else if (!strcasecmp(line
, "DefaultAuthType"))
2228 * DefaultAuthType {basic,digest,basicdigest}
2231 if (!strcasecmp(value
, "basic"))
2232 DefaultAuthType
= AUTH_BASIC
;
2233 else if (!strcasecmp(value
, "digest"))
2234 DefaultAuthType
= AUTH_DIGEST
;
2235 else if (!strcasecmp(value
, "basicdigest"))
2236 DefaultAuthType
= AUTH_BASICDIGEST
;
2239 LogMessage(L_WARN
, "Unknown default authorization type %s on line %d.",
2244 else if (!strcasecmp(line
, "User"))
2247 * User ID to run as...
2250 if (isdigit(value
[0]))
2254 struct passwd
*p
; /* Password information */
2257 p
= getpwnam(value
);
2262 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
2265 else if (!strcasecmp(line
, "Group"))
2268 * Group ID to run as...
2271 if (isdigit(value
[0]))
2272 Group
= atoi(value
);
2275 struct group
*g
; /* Group information */
2278 g
= getgrnam(value
);
2283 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
2286 else if (!strcasecmp(line
, "SystemGroup"))
2289 * System (admin) group(s)...
2292 char *valueptr
, /* Pointer into value */
2293 quote
; /* Quote character */
2296 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
2298 if (*value
== '\'' || *value
== '\"')
2301 * Scan quoted name...
2306 for (valueptr
= value
; *valueptr
; valueptr
++)
2307 if (*valueptr
== quote
)
2313 * Scan space or comma-delimited name...
2316 for (valueptr
= value
; *valueptr
; valueptr
++)
2317 if (isspace(*valueptr
) || *valueptr
== ',')
2324 SetString(SystemGroups
+ i
, value
);
2328 while (*value
== ',' || isspace(*value
))
2333 NumSystemGroups
= i
;
2335 else if (!strcasecmp(line
, "HostNameLookups"))
2338 * Do hostname lookups?
2341 if (!strcasecmp(value
, "off"))
2342 HostNameLookups
= 0;
2343 else if (!strcasecmp(value
, "on"))
2344 HostNameLookups
= 1;
2345 else if (!strcasecmp(value
, "double"))
2346 HostNameLookups
= 2;
2348 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
2351 else if (!strcasecmp(line
, "LogLevel"))
2354 * Amount of logging to do...
2357 if (!strcasecmp(value
, "debug2"))
2358 LogLevel
= L_DEBUG2
;
2359 else if (!strcasecmp(value
, "debug"))
2361 else if (!strcasecmp(value
, "info"))
2363 else if (!strcasecmp(value
, "notice"))
2364 LogLevel
= L_NOTICE
;
2365 else if (!strcasecmp(value
, "warn"))
2367 else if (!strcasecmp(value
, "error"))
2369 else if (!strcasecmp(value
, "crit"))
2371 else if (!strcasecmp(value
, "alert"))
2373 else if (!strcasecmp(value
, "emerg"))
2375 else if (!strcasecmp(value
, "none"))
2378 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
2380 else if (!strcasecmp(line
, "PrintcapFormat"))
2383 * Format of printcap file?
2386 if (!strcasecmp(value
, "bsd"))
2387 PrintcapFormat
= PRINTCAP_BSD
;
2388 else if (!strcasecmp(value
, "solaris"))
2389 PrintcapFormat
= PRINTCAP_SOLARIS
;
2391 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
2394 else if (!strcasecmp(line
, "ServerTokens"))
2397 * Set the string used for the Server header...
2400 struct utsname plat
; /* Platform info */
2405 if (!strcasecmp(value
, "ProductOnly"))
2406 SetString(&ServerHeader
, "CUPS");
2407 else if (!strcasecmp(value
, "Major"))
2408 SetString(&ServerHeader
, "CUPS/1");
2409 else if (!strcasecmp(value
, "Minor"))
2410 SetString(&ServerHeader
, "CUPS/1.1");
2411 else if (!strcasecmp(value
, "Minimal"))
2412 SetString(&ServerHeader
, CUPS_MINIMAL
);
2413 else if (!strcasecmp(value
, "OS"))
2414 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2415 else if (!strcasecmp(value
, "Full"))
2416 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
2417 else if (!strcasecmp(value
, "None"))
2418 ClearString(&ServerHeader
);
2420 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
2425 * Find a simple variable in the list...
2428 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2429 if (!strcasecmp(line
, var
->name
))
2435 * Unknown directive! Output an error message and continue...
2438 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
2448 char *units
; /* Units */
2451 n
= strtol(value
, &units
, 0);
2453 if (units
&& *units
)
2455 if (tolower(units
[0] & 255) == 'g')
2456 n
*= 1024 * 1024 * 1024;
2457 else if (tolower(units
[0] & 255) == 'm')
2459 else if (tolower(units
[0] & 255) == 'k')
2461 else if (tolower(units
[0] & 255) == 't')
2465 *((int *)var
->ptr
) = n
;
2470 if (!strcasecmp(value
, "true") ||
2471 !strcasecmp(value
, "on") ||
2472 !strcasecmp(value
, "enabled") ||
2473 !strcasecmp(value
, "yes") ||
2475 *((int *)var
->ptr
) = TRUE
;
2476 else if (!strcasecmp(value
, "false") ||
2477 !strcasecmp(value
, "off") ||
2478 !strcasecmp(value
, "disabled") ||
2479 !strcasecmp(value
, "no") ||
2480 !strcasecmp(value
, "0"))
2481 *((int *)var
->ptr
) = FALSE
;
2483 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
2488 SetString((char **)var
->ptr
, value
);
2499 * 'read_location()' - Read a <Location path> definition.
2502 static int /* O - New line number or 0 on error */
2503 read_location(cups_file_t
*fp
, /* I - Configuration file */
2504 char *location
, /* I - Location name/path */
2505 int linenum
) /* I - Current line number */
2507 location_t
*loc
, /* New location */
2508 *parent
; /* Parent location */
2509 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2510 *value
, /* Value for directive */
2511 *valptr
; /* Pointer into value */
2514 if ((parent
= AddLocation(location
)) == NULL
)
2517 parent
->limit
= AUTH_LIMIT_ALL
;
2520 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2523 * Decode the directive...
2526 if (!strcasecmp(line
, "</Location>"))
2528 else if (!strcasecmp(line
, "<Limit") ||
2529 !strcasecmp(line
, "<LimitExcept"))
2533 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2537 if ((loc
= CopyLocation(&parent
)) == NULL
)
2543 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2548 if (!strcmp(value
, "ALL"))
2549 loc
->limit
= AUTH_LIMIT_ALL
;
2550 else if (!strcmp(value
, "GET"))
2551 loc
->limit
|= AUTH_LIMIT_GET
;
2552 else if (!strcmp(value
, "HEAD"))
2553 loc
->limit
|= AUTH_LIMIT_HEAD
;
2554 else if (!strcmp(value
, "OPTIONS"))
2555 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2556 else if (!strcmp(value
, "POST"))
2557 loc
->limit
|= AUTH_LIMIT_POST
;
2558 else if (!strcmp(value
, "PUT"))
2559 loc
->limit
|= AUTH_LIMIT_PUT
;
2560 else if (!strcmp(value
, "TRACE"))
2561 loc
->limit
|= AUTH_LIMIT_TRACE
;
2563 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
2566 for (value
= valptr
; isspace(*value
& 255); value
++);
2569 if (!strcasecmp(line
, "<LimitExcept"))
2570 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2572 parent
->limit
&= ~loc
->limit
;
2574 else if (!strcasecmp(line
, "</Limit>"))
2576 else if (!parse_aaa(loc
, line
, value
, linenum
))
2578 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2584 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2592 * 'read_policy()' - Read a <Policy name> definition.
2595 static int /* O - New line number or 0 on error */
2596 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2597 char *policy
, /* I - Location name/path */
2598 int linenum
) /* I - Current line number */
2600 int i
; /* Looping var */
2601 cupsd_policy_t
*pol
; /* Policy */
2602 location_t
*op
; /* Policy operation */
2603 int num_ops
; /* Number of IPP operations */
2604 ipp_op_t ops
[100]; /* Operations */
2605 char line
[HTTP_MAX_BUFFER
],
2607 *value
, /* Value for directive */
2608 *valptr
; /* Pointer into value */
2612 * Create the policy...
2615 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2619 * Read from the file...
2625 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2628 * Decode the directive...
2631 if (!strcasecmp(line
, "</Policy>"))
2634 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2639 else if (!strcasecmp(line
, "<Limit") && !op
)
2643 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2648 * Scan for IPP operation names...
2655 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2660 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2662 if (!strcasecmp(value
, "All"))
2663 ops
[num_ops
] = IPP_ANY_OPERATION
;
2664 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2665 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2671 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2674 for (value
= valptr
; isspace(*value
& 255); value
++);
2678 * If none are specified, apply the policy to all operations...
2683 ops
[0] = IPP_ANY_OPERATION
;
2688 * Add a new policy for the first operation...
2691 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2693 else if (!strcasecmp(line
, "</Limit>") && op
)
2696 * Finish the current operation limit...
2702 * Copy the policy to the other operations...
2705 for (i
= 1; i
< num_ops
; i
++)
2706 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2713 LogMessage(L_ERROR
, "Missing <Limit ops> directive before %s on line %d.",
2717 else if (!parse_aaa(op
, line
, value
, linenum
))
2720 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2723 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2730 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2739 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2740 * required by SSLSetCertificate.
2742 * For now we assumes that there is exactly one SecIdentity in the
2743 * keychain - i.e. there is exactly one matching cert/private key pair.
2744 * In the future we will search a keychain for a SecIdentity matching a
2745 * specific criteria. We also skip the operation of adding additional
2746 * non-signing certs from the keychain to the CFArrayRef.
2748 * To create a self-signed certificate for testing use the certtool.
2749 * Executing the following as root will do it:
2751 * certtool c c v k=CUPS
2755 CDSAGetServerCerts(void)
2757 OSStatus err
; /* Error info */
2758 SecKeychainRef kcRef
; /* Keychain reference */
2759 SecIdentitySearchRef srchRef
; /* Search reference */
2760 SecIdentityRef identity
; /* Identity */
2761 CFArrayRef ca
; /* Certificate array */
2768 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2771 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2772 ServerCertificate
, err
);
2776 * Search for "any" identity matching specified key use;
2777 * in this app, we expect there to be exactly one.
2780 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2784 "Cannot find signing key in keychain \"%s\", error %d",
2785 ServerCertificate
, err
);
2788 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2792 "Cannot find signing key in keychain \"%s\", error %d",
2793 ServerCertificate
, err
);
2796 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2797 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2801 * Found one. Place it in a CFArray.
2802 * TBD: snag other (non-identity) certs from keychain and add them
2806 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2809 LogMessage(L_ERROR
, "CFArrayCreate error");
2812 /*CFRelease(identity);*/
2815 /*CFRelease(srchRef);*/
2818 /*CFRelease(kcRef);*/
2823 #endif /* HAVE_CDSASSL */