2 * "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
19 * cupsdReadConfiguration() - Read the cupsd.conf file.
20 * get_address() - Get an address + port number from a line.
21 * get_addr_and_mask() - Get an IP address and netmask.
22 * parse_aaa() - Parse authentication, authorization, and
23 * access control lines.
24 * parse_fatal_errors() - Parse FatalErrors values in a string.
25 * parse_groups() - Parse system group names in a string.
26 * parse_protocols() - Parse browse protocols in a string.
27 * read_configuration() - Read a configuration file.
28 * read_location() - Read a <Location path> definition.
29 * read_policy() - Read a <Policy name> definition.
33 * Include necessary headers...
39 #include <sys/utsname.h>
44 * Possibly missing network definitions...
48 # define INADDR_NONE 0xffffffff
49 #endif /* !INADDR_NONE */
53 * Configuration variable structure...
58 CUPSD_VARTYPE_INTEGER
, /* Integer option */
59 CUPSD_VARTYPE_STRING
, /* String option */
60 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
61 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
66 char *name
; /* Name of variable */
67 void *ptr
; /* Pointer to variable */
68 cupsd_vartype_t type
; /* Type (int, string, address) */
76 static const cupsd_var_t variables
[] =
78 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
80 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
81 #endif /* __APPLE__ */
82 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
83 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
85 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
87 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
88 # endif /* HAVE_LDAP_SSL */
89 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
90 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
91 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
92 #endif /* HAVE_LDAP */
93 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
94 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
95 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
96 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
97 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
98 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
99 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
100 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
101 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
102 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
103 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
104 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
105 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
106 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
107 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
108 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
109 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
110 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
111 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
112 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
113 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
114 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
115 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
116 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
117 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
118 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
120 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
121 #endif /* HAVE_GSSAPI */
122 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
123 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
124 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
125 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
126 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
127 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
128 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
130 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
131 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
132 #endif /* HAVE_LAUNCHD */
133 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
134 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
135 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
136 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
137 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
153 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
154 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
155 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
156 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
157 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
158 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
159 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
160 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
161 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
162 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
163 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
164 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
165 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
167 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
168 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
169 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
170 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
171 #endif /* HAVE_SSL */
172 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
173 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
174 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
175 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
176 #ifdef HAVE_AUTHORIZATION_H
177 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
178 #endif /* HAVE_AUTHORIZATION_H */
179 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
180 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
181 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
183 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
186 static const unsigned ones
[4] =
188 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
190 static const unsigned zeros
[4] =
192 0x00000000, 0x00000000, 0x00000000, 0x00000000
199 static http_addrlist_t
*get_address(const char *value
, int defport
);
200 static int get_addr_and_mask(const char *value
, unsigned *ip
,
202 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
203 char *value
, int linenum
);
204 static int parse_fatal_errors(const char *s
);
205 static int parse_groups(const char *s
);
206 static int parse_protocols(const char *s
);
207 static int read_configuration(cups_file_t
*fp
);
208 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
209 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
213 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
216 int /* O - 0 on success, -1 on error, 1 on warning */
217 cupsdCheckPermissions(
218 const char *filename
, /* I - File/directory name */
219 const char *suffix
, /* I - Additional file/directory name */
220 int mode
, /* I - Permissions */
221 int user
, /* I - Owner */
222 int group
, /* I - Group */
223 int is_dir
, /* I - 1 = directory, 0 = file */
224 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
226 int dir_created
= 0; /* Did we create a directory? */
227 char pathname
[1024]; /* File name with prefix */
228 struct stat fileinfo
; /* Stat buffer */
229 int is_symlink
; /* Is "filename" a symlink? */
233 * Prepend the given root to the filename before testing it...
238 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
243 * See if we can stat the file/directory...
246 if (lstat(filename
, &fileinfo
))
248 if (errno
== ENOENT
&& create_dir
)
251 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
254 if (mkdir(filename
, mode
))
257 cupsdLogMessage(CUPSD_LOG_ERROR
,
258 "Unable to create directory \"%s\" - %s", filename
,
261 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
270 return (create_dir
? -1 : 1);
273 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
275 if (stat(filename
, &fileinfo
))
277 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
278 filename
, strerror(errno
));
284 * Make sure it's a regular file or a directory as needed...
287 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
289 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
293 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
296 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
298 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
304 * If the filename is a symlink, do not change permissions (STR #2937)...
311 * Fix owner, group, and mode as needed...
314 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
317 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
320 if (chown(filename
, user
, group
) && !getuid())
323 cupsdLogMessage(CUPSD_LOG_ERROR
,
324 "Unable to change ownership of \"%s\" - %s", filename
,
327 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
334 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
337 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
340 if (chmod(filename
, mode
))
343 cupsdLogMessage(CUPSD_LOG_ERROR
,
344 "Unable to change permissions of \"%s\" - %s", filename
,
347 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
355 * Everything is OK...
363 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
366 int /* O - 1 on success, 0 otherwise */
367 cupsdReadConfiguration(void)
369 int i
; /* Looping var */
370 cups_file_t
*fp
; /* Configuration file */
371 int status
; /* Return status */
372 char temp
[1024], /* Temporary buffer */
373 mimedir
[1024], /* MIME directory */
374 *slash
; /* Directory separator */
375 cups_lang_t
*language
; /* Language */
376 struct passwd
*user
; /* Default user */
377 struct group
*group
; /* Default group */
378 char *old_serverroot
, /* Old ServerRoot */
379 *old_requestroot
; /* Old RequestRoot */
380 const char *tmpdir
; /* TMPDIR environment variable */
381 struct stat tmpinfo
; /* Temporary directory info */
382 cupsd_policy_t
*p
; /* Policy */
386 * Save the old root paths...
389 old_serverroot
= NULL
;
390 cupsdSetString(&old_serverroot
, ServerRoot
);
391 old_requestroot
= NULL
;
392 cupsdSetString(&old_requestroot
, RequestRoot
);
395 * Reset the server configuration data...
398 cupsdDeleteAllLocations();
417 for (i
= 0; i
< NumRelays
; i
++)
418 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
419 free(Relays
[i
].from
.mask
.name
.name
);
426 cupsdDeleteAllListeners();
432 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
433 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
434 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
435 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
436 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
437 cupsdSetString(&DataDir
, CUPS_DATADIR
);
438 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
439 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
440 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
441 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
442 cupsdSetString(&PageLogFormat
,
443 "%p %j %u %T %P %C %{job-billing} "
444 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
445 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
446 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
447 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
448 cupsdSetString(&RemoteRoot
, "remroot");
449 cupsdSetString(&ServerHeader
, "CUPS/1.4");
450 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
452 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
453 #endif /* HAVE_GSSAPI */
455 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
456 PrintcapFormat
= PRINTCAP_SOLARIS
;
457 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
458 "/Library/Preferences/org.cups.printers.plist"))
459 PrintcapFormat
= PRINTCAP_PLIST
;
461 PrintcapFormat
= PRINTCAP_BSD
;
463 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
464 if ((slash
= strrchr(temp
, '/')) != NULL
)
467 cupsdSetString(&ServerRoot
, temp
);
469 cupsdClearString(&Classification
);
470 ClassifyOverride
= 0;
474 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
476 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
477 cupsdSetString(&ServerKey
, "ssl/server.key");
478 # endif /* HAVE_CDSASSL */
479 #endif /* HAVE_SSL */
481 language
= cupsLangDefault();
483 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
484 cupsdSetString(&DefaultLanguage
, "en");
486 cupsdSetString(&DefaultLanguage
, language
->language
);
488 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
490 cupsdClearString(&DefaultPaperSize
);
492 cupsdSetString(&RIPCache
, "8m");
494 cupsdSetString(&TempDir
, NULL
);
497 * Find the default user...
500 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
505 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
506 * complement number...)
515 * Find the default group...
518 group
= getgrnam(CUPS_DEFAULT_GROUP
);
522 Group
= group
->gr_gid
;
526 * Fallback to group "nobody"...
529 group
= getgrnam("nobody");
533 Group
= group
->gr_gid
;
537 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
538 * complement number...)
549 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
550 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
551 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
552 DefaultAuthType
= CUPSD_AUTH_BASIC
;
554 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
555 SSLOptions
= CUPSD_SSL_NONE
;
556 #endif /* HAVE_SSL */
557 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
559 JobRetryInterval
= 300;
564 HostNameLookups
= FALSE
;
565 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
566 ImplicitAnyClasses
= FALSE
;
567 HideImplicitMembers
= TRUE
;
569 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
570 ListenBackLog
= SOMAXCONN
;
571 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
572 LogLevel
= CUPSD_LOG_WARN
;
574 MaxClientsPerHost
= 0;
575 MaxLogSize
= 1024 * 1024;
576 MaxPrinterHistory
= 10;
578 ReloadTimeout
= DEFAULT_KEEPALIVE
;
579 RootCertDuration
= 300;
580 Timeout
= DEFAULT_TIMEOUT
;
583 BrowseInterval
= DEFAULT_INTERVAL
;
584 BrowsePort
= ippPort();
585 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
586 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
587 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
588 BrowseTimeout
= DEFAULT_TIMEOUT
;
590 Browsing
= CUPS_DEFAULT_BROWSING
;
591 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
593 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
594 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
596 cupsdClearString(&BrowseLocalOptions
);
597 cupsdClearString(&BrowseRemoteOptions
);
599 cupsdSetString(&ErrorPolicy
, "stop-printer");
602 cupsdClearString(&BrowseLDAPBindDN
);
603 cupsdClearString(&BrowseLDAPDN
);
604 cupsdClearString(&BrowseLDAPPassword
);
605 cupsdClearString(&BrowseLDAPServer
);
606 # ifdef HAVE_LDAP_SSL
607 cupsdClearString(&BrowseLDAPCACertFile
);
608 # endif /* HAVE_LDAP_SSL */
609 #endif /* HAVE_LDAP */
611 JobHistory
= DEFAULT_HISTORY
;
612 JobFiles
= DEFAULT_FILES
;
617 MaxJobsPerPrinter
= 0;
618 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
620 cupsdDeleteAllPolicies();
621 cupsdClearString(&DefaultPolicy
);
623 #ifdef HAVE_AUTHORIZATION_H
624 cupsdClearString(&SystemGroupAuthKey
);
625 #endif /* HAVE_AUTHORIZATION_H */
627 MaxSubscriptions
= 100;
628 MaxSubscriptionsPerJob
= 0;
629 MaxSubscriptionsPerPrinter
= 0;
630 MaxSubscriptionsPerUser
= 0;
631 DefaultLeaseDuration
= 86400;
632 MaxLeaseDuration
= 0;
635 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
636 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
637 #endif /* HAVE_LAUNCHD */
641 #endif /* __APPLE__ */
644 * Read the configuration file...
647 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
650 status
= read_configuration(fp
);
660 * See if the ServerName is an IP address...
663 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
665 ServerNameIsIP
= !*slash
;
668 * Use the default system group if none was supplied in cupsd.conf...
671 if (NumSystemGroups
== 0)
673 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
676 * Find the group associated with GID 0...
683 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
685 cupsdSetString(&SystemGroups
[0], "unknown");
687 SystemGroupIDs
[0] = 0;
693 * Get the access control list for browsing...
696 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
699 * Open the system log for cupsd if necessary...
703 if (!strcmp(AccessLog
, "syslog") ||
704 !strcmp(ErrorLog
, "syslog") ||
705 !strcmp(PageLog
, "syslog"))
706 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
707 #endif /* HAVE_VSYSLOG */
710 * Log the configuration file that was used...
713 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
717 * Validate the Group and SystemGroup settings - they cannot be the same,
718 * otherwise the CGI programs will be able to authenticate as root without
724 for (i
= 0; i
< NumSystemGroups
; i
++)
725 if (Group
== SystemGroupIDs
[i
])
728 if (i
< NumSystemGroups
)
731 * Log the error and reset the group to a safe value...
734 cupsdLogMessage(CUPSD_LOG_NOTICE
,
735 "Group and SystemGroup cannot use the same groups!");
736 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
738 group
= getgrnam("nobody");
742 Group
= group
->gr_gid
;
746 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
747 * complement number...)
756 * Check that we have at least one listen/port line; if not, report this
757 * as an error and exit!
760 if (cupsArrayCount(Listeners
) == 0)
766 cupsdLogMessage(CUPSD_LOG_EMERG
,
767 "No valid Listen or Port lines were found in the "
768 "configuration file!");
774 cupsdEndProcess(getpid(), 0);
778 * Set the default locale using the language and charset...
781 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
784 * Update all relative filenames to include the full path from ServerRoot...
787 if (DocumentRoot
[0] != '/')
788 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
790 if (RequestRoot
[0] != '/')
791 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
793 if (ServerBin
[0] != '/')
794 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
796 if (StateDir
[0] != '/')
797 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
799 if (CacheDir
[0] != '/')
800 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
803 if (ServerCertificate
[0] != '/')
804 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
806 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
807 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
809 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
812 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
813 if (ServerKey
[0] != '/')
814 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
816 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
817 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
818 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
820 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
821 #endif /* HAVE_SSL */
824 * Make sure that directories and config files are owned and
825 * writable by the user and group in the cupsd.conf file...
828 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
830 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
832 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
834 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
836 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
838 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
839 SystemGroupIDs
[0], 1, 1) < 0 ||
840 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
842 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
844 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
846 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
848 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
850 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
852 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
854 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
858 * Update TempDir to the default if it hasn't been set already...
863 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
866 * TMPDIR is defined, see if it is OK for us to use...
869 if (stat(tmpdir
, &tmpinfo
))
870 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
871 tmpdir
, strerror(errno
));
872 else if (!S_ISDIR(tmpinfo
.st_mode
))
873 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
875 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
876 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
877 !(tmpinfo
.st_mode
& S_IWOTH
))
878 cupsdLogMessage(CUPSD_LOG_ERROR
,
879 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
881 cupsdSetString(&TempDir
, tmpdir
);
886 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
888 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
893 * Make sure the temporary directory has the right permissions...
896 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
900 * Update ownership and permissions if the CUPS temp directory
901 * is under the spool directory or does not exist...
904 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
905 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
910 * Setup environment variables...
916 * Update default paper size setting as needed...
919 if (!DefaultPaperSize
)
922 char *paper_result
; /* Paper size name from libpaper */
924 if ((paper_result
= systempapername()) != NULL
)
925 cupsdSetString(&DefaultPaperSize
, paper_result
);
927 #endif /* HAVE_LIBPAPER */
928 if (!DefaultLanguage
||
929 !strcasecmp(DefaultLanguage
, "C") ||
930 !strcasecmp(DefaultLanguage
, "POSIX") ||
931 !strcasecmp(DefaultLanguage
, "en") ||
932 !strncasecmp(DefaultLanguage
, "en.", 3) ||
933 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
934 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
935 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
938 * These are the only locales that will default to "letter" size...
941 cupsdSetString(&DefaultPaperSize
, "Letter");
944 cupsdSetString(&DefaultPaperSize
, "A4");
948 * Update classification setting as needed...
951 if (Classification
&& !strcasecmp(Classification
, "none"))
952 cupsdClearString(&Classification
);
955 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
958 * Check the MaxClients setting, and then allocate memory for it...
961 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
964 cupsdLogMessage(CUPSD_LOG_INFO
,
965 "MaxClients limited to 1/3 (%d) of the file descriptor "
969 MaxClients
= MaxFDs
/ 3;
972 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
976 * Check the MaxActiveJobs setting; limit to 1/3 the available
977 * file descriptors, since we need a pipe for each job...
980 if (MaxActiveJobs
> (MaxFDs
/ 3))
981 MaxActiveJobs
= MaxFDs
/ 3;
984 * Update the MaxClientsPerHost value, as needed...
987 if (MaxClientsPerHost
<= 0)
988 MaxClientsPerHost
= MaxClients
;
990 if (MaxClientsPerHost
> MaxClients
)
991 MaxClientsPerHost
= MaxClients
;
993 cupsdLogMessage(CUPSD_LOG_INFO
,
994 "Allowing up to %d client connections per host.",
998 * Make sure that BrowseTimeout is at least twice the interval...
1001 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1003 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1007 BrowseTimeout
= BrowseInterval
* 2;
1009 BrowseTimeout
= DEFAULT_TIMEOUT
;
1011 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1016 * Update the default policy, as needed...
1020 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1022 DefaultPolicyPtr
= NULL
;
1024 if (!DefaultPolicyPtr
)
1026 cupsd_location_t
*po
; /* New policy operation */
1030 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1033 cupsdSetString(&DefaultPolicy
, "default");
1035 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1036 cupsdLogMessage(CUPSD_LOG_INFO
,
1037 "Using policy \"default\" as the default!");
1040 cupsdLogMessage(CUPSD_LOG_INFO
,
1041 "Creating CUPS default administrative policy:");
1043 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1045 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1046 cupsdLogMessage(CUPSD_LOG_INFO
,
1047 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1048 "Release-Job Restart-Job Purge-Jobs "
1049 "Set-Job-Attributes Create-Job-Subscription "
1050 "Renew-Subscription Cancel-Subscription "
1051 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1052 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1053 "CUPS-Authenticate-Job CUPS-Get-Document>");
1054 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1056 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1057 po
->order_type
= CUPSD_AUTH_ALLOW
;
1058 po
->level
= CUPSD_AUTH_USER
;
1060 cupsdAddName(po
, "@OWNER");
1061 cupsdAddName(po
, "@SYSTEM");
1062 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1064 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1065 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1066 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1067 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1068 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1069 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1070 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1071 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1072 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1073 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1074 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1075 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1076 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1077 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1078 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1079 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1080 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1081 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1085 cupsdLogMessage(CUPSD_LOG_INFO
,
1086 "<Limit Pause-Printer Resume-Printer "
1087 "Set-Printer-Attributes Enable-Printer "
1088 "Disable-Printer Pause-Printer-After-Current-Job "
1089 "Hold-New-Jobs Release-Held-New-Jobs "
1090 "Deactivate-Printer Activate-Printer Restart-Printer "
1091 "Shutdown-Printer Startup-Printer Promote-Job "
1092 "Schedule-Job-After CUPS-Add-Printer "
1093 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1094 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1095 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1096 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1098 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1099 po
->order_type
= CUPSD_AUTH_ALLOW
;
1100 po
->type
= CUPSD_AUTH_DEFAULT
;
1101 po
->level
= CUPSD_AUTH_USER
;
1103 cupsdAddName(po
, "@SYSTEM");
1104 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1106 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1107 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1108 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1109 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1110 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1111 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1112 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1113 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1114 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1115 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1116 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1117 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1118 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1119 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1120 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1121 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1122 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1123 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1124 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1125 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1126 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1128 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1130 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1131 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1133 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1134 po
->order_type
= CUPSD_AUTH_ALLOW
;
1136 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1137 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1141 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1142 cupsArrayCount(Policies
));
1143 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1145 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1146 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1147 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1150 * If we are doing a full reload or the server root has changed, flush
1151 * the jobs, printers, etc. and start from scratch...
1154 if (NeedReload
== RELOAD_ALL
||
1155 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1156 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1158 mime_type_t
*type
; /* Current type */
1159 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1160 /* MIME type name */
1163 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1166 * Free all memory...
1169 cupsdDeleteAllSubscriptions();
1171 cupsdDeleteAllPrinters();
1173 DefaultPrinter
= NULL
;
1175 if (MimeDatabase
!= NULL
)
1176 mimeDelete(MimeDatabase
);
1180 for (i
= 0; i
< NumMimeTypes
; i
++)
1181 _cupsStrFree(MimeTypes
[i
]);
1187 * Read the MIME type and conversion database...
1190 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1191 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1193 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1194 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1195 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1196 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1200 cupsdLogMessage(CUPSD_LOG_EMERG
,
1201 "Unable to load MIME database from \"%s\" or \"%s\"!",
1202 mimedir
, ServerRoot
);
1203 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1207 cupsdLogMessage(CUPSD_LOG_INFO
,
1208 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1209 "%d filters...", mimedir
, ServerRoot
,
1210 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1213 * Create a list of MIME types for the document-format-supported
1217 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1218 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1221 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1223 cupsdLogMessage(CUPSD_LOG_ERROR
,
1224 "Unable to allocate memory for %d MIME types!",
1230 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1232 i
++, type
= mimeNextType(MimeDatabase
))
1234 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1236 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1239 if (i
< NumMimeTypes
)
1240 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1243 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1245 mime_filter_t
*filter
; /* Current filter */
1248 for (type
= mimeFirstType(MimeDatabase
);
1250 type
= mimeNextType(MimeDatabase
))
1251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1252 type
->super
, type
->type
);
1254 for (filter
= mimeFirstFilter(MimeDatabase
);
1256 filter
= mimeNextFilter(MimeDatabase
))
1257 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1258 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1259 filter
->src
->super
, filter
->src
->type
,
1260 filter
->dst
->super
, filter
->dst
->type
,
1261 filter
->cost
, filter
->filter
);
1268 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1269 cupsdLoadBanners(temp
);
1272 * Load printers and classes...
1275 cupsdLoadAllPrinters();
1276 cupsdLoadAllClasses();
1277 cupsdLoadRemoteCache();
1278 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1280 cupsdCreateCommonData();
1283 * Load queued jobs...
1289 * Load subscriptions...
1292 cupsdLoadAllSubscriptions();
1294 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1299 * Not a full reload, so recreate the common printer attributes...
1302 cupsdCreateCommonData();
1305 * Update all printers as needed...
1308 cupsdUpdatePrinters();
1309 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1311 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1315 * Reset the reload state...
1318 NeedReload
= RELOAD_NONE
;
1320 cupsdClearString(&old_serverroot
);
1321 cupsdClearString(&old_requestroot
);
1328 * 'get_address()' - Get an address + port number from a line.
1331 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1332 get_address(const char *value
, /* I - Value string */
1333 int defport
) /* I - Default port */
1335 char buffer
[1024], /* Hostname + port number buffer */
1336 defpname
[255], /* Default port name */
1337 *hostname
, /* Hostname or IP */
1338 *portname
; /* Port number or name */
1339 http_addrlist_t
*addrlist
; /* Address list */
1343 * Check for an empty value...
1348 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1353 * Grab a hostname and port number; if there is no colon and the port name
1354 * is only digits, then we have a port number by itself...
1357 strlcpy(buffer
, value
, sizeof(buffer
));
1359 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1366 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1371 * Use the default port...
1374 sprintf(defpname
, "%d", defport
);
1375 portname
= defpname
;
1381 * The buffer contains just a port number...
1389 if (hostname
&& !strcmp(hostname
, "*"))
1393 * Now lookup the address using httpAddrGetList()...
1396 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1397 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1398 hostname
? hostname
: "(nil)");
1405 * 'get_addr_and_mask()' - Get an IP address and netmask.
1408 static int /* O - 1 on success, 0 on failure */
1409 get_addr_and_mask(const char *value
, /* I - String from config file */
1410 unsigned *ip
, /* O - Address value */
1411 unsigned *mask
) /* O - Mask value */
1413 int i
, j
, /* Looping vars */
1414 family
, /* Address family */
1415 ipcount
; /* Count of fields in address */
1416 unsigned ipval
; /* Value */
1417 const char *maskval
, /* Pointer to start of mask value */
1418 *ptr
, /* Pointer into value */
1423 * Get the address...
1426 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1427 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1429 if ((maskval
= strchr(value
, '/')) != NULL
)
1432 maskval
= value
+ strlen(value
);
1436 * Check for an IPv6 address...
1442 * Parse hexadecimal IPv6 address...
1447 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1451 else if (!strncmp(ptr
, "::", 2))
1453 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1455 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1460 else if (isxdigit(*ptr
& 255))
1462 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1470 ip
[i
/ 2] |= ipval
<< 16;
1484 if (*ptr
&& *ptr
!= '/')
1488 #endif /* AF_INET6 */
1491 * Parse dotted-decimal IPv4 address...
1494 unsigned val
[4]; /* IPv4 address values */
1498 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1501 * Range check the IP numbers...
1504 for (i
= 0; i
< ipcount
; i
++)
1509 * Make sure the trailing values are zeroed, as some C libraries like
1510 * glibc apparently like to fill the unused arguments with garbage...
1513 for (i
= ipcount
; i
< 4; i
++)
1517 * Merge everything into a 32-bit IPv4 address in ip[3]...
1520 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1523 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1529 * Get the netmask value(s)...
1532 memset(mask
, 0, sizeof(unsigned) * 4);
1534 if (strchr(maskval
, '.'))
1537 * Get dotted-decimal mask...
1540 if (family
!= AF_INET
)
1543 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1546 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1547 mask
[0] = mask
[1] = mask
[2] = 0;
1552 * Get address/bits format...
1558 if (family
== AF_INET6
)
1566 mask
[0] = 0xffffffff;
1568 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1571 mask
[1] = 0xffffffff;
1575 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1578 mask
[2] = 0xffffffff;
1582 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1585 mask
[3] = 0xffffffff;
1589 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1592 #endif /* AF_INET6 */
1597 mask
[0] = 0xffffffff;
1598 mask
[1] = 0xffffffff;
1599 mask
[2] = 0xffffffff;
1602 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1604 mask
[3] = 0xffffffff;
1609 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1610 "get_addr_and_mask(value=\"%s\", "
1611 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1612 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1616 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1619 if ((ip
[0] & ~mask
[0]) != 0 ||
1620 (ip
[1] & ~mask
[1]) != 0 ||
1621 (ip
[2] & ~mask
[2]) != 0 ||
1622 (ip
[3] & ~mask
[3]) != 0)
1630 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1633 static int /* O - 1 on success, 0 on failure */
1634 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1635 char *line
, /* I - Line from file */
1636 char *value
, /* I - Start of value data */
1637 int linenum
) /* I - Current line number */
1639 char *valptr
; /* Pointer into value */
1640 unsigned ip
[4], /* IP address components */
1641 mask
[4]; /* IP netmask components */
1644 if (!strcasecmp(line
, "Encryption"))
1647 * "Encryption xxx" - set required encryption level...
1650 if (!strcasecmp(value
, "never"))
1651 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1652 else if (!strcasecmp(value
, "always"))
1654 cupsdLogMessage(CUPSD_LOG_ERROR
,
1655 "Encryption value \"%s\" on line %d is invalid in this "
1656 "context. Using \"required\" instead.", value
, linenum
);
1658 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1660 else if (!strcasecmp(value
, "required"))
1661 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1662 else if (!strcasecmp(value
, "ifrequested"))
1663 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1666 cupsdLogMessage(CUPSD_LOG_ERROR
,
1667 "Unknown Encryption value %s on line %d.", value
, linenum
);
1671 else if (!strcasecmp(line
, "Order"))
1674 * "Order Deny,Allow" or "Order Allow,Deny"...
1677 if (!strncasecmp(value
, "deny", 4))
1678 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1679 else if (!strncasecmp(value
, "allow", 5))
1680 loc
->order_type
= CUPSD_AUTH_DENY
;
1683 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1688 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1691 * Allow [From] host/ip...
1692 * Deny [From] host/ip...
1697 if (!strncasecmp(value
, "from", 4))
1700 * Strip leading "from"...
1705 while (isspace(*value
& 255))
1713 * Find the end of the value...
1716 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1718 while (isspace(*valptr
& 255))
1722 * Figure out what form the allow/deny address takes:
1733 * nnn.nnn.nnn.nnn/mm
1734 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1737 if (!strcasecmp(value
, "all"))
1743 if (!strcasecmp(line
, "Allow"))
1744 cupsdAllowIP(loc
, zeros
, zeros
);
1746 cupsdDenyIP(loc
, zeros
, zeros
);
1748 else if (!strcasecmp(value
, "none"))
1754 if (!strcasecmp(line
, "Allow"))
1755 cupsdAllowIP(loc
, ones
, zeros
);
1757 cupsdDenyIP(loc
, ones
, zeros
);
1760 else if (value
[0] == '*' || value
[0] == '.' ||
1761 (!isdigit(value
[0] & 255) && value
[0] != '['))
1763 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1764 #endif /* AF_INET6 */
1767 * Host or domain name...
1770 if (value
[0] == '*')
1773 if (!strcasecmp(line
, "Allow"))
1774 cupsdAllowHost(loc
, value
);
1776 cupsdDenyHost(loc
, value
);
1781 * One of many IP address forms...
1784 if (!get_addr_and_mask(value
, ip
, mask
))
1786 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1791 if (!strcasecmp(line
, "Allow"))
1792 cupsdAllowIP(loc
, ip
, mask
);
1794 cupsdDenyIP(loc
, ip
, mask
);
1798 * Advance to next value...
1804 else if (!strcasecmp(line
, "AuthType"))
1807 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1810 if (!strcasecmp(value
, "none"))
1812 loc
->type
= CUPSD_AUTH_NONE
;
1813 loc
->level
= CUPSD_AUTH_ANON
;
1815 else if (!strcasecmp(value
, "basic"))
1817 loc
->type
= CUPSD_AUTH_BASIC
;
1819 if (loc
->level
== CUPSD_AUTH_ANON
)
1820 loc
->level
= CUPSD_AUTH_USER
;
1822 else if (!strcasecmp(value
, "digest"))
1824 loc
->type
= CUPSD_AUTH_DIGEST
;
1826 if (loc
->level
== CUPSD_AUTH_ANON
)
1827 loc
->level
= CUPSD_AUTH_USER
;
1829 else if (!strcasecmp(value
, "basicdigest"))
1831 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1833 if (loc
->level
== CUPSD_AUTH_ANON
)
1834 loc
->level
= CUPSD_AUTH_USER
;
1836 else if (!strcasecmp(value
, "default"))
1838 loc
->type
= CUPSD_AUTH_DEFAULT
;
1840 if (loc
->level
== CUPSD_AUTH_ANON
)
1841 loc
->level
= CUPSD_AUTH_USER
;
1844 else if (!strcasecmp(value
, "negotiate"))
1846 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1848 if (loc
->level
== CUPSD_AUTH_ANON
)
1849 loc
->level
= CUPSD_AUTH_USER
;
1851 #endif /* HAVE_GSSAPI */
1854 cupsdLogMessage(CUPSD_LOG_WARN
,
1855 "Unknown authorization type %s on line %d.",
1860 else if (!strcasecmp(line
, "AuthClass"))
1863 * AuthClass anonymous, user, system, group
1866 if (!strcasecmp(value
, "anonymous"))
1868 loc
->type
= CUPSD_AUTH_NONE
;
1869 loc
->level
= CUPSD_AUTH_ANON
;
1871 cupsdLogMessage(CUPSD_LOG_WARN
,
1872 "\"AuthClass %s\" is deprecated; consider removing "
1876 else if (!strcasecmp(value
, "user"))
1878 loc
->level
= CUPSD_AUTH_USER
;
1880 cupsdLogMessage(CUPSD_LOG_WARN
,
1881 "\"AuthClass %s\" is deprecated; consider using "
1882 "\"Require valid-user\" on line %d.",
1885 else if (!strcasecmp(value
, "group"))
1887 loc
->level
= CUPSD_AUTH_GROUP
;
1889 cupsdLogMessage(CUPSD_LOG_WARN
,
1890 "\"AuthClass %s\" is deprecated; consider using "
1891 "\"Require user @groupname\" on line %d.",
1894 else if (!strcasecmp(value
, "system"))
1896 loc
->level
= CUPSD_AUTH_GROUP
;
1898 cupsdAddName(loc
, "@SYSTEM");
1900 cupsdLogMessage(CUPSD_LOG_WARN
,
1901 "\"AuthClass %s\" is deprecated; consider using "
1902 "\"Require user @SYSTEM\" on line %d.",
1907 cupsdLogMessage(CUPSD_LOG_WARN
,
1908 "Unknown authorization class %s on line %d.",
1913 else if (!strcasecmp(line
, "AuthGroupName"))
1915 cupsdAddName(loc
, value
);
1917 cupsdLogMessage(CUPSD_LOG_WARN
,
1918 "\"AuthGroupName %s\" directive is deprecated; consider "
1919 "using \"Require user @%s\" on line %d.",
1920 value
, value
, linenum
);
1922 else if (!strcasecmp(line
, "Require"))
1925 * Apache synonym for AuthClass and AuthGroupName...
1929 * Require valid-user
1930 * Require group names
1931 * Require user names
1934 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1939 if (!strcasecmp(value
, "valid-user") ||
1940 !strcasecmp(value
, "user"))
1941 loc
->level
= CUPSD_AUTH_USER
;
1942 else if (!strcasecmp(value
, "group"))
1943 loc
->level
= CUPSD_AUTH_GROUP
;
1946 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1952 * Get the list of names from the line...
1955 for (value
= valptr
; *value
;)
1957 while (isspace(*value
& 255))
1960 #ifdef HAVE_AUTHORIZATION_H
1961 if (!strncmp(value
, "@AUTHKEY(", 9))
1964 * Grab "@AUTHKEY(name)" value...
1967 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1973 #endif /* HAVE_AUTHORIZATION_H */
1974 if (*value
== '\"' || *value
== '\'')
1977 * Grab quoted name...
1980 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1987 * Grab literal name.
1990 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1996 cupsdAddName(loc
, value
);
1998 for (value
= valptr
; isspace(*value
& 255); value
++);
2001 else if (!strcasecmp(line
, "Satisfy"))
2003 if (!strcasecmp(value
, "all"))
2004 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2005 else if (!strcasecmp(value
, "any"))
2006 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2009 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2022 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2025 static int /* O - FatalErrors bits */
2026 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2028 int fatal
; /* FatalErrors bits */
2029 char value
[1024], /* Value string */
2030 *valstart
, /* Pointer into value */
2031 *valend
; /* End of value */
2035 * Empty FatalErrors line yields NULL pointer...
2039 return (CUPSD_FATAL_NONE
);
2042 * Loop through the value string,...
2045 strlcpy(value
, s
, sizeof(value
));
2047 fatal
= CUPSD_FATAL_NONE
;
2049 for (valstart
= value
; *valstart
;)
2052 * Get the current space/comma-delimited kind name...
2055 for (valend
= valstart
; *valend
; valend
++)
2056 if (isspace(*valend
& 255) || *valend
== ',')
2063 * Add the error to the bitmask...
2066 if (!strcasecmp(valstart
, "all"))
2067 fatal
= CUPSD_FATAL_ALL
;
2068 else if (!strcasecmp(valstart
, "browse"))
2069 fatal
|= CUPSD_FATAL_BROWSE
;
2070 else if (!strcasecmp(valstart
, "-browse"))
2071 fatal
&= ~CUPSD_FATAL_BROWSE
;
2072 else if (!strcasecmp(valstart
, "config"))
2073 fatal
|= CUPSD_FATAL_CONFIG
;
2074 else if (!strcasecmp(valstart
, "-config"))
2075 fatal
&= ~CUPSD_FATAL_CONFIG
;
2076 else if (!strcasecmp(valstart
, "listen"))
2077 fatal
|= CUPSD_FATAL_LISTEN
;
2078 else if (!strcasecmp(valstart
, "-listen"))
2079 fatal
&= ~CUPSD_FATAL_LISTEN
;
2080 else if (!strcasecmp(valstart
, "log"))
2081 fatal
|= CUPSD_FATAL_LOG
;
2082 else if (!strcasecmp(valstart
, "-log"))
2083 fatal
&= ~CUPSD_FATAL_LOG
;
2084 else if (!strcasecmp(valstart
, "permissions"))
2085 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2086 else if (!strcasecmp(valstart
, "-permissions"))
2087 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2088 else if (strcasecmp(valstart
, "none"))
2089 cupsdLogMessage(CUPSD_LOG_ERROR
,
2090 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2092 for (valstart
= valend
; *valstart
; valstart
++)
2093 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2102 * 'parse_groups()' - Parse system group names in a string.
2105 static int /* O - 1 on success, 0 on failure */
2106 parse_groups(const char *s
) /* I - Space-delimited groups */
2108 int status
; /* Return status */
2109 char value
[1024], /* Value string */
2110 *valstart
, /* Pointer into value */
2111 *valend
, /* End of value */
2112 quote
; /* Quote character */
2113 struct group
*group
; /* Group */
2117 * Make a copy of the string and parse out the groups...
2120 strlcpy(value
, s
, sizeof(value
));
2125 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2127 if (*valstart
== '\'' || *valstart
== '\"')
2130 * Scan quoted name...
2133 quote
= *valstart
++;
2135 for (valend
= valstart
; *valend
; valend
++)
2136 if (*valend
== quote
)
2142 * Scan space or comma-delimited name...
2145 for (valend
= valstart
; *valend
; valend
++)
2146 if (isspace(*valend
) || *valend
== ',')
2153 group
= getgrnam(valstart
);
2156 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2157 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2168 while (*valstart
== ',' || isspace(*valstart
))
2177 * 'parse_protocols()' - Parse browse protocols in a string.
2180 static int /* O - Browse protocol bits */
2181 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2183 int protocols
; /* Browse protocol bits */
2184 char value
[1024], /* Value string */
2185 *valstart
, /* Pointer into value */
2186 *valend
; /* End of value */
2190 * Empty protocol line yields NULL pointer...
2197 * Loop through the value string,...
2200 strlcpy(value
, s
, sizeof(value
));
2204 for (valstart
= value
; *valstart
;)
2207 * Get the current space/comma-delimited protocol name...
2210 for (valend
= valstart
; *valend
; valend
++)
2211 if (isspace(*valend
& 255) || *valend
== ',')
2218 * Add the protocol to the bitmask...
2221 if (!strcasecmp(valstart
, "cups"))
2222 protocols
|= BROWSE_CUPS
;
2223 else if (!strcasecmp(valstart
, "slp"))
2224 protocols
|= BROWSE_SLP
;
2225 else if (!strcasecmp(valstart
, "ldap"))
2226 protocols
|= BROWSE_LDAP
;
2227 else if (!strcasecmp(valstart
, "dnssd") ||
2228 !strcasecmp(valstart
, "dns-sd") ||
2229 !strcasecmp(valstart
, "bonjour"))
2230 protocols
|= BROWSE_DNSSD
;
2231 else if (!strcasecmp(valstart
, "lpd"))
2232 protocols
|= BROWSE_LPD
;
2233 else if (!strcasecmp(valstart
, "smb"))
2234 protocols
|= BROWSE_SMB
;
2235 else if (!strcasecmp(valstart
, "all"))
2236 protocols
|= BROWSE_ALL
;
2237 else if (strcasecmp(valstart
, "none"))
2238 cupsdLogMessage(CUPSD_LOG_ERROR
,
2239 "Unknown browse protocol \"%s\" ignored!", valstart
);
2241 for (valstart
= valend
; *valstart
; valstart
++)
2242 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2251 * 'read_configuration()' - Read a configuration file.
2254 static int /* O - 1 on success, 0 on failure */
2255 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2257 int i
; /* Looping var */
2258 int linenum
; /* Current line number */
2259 char line
[HTTP_MAX_BUFFER
],
2260 /* Line from file */
2261 temp
[HTTP_MAX_BUFFER
],
2262 /* Temporary buffer for value */
2263 temp2
[HTTP_MAX_BUFFER
],
2264 /* Temporary buffer 2 for value */
2265 *ptr
, /* Pointer into line/temp */
2266 *value
, /* Pointer to value */
2267 *valueptr
; /* Pointer into value */
2268 int valuelen
; /* Length of value */
2269 cupsd_var_t
const *var
; /* Current variable */
2270 http_addrlist_t
*addrlist
, /* Address list */
2271 *addr
; /* Current address */
2272 unsigned ip
[4], /* Address value */
2273 mask
[4]; /* Netmask value */
2274 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2275 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2276 cupsd_location_t
*location
; /* Browse location */
2277 cups_file_t
*incfile
; /* Include file */
2278 char incname
[1024]; /* Include filename */
2279 struct group
*group
; /* Group */
2283 * Loop through each line in the file...
2288 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2291 * Decode the directive...
2294 if (!strcasecmp(line
, "Include") && value
)
2300 if (value
[0] == '/')
2301 strlcpy(incname
, value
, sizeof(incname
));
2303 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2305 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2306 cupsdLogMessage(CUPSD_LOG_ERROR
,
2307 "Unable to include config file \"%s\" - %s",
2308 incname
, strerror(errno
));
2311 read_configuration(incfile
);
2312 cupsFileClose(incfile
);
2315 else if (!strcasecmp(line
, "<Location") && value
)
2321 linenum
= read_location(fp
, value
, linenum
);
2325 else if (!strcasecmp(line
, "<Policy") && value
)
2331 linenum
= read_policy(fp
, value
, linenum
);
2335 else if (!strcasecmp(line
, "FatalErrors"))
2336 FatalErrors
= parse_fatal_errors(value
);
2337 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2339 JobRetryInterval
= atoi(value
);
2340 cupsdLogMessage(CUPSD_LOG_WARN
,
2341 "FaxRetryInterval is deprecated; use "
2342 "JobRetryInterval on line %d.", linenum
);
2344 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2346 JobRetryLimit
= atoi(value
);
2347 cupsdLogMessage(CUPSD_LOG_WARN
,
2348 "FaxRetryLimit is deprecated; use "
2349 "JobRetryLimit on line %d.", linenum
);
2351 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2353 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2354 #endif /* HAVE_SSL */
2358 * Add listening address(es) to the list...
2361 cupsd_listener_t
*lis
; /* New listeners array */
2365 * Get the address list...
2368 addrlist
= get_address(value
, IPP_PORT
);
2372 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2378 * Add each address...
2381 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2384 * See if this address is already present...
2387 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2389 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2390 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2391 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2396 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2397 cupsdLogMessage(CUPSD_LOG_WARN
,
2398 "Duplicate listen address \"%s\" ignored!", temp
);
2403 * Allocate another listener...
2407 Listeners
= cupsArrayNew(NULL
, NULL
);
2411 cupsdLogMessage(CUPSD_LOG_ERROR
,
2412 "Unable to allocate %s at line %d - %s.",
2413 line
, linenum
, strerror(errno
));
2417 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2419 cupsdLogMessage(CUPSD_LOG_ERROR
,
2420 "Unable to allocate %s at line %d - %s.",
2421 line
, linenum
, strerror(errno
));
2425 cupsArrayAdd(Listeners
, lis
);
2428 * Copy the current address and log it...
2431 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2435 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2436 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2437 #endif /* HAVE_SSL */
2439 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2442 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2443 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2444 ntohs(lis
->address
.ipv6
.sin6_port
));
2446 #endif /* AF_INET6 */
2448 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2449 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2451 #endif /* AF_LOCAL */
2452 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2453 ntohs(lis
->address
.ipv4
.sin_port
));
2460 httpAddrFreeList(addrlist
);
2462 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2465 * Add a browse address to the list...
2468 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2471 if (NumBrowsers
== 0)
2472 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2474 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2478 cupsdLogMessage(CUPSD_LOG_ERROR
,
2479 "Unable to allocate BrowseAddress at line %d - %s.",
2480 linenum
, strerror(errno
));
2485 dira
+= NumBrowsers
;
2487 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2489 if (!strcasecmp(value
, "@LOCAL"))
2492 * Send browse data to all local interfaces...
2495 strcpy(dira
->iface
, "*");
2498 else if (!strncasecmp(value
, "@IF(", 4))
2501 * Send browse data to the named interface...
2504 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2506 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2512 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2515 * Only IPv4 addresses are supported...
2518 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2519 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2524 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2525 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2527 cupsdLogMessage(CUPSD_LOG_INFO
,
2528 "Sending browsing info to %s:%d (IPv4)",
2529 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2534 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2537 httpAddrFreeList(addrlist
);
2540 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2543 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2546 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2549 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2550 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2552 if (location
== NULL
)
2553 cupsdLogMessage(CUPSD_LOG_ERROR
,
2554 "Unable to initialize browse access control list!");
2555 else if (!strncasecmp(value
, "deny", 4))
2556 location
->order_type
= CUPSD_AUTH_ALLOW
;
2557 else if (!strncasecmp(value
, "allow", 5))
2558 location
->order_type
= CUPSD_AUTH_DENY
;
2560 cupsdLogMessage(CUPSD_LOG_ERROR
,
2561 "Unknown BrowseOrder value %s on line %d.",
2564 else if (!strcasecmp(line
, "BrowseProtocols") ||
2565 !strcasecmp(line
, "BrowseLocalProtocols") ||
2566 !strcasecmp(line
, "BrowseRemoteProtocols"))
2569 * "BrowseProtocols name [... name]"
2570 * "BrowseLocalProtocols name [... name]"
2571 * "BrowseRemoteProtocols name [... name]"
2574 int protocols
= parse_protocols(value
);
2578 cupsdLogMessage(CUPSD_LOG_ERROR
,
2579 "Unknown browse protocol \"%s\" on line %d.",
2584 if (strcasecmp(line
, "BrowseLocalProtocols"))
2585 BrowseRemoteProtocols
= protocols
;
2586 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2587 BrowseLocalProtocols
= protocols
;
2589 else if ((!strcasecmp(line
, "BrowseAllow") ||
2590 !strcasecmp(line
, "BrowseDeny")) && value
)
2593 * BrowseAllow [From] host/ip...
2594 * BrowseDeny [From] host/ip...
2597 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2598 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2600 if (location
== NULL
)
2601 cupsdLogMessage(CUPSD_LOG_ERROR
,
2602 "Unable to initialize browse access control list!");
2607 if (!strncasecmp(value
, "from", 4))
2610 * Strip leading "from"...
2615 while (isspace(*value
& 255))
2623 * Find the end of the value...
2626 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2628 while (isspace(*valueptr
& 255))
2632 * Figure out what form the allow/deny address takes:
2643 * nnn.nnn.nnn.nnn/mm
2644 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2647 if (!strcasecmp(value
, "all"))
2653 if (!strcasecmp(line
, "BrowseAllow"))
2654 cupsdAllowIP(location
, zeros
, zeros
);
2656 cupsdDenyIP(location
, zeros
, zeros
);
2658 else if (!strcasecmp(value
, "none"))
2664 if (!strcasecmp(line
, "BrowseAllow"))
2665 cupsdAllowIP(location
, ones
, zeros
);
2667 cupsdDenyIP(location
, ones
, zeros
);
2670 else if (value
[0] == '*' || value
[0] == '.' ||
2671 (!isdigit(value
[0] & 255) && value
[0] != '['))
2673 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2674 #endif /* AF_INET6 */
2677 * Host or domain name...
2680 if (value
[0] == '*')
2683 if (!strcasecmp(line
, "BrowseAllow"))
2684 cupsdAllowHost(location
, value
);
2686 cupsdDenyHost(location
, value
);
2691 * One of many IP address forms...
2694 if (!get_addr_and_mask(value
, ip
, mask
))
2696 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2701 if (!strcasecmp(line
, "BrowseAllow"))
2702 cupsdAllowIP(location
, ip
, mask
);
2704 cupsdDenyIP(location
, ip
, mask
);
2708 * Advance to next value...
2715 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2718 * BrowseRelay [from] source [to] destination
2722 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2724 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2728 cupsdLogMessage(CUPSD_LOG_ERROR
,
2729 "Unable to allocate BrowseRelay at line %d - %s.",
2730 linenum
, strerror(errno
));
2737 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2739 if (!strncasecmp(value
, "from ", 5))
2742 * Strip leading "from"...
2747 while (isspace(*value
))
2752 * Figure out what form the from address takes:
2761 * nnn.nnn.nnn.nnn/mm
2762 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2766 if (value
[0] == '*' || value
[0] == '.' ||
2767 (!isdigit(value
[0] & 255) && value
[0] != '['))
2769 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2770 #endif /* AF_INET6 */
2773 * Host or domain name...
2776 if (value
[0] == '*')
2779 strlcpy(temp
, value
, sizeof(temp
));
2780 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2783 relay
->from
.type
= CUPSD_AUTH_NAME
;
2785 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2787 cupsdLogMessage(CUPSD_LOG_ERROR
,
2788 "Unable to allocate BrowseRelay name at line %d - %s.",
2789 linenum
, strerror(errno
));
2793 relay
->from
.mask
.name
.length
= strlen(temp
);
2798 * One of many IP address forms...
2801 if (!get_addr_and_mask(value
, ip
, mask
))
2803 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2808 relay
->from
.type
= CUPSD_AUTH_IP
;
2809 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2810 sizeof(relay
->from
.mask
.ip
.address
));
2811 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2812 sizeof(relay
->from
.mask
.ip
.netmask
));
2816 * Skip value and trailing whitespace...
2819 for (; *value
; value
++)
2820 if (isspace(*value
))
2823 while (isspace(*value
))
2826 if (!strncasecmp(value
, "to ", 3))
2829 * Strip leading "to"...
2834 while (isspace(*value
))
2839 * Get "to" address and port...
2842 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2845 * Only IPv4 addresses are supported...
2848 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2849 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2854 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2856 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2858 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2859 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2860 relay
->from
.mask
.ip
.address
[0] >> 24,
2861 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2862 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2863 relay
->from
.mask
.ip
.address
[0] & 255,
2864 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2865 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2866 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2867 relay
->from
.mask
.ip
.netmask
[0] & 255);
2869 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2871 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2872 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2877 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2880 httpAddrFreeList(addrlist
);
2884 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2885 free(relay
->from
.mask
.name
.name
);
2887 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2891 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2894 * BrowsePoll address[:port]
2897 char *portname
; /* Port name */
2898 int portnum
; /* Port number */
2899 struct servent
*service
; /* Service */
2903 * Extract the port name from the address...
2906 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2910 if (isdigit(*portname
& 255))
2911 portnum
= atoi(portname
);
2912 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2913 portnum
= ntohs(service
->s_port
);
2916 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2922 portnum
= ippPort();
2925 * Add the poll entry...
2929 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2931 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2935 cupsdLogMessage(CUPSD_LOG_ERROR
,
2936 "Unable to allocate BrowsePoll at line %d - %s.",
2937 linenum
, strerror(errno
));
2945 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2947 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2948 pollp
->port
= portnum
;
2950 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2953 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2956 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2959 if (!strcasecmp(value
, "none"))
2960 DefaultAuthType
= CUPSD_AUTH_NONE
;
2961 else if (!strcasecmp(value
, "basic"))
2962 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2963 else if (!strcasecmp(value
, "digest"))
2964 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2965 else if (!strcasecmp(value
, "basicdigest"))
2966 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2968 else if (!strcasecmp(value
, "negotiate"))
2969 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2970 #endif /* HAVE_GSSAPI */
2973 cupsdLogMessage(CUPSD_LOG_WARN
,
2974 "Unknown default authorization type %s on line %d.",
2976 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2981 else if (!strcasecmp(line
, "DefaultEncryption"))
2984 * DefaultEncryption {Never,IfRequested,Required}
2987 if (!value
|| !strcasecmp(value
, "never"))
2988 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2989 else if (!strcasecmp(value
, "required"))
2990 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2991 else if (!strcasecmp(value
, "ifrequested"))
2992 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2995 cupsdLogMessage(CUPSD_LOG_WARN
,
2996 "Unknown default encryption %s on line %d.",
2998 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3002 #endif /* HAVE_SSL */
3004 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
3006 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
3009 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
3010 gsskrb5_register_acceptor_identity(value
);
3012 cupsdSetEnv("KRB5_KTNAME", value
);
3013 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
3015 #endif /* HAVE_GSSAPI */
3016 else if (!strcasecmp(line
, "User") && value
)
3019 * User ID to run as...
3022 if (isdigit(value
[0] & 255))
3024 int uid
= atoi(value
);
3027 cupsdLogMessage(CUPSD_LOG_ERROR
,
3028 "Will not use User 0 as specified on line %d "
3029 "for security reasons. You must use a non-"
3030 "privileged account instead.",
3037 struct passwd
*p
; /* Password information */
3040 p
= getpwnam(value
);
3045 cupsdLogMessage(CUPSD_LOG_ERROR
,
3046 "Will not use User %s (UID=0) as specified on line "
3047 "%d for security reasons. You must use a non-"
3048 "privileged account instead.",
3054 cupsdLogMessage(CUPSD_LOG_ERROR
,
3055 "Unknown User \"%s\" on line %d, ignoring!",
3059 else if (!strcasecmp(line
, "Group") && value
)
3062 * Group ID to run as...
3065 if (isdigit(value
[0]))
3066 Group
= atoi(value
);
3070 group
= getgrnam(value
);
3073 Group
= group
->gr_gid
;
3075 cupsdLogMessage(CUPSD_LOG_ERROR
,
3076 "Unknown Group \"%s\" on line %d, ignoring!",
3080 else if (!strcasecmp(line
, "SystemGroup") && value
)
3083 * SystemGroup (admin) group(s)...
3086 if (!parse_groups(value
))
3087 cupsdLogMessage(CUPSD_LOG_ERROR
,
3088 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3091 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3094 * Do hostname lookups?
3097 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3098 !strcasecmp(value
, "false"))
3099 HostNameLookups
= 0;
3100 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3101 !strcasecmp(value
, "true"))
3102 HostNameLookups
= 1;
3103 else if (!strcasecmp(value
, "double"))
3104 HostNameLookups
= 2;
3106 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3109 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3112 * Amount of logging to do to access log...
3115 if (!strcasecmp(value
, "all"))
3116 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3117 else if (!strcasecmp(value
, "actions"))
3118 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3119 else if (!strcasecmp(value
, "config"))
3120 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3122 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3125 else if (!strcasecmp(line
, "LogLevel") && value
)
3128 * Amount of logging to do to error log...
3131 if (!strcasecmp(value
, "debug2"))
3132 LogLevel
= CUPSD_LOG_DEBUG2
;
3133 else if (!strcasecmp(value
, "debug"))
3134 LogLevel
= CUPSD_LOG_DEBUG
;
3135 else if (!strcasecmp(value
, "info"))
3136 LogLevel
= CUPSD_LOG_INFO
;
3137 else if (!strcasecmp(value
, "notice"))
3138 LogLevel
= CUPSD_LOG_NOTICE
;
3139 else if (!strcasecmp(value
, "warn"))
3140 LogLevel
= CUPSD_LOG_WARN
;
3141 else if (!strcasecmp(value
, "error"))
3142 LogLevel
= CUPSD_LOG_ERROR
;
3143 else if (!strcasecmp(value
, "crit"))
3144 LogLevel
= CUPSD_LOG_CRIT
;
3145 else if (!strcasecmp(value
, "alert"))
3146 LogLevel
= CUPSD_LOG_ALERT
;
3147 else if (!strcasecmp(value
, "emerg"))
3148 LogLevel
= CUPSD_LOG_EMERG
;
3149 else if (!strcasecmp(value
, "none"))
3150 LogLevel
= CUPSD_LOG_NONE
;
3152 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3155 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3158 * Format of printcap file?
3161 if (!strcasecmp(value
, "bsd"))
3162 PrintcapFormat
= PRINTCAP_BSD
;
3163 else if (!strcasecmp(value
, "plist"))
3164 PrintcapFormat
= PRINTCAP_PLIST
;
3165 else if (!strcasecmp(value
, "solaris"))
3166 PrintcapFormat
= PRINTCAP_SOLARIS
;
3168 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3171 else if (!strcasecmp(line
, "ServerTokens") && value
)
3174 * Set the string used for the Server header...
3177 struct utsname plat
; /* Platform info */
3182 if (!strcasecmp(value
, "ProductOnly"))
3183 cupsdSetString(&ServerHeader
, "CUPS");
3184 else if (!strcasecmp(value
, "Major"))
3185 cupsdSetString(&ServerHeader
, "CUPS/1");
3186 else if (!strcasecmp(value
, "Minor"))
3187 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3188 else if (!strcasecmp(value
, "Minimal"))
3189 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3190 else if (!strcasecmp(value
, "OS"))
3191 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3192 else if (!strcasecmp(value
, "Full"))
3193 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3195 else if (!strcasecmp(value
, "None"))
3196 cupsdClearString(&ServerHeader
);
3198 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3201 else if (!strcasecmp(line
, "PassEnv") && value
)
3204 * PassEnv variable [... variable]
3209 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3210 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3213 if (value
[valuelen
])
3215 value
[valuelen
] = '\0';
3219 cupsdSetEnv(value
, NULL
);
3221 for (value
+= valuelen
; *value
; value
++)
3222 if (!isspace(*value
) || *value
!= ',')
3226 else if (!strcasecmp(line
, "SetEnv") && value
)
3229 * SetEnv variable value
3232 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3240 while (isspace(*valueptr
& 255))
3243 cupsdSetEnv(value
, valueptr
);
3246 cupsdLogMessage(CUPSD_LOG_ERROR
,
3247 "Missing value for SetEnv directive on line %d.",
3251 else if (!strcasecmp(line
, "SSLOptions"))
3254 * SSLOptions options
3257 if (!value
|| !strcasecmp(value
, "none"))
3258 SSLOptions
= CUPSD_SSL_NONE
;
3259 else if (!strcasecmp(value
, "noemptyfragments"))
3260 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3262 cupsdLogMessage(CUPSD_LOG_ERROR
,
3263 "Unknown value \"%s\" for SSLOptions directive on "
3264 "line %d.", value
, linenum
);
3266 #endif /* HAVE_SSL */
3270 * Find a simple variable in the list...
3273 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3274 if (!strcasecmp(line
, var
->name
))
3280 * Unknown directive! Output an error message and continue...
3284 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3287 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3294 case CUPSD_VARTYPE_INTEGER
:
3296 cupsdLogMessage(CUPSD_LOG_ERROR
,
3297 "Missing integer value for %s on line %d!",
3302 char *units
; /* Units */
3305 n
= strtol(value
, &units
, 0);
3307 if (units
&& *units
)
3309 if (tolower(units
[0] & 255) == 'g')
3310 n
*= 1024 * 1024 * 1024;
3311 else if (tolower(units
[0] & 255) == 'm')
3313 else if (tolower(units
[0] & 255) == 'k')
3315 else if (tolower(units
[0] & 255) == 't')
3320 cupsdLogMessage(CUPSD_LOG_ERROR
,
3321 "Bad negative integer value for %s on line %d!",
3324 *((int *)var
->ptr
) = n
;
3328 case CUPSD_VARTYPE_BOOLEAN
:
3330 cupsdLogMessage(CUPSD_LOG_ERROR
,
3331 "Missing boolean value for %s on line %d!",
3333 else if (!strcasecmp(value
, "true") ||
3334 !strcasecmp(value
, "on") ||
3335 !strcasecmp(value
, "enabled") ||
3336 !strcasecmp(value
, "yes") ||
3338 *((int *)var
->ptr
) = TRUE
;
3339 else if (!strcasecmp(value
, "false") ||
3340 !strcasecmp(value
, "off") ||
3341 !strcasecmp(value
, "disabled") ||
3342 !strcasecmp(value
, "no") ||
3343 !strcasecmp(value
, "0"))
3344 *((int *)var
->ptr
) = FALSE
;
3346 cupsdLogMessage(CUPSD_LOG_ERROR
,
3347 "Unknown boolean value %s on line %d.",
3351 case CUPSD_VARTYPE_PATHNAME
:
3354 cupsdLogMessage(CUPSD_LOG_ERROR
,
3355 "Missing pathname value for %s on line %d!",
3360 if (value
[0] == '/')
3361 strlcpy(temp
, value
, sizeof(temp
));
3363 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3365 if (access(temp
, 0))
3367 cupsdLogMessage(CUPSD_LOG_ERROR
,
3368 "File or directory for \"%s %s\" on line %d "
3369 "does not exist!", line
, value
, linenum
);
3373 case CUPSD_VARTYPE_STRING
:
3374 cupsdSetString((char **)var
->ptr
, value
);
3385 * 'read_location()' - Read a <Location path> definition.
3388 static int /* O - New line number or 0 on error */
3389 read_location(cups_file_t
*fp
, /* I - Configuration file */
3390 char *location
, /* I - Location name/path */
3391 int linenum
) /* I - Current line number */
3393 cupsd_location_t
*loc
, /* New location */
3394 *parent
; /* Parent location */
3395 char line
[HTTP_MAX_BUFFER
],
3397 *value
, /* Value for directive */
3398 *valptr
; /* Pointer into value */
3401 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3404 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3407 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3410 * Decode the directive...
3413 if (!strcasecmp(line
, "</Location>"))
3415 else if (!strcasecmp(line
, "<Limit") ||
3416 !strcasecmp(line
, "<LimitExcept"))
3420 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3421 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3427 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3433 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3438 if (!strcmp(value
, "ALL"))
3439 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3440 else if (!strcmp(value
, "GET"))
3441 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3442 else if (!strcmp(value
, "HEAD"))
3443 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3444 else if (!strcmp(value
, "OPTIONS"))
3445 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3446 else if (!strcmp(value
, "POST"))
3447 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3448 else if (!strcmp(value
, "PUT"))
3449 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3450 else if (!strcmp(value
, "TRACE"))
3451 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3453 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3456 for (value
= valptr
; isspace(*value
& 255); value
++);
3459 if (!strcasecmp(line
, "<LimitExcept"))
3460 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3462 parent
->limit
&= ~loc
->limit
;
3464 else if (!strcasecmp(line
, "</Limit>") ||
3465 !strcasecmp(line
, "</LimitExcept>"))
3467 else if (!parse_aaa(loc
, line
, value
, linenum
))
3469 cupsdLogMessage(CUPSD_LOG_ERROR
,
3470 "Unknown Location directive %s on line %d.",
3472 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3477 cupsdLogMessage(CUPSD_LOG_ERROR
,
3478 "Unexpected end-of-file at line %d while reading location!",
3481 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3486 * 'read_policy()' - Read a <Policy name> definition.
3489 static int /* O - New line number or 0 on error */
3490 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3491 char *policy
, /* I - Location name/path */
3492 int linenum
) /* I - Current line number */
3494 int i
; /* Looping var */
3495 cupsd_policy_t
*pol
; /* Policy */
3496 cupsd_location_t
*op
; /* Policy operation */
3497 int num_ops
; /* Number of IPP operations */
3498 ipp_op_t ops
[100]; /* Operations */
3499 char line
[HTTP_MAX_BUFFER
],
3501 *value
, /* Value for directive */
3502 *valptr
; /* Pointer into value */
3506 * Create the policy...
3509 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3513 * Read from the file...
3519 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3522 * Decode the directive...
3525 if (!strcasecmp(line
, "</Policy>"))
3528 cupsdLogMessage(CUPSD_LOG_WARN
,
3529 "Missing </Limit> before </Policy> on line %d!",
3533 * Verify that we have an explicit policy for CUPS-Get-Document
3534 * (ensures that upgrades do not introduce new security issues...)
3537 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3538 op
->op
== IPP_ANY_OPERATION
)
3540 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3541 op
->op
!= IPP_ANY_OPERATION
)
3544 * Add a new limit for CUPS-Get-Document using the Send-Document
3545 * limit as a template...
3548 cupsdLogMessage(CUPSD_LOG_WARN
,
3549 "No limit for CUPS-Get-Document defined in policy %s "
3550 "- using Send-Document's policy", pol
->name
);
3552 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3558 else if (!strcasecmp(line
, "<Limit") && !op
)
3562 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3563 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3570 * Scan for IPP operation names...
3577 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3582 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3584 if (!strcasecmp(value
, "All"))
3585 ops
[num_ops
] = IPP_ANY_OPERATION
;
3586 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3587 cupsdLogMessage(CUPSD_LOG_ERROR
,
3588 "Bad IPP operation name \"%s\" on line %d!",
3594 cupsdLogMessage(CUPSD_LOG_ERROR
,
3595 "Too many operations listed on line %d!",
3598 for (value
= valptr
; isspace(*value
& 255); value
++);
3602 * If none are specified, apply the policy to all operations...
3607 ops
[0] = IPP_ANY_OPERATION
;
3612 * Add a new policy for the first operation...
3615 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3617 else if (!strcasecmp(line
, "</Limit>") && op
)
3620 * Finish the current operation limit...
3626 * Copy the policy to the other operations...
3629 for (i
= 1; i
< num_ops
; i
++)
3630 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3637 cupsdLogMessage(CUPSD_LOG_ERROR
,
3638 "Missing <Limit ops> directive before %s on line %d.",
3640 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3643 else if (!parse_aaa(op
, line
, value
, linenum
))
3646 cupsdLogMessage(CUPSD_LOG_ERROR
,
3647 "Unknown Policy Limit directive %s on line %d.",
3650 cupsdLogMessage(CUPSD_LOG_ERROR
,
3651 "Unknown Policy directive %s on line %d.",
3654 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3659 cupsdLogMessage(CUPSD_LOG_ERROR
,
3660 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3663 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3668 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".