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
, RunUser
, SystemGroupIDs
[0]);
626 chown(ServerRoot
, RunUser
, Group
);
627 chmod(ServerRoot
, 0755);
629 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
632 chown(temp
, RunUser
, Group
);
635 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
638 chown(temp
, RunUser
, Group
);
641 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
642 chown(temp
, RunUser
, Group
);
643 chmod(temp
, ConfigFilePerm
);
645 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
646 chown(temp
, RunUser
, Group
);
649 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
650 chown(temp
, RunUser
, Group
);
653 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
654 chown(temp
, User
, Group
);
658 * Make sure the request and temporary directories have the right
662 chown(RequestRoot
, RunUser
, Group
);
663 chmod(RequestRoot
, 0710);
665 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
669 * Update ownership and permissions if the CUPS temp directory
670 * is under the spool directory or does not exist...
673 if (access(TempDir
, 0))
674 mkdir(TempDir
, 01770);
676 chown(TempDir
, RunUser
, Group
);
677 chmod(TempDir
, 01770);
680 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
683 * Clean out the temporary directory...
686 cups_dir_t
*dir
; /* Temporary directory */
687 cups_dentry_t
*dent
; /* Directory entry */
688 char tempfile
[1024]; /* Temporary filename */
691 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
693 LogMessage(L_INFO
, "Cleaning out old temporary files in \"%s\"...",
696 while ((dent
= cupsDirRead(dir
)) != NULL
)
698 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
700 if (unlink(tempfile
))
701 LogMessage(L_ERROR
, "Unable to remove temporary file \"%s\" - %s",
702 tempfile
, strerror(errno
));
704 LogMessage(L_DEBUG
, "Removed temporary file \"%s\"...", tempfile
);
710 LogMessage(L_ERROR
, "Unable to open temporary directory \"%s\" - %s",
711 TempDir
, strerror(errno
));
715 * Setup environment variables...
721 * Check the MaxClients setting, and then allocate memory for it...
724 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
727 LogMessage(L_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
730 MaxClients
= MaxFDs
/ 3;
733 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
735 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
736 MaxClients
, strerror(errno
));
740 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
743 * Check the MaxActiveJobs setting; limit to 1/3 the available
744 * file descriptors, since we need a pipe for each job...
747 if (MaxActiveJobs
> (MaxFDs
/ 3))
748 MaxActiveJobs
= MaxFDs
/ 3;
750 if (Classification
&& strcasecmp(Classification
, "none") == 0)
751 ClearString(&Classification
);
754 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
757 * Update the MaxClientsPerHost value, as needed...
760 if (MaxClientsPerHost
<= 0)
761 MaxClientsPerHost
= MaxClients
;
763 if (MaxClientsPerHost
> MaxClients
)
764 MaxClientsPerHost
= MaxClients
;
766 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
770 * Update the default policy, as needed...
774 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
776 DefaultPolicyPtr
= NULL
;
778 if (!DefaultPolicyPtr
)
780 cupsd_policy_t
*p
; /* New policy */
781 location_t
*po
; /* New policy operation */
785 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
787 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
788 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
791 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
793 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
795 LogMessage(L_INFO
, "<Policy default>");
796 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
797 "Release-Job Restart-Job Purge-Jobs "
798 "Set-Job-Attributes Create-Job-Subscription "
799 "Renew-Subscription Cancel-Subscription "
800 "Get-Notifications Reprocess-Job Cancel-Current-Job "
801 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
802 LogMessage(L_INFO
, "Order Deny,Allow");
804 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
805 po
->order_type
= AUTH_ALLOW
;
806 po
->level
= AUTH_USER
;
808 AddName(po
, "@OWNER");
809 AddName(po
, "@SYSTEM");
810 LogMessage(L_INFO
, "Require user @OWNER @SYSTEM");
812 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
813 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
814 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
815 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
816 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
817 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
818 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
819 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
820 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
821 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
822 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
823 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
824 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
825 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
826 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
827 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
829 LogMessage(L_INFO
, "</Limit>");
831 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
832 "Set-Printer-Attributes Enable-Printer "
833 "Disable-Printer Pause-Printer-After-Current-Job "
834 "Hold-New-Jobs Release-Held-New-Jobs "
835 "Deactivate-Printer Activate-Printer Restart-Printer "
836 "Shutdown-Printer Startup-Printer Promote-Job "
837 "Schedule-Job-After CUPS-Add-Printer "
838 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
839 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
840 LogMessage(L_INFO
, "Order Deny,Allow");
841 LogMessage(L_INFO
, "AuthType Basic");
843 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
844 po
->order_type
= AUTH_ALLOW
;
845 po
->type
= AUTH_BASIC
;
846 po
->level
= AUTH_USER
;
848 AddName(po
, "@SYSTEM");
849 LogMessage(L_INFO
, "Require user @SYSTEM");
851 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
852 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
853 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
854 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
855 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
856 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
857 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
858 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
859 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
860 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
861 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
862 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
863 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
864 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
865 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
866 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
867 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
868 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
869 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
870 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
871 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
873 LogMessage(L_INFO
, "</Limit>");
875 LogMessage(L_INFO
, "<Limit All>");
876 LogMessage(L_INFO
, "Order Deny,Allow");
878 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
879 po
->order_type
= AUTH_ALLOW
;
881 LogMessage(L_INFO
, "</Limit>");
882 LogMessage(L_INFO
, "</Policy>");
887 * If we are doing a full reload or the server root has changed, flush
888 * the jobs, printers, etc. and start from scratch...
891 if (NeedReload
== RELOAD_ALL
||
892 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
893 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
895 LogMessage(L_INFO
, "Full reload is required.");
905 DefaultPrinter
= NULL
;
907 if (MimeDatabase
!= NULL
)
908 mimeDelete(MimeDatabase
);
912 for (i
= 0; i
< NumMimeTypes
; i
++)
913 free((void *)MimeTypes
[i
]);
919 * Read the MIME type and conversion database...
922 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
924 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
926 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
927 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
930 * Create a list of MIME types for the document-format-supported
934 NumMimeTypes
= MimeDatabase
->num_types
;
935 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
938 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
940 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
942 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
943 MimeDatabase
->types
[i
]->type
);
945 MimeTypes
[i
] = strdup(type
);
948 if (i
< NumMimeTypes
)
949 MimeTypes
[i
] = strdup("application/octet-stream");
955 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
959 * Load printers and classes...
968 * Load queued jobs...
973 LogMessage(L_INFO
, "Full reload complete.");
979 LogMessage(L_INFO
, "Partial reload complete.");
983 * Reset the reload state...
986 NeedReload
= RELOAD_NONE
;
988 ClearString(&old_serverroot
);
989 ClearString(&old_requestroot
);
992 * Startup the server and return...
1002 * 'get_address()' - Get an address + port number from a line.
1005 static int /* O - 1 if address good, 0 if bad */
1006 get_address(const char *value
, /* I - Value string */
1007 unsigned defaddress
, /* I - Default address */
1008 int defport
, /* I - Default port */
1009 int deffamily
, /* I - Default family */
1010 http_addr_t
*address
) /* O - Socket address */
1012 char hostname
[256], /* Hostname or IP */
1013 portname
[256], /* Port number or name */
1014 *ptr
; /* Pointer into hostname string */
1015 struct hostent
*host
; /* Host address */
1016 struct servent
*port
; /* Port number */
1020 * Check for an empty value...
1025 LogMessage(L_ERROR
, "Bad (empty) address!");
1030 * Initialize the socket address to the defaults...
1033 memset(address
, 0, sizeof(http_addr_t
));
1036 if (deffamily
== AF_INET6
)
1038 address
->ipv6
.sin6_family
= AF_INET6
;
1039 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1040 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1041 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1042 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1043 address
->ipv6
.sin6_port
= htons(defport
);
1046 #endif /* AF_INET6 */
1048 address
->ipv4
.sin_family
= AF_INET
;
1049 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1050 address
->ipv4
.sin_port
= htons(defport
);
1055 * If the address starts with a "/", it is a domain socket...
1060 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
1062 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
1066 address
->un
.sun_family
= AF_LOCAL
;
1067 strcpy(address
->un
.sun_path
, value
);
1071 #endif /* AF_LOCAL */
1074 * Try to grab a hostname and port number...
1077 strlcpy(hostname
, value
, sizeof(hostname
));
1079 if ((ptr
= strrchr(hostname
, ':')) != NULL
)
1082 * Copy hostname and port separately...
1087 strlcpy(portname
, ptr
, sizeof(portname
));
1089 else if (isdigit(value
[0] & 255))
1096 strlcpy(portname
, value
, sizeof(portname
));
1101 * Hostname by itself...
1108 * Decode the hostname and port number as needed...
1111 if (hostname
[0] && strcmp(hostname
, "*"))
1113 if ((host
= httpGetHostByName(hostname
)) == NULL
)
1115 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
1116 hstrerror(h_errno
));
1120 httpAddrLoad(host
, defport
, 0, address
);
1123 if (portname
[0] != '\0')
1125 if (isdigit(portname
[0] & 255))
1128 if (address
->addr
.sa_family
== AF_INET6
)
1129 address
->ipv6
.sin6_port
= htons(atoi(portname
));
1131 #endif /* AF_INET6 */
1132 address
->ipv4
.sin_port
= htons(atoi(portname
));
1136 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
1138 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
1145 if (address
->addr
.sa_family
== AF_INET6
)
1146 address
->ipv6
.sin6_port
= htons(port
->s_port
);
1148 #endif /* AF_INET6 */
1149 address
->ipv4
.sin_port
= htons(port
->s_port
);
1159 * 'get_addr_and_mask()' - Get an IP address and netmask.
1162 static int /* O - 1 on success, 0 on failure */
1163 get_addr_and_mask(const char *value
, /* I - String from config file */
1164 unsigned *ip
, /* O - Address value */
1165 unsigned *mask
) /* O - Mask value */
1167 int i
, /* Looping var */
1168 family
, /* Address family */
1169 ipcount
; /* Count of fields in address */
1170 const char *maskval
, /* Pointer to start of mask value */
1171 *ptr
; /* Pointer into value */
1172 static unsigned netmasks
[4][4] = /* Standard netmasks... */
1174 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1175 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1176 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1177 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1182 * Get the address...
1185 memset(ip
, 0, sizeof(unsigned) * 4);
1187 if ((maskval
= strchr(value
, '/')) != NULL
)
1190 maskval
= value
+ strlen(value
);
1194 * Check for an IPv6 address...
1200 * Parse hexadecimal IPv6 address...
1205 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 4; i
++)
1209 else if (*ptr
== ':')
1212 ip
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1214 if (*ptr
== ':' || *ptr
== ']')
1220 if (*ptr
&& *ptr
!= '/')
1224 #endif /* AF_INET6 */
1227 * Parse dotted-decimal IPv4 address...
1231 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1233 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1234 ip
[0] = ip
[1] = ip
[2] = 0;
1240 * Get the netmask value(s)...
1243 memset(mask
, 0, sizeof(unsigned) * 4);
1246 if (maskval
[1] == '[')
1249 * Get hexadecimal mask value...
1252 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 4; i
++)
1256 else if (*ptr
== ':')
1259 mask
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1261 if (*ptr
== ':' || *ptr
== ']')
1269 #endif /* AF_INET6 */
1270 if (strchr(maskval
, '.'))
1273 * Get dotted-decimal mask...
1276 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1279 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1280 mask
[0] = mask
[1] = mask
[2] = 0;
1285 * Get address/bits format...
1291 if (family
== AF_INET6
)
1296 mask
[0] = 0xffffffff;
1298 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1301 mask
[1] = 0xffffffff;
1305 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1308 mask
[2] = 0xffffffff;
1312 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1315 mask
[3] = 0xffffffff;
1319 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1322 #endif /* AF_INET6 */
1326 mask
[0] = 0xffffffff;
1327 mask
[1] = 0xffffffff;
1328 mask
[2] = 0xffffffff;
1331 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1333 mask
[3] = 0xffffffff;
1338 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1340 LogMessage(L_DEBUG2
, "get_addr_and_mask(value=\"%s\", "
1341 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1342 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1346 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1349 if ((ip
[0] & ~mask
[0]) != 0 ||
1350 (ip
[1] & ~mask
[1]) != 0 ||
1351 (ip
[2] & ~mask
[2]) != 0 ||
1352 (ip
[3] & ~mask
[3]) != 0)
1360 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1363 static int /* O - 1 on success, 0 on failure */
1364 parse_aaa(location_t
*loc
, /* I - Location */
1365 char *line
, /* I - Line from file */
1366 char *value
, /* I - Start of value data */
1367 int linenum
) /* I - Current line number */
1369 char *valptr
; /* Pointer into value */
1370 unsigned ip
[4], /* IP address components */
1371 mask
[4]; /* IP netmask components */
1374 if (!strcasecmp(line
, "Encryption"))
1377 * "Encryption xxx" - set required encryption level...
1380 if (!strcasecmp(value
, "never"))
1381 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1382 else if (!strcasecmp(value
, "always"))
1384 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1385 "Using \"required\" instead.", value
, linenum
);
1387 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1389 else if (!strcasecmp(value
, "required"))
1390 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1391 else if (!strcasecmp(value
, "ifrequested"))
1392 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1395 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1400 else if (!strcasecmp(line
, "Order"))
1403 * "Order Deny,Allow" or "Order Allow,Deny"...
1406 if (!strncasecmp(value
, "deny", 4))
1407 loc
->order_type
= AUTH_ALLOW
;
1408 else if (!strncasecmp(value
, "allow", 5))
1409 loc
->order_type
= AUTH_DENY
;
1412 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1417 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1420 * Allow [From] host/ip...
1421 * Deny [From] host/ip...
1424 if (!strncasecmp(value
, "from", 4))
1427 * Strip leading "from"...
1432 while (isspace(*value
& 255))
1437 * Figure out what form the allow/deny address takes:
1448 * nnn.nnn.nnn.nnn/mm
1449 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1452 if (!strcasecmp(value
, "all"))
1458 if (!strcasecmp(line
, "Allow"))
1459 AllowIP(loc
, zeros
, zeros
);
1461 DenyIP(loc
, zeros
, zeros
);
1463 else if (!strcasecmp(value
, "none"))
1469 if (!strcasecmp(line
, "Allow"))
1470 AllowIP(loc
, ones
, zeros
);
1472 DenyIP(loc
, ones
, zeros
);
1474 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1477 * Host or domain name...
1480 if (value
[0] == '*')
1483 if (!strcasecmp(line
, "Allow"))
1484 AllowHost(loc
, value
);
1486 DenyHost(loc
, value
);
1491 * One of many IP address forms...
1494 if (!get_addr_and_mask(value
, ip
, mask
))
1496 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1501 if (!strcasecmp(line
, "Allow"))
1502 AllowIP(loc
, ip
, mask
);
1504 DenyIP(loc
, ip
, mask
);
1507 else if (!strcasecmp(line
, "AuthType"))
1510 * AuthType {none,basic,digest,basicdigest}
1513 if (!strcasecmp(value
, "none"))
1515 loc
->type
= AUTH_NONE
;
1516 loc
->level
= AUTH_ANON
;
1518 else if (!strcasecmp(value
, "basic"))
1520 loc
->type
= AUTH_BASIC
;
1522 if (loc
->level
== AUTH_ANON
)
1523 loc
->level
= AUTH_USER
;
1525 else if (!strcasecmp(value
, "digest"))
1527 loc
->type
= AUTH_DIGEST
;
1529 if (loc
->level
== AUTH_ANON
)
1530 loc
->level
= AUTH_USER
;
1532 else if (!strcasecmp(value
, "basicdigest"))
1534 loc
->type
= AUTH_BASICDIGEST
;
1536 if (loc
->level
== AUTH_ANON
)
1537 loc
->level
= AUTH_USER
;
1541 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1546 else if (!strcasecmp(line
, "AuthClass"))
1549 * AuthClass anonymous, user, system, group
1552 if (!strcasecmp(value
, "anonymous"))
1554 loc
->type
= AUTH_NONE
;
1555 loc
->level
= AUTH_ANON
;
1557 else if (!strcasecmp(value
, "user"))
1558 loc
->level
= AUTH_USER
;
1559 else if (!strcasecmp(value
, "group"))
1560 loc
->level
= AUTH_GROUP
;
1561 else if (!strcasecmp(value
, "system"))
1563 loc
->level
= AUTH_GROUP
;
1565 AddName(loc
, "@SYSTEM");
1569 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1574 else if (!strcasecmp(line
, "AuthGroupName"))
1575 AddName(loc
, value
);
1576 else if (!strcasecmp(line
, "Require"))
1579 * Apache synonym for AuthClass and AuthGroupName...
1583 * Require valid-user
1584 * Require group names
1585 * Require user names
1588 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1593 if (!strcasecmp(value
, "valid-user") ||
1594 !strcasecmp(value
, "user"))
1595 loc
->level
= AUTH_USER
;
1596 else if (!strcasecmp(value
, "group"))
1597 loc
->level
= AUTH_GROUP
;
1600 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
1606 * Get the list of names from the line...
1609 for (value
= valptr
; *value
;)
1611 while (isspace(*value
& 255))
1614 if (*value
== '\"' || *value
== '\'')
1617 * Grab quoted name...
1620 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1627 * Grab literal name.
1630 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1636 AddName(loc
, value
);
1638 for (value
= valptr
; isspace(*value
& 255); value
++);
1641 else if (!strcasecmp(line
, "Satisfy"))
1643 if (!strcasecmp(value
, "all"))
1644 loc
->satisfy
= AUTH_SATISFY_ALL
;
1645 else if (!strcasecmp(value
, "any"))
1646 loc
->satisfy
= AUTH_SATISFY_ANY
;
1649 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
1662 * 'read_configuration()' - Read a configuration file.
1665 static int /* O - 1 on success, 0 on failure */
1666 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1668 int i
; /* Looping var */
1669 int linenum
; /* Current line number */
1670 char line
[HTTP_MAX_BUFFER
], /* Line from file */
1671 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
1672 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
1673 *ptr
, /* Pointer into line/temp */
1674 *value
; /* Pointer to value */
1675 int valuelen
; /* Length of value */
1676 var_t
*var
; /* Current variable */
1677 unsigned ip
[4], /* Address value */
1678 mask
[4]; /* Netmask value */
1679 dirsvc_relay_t
*relay
; /* Relay data */
1680 dirsvc_poll_t
*poll
; /* Polling data */
1681 http_addr_t polladdr
; /* Polling address */
1682 location_t
*location
; /* Browse location */
1683 cups_file_t
*incfile
; /* Include file */
1684 char incname
[1024]; /* Include filename */
1685 struct group
*group
; /* Group */
1689 * Loop through each line in the file...
1694 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1697 * Decode the directive...
1700 if (!strcasecmp(line
, "Include"))
1706 if (value
[0] == '/')
1707 strlcpy(incname
, value
, sizeof(incname
));
1709 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1711 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1712 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
1713 incname
, strerror(errno
));
1716 read_configuration(incfile
);
1717 cupsFileClose(incfile
);
1720 else if (!strcasecmp(line
, "<Location"))
1728 linenum
= read_location(fp
, value
, linenum
);
1734 LogMessage(L_ERROR
, "Syntax error on line %d.",
1739 else if (!strcasecmp(line
, "<Policy"))
1747 linenum
= read_policy(fp
, value
, linenum
);
1753 LogMessage(L_ERROR
, "Syntax error on line %d.",
1758 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1761 * Add a listening address to the list...
1764 listener_t
*lis
; /* New listeners array */
1767 if (NumListeners
== 0)
1768 lis
= malloc(sizeof(listener_t
));
1770 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1774 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1775 line
, linenum
, strerror(errno
));
1780 lis
+= NumListeners
;
1782 memset(lis
, 0, sizeof(listener_t
));
1784 #if defined(AF_INET6) && !defined(__OpenBSD__)
1785 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
, &(lis
->address
)))
1787 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1788 #endif /* AF_INET6 && !__OpenBSD__ */
1790 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1793 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1794 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1795 ntohs(lis
->address
.ipv6
.sin6_port
));
1797 #endif /* AF_INET6 */
1799 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1800 LogMessage(L_INFO
, "Listening to %s (Domain)", temp
);
1802 #endif /* AF_LOCAL */
1803 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1804 ntohs(lis
->address
.ipv4
.sin_port
));
1809 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1813 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1816 * Add a listening address to the list...
1819 listener_t
*lis
; /* New listeners array */
1822 if (NumListeners
== 0)
1823 lis
= malloc(sizeof(listener_t
));
1825 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1829 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1830 line
, linenum
, strerror(errno
));
1835 lis
+= NumListeners
;
1837 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1839 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1842 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1843 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1844 ntohs(lis
->address
.ipv6
.sin6_port
));
1846 #endif /* AF_INET6 */
1847 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1848 ntohs(lis
->address
.ipv4
.sin_port
));
1849 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1853 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1856 #endif /* HAVE_SSL */
1857 else if (!strcasecmp(line
, "BrowseAddress"))
1860 * Add a browse address to the list...
1863 dirsvc_addr_t
*dira
; /* New browse address array */
1866 if (NumBrowsers
== 0)
1867 dira
= malloc(sizeof(dirsvc_addr_t
));
1869 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1873 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1874 linenum
, strerror(errno
));
1879 dira
+= NumBrowsers
;
1881 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1883 if (!strcasecmp(value
, "@LOCAL"))
1886 * Send browse data to all local interfaces...
1889 strcpy(dira
->iface
, "*");
1892 else if (!strncasecmp(value
, "@IF(", 4))
1895 * Send browse data to the named interface...
1898 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1900 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1906 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1908 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1911 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1912 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1913 ntohs(dira
->to
.ipv6
.sin6_port
));
1915 #endif /* AF_INET6 */
1916 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1917 ntohs(dira
->to
.ipv4
.sin_port
));
1922 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1925 else if (!strcasecmp(line
, "BrowseOrder"))
1928 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1931 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1932 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1934 if (location
== NULL
)
1935 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1936 else if (!strncasecmp(value
, "deny", 4))
1937 location
->order_type
= AUTH_ALLOW
;
1938 else if (!strncasecmp(value
, "allow", 5))
1939 location
->order_type
= AUTH_DENY
;
1941 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1944 else if (!strcasecmp(line
, "BrowseProtocols") ||
1945 !strcasecmp(line
, "BrowseLocalProtocols") ||
1946 !strcasecmp(line
, "BrowseRemoteProtocols"))
1949 * "BrowseProtocol name [... name]"
1952 if (strcasecmp(line
, "BrowseLocalProtocols"))
1953 BrowseRemoteProtocols
= 0;
1954 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1955 BrowseLocalProtocols
= 0;
1959 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1960 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1963 if (value
[valuelen
])
1965 value
[valuelen
] = '\0';
1969 if (!strcasecmp(value
, "cups"))
1971 if (strcasecmp(line
, "BrowseLocalProtocols"))
1972 BrowseRemoteProtocols
|= BROWSE_CUPS
;
1973 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1974 BrowseLocalProtocols
|= BROWSE_CUPS
;
1976 else if (!strcasecmp(value
, "slp"))
1978 if (strcasecmp(line
, "BrowseLocalProtocols"))
1979 BrowseRemoteProtocols
|= BROWSE_SLP
;
1980 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1981 BrowseLocalProtocols
|= BROWSE_SLP
;
1983 else if (!strcasecmp(value
, "ldap"))
1985 if (strcasecmp(line
, "BrowseLocalProtocols"))
1986 BrowseRemoteProtocols
|= BROWSE_LDAP
;
1987 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1988 BrowseLocalProtocols
|= BROWSE_LDAP
;
1990 else if (!strcasecmp(value
, "all"))
1992 if (strcasecmp(line
, "BrowseLocalProtocols"))
1993 BrowseRemoteProtocols
|= BROWSE_ALL
;
1994 if (strcasecmp(line
, "BrowseRemoteProtocols"))
1995 BrowseLocalProtocols
|= BROWSE_ALL
;
1999 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
2004 for (value
+= valuelen
; *value
; value
++)
2005 if (!isspace(*value
) || *value
!= ',')
2009 else if (!strcasecmp(line
, "BrowseAllow") ||
2010 !strcasecmp(line
, "BrowseDeny"))
2013 * BrowseAllow [From] host/ip...
2014 * BrowseDeny [From] host/ip...
2017 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2018 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
2020 if (location
== NULL
)
2021 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
2024 if (!strncasecmp(value
, "from ", 5))
2027 * Strip leading "from"...
2032 while (isspace(*value
))
2037 * Figure out what form the allow/deny address takes:
2048 * nnn.nnn.nnn.nnn/mm
2049 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2052 if (!strcasecmp(value
, "all"))
2058 if (!strcasecmp(line
, "BrowseAllow"))
2059 AllowIP(location
, zeros
, zeros
);
2061 DenyIP(location
, zeros
, zeros
);
2063 else if (!strcasecmp(value
, "none"))
2069 if (!strcasecmp(line
, "BrowseAllow"))
2070 AllowIP(location
, ones
, zeros
);
2072 DenyIP(location
, ones
, zeros
);
2074 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2077 * Host or domain name...
2080 if (value
[0] == '*')
2083 if (!strcasecmp(line
, "BrowseAllow"))
2084 AllowHost(location
, value
);
2086 DenyHost(location
, value
);
2091 * One of many IP address forms...
2094 if (!get_addr_and_mask(value
, ip
, mask
))
2096 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2101 if (!strcasecmp(line
, "BrowseAllow"))
2102 AllowIP(location
, ip
, mask
);
2104 DenyIP(location
, ip
, mask
);
2108 else if (!strcasecmp(line
, "BrowseRelay"))
2111 * BrowseRelay [from] source [to] destination
2115 relay
= malloc(sizeof(dirsvc_relay_t
));
2117 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
2121 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
2122 linenum
, strerror(errno
));
2129 memset(relay
, 0, sizeof(dirsvc_relay_t
));
2131 if (!strncasecmp(value
, "from ", 5))
2134 * Strip leading "from"...
2139 while (isspace(*value
))
2144 * Figure out what form the from address takes:
2153 * nnn.nnn.nnn.nnn/mm
2154 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2157 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2160 * Host or domain name...
2163 if (value
[0] == '*')
2166 strlcpy(temp
, value
, sizeof(temp
));
2167 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2170 relay
->from
.type
= AUTH_NAME
;
2171 relay
->from
.mask
.name
.name
= strdup(temp
);
2172 relay
->from
.mask
.name
.length
= strlen(temp
);
2177 * One of many IP address forms...
2180 if (!get_addr_and_mask(value
, ip
, mask
))
2182 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2187 relay
->from
.type
= AUTH_IP
;
2188 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2189 sizeof(relay
->from
.mask
.ip
.address
));
2190 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2191 sizeof(relay
->from
.mask
.ip
.netmask
));
2195 * Skip value and trailing whitespace...
2198 for (; *value
; value
++)
2199 if (isspace(*value
))
2202 while (isspace(*value
))
2205 if (!strncasecmp(value
, "to ", 3))
2208 * Strip leading "to"...
2213 while (isspace(*value
))
2218 * Get "to" address and port...
2221 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
2223 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2225 if (relay
->from
.type
== AUTH_IP
)
2226 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2227 relay
->from
.mask
.ip
.address
[0],
2228 relay
->from
.mask
.ip
.address
[1],
2229 relay
->from
.mask
.ip
.address
[2],
2230 relay
->from
.mask
.ip
.address
[3],
2231 relay
->from
.mask
.ip
.netmask
[0],
2232 relay
->from
.mask
.ip
.netmask
[1],
2233 relay
->from
.mask
.ip
.netmask
[2],
2234 relay
->from
.mask
.ip
.netmask
[3]);
2236 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2239 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2240 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2241 ntohs(relay
->to
.ipv6
.sin6_port
));
2243 #endif /* AF_INET6 */
2244 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
2245 ntohs(relay
->to
.ipv4
.sin_port
));
2251 if (relay
->from
.type
== AUTH_NAME
)
2252 free(relay
->from
.mask
.name
.name
);
2254 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
2257 else if (!strcasecmp(line
, "BrowsePoll"))
2260 * BrowsePoll address[:port]
2264 poll
= malloc(sizeof(dirsvc_poll_t
));
2266 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
2270 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
2271 linenum
, strerror(errno
));
2279 * Get poll address and port...
2282 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
2285 memset(poll
, 0, sizeof(dirsvc_poll_t
));
2287 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
2290 if (polladdr
.addr
.sa_family
== AF_INET6
)
2291 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
2293 #endif /* AF_INET6 */
2294 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
2296 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
2299 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
2301 else if (!strcasecmp(line
, "DefaultAuthType"))
2304 * DefaultAuthType {basic,digest,basicdigest}
2307 if (!strcasecmp(value
, "basic"))
2308 DefaultAuthType
= AUTH_BASIC
;
2309 else if (!strcasecmp(value
, "digest"))
2310 DefaultAuthType
= AUTH_DIGEST
;
2311 else if (!strcasecmp(value
, "basicdigest"))
2312 DefaultAuthType
= AUTH_BASICDIGEST
;
2315 LogMessage(L_WARN
, "Unknown default authorization type %s on line %d.",
2320 else if (!strcasecmp(line
, "User"))
2323 * User ID to run as...
2326 if (isdigit(value
[0]))
2330 struct passwd
*p
; /* Password information */
2333 p
= getpwnam(value
);
2338 LogMessage(L_ERROR
, "Unknown User \"%s\" on line %d, ignoring!",
2342 else if (!strcasecmp(line
, "Group"))
2345 * Group ID to run as...
2348 if (isdigit(value
[0]))
2349 Group
= atoi(value
);
2353 group
= getgrnam(value
);
2356 Group
= group
->gr_gid
;
2358 LogMessage(L_ERROR
, "Unknown Group \"%s\" on line %d, ignoring!",
2362 else if (!strcasecmp(line
, "SystemGroup"))
2365 * System (admin) group(s)...
2368 char *valueptr
, /* Pointer into value */
2369 quote
; /* Quote character */
2372 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2374 if (*value
== '\'' || *value
== '\"')
2377 * Scan quoted name...
2382 for (valueptr
= value
; *valueptr
; valueptr
++)
2383 if (*valueptr
== quote
)
2389 * Scan space or comma-delimited name...
2392 for (valueptr
= value
; *valueptr
; valueptr
++)
2393 if (isspace(*valueptr
) || *valueptr
== ',')
2400 group
= getgrnam(value
);
2403 SetString(SystemGroups
+ i
, value
);
2404 SystemGroupIDs
[i
] = group
->gr_gid
;
2409 LogMessage(L_ERROR
, "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2416 while (*value
== ',' || isspace(*value
))
2421 NumSystemGroups
= i
;
2423 else if (!strcasecmp(line
, "HostNameLookups"))
2426 * Do hostname lookups?
2429 if (!strcasecmp(value
, "off"))
2430 HostNameLookups
= 0;
2431 else if (!strcasecmp(value
, "on"))
2432 HostNameLookups
= 1;
2433 else if (!strcasecmp(value
, "double"))
2434 HostNameLookups
= 2;
2436 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
2439 else if (!strcasecmp(line
, "LogLevel"))
2442 * Amount of logging to do...
2445 if (!strcasecmp(value
, "debug2"))
2446 LogLevel
= L_DEBUG2
;
2447 else if (!strcasecmp(value
, "debug"))
2449 else if (!strcasecmp(value
, "info"))
2451 else if (!strcasecmp(value
, "notice"))
2452 LogLevel
= L_NOTICE
;
2453 else if (!strcasecmp(value
, "warn"))
2455 else if (!strcasecmp(value
, "error"))
2457 else if (!strcasecmp(value
, "crit"))
2459 else if (!strcasecmp(value
, "alert"))
2461 else if (!strcasecmp(value
, "emerg"))
2463 else if (!strcasecmp(value
, "none"))
2466 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
2468 else if (!strcasecmp(line
, "PrintcapFormat"))
2471 * Format of printcap file?
2474 if (!strcasecmp(value
, "bsd"))
2475 PrintcapFormat
= PRINTCAP_BSD
;
2476 else if (!strcasecmp(value
, "solaris"))
2477 PrintcapFormat
= PRINTCAP_SOLARIS
;
2479 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
2482 else if (!strcasecmp(line
, "ServerTokens"))
2485 * Set the string used for the Server header...
2488 struct utsname plat
; /* Platform info */
2493 if (!strcasecmp(value
, "ProductOnly"))
2494 SetString(&ServerHeader
, "CUPS");
2495 else if (!strcasecmp(value
, "Major"))
2496 SetString(&ServerHeader
, "CUPS/1");
2497 else if (!strcasecmp(value
, "Minor"))
2498 SetString(&ServerHeader
, "CUPS/1.1");
2499 else if (!strcasecmp(value
, "Minimal"))
2500 SetString(&ServerHeader
, CUPS_MINIMAL
);
2501 else if (!strcasecmp(value
, "OS"))
2502 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2503 else if (!strcasecmp(value
, "Full"))
2504 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
2505 else if (!strcasecmp(value
, "None"))
2506 ClearString(&ServerHeader
);
2508 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
2513 * Find a simple variable in the list...
2516 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2517 if (!strcasecmp(line
, var
->name
))
2523 * Unknown directive! Output an error message and continue...
2526 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
2536 char *units
; /* Units */
2539 n
= strtol(value
, &units
, 0);
2541 if (units
&& *units
)
2543 if (tolower(units
[0] & 255) == 'g')
2544 n
*= 1024 * 1024 * 1024;
2545 else if (tolower(units
[0] & 255) == 'm')
2547 else if (tolower(units
[0] & 255) == 'k')
2549 else if (tolower(units
[0] & 255) == 't')
2553 *((int *)var
->ptr
) = n
;
2558 if (!strcasecmp(value
, "true") ||
2559 !strcasecmp(value
, "on") ||
2560 !strcasecmp(value
, "enabled") ||
2561 !strcasecmp(value
, "yes") ||
2563 *((int *)var
->ptr
) = TRUE
;
2564 else if (!strcasecmp(value
, "false") ||
2565 !strcasecmp(value
, "off") ||
2566 !strcasecmp(value
, "disabled") ||
2567 !strcasecmp(value
, "no") ||
2568 !strcasecmp(value
, "0"))
2569 *((int *)var
->ptr
) = FALSE
;
2571 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
2576 SetString((char **)var
->ptr
, value
);
2587 * 'read_location()' - Read a <Location path> definition.
2590 static int /* O - New line number or 0 on error */
2591 read_location(cups_file_t
*fp
, /* I - Configuration file */
2592 char *location
, /* I - Location name/path */
2593 int linenum
) /* I - Current line number */
2595 location_t
*loc
, /* New location */
2596 *parent
; /* Parent location */
2597 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2598 *value
, /* Value for directive */
2599 *valptr
; /* Pointer into value */
2602 if ((parent
= AddLocation(location
)) == NULL
)
2605 parent
->limit
= AUTH_LIMIT_ALL
;
2608 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2611 * Decode the directive...
2614 if (!strcasecmp(line
, "</Location>"))
2616 else if (!strcasecmp(line
, "<Limit") ||
2617 !strcasecmp(line
, "<LimitExcept"))
2621 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2625 if ((loc
= CopyLocation(&parent
)) == NULL
)
2631 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2636 if (!strcmp(value
, "ALL"))
2637 loc
->limit
= AUTH_LIMIT_ALL
;
2638 else if (!strcmp(value
, "GET"))
2639 loc
->limit
|= AUTH_LIMIT_GET
;
2640 else if (!strcmp(value
, "HEAD"))
2641 loc
->limit
|= AUTH_LIMIT_HEAD
;
2642 else if (!strcmp(value
, "OPTIONS"))
2643 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2644 else if (!strcmp(value
, "POST"))
2645 loc
->limit
|= AUTH_LIMIT_POST
;
2646 else if (!strcmp(value
, "PUT"))
2647 loc
->limit
|= AUTH_LIMIT_PUT
;
2648 else if (!strcmp(value
, "TRACE"))
2649 loc
->limit
|= AUTH_LIMIT_TRACE
;
2651 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
2654 for (value
= valptr
; isspace(*value
& 255); value
++);
2657 if (!strcasecmp(line
, "<LimitExcept"))
2658 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2660 parent
->limit
&= ~loc
->limit
;
2662 else if (!strcasecmp(line
, "</Limit>"))
2664 else if (!parse_aaa(loc
, line
, value
, linenum
))
2666 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2672 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2680 * 'read_policy()' - Read a <Policy name> definition.
2683 static int /* O - New line number or 0 on error */
2684 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2685 char *policy
, /* I - Location name/path */
2686 int linenum
) /* I - Current line number */
2688 int i
; /* Looping var */
2689 cupsd_policy_t
*pol
; /* Policy */
2690 location_t
*op
; /* Policy operation */
2691 int num_ops
; /* Number of IPP operations */
2692 ipp_op_t ops
[100]; /* Operations */
2693 char line
[HTTP_MAX_BUFFER
],
2695 *value
, /* Value for directive */
2696 *valptr
; /* Pointer into value */
2700 * Create the policy...
2703 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2707 * Read from the file...
2713 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2716 * Decode the directive...
2719 if (!strcasecmp(line
, "</Policy>"))
2722 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2727 else if (!strcasecmp(line
, "<Limit") && !op
)
2731 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2736 * Scan for IPP operation names...
2743 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2748 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2750 if (!strcasecmp(value
, "All"))
2751 ops
[num_ops
] = IPP_ANY_OPERATION
;
2752 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2753 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2759 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2762 for (value
= valptr
; isspace(*value
& 255); value
++);
2766 * If none are specified, apply the policy to all operations...
2771 ops
[0] = IPP_ANY_OPERATION
;
2776 * Add a new policy for the first operation...
2779 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2781 else if (!strcasecmp(line
, "</Limit>") && op
)
2784 * Finish the current operation limit...
2790 * Copy the policy to the other operations...
2793 for (i
= 1; i
< num_ops
; i
++)
2794 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2801 LogMessage(L_ERROR
, "Missing <Limit ops> directive before %s on line %d.",
2805 else if (!parse_aaa(op
, line
, value
, linenum
))
2808 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2811 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2818 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2827 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2828 * required by SSLSetCertificate.
2830 * For now we assumes that there is exactly one SecIdentity in the
2831 * keychain - i.e. there is exactly one matching cert/private key pair.
2832 * In the future we will search a keychain for a SecIdentity matching a
2833 * specific criteria. We also skip the operation of adding additional
2834 * non-signing certs from the keychain to the CFArrayRef.
2836 * To create a self-signed certificate for testing use the certtool.
2837 * Executing the following as root will do it:
2839 * certtool c c v k=CUPS
2843 CDSAGetServerCerts(void)
2845 OSStatus err
; /* Error info */
2846 SecKeychainRef kcRef
; /* Keychain reference */
2847 SecIdentitySearchRef srchRef
; /* Search reference */
2848 SecIdentityRef identity
; /* Identity */
2849 CFArrayRef ca
; /* Certificate array */
2856 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2859 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2860 ServerCertificate
, err
);
2864 * Search for "any" identity matching specified key use;
2865 * in this app, we expect there to be exactly one.
2868 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2872 "Cannot find signing key in keychain \"%s\", error %d",
2873 ServerCertificate
, err
);
2876 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2880 "Cannot find signing key in keychain \"%s\", error %d",
2881 ServerCertificate
, err
);
2884 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2885 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2889 * Found one. Place it in a CFArray.
2890 * TBD: snag other (non-identity) certs from keychain and add them
2894 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2897 LogMessage(L_ERROR
, "CFArrayCreate error");
2900 /*CFRelease(identity);*/
2903 /*CFRelease(srchRef);*/
2906 /*CFRelease(kcRef);*/
2911 #endif /* HAVE_CDSASSL */