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") || !strcmp(language
, "POSIX"))
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
);
341 * Found the group, use it!
344 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
346 SystemGroupIDs
[0] = group
->gr_gid
;
351 * Find the group associated with GID 0...
358 SetString(&SystemGroups
[0], group
->gr_name
);
360 SetString(&SystemGroups
[0], "unknown");
362 SystemGroupIDs
[0] = 0;
366 * Find the default user...
369 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
374 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
375 * complement number...)
384 * Find the default group (nobody)...
387 group
= getgrnam("nobody");
391 Group
= group
->gr_gid
;
395 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
396 * complement number...)
406 ConfigFilePerm
= 0640;
407 DefaultAuthType
= AUTH_BASIC
;
409 FaxRetryInterval
= 300;
414 HostNameLookups
= FALSE
;
415 ImplicitClasses
= TRUE
;
416 ImplicitAnyClasses
= FALSE
;
417 HideImplicitMembers
= TRUE
;
419 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
420 ListenBackLog
= SOMAXCONN
;
424 MaxClientsPerHost
= 0;
425 MaxLogSize
= 1024 * 1024;
426 MaxPrinterHistory
= 10;
429 RootCertDuration
= 300;
431 Timeout
= DEFAULT_TIMEOUT
;
433 BrowseInterval
= DEFAULT_INTERVAL
;
434 BrowsePort
= ippPort();
435 BrowseLocalProtocols
= BROWSE_CUPS
;
436 BrowseRemoteProtocols
= BROWSE_CUPS
;
437 BrowseShortNames
= TRUE
;
438 BrowseTimeout
= DEFAULT_TIMEOUT
;
441 ClearString(&BrowseLocalOptions
);
442 ClearString(&BrowseRemoteOptions
);
444 JobHistory
= DEFAULT_HISTORY
;
445 JobFiles
= DEFAULT_FILES
;
450 MaxJobsPerPrinter
= 0;
453 ClearString(&DefaultPolicy
);
456 * Read the configuration file...
459 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
462 status
= read_configuration(fp
);
475 * Use the default system group if none was supplied in cupsd.conf...
478 if (NumSystemGroups
== 0)
482 * Get the access control list for browsing...
485 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
488 * Open the system log for cupsd if necessary...
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 */
499 * Log the configuration file that was used...
502 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
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
512 for (i
= 0; i
< NumSystemGroups
; i
++)
513 if (Group
== SystemGroupIDs
[i
])
516 if (i
< NumSystemGroups
)
519 * Log the error and reset the group to a safe value...
522 LogMessage(L_NOTICE
, "Group and SystemGroup cannot use the same groups!");
523 LogMessage(L_INFO
, "Resetting Group to \"nobody\"...");
525 group
= getgrnam("nobody");
529 Group
= group
->gr_gid
;
533 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
534 * complement number...)
543 * Check that we have at least one listen/port line; if not, report this
544 * as an error and exit!
547 if (NumListeners
== 0)
553 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
559 cupsdEndProcess(getpid(), 0);
563 * Set the default locale using the language and charset...
566 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
569 * Update all relative filenames to include the full path from ServerRoot...
572 if (DocumentRoot
[0] != '/')
573 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
575 if (RequestRoot
[0] != '/')
576 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
578 if (ServerBin
[0] != '/')
579 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
581 if (StateDir
[0] != '/')
582 SetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
584 if (CacheDir
[0] != '/')
585 SetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
588 if (ServerCertificate
[0] != '/')
589 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
591 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
592 chown(ServerCertificate
, RunUser
, Group
);
593 chmod(ServerCertificate
, ConfigFilePerm
);
595 if (ServerKey
[0] != '/')
596 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
598 chown(ServerKey
, RunUser
, Group
);
599 chmod(ServerKey
, ConfigFilePerm
);
600 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
601 #endif /* HAVE_SSL */
604 * Make sure that directories and config files are owned and
605 * writable by the user and group in the cupsd.conf file...
608 chown(CacheDir
, RunUser
, Group
);
609 chmod(CacheDir
, 0775);
611 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
614 chown(temp
, RunUser
, Group
);
617 chown(StateDir
, RunUser
, Group
);
618 chmod(StateDir
, 0775);
620 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
623 chown(temp
, User
, SystemGroupIDs
[0]);
629 chown(ServerRoot
, RunUser
, Group
);
630 chmod(ServerRoot
, 0755);
632 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
635 chown(temp
, RunUser
, Group
);
638 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
641 chown(temp
, RunUser
, Group
);
644 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
645 chown(temp
, RunUser
, Group
);
646 chmod(temp
, ConfigFilePerm
);
648 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
649 chown(temp
, RunUser
, Group
);
652 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
653 chown(temp
, RunUser
, Group
);
656 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
657 chown(temp
, User
, Group
);
661 * Make sure the request and temporary directories have the right
665 chown(RequestRoot
, RunUser
, Group
);
666 chmod(RequestRoot
, 0710);
668 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
672 * Update ownership and permissions if the CUPS temp directory
673 * is under the spool directory or does not exist...
676 if (access(TempDir
, 0))
677 mkdir(TempDir
, 01770);
679 chown(TempDir
, RunUser
, Group
);
680 chmod(TempDir
, 01770);
683 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
686 * Clean out the temporary directory...
689 cups_dir_t
*dir
; /* Temporary directory */
690 cups_dentry_t
*dent
; /* Directory entry */
691 char tempfile
[1024]; /* Temporary filename */
694 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
696 LogMessage(L_INFO
, "Cleaning out old temporary files in \"%s\"...",
699 while ((dent
= cupsDirRead(dir
)) != NULL
)
701 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
703 if (unlink(tempfile
))
704 LogMessage(L_ERROR
, "Unable to remove temporary file \"%s\" - %s",
705 tempfile
, strerror(errno
));
707 LogMessage(L_DEBUG
, "Removed temporary file \"%s\"...", tempfile
);
713 LogMessage(L_ERROR
, "Unable to open temporary directory \"%s\" - %s",
714 TempDir
, strerror(errno
));
718 * Setup environment variables...
724 * Check the MaxClients setting, and then allocate memory for it...
727 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
730 LogMessage(L_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
733 MaxClients
= MaxFDs
/ 3;
736 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
738 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
739 MaxClients
, strerror(errno
));
743 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
746 * Check the MaxActiveJobs setting; limit to 1/3 the available
747 * file descriptors, since we need a pipe for each job...
750 if (MaxActiveJobs
> (MaxFDs
/ 3))
751 MaxActiveJobs
= MaxFDs
/ 3;
753 if (Classification
&& strcasecmp(Classification
, "none") == 0)
754 ClearString(&Classification
);
757 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
760 * Update the MaxClientsPerHost value, as needed...
763 if (MaxClientsPerHost
<= 0)
764 MaxClientsPerHost
= MaxClients
;
766 if (MaxClientsPerHost
> MaxClients
)
767 MaxClientsPerHost
= MaxClients
;
769 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
773 * Update the default policy, as needed...
777 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
779 DefaultPolicyPtr
= NULL
;
781 if (!DefaultPolicyPtr
)
783 cupsd_policy_t
*p
; /* New policy */
784 location_t
*po
; /* New policy operation */
788 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
790 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
791 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
794 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
796 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
798 LogMessage(L_INFO
, "<Policy default>");
799 LogMessage(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 LogMessage(L_INFO
, "Order Deny,Allow");
807 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
808 po
->order_type
= AUTH_ALLOW
;
809 po
->level
= AUTH_USER
;
811 AddName(po
, "@OWNER");
812 AddName(po
, "@SYSTEM");
813 LogMessage(L_INFO
, "Require user @OWNER @SYSTEM");
815 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
816 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
817 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
818 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
819 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
820 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
821 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
822 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
823 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
824 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
825 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
826 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
827 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
828 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
829 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
830 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
832 LogMessage(L_INFO
, "</Limit>");
834 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
835 "Set-Printer-Attributes Enable-Printer "
836 "Disable-Printer Pause-Printer-After-Current-Job "
837 "Hold-New-Jobs Release-Held-New-Jobs "
838 "Deactivate-Printer Activate-Printer Restart-Printer "
839 "Shutdown-Printer Startup-Printer Promote-Job "
840 "Schedule-Job-After CUPS-Add-Printer "
841 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
842 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
843 LogMessage(L_INFO
, "Order Deny,Allow");
844 LogMessage(L_INFO
, "AuthType Basic");
846 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
847 po
->order_type
= AUTH_ALLOW
;
848 po
->type
= AUTH_BASIC
;
849 po
->level
= AUTH_USER
;
851 AddName(po
, "@SYSTEM");
852 LogMessage(L_INFO
, "Require user @SYSTEM");
854 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
855 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
856 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
857 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
858 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
859 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
860 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
861 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
862 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
863 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
864 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
865 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
866 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
867 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
868 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
869 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
871 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
872 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
873 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
874 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
876 LogMessage(L_INFO
, "</Limit>");
878 LogMessage(L_INFO
, "<Limit All>");
879 LogMessage(L_INFO
, "Order Deny,Allow");
881 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
882 po
->order_type
= AUTH_ALLOW
;
884 LogMessage(L_INFO
, "</Limit>");
885 LogMessage(L_INFO
, "</Policy>");
890 * If we are doing a full reload or the server root has changed, flush
891 * the jobs, printers, etc. and start from scratch...
894 if (NeedReload
== RELOAD_ALL
||
895 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
896 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
898 LogMessage(L_INFO
, "Full reload is required.");
908 DefaultPrinter
= NULL
;
910 if (MimeDatabase
!= NULL
)
911 mimeDelete(MimeDatabase
);
915 for (i
= 0; i
< NumMimeTypes
; i
++)
916 free((void *)MimeTypes
[i
]);
922 * Read the MIME type and conversion database...
925 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
927 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
931 LogMessage(L_EMERG
, "Unable to load MIME database from \'%s\'!",
936 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
937 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
940 * Create a list of MIME types for the document-format-supported
944 NumMimeTypes
= MimeDatabase
->num_types
;
945 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
948 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
950 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
952 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
953 MimeDatabase
->types
[i
]->type
);
955 MimeTypes
[i
] = strdup(type
);
958 if (i
< NumMimeTypes
)
959 MimeTypes
[i
] = strdup("application/octet-stream");
965 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
969 * Load printers and classes...
978 * Load queued jobs...
983 LogMessage(L_INFO
, "Full reload complete.");
989 LogMessage(L_INFO
, "Partial reload complete.");
993 * Reset the reload state...
996 NeedReload
= RELOAD_NONE
;
998 ClearString(&old_serverroot
);
999 ClearString(&old_requestroot
);
1002 * Startup the server and return...
1012 * 'get_address()' - Get an address + port number from a line.
1015 static int /* O - 1 if address good, 0 if bad */
1016 get_address(const char *value
, /* I - Value string */
1017 unsigned defaddress
, /* I - Default address */
1018 int defport
, /* I - Default port */
1019 int deffamily
, /* I - Default family */
1020 http_addr_t
*address
) /* O - Socket address */
1022 char hostname
[256], /* Hostname or IP */
1023 portname
[256], /* Port number or name */
1024 *ptr
; /* Pointer into hostname string */
1025 struct hostent
*host
; /* Host address */
1026 struct servent
*port
; /* Port number */
1030 * Check for an empty value...
1035 LogMessage(L_ERROR
, "Bad (empty) address!");
1040 * Initialize the socket address to the defaults...
1043 memset(address
, 0, sizeof(http_addr_t
));
1046 if (deffamily
== AF_INET6
)
1048 address
->ipv6
.sin6_family
= AF_INET6
;
1049 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1050 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1051 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1052 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1053 address
->ipv6
.sin6_port
= htons(defport
);
1056 #endif /* AF_INET6 */
1058 address
->ipv4
.sin_family
= AF_INET
;
1059 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1060 address
->ipv4
.sin_port
= htons(defport
);
1065 * If the address starts with a "/", it is a domain socket...
1070 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
1072 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
1076 address
->un
.sun_family
= AF_LOCAL
;
1077 strcpy(address
->un
.sun_path
, value
);
1081 #endif /* AF_LOCAL */
1084 * Try to grab a hostname and port number...
1087 strlcpy(hostname
, value
, sizeof(hostname
));
1089 if ((ptr
= strrchr(hostname
, ':')) != NULL
)
1092 * Copy hostname and port separately...
1097 strlcpy(portname
, ptr
, sizeof(portname
));
1099 else if (isdigit(value
[0] & 255))
1106 strlcpy(portname
, value
, sizeof(portname
));
1111 * Hostname by itself...
1118 * Decode the hostname and port number as needed...
1121 if (hostname
[0] && strcmp(hostname
, "*"))
1123 if ((host
= httpGetHostByName(hostname
)) == NULL
)
1125 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
1126 hstrerror(h_errno
));
1130 httpAddrLoad(host
, defport
, 0, address
);
1133 if (portname
[0] != '\0')
1135 if (isdigit(portname
[0] & 255))
1138 if (address
->addr
.sa_family
== AF_INET6
)
1139 address
->ipv6
.sin6_port
= htons(atoi(portname
));
1141 #endif /* AF_INET6 */
1142 address
->ipv4
.sin_port
= htons(atoi(portname
));
1146 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
1148 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
1155 if (address
->addr
.sa_family
== AF_INET6
)
1156 address
->ipv6
.sin6_port
= htons(port
->s_port
);
1158 #endif /* AF_INET6 */
1159 address
->ipv4
.sin_port
= htons(port
->s_port
);
1169 * 'get_addr_and_mask()' - Get an IP address and netmask.
1172 static int /* O - 1 on success, 0 on failure */
1173 get_addr_and_mask(const char *value
, /* I - String from config file */
1174 unsigned *ip
, /* O - Address value */
1175 unsigned *mask
) /* O - Mask value */
1177 int i
, /* Looping var */
1178 family
, /* Address family */
1179 ipcount
; /* Count of fields in address */
1180 const char *maskval
, /* Pointer to start of mask value */
1181 *ptr
; /* Pointer into value */
1182 static unsigned netmasks
[4][4] = /* Standard netmasks... */
1184 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1185 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1186 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1187 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1192 * Get the address...
1195 memset(ip
, 0, sizeof(unsigned) * 4);
1197 if ((maskval
= strchr(value
, '/')) != NULL
)
1200 maskval
= value
+ strlen(value
);
1204 * Check for an IPv6 address...
1210 * Parse hexadecimal IPv6 address...
1215 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 4; i
++)
1219 else if (*ptr
== ':')
1222 ip
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1224 if (*ptr
== ':' || *ptr
== ']')
1230 if (*ptr
&& *ptr
!= '/')
1234 #endif /* AF_INET6 */
1237 * Parse dotted-decimal IPv4 address...
1241 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1243 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1244 ip
[0] = ip
[1] = ip
[2] = 0;
1250 * Get the netmask value(s)...
1253 memset(mask
, 0, sizeof(unsigned) * 4);
1256 if (maskval
[1] == '[')
1259 * Get hexadecimal mask value...
1262 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 4; i
++)
1266 else if (*ptr
== ':')
1269 mask
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1271 if (*ptr
== ':' || *ptr
== ']')
1279 #endif /* AF_INET6 */
1280 if (strchr(maskval
, '.'))
1283 * Get dotted-decimal mask...
1286 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1289 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1290 mask
[0] = mask
[1] = mask
[2] = 0;
1295 * Get address/bits format...
1301 if (family
== AF_INET6
)
1306 mask
[0] = 0xffffffff;
1308 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1311 mask
[1] = 0xffffffff;
1315 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1318 mask
[2] = 0xffffffff;
1322 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1325 mask
[3] = 0xffffffff;
1329 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1332 #endif /* AF_INET6 */
1336 mask
[0] = 0xffffffff;
1337 mask
[1] = 0xffffffff;
1338 mask
[2] = 0xffffffff;
1341 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1343 mask
[3] = 0xffffffff;
1348 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1350 LogMessage(L_DEBUG2
, "get_addr_and_mask(value=\"%s\", "
1351 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1352 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1356 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1359 if ((ip
[0] & ~mask
[0]) != 0 ||
1360 (ip
[1] & ~mask
[1]) != 0 ||
1361 (ip
[2] & ~mask
[2]) != 0 ||
1362 (ip
[3] & ~mask
[3]) != 0)
1370 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1373 static int /* O - 1 on success, 0 on failure */
1374 parse_aaa(location_t
*loc
, /* I - Location */
1375 char *line
, /* I - Line from file */
1376 char *value
, /* I - Start of value data */
1377 int linenum
) /* I - Current line number */
1379 char *valptr
; /* Pointer into value */
1380 unsigned ip
[4], /* IP address components */
1381 mask
[4]; /* IP netmask components */
1384 if (!strcasecmp(line
, "Encryption"))
1387 * "Encryption xxx" - set required encryption level...
1390 if (!strcasecmp(value
, "never"))
1391 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1392 else if (!strcasecmp(value
, "always"))
1394 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1395 "Using \"required\" instead.", value
, linenum
);
1397 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1399 else if (!strcasecmp(value
, "required"))
1400 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1401 else if (!strcasecmp(value
, "ifrequested"))
1402 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1405 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1410 else if (!strcasecmp(line
, "Order"))
1413 * "Order Deny,Allow" or "Order Allow,Deny"...
1416 if (!strncasecmp(value
, "deny", 4))
1417 loc
->order_type
= AUTH_ALLOW
;
1418 else if (!strncasecmp(value
, "allow", 5))
1419 loc
->order_type
= AUTH_DENY
;
1422 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1427 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1430 * Allow [From] host/ip...
1431 * Deny [From] host/ip...
1434 if (!strncasecmp(value
, "from", 4))
1437 * Strip leading "from"...
1442 while (isspace(*value
& 255))
1447 * Figure out what form the allow/deny address takes:
1458 * nnn.nnn.nnn.nnn/mm
1459 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1462 if (!strcasecmp(value
, "all"))
1468 if (!strcasecmp(line
, "Allow"))
1469 AllowIP(loc
, zeros
, zeros
);
1471 DenyIP(loc
, zeros
, zeros
);
1473 else if (!strcasecmp(value
, "none"))
1479 if (!strcasecmp(line
, "Allow"))
1480 AllowIP(loc
, ones
, zeros
);
1482 DenyIP(loc
, ones
, zeros
);
1484 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1487 * Host or domain name...
1490 if (value
[0] == '*')
1493 if (!strcasecmp(line
, "Allow"))
1494 AllowHost(loc
, value
);
1496 DenyHost(loc
, value
);
1501 * One of many IP address forms...
1504 if (!get_addr_and_mask(value
, ip
, mask
))
1506 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1511 if (!strcasecmp(line
, "Allow"))
1512 AllowIP(loc
, ip
, mask
);
1514 DenyIP(loc
, ip
, mask
);
1517 else if (!strcasecmp(line
, "AuthType"))
1520 * AuthType {none,basic,digest,basicdigest}
1523 if (!strcasecmp(value
, "none"))
1525 loc
->type
= AUTH_NONE
;
1526 loc
->level
= AUTH_ANON
;
1528 else if (!strcasecmp(value
, "basic"))
1530 loc
->type
= AUTH_BASIC
;
1532 if (loc
->level
== AUTH_ANON
)
1533 loc
->level
= AUTH_USER
;
1535 else if (!strcasecmp(value
, "digest"))
1537 loc
->type
= AUTH_DIGEST
;
1539 if (loc
->level
== AUTH_ANON
)
1540 loc
->level
= AUTH_USER
;
1542 else if (!strcasecmp(value
, "basicdigest"))
1544 loc
->type
= AUTH_BASICDIGEST
;
1546 if (loc
->level
== AUTH_ANON
)
1547 loc
->level
= AUTH_USER
;
1551 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1556 else if (!strcasecmp(line
, "AuthClass"))
1559 * AuthClass anonymous, user, system, group
1562 if (!strcasecmp(value
, "anonymous"))
1564 loc
->type
= AUTH_NONE
;
1565 loc
->level
= AUTH_ANON
;
1567 else if (!strcasecmp(value
, "user"))
1568 loc
->level
= AUTH_USER
;
1569 else if (!strcasecmp(value
, "group"))
1570 loc
->level
= AUTH_GROUP
;
1571 else if (!strcasecmp(value
, "system"))
1573 loc
->level
= AUTH_GROUP
;
1575 AddName(loc
, "@SYSTEM");
1579 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1584 else if (!strcasecmp(line
, "AuthGroupName"))
1585 AddName(loc
, value
);
1586 else if (!strcasecmp(line
, "Require"))
1589 * Apache synonym for AuthClass and AuthGroupName...
1593 * Require valid-user
1594 * Require group names
1595 * Require user names
1598 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1603 if (!strcasecmp(value
, "valid-user") ||
1604 !strcasecmp(value
, "user"))
1605 loc
->level
= AUTH_USER
;
1606 else if (!strcasecmp(value
, "group"))
1607 loc
->level
= AUTH_GROUP
;
1610 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1616 * Get the list of names from the line...
1619 for (value
= valptr
; *value
;)
1621 while (isspace(*value
& 255))
1624 if (*value
== '\"' || *value
== '\'')
1627 * Grab quoted name...
1630 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1637 * Grab literal name.
1640 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1646 AddName(loc
, value
);
1648 for (value
= valptr
; isspace(*value
& 255); value
++);
1651 else if (!strcasecmp(line
, "Satisfy"))
1653 if (!strcasecmp(value
, "all"))
1654 loc
->satisfy
= AUTH_SATISFY_ALL
;
1655 else if (!strcasecmp(value
, "any"))
1656 loc
->satisfy
= AUTH_SATISFY_ANY
;
1659 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1672 * 'read_configuration()' - Read a configuration file.
1675 static int /* O - 1 on success, 0 on failure */
1676 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1678 int i
; /* Looping var */
1679 int linenum
; /* Current line number */
1680 char line
[HTTP_MAX_BUFFER
], /* Line from file */
1681 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
1682 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
1683 *ptr
, /* Pointer into line/temp */
1684 *value
; /* Pointer to value */
1685 int valuelen
; /* Length of value */
1686 var_t
*var
; /* Current variable */
1687 unsigned ip
[4], /* Address value */
1688 mask
[4]; /* Netmask value */
1689 dirsvc_relay_t
*relay
; /* Relay data */
1690 dirsvc_poll_t
*poll
; /* Polling data */
1691 http_addr_t polladdr
; /* Polling address */
1692 location_t
*location
; /* Browse location */
1693 cups_file_t
*incfile
; /* Include file */
1694 char incname
[1024]; /* Include filename */
1695 struct group
*group
; /* Group */
1699 * Loop through each line in the file...
1704 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1707 * Decode the directive...
1710 if (!strcasecmp(line
, "Include"))
1716 if (value
[0] == '/')
1717 strlcpy(incname
, value
, sizeof(incname
));
1719 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1721 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1722 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
1723 incname
, strerror(errno
));
1726 read_configuration(incfile
);
1727 cupsFileClose(incfile
);
1730 else if (!strcasecmp(line
, "<Location"))
1738 linenum
= read_location(fp
, value
, linenum
);
1744 LogMessage(L_ERROR
, "Syntax error on line %d.",
1749 else if (!strcasecmp(line
, "<Policy"))
1757 linenum
= read_policy(fp
, value
, linenum
);
1763 LogMessage(L_ERROR
, "Syntax error on line %d.",
1768 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1771 * Add a listening address to the list...
1774 listener_t
*lis
; /* New listeners array */
1777 if (NumListeners
== 0)
1778 lis
= malloc(sizeof(listener_t
));
1780 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1784 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1785 line
, linenum
, strerror(errno
));
1790 lis
+= NumListeners
;
1792 memset(lis
, 0, sizeof(listener_t
));
1794 #if defined(AF_INET6) && !defined(__OpenBSD__)
1795 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
, &(lis
->address
)))
1797 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1798 #endif /* AF_INET6 && !__OpenBSD__ */
1800 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1803 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1804 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1805 ntohs(lis
->address
.ipv6
.sin6_port
));
1807 #endif /* AF_INET6 */
1809 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1810 LogMessage(L_INFO
, "Listening to %s (Domain)", temp
);
1812 #endif /* AF_LOCAL */
1813 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1814 ntohs(lis
->address
.ipv4
.sin_port
));
1819 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1823 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1826 * Add a listening address to the list...
1829 listener_t
*lis
; /* New listeners array */
1832 if (NumListeners
== 0)
1833 lis
= malloc(sizeof(listener_t
));
1835 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1839 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1840 line
, linenum
, strerror(errno
));
1845 lis
+= NumListeners
;
1847 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1849 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1852 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1853 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1854 ntohs(lis
->address
.ipv6
.sin6_port
));
1856 #endif /* AF_INET6 */
1857 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1858 ntohs(lis
->address
.ipv4
.sin_port
));
1859 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1863 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1866 #endif /* HAVE_SSL */
1867 else if (!strcasecmp(line
, "BrowseAddress"))
1870 * Add a browse address to the list...
1873 dirsvc_addr_t
*dira
; /* New browse address array */
1876 if (NumBrowsers
== 0)
1877 dira
= malloc(sizeof(dirsvc_addr_t
));
1879 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1883 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1884 linenum
, strerror(errno
));
1889 dira
+= NumBrowsers
;
1891 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1893 if (!strcasecmp(value
, "@LOCAL"))
1896 * Send browse data to all local interfaces...
1899 strcpy(dira
->iface
, "*");
1902 else if (!strncasecmp(value
, "@IF(", 4))
1905 * Send browse data to the named interface...
1908 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1910 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1916 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1918 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1921 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1922 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1923 ntohs(dira
->to
.ipv6
.sin6_port
));
1925 #endif /* AF_INET6 */
1926 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1927 ntohs(dira
->to
.ipv4
.sin_port
));
1932 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1935 else if (!strcasecmp(line
, "BrowseOrder"))
1938 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
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!");
1946 else if (!strncasecmp(value
, "deny", 4))
1947 location
->order_type
= AUTH_ALLOW
;
1948 else if (!strncasecmp(value
, "allow", 5))
1949 location
->order_type
= AUTH_DENY
;
1951 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1954 else if (!strcasecmp(line
, "BrowseProtocols") ||
1955 !strcasecmp(line
, "BrowseLocalProtocols") ||
1956 !strcasecmp(line
, "BrowseRemoteProtocols"))
1959 * "BrowseProtocol name [... name]"
1962 if (strcasecmp(line
, "BrowseLocalProtocols"))
1963 BrowseRemoteProtocols
= 0;
1964 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1965 BrowseLocalProtocols
= 0;
1969 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1970 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1973 if (value
[valuelen
])
1975 value
[valuelen
] = '\0';
1979 if (!strcasecmp(value
, "cups"))
1981 if (strcasecmp(line
, "BrowseLocalProtocols"))
1982 BrowseRemoteProtocols
|= BROWSE_CUPS
;
1983 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1984 BrowseLocalProtocols
|= BROWSE_CUPS
;
1986 else if (!strcasecmp(value
, "slp"))
1988 if (strcasecmp(line
, "BrowseLocalProtocols"))
1989 BrowseRemoteProtocols
|= BROWSE_SLP
;
1990 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1991 BrowseLocalProtocols
|= BROWSE_SLP
;
1993 else if (!strcasecmp(value
, "ldap"))
1995 if (strcasecmp(line
, "BrowseLocalProtocols"))
1996 BrowseRemoteProtocols
|= BROWSE_LDAP
;
1997 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1998 BrowseLocalProtocols
|= BROWSE_LDAP
;
2000 else if (!strcasecmp(value
, "all"))
2002 if (strcasecmp(line
, "BrowseLocalProtocols"))
2003 BrowseRemoteProtocols
|= BROWSE_ALL
;
2004 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2005 BrowseLocalProtocols
|= BROWSE_ALL
;
2009 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
2014 for (value
+= valuelen
; *value
; value
++)
2015 if (!isspace(*value
) || *value
!= ',')
2019 else if (!strcasecmp(line
, "BrowseAllow") ||
2020 !strcasecmp(line
, "BrowseDeny"))
2023 * BrowseAllow [From] host/ip...
2024 * BrowseDeny [From] host/ip...
2027 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2028 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
2030 if (location
== NULL
)
2031 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
2034 if (!strncasecmp(value
, "from ", 5))
2037 * Strip leading "from"...
2042 while (isspace(*value
))
2047 * Figure out what form the allow/deny address takes:
2058 * nnn.nnn.nnn.nnn/mm
2059 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2062 if (!strcasecmp(value
, "all"))
2068 if (!strcasecmp(line
, "BrowseAllow"))
2069 AllowIP(location
, zeros
, zeros
);
2071 DenyIP(location
, zeros
, zeros
);
2073 else if (!strcasecmp(value
, "none"))
2079 if (!strcasecmp(line
, "BrowseAllow"))
2080 AllowIP(location
, ones
, zeros
);
2082 DenyIP(location
, ones
, zeros
);
2084 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2087 * Host or domain name...
2090 if (value
[0] == '*')
2093 if (!strcasecmp(line
, "BrowseAllow"))
2094 AllowHost(location
, value
);
2096 DenyHost(location
, value
);
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 if (!strcasecmp(line
, "BrowseAllow"))
2112 AllowIP(location
, ip
, mask
);
2114 DenyIP(location
, ip
, mask
);
2118 else if (!strcasecmp(line
, "BrowseRelay"))
2121 * BrowseRelay [from] source [to] destination
2125 relay
= malloc(sizeof(dirsvc_relay_t
));
2127 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
2131 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
2132 linenum
, strerror(errno
));
2139 memset(relay
, 0, sizeof(dirsvc_relay_t
));
2141 if (!strncasecmp(value
, "from ", 5))
2144 * Strip leading "from"...
2149 while (isspace(*value
))
2154 * Figure out what form the from address takes:
2163 * nnn.nnn.nnn.nnn/mm
2164 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2167 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2170 * Host or domain name...
2173 if (value
[0] == '*')
2176 strlcpy(temp
, value
, sizeof(temp
));
2177 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2180 relay
->from
.type
= AUTH_NAME
;
2181 relay
->from
.mask
.name
.name
= strdup(temp
);
2182 relay
->from
.mask
.name
.length
= strlen(temp
);
2187 * One of many IP address forms...
2190 if (!get_addr_and_mask(value
, ip
, mask
))
2192 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2197 relay
->from
.type
= AUTH_IP
;
2198 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2199 sizeof(relay
->from
.mask
.ip
.address
));
2200 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2201 sizeof(relay
->from
.mask
.ip
.netmask
));
2205 * Skip value and trailing whitespace...
2208 for (; *value
; value
++)
2209 if (isspace(*value
))
2212 while (isspace(*value
))
2215 if (!strncasecmp(value
, "to ", 3))
2218 * Strip leading "to"...
2223 while (isspace(*value
))
2228 * Get "to" address and port...
2231 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
2233 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2235 if (relay
->from
.type
== AUTH_IP
)
2236 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2237 relay
->from
.mask
.ip
.address
[0],
2238 relay
->from
.mask
.ip
.address
[1],
2239 relay
->from
.mask
.ip
.address
[2],
2240 relay
->from
.mask
.ip
.address
[3],
2241 relay
->from
.mask
.ip
.netmask
[0],
2242 relay
->from
.mask
.ip
.netmask
[1],
2243 relay
->from
.mask
.ip
.netmask
[2],
2244 relay
->from
.mask
.ip
.netmask
[3]);
2246 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2249 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2250 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2251 ntohs(relay
->to
.ipv6
.sin6_port
));
2253 #endif /* AF_INET6 */
2254 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2255 ntohs(relay
->to
.ipv4
.sin_port
));
2261 if (relay
->from
.type
== AUTH_NAME
)
2262 free(relay
->from
.mask
.name
.name
);
2264 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
2267 else if (!strcasecmp(line
, "BrowsePoll"))
2270 * BrowsePoll address[:port]
2274 poll
= malloc(sizeof(dirsvc_poll_t
));
2276 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
2280 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
2281 linenum
, strerror(errno
));
2289 * Get poll address and port...
2292 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
2295 memset(poll
, 0, sizeof(dirsvc_poll_t
));
2297 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
2300 if (polladdr
.addr
.sa_family
== AF_INET6
)
2301 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
2303 #endif /* AF_INET6 */
2304 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
2306 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
2309 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
2311 else if (!strcasecmp(line
, "DefaultAuthType"))
2314 * DefaultAuthType {basic,digest,basicdigest}
2317 if (!strcasecmp(value
, "basic"))
2318 DefaultAuthType
= AUTH_BASIC
;
2319 else if (!strcasecmp(value
, "digest"))
2320 DefaultAuthType
= AUTH_DIGEST
;
2321 else if (!strcasecmp(value
, "basicdigest"))
2322 DefaultAuthType
= AUTH_BASICDIGEST
;
2325 LogMessage(L_WARN
, "Unknown default authorization type %s on line %d.",
2330 else if (!strcasecmp(line
, "User"))
2333 * User ID to run as...
2336 if (isdigit(value
[0]))
2340 struct passwd
*p
; /* Password information */
2343 p
= getpwnam(value
);
2348 LogMessage(L_ERROR
, "Unknown User \"%s\" on line %d, ignoring!",
2352 else if (!strcasecmp(line
, "Group"))
2355 * Group ID to run as...
2358 if (isdigit(value
[0]))
2359 Group
= atoi(value
);
2363 group
= getgrnam(value
);
2366 Group
= group
->gr_gid
;
2368 LogMessage(L_ERROR
, "Unknown Group \"%s\" on line %d, ignoring!",
2372 else if (!strcasecmp(line
, "SystemGroup"))
2375 * System (admin) group(s)...
2378 char *valueptr
, /* Pointer into value */
2379 quote
; /* Quote character */
2382 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2384 if (*value
== '\'' || *value
== '\"')
2387 * Scan quoted name...
2392 for (valueptr
= value
; *valueptr
; valueptr
++)
2393 if (*valueptr
== quote
)
2399 * Scan space or comma-delimited name...
2402 for (valueptr
= value
; *valueptr
; valueptr
++)
2403 if (isspace(*valueptr
) || *valueptr
== ',')
2410 group
= getgrnam(value
);
2413 SetString(SystemGroups
+ i
, value
);
2414 SystemGroupIDs
[i
] = group
->gr_gid
;
2419 LogMessage(L_ERROR
, "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2426 while (*value
== ',' || isspace(*value
))
2431 NumSystemGroups
= i
;
2433 else if (!strcasecmp(line
, "HostNameLookups"))
2436 * Do hostname lookups?
2439 if (!strcasecmp(value
, "off"))
2440 HostNameLookups
= 0;
2441 else if (!strcasecmp(value
, "on"))
2442 HostNameLookups
= 1;
2443 else if (!strcasecmp(value
, "double"))
2444 HostNameLookups
= 2;
2446 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
2449 else if (!strcasecmp(line
, "LogLevel"))
2452 * Amount of logging to do...
2455 if (!strcasecmp(value
, "debug2"))
2456 LogLevel
= L_DEBUG2
;
2457 else if (!strcasecmp(value
, "debug"))
2459 else if (!strcasecmp(value
, "info"))
2461 else if (!strcasecmp(value
, "notice"))
2462 LogLevel
= L_NOTICE
;
2463 else if (!strcasecmp(value
, "warn"))
2465 else if (!strcasecmp(value
, "error"))
2467 else if (!strcasecmp(value
, "crit"))
2469 else if (!strcasecmp(value
, "alert"))
2471 else if (!strcasecmp(value
, "emerg"))
2473 else if (!strcasecmp(value
, "none"))
2476 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
2478 else if (!strcasecmp(line
, "PrintcapFormat"))
2481 * Format of printcap file?
2484 if (!strcasecmp(value
, "bsd"))
2485 PrintcapFormat
= PRINTCAP_BSD
;
2486 else if (!strcasecmp(value
, "solaris"))
2487 PrintcapFormat
= PRINTCAP_SOLARIS
;
2489 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
2492 else if (!strcasecmp(line
, "ServerTokens"))
2495 * Set the string used for the Server header...
2498 struct utsname plat
; /* Platform info */
2503 if (!strcasecmp(value
, "ProductOnly"))
2504 SetString(&ServerHeader
, "CUPS");
2505 else if (!strcasecmp(value
, "Major"))
2506 SetString(&ServerHeader
, "CUPS/1");
2507 else if (!strcasecmp(value
, "Minor"))
2508 SetString(&ServerHeader
, "CUPS/1.1");
2509 else if (!strcasecmp(value
, "Minimal"))
2510 SetString(&ServerHeader
, CUPS_MINIMAL
);
2511 else if (!strcasecmp(value
, "OS"))
2512 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2513 else if (!strcasecmp(value
, "Full"))
2514 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
2515 else if (!strcasecmp(value
, "None"))
2516 ClearString(&ServerHeader
);
2518 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
2523 * Find a simple variable in the list...
2526 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2527 if (!strcasecmp(line
, var
->name
))
2533 * Unknown directive! Output an error message and continue...
2536 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
2546 char *units
; /* Units */
2549 n
= strtol(value
, &units
, 0);
2551 if (units
&& *units
)
2553 if (tolower(units
[0] & 255) == 'g')
2554 n
*= 1024 * 1024 * 1024;
2555 else if (tolower(units
[0] & 255) == 'm')
2557 else if (tolower(units
[0] & 255) == 'k')
2559 else if (tolower(units
[0] & 255) == 't')
2563 *((int *)var
->ptr
) = n
;
2568 if (!strcasecmp(value
, "true") ||
2569 !strcasecmp(value
, "on") ||
2570 !strcasecmp(value
, "enabled") ||
2571 !strcasecmp(value
, "yes") ||
2573 *((int *)var
->ptr
) = TRUE
;
2574 else if (!strcasecmp(value
, "false") ||
2575 !strcasecmp(value
, "off") ||
2576 !strcasecmp(value
, "disabled") ||
2577 !strcasecmp(value
, "no") ||
2578 !strcasecmp(value
, "0"))
2579 *((int *)var
->ptr
) = FALSE
;
2581 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
2586 SetString((char **)var
->ptr
, value
);
2597 * 'read_location()' - Read a <Location path> definition.
2600 static int /* O - New line number or 0 on error */
2601 read_location(cups_file_t
*fp
, /* I - Configuration file */
2602 char *location
, /* I - Location name/path */
2603 int linenum
) /* I - Current line number */
2605 location_t
*loc
, /* New location */
2606 *parent
; /* Parent location */
2607 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2608 *value
, /* Value for directive */
2609 *valptr
; /* Pointer into value */
2612 if ((parent
= AddLocation(location
)) == NULL
)
2615 parent
->limit
= AUTH_LIMIT_ALL
;
2618 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2621 * Decode the directive...
2624 if (!strcasecmp(line
, "</Location>"))
2626 else if (!strcasecmp(line
, "<Limit") ||
2627 !strcasecmp(line
, "<LimitExcept"))
2631 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2635 if ((loc
= CopyLocation(&parent
)) == NULL
)
2641 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2646 if (!strcmp(value
, "ALL"))
2647 loc
->limit
= AUTH_LIMIT_ALL
;
2648 else if (!strcmp(value
, "GET"))
2649 loc
->limit
|= AUTH_LIMIT_GET
;
2650 else if (!strcmp(value
, "HEAD"))
2651 loc
->limit
|= AUTH_LIMIT_HEAD
;
2652 else if (!strcmp(value
, "OPTIONS"))
2653 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2654 else if (!strcmp(value
, "POST"))
2655 loc
->limit
|= AUTH_LIMIT_POST
;
2656 else if (!strcmp(value
, "PUT"))
2657 loc
->limit
|= AUTH_LIMIT_PUT
;
2658 else if (!strcmp(value
, "TRACE"))
2659 loc
->limit
|= AUTH_LIMIT_TRACE
;
2661 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
2664 for (value
= valptr
; isspace(*value
& 255); value
++);
2667 if (!strcasecmp(line
, "<LimitExcept"))
2668 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2670 parent
->limit
&= ~loc
->limit
;
2672 else if (!strcasecmp(line
, "</Limit>"))
2674 else if (!parse_aaa(loc
, line
, value
, linenum
))
2676 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2682 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2690 * 'read_policy()' - Read a <Policy name> definition.
2693 static int /* O - New line number or 0 on error */
2694 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2695 char *policy
, /* I - Location name/path */
2696 int linenum
) /* I - Current line number */
2698 int i
; /* Looping var */
2699 cupsd_policy_t
*pol
; /* Policy */
2700 location_t
*op
; /* Policy operation */
2701 int num_ops
; /* Number of IPP operations */
2702 ipp_op_t ops
[100]; /* Operations */
2703 char line
[HTTP_MAX_BUFFER
],
2705 *value
, /* Value for directive */
2706 *valptr
; /* Pointer into value */
2710 * Create the policy...
2713 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2717 * Read from the file...
2723 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2726 * Decode the directive...
2729 if (!strcasecmp(line
, "</Policy>"))
2732 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2737 else if (!strcasecmp(line
, "<Limit") && !op
)
2741 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2746 * Scan for IPP operation names...
2753 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2758 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2760 if (!strcasecmp(value
, "All"))
2761 ops
[num_ops
] = IPP_ANY_OPERATION
;
2762 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2763 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2769 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2772 for (value
= valptr
; isspace(*value
& 255); value
++);
2776 * If none are specified, apply the policy to all operations...
2781 ops
[0] = IPP_ANY_OPERATION
;
2786 * Add a new policy for the first operation...
2789 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2791 else if (!strcasecmp(line
, "</Limit>") && op
)
2794 * Finish the current operation limit...
2800 * Copy the policy to the other operations...
2803 for (i
= 1; i
< num_ops
; i
++)
2804 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2811 LogMessage(L_ERROR
, "Missing <Limit ops> directive before %s on line %d.",
2815 else if (!parse_aaa(op
, line
, value
, linenum
))
2818 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2821 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2828 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2837 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2838 * required by SSLSetCertificate.
2840 * For now we assumes that there is exactly one SecIdentity in the
2841 * keychain - i.e. there is exactly one matching cert/private key pair.
2842 * In the future we will search a keychain for a SecIdentity matching a
2843 * specific criteria. We also skip the operation of adding additional
2844 * non-signing certs from the keychain to the CFArrayRef.
2846 * To create a self-signed certificate for testing use the certtool.
2847 * Executing the following as root will do it:
2849 * certtool c c v k=CUPS
2853 CDSAGetServerCerts(void)
2855 OSStatus err
; /* Error info */
2856 SecKeychainRef kcRef
; /* Keychain reference */
2857 SecIdentitySearchRef srchRef
; /* Search reference */
2858 SecIdentityRef identity
; /* Identity */
2859 CFArrayRef ca
; /* Certificate array */
2866 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2869 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2870 ServerCertificate
, err
);
2874 * Search for "any" identity matching specified key use;
2875 * in this app, we expect there to be exactly one.
2878 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2882 "Cannot find signing key in keychain \"%s\", error %d",
2883 ServerCertificate
, err
);
2886 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2890 "Cannot find signing key in keychain \"%s\", error %d",
2891 ServerCertificate
, err
);
2894 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2895 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2899 * Found one. Place it in a CFArray.
2900 * TBD: snag other (non-identity) certs from keychain and add them
2904 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2907 LogMessage(L_ERROR
, "CFArrayCreate error");
2910 /*CFRelease(identity);*/
2913 /*CFRelease(srchRef);*/
2916 /*CFRelease(kcRef);*/
2921 #endif /* HAVE_CDSASSL */