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 int get_address(const char *value
, unsigned defaddress
, int defport
,
182 int deffamily
, http_addr_t
*address
);
183 static int get_addr_and_mask(const char *value
, unsigned *ip
,
185 static int parse_aaa(cupsd_location_t
*loc
, char *line
, char *value
, int linenum
);
186 static int read_configuration(cups_file_t
*fp
);
187 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
188 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
192 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
195 int /* O - 1 on success, 0 otherwise */
196 cupsdReadConfiguration(void)
198 int i
; /* Looping var */
199 cups_file_t
*fp
; /* Configuration file */
200 int status
; /* Return status */
201 char temp
[1024], /* Temporary buffer */
202 *slash
; /* Directory separator */
203 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
205 cups_lang_t
*language
; /* Language */
206 struct passwd
*user
; /* Default user */
207 struct group
*group
; /* Default group */
208 char *old_serverroot
, /* Old ServerRoot */
209 *old_requestroot
; /* Old RequestRoot */
212 * Shutdown the server...
218 * Save the old root paths...
221 old_serverroot
= NULL
;
222 cupsdSetString(&old_serverroot
, ServerRoot
);
223 old_requestroot
= NULL
;
224 cupsdSetString(&old_requestroot
, RequestRoot
);
227 * Reset the server configuration data...
230 cupsdDeleteAllLocations();
248 for (i
= 0; i
< NumRelays
; i
++)
249 if (Relays
[i
].from
.type
== AUTH_NAME
)
250 free(Relays
[i
].from
.mask
.name
.name
);
257 if (NumListeners
> 0)
259 #ifdef HAVE_DOMAINSOCKETS
260 int i
; /* Looping var */
261 cupsd_listener_t
*lis
; /* Current listening socket */
263 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
264 if (lis
->address
.sin_family
== AF_LOCAL
)
265 cupsdClearString((char **)&lis
->address
.sin_addr
);
266 #endif /* HAVE_DOMAINSOCKETS */
277 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
278 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
279 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
280 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
281 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
282 cupsdSetString(&DataDir
, CUPS_DATADIR
);
283 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
284 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
285 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
286 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
287 cupsdSetString(&Printcap
, "/etc/printcap");
288 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
289 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
290 cupsdSetString(&RemoteRoot
, "remroot");
291 cupsdSetString(&ServerHeader
, "CUPS/1.1");
292 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
294 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
295 if ((slash
= strrchr(temp
, '/')) != NULL
)
298 cupsdSetString(&ServerRoot
, temp
);
300 cupsdClearString(&Classification
);
301 ClassifyOverride
= 0;
305 cupsdSetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
307 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
308 cupsdSetString(&ServerKey
, "ssl/server.key");
309 # endif /* HAVE_CDSASSL */
310 #endif /* HAVE_SSL */
312 language
= cupsLangDefault();
314 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
315 cupsdSetString(&DefaultLanguage
, "en");
317 cupsdSetString(&DefaultLanguage
, language
->language
);
319 cupsdSetString(&DefaultCharset
, cupsEncodingName(language
->encoding
));
321 cupsdSetString(&RIPCache
, "8m");
323 if (getenv("TMPDIR") == NULL
)
324 cupsdSetString(&TempDir
, CUPS_REQUESTS
"/tmp");
326 cupsdSetString(&TempDir
, getenv("TMPDIR"));
329 * Find the default system group: "sys", "system", or "root"...
332 group
= getgrnam(CUPS_DEFAULT_GROUP
);
340 * Found the group, use it!
343 cupsdSetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
345 SystemGroupIDs
[0] = group
->gr_gid
;
350 * Find the group associated with GID 0...
357 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
359 cupsdSetString(&SystemGroups
[0], "unknown");
361 SystemGroupIDs
[0] = 0;
365 * Find the default user...
368 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
373 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
374 * complement number...)
383 * Find the default group (nobody)...
386 group
= getgrnam("nobody");
390 Group
= group
->gr_gid
;
394 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
395 * complement number...)
405 ConfigFilePerm
= 0640;
406 DefaultAuthType
= AUTH_BASIC
;
408 FaxRetryInterval
= 300;
413 HostNameLookups
= FALSE
;
414 ImplicitClasses
= TRUE
;
415 ImplicitAnyClasses
= FALSE
;
416 HideImplicitMembers
= TRUE
;
418 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
419 ListenBackLog
= SOMAXCONN
;
421 LogLevel
= CUPSD_LOG_ERROR
;
423 MaxClientsPerHost
= 0;
424 MaxLogSize
= 1024 * 1024;
425 MaxPrinterHistory
= 10;
428 RootCertDuration
= 300;
430 Timeout
= DEFAULT_TIMEOUT
;
432 BrowseInterval
= DEFAULT_INTERVAL
;
433 BrowsePort
= ippPort();
434 BrowseLocalProtocols
= BROWSE_CUPS
;
435 BrowseRemoteProtocols
= BROWSE_CUPS
;
436 BrowseShortNames
= TRUE
;
437 BrowseTimeout
= DEFAULT_TIMEOUT
;
440 cupsdClearString(&BrowseLocalOptions
);
441 cupsdClearString(&BrowseRemoteOptions
);
443 JobHistory
= DEFAULT_HISTORY
;
444 JobFiles
= DEFAULT_FILES
;
449 MaxJobsPerPrinter
= 0;
452 cupsdClearString(&DefaultPolicy
);
455 * Read the configuration file...
458 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
461 status
= read_configuration(fp
);
474 * Use the default system group if none was supplied in cupsd.conf...
477 if (NumSystemGroups
== 0)
481 * Get the access control list for browsing...
484 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
487 * Open the system log for cupsd if necessary...
491 if (!strcmp(AccessLog
, "syslog") ||
492 !strcmp(ErrorLog
, "syslog") ||
493 !strcmp(PageLog
, "syslog"))
494 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
495 #endif /* HAVE_VSYSLOG */
498 * Log the configuration file that was used...
501 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
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 cupsdLogMessage(CUPSD_LOG_NOTICE
,
523 "Group and SystemGroup cannot use the same groups!");
524 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
526 group
= getgrnam("nobody");
530 Group
= group
->gr_gid
;
534 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
535 * complement number...)
544 * Check that we have at least one listen/port line; if not, report this
545 * as an error and exit!
548 if (NumListeners
== 0)
554 cupsdLogMessage(CUPSD_LOG_EMERG
,
555 "No valid Listen or Port lines were found in the configuration file!");
561 cupsdEndProcess(getpid(), 0);
565 * Set the default locale using the language and charset...
568 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
571 * Update all relative filenames to include the full path from ServerRoot...
574 if (DocumentRoot
[0] != '/')
575 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
577 if (RequestRoot
[0] != '/')
578 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
580 if (ServerBin
[0] != '/')
581 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
583 if (StateDir
[0] != '/')
584 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
586 if (CacheDir
[0] != '/')
587 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
590 if (ServerCertificate
[0] != '/')
591 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
593 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
594 chown(ServerCertificate
, RunUser
, Group
);
595 chmod(ServerCertificate
, ConfigFilePerm
);
597 if (ServerKey
[0] != '/')
598 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
600 chown(ServerKey
, RunUser
, Group
);
601 chmod(ServerKey
, ConfigFilePerm
);
602 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
603 #endif /* HAVE_SSL */
606 * Make sure that directories and config files are owned and
607 * writable by the user and group in the cupsd.conf file...
610 chown(CacheDir
, RunUser
, Group
);
611 chmod(CacheDir
, 0775);
613 snprintf(temp
, sizeof(temp
), "%s/ppd", CacheDir
);
616 chown(temp
, RunUser
, Group
);
619 chown(StateDir
, RunUser
, Group
);
620 chmod(StateDir
, 0775);
622 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
625 chown(temp
, User
, SystemGroupIDs
[0]);
631 chown(ServerRoot
, RunUser
, Group
);
632 chmod(ServerRoot
, 0755);
634 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
637 chown(temp
, RunUser
, Group
);
640 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
643 chown(temp
, RunUser
, Group
);
646 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
647 chown(temp
, RunUser
, Group
);
648 chmod(temp
, ConfigFilePerm
);
650 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
651 chown(temp
, RunUser
, Group
);
654 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
655 chown(temp
, RunUser
, Group
);
658 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
659 chown(temp
, User
, Group
);
663 * Make sure the request and temporary directories have the right
667 chown(RequestRoot
, RunUser
, Group
);
668 chmod(RequestRoot
, 0710);
670 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
674 * Update ownership and permissions if the CUPS temp directory
675 * is under the spool directory or does not exist...
678 if (access(TempDir
, 0))
679 mkdir(TempDir
, 01770);
681 chown(TempDir
, RunUser
, Group
);
682 chmod(TempDir
, 01770);
685 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
688 * Clean out the temporary directory...
691 cups_dir_t
*dir
; /* Temporary directory */
692 cups_dentry_t
*dent
; /* Directory entry */
693 char tempfile
[1024]; /* Temporary filename */
696 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
698 cupsdLogMessage(CUPSD_LOG_INFO
,
699 "Cleaning out old temporary files in \"%s\"...", TempDir
);
701 while ((dent
= cupsDirRead(dir
)) != NULL
)
703 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
705 if (unlink(tempfile
))
706 cupsdLogMessage(CUPSD_LOG_ERROR
,
707 "Unable to remove temporary file \"%s\" - %s",
708 tempfile
, strerror(errno
));
710 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
717 cupsdLogMessage(CUPSD_LOG_ERROR
,
718 "Unable to open temporary directory \"%s\" - %s",
719 TempDir
, strerror(errno
));
723 * Setup environment variables...
729 * Check the MaxClients setting, and then allocate memory for it...
732 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
735 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
738 MaxClients
= MaxFDs
/ 3;
741 if ((Clients
= calloc(sizeof(cupsd_client_t
), MaxClients
)) == NULL
)
743 cupsdLogMessage(CUPSD_LOG_ERROR
,
744 "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
745 MaxClients
, strerror(errno
));
749 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
753 * Check the MaxActiveJobs setting; limit to 1/3 the available
754 * file descriptors, since we need a pipe for each job...
757 if (MaxActiveJobs
> (MaxFDs
/ 3))
758 MaxActiveJobs
= MaxFDs
/ 3;
760 if (Classification
&& strcasecmp(Classification
, "none") == 0)
761 cupsdClearString(&Classification
);
764 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
767 * Update the MaxClientsPerHost value, as needed...
770 if (MaxClientsPerHost
<= 0)
771 MaxClientsPerHost
= MaxClients
;
773 if (MaxClientsPerHost
> MaxClients
)
774 MaxClientsPerHost
= MaxClients
;
776 cupsdLogMessage(CUPSD_LOG_INFO
,
777 "Allowing up to %d client connections per host.",
781 * Update the default policy, as needed...
785 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
787 DefaultPolicyPtr
= NULL
;
789 if (!DefaultPolicyPtr
)
791 cupsd_policy_t
*p
; /* New policy */
792 cupsd_location_t
*po
; /* New policy operation */
796 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
799 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
800 cupsdLogMessage(CUPSD_LOG_INFO
,
801 "Using policy \"default\" as the default!");
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Creating CUPS default administrative policy:");
807 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
809 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
810 cupsdLogMessage(CUPSD_LOG_INFO
,
811 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
812 "Release-Job Restart-Job Purge-Jobs "
813 "Set-Job-Attributes Create-Job-Subscription "
814 "Renew-Subscription Cancel-Subscription "
815 "Get-Notifications Reprocess-Job Cancel-Current-Job "
816 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
817 "CUPS-Authenticate-Job>");
818 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
820 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
821 po
->order_type
= AUTH_ALLOW
;
822 po
->level
= AUTH_USER
;
824 cupsdAddName(po
, "@OWNER");
825 cupsdAddName(po
, "@SYSTEM");
826 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
828 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
829 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
830 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
832 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
833 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
834 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
835 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
836 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
837 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
838 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
839 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
840 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
843 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
844 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
846 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
848 cupsdLogMessage(CUPSD_LOG_INFO
,
849 "<Limit Pause-Printer Resume-Printer "
850 "Set-Printer-Attributes Enable-Printer "
851 "Disable-Printer Pause-Printer-After-Current-Job "
852 "Hold-New-Jobs Release-Held-New-Jobs "
853 "Deactivate-Printer Activate-Printer Restart-Printer "
854 "Shutdown-Printer Startup-Printer Promote-Job "
855 "Schedule-Job-After CUPS-Add-Printer "
856 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
857 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
859 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
861 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
862 po
->order_type
= AUTH_ALLOW
;
863 po
->type
= AUTH_BASIC
;
864 po
->level
= AUTH_USER
;
866 cupsdAddName(po
, "@SYSTEM");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
869 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
871 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
872 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
873 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
874 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
875 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
876 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
877 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
878 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
879 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
880 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
882 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
883 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
884 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
885 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
886 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
887 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
888 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
889 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
891 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
893 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
894 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
896 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
897 po
->order_type
= AUTH_ALLOW
;
899 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
900 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
905 * If we are doing a full reload or the server root has changed, flush
906 * the jobs, printers, etc. and start from scratch...
909 if (NeedReload
== RELOAD_ALL
||
910 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
911 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
913 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
920 cupsdDeleteAllClasses();
921 cupsdDeleteAllPrinters();
923 DefaultPrinter
= NULL
;
925 if (MimeDatabase
!= NULL
)
926 mimeDelete(MimeDatabase
);
930 for (i
= 0; i
< NumMimeTypes
; i
++)
931 free((void *)MimeTypes
[i
]);
937 * Read the MIME type and conversion database...
940 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
942 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
946 cupsdLogMessage(CUPSD_LOG_EMERG
,
947 "Unable to load MIME database from \'%s\'!", ServerRoot
);
951 cupsdLogMessage(CUPSD_LOG_INFO
,
952 "Loaded MIME database from \'%s\': %d types, %d filters...",
953 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
956 * Create a list of MIME types for the document-format-supported
960 NumMimeTypes
= MimeDatabase
->num_types
;
961 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
964 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
966 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
968 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
969 MimeDatabase
->types
[i
]->type
);
971 MimeTypes
[i
] = strdup(type
);
974 if (i
< NumMimeTypes
)
975 MimeTypes
[i
] = strdup("application/octet-stream");
981 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
982 cupsdLoadBanners(temp
);
985 * Load printers and classes...
988 cupsdLoadAllPrinters();
989 cupsdLoadAllClasses();
991 cupsdCreateCommonData();
994 * Load queued jobs...
999 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1003 cupsdCreateCommonData();
1005 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1009 * Reset the reload state...
1012 NeedReload
= RELOAD_NONE
;
1014 cupsdClearString(&old_serverroot
);
1015 cupsdClearString(&old_requestroot
);
1018 * Startup the server and return...
1028 * 'get_address()' - Get an address + port number from a line.
1031 static int /* O - 1 if address good, 0 if bad */
1032 get_address(const char *value
, /* I - Value string */
1033 unsigned defaddress
, /* I - Default address */
1034 int defport
, /* I - Default port */
1035 int deffamily
, /* I - Default family */
1036 http_addr_t
*address
) /* O - Socket address */
1038 char hostname
[256], /* Hostname or IP */
1039 portname
[256], /* Port number or name */
1040 *ptr
; /* Pointer into hostname string */
1041 struct hostent
*host
; /* Host address */
1042 struct servent
*port
; /* Port number */
1046 * Check for an empty value...
1051 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1056 * Initialize the socket address to the defaults...
1059 memset(address
, 0, sizeof(http_addr_t
));
1062 if (deffamily
== AF_INET6
)
1064 address
->ipv6
.sin6_family
= AF_INET6
;
1065 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
1066 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
1067 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
1068 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
1069 address
->ipv6
.sin6_port
= htons(defport
);
1072 #endif /* AF_INET6 */
1074 address
->ipv4
.sin_family
= AF_INET
;
1075 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
1076 address
->ipv4
.sin_port
= htons(defport
);
1081 * If the address starts with a "/", it is a domain socket...
1086 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
1088 cupsdLogMessage(CUPSD_LOG_ERROR
, "Domain socket name \"%s\" too long!",
1093 address
->un
.sun_family
= AF_LOCAL
;
1094 strcpy(address
->un
.sun_path
, value
);
1098 #endif /* AF_LOCAL */
1101 * Try to grab a hostname and port number...
1104 strlcpy(hostname
, value
, sizeof(hostname
));
1106 if ((ptr
= strrchr(hostname
, ':')) != NULL
)
1109 * Copy hostname and port separately...
1114 strlcpy(portname
, ptr
, sizeof(portname
));
1116 else if (isdigit(value
[0] & 255))
1123 strlcpy(portname
, value
, sizeof(portname
));
1128 * Hostname by itself...
1135 * Decode the hostname and port number as needed...
1138 if (hostname
[0] && strcmp(hostname
, "*"))
1140 if ((host
= httpGetHostByName(hostname
)) == NULL
)
1142 cupsdLogMessage(CUPSD_LOG_ERROR
, "httpGetHostByName(\"%s\") failed - %s!",
1143 hostname
, hstrerror(h_errno
));
1147 httpAddrLoad(host
, defport
, 0, address
);
1150 if (portname
[0] != '\0')
1152 if (isdigit(portname
[0] & 255))
1155 if (address
->addr
.sa_family
== AF_INET6
)
1156 address
->ipv6
.sin6_port
= htons(atoi(portname
));
1158 #endif /* AF_INET6 */
1159 address
->ipv4
.sin_port
= htons(atoi(portname
));
1163 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
1165 cupsdLogMessage(CUPSD_LOG_ERROR
, "getservbyname(\"%s\") failed - %s!",
1166 portname
, strerror(errno
));
1172 if (address
->addr
.sa_family
== AF_INET6
)
1173 address
->ipv6
.sin6_port
= htons(port
->s_port
);
1175 #endif /* AF_INET6 */
1176 address
->ipv4
.sin_port
= htons(port
->s_port
);
1186 * 'get_addr_and_mask()' - Get an IP address and netmask.
1189 static int /* O - 1 on success, 0 on failure */
1190 get_addr_and_mask(const char *value
, /* I - String from config file */
1191 unsigned *ip
, /* O - Address value */
1192 unsigned *mask
) /* O - Mask value */
1194 int i
, /* Looping var */
1195 family
, /* Address family */
1196 ipcount
; /* Count of fields in address */
1197 const char *maskval
, /* Pointer to start of mask value */
1198 *ptr
; /* Pointer into value */
1199 static unsigned netmasks
[4][4] = /* Standard netmasks... */
1201 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1202 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1203 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1204 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1209 * Get the address...
1212 memset(ip
, 0, sizeof(unsigned) * 4);
1214 if ((maskval
= strchr(value
, '/')) != NULL
)
1217 maskval
= value
+ strlen(value
);
1221 * Check for an IPv6 address...
1227 * Parse hexadecimal IPv6 address...
1232 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 4; i
++)
1236 else if (*ptr
== ':')
1239 ip
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1241 if (*ptr
== ':' || *ptr
== ']')
1247 if (*ptr
&& *ptr
!= '/')
1251 #endif /* AF_INET6 */
1254 * Parse dotted-decimal IPv4 address...
1258 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1260 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1261 ip
[0] = ip
[1] = ip
[2] = 0;
1267 * Get the netmask value(s)...
1270 memset(mask
, 0, sizeof(unsigned) * 4);
1273 if (maskval
[1] == '[')
1276 * Get hexadecimal mask value...
1279 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 4; i
++)
1283 else if (*ptr
== ':')
1286 mask
[i
] = strtoul(ptr
, (char **)&ptr
, 16);
1288 if (*ptr
== ':' || *ptr
== ']')
1296 #endif /* AF_INET6 */
1297 if (strchr(maskval
, '.'))
1300 * Get dotted-decimal mask...
1303 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1306 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1307 mask
[0] = mask
[1] = mask
[2] = 0;
1312 * Get address/bits format...
1318 if (family
== AF_INET6
)
1323 mask
[0] = 0xffffffff;
1325 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1328 mask
[1] = 0xffffffff;
1332 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1335 mask
[2] = 0xffffffff;
1339 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1342 mask
[3] = 0xffffffff;
1346 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1349 #endif /* AF_INET6 */
1353 mask
[0] = 0xffffffff;
1354 mask
[1] = 0xffffffff;
1355 mask
[2] = 0xffffffff;
1358 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1360 mask
[3] = 0xffffffff;
1365 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1367 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1368 "get_addr_and_mask(value=\"%s\", "
1369 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1370 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1374 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1377 if ((ip
[0] & ~mask
[0]) != 0 ||
1378 (ip
[1] & ~mask
[1]) != 0 ||
1379 (ip
[2] & ~mask
[2]) != 0 ||
1380 (ip
[3] & ~mask
[3]) != 0)
1388 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1391 static int /* O - 1 on success, 0 on failure */
1392 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1393 char *line
, /* I - Line from file */
1394 char *value
, /* I - Start of value data */
1395 int linenum
) /* I - Current line number */
1397 char *valptr
; /* Pointer into value */
1398 unsigned ip
[4], /* IP address components */
1399 mask
[4]; /* IP netmask components */
1402 if (!strcasecmp(line
, "Encryption"))
1405 * "Encryption xxx" - set required encryption level...
1408 if (!strcasecmp(value
, "never"))
1409 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1410 else if (!strcasecmp(value
, "always"))
1412 cupsdLogMessage(CUPSD_LOG_ERROR
,
1413 "Encryption value \"%s\" on line %d is invalid in this "
1414 "context. Using \"required\" instead.", value
, linenum
);
1416 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1418 else if (!strcasecmp(value
, "required"))
1419 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1420 else if (!strcasecmp(value
, "ifrequested"))
1421 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1424 cupsdLogMessage(CUPSD_LOG_ERROR
,
1425 "Unknown Encryption value %s on line %d.", value
, linenum
);
1429 else if (!strcasecmp(line
, "Order"))
1432 * "Order Deny,Allow" or "Order Allow,Deny"...
1435 if (!strncasecmp(value
, "deny", 4))
1436 loc
->order_type
= AUTH_ALLOW
;
1437 else if (!strncasecmp(value
, "allow", 5))
1438 loc
->order_type
= AUTH_DENY
;
1441 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1446 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1449 * Allow [From] host/ip...
1450 * Deny [From] host/ip...
1453 if (!strncasecmp(value
, "from", 4))
1456 * Strip leading "from"...
1461 while (isspace(*value
& 255))
1466 * Figure out what form the allow/deny address takes:
1477 * nnn.nnn.nnn.nnn/mm
1478 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1481 if (!strcasecmp(value
, "all"))
1487 if (!strcasecmp(line
, "Allow"))
1488 cupsdAllowIP(loc
, zeros
, zeros
);
1490 cupsdDenyIP(loc
, zeros
, zeros
);
1492 else if (!strcasecmp(value
, "none"))
1498 if (!strcasecmp(line
, "Allow"))
1499 cupsdAllowIP(loc
, ones
, zeros
);
1501 cupsdDenyIP(loc
, ones
, zeros
);
1503 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1506 * Host or domain name...
1509 if (value
[0] == '*')
1512 if (!strcasecmp(line
, "Allow"))
1513 cupsdAllowHost(loc
, value
);
1515 cupsdDenyHost(loc
, value
);
1520 * One of many IP address forms...
1523 if (!get_addr_and_mask(value
, ip
, mask
))
1525 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1530 if (!strcasecmp(line
, "Allow"))
1531 cupsdAllowIP(loc
, ip
, mask
);
1533 cupsdDenyIP(loc
, ip
, mask
);
1536 else if (!strcasecmp(line
, "AuthType"))
1539 * AuthType {none,basic,digest,basicdigest}
1542 if (!strcasecmp(value
, "none"))
1544 loc
->type
= AUTH_NONE
;
1545 loc
->level
= AUTH_ANON
;
1547 else if (!strcasecmp(value
, "basic"))
1549 loc
->type
= AUTH_BASIC
;
1551 if (loc
->level
== AUTH_ANON
)
1552 loc
->level
= AUTH_USER
;
1554 else if (!strcasecmp(value
, "digest"))
1556 loc
->type
= AUTH_DIGEST
;
1558 if (loc
->level
== AUTH_ANON
)
1559 loc
->level
= AUTH_USER
;
1561 else if (!strcasecmp(value
, "basicdigest"))
1563 loc
->type
= AUTH_BASICDIGEST
;
1565 if (loc
->level
== AUTH_ANON
)
1566 loc
->level
= AUTH_USER
;
1570 cupsdLogMessage(CUPSD_LOG_WARN
,
1571 "Unknown authorization type %s on line %d.",
1576 else if (!strcasecmp(line
, "AuthClass"))
1579 * AuthClass anonymous, user, system, group
1582 if (!strcasecmp(value
, "anonymous"))
1584 loc
->type
= AUTH_NONE
;
1585 loc
->level
= AUTH_ANON
;
1587 else if (!strcasecmp(value
, "user"))
1588 loc
->level
= AUTH_USER
;
1589 else if (!strcasecmp(value
, "group"))
1590 loc
->level
= AUTH_GROUP
;
1591 else if (!strcasecmp(value
, "system"))
1593 loc
->level
= AUTH_GROUP
;
1595 cupsdAddName(loc
, "@SYSTEM");
1599 cupsdLogMessage(CUPSD_LOG_WARN
,
1600 "Unknown authorization class %s on line %d.",
1605 else if (!strcasecmp(line
, "AuthGroupName"))
1606 cupsdAddName(loc
, value
);
1607 else if (!strcasecmp(line
, "Require"))
1610 * Apache synonym for AuthClass and AuthGroupName...
1614 * Require valid-user
1615 * Require group names
1616 * Require user names
1619 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1624 if (!strcasecmp(value
, "valid-user") ||
1625 !strcasecmp(value
, "user"))
1626 loc
->level
= AUTH_USER
;
1627 else if (!strcasecmp(value
, "group"))
1628 loc
->level
= AUTH_GROUP
;
1631 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1637 * Get the list of names from the line...
1640 for (value
= valptr
; *value
;)
1642 while (isspace(*value
& 255))
1645 if (*value
== '\"' || *value
== '\'')
1648 * Grab quoted name...
1651 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1658 * Grab literal name.
1661 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1667 cupsdAddName(loc
, value
);
1669 for (value
= valptr
; isspace(*value
& 255); value
++);
1672 else if (!strcasecmp(line
, "Satisfy"))
1674 if (!strcasecmp(value
, "all"))
1675 loc
->satisfy
= AUTH_SATISFY_ALL
;
1676 else if (!strcasecmp(value
, "any"))
1677 loc
->satisfy
= AUTH_SATISFY_ANY
;
1680 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1693 * 'read_configuration()' - Read a configuration file.
1696 static int /* O - 1 on success, 0 on failure */
1697 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1699 int i
; /* Looping var */
1700 int linenum
; /* Current line number */
1701 char line
[HTTP_MAX_BUFFER
],
1702 /* Line from file */
1703 temp
[HTTP_MAX_BUFFER
],
1704 /* Temporary buffer for value */
1705 temp2
[HTTP_MAX_BUFFER
],
1706 /* Temporary buffer 2 for value */
1707 *ptr
, /* Pointer into line/temp */
1708 *value
, /* Pointer to value */
1709 *valueptr
, /* Pointer into value */
1710 quote
; /* Quote character */
1711 int valuelen
; /* Length of value */
1712 cupsd_var_t
*var
; /* Current variable */
1713 unsigned ip
[4], /* Address value */
1714 mask
[4]; /* Netmask value */
1715 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1716 cupsd_dirsvc_poll_t
*poll
; /* Polling data */
1717 http_addr_t polladdr
; /* Polling address */
1718 cupsd_location_t
*location
; /* Browse location */
1719 cups_file_t
*incfile
; /* Include file */
1720 char incname
[1024]; /* Include filename */
1721 struct group
*group
; /* Group */
1725 * Loop through each line in the file...
1730 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1733 * Decode the directive...
1736 if (!strcasecmp(line
, "Include"))
1742 if (value
[0] == '/')
1743 strlcpy(incname
, value
, sizeof(incname
));
1745 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
1747 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
1748 cupsdLogMessage(CUPSD_LOG_ERROR
,
1749 "Unable to include config file \"%s\" - %s",
1750 incname
, strerror(errno
));
1753 read_configuration(incfile
);
1754 cupsFileClose(incfile
);
1757 else if (!strcasecmp(line
, "<Location"))
1765 linenum
= read_location(fp
, value
, linenum
);
1771 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
1776 else if (!strcasecmp(line
, "<Policy"))
1784 linenum
= read_policy(fp
, value
, linenum
);
1790 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
1794 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1797 * Add a listening address to the list...
1800 cupsd_listener_t
*lis
; /* New listeners array */
1803 if (NumListeners
== 0)
1804 lis
= malloc(sizeof(cupsd_listener_t
));
1806 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1810 cupsdLogMessage(CUPSD_LOG_ERROR
,
1811 "Unable to allocate %s at line %d - %s.",
1812 line
, linenum
, strerror(errno
));
1817 lis
+= NumListeners
;
1819 memset(lis
, 0, sizeof(cupsd_listener_t
));
1821 #if defined(AF_INET6) && !defined(__OpenBSD__)
1822 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET6
, &(lis
->address
)))
1824 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1825 #endif /* AF_INET6 && !__OpenBSD__ */
1827 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1830 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1831 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1832 ntohs(lis
->address
.ipv6
.sin6_port
));
1834 #endif /* AF_INET6 */
1836 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1837 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1839 #endif /* AF_LOCAL */
1840 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1841 ntohs(lis
->address
.ipv4
.sin_port
));
1846 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1850 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1853 * Add a listening address to the list...
1856 cupsd_listener_t
*lis
; /* New listeners array */
1859 if (NumListeners
== 0)
1860 lis
= malloc(sizeof(cupsd_listener_t
));
1862 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(cupsd_listener_t
));
1866 cupsdLogMessage(CUPSD_LOG_ERROR
,
1867 "Unable to allocate %s at line %d - %s.",
1868 line
, linenum
, strerror(errno
));
1873 lis
+= NumListeners
;
1875 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1877 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1880 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1881 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
1882 ntohs(lis
->address
.ipv6
.sin6_port
));
1884 #endif /* AF_INET6 */
1886 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
1887 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
1889 #endif /* AF_LOCAL */
1890 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
1891 ntohs(lis
->address
.ipv4
.sin_port
));
1892 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1896 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
1899 #endif /* HAVE_SSL */
1900 else if (!strcasecmp(line
, "BrowseAddress"))
1903 * Add a browse address to the list...
1906 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
1909 if (NumBrowsers
== 0)
1910 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
1912 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
1916 cupsdLogMessage(CUPSD_LOG_ERROR
,
1917 "Unable to allocate BrowseAddress at line %d - %s.",
1918 linenum
, strerror(errno
));
1923 dira
+= NumBrowsers
;
1925 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
1927 if (!strcasecmp(value
, "@LOCAL"))
1930 * Send browse data to all local interfaces...
1933 strcpy(dira
->iface
, "*");
1936 else if (!strncasecmp(value
, "@IF(", 4))
1939 * Send browse data to the named interface...
1942 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1944 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1950 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1952 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1955 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1956 cupsdLogMessage(CUPSD_LOG_INFO
,
1957 "Sending browsing info to %s:%d (IPv6)", temp
,
1958 ntohs(dira
->to
.ipv6
.sin6_port
));
1960 #endif /* AF_INET6 */
1961 cupsdLogMessage(CUPSD_LOG_INFO
, "Sending browsing info to %s:%d (IPv4)",
1962 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
1967 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
1970 else if (!strcasecmp(line
, "BrowseOrder"))
1973 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1976 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1977 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
1979 if (location
== NULL
)
1980 cupsdLogMessage(CUPSD_LOG_ERROR
,
1981 "Unable to initialize browse access control list!");
1982 else if (!strncasecmp(value
, "deny", 4))
1983 location
->order_type
= AUTH_ALLOW
;
1984 else if (!strncasecmp(value
, "allow", 5))
1985 location
->order_type
= AUTH_DENY
;
1987 cupsdLogMessage(CUPSD_LOG_ERROR
,
1988 "Unknown BrowseOrder value %s on line %d.",
1991 else if (!strcasecmp(line
, "BrowseProtocols") ||
1992 !strcasecmp(line
, "BrowseLocalProtocols") ||
1993 !strcasecmp(line
, "BrowseRemoteProtocols"))
1996 * "BrowseProtocol name [... name]"
1999 if (strcasecmp(line
, "BrowseLocalProtocols"))
2000 BrowseRemoteProtocols
= 0;
2001 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2002 BrowseLocalProtocols
= 0;
2006 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2007 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2010 if (value
[valuelen
])
2012 value
[valuelen
] = '\0';
2016 if (!strcasecmp(value
, "cups"))
2018 if (strcasecmp(line
, "BrowseLocalProtocols"))
2019 BrowseRemoteProtocols
|= BROWSE_CUPS
;
2020 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2021 BrowseLocalProtocols
|= BROWSE_CUPS
;
2023 else if (!strcasecmp(value
, "slp"))
2025 if (strcasecmp(line
, "BrowseLocalProtocols"))
2026 BrowseRemoteProtocols
|= BROWSE_SLP
;
2027 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2028 BrowseLocalProtocols
|= BROWSE_SLP
;
2030 else if (!strcasecmp(value
, "ldap"))
2032 if (strcasecmp(line
, "BrowseLocalProtocols"))
2033 BrowseRemoteProtocols
|= BROWSE_LDAP
;
2034 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2035 BrowseLocalProtocols
|= BROWSE_LDAP
;
2037 else if (!strcasecmp(value
, "all"))
2039 if (strcasecmp(line
, "BrowseLocalProtocols"))
2040 BrowseRemoteProtocols
|= BROWSE_ALL
;
2041 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2042 BrowseLocalProtocols
|= BROWSE_ALL
;
2046 cupsdLogMessage(CUPSD_LOG_ERROR
,
2047 "Unknown browse protocol \"%s\" on line %d.",
2052 for (value
+= valuelen
; *value
; value
++)
2053 if (!isspace(*value
) || *value
!= ',')
2057 else if (!strcasecmp(line
, "BrowseAllow") ||
2058 !strcasecmp(line
, "BrowseDeny"))
2061 * BrowseAllow [From] host/ip...
2062 * BrowseDeny [From] host/ip...
2065 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2066 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2068 if (location
== NULL
)
2069 cupsdLogMessage(CUPSD_LOG_ERROR
,
2070 "Unable to initialize browse access control list!");
2073 if (!strncasecmp(value
, "from ", 5))
2076 * Strip leading "from"...
2081 while (isspace(*value
))
2086 * Figure out what form the allow/deny address takes:
2097 * nnn.nnn.nnn.nnn/mm
2098 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2101 if (!strcasecmp(value
, "all"))
2107 if (!strcasecmp(line
, "BrowseAllow"))
2108 cupsdAllowIP(location
, zeros
, zeros
);
2110 cupsdDenyIP(location
, zeros
, zeros
);
2112 else if (!strcasecmp(value
, "none"))
2118 if (!strcasecmp(line
, "BrowseAllow"))
2119 cupsdAllowIP(location
, ones
, zeros
);
2121 cupsdDenyIP(location
, ones
, zeros
);
2123 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2126 * Host or domain name...
2129 if (value
[0] == '*')
2132 if (!strcasecmp(line
, "BrowseAllow"))
2133 cupsdAllowHost(location
, value
);
2135 cupsdDenyHost(location
, value
);
2140 * One of many IP address forms...
2143 if (!get_addr_and_mask(value
, ip
, mask
))
2145 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2150 if (!strcasecmp(line
, "BrowseAllow"))
2151 cupsdAllowIP(location
, ip
, mask
);
2153 cupsdDenyIP(location
, ip
, mask
);
2157 else if (!strcasecmp(line
, "BrowseRelay"))
2160 * BrowseRelay [from] source [to] destination
2164 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2166 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2170 cupsdLogMessage(CUPSD_LOG_ERROR
,
2171 "Unable to allocate BrowseRelay at line %d - %s.",
2172 linenum
, strerror(errno
));
2179 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2181 if (!strncasecmp(value
, "from ", 5))
2184 * Strip leading "from"...
2189 while (isspace(*value
))
2194 * Figure out what form the from address takes:
2203 * nnn.nnn.nnn.nnn/mm
2204 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2207 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2210 * Host or domain name...
2213 if (value
[0] == '*')
2216 strlcpy(temp
, value
, sizeof(temp
));
2217 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2220 relay
->from
.type
= AUTH_NAME
;
2221 relay
->from
.mask
.name
.name
= strdup(temp
);
2222 relay
->from
.mask
.name
.length
= strlen(temp
);
2227 * One of many IP address forms...
2230 if (!get_addr_and_mask(value
, ip
, mask
))
2232 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2237 relay
->from
.type
= AUTH_IP
;
2238 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2239 sizeof(relay
->from
.mask
.ip
.address
));
2240 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2241 sizeof(relay
->from
.mask
.ip
.netmask
));
2245 * Skip value and trailing whitespace...
2248 for (; *value
; value
++)
2249 if (isspace(*value
))
2252 while (isspace(*value
))
2255 if (!strncasecmp(value
, "to ", 3))
2258 * Strip leading "to"...
2263 while (isspace(*value
))
2268 * Get "to" address and port...
2271 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
2273 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2275 if (relay
->from
.type
== AUTH_IP
)
2276 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2277 relay
->from
.mask
.ip
.address
[0],
2278 relay
->from
.mask
.ip
.address
[1],
2279 relay
->from
.mask
.ip
.address
[2],
2280 relay
->from
.mask
.ip
.address
[3],
2281 relay
->from
.mask
.ip
.netmask
[0],
2282 relay
->from
.mask
.ip
.netmask
[1],
2283 relay
->from
.mask
.ip
.netmask
[2],
2284 relay
->from
.mask
.ip
.netmask
[3]);
2286 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2289 if (relay
->to
.addr
.sa_family
== AF_INET6
)
2290 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv6)",
2291 temp
, temp2
, ntohs(relay
->to
.ipv6
.sin6_port
));
2293 #endif /* AF_INET6 */
2294 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2295 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2301 if (relay
->from
.type
== AUTH_NAME
)
2302 free(relay
->from
.mask
.name
.name
);
2304 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2308 else if (!strcasecmp(line
, "BrowsePoll"))
2311 * BrowsePoll address[:port]
2315 poll
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2317 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2321 cupsdLogMessage(CUPSD_LOG_ERROR
,
2322 "Unable to allocate BrowsePoll at line %d - %s.",
2323 linenum
, strerror(errno
));
2331 * Get poll address and port...
2334 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
2337 memset(poll
, 0, sizeof(cupsd_dirsvc_poll_t
));
2339 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
2342 if (polladdr
.addr
.sa_family
== AF_INET6
)
2343 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
2345 #endif /* AF_INET6 */
2346 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
2348 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", poll
->hostname
,
2352 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad poll address %s at line %d.",
2355 else if (!strcasecmp(line
, "DefaultAuthType"))
2358 * DefaultAuthType {basic,digest,basicdigest}
2361 if (!strcasecmp(value
, "basic"))
2362 DefaultAuthType
= AUTH_BASIC
;
2363 else if (!strcasecmp(value
, "digest"))
2364 DefaultAuthType
= AUTH_DIGEST
;
2365 else if (!strcasecmp(value
, "basicdigest"))
2366 DefaultAuthType
= AUTH_BASICDIGEST
;
2369 cupsdLogMessage(CUPSD_LOG_WARN
,
2370 "Unknown default authorization type %s on line %d.",
2375 else if (!strcasecmp(line
, "User"))
2378 * User ID to run as...
2381 if (isdigit(value
[0]))
2385 struct passwd
*p
; /* Password information */
2388 p
= getpwnam(value
);
2393 cupsdLogMessage(CUPSD_LOG_ERROR
,
2394 "Unknown User \"%s\" on line %d, ignoring!",
2398 else if (!strcasecmp(line
, "Group"))
2401 * Group ID to run as...
2404 if (isdigit(value
[0]))
2405 Group
= atoi(value
);
2409 group
= getgrnam(value
);
2412 Group
= group
->gr_gid
;
2414 cupsdLogMessage(CUPSD_LOG_ERROR
,
2415 "Unknown Group \"%s\" on line %d, ignoring!",
2419 else if (!strcasecmp(line
, "SystemGroup"))
2422 * System (admin) group(s)...
2425 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
;)
2427 if (*value
== '\'' || *value
== '\"')
2430 * Scan quoted name...
2435 for (valueptr
= value
; *valueptr
; valueptr
++)
2436 if (*valueptr
== quote
)
2442 * Scan space or comma-delimited name...
2445 for (valueptr
= value
; *valueptr
; valueptr
++)
2446 if (isspace(*valueptr
) || *valueptr
== ',')
2453 group
= getgrnam(value
);
2456 cupsdSetString(SystemGroups
+ i
, value
);
2457 SystemGroupIDs
[i
] = group
->gr_gid
;
2462 cupsdLogMessage(CUPSD_LOG_ERROR
,
2463 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2470 while (*value
== ',' || isspace(*value
))
2475 NumSystemGroups
= i
;
2477 else if (!strcasecmp(line
, "HostNameLookups"))
2480 * Do hostname lookups?
2483 if (!strcasecmp(value
, "off"))
2484 HostNameLookups
= 0;
2485 else if (!strcasecmp(value
, "on"))
2486 HostNameLookups
= 1;
2487 else if (!strcasecmp(value
, "double"))
2488 HostNameLookups
= 2;
2490 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2493 else if (!strcasecmp(line
, "LogLevel"))
2496 * Amount of logging to do...
2499 if (!strcasecmp(value
, "debug2"))
2500 LogLevel
= CUPSD_LOG_DEBUG2
;
2501 else if (!strcasecmp(value
, "debug"))
2502 LogLevel
= CUPSD_LOG_DEBUG
;
2503 else if (!strcasecmp(value
, "info"))
2504 LogLevel
= CUPSD_LOG_INFO
;
2505 else if (!strcasecmp(value
, "notice"))
2506 LogLevel
= CUPSD_LOG_NOTICE
;
2507 else if (!strcasecmp(value
, "warn"))
2508 LogLevel
= CUPSD_LOG_WARN
;
2509 else if (!strcasecmp(value
, "error"))
2510 LogLevel
= CUPSD_LOG_ERROR
;
2511 else if (!strcasecmp(value
, "crit"))
2512 LogLevel
= CUPSD_LOG_CRIT
;
2513 else if (!strcasecmp(value
, "alert"))
2514 LogLevel
= CUPSD_LOG_ALERT
;
2515 else if (!strcasecmp(value
, "emerg"))
2516 LogLevel
= CUPSD_LOG_EMERG
;
2517 else if (!strcasecmp(value
, "none"))
2518 LogLevel
= CUPSD_LOG_NONE
;
2520 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2523 else if (!strcasecmp(line
, "PrintcapFormat"))
2526 * Format of printcap file?
2529 if (!strcasecmp(value
, "bsd"))
2530 PrintcapFormat
= PRINTCAP_BSD
;
2531 else if (!strcasecmp(value
, "solaris"))
2532 PrintcapFormat
= PRINTCAP_SOLARIS
;
2534 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2537 else if (!strcasecmp(line
, "ServerTokens"))
2540 * Set the string used for the Server header...
2543 struct utsname plat
; /* Platform info */
2548 if (!strcasecmp(value
, "ProductOnly"))
2549 cupsdSetString(&ServerHeader
, "CUPS");
2550 else if (!strcasecmp(value
, "Major"))
2551 cupsdSetString(&ServerHeader
, "CUPS/1");
2552 else if (!strcasecmp(value
, "Minor"))
2553 cupsdSetString(&ServerHeader
, "CUPS/1.1");
2554 else if (!strcasecmp(value
, "Minimal"))
2555 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2556 else if (!strcasecmp(value
, "OS"))
2557 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2558 else if (!strcasecmp(value
, "Full"))
2559 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2561 else if (!strcasecmp(value
, "None"))
2562 cupsdClearString(&ServerHeader
);
2564 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2567 else if (!strcasecmp(line
, "PassEnv"))
2570 * PassEnv variable [... variable]
2575 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2576 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2579 if (value
[valuelen
])
2581 value
[valuelen
] = '\0';
2585 cupsdSetEnv(value
, NULL
);
2587 for (value
+= valuelen
; *value
; value
++)
2588 if (!isspace(*value
) || *value
!= ',')
2592 else if (!strcasecmp(line
, "SetEnv"))
2595 * SetEnv variable value
2598 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2606 while (isspace(*valueptr
& 255))
2609 cupsdSetEnv(value
, valueptr
);
2612 cupsdLogMessage(CUPSD_LOG_ERROR
,
2613 "Missing value for SetEnv directive on line %d.",
2619 * Find a simple variable in the list...
2622 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2623 if (!strcasecmp(line
, var
->name
))
2629 * Unknown directive! Output an error message and continue...
2632 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2639 case CUPSD_VARTYPE_INTEGER
:
2642 char *units
; /* Units */
2645 n
= strtol(value
, &units
, 0);
2647 if (units
&& *units
)
2649 if (tolower(units
[0] & 255) == 'g')
2650 n
*= 1024 * 1024 * 1024;
2651 else if (tolower(units
[0] & 255) == 'm')
2653 else if (tolower(units
[0] & 255) == 'k')
2655 else if (tolower(units
[0] & 255) == 't')
2659 *((int *)var
->ptr
) = n
;
2663 case CUPSD_VARTYPE_BOOLEAN
:
2664 if (!strcasecmp(value
, "true") ||
2665 !strcasecmp(value
, "on") ||
2666 !strcasecmp(value
, "enabled") ||
2667 !strcasecmp(value
, "yes") ||
2669 *((int *)var
->ptr
) = TRUE
;
2670 else if (!strcasecmp(value
, "false") ||
2671 !strcasecmp(value
, "off") ||
2672 !strcasecmp(value
, "disabled") ||
2673 !strcasecmp(value
, "no") ||
2674 !strcasecmp(value
, "0"))
2675 *((int *)var
->ptr
) = FALSE
;
2677 cupsdLogMessage(CUPSD_LOG_ERROR
,
2678 "Unknown boolean value %s on line %d.",
2682 case CUPSD_VARTYPE_STRING
:
2683 cupsdSetString((char **)var
->ptr
, value
);
2694 * 'read_location()' - Read a <Location path> definition.
2697 static int /* O - New line number or 0 on error */
2698 read_location(cups_file_t
*fp
, /* I - Configuration file */
2699 char *location
, /* I - Location name/path */
2700 int linenum
) /* I - Current line number */
2702 cupsd_location_t
*loc
, /* New location */
2703 *parent
; /* Parent location */
2704 char line
[HTTP_MAX_BUFFER
],
2706 *value
, /* Value for directive */
2707 *valptr
; /* Pointer into value */
2710 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2713 parent
->limit
= AUTH_LIMIT_ALL
;
2716 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2719 * Decode the directive...
2722 if (!strcasecmp(line
, "</Location>"))
2724 else if (!strcasecmp(line
, "<Limit") ||
2725 !strcasecmp(line
, "<LimitExcept"))
2729 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2733 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
2739 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2744 if (!strcmp(value
, "ALL"))
2745 loc
->limit
= AUTH_LIMIT_ALL
;
2746 else if (!strcmp(value
, "GET"))
2747 loc
->limit
|= AUTH_LIMIT_GET
;
2748 else if (!strcmp(value
, "HEAD"))
2749 loc
->limit
|= AUTH_LIMIT_HEAD
;
2750 else if (!strcmp(value
, "OPTIONS"))
2751 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
2752 else if (!strcmp(value
, "POST"))
2753 loc
->limit
|= AUTH_LIMIT_POST
;
2754 else if (!strcmp(value
, "PUT"))
2755 loc
->limit
|= AUTH_LIMIT_PUT
;
2756 else if (!strcmp(value
, "TRACE"))
2757 loc
->limit
|= AUTH_LIMIT_TRACE
;
2759 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
2762 for (value
= valptr
; isspace(*value
& 255); value
++);
2765 if (!strcasecmp(line
, "<LimitExcept"))
2766 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
2768 parent
->limit
&= ~loc
->limit
;
2770 else if (!strcasecmp(line
, "</Limit>"))
2772 else if (!parse_aaa(loc
, line
, value
, linenum
))
2774 cupsdLogMessage(CUPSD_LOG_ERROR
,
2775 "Unknown Location directive %s on line %d.",
2781 cupsdLogMessage(CUPSD_LOG_ERROR
,
2782 "Unexpected end-of-file at line %d while reading location!",
2790 * 'read_policy()' - Read a <Policy name> definition.
2793 static int /* O - New line number or 0 on error */
2794 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2795 char *policy
, /* I - Location name/path */
2796 int linenum
) /* I - Current line number */
2798 int i
; /* Looping var */
2799 cupsd_policy_t
*pol
; /* Policy */
2800 cupsd_location_t
*op
; /* Policy operation */
2801 int num_ops
; /* Number of IPP operations */
2802 ipp_op_t ops
[100]; /* Operations */
2803 char line
[HTTP_MAX_BUFFER
],
2805 *value
, /* Value for directive */
2806 *valptr
; /* Pointer into value */
2810 * Create the policy...
2813 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
2817 * Read from the file...
2823 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2826 * Decode the directive...
2829 if (!strcasecmp(line
, "</Policy>"))
2832 cupsdLogMessage(CUPSD_LOG_WARN
,
2833 "Missing </Limit> before </Policy> on line %d!",
2838 else if (!strcasecmp(line
, "<Limit") && !op
)
2842 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2847 * Scan for IPP operation names...
2854 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2859 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2861 if (!strcasecmp(value
, "All"))
2862 ops
[num_ops
] = IPP_ANY_OPERATION
;
2863 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
2864 cupsdLogMessage(CUPSD_LOG_ERROR
,
2865 "Bad IPP operation name \"%s\" on line %d!",
2871 cupsdLogMessage(CUPSD_LOG_ERROR
,
2872 "Too many operations listed on line %d!",
2875 for (value
= valptr
; isspace(*value
& 255); value
++);
2879 * If none are specified, apply the policy to all operations...
2884 ops
[0] = IPP_ANY_OPERATION
;
2889 * Add a new policy for the first operation...
2892 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
2894 else if (!strcasecmp(line
, "</Limit>") && op
)
2897 * Finish the current operation limit...
2903 * Copy the policy to the other operations...
2906 for (i
= 1; i
< num_ops
; i
++)
2907 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
2914 cupsdLogMessage(CUPSD_LOG_ERROR
,
2915 "Missing <Limit ops> directive before %s on line %d.",
2919 else if (!parse_aaa(op
, line
, value
, linenum
))
2922 cupsdLogMessage(CUPSD_LOG_ERROR
,
2923 "Unknown Policy Limit directive %s on line %d.",
2926 cupsdLogMessage(CUPSD_LOG_ERROR
,
2927 "Unknown Policy directive %s on line %d.",
2934 cupsdLogMessage(CUPSD_LOG_ERROR
,
2935 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2944 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2945 * required by SSLSetCertificate.
2947 * For now we assumes that there is exactly one SecIdentity in the
2948 * keychain - i.e. there is exactly one matching cert/private key pair.
2949 * In the future we will search a keychain for a SecIdentity matching a
2950 * specific criteria. We also skip the operation of adding additional
2951 * non-signing certs from the keychain to the CFArrayRef.
2953 * To create a self-signed certificate for testing use the certtool.
2954 * Executing the following as root will do it:
2956 * certtool c c v k=CUPS
2960 CDSAGetServerCerts(void)
2962 OSStatus err
; /* Error info */
2963 SecKeychainRef kcRef
; /* Keychain reference */
2964 SecIdentitySearchRef srchRef
; /* Search reference */
2965 SecIdentityRef identity
; /* Identity */
2966 CFArrayRef ca
; /* Certificate array */
2973 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2976 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot open keychain \"%s\", error %d.",
2977 ServerCertificate
, err
);
2981 * Search for "any" identity matching specified key use;
2982 * in this app, we expect there to be exactly one.
2985 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2988 cupsdLogMessage(CUPSD_LOG_ERROR
,
2989 "Cannot find signing key in keychain \"%s\", error %d",
2990 ServerCertificate
, err
);
2993 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2996 cupsdLogMessage(CUPSD_LOG_ERROR
,
2997 "Cannot find signing key in keychain \"%s\", error %d",
2998 ServerCertificate
, err
);
3001 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
3002 cupsdLogMessage(CUPSD_LOG_ERROR
,
3003 "SecIdentitySearchCopyNext CFTypeID failure!");
3007 * Found one. Place it in a CFArray.
3008 * TBD: snag other (non-identity) certs from keychain and add them
3012 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
3015 cupsdLogMessage(CUPSD_LOG_ERROR
, "CFArrayCreate error");
3018 /*CFRelease(identity);*/
3021 /*CFRelease(srchRef);*/
3024 /*CFRelease(kcRef);*/
3029 #endif /* HAVE_CDSASSL */