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 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * get_address() - Get an address + port number from a line.
28 * get_addr_and_mask() - Get an IP address and netmask.
29 * parse_aaa() - Parse authentication, authorization, and
30 * access control lines.
31 * read_configuration() - Read a configuration file.
32 * read_location() - Read a <Location path> definition.
33 * read_policy() - Read a <Policy name> definition.
34 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
35 * required by SSLSetCertificate.
39 * Include necessary headers...
45 #include <sys/utsname.h>
49 # include <Security/SecureTransport.h>
50 # include <Security/SecIdentitySearch.h>
51 #endif /* HAVE_CDSASSL */
55 #endif /* HAVE_VSYSLOG */
59 * Possibly missing network definitions...
63 # define INADDR_NONE 0xffffffff
64 #endif /* !INADDR_NONE */
68 * Configuration variable structure...
73 CUPSD_VARTYPE_INTEGER
, /* Integer option */
74 CUPSD_VARTYPE_STRING
, /* String option */
75 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
80 char *name
; /* Name of variable */
81 void *ptr
; /* Pointer to variable */
82 cupsd_vartype_t type
; /* Type (int, string, address) */
90 static cupsd_var_t variables
[] =
92 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
93 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
94 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
95 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
96 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
97 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
98 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
99 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
100 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
101 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
102 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
103 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
104 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
105 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
106 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
107 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
108 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
109 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
110 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
111 { "FaxRetryLimit", &FaxRetryLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "FaxRetryInterval", &FaxRetryInterval
, CUPSD_VARTYPE_INTEGER
},
113 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
114 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
115 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
116 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
117 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
118 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
119 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
120 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
121 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
122 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
123 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
124 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
127 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
135 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
136 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
137 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
138 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
139 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
140 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
141 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
142 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
143 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
144 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
145 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
147 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
149 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
150 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
151 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
152 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
153 #endif /* HAVE_SSL */
154 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
155 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
156 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
157 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
158 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
}
160 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
163 static unsigned ones
[4] =
165 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
167 static unsigned zeros
[4] =
169 0x00000000, 0x00000000, 0x00000000, 0x00000000
173 CFArrayRef
CDSAGetServerCerts();
174 #endif /* HAVE_CDSASSL */
181 static http_addrlist_t
*get_address(const char *value
, unsigned defaddress
,
182 int defport
, int deffamily
);
183 static int get_addr_and_mask(const char *value
, unsigned *ip
,
185 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
186 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 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
196 int /* O - 1 on success, 0 otherwise */
197 cupsdReadConfiguration(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 cups_lang_t
*language
; /* Language */
207 struct passwd
*user
; /* Default user */
208 struct group
*group
; /* Default group */
209 char *old_serverroot
, /* Old ServerRoot */
210 *old_requestroot
; /* Old RequestRoot */
213 * Shutdown the server...
219 * Save the old root paths...
222 old_serverroot
= NULL
;
223 cupsdSetString(&old_serverroot
, ServerRoot
);
224 old_requestroot
= NULL
;
225 cupsdSetString(&old_requestroot
, RequestRoot
);
228 * Reset the server configuration data...
231 cupsdDeleteAllLocations();
249 for (i
= 0; i
< NumRelays
; i
++)
250 if (Relays
[i
].from
.type
== AUTH_NAME
)
251 free(Relays
[i
].from
.mask
.name
.name
);
258 if (NumListeners
> 0)
260 #ifdef HAVE_DOMAINSOCKETS
261 int i
; /* Looping var */
262 cupsd_listener_t
*lis
; /* Current listening socket */
264 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
265 if (lis
->address
.sin_family
== AF_LOCAL
)
266 cupsdClearString((char **)&lis
->address
.sin_addr
);
267 #endif /* HAVE_DOMAINSOCKETS */
278 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
279 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
280 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
281 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
282 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
283 cupsdSetString(&DataDir
, CUPS_DATADIR
);
284 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
285 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
286 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
287 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
288 cupsdSetString(&Printcap
, "/etc/printcap");
289 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
290 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
291 cupsdSetString(&RemoteRoot
, "remroot");
292 cupsdSetString(&ServerHeader
, "CUPS/1.1");
293 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
295 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
296 if ((slash
= strrchr(temp
, '/')) != NULL
)
299 cupsdSetString(&ServerRoot
, temp
);
301 cupsdClearString(&Classification
);
302 ClassifyOverride
= 0;
306 cupsdSetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
308 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
309 cupsdSetString(&ServerKey
, "ssl/server.key");
310 # endif /* HAVE_CDSASSL */
311 #endif /* HAVE_SSL */
313 language
= cupsLangDefault();
315 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
316 cupsdSetString(&DefaultLanguage
, "en");
318 cupsdSetString(&DefaultLanguage
, language
->language
);
320 cupsdSetString(&DefaultCharset
, cupsEncodingName(language
->encoding
));
322 cupsdSetString(&RIPCache
, "8m");
324 if (getenv("TMPDIR") == NULL
)
325 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
327 cupsdSetString(&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 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
346 SystemGroupIDs
[0] = group
->gr_gid
;
351 * Find the group associated with GID 0...
358 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
360 cupsdSetString(&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
;
422 LogLevel
= CUPSD_LOG_ERROR
;
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 cupsdClearString(&BrowseLocalOptions
);
442 cupsdClearString(&BrowseRemoteOptions
);
444 JobHistory
= DEFAULT_HISTORY
;
445 JobFiles
= DEFAULT_FILES
;
450 MaxJobsPerPrinter
= 0;
453 cupsdClearString(&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
= cupsdFindLocation("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 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
506 * Validate the Group and SystemGroup settings - they cannot be the same,
507 * otherwise the CGI programs will be able to authenticate as root without
513 for (i
= 0; i
< NumSystemGroups
; i
++)
514 if (Group
== SystemGroupIDs
[i
])
517 if (i
< NumSystemGroups
)
520 * Log the error and reset the group to a safe value...
523 cupsdLogMessage(CUPSD_LOG_NOTICE
,
524 "Group and SystemGroup cannot use the same groups!");
525 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
527 group
= getgrnam("nobody");
531 Group
= group
->gr_gid
;
535 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
536 * complement number...)
545 * Check that we have at least one listen/port line; if not, report this
546 * as an error and exit!
549 if (NumListeners
== 0)
555 cupsdLogMessage(CUPSD_LOG_EMERG
,
556 "No valid Listen or Port lines were found in the configuration file!");
562 cupsdEndProcess(getpid(), 0);
566 * Set the default locale using the language and charset...
569 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
572 * Update all relative filenames to include the full path from ServerRoot...
575 if (DocumentRoot
[0] != '/')
576 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
578 if (RequestRoot
[0] != '/')
579 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
581 if (ServerBin
[0] != '/')
582 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
584 if (StateDir
[0] != '/')
585 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
587 if (CacheDir
[0] != '/')
588 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
591 if (ServerCertificate
[0] != '/')
592 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
594 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
595 chown(ServerCertificate
, RunUser
, Group
);
596 chmod(ServerCertificate
, ConfigFilePerm
);
598 if (ServerKey
[0] != '/')
599 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
601 chown(ServerKey
, RunUser
, Group
);
602 chmod(ServerKey
, ConfigFilePerm
);
603 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
604 #endif /* HAVE_SSL */
607 * Make sure that directories and config files are owned and
608 * writable by the user and group in the cupsd.conf file...
611 chown(CacheDir
, RunUser
, Group
);
612 chmod(CacheDir
, 0775);
614 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
617 chown(temp
, RunUser
, Group
);
620 chown(StateDir
, RunUser
, Group
);
621 chmod(StateDir
, 0775);
623 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
626 chown(temp
, User
, SystemGroupIDs
[0]);
632 chown(ServerRoot
, RunUser
, Group
);
633 chmod(ServerRoot
, 0755);
635 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
638 chown(temp
, RunUser
, Group
);
641 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
644 chown(temp
, RunUser
, Group
);
647 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
648 chown(temp
, RunUser
, Group
);
649 chmod(temp
, ConfigFilePerm
);
651 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
652 chown(temp
, RunUser
, Group
);
655 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
656 chown(temp
, RunUser
, Group
);
659 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
660 chown(temp
, User
, Group
);
664 * Make sure the request and temporary directories have the right
668 chown(RequestRoot
, RunUser
, Group
);
669 chmod(RequestRoot
, 0710);
671 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
675 * Update ownership and permissions if the CUPS temp directory
676 * is under the spool directory or does not exist...
679 if (access(TempDir
, 0))
680 mkdir(TempDir
, 01770);
682 chown(TempDir
, RunUser
, Group
);
683 chmod(TempDir
, 01770);
686 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
689 * Clean out the temporary directory...
692 cups_dir_t
*dir
; /* Temporary directory */
693 cups_dentry_t
*dent
; /* Directory entry */
694 char tempfile
[1024]; /* Temporary filename */
697 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
699 cupsdLogMessage(CUPSD_LOG_INFO
,
700 "Cleaning out old temporary files in \"%s\"...", TempDir
);
702 while ((dent
= cupsDirRead(dir
)) != NULL
)
704 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
706 if (unlink(tempfile
))
707 cupsdLogMessage(CUPSD_LOG_ERROR
,
708 "Unable to remove temporary file \"%s\" - %s",
709 tempfile
, strerror(errno
));
711 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
718 cupsdLogMessage(CUPSD_LOG_ERROR
,
719 "Unable to open temporary directory \"%s\" - %s",
720 TempDir
, strerror(errno
));
724 * Setup environment variables...
730 * Check the MaxClients setting, and then allocate memory for it...
733 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
736 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
739 MaxClients
= MaxFDs
/ 3;
742 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
744 cupsdLogMessage(CUPSD_LOG_ERROR
,
745 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
746 MaxClients
, strerror(errno
));
750 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
754 * Check the MaxActiveJobs setting; limit to 1/3 the available
755 * file descriptors, since we need a pipe for each job...
758 if (MaxActiveJobs
> (MaxFDs
/ 3))
759 MaxActiveJobs
= MaxFDs
/ 3;
761 if (Classification
&& strcasecmp(Classification
, "none") == 0)
762 cupsdClearString(&Classification
);
765 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
768 * Update the MaxClientsPerHost value, as needed...
771 if (MaxClientsPerHost
<= 0)
772 MaxClientsPerHost
= MaxClients
;
774 if (MaxClientsPerHost
> MaxClients
)
775 MaxClientsPerHost
= MaxClients
;
777 cupsdLogMessage(CUPSD_LOG_INFO
,
778 "Allowing up to %d client connections per host.",
782 * Update the default policy, as needed...
786 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
788 DefaultPolicyPtr
= NULL
;
790 if (!DefaultPolicyPtr
)
792 cupsd_policy_t
*p
; /* New policy */
793 cupsd_location_t
*po
; /* New policy operation */
797 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
800 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
801 cupsdLogMessage(CUPSD_LOG_INFO
,
802 "Using policy \"default\" as the default!");
805 cupsdLogMessage(CUPSD_LOG_INFO
,
806 "Creating CUPS default administrative policy:");
808 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
810 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
811 cupsdLogMessage(CUPSD_LOG_INFO
,
812 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
813 "Release-Job Restart-Job Purge-Jobs "
814 "Set-Job-Attributes Create-Job-Subscription "
815 "Renew-Subscription Cancel-Subscription "
816 "Get-Notifications Reprocess-Job Cancel-Current-Job "
817 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
818 "CUPS-Authenticate-Job>");
819 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
821 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
822 po
->order_type
= AUTH_ALLOW
;
823 po
->level
= AUTH_USER
;
825 cupsdAddName(po
, "@OWNER");
826 cupsdAddName(po
, "@SYSTEM");
827 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
829 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
830 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
832 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
833 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
834 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
835 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
836 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
837 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
838 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
839 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
840 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
843 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
844 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
845 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
847 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
849 cupsdLogMessage(CUPSD_LOG_INFO
,
850 "<Limit Pause-Printer Resume-Printer "
851 "Set-Printer-Attributes Enable-Printer "
852 "Disable-Printer Pause-Printer-After-Current-Job "
853 "Hold-New-Jobs Release-Held-New-Jobs "
854 "Deactivate-Printer Activate-Printer Restart-Printer "
855 "Shutdown-Printer Startup-Printer Promote-Job "
856 "Schedule-Job-After CUPS-Add-Printer "
857 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
858 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
859 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
860 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
862 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
863 po
->order_type
= AUTH_ALLOW
;
864 po
->type
= AUTH_BASIC
;
865 po
->level
= AUTH_USER
;
867 cupsdAddName(po
, "@SYSTEM");
868 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
870 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
871 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
872 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
873 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
874 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
875 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
876 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
877 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
878 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
879 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
880 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
882 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
883 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
884 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
885 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
886 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
887 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
888 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
889 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
890 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
892 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
894 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
895 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
897 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
898 po
->order_type
= AUTH_ALLOW
;
900 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
901 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
906 * If we are doing a full reload or the server root has changed, flush
907 * the jobs, printers, etc. and start from scratch...
910 if (NeedReload
== RELOAD_ALL
||
911 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
912 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
914 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
921 cupsdDeleteAllClasses();
922 cupsdDeleteAllPrinters();
924 DefaultPrinter
= NULL
;
926 if (MimeDatabase
!= NULL
)
927 mimeDelete(MimeDatabase
);
931 for (i
= 0; i
< NumMimeTypes
; i
++)
932 free((void *)MimeTypes
[i
]);
938 * Read the MIME type and conversion database...
941 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
943 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
947 cupsdLogMessage(CUPSD_LOG_EMERG
,
948 "Unable to load MIME database from \'%s\'!", ServerRoot
);
952 cupsdLogMessage(CUPSD_LOG_INFO
,
953 "Loaded MIME database from \'%s\': %d types, %d filters...",
954 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
957 * Create a list of MIME types for the document-format-supported
961 NumMimeTypes
= MimeDatabase
->num_types
;
962 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
965 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
967 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
969 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
970 MimeDatabase
->types
[i
]->type
);
972 MimeTypes
[i
] = strdup(type
);
975 if (i
< NumMimeTypes
)
976 MimeTypes
[i
] = strdup("application/octet-stream");
982 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
983 cupsdLoadBanners(temp
);
986 * Load printers and classes...
989 cupsdLoadAllPrinters();
990 cupsdLoadAllClasses();
992 cupsdCreateCommonData();
995 * Load queued jobs...
1000 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1004 cupsdCreateCommonData();
1006 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1010 * Reset the reload state...
1013 NeedReload
= RELOAD_NONE
;
1015 cupsdClearString(&old_serverroot
);
1016 cupsdClearString(&old_requestroot
);
1019 * Startup the server and return...
1029 * 'get_address()' - Get an address + port number from a line.
1032 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1033 get_address(const char *value
, /* I - Value string */
1034 unsigned defaddress
, /* I - Default address */
1035 int defport
, /* I - Default port */
1036 int deffamily
) /* I - Default family */
1038 char buffer
[1024], /* Hostname + port number buffer */
1039 defpname
[255], /* Default port name */
1040 *hostname
, /* Hostname or IP */
1041 *portname
; /* Port number or name */
1042 int portnum
; /* Port number */
1043 http_addrlist_t
*addrlist
; /* Address list */
1044 struct servent
*service
; /* Service entry */
1048 * Check for an empty value...
1053 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1058 * Grab a hostname and port number; if there is no colon and the port name
1059 * is only digits, then we have a port number by itself...
1062 strlcpy(buffer
, value
, sizeof(buffer
));
1064 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1071 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1076 * Use the default port...
1079 sprintf(defpname
, "%d", defport
);
1080 portname
= defpname
;
1086 * The buffer contains just a port number...
1094 if (!strcmp(hostname
, "*"))
1098 * Now lookup the address or use the default address...
1104 * Use httpAddrGetList() to get 1 or more addresses for the
1105 * hostname and port name...
1108 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1109 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1115 * Create up to 2 addresses entry using the default address and
1116 * family, and set the port...
1119 if (isdigit(*portname
& 255))
1120 portnum
= atoi(portname
);
1121 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
1122 portnum
= ntohs(service
->s_port
);
1125 cupsdLogMessage(CUPSD_LOG_ERROR
, "Service lookup for \"%s\" failed!",
1131 addrlist
= (http_addrlist_t
*)calloc(1, sizeof(http_addrlist_t
));
1135 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to allocate address for \"%s\"!",
1141 if (deffamily
== AF_INET6
)
1143 addrlist
->addr
.ipv6
.sin6_family
= AF_INET6
;
1144 addrlist
->addr
.ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1145 addrlist
->addr
.ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1146 addrlist
->addr
.ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1147 addrlist
->addr
.ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1148 addrlist
->addr
.ipv6
.sin6_port
= htons(portnum
);
1151 #endif /* AF_INET6 */
1153 addrlist
->addr
.ipv4
.sin_family
= AF_INET
;
1154 addrlist
->addr
.ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1155 addrlist
->addr
.ipv4
.sin_port
= htons(portnum
);
1158 #if defined(AF_INET6) && defined(__OpenBSD__)
1160 * Since OpenBSD does no allow an IPv6 socket to accept IPv4 connections,
1161 * add an IPv4 address...
1164 if (deffamily
== AF_INET6
&& !defaddress
)
1167 * Add an additional IPv4 address...
1170 http_addrlist_t
*ipv4
; /* IPv4 address */
1173 ipv4
= (http_addrlist_t
*)calloc(1, sizeof(http_addrlist_t
));
1175 cupsdLogMessage(CUPSD_LOG_ERROR
,
1176 "Unable to allocate IPv4 address for \"%s\"!", value
);
1178 addrlist
->next
= ipv4
;
1180 ipv4
->addr
.ipv4
.sin_family
= AF_INET
;
1181 ipv4
->addr
.ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1182 ipv4
->addr
.ipv4
.sin_port
= htons(defport
);
1183 ipv4
->addr
.ipv4
.sin_port
= htons(portnum
);
1186 #endif /* AF_INET6 && __OpenBSD__ */
1194 * 'get_addr_and_mask()' - Get an IP address and netmask.
1197 static int /* O - 1 on success, 0 on failure */
1198 get_addr_and_mask(const char *value
, /* I - String from config file */
1199 unsigned *ip
, /* O - Address value */
1200 unsigned *mask
) /* O - Mask value */
1202 int i
, j
, /* Looping vars */
1203 family
, /* Address family */
1204 ipcount
; /* Count of fields in address */
1205 unsigned ipval
; /* Value */
1206 const char *maskval
, /* Pointer to start of mask value */
1207 *ptr
, /* Pointer into value */
1209 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1211 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1212 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1213 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1214 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1217 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1219 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1220 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1221 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1222 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1223 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1224 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1225 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1226 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1228 #endif /* AF_INET6 */
1232 * Get the address...
1235 memset(ip
, 0, sizeof(unsigned) * 4);
1237 if ((maskval
= strchr(value
, '/')) != NULL
)
1240 maskval
= value
+ strlen(value
);
1244 * Check for an IPv6 address...
1250 * Parse hexadecimal IPv6 address...
1255 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1259 else if (!strncmp(ptr
, "::", 2))
1261 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1263 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1267 else if (isxdigit(*ptr
& 255))
1269 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1277 ip
[i
] |= ipval
<< 16;
1288 if (*ptr
&& *ptr
!= '/')
1292 #endif /* AF_INET6 */
1295 * Parse dotted-decimal IPv4 address...
1299 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1301 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1302 ip
[0] = ip
[1] = ip
[2] = 0;
1308 * Get the netmask value(s)...
1311 memset(mask
, 0, sizeof(unsigned) * 4);
1314 if (*maskval
== '[')
1317 * Get hexadecimal mask value...
1320 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1324 else if (!strncmp(ptr
, "::", 2))
1326 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1328 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1332 else if (isxdigit(*ptr
& 255))
1334 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1342 mask
[i
] |= ipval
<< 16;
1355 #endif /* AF_INET6 */
1356 if (strchr(maskval
, '.'))
1359 * Get dotted-decimal mask...
1362 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1365 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1366 mask
[0] = mask
[1] = mask
[2] = 0;
1371 * Get address/bits format...
1377 if (family
== AF_INET6
)
1382 mask
[0] = 0xffffffff;
1384 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1387 mask
[1] = 0xffffffff;
1391 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1394 mask
[2] = 0xffffffff;
1398 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1401 mask
[3] = 0xffffffff;
1405 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1408 #endif /* AF_INET6 */
1412 mask
[0] = 0xffffffff;
1413 mask
[1] = 0xffffffff;
1414 mask
[2] = 0xffffffff;
1417 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1419 mask
[3] = 0xffffffff;
1424 else if (family
== AF_INET6
)
1425 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1426 #endif /* AF_INET6 */
1428 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1431 "get_addr_and_mask(value=\"%s\", "
1432 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1433 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1437 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1440 if ((ip
[0] & ~mask
[0]) != 0 ||
1441 (ip
[1] & ~mask
[1]) != 0 ||
1442 (ip
[2] & ~mask
[2]) != 0 ||
1443 (ip
[3] & ~mask
[3]) != 0)
1451 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1454 static int /* O - 1 on success, 0 on failure */
1455 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1456 char *line
, /* I - Line from file */
1457 char *value
, /* I - Start of value data */
1458 int linenum
) /* I - Current line number */
1460 char *valptr
; /* Pointer into value */
1461 unsigned ip
[4], /* IP address components */
1462 mask
[4]; /* IP netmask components */
1465 if (!strcasecmp(line
, "Encryption"))
1468 * "Encryption xxx" - set required encryption level...
1471 if (!strcasecmp(value
, "never"))
1472 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1473 else if (!strcasecmp(value
, "always"))
1475 cupsdLogMessage(CUPSD_LOG_ERROR
,
1476 "Encryption value \"%s\" on line %d is invalid in this "
1477 "context. Using \"required\" instead.", value
, linenum
);
1479 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1481 else if (!strcasecmp(value
, "required"))
1482 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1483 else if (!strcasecmp(value
, "ifrequested"))
1484 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1487 cupsdLogMessage(CUPSD_LOG_ERROR
,
1488 "Unknown Encryption value %s on line %d.", value
, linenum
);
1492 else if (!strcasecmp(line
, "Order"))
1495 * "Order Deny,Allow" or "Order Allow,Deny"...
1498 if (!strncasecmp(value
, "deny", 4))
1499 loc
->order_type
= AUTH_ALLOW
;
1500 else if (!strncasecmp(value
, "allow", 5))
1501 loc
->order_type
= AUTH_DENY
;
1504 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1509 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1512 * Allow [From] host/ip...
1513 * Deny [From] host/ip...
1516 if (!strncasecmp(value
, "from", 4))
1519 * Strip leading "from"...
1524 while (isspace(*value
& 255))
1529 * Figure out what form the allow/deny address takes:
1540 * nnn.nnn.nnn.nnn/mm
1541 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1544 if (!strcasecmp(value
, "all"))
1550 if (!strcasecmp(line
, "Allow"))
1551 cupsdAllowIP(loc
, zeros
, zeros
);
1553 cupsdDenyIP(loc
, zeros
, zeros
);
1555 else if (!strcasecmp(value
, "none"))
1561 if (!strcasecmp(line
, "Allow"))
1562 cupsdAllowIP(loc
, ones
, zeros
);
1564 cupsdDenyIP(loc
, ones
, zeros
);
1566 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1569 * Host or domain name...
1572 if (value
[0] == '*')
1575 if (!strcasecmp(line
, "Allow"))
1576 cupsdAllowHost(loc
, value
);
1578 cupsdDenyHost(loc
, value
);
1583 * One of many IP address forms...
1586 if (!get_addr_and_mask(value
, ip
, mask
))
1588 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1593 if (!strcasecmp(line
, "Allow"))
1594 cupsdAllowIP(loc
, ip
, mask
);
1596 cupsdDenyIP(loc
, ip
, mask
);
1599 else if (!strcasecmp(line
, "AuthType"))
1602 * AuthType {none,basic,digest,basicdigest}
1605 if (!strcasecmp(value
, "none"))
1607 loc
->type
= AUTH_NONE
;
1608 loc
->level
= AUTH_ANON
;
1610 else if (!strcasecmp(value
, "basic"))
1612 loc
->type
= AUTH_BASIC
;
1614 if (loc
->level
== AUTH_ANON
)
1615 loc
->level
= AUTH_USER
;
1617 else if (!strcasecmp(value
, "digest"))
1619 loc
->type
= AUTH_DIGEST
;
1621 if (loc
->level
== AUTH_ANON
)
1622 loc
->level
= AUTH_USER
;
1624 else if (!strcasecmp(value
, "basicdigest"))
1626 loc
->type
= AUTH_BASICDIGEST
;
1628 if (loc
->level
== AUTH_ANON
)
1629 loc
->level
= AUTH_USER
;
1633 cupsdLogMessage(CUPSD_LOG_WARN
,
1634 "Unknown authorization type %s on line %d.",
1639 else if (!strcasecmp(line
, "AuthClass"))
1642 * AuthClass anonymous, user, system, group
1645 if (!strcasecmp(value
, "anonymous"))
1647 loc
->type
= AUTH_NONE
;
1648 loc
->level
= AUTH_ANON
;
1650 else if (!strcasecmp(value
, "user"))
1651 loc
->level
= AUTH_USER
;
1652 else if (!strcasecmp(value
, "group"))
1653 loc
->level
= AUTH_GROUP
;
1654 else if (!strcasecmp(value
, "system"))
1656 loc
->level
= AUTH_GROUP
;
1658 cupsdAddName(loc
, "@SYSTEM");
1662 cupsdLogMessage(CUPSD_LOG_WARN
,
1663 "Unknown authorization class %s on line %d.",
1668 else if (!strcasecmp(line
, "AuthGroupName"))
1669 cupsdAddName(loc
, value
);
1670 else if (!strcasecmp(line
, "Require"))
1673 * Apache synonym for AuthClass and AuthGroupName...
1677 * Require valid-user
1678 * Require group names
1679 * Require user names
1682 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1687 if (!strcasecmp(value
, "valid-user") ||
1688 !strcasecmp(value
, "user"))
1689 loc
->level
= AUTH_USER
;
1690 else if (!strcasecmp(value
, "group"))
1691 loc
->level
= AUTH_GROUP
;
1694 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1700 * Get the list of names from the line...
1703 for (value
= valptr
; *value
;)
1705 while (isspace(*value
& 255))
1708 if (*value
== '\"' || *value
== '\'')
1711 * Grab quoted name...
1714 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1721 * Grab literal name.
1724 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1730 cupsdAddName(loc
, value
);
1732 for (value
= valptr
; isspace(*value
& 255); value
++);
1735 else if (!strcasecmp(line
, "Satisfy"))
1737 if (!strcasecmp(value
, "all"))
1738 loc
->satisfy
= AUTH_SATISFY_ALL
;
1739 else if (!strcasecmp(value
, "any"))
1740 loc
->satisfy
= AUTH_SATISFY_ANY
;
1743 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1756 * 'read_configuration()' - Read a configuration file.
1759 static int /* O - 1 on success, 0 on failure */
1760 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1762 int i
; /* Looping var */
1763 int linenum
; /* Current line number */
1764 char line
[HTTP_MAX_BUFFER
],
1765 /* Line from file */
1766 temp
[HTTP_MAX_BUFFER
],
1767 /* Temporary buffer for value */
1768 temp2
[HTTP_MAX_BUFFER
],
1769 /* Temporary buffer 2 for value */
1770 *ptr
, /* Pointer into line/temp */
1771 *value
, /* Pointer to value */
1772 *valueptr
, /* Pointer into value */
1773 quote
; /* Quote character */
1774 int valuelen
; /* Length of value */
1775 cupsd_var_t
*var
; /* Current variable */
1776 http_addrlist_t
*addrlist
, /* Address list */
1777 *addr
; /* Current address */
1778 unsigned ip
[4], /* Address value */
1779 mask
[4]; /* Netmask value */
1780 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1781 cupsd_dirsvc_poll_t
*poll
; /* Polling data */
1782 cupsd_location_t
*location
; /* Browse location */
1783 cups_file_t
*incfile
; /* Include file */
1784 char incname
[1024]; /* Include filename */
1785 struct group
*group
; /* Group */
1789 * Loop through each line in the file...
1794 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1797 * Decode the directive...
1800 if (!strcasecmp(line
, "Include"))
1806 if (value
[0] == '/')
1807 strlcpy(incname
, value
, sizeof(incname
));
1809 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1811 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1812 cupsdLogMessage(CUPSD_LOG_ERROR
,
1813 "Unable to include config file \"%s\" - %s",
1814 incname
, strerror(errno
));
1817 read_configuration(incfile
);
1818 cupsFileClose(incfile
);
1821 else if (!strcasecmp(line
, "<Location"))
1829 linenum
= read_location(fp
, value
, linenum
);
1835 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1840 else if (!strcasecmp(line
, "<Policy"))
1848 linenum
= read_policy(fp
, value
, linenum
);
1854 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1858 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
1860 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
1861 #endif /* HAVE_SSL */
1865 * Add listening address(es) to the list...
1868 cupsd_listener_t
*lis
; /* New listeners array */
1872 * Get the address list...
1875 #if defined(AF_INET6)
1876 addrlist
= get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
);
1878 addrlist
= get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
);
1879 #endif /* AF_INET6 */
1883 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1889 * Add each address...
1892 for (addr
= addrlist
; addr
; addr
= addr
->next
)
1895 * Allocate another listener...
1898 if (NumListeners
== 0)
1899 lis
= malloc(sizeof(cupsd_listener_t
));
1901 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1905 cupsdLogMessage(CUPSD_LOG_ERROR
,
1906 "Unable to allocate %s at line %d - %s.",
1907 line
, linenum
, strerror(errno
));
1912 lis
+= NumListeners
;
1915 * Copy the current address and log it...
1918 memset(lis
, 0, sizeof(cupsd_listener_t
));
1919 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
1922 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1923 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1924 #endif /* HAVE_SSL */
1927 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1928 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1929 ntohs(lis
->address
.ipv6
.sin6_port
));
1931 #endif /* AF_INET6 */
1933 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1934 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1936 #endif /* AF_LOCAL */
1937 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1938 ntohs(lis
->address
.ipv4
.sin_port
));
1947 httpAddrFreeList(addrlist
);
1949 else if (!strcasecmp(line
, "BrowseAddress"))
1952 * Add a browse address to the list...
1955 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1958 if (NumBrowsers
== 0)
1959 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1961 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1965 cupsdLogMessage(CUPSD_LOG_ERROR
,
1966 "Unable to allocate BrowseAddress at line %d - %s.",
1967 linenum
, strerror(errno
));
1972 dira
+= NumBrowsers
;
1974 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1976 if (!strcasecmp(value
, "@LOCAL"))
1979 * Send browse data to all local interfaces...
1982 strcpy(dira
->iface
, "*");
1985 else if (!strncasecmp(value
, "@IF(", 4))
1988 * Send browse data to the named interface...
1991 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1993 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1999 else if ((addrlist
= get_address(value
, INADDR_NONE
, BrowsePort
,
2002 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2003 httpAddrFreeList(addrlist
);
2005 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2008 if (dira
->to
.addr
.sa_family
== AF_INET6
)
2009 cupsdLogMessage(CUPSD_LOG_INFO
,
2010 "Sending browsing info to %s:%d (IPv6)", temp
,
2011 ntohs(dira
->to
.ipv6
.sin6_port
));
2013 #endif /* AF_INET6 */
2014 cupsdLogMessage(CUPSD_LOG_INFO
, "Sending browsing info to %s:%d (IPv4)",
2015 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2020 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2023 else if (!strcasecmp(line
, "BrowseOrder"))
2026 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2029 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2030 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2032 if (location
== NULL
)
2033 cupsdLogMessage(CUPSD_LOG_ERROR
,
2034 "Unable to initialize browse access control list!");
2035 else if (!strncasecmp(value
, "deny", 4))
2036 location
->order_type
= AUTH_ALLOW
;
2037 else if (!strncasecmp(value
, "allow", 5))
2038 location
->order_type
= AUTH_DENY
;
2040 cupsdLogMessage(CUPSD_LOG_ERROR
,
2041 "Unknown BrowseOrder value %s on line %d.",
2044 else if (!strcasecmp(line
, "BrowseProtocols") ||
2045 !strcasecmp(line
, "BrowseLocalProtocols") ||
2046 !strcasecmp(line
, "BrowseRemoteProtocols"))
2049 * "BrowseProtocol name [... name]"
2052 if (strcasecmp(line
, "BrowseLocalProtocols"))
2053 BrowseRemoteProtocols
= 0;
2054 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2055 BrowseLocalProtocols
= 0;
2059 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2060 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2063 if (value
[valuelen
])
2065 value
[valuelen
] = '\0';
2069 if (!strcasecmp(value
, "cups"))
2071 if (strcasecmp(line
, "BrowseLocalProtocols"))
2072 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2073 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2074 BrowseLocalProtocols
|= BROWSE_CUPS
;
2076 else if (!strcasecmp(value
, "slp"))
2078 if (strcasecmp(line
, "BrowseLocalProtocols"))
2079 BrowseRemoteProtocols
|= BROWSE_SLP
;
2080 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2081 BrowseLocalProtocols
|= BROWSE_SLP
;
2083 else if (!strcasecmp(value
, "ldap"))
2085 if (strcasecmp(line
, "BrowseLocalProtocols"))
2086 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2087 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2088 BrowseLocalProtocols
|= BROWSE_LDAP
;
2090 else if (!strcasecmp(value
, "all"))
2092 if (strcasecmp(line
, "BrowseLocalProtocols"))
2093 BrowseRemoteProtocols
|= BROWSE_ALL
;
2094 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2095 BrowseLocalProtocols
|= BROWSE_ALL
;
2099 cupsdLogMessage(CUPSD_LOG_ERROR
,
2100 "Unknown browse protocol \"%s\" on line %d.",
2105 for (value
+= valuelen
; *value
; value
++)
2106 if (!isspace(*value
) || *value
!= ',')
2110 else if (!strcasecmp(line
, "BrowseAllow") ||
2111 !strcasecmp(line
, "BrowseDeny"))
2114 * BrowseAllow [From] host/ip...
2115 * BrowseDeny [From] host/ip...
2118 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2119 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2121 if (location
== NULL
)
2122 cupsdLogMessage(CUPSD_LOG_ERROR
,
2123 "Unable to initialize browse access control list!");
2126 if (!strncasecmp(value
, "from ", 5))
2129 * Strip leading "from"...
2134 while (isspace(*value
))
2139 * Figure out what form the allow/deny address takes:
2150 * nnn.nnn.nnn.nnn/mm
2151 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2154 if (!strcasecmp(value
, "all"))
2160 if (!strcasecmp(line
, "BrowseAllow"))
2161 cupsdAllowIP(location
, zeros
, zeros
);
2163 cupsdDenyIP(location
, zeros
, zeros
);
2165 else if (!strcasecmp(value
, "none"))
2171 if (!strcasecmp(line
, "BrowseAllow"))
2172 cupsdAllowIP(location
, ones
, zeros
);
2174 cupsdDenyIP(location
, ones
, zeros
);
2176 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2179 * Host or domain name...
2182 if (value
[0] == '*')
2185 if (!strcasecmp(line
, "BrowseAllow"))
2186 cupsdAllowHost(location
, value
);
2188 cupsdDenyHost(location
, value
);
2193 * One of many IP address forms...
2196 if (!get_addr_and_mask(value
, ip
, mask
))
2198 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2203 if (!strcasecmp(line
, "BrowseAllow"))
2204 cupsdAllowIP(location
, ip
, mask
);
2206 cupsdDenyIP(location
, ip
, mask
);
2210 else if (!strcasecmp(line
, "BrowseRelay"))
2213 * BrowseRelay [from] source [to] destination
2217 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2219 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2223 cupsdLogMessage(CUPSD_LOG_ERROR
,
2224 "Unable to allocate BrowseRelay at line %d - %s.",
2225 linenum
, strerror(errno
));
2232 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2234 if (!strncasecmp(value
, "from ", 5))
2237 * Strip leading "from"...
2242 while (isspace(*value
))
2247 * Figure out what form the from address takes:
2256 * nnn.nnn.nnn.nnn/mm
2257 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2260 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2263 * Host or domain name...
2266 if (value
[0] == '*')
2269 strlcpy(temp
, value
, sizeof(temp
));
2270 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2273 relay
->from
.type
= AUTH_NAME
;
2274 relay
->from
.mask
.name
.name
= strdup(temp
);
2275 relay
->from
.mask
.name
.length
= strlen(temp
);
2280 * One of many IP address forms...
2283 if (!get_addr_and_mask(value
, ip
, mask
))
2285 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2290 relay
->from
.type
= AUTH_IP
;
2291 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2292 sizeof(relay
->from
.mask
.ip
.address
));
2293 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2294 sizeof(relay
->from
.mask
.ip
.netmask
));
2298 * Skip value and trailing whitespace...
2301 for (; *value
; value
++)
2302 if (isspace(*value
))
2305 while (isspace(*value
))
2308 if (!strncasecmp(value
, "to ", 3))
2311 * Strip leading "to"...
2316 while (isspace(*value
))
2321 * Get "to" address and port...
2324 if ((addrlist
= get_address(value
, INADDR_BROADCAST
, BrowsePort
,
2327 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2328 httpAddrFreeList(addrlist
);
2330 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2332 if (relay
->from
.type
== AUTH_IP
)
2333 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2334 relay
->from
.mask
.ip
.address
[0],
2335 relay
->from
.mask
.ip
.address
[1],
2336 relay
->from
.mask
.ip
.address
[2],
2337 relay
->from
.mask
.ip
.address
[3],
2338 relay
->from
.mask
.ip
.netmask
[0],
2339 relay
->from
.mask
.ip
.netmask
[1],
2340 relay
->from
.mask
.ip
.netmask
[2],
2341 relay
->from
.mask
.ip
.netmask
[3]);
2343 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2346 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2347 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv6)",
2348 temp
, temp2
, ntohs(relay
->to
.ipv6
.sin6_port
));
2350 #endif /* AF_INET6 */
2351 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2352 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2358 if (relay
->from
.type
== AUTH_NAME
)
2359 free(relay
->from
.mask
.name
.name
);
2361 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2365 else if (!strcasecmp(line
, "BrowsePoll"))
2368 * BrowsePoll address[:port]
2371 char *portname
; /* Port name */
2372 int portnum
; /* Port number */
2373 struct servent
*service
; /* Service */
2377 * Extract the port name from the address...
2380 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2384 if (isdigit(*portname
& 255))
2385 portnum
= atoi(portname
);
2386 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2387 portnum
= ntohs(service
->s_port
);
2390 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2396 portnum
= ippPort();
2399 * Add the poll entry...
2403 poll
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2405 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2409 cupsdLogMessage(CUPSD_LOG_ERROR
,
2410 "Unable to allocate BrowsePoll at line %d - %s.",
2411 linenum
, strerror(errno
));
2419 memset(poll
, 0, sizeof(cupsd_dirsvc_poll_t
));
2421 strlcpy(poll
->hostname
, value
, sizeof(poll
->hostname
));
2422 poll
->port
= portnum
;
2424 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", poll
->hostname
,
2427 else if (!strcasecmp(line
, "DefaultAuthType"))
2430 * DefaultAuthType {basic,digest,basicdigest}
2433 if (!strcasecmp(value
, "basic"))
2434 DefaultAuthType
= AUTH_BASIC
;
2435 else if (!strcasecmp(value
, "digest"))
2436 DefaultAuthType
= AUTH_DIGEST
;
2437 else if (!strcasecmp(value
, "basicdigest"))
2438 DefaultAuthType
= AUTH_BASICDIGEST
;
2441 cupsdLogMessage(CUPSD_LOG_WARN
,
2442 "Unknown default authorization type %s on line %d.",
2447 else if (!strcasecmp(line
, "User"))
2450 * User ID to run as...
2453 if (isdigit(value
[0]))
2457 struct passwd
*p
; /* Password information */
2460 p
= getpwnam(value
);
2465 cupsdLogMessage(CUPSD_LOG_ERROR
,
2466 "Unknown User \"%s\" on line %d, ignoring!",
2470 else if (!strcasecmp(line
, "Group"))
2473 * Group ID to run as...
2476 if (isdigit(value
[0]))
2477 Group
= atoi(value
);
2481 group
= getgrnam(value
);
2484 Group
= group
->gr_gid
;
2486 cupsdLogMessage(CUPSD_LOG_ERROR
,
2487 "Unknown Group \"%s\" on line %d, ignoring!",
2491 else if (!strcasecmp(line
, "SystemGroup"))
2494 * System (admin) group(s)...
2497 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2499 if (*value
== '\'' || *value
== '\"')
2502 * Scan quoted name...
2507 for (valueptr
= value
; *valueptr
; valueptr
++)
2508 if (*valueptr
== quote
)
2514 * Scan space or comma-delimited name...
2517 for (valueptr
= value
; *valueptr
; valueptr
++)
2518 if (isspace(*valueptr
) || *valueptr
== ',')
2525 group
= getgrnam(value
);
2528 cupsdSetString(SystemGroups
+ i
, value
);
2529 SystemGroupIDs
[i
] = group
->gr_gid
;
2534 cupsdLogMessage(CUPSD_LOG_ERROR
,
2535 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2542 while (*value
== ',' || isspace(*value
))
2547 NumSystemGroups
= i
;
2549 else if (!strcasecmp(line
, "HostNameLookups"))
2552 * Do hostname lookups?
2555 if (!strcasecmp(value
, "off"))
2556 HostNameLookups
= 0;
2557 else if (!strcasecmp(value
, "on"))
2558 HostNameLookups
= 1;
2559 else if (!strcasecmp(value
, "double"))
2560 HostNameLookups
= 2;
2562 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2565 else if (!strcasecmp(line
, "LogLevel"))
2568 * Amount of logging to do...
2571 if (!strcasecmp(value
, "debug2"))
2572 LogLevel
= CUPSD_LOG_DEBUG2
;
2573 else if (!strcasecmp(value
, "debug"))
2574 LogLevel
= CUPSD_LOG_DEBUG
;
2575 else if (!strcasecmp(value
, "info"))
2576 LogLevel
= CUPSD_LOG_INFO
;
2577 else if (!strcasecmp(value
, "notice"))
2578 LogLevel
= CUPSD_LOG_NOTICE
;
2579 else if (!strcasecmp(value
, "warn"))
2580 LogLevel
= CUPSD_LOG_WARN
;
2581 else if (!strcasecmp(value
, "error"))
2582 LogLevel
= CUPSD_LOG_ERROR
;
2583 else if (!strcasecmp(value
, "crit"))
2584 LogLevel
= CUPSD_LOG_CRIT
;
2585 else if (!strcasecmp(value
, "alert"))
2586 LogLevel
= CUPSD_LOG_ALERT
;
2587 else if (!strcasecmp(value
, "emerg"))
2588 LogLevel
= CUPSD_LOG_EMERG
;
2589 else if (!strcasecmp(value
, "none"))
2590 LogLevel
= CUPSD_LOG_NONE
;
2592 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2595 else if (!strcasecmp(line
, "PrintcapFormat"))
2598 * Format of printcap file?
2601 if (!strcasecmp(value
, "bsd"))
2602 PrintcapFormat
= PRINTCAP_BSD
;
2603 else if (!strcasecmp(value
, "solaris"))
2604 PrintcapFormat
= PRINTCAP_SOLARIS
;
2606 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2609 else if (!strcasecmp(line
, "ServerTokens"))
2612 * Set the string used for the Server header...
2615 struct utsname plat
; /* Platform info */
2620 if (!strcasecmp(value
, "ProductOnly"))
2621 cupsdSetString(&ServerHeader
, "CUPS");
2622 else if (!strcasecmp(value
, "Major"))
2623 cupsdSetString(&ServerHeader
, "CUPS/1");
2624 else if (!strcasecmp(value
, "Minor"))
2625 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2626 else if (!strcasecmp(value
, "Minimal"))
2627 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2628 else if (!strcasecmp(value
, "OS"))
2629 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2630 else if (!strcasecmp(value
, "Full"))
2631 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2633 else if (!strcasecmp(value
, "None"))
2634 cupsdClearString(&ServerHeader
);
2636 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2639 else if (!strcasecmp(line
, "PassEnv"))
2642 * PassEnv variable [... variable]
2647 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2648 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2651 if (value
[valuelen
])
2653 value
[valuelen
] = '\0';
2657 cupsdSetEnv(value
, NULL
);
2659 for (value
+= valuelen
; *value
; value
++)
2660 if (!isspace(*value
) || *value
!= ',')
2664 else if (!strcasecmp(line
, "SetEnv"))
2667 * SetEnv variable value
2670 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2678 while (isspace(*valueptr
& 255))
2681 cupsdSetEnv(value
, valueptr
);
2684 cupsdLogMessage(CUPSD_LOG_ERROR
,
2685 "Missing value for SetEnv directive on line %d.",
2691 * Find a simple variable in the list...
2694 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2695 if (!strcasecmp(line
, var
->name
))
2701 * Unknown directive! Output an error message and continue...
2704 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2711 case CUPSD_VARTYPE_INTEGER
:
2714 char *units
; /* Units */
2717 n
= strtol(value
, &units
, 0);
2719 if (units
&& *units
)
2721 if (tolower(units
[0] & 255) == 'g')
2722 n
*= 1024 * 1024 * 1024;
2723 else if (tolower(units
[0] & 255) == 'm')
2725 else if (tolower(units
[0] & 255) == 'k')
2727 else if (tolower(units
[0] & 255) == 't')
2731 *((int *)var
->ptr
) = n
;
2735 case CUPSD_VARTYPE_BOOLEAN
:
2736 if (!strcasecmp(value
, "true") ||
2737 !strcasecmp(value
, "on") ||
2738 !strcasecmp(value
, "enabled") ||
2739 !strcasecmp(value
, "yes") ||
2741 *((int *)var
->ptr
) = TRUE
;
2742 else if (!strcasecmp(value
, "false") ||
2743 !strcasecmp(value
, "off") ||
2744 !strcasecmp(value
, "disabled") ||
2745 !strcasecmp(value
, "no") ||
2746 !strcasecmp(value
, "0"))
2747 *((int *)var
->ptr
) = FALSE
;
2749 cupsdLogMessage(CUPSD_LOG_ERROR
,
2750 "Unknown boolean value %s on line %d.",
2754 case CUPSD_VARTYPE_STRING
:
2755 cupsdSetString((char **)var
->ptr
, value
);
2766 * 'read_location()' - Read a <Location path> definition.
2769 static int /* O - New line number or 0 on error */
2770 read_location(cups_file_t
*fp
, /* I - Configuration file */
2771 char *location
, /* I - Location name/path */
2772 int linenum
) /* I - Current line number */
2774 cupsd_location_t
*loc
, /* New location */
2775 *parent
; /* Parent location */
2776 char line
[HTTP_MAX_BUFFER
],
2778 *value
, /* Value for directive */
2779 *valptr
; /* Pointer into value */
2782 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2785 parent
->limit
= AUTH_LIMIT_ALL
;
2788 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2791 * Decode the directive...
2794 if (!strcasecmp(line
, "</Location>"))
2796 else if (!strcasecmp(line
, "<Limit") ||
2797 !strcasecmp(line
, "<LimitExcept"))
2801 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2805 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2811 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2816 if (!strcmp(value
, "ALL"))
2817 loc
->limit
= AUTH_LIMIT_ALL
;
2818 else if (!strcmp(value
, "GET"))
2819 loc
->limit
|= AUTH_LIMIT_GET
;
2820 else if (!strcmp(value
, "HEAD"))
2821 loc
->limit
|= AUTH_LIMIT_HEAD
;
2822 else if (!strcmp(value
, "OPTIONS"))
2823 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2824 else if (!strcmp(value
, "POST"))
2825 loc
->limit
|= AUTH_LIMIT_POST
;
2826 else if (!strcmp(value
, "PUT"))
2827 loc
->limit
|= AUTH_LIMIT_PUT
;
2828 else if (!strcmp(value
, "TRACE"))
2829 loc
->limit
|= AUTH_LIMIT_TRACE
;
2831 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2834 for (value
= valptr
; isspace(*value
& 255); value
++);
2837 if (!strcasecmp(line
, "<LimitExcept"))
2838 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2840 parent
->limit
&= ~loc
->limit
;
2842 else if (!strcasecmp(line
, "</Limit>"))
2844 else if (!parse_aaa(loc
, line
, value
, linenum
))
2846 cupsdLogMessage(CUPSD_LOG_ERROR
,
2847 "Unknown Location directive %s on line %d.",
2853 cupsdLogMessage(CUPSD_LOG_ERROR
,
2854 "Unexpected end-of-file at line %d while reading location!",
2862 * 'read_policy()' - Read a <Policy name> definition.
2865 static int /* O - New line number or 0 on error */
2866 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2867 char *policy
, /* I - Location name/path */
2868 int linenum
) /* I - Current line number */
2870 int i
; /* Looping var */
2871 cupsd_policy_t
*pol
; /* Policy */
2872 cupsd_location_t
*op
; /* Policy operation */
2873 int num_ops
; /* Number of IPP operations */
2874 ipp_op_t ops
[100]; /* Operations */
2875 char line
[HTTP_MAX_BUFFER
],
2877 *value
, /* Value for directive */
2878 *valptr
; /* Pointer into value */
2882 * Create the policy...
2885 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2889 * Read from the file...
2895 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2898 * Decode the directive...
2901 if (!strcasecmp(line
, "</Policy>"))
2904 cupsdLogMessage(CUPSD_LOG_WARN
,
2905 "Missing </Limit> before </Policy> on line %d!",
2910 else if (!strcasecmp(line
, "<Limit") && !op
)
2914 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2919 * Scan for IPP operation names...
2926 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2931 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2933 if (!strcasecmp(value
, "All"))
2934 ops
[num_ops
] = IPP_ANY_OPERATION
;
2935 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2936 cupsdLogMessage(CUPSD_LOG_ERROR
,
2937 "Bad IPP operation name \"%s\" on line %d!",
2943 cupsdLogMessage(CUPSD_LOG_ERROR
,
2944 "Too many operations listed on line %d!",
2947 for (value
= valptr
; isspace(*value
& 255); value
++);
2951 * If none are specified, apply the policy to all operations...
2956 ops
[0] = IPP_ANY_OPERATION
;
2961 * Add a new policy for the first operation...
2964 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2966 else if (!strcasecmp(line
, "</Limit>") && op
)
2969 * Finish the current operation limit...
2975 * Copy the policy to the other operations...
2978 for (i
= 1; i
< num_ops
; i
++)
2979 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2986 cupsdLogMessage(CUPSD_LOG_ERROR
,
2987 "Missing <Limit ops> directive before %s on line %d.",
2991 else if (!parse_aaa(op
, line
, value
, linenum
))
2994 cupsdLogMessage(CUPSD_LOG_ERROR
,
2995 "Unknown Policy Limit directive %s on line %d.",
2998 cupsdLogMessage(CUPSD_LOG_ERROR
,
2999 "Unknown Policy directive %s on line %d.",
3006 cupsdLogMessage(CUPSD_LOG_ERROR
,
3007 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3016 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
3017 * required by SSLSetCertificate.
3019 * For now we assumes that there is exactly one SecIdentity in the
3020 * keychain - i.e. there is exactly one matching cert/private key pair.
3021 * In the future we will search a keychain for a SecIdentity matching a
3022 * specific criteria. We also skip the operation of adding additional
3023 * non-signing certs from the keychain to the CFArrayRef.
3025 * To create a self-signed certificate for testing use the certtool.
3026 * Executing the following as root will do it:
3028 * certtool c c v k=CUPS
3032 CDSAGetServerCerts(void)
3034 OSStatus err
; /* Error info */
3035 SecKeychainRef kcRef
; /* Keychain reference */
3036 SecIdentitySearchRef srchRef
; /* Search reference */
3037 SecIdentityRef identity
; /* Identity */
3038 CFArrayRef ca
; /* Certificate array */
3045 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
3048 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot open keychain \"%s\", error %d.",
3049 ServerCertificate
, err
);
3053 * Search for "any" identity matching specified key use;
3054 * in this app, we expect there to be exactly one.
3057 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
3060 cupsdLogMessage(CUPSD_LOG_ERROR
,
3061 "Cannot find signing key in keychain \"%s\", error %d",
3062 ServerCertificate
, err
);
3065 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
3068 cupsdLogMessage(CUPSD_LOG_ERROR
,
3069 "Cannot find signing key in keychain \"%s\", error %d",
3070 ServerCertificate
, err
);
3073 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
3074 cupsdLogMessage(CUPSD_LOG_ERROR
,
3075 "SecIdentitySearchCopyNext CFTypeID failure!");
3079 * Found one. Place it in a CFArray.
3080 * TBD: snag other (non-identity) certs from keychain and add them
3084 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
3087 cupsdLogMessage(CUPSD_LOG_ERROR
, "CFArrayCreate error");
3090 /*CFRelease(identity);*/
3093 /*CFRelease(srchRef);*/
3096 /*CFRelease(kcRef);*/
3101 #endif /* HAVE_CDSASSL */