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
;
458 PrintcapFormat
= PRINTCAP_BSD
;
460 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
461 if ((slash
= strrchr(temp
, '/')) != NULL
)
464 cupsdSetString(&ServerRoot
, temp
);
466 cupsdClearString(&Classification
);
467 ClassifyOverride
= 0;
471 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
473 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
474 cupsdSetString(&ServerKey
, "ssl/server.key");
475 # endif /* HAVE_CDSASSL */
476 #endif /* HAVE_SSL */
478 language
= cupsLangDefault();
480 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
481 cupsdSetString(&DefaultLanguage
, "en");
483 cupsdSetString(&DefaultLanguage
, language
->language
);
485 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
487 cupsdClearString(&DefaultPaperSize
);
489 cupsdSetString(&RIPCache
, "8m");
491 cupsdSetString(&TempDir
, NULL
);
494 * Find the default user...
497 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
502 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
503 * complement number...)
512 * Find the default group...
515 group
= getgrnam(CUPS_DEFAULT_GROUP
);
519 Group
= group
->gr_gid
;
523 * Fallback to group "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...)
546 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
547 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
548 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
549 DefaultAuthType
= CUPSD_AUTH_BASIC
;
551 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
552 SSLOptions
= CUPSD_SSL_NONE
;
553 #endif /* HAVE_SSL */
554 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
556 JobRetryInterval
= 300;
561 HostNameLookups
= FALSE
;
562 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
563 ImplicitAnyClasses
= FALSE
;
564 HideImplicitMembers
= TRUE
;
566 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
567 ListenBackLog
= SOMAXCONN
;
568 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
569 LogLevel
= CUPSD_LOG_WARN
;
571 MaxClientsPerHost
= 0;
572 MaxLogSize
= 1024 * 1024;
573 MaxPrinterHistory
= 10;
575 ReloadTimeout
= DEFAULT_KEEPALIVE
;
576 RootCertDuration
= 300;
577 Timeout
= DEFAULT_TIMEOUT
;
580 BrowseInterval
= DEFAULT_INTERVAL
;
581 BrowsePort
= ippPort();
582 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
583 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
584 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
585 BrowseTimeout
= DEFAULT_TIMEOUT
;
587 Browsing
= CUPS_DEFAULT_BROWSING
;
588 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
590 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
591 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
593 cupsdClearString(&BrowseLocalOptions
);
594 cupsdClearString(&BrowseRemoteOptions
);
596 cupsdSetString(&ErrorPolicy
, "stop-printer");
599 cupsdClearString(&BrowseLDAPBindDN
);
600 cupsdClearString(&BrowseLDAPDN
);
601 cupsdClearString(&BrowseLDAPPassword
);
602 cupsdClearString(&BrowseLDAPServer
);
603 # ifdef HAVE_LDAP_SSL
604 cupsdClearString(&BrowseLDAPCACertFile
);
605 # endif /* HAVE_LDAP_SSL */
606 #endif /* HAVE_LDAP */
608 JobHistory
= DEFAULT_HISTORY
;
609 JobFiles
= DEFAULT_FILES
;
614 MaxJobsPerPrinter
= 0;
615 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
617 cupsdDeleteAllPolicies();
618 cupsdClearString(&DefaultPolicy
);
620 #ifdef HAVE_AUTHORIZATION_H
621 cupsdClearString(&SystemGroupAuthKey
);
622 #endif /* HAVE_AUTHORIZATION_H */
624 MaxSubscriptions
= 100;
625 MaxSubscriptionsPerJob
= 0;
626 MaxSubscriptionsPerPrinter
= 0;
627 MaxSubscriptionsPerUser
= 0;
628 DefaultLeaseDuration
= 86400;
629 MaxLeaseDuration
= 0;
632 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
633 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
634 #endif /* HAVE_LAUNCHD */
638 #endif /* __APPLE__ */
641 * Read the configuration file...
644 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
647 status
= read_configuration(fp
);
657 * See if the ServerName is an IP address...
660 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
662 ServerNameIsIP
= !*slash
;
665 * Use the default system group if none was supplied in cupsd.conf...
668 if (NumSystemGroups
== 0)
670 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
673 * Find the group associated with GID 0...
680 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
682 cupsdSetString(&SystemGroups
[0], "unknown");
684 SystemGroupIDs
[0] = 0;
690 * Get the access control list for browsing...
693 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
696 * Open the system log for cupsd if necessary...
700 if (!strcmp(AccessLog
, "syslog") ||
701 !strcmp(ErrorLog
, "syslog") ||
702 !strcmp(PageLog
, "syslog"))
703 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
704 #endif /* HAVE_VSYSLOG */
707 * Log the configuration file that was used...
710 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
714 * Validate the Group and SystemGroup settings - they cannot be the same,
715 * otherwise the CGI programs will be able to authenticate as root without
721 for (i
= 0; i
< NumSystemGroups
; i
++)
722 if (Group
== SystemGroupIDs
[i
])
725 if (i
< NumSystemGroups
)
728 * Log the error and reset the group to a safe value...
731 cupsdLogMessage(CUPSD_LOG_NOTICE
,
732 "Group and SystemGroup cannot use the same groups!");
733 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
735 group
= getgrnam("nobody");
739 Group
= group
->gr_gid
;
743 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
744 * complement number...)
753 * Check that we have at least one listen/port line; if not, report this
754 * as an error and exit!
757 if (cupsArrayCount(Listeners
) == 0)
763 cupsdLogMessage(CUPSD_LOG_EMERG
,
764 "No valid Listen or Port lines were found in the "
765 "configuration file!");
771 cupsdEndProcess(getpid(), 0);
775 * Set the default locale using the language and charset...
778 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
781 * Update all relative filenames to include the full path from ServerRoot...
784 if (DocumentRoot
[0] != '/')
785 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
787 if (RequestRoot
[0] != '/')
788 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
790 if (ServerBin
[0] != '/')
791 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
793 if (StateDir
[0] != '/')
794 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
796 if (CacheDir
[0] != '/')
797 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
800 if (ServerCertificate
[0] != '/')
801 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
803 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
804 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
806 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
809 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
810 if (ServerKey
[0] != '/')
811 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
813 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
814 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
815 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
817 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
818 #endif /* HAVE_SSL */
821 * Make sure that directories and config files are owned and
822 * writable by the user and group in the cupsd.conf file...
825 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
827 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
829 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
831 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
833 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
835 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
836 SystemGroupIDs
[0], 1, 1) < 0 ||
837 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
839 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
841 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
843 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
845 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
847 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
849 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
851 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
855 * Update TempDir to the default if it hasn't been set already...
860 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
863 * TMPDIR is defined, see if it is OK for us to use...
866 if (stat(tmpdir
, &tmpinfo
))
867 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
868 tmpdir
, strerror(errno
));
869 else if (!S_ISDIR(tmpinfo
.st_mode
))
870 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
872 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
873 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
874 !(tmpinfo
.st_mode
& S_IWOTH
))
875 cupsdLogMessage(CUPSD_LOG_ERROR
,
876 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
878 cupsdSetString(&TempDir
, tmpdir
);
883 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
885 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
890 * Make sure the temporary directory has the right permissions...
893 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
897 * Update ownership and permissions if the CUPS temp directory
898 * is under the spool directory or does not exist...
901 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
902 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
907 * Setup environment variables...
913 * Update default paper size setting as needed...
916 if (!DefaultPaperSize
)
919 char *paper_result
; /* Paper size name from libpaper */
921 if ((paper_result
= systempapername()) != NULL
)
922 cupsdSetString(&DefaultPaperSize
, paper_result
);
924 #endif /* HAVE_LIBPAPER */
925 if (!DefaultLanguage
||
926 !strcasecmp(DefaultLanguage
, "C") ||
927 !strcasecmp(DefaultLanguage
, "POSIX") ||
928 !strcasecmp(DefaultLanguage
, "en") ||
929 !strncasecmp(DefaultLanguage
, "en.", 3) ||
930 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
931 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
932 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
935 * These are the only locales that will default to "letter" size...
938 cupsdSetString(&DefaultPaperSize
, "Letter");
941 cupsdSetString(&DefaultPaperSize
, "A4");
945 * Update classification setting as needed...
948 if (Classification
&& !strcasecmp(Classification
, "none"))
949 cupsdClearString(&Classification
);
952 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
955 * Check the MaxClients setting, and then allocate memory for it...
958 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
961 cupsdLogMessage(CUPSD_LOG_INFO
,
962 "MaxClients limited to 1/3 (%d) of the file descriptor "
966 MaxClients
= MaxFDs
/ 3;
969 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
973 * Check the MaxActiveJobs setting; limit to 1/3 the available
974 * file descriptors, since we need a pipe for each job...
977 if (MaxActiveJobs
> (MaxFDs
/ 3))
978 MaxActiveJobs
= MaxFDs
/ 3;
981 * Update the MaxClientsPerHost value, as needed...
984 if (MaxClientsPerHost
<= 0)
985 MaxClientsPerHost
= MaxClients
;
987 if (MaxClientsPerHost
> MaxClients
)
988 MaxClientsPerHost
= MaxClients
;
990 cupsdLogMessage(CUPSD_LOG_INFO
,
991 "Allowing up to %d client connections per host.",
995 * Make sure that BrowseTimeout is at least twice the interval...
998 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1000 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1004 BrowseTimeout
= BrowseInterval
* 2;
1006 BrowseTimeout
= DEFAULT_TIMEOUT
;
1008 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1013 * Update the default policy, as needed...
1017 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1019 DefaultPolicyPtr
= NULL
;
1021 if (!DefaultPolicyPtr
)
1023 cupsd_location_t
*po
; /* New policy operation */
1027 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1030 cupsdSetString(&DefaultPolicy
, "default");
1032 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1033 cupsdLogMessage(CUPSD_LOG_INFO
,
1034 "Using policy \"default\" as the default!");
1037 cupsdLogMessage(CUPSD_LOG_INFO
,
1038 "Creating CUPS default administrative policy:");
1040 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1042 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1043 cupsdLogMessage(CUPSD_LOG_INFO
,
1044 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1045 "Release-Job Restart-Job Purge-Jobs "
1046 "Set-Job-Attributes Create-Job-Subscription "
1047 "Renew-Subscription Cancel-Subscription "
1048 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1049 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1050 "CUPS-Authenticate-Job CUPS-Get-Document>");
1051 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1053 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1054 po
->order_type
= CUPSD_AUTH_ALLOW
;
1055 po
->level
= CUPSD_AUTH_USER
;
1057 cupsdAddName(po
, "@OWNER");
1058 cupsdAddName(po
, "@SYSTEM");
1059 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1061 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1062 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1063 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1064 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1065 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1066 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1067 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1068 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1069 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1070 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1071 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1072 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1073 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1074 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1075 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1076 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1077 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1078 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1080 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1082 cupsdLogMessage(CUPSD_LOG_INFO
,
1083 "<Limit Pause-Printer Resume-Printer "
1084 "Set-Printer-Attributes Enable-Printer "
1085 "Disable-Printer Pause-Printer-After-Current-Job "
1086 "Hold-New-Jobs Release-Held-New-Jobs "
1087 "Deactivate-Printer Activate-Printer Restart-Printer "
1088 "Shutdown-Printer Startup-Printer Promote-Job "
1089 "Schedule-Job-After CUPS-Add-Printer "
1090 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1091 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1092 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1093 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1095 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1096 po
->order_type
= CUPSD_AUTH_ALLOW
;
1097 po
->type
= CUPSD_AUTH_DEFAULT
;
1098 po
->level
= CUPSD_AUTH_USER
;
1100 cupsdAddName(po
, "@SYSTEM");
1101 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1103 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1104 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1105 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1106 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1107 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1108 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1109 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1110 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1111 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1112 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1113 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1114 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1115 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1116 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1117 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1118 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1119 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1120 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1121 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1122 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1123 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1125 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1127 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1128 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1130 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1131 po
->order_type
= CUPSD_AUTH_ALLOW
;
1133 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1134 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1139 cupsArrayCount(Policies
));
1140 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1142 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1143 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1144 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1147 * If we are doing a full reload or the server root has changed, flush
1148 * the jobs, printers, etc. and start from scratch...
1151 if (NeedReload
== RELOAD_ALL
||
1152 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1153 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1155 mime_type_t
*type
; /* Current type */
1156 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1157 /* MIME type name */
1160 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1163 * Free all memory...
1166 cupsdDeleteAllSubscriptions();
1168 cupsdDeleteAllClasses();
1169 cupsdDeleteAllPrinters();
1171 DefaultPrinter
= NULL
;
1173 if (MimeDatabase
!= NULL
)
1174 mimeDelete(MimeDatabase
);
1178 for (i
= 0; i
< NumMimeTypes
; i
++)
1179 _cupsStrFree(MimeTypes
[i
]);
1185 * Read the MIME type and conversion database...
1188 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1189 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1191 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1192 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1193 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1194 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1198 cupsdLogMessage(CUPSD_LOG_EMERG
,
1199 "Unable to load MIME database from \"%s\" or \"%s\"!",
1200 mimedir
, ServerRoot
);
1201 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1205 cupsdLogMessage(CUPSD_LOG_INFO
,
1206 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1207 "%d filters...", mimedir
, ServerRoot
,
1208 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1211 * Create a list of MIME types for the document-format-supported
1215 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1216 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1219 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1221 cupsdLogMessage(CUPSD_LOG_ERROR
,
1222 "Unable to allocate memory for %d MIME types!",
1228 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1230 i
++, type
= mimeNextType(MimeDatabase
))
1232 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1234 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1237 if (i
< NumMimeTypes
)
1238 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1241 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1243 mime_filter_t
*filter
; /* Current filter */
1246 for (type
= mimeFirstType(MimeDatabase
);
1248 type
= mimeNextType(MimeDatabase
))
1249 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1250 type
->super
, type
->type
);
1252 for (filter
= mimeFirstFilter(MimeDatabase
);
1254 filter
= mimeNextFilter(MimeDatabase
))
1255 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1256 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1257 filter
->src
->super
, filter
->src
->type
,
1258 filter
->dst
->super
, filter
->dst
->type
,
1259 filter
->cost
, filter
->filter
);
1266 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1267 cupsdLoadBanners(temp
);
1270 * Load printers and classes...
1273 cupsdLoadAllPrinters();
1274 cupsdLoadAllClasses();
1275 cupsdLoadRemoteCache();
1276 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1278 cupsdCreateCommonData();
1281 * Load queued jobs...
1287 * Load subscriptions...
1290 cupsdLoadAllSubscriptions();
1292 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1297 * Not a full reload, so recreate the common printer attributes...
1300 cupsdCreateCommonData();
1303 * Update all printers as needed...
1306 cupsdUpdatePrinters();
1307 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1309 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1313 * Reset the reload state...
1316 NeedReload
= RELOAD_NONE
;
1318 cupsdClearString(&old_serverroot
);
1319 cupsdClearString(&old_requestroot
);
1326 * 'get_address()' - Get an address + port number from a line.
1329 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1330 get_address(const char *value
, /* I - Value string */
1331 int defport
) /* I - Default port */
1333 char buffer
[1024], /* Hostname + port number buffer */
1334 defpname
[255], /* Default port name */
1335 *hostname
, /* Hostname or IP */
1336 *portname
; /* Port number or name */
1337 http_addrlist_t
*addrlist
; /* Address list */
1341 * Check for an empty value...
1346 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1351 * Grab a hostname and port number; if there is no colon and the port name
1352 * is only digits, then we have a port number by itself...
1355 strlcpy(buffer
, value
, sizeof(buffer
));
1357 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1364 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1369 * Use the default port...
1372 sprintf(defpname
, "%d", defport
);
1373 portname
= defpname
;
1379 * The buffer contains just a port number...
1387 if (hostname
&& !strcmp(hostname
, "*"))
1391 * Now lookup the address using httpAddrGetList()...
1394 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1395 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1396 hostname
? hostname
: "(nil)");
1403 * 'get_addr_and_mask()' - Get an IP address and netmask.
1406 static int /* O - 1 on success, 0 on failure */
1407 get_addr_and_mask(const char *value
, /* I - String from config file */
1408 unsigned *ip
, /* O - Address value */
1409 unsigned *mask
) /* O - Mask value */
1411 int i
, j
, /* Looping vars */
1412 family
, /* Address family */
1413 ipcount
; /* Count of fields in address */
1414 unsigned ipval
; /* Value */
1415 const char *maskval
, /* Pointer to start of mask value */
1416 *ptr
, /* Pointer into value */
1421 * Get the address...
1424 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1425 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1427 if ((maskval
= strchr(value
, '/')) != NULL
)
1430 maskval
= value
+ strlen(value
);
1434 * Check for an IPv6 address...
1440 * Parse hexadecimal IPv6 address...
1445 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1449 else if (!strncmp(ptr
, "::", 2))
1451 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1453 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1458 else if (isxdigit(*ptr
& 255))
1460 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1468 ip
[i
/ 2] |= ipval
<< 16;
1482 if (*ptr
&& *ptr
!= '/')
1486 #endif /* AF_INET6 */
1489 * Parse dotted-decimal IPv4 address...
1492 unsigned val
[4]; /* IPv4 address values */
1496 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1499 * Range check the IP numbers...
1502 for (i
= 0; i
< ipcount
; i
++)
1507 * Make sure the trailing values are zeroed, as some C libraries like
1508 * glibc apparently like to fill the unused arguments with garbage...
1511 for (i
= ipcount
; i
< 4; i
++)
1515 * Merge everything into a 32-bit IPv4 address in ip[3]...
1518 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1521 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1527 * Get the netmask value(s)...
1530 memset(mask
, 0, sizeof(unsigned) * 4);
1532 if (strchr(maskval
, '.'))
1535 * Get dotted-decimal mask...
1538 if (family
!= AF_INET
)
1541 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1544 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1545 mask
[0] = mask
[1] = mask
[2] = 0;
1550 * Get address/bits format...
1556 if (family
== AF_INET6
)
1564 mask
[0] = 0xffffffff;
1566 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1569 mask
[1] = 0xffffffff;
1573 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1576 mask
[2] = 0xffffffff;
1580 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1583 mask
[3] = 0xffffffff;
1587 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1590 #endif /* AF_INET6 */
1595 mask
[0] = 0xffffffff;
1596 mask
[1] = 0xffffffff;
1597 mask
[2] = 0xffffffff;
1600 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1602 mask
[3] = 0xffffffff;
1607 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1608 "get_addr_and_mask(value=\"%s\", "
1609 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1610 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1614 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1617 if ((ip
[0] & ~mask
[0]) != 0 ||
1618 (ip
[1] & ~mask
[1]) != 0 ||
1619 (ip
[2] & ~mask
[2]) != 0 ||
1620 (ip
[3] & ~mask
[3]) != 0)
1628 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1631 static int /* O - 1 on success, 0 on failure */
1632 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1633 char *line
, /* I - Line from file */
1634 char *value
, /* I - Start of value data */
1635 int linenum
) /* I - Current line number */
1637 char *valptr
; /* Pointer into value */
1638 unsigned ip
[4], /* IP address components */
1639 mask
[4]; /* IP netmask components */
1642 if (!strcasecmp(line
, "Encryption"))
1645 * "Encryption xxx" - set required encryption level...
1648 if (!strcasecmp(value
, "never"))
1649 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1650 else if (!strcasecmp(value
, "always"))
1652 cupsdLogMessage(CUPSD_LOG_ERROR
,
1653 "Encryption value \"%s\" on line %d is invalid in this "
1654 "context. Using \"required\" instead.", value
, linenum
);
1656 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1658 else if (!strcasecmp(value
, "required"))
1659 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1660 else if (!strcasecmp(value
, "ifrequested"))
1661 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1664 cupsdLogMessage(CUPSD_LOG_ERROR
,
1665 "Unknown Encryption value %s on line %d.", value
, linenum
);
1669 else if (!strcasecmp(line
, "Order"))
1672 * "Order Deny,Allow" or "Order Allow,Deny"...
1675 if (!strncasecmp(value
, "deny", 4))
1676 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1677 else if (!strncasecmp(value
, "allow", 5))
1678 loc
->order_type
= CUPSD_AUTH_DENY
;
1681 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1686 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1689 * Allow [From] host/ip...
1690 * Deny [From] host/ip...
1693 if (!strncasecmp(value
, "from", 4))
1696 * Strip leading "from"...
1701 while (isspace(*value
& 255))
1706 * Figure out what form the allow/deny address takes:
1717 * nnn.nnn.nnn.nnn/mm
1718 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1721 if (!strcasecmp(value
, "all"))
1727 if (!strcasecmp(line
, "Allow"))
1728 cupsdAllowIP(loc
, zeros
, zeros
);
1730 cupsdDenyIP(loc
, zeros
, zeros
);
1732 else if (!strcasecmp(value
, "none"))
1738 if (!strcasecmp(line
, "Allow"))
1739 cupsdAllowIP(loc
, ones
, zeros
);
1741 cupsdDenyIP(loc
, ones
, zeros
);
1744 else if (value
[0] == '*' || value
[0] == '.' ||
1745 (!isdigit(value
[0] & 255) && value
[0] != '['))
1747 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1748 #endif /* AF_INET6 */
1751 * Host or domain name...
1754 if (value
[0] == '*')
1757 if (!strcasecmp(line
, "Allow"))
1758 cupsdAllowHost(loc
, value
);
1760 cupsdDenyHost(loc
, value
);
1765 * One of many IP address forms...
1768 if (!get_addr_and_mask(value
, ip
, mask
))
1770 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1775 if (!strcasecmp(line
, "Allow"))
1776 cupsdAllowIP(loc
, ip
, mask
);
1778 cupsdDenyIP(loc
, ip
, mask
);
1781 else if (!strcasecmp(line
, "AuthType"))
1784 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1787 if (!strcasecmp(value
, "none"))
1789 loc
->type
= CUPSD_AUTH_NONE
;
1790 loc
->level
= CUPSD_AUTH_ANON
;
1792 else if (!strcasecmp(value
, "basic"))
1794 loc
->type
= CUPSD_AUTH_BASIC
;
1796 if (loc
->level
== CUPSD_AUTH_ANON
)
1797 loc
->level
= CUPSD_AUTH_USER
;
1799 else if (!strcasecmp(value
, "digest"))
1801 loc
->type
= CUPSD_AUTH_DIGEST
;
1803 if (loc
->level
== CUPSD_AUTH_ANON
)
1804 loc
->level
= CUPSD_AUTH_USER
;
1806 else if (!strcasecmp(value
, "basicdigest"))
1808 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1810 if (loc
->level
== CUPSD_AUTH_ANON
)
1811 loc
->level
= CUPSD_AUTH_USER
;
1813 else if (!strcasecmp(value
, "default"))
1815 loc
->type
= CUPSD_AUTH_DEFAULT
;
1817 if (loc
->level
== CUPSD_AUTH_ANON
)
1818 loc
->level
= CUPSD_AUTH_USER
;
1821 else if (!strcasecmp(value
, "negotiate"))
1823 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1825 if (loc
->level
== CUPSD_AUTH_ANON
)
1826 loc
->level
= CUPSD_AUTH_USER
;
1828 #endif /* HAVE_GSSAPI */
1831 cupsdLogMessage(CUPSD_LOG_WARN
,
1832 "Unknown authorization type %s on line %d.",
1837 else if (!strcasecmp(line
, "AuthClass"))
1840 * AuthClass anonymous, user, system, group
1843 if (!strcasecmp(value
, "anonymous"))
1845 loc
->type
= CUPSD_AUTH_NONE
;
1846 loc
->level
= CUPSD_AUTH_ANON
;
1848 cupsdLogMessage(CUPSD_LOG_WARN
,
1849 "\"AuthClass %s\" is deprecated; consider removing "
1853 else if (!strcasecmp(value
, "user"))
1855 loc
->level
= CUPSD_AUTH_USER
;
1857 cupsdLogMessage(CUPSD_LOG_WARN
,
1858 "\"AuthClass %s\" is deprecated; consider using "
1859 "\"Require valid-user\" on line %d.",
1862 else if (!strcasecmp(value
, "group"))
1864 loc
->level
= CUPSD_AUTH_GROUP
;
1866 cupsdLogMessage(CUPSD_LOG_WARN
,
1867 "\"AuthClass %s\" is deprecated; consider using "
1868 "\"Require user @groupname\" on line %d.",
1871 else if (!strcasecmp(value
, "system"))
1873 loc
->level
= CUPSD_AUTH_GROUP
;
1875 cupsdAddName(loc
, "@SYSTEM");
1877 cupsdLogMessage(CUPSD_LOG_WARN
,
1878 "\"AuthClass %s\" is deprecated; consider using "
1879 "\"Require user @SYSTEM\" on line %d.",
1884 cupsdLogMessage(CUPSD_LOG_WARN
,
1885 "Unknown authorization class %s on line %d.",
1890 else if (!strcasecmp(line
, "AuthGroupName"))
1892 cupsdAddName(loc
, value
);
1894 cupsdLogMessage(CUPSD_LOG_WARN
,
1895 "\"AuthGroupName %s\" directive is deprecated; consider "
1896 "using \"Require user @%s\" on line %d.",
1897 value
, value
, linenum
);
1899 else if (!strcasecmp(line
, "Require"))
1902 * Apache synonym for AuthClass and AuthGroupName...
1906 * Require valid-user
1907 * Require group names
1908 * Require user names
1911 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1916 if (!strcasecmp(value
, "valid-user") ||
1917 !strcasecmp(value
, "user"))
1918 loc
->level
= CUPSD_AUTH_USER
;
1919 else if (!strcasecmp(value
, "group"))
1920 loc
->level
= CUPSD_AUTH_GROUP
;
1923 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1929 * Get the list of names from the line...
1932 for (value
= valptr
; *value
;)
1934 while (isspace(*value
& 255))
1937 #ifdef HAVE_AUTHORIZATION_H
1938 if (!strncmp(value
, "@AUTHKEY(", 9))
1941 * Grab "@AUTHKEY(name)" value...
1944 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1950 #endif /* HAVE_AUTHORIZATION_H */
1951 if (*value
== '\"' || *value
== '\'')
1954 * Grab quoted name...
1957 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1964 * Grab literal name.
1967 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1973 cupsdAddName(loc
, value
);
1975 for (value
= valptr
; isspace(*value
& 255); value
++);
1978 else if (!strcasecmp(line
, "Satisfy"))
1980 if (!strcasecmp(value
, "all"))
1981 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1982 else if (!strcasecmp(value
, "any"))
1983 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1986 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1999 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2002 static int /* O - FatalErrors bits */
2003 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2005 int fatal
; /* FatalErrors bits */
2006 char value
[1024], /* Value string */
2007 *valstart
, /* Pointer into value */
2008 *valend
; /* End of value */
2012 * Empty FatalErrors line yields NULL pointer...
2016 return (CUPSD_FATAL_NONE
);
2019 * Loop through the value string,...
2022 strlcpy(value
, s
, sizeof(value
));
2024 fatal
= CUPSD_FATAL_NONE
;
2026 for (valstart
= value
; *valstart
;)
2029 * Get the current space/comma-delimited kind name...
2032 for (valend
= valstart
; *valend
; valend
++)
2033 if (isspace(*valend
& 255) || *valend
== ',')
2040 * Add the error to the bitmask...
2043 if (!strcasecmp(valstart
, "all"))
2044 fatal
= CUPSD_FATAL_ALL
;
2045 else if (!strcasecmp(valstart
, "browse"))
2046 fatal
|= CUPSD_FATAL_BROWSE
;
2047 else if (!strcasecmp(valstart
, "-browse"))
2048 fatal
&= ~CUPSD_FATAL_BROWSE
;
2049 else if (!strcasecmp(valstart
, "config"))
2050 fatal
|= CUPSD_FATAL_CONFIG
;
2051 else if (!strcasecmp(valstart
, "-config"))
2052 fatal
&= ~CUPSD_FATAL_CONFIG
;
2053 else if (!strcasecmp(valstart
, "listen"))
2054 fatal
|= CUPSD_FATAL_LISTEN
;
2055 else if (!strcasecmp(valstart
, "-listen"))
2056 fatal
&= ~CUPSD_FATAL_LISTEN
;
2057 else if (!strcasecmp(valstart
, "log"))
2058 fatal
|= CUPSD_FATAL_LOG
;
2059 else if (!strcasecmp(valstart
, "-log"))
2060 fatal
&= ~CUPSD_FATAL_LOG
;
2061 else if (!strcasecmp(valstart
, "permissions"))
2062 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2063 else if (!strcasecmp(valstart
, "-permissions"))
2064 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2065 else if (strcasecmp(valstart
, "none"))
2066 cupsdLogMessage(CUPSD_LOG_ERROR
,
2067 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2069 for (valstart
= valend
; *valstart
; valstart
++)
2070 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2079 * 'parse_groups()' - Parse system group names in a string.
2082 static int /* O - 1 on success, 0 on failure */
2083 parse_groups(const char *s
) /* I - Space-delimited groups */
2085 int status
; /* Return status */
2086 char value
[1024], /* Value string */
2087 *valstart
, /* Pointer into value */
2088 *valend
, /* End of value */
2089 quote
; /* Quote character */
2090 struct group
*group
; /* Group */
2094 * Make a copy of the string and parse out the groups...
2097 strlcpy(value
, s
, sizeof(value
));
2102 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2104 if (*valstart
== '\'' || *valstart
== '\"')
2107 * Scan quoted name...
2110 quote
= *valstart
++;
2112 for (valend
= valstart
; *valend
; valend
++)
2113 if (*valend
== quote
)
2119 * Scan space or comma-delimited name...
2122 for (valend
= valstart
; *valend
; valend
++)
2123 if (isspace(*valend
) || *valend
== ',')
2130 group
= getgrnam(valstart
);
2133 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2134 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2145 while (*valstart
== ',' || isspace(*valstart
))
2154 * 'parse_protocols()' - Parse browse protocols in a string.
2157 static int /* O - Browse protocol bits */
2158 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2160 int protocols
; /* Browse protocol bits */
2161 char value
[1024], /* Value string */
2162 *valstart
, /* Pointer into value */
2163 *valend
; /* End of value */
2167 * Empty protocol line yields NULL pointer...
2174 * Loop through the value string,...
2177 strlcpy(value
, s
, sizeof(value
));
2181 for (valstart
= value
; *valstart
;)
2184 * Get the current space/comma-delimited protocol name...
2187 for (valend
= valstart
; *valend
; valend
++)
2188 if (isspace(*valend
& 255) || *valend
== ',')
2195 * Add the protocol to the bitmask...
2198 if (!strcasecmp(valstart
, "cups"))
2199 protocols
|= BROWSE_CUPS
;
2200 else if (!strcasecmp(valstart
, "slp"))
2201 protocols
|= BROWSE_SLP
;
2202 else if (!strcasecmp(valstart
, "ldap"))
2203 protocols
|= BROWSE_LDAP
;
2204 else if (!strcasecmp(valstart
, "dnssd") ||
2205 !strcasecmp(valstart
, "dns-sd") ||
2206 !strcasecmp(valstart
, "bonjour"))
2207 protocols
|= BROWSE_DNSSD
;
2208 else if (!strcasecmp(valstart
, "lpd"))
2209 protocols
|= BROWSE_LPD
;
2210 else if (!strcasecmp(valstart
, "smb"))
2211 protocols
|= BROWSE_SMB
;
2212 else if (!strcasecmp(valstart
, "all"))
2213 protocols
|= BROWSE_ALL
;
2214 else if (strcasecmp(valstart
, "none"))
2215 cupsdLogMessage(CUPSD_LOG_ERROR
,
2216 "Unknown browse protocol \"%s\" ignored!", valstart
);
2218 for (valstart
= valend
; *valstart
; valstart
++)
2219 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2228 * 'read_configuration()' - Read a configuration file.
2231 static int /* O - 1 on success, 0 on failure */
2232 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2234 int i
; /* Looping var */
2235 int linenum
; /* Current line number */
2236 char line
[HTTP_MAX_BUFFER
],
2237 /* Line from file */
2238 temp
[HTTP_MAX_BUFFER
],
2239 /* Temporary buffer for value */
2240 temp2
[HTTP_MAX_BUFFER
],
2241 /* Temporary buffer 2 for value */
2242 *ptr
, /* Pointer into line/temp */
2243 *value
, /* Pointer to value */
2244 *valueptr
; /* Pointer into value */
2245 int valuelen
; /* Length of value */
2246 cupsd_var_t
const *var
; /* Current variable */
2247 http_addrlist_t
*addrlist
, /* Address list */
2248 *addr
; /* Current address */
2249 unsigned ip
[4], /* Address value */
2250 mask
[4]; /* Netmask value */
2251 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2252 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2253 cupsd_location_t
*location
; /* Browse location */
2254 cups_file_t
*incfile
; /* Include file */
2255 char incname
[1024]; /* Include filename */
2256 struct group
*group
; /* Group */
2260 * Loop through each line in the file...
2265 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2268 * Decode the directive...
2271 if (!strcasecmp(line
, "Include") && value
)
2277 if (value
[0] == '/')
2278 strlcpy(incname
, value
, sizeof(incname
));
2280 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2282 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2283 cupsdLogMessage(CUPSD_LOG_ERROR
,
2284 "Unable to include config file \"%s\" - %s",
2285 incname
, strerror(errno
));
2288 read_configuration(incfile
);
2289 cupsFileClose(incfile
);
2292 else if (!strcasecmp(line
, "<Location") && value
)
2298 linenum
= read_location(fp
, value
, linenum
);
2302 else if (!strcasecmp(line
, "<Policy") && value
)
2308 linenum
= read_policy(fp
, value
, linenum
);
2312 else if (!strcasecmp(line
, "FatalErrors"))
2313 FatalErrors
= parse_fatal_errors(value
);
2314 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2316 JobRetryInterval
= atoi(value
);
2317 cupsdLogMessage(CUPSD_LOG_WARN
,
2318 "FaxRetryInterval is deprecated; use "
2319 "JobRetryInterval on line %d.", linenum
);
2321 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2323 JobRetryLimit
= atoi(value
);
2324 cupsdLogMessage(CUPSD_LOG_WARN
,
2325 "FaxRetryLimit is deprecated; use "
2326 "JobRetryLimit on line %d.", linenum
);
2328 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2330 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2331 #endif /* HAVE_SSL */
2335 * Add listening address(es) to the list...
2338 cupsd_listener_t
*lis
; /* New listeners array */
2342 * Get the address list...
2345 addrlist
= get_address(value
, IPP_PORT
);
2349 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2355 * Add each address...
2358 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2361 * See if this address is already present...
2364 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2366 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2367 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2368 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2373 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2374 cupsdLogMessage(CUPSD_LOG_WARN
,
2375 "Duplicate listen address \"%s\" ignored!", temp
);
2380 * Allocate another listener...
2384 Listeners
= cupsArrayNew(NULL
, NULL
);
2388 cupsdLogMessage(CUPSD_LOG_ERROR
,
2389 "Unable to allocate %s at line %d - %s.",
2390 line
, linenum
, strerror(errno
));
2394 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2396 cupsdLogMessage(CUPSD_LOG_ERROR
,
2397 "Unable to allocate %s at line %d - %s.",
2398 line
, linenum
, strerror(errno
));
2402 cupsArrayAdd(Listeners
, lis
);
2405 * Copy the current address and log it...
2408 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2412 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2413 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2414 #endif /* HAVE_SSL */
2416 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2419 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2420 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2421 ntohs(lis
->address
.ipv6
.sin6_port
));
2423 #endif /* AF_INET6 */
2425 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2426 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2428 #endif /* AF_LOCAL */
2429 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2430 ntohs(lis
->address
.ipv4
.sin_port
));
2437 httpAddrFreeList(addrlist
);
2439 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2442 * Add a browse address to the list...
2445 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2448 if (NumBrowsers
== 0)
2449 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2451 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2455 cupsdLogMessage(CUPSD_LOG_ERROR
,
2456 "Unable to allocate BrowseAddress at line %d - %s.",
2457 linenum
, strerror(errno
));
2462 dira
+= NumBrowsers
;
2464 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2466 if (!strcasecmp(value
, "@LOCAL"))
2469 * Send browse data to all local interfaces...
2472 strcpy(dira
->iface
, "*");
2475 else if (!strncasecmp(value
, "@IF(", 4))
2478 * Send browse data to the named interface...
2481 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2483 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2489 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2492 * Only IPv4 addresses are supported...
2495 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2496 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2501 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2502 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2504 cupsdLogMessage(CUPSD_LOG_INFO
,
2505 "Sending browsing info to %s:%d (IPv4)",
2506 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2511 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2514 httpAddrFreeList(addrlist
);
2517 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2520 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2523 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2526 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2527 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2529 if (location
== NULL
)
2530 cupsdLogMessage(CUPSD_LOG_ERROR
,
2531 "Unable to initialize browse access control list!");
2532 else if (!strncasecmp(value
, "deny", 4))
2533 location
->order_type
= CUPSD_AUTH_ALLOW
;
2534 else if (!strncasecmp(value
, "allow", 5))
2535 location
->order_type
= CUPSD_AUTH_DENY
;
2537 cupsdLogMessage(CUPSD_LOG_ERROR
,
2538 "Unknown BrowseOrder value %s on line %d.",
2541 else if (!strcasecmp(line
, "BrowseProtocols") ||
2542 !strcasecmp(line
, "BrowseLocalProtocols") ||
2543 !strcasecmp(line
, "BrowseRemoteProtocols"))
2546 * "BrowseProtocols name [... name]"
2547 * "BrowseLocalProtocols name [... name]"
2548 * "BrowseRemoteProtocols name [... name]"
2551 int protocols
= parse_protocols(value
);
2555 cupsdLogMessage(CUPSD_LOG_ERROR
,
2556 "Unknown browse protocol \"%s\" on line %d.",
2561 if (strcasecmp(line
, "BrowseLocalProtocols"))
2562 BrowseRemoteProtocols
= protocols
;
2563 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2564 BrowseLocalProtocols
= protocols
;
2566 else if ((!strcasecmp(line
, "BrowseAllow") ||
2567 !strcasecmp(line
, "BrowseDeny")) && value
)
2570 * BrowseAllow [From] host/ip...
2571 * BrowseDeny [From] host/ip...
2574 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2575 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2577 if (location
== NULL
)
2578 cupsdLogMessage(CUPSD_LOG_ERROR
,
2579 "Unable to initialize browse access control list!");
2582 if (!strncasecmp(value
, "from ", 5))
2585 * Strip leading "from"...
2590 while (isspace(*value
))
2595 * Figure out what form the allow/deny address takes:
2606 * nnn.nnn.nnn.nnn/mm
2607 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2610 if (!strcasecmp(value
, "all"))
2616 if (!strcasecmp(line
, "BrowseAllow"))
2617 cupsdAllowIP(location
, zeros
, zeros
);
2619 cupsdDenyIP(location
, zeros
, zeros
);
2621 else if (!strcasecmp(value
, "none"))
2627 if (!strcasecmp(line
, "BrowseAllow"))
2628 cupsdAllowIP(location
, ones
, zeros
);
2630 cupsdDenyIP(location
, ones
, zeros
);
2633 else if (value
[0] == '*' || value
[0] == '.' ||
2634 (!isdigit(value
[0] & 255) && value
[0] != '['))
2636 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2637 #endif /* AF_INET6 */
2640 * Host or domain name...
2643 if (value
[0] == '*')
2646 if (!strcasecmp(line
, "BrowseAllow"))
2647 cupsdAllowHost(location
, value
);
2649 cupsdDenyHost(location
, value
);
2654 * One of many IP address forms...
2657 if (!get_addr_and_mask(value
, ip
, mask
))
2659 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2664 if (!strcasecmp(line
, "BrowseAllow"))
2665 cupsdAllowIP(location
, ip
, mask
);
2667 cupsdDenyIP(location
, ip
, mask
);
2671 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2674 * BrowseRelay [from] source [to] destination
2678 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2680 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2684 cupsdLogMessage(CUPSD_LOG_ERROR
,
2685 "Unable to allocate BrowseRelay at line %d - %s.",
2686 linenum
, strerror(errno
));
2693 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2695 if (!strncasecmp(value
, "from ", 5))
2698 * Strip leading "from"...
2703 while (isspace(*value
))
2708 * Figure out what form the from address takes:
2717 * nnn.nnn.nnn.nnn/mm
2718 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2722 if (value
[0] == '*' || value
[0] == '.' ||
2723 (!isdigit(value
[0] & 255) && value
[0] != '['))
2725 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2726 #endif /* AF_INET6 */
2729 * Host or domain name...
2732 if (value
[0] == '*')
2735 strlcpy(temp
, value
, sizeof(temp
));
2736 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2739 relay
->from
.type
= CUPSD_AUTH_NAME
;
2741 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2743 cupsdLogMessage(CUPSD_LOG_ERROR
,
2744 "Unable to allocate BrowseRelay name at line %d - %s.",
2745 linenum
, strerror(errno
));
2749 relay
->from
.mask
.name
.length
= strlen(temp
);
2754 * One of many IP address forms...
2757 if (!get_addr_and_mask(value
, ip
, mask
))
2759 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2764 relay
->from
.type
= CUPSD_AUTH_IP
;
2765 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2766 sizeof(relay
->from
.mask
.ip
.address
));
2767 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2768 sizeof(relay
->from
.mask
.ip
.netmask
));
2772 * Skip value and trailing whitespace...
2775 for (; *value
; value
++)
2776 if (isspace(*value
))
2779 while (isspace(*value
))
2782 if (!strncasecmp(value
, "to ", 3))
2785 * Strip leading "to"...
2790 while (isspace(*value
))
2795 * Get "to" address and port...
2798 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2801 * Only IPv4 addresses are supported...
2804 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2805 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2810 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2812 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2814 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2815 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2816 relay
->from
.mask
.ip
.address
[0] >> 24,
2817 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2818 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2819 relay
->from
.mask
.ip
.address
[0] & 255,
2820 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2821 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2822 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2823 relay
->from
.mask
.ip
.netmask
[0] & 255);
2825 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2827 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2828 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2833 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2836 httpAddrFreeList(addrlist
);
2840 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2841 free(relay
->from
.mask
.name
.name
);
2843 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2847 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2850 * BrowsePoll address[:port]
2853 char *portname
; /* Port name */
2854 int portnum
; /* Port number */
2855 struct servent
*service
; /* Service */
2859 * Extract the port name from the address...
2862 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2866 if (isdigit(*portname
& 255))
2867 portnum
= atoi(portname
);
2868 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2869 portnum
= ntohs(service
->s_port
);
2872 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2878 portnum
= ippPort();
2881 * Add the poll entry...
2885 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2887 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2891 cupsdLogMessage(CUPSD_LOG_ERROR
,
2892 "Unable to allocate BrowsePoll at line %d - %s.",
2893 linenum
, strerror(errno
));
2901 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2903 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2904 pollp
->port
= portnum
;
2906 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2909 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2912 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2915 if (!strcasecmp(value
, "none"))
2916 DefaultAuthType
= CUPSD_AUTH_NONE
;
2917 else if (!strcasecmp(value
, "basic"))
2918 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2919 else if (!strcasecmp(value
, "digest"))
2920 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2921 else if (!strcasecmp(value
, "basicdigest"))
2922 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2924 else if (!strcasecmp(value
, "negotiate"))
2925 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2926 #endif /* HAVE_GSSAPI */
2929 cupsdLogMessage(CUPSD_LOG_WARN
,
2930 "Unknown default authorization type %s on line %d.",
2932 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2937 else if (!strcasecmp(line
, "DefaultEncryption"))
2940 * DefaultEncryption {Never,IfRequested,Required}
2943 if (!value
|| !strcasecmp(value
, "never"))
2944 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2945 else if (!strcasecmp(value
, "required"))
2946 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2947 else if (!strcasecmp(value
, "ifrequested"))
2948 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2951 cupsdLogMessage(CUPSD_LOG_WARN
,
2952 "Unknown default encryption %s on line %d.",
2954 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2958 #endif /* HAVE_SSL */
2960 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
2962 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2965 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2966 gsskrb5_register_acceptor_identity(value
);
2968 cupsdSetEnv("KRB5_KTNAME", value
);
2969 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2971 #endif /* HAVE_GSSAPI */
2972 else if (!strcasecmp(line
, "User") && value
)
2975 * User ID to run as...
2978 if (isdigit(value
[0] & 255))
2980 int uid
= atoi(value
);
2983 cupsdLogMessage(CUPSD_LOG_ERROR
,
2984 "Will not use User 0 as specified on line %d "
2985 "for security reasons. You must use a non-"
2986 "privileged account instead.",
2993 struct passwd
*p
; /* Password information */
2996 p
= getpwnam(value
);
3001 cupsdLogMessage(CUPSD_LOG_ERROR
,
3002 "Will not use User %s (UID=0) as specified on line "
3003 "%d for security reasons. You must use a non-"
3004 "privileged account instead.",
3010 cupsdLogMessage(CUPSD_LOG_ERROR
,
3011 "Unknown User \"%s\" on line %d, ignoring!",
3015 else if (!strcasecmp(line
, "Group") && value
)
3018 * Group ID to run as...
3021 if (isdigit(value
[0]))
3022 Group
= atoi(value
);
3026 group
= getgrnam(value
);
3029 Group
= group
->gr_gid
;
3031 cupsdLogMessage(CUPSD_LOG_ERROR
,
3032 "Unknown Group \"%s\" on line %d, ignoring!",
3036 else if (!strcasecmp(line
, "SystemGroup") && value
)
3039 * SystemGroup (admin) group(s)...
3042 if (!parse_groups(value
))
3043 cupsdLogMessage(CUPSD_LOG_ERROR
,
3044 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3047 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3050 * Do hostname lookups?
3053 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3054 !strcasecmp(value
, "false"))
3055 HostNameLookups
= 0;
3056 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3057 !strcasecmp(value
, "true"))
3058 HostNameLookups
= 1;
3059 else if (!strcasecmp(value
, "double"))
3060 HostNameLookups
= 2;
3062 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3065 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3068 * Amount of logging to do to access log...
3071 if (!strcasecmp(value
, "all"))
3072 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3073 else if (!strcasecmp(value
, "actions"))
3074 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3075 else if (!strcasecmp(value
, "config"))
3076 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3078 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3081 else if (!strcasecmp(line
, "LogLevel") && value
)
3084 * Amount of logging to do to error log...
3087 if (!strcasecmp(value
, "debug2"))
3088 LogLevel
= CUPSD_LOG_DEBUG2
;
3089 else if (!strcasecmp(value
, "debug"))
3090 LogLevel
= CUPSD_LOG_DEBUG
;
3091 else if (!strcasecmp(value
, "info"))
3092 LogLevel
= CUPSD_LOG_INFO
;
3093 else if (!strcasecmp(value
, "notice"))
3094 LogLevel
= CUPSD_LOG_NOTICE
;
3095 else if (!strcasecmp(value
, "warn"))
3096 LogLevel
= CUPSD_LOG_WARN
;
3097 else if (!strcasecmp(value
, "error"))
3098 LogLevel
= CUPSD_LOG_ERROR
;
3099 else if (!strcasecmp(value
, "crit"))
3100 LogLevel
= CUPSD_LOG_CRIT
;
3101 else if (!strcasecmp(value
, "alert"))
3102 LogLevel
= CUPSD_LOG_ALERT
;
3103 else if (!strcasecmp(value
, "emerg"))
3104 LogLevel
= CUPSD_LOG_EMERG
;
3105 else if (!strcasecmp(value
, "none"))
3106 LogLevel
= CUPSD_LOG_NONE
;
3108 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3111 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3114 * Format of printcap file?
3117 if (!strcasecmp(value
, "bsd"))
3118 PrintcapFormat
= PRINTCAP_BSD
;
3119 else if (!strcasecmp(value
, "solaris"))
3120 PrintcapFormat
= PRINTCAP_SOLARIS
;
3122 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3125 else if (!strcasecmp(line
, "ServerTokens") && value
)
3128 * Set the string used for the Server header...
3131 struct utsname plat
; /* Platform info */
3136 if (!strcasecmp(value
, "ProductOnly"))
3137 cupsdSetString(&ServerHeader
, "CUPS");
3138 else if (!strcasecmp(value
, "Major"))
3139 cupsdSetString(&ServerHeader
, "CUPS/1");
3140 else if (!strcasecmp(value
, "Minor"))
3141 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3142 else if (!strcasecmp(value
, "Minimal"))
3143 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3144 else if (!strcasecmp(value
, "OS"))
3145 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3146 else if (!strcasecmp(value
, "Full"))
3147 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3149 else if (!strcasecmp(value
, "None"))
3150 cupsdClearString(&ServerHeader
);
3152 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3155 else if (!strcasecmp(line
, "PassEnv") && value
)
3158 * PassEnv variable [... variable]
3163 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3164 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3167 if (value
[valuelen
])
3169 value
[valuelen
] = '\0';
3173 cupsdSetEnv(value
, NULL
);
3175 for (value
+= valuelen
; *value
; value
++)
3176 if (!isspace(*value
) || *value
!= ',')
3180 else if (!strcasecmp(line
, "SetEnv") && value
)
3183 * SetEnv variable value
3186 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3194 while (isspace(*valueptr
& 255))
3197 cupsdSetEnv(value
, valueptr
);
3200 cupsdLogMessage(CUPSD_LOG_ERROR
,
3201 "Missing value for SetEnv directive on line %d.",
3204 else if (!strcasecmp(line
, "SSLOptions"))
3207 * SSLOptions options
3210 if (!value
|| !strcasecmp(value
, "none"))
3211 SSLOptions
= CUPSD_SSL_NONE
;
3212 else if (!strcasecmp(value
, "noemptyfragments"))
3213 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3215 cupsdLogMessage(CUPSD_LOG_ERROR
,
3216 "Unknown value \"%s\" for SSLOptions directive on "
3217 "line %d.", value
, linenum
);
3222 * Find a simple variable in the list...
3225 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3226 if (!strcasecmp(line
, var
->name
))
3232 * Unknown directive! Output an error message and continue...
3236 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3239 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3246 case CUPSD_VARTYPE_INTEGER
:
3248 cupsdLogMessage(CUPSD_LOG_ERROR
,
3249 "Missing integer value for %s on line %d!",
3254 char *units
; /* Units */
3257 n
= strtol(value
, &units
, 0);
3259 if (units
&& *units
)
3261 if (tolower(units
[0] & 255) == 'g')
3262 n
*= 1024 * 1024 * 1024;
3263 else if (tolower(units
[0] & 255) == 'm')
3265 else if (tolower(units
[0] & 255) == 'k')
3267 else if (tolower(units
[0] & 255) == 't')
3272 cupsdLogMessage(CUPSD_LOG_ERROR
,
3273 "Bad negative integer value for %s on line %d!",
3276 *((int *)var
->ptr
) = n
;
3280 case CUPSD_VARTYPE_BOOLEAN
:
3282 cupsdLogMessage(CUPSD_LOG_ERROR
,
3283 "Missing boolean value for %s on line %d!",
3285 else if (!strcasecmp(value
, "true") ||
3286 !strcasecmp(value
, "on") ||
3287 !strcasecmp(value
, "enabled") ||
3288 !strcasecmp(value
, "yes") ||
3290 *((int *)var
->ptr
) = TRUE
;
3291 else if (!strcasecmp(value
, "false") ||
3292 !strcasecmp(value
, "off") ||
3293 !strcasecmp(value
, "disabled") ||
3294 !strcasecmp(value
, "no") ||
3295 !strcasecmp(value
, "0"))
3296 *((int *)var
->ptr
) = FALSE
;
3298 cupsdLogMessage(CUPSD_LOG_ERROR
,
3299 "Unknown boolean value %s on line %d.",
3303 case CUPSD_VARTYPE_PATHNAME
:
3306 cupsdLogMessage(CUPSD_LOG_ERROR
,
3307 "Missing pathname value for %s on line %d!",
3312 if (value
[0] == '/')
3313 strlcpy(temp
, value
, sizeof(temp
));
3315 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3317 if (access(temp
, 0))
3319 cupsdLogMessage(CUPSD_LOG_ERROR
,
3320 "File or directory for \"%s %s\" on line %d "
3321 "does not exist!", line
, value
, linenum
);
3325 case CUPSD_VARTYPE_STRING
:
3326 cupsdSetString((char **)var
->ptr
, value
);
3337 * 'read_location()' - Read a <Location path> definition.
3340 static int /* O - New line number or 0 on error */
3341 read_location(cups_file_t
*fp
, /* I - Configuration file */
3342 char *location
, /* I - Location name/path */
3343 int linenum
) /* I - Current line number */
3345 cupsd_location_t
*loc
, /* New location */
3346 *parent
; /* Parent location */
3347 char line
[HTTP_MAX_BUFFER
],
3349 *value
, /* Value for directive */
3350 *valptr
; /* Pointer into value */
3353 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3356 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3359 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3362 * Decode the directive...
3365 if (!strcasecmp(line
, "</Location>"))
3367 else if (!strcasecmp(line
, "<Limit") ||
3368 !strcasecmp(line
, "<LimitExcept"))
3372 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3373 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3379 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3385 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3390 if (!strcmp(value
, "ALL"))
3391 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3392 else if (!strcmp(value
, "GET"))
3393 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3394 else if (!strcmp(value
, "HEAD"))
3395 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3396 else if (!strcmp(value
, "OPTIONS"))
3397 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3398 else if (!strcmp(value
, "POST"))
3399 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3400 else if (!strcmp(value
, "PUT"))
3401 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3402 else if (!strcmp(value
, "TRACE"))
3403 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3405 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3408 for (value
= valptr
; isspace(*value
& 255); value
++);
3411 if (!strcasecmp(line
, "<LimitExcept"))
3412 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3414 parent
->limit
&= ~loc
->limit
;
3416 else if (!strcasecmp(line
, "</Limit>") ||
3417 !strcasecmp(line
, "</LimitExcept>"))
3419 else if (!parse_aaa(loc
, line
, value
, linenum
))
3421 cupsdLogMessage(CUPSD_LOG_ERROR
,
3422 "Unknown Location directive %s on line %d.",
3424 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3429 cupsdLogMessage(CUPSD_LOG_ERROR
,
3430 "Unexpected end-of-file at line %d while reading location!",
3433 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3438 * 'read_policy()' - Read a <Policy name> definition.
3441 static int /* O - New line number or 0 on error */
3442 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3443 char *policy
, /* I - Location name/path */
3444 int linenum
) /* I - Current line number */
3446 int i
; /* Looping var */
3447 cupsd_policy_t
*pol
; /* Policy */
3448 cupsd_location_t
*op
; /* Policy operation */
3449 int num_ops
; /* Number of IPP operations */
3450 ipp_op_t ops
[100]; /* Operations */
3451 char line
[HTTP_MAX_BUFFER
],
3453 *value
, /* Value for directive */
3454 *valptr
; /* Pointer into value */
3458 * Create the policy...
3461 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3465 * Read from the file...
3471 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3474 * Decode the directive...
3477 if (!strcasecmp(line
, "</Policy>"))
3480 cupsdLogMessage(CUPSD_LOG_WARN
,
3481 "Missing </Limit> before </Policy> on line %d!",
3485 * Verify that we have an explicit policy for CUPS-Get-Document
3486 * (ensures that upgrades do not introduce new security issues...)
3489 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3490 op
->op
== IPP_ANY_OPERATION
)
3492 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3493 op
->op
!= IPP_ANY_OPERATION
)
3496 * Add a new limit for CUPS-Get-Document using the Send-Document
3497 * limit as a template...
3500 cupsdLogMessage(CUPSD_LOG_WARN
,
3501 "No limit for CUPS-Get-Document defined in policy %s "
3502 "- using Send-Document's policy", pol
->name
);
3504 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3510 else if (!strcasecmp(line
, "<Limit") && !op
)
3514 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3515 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3522 * Scan for IPP operation names...
3529 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3534 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3536 if (!strcasecmp(value
, "All"))
3537 ops
[num_ops
] = IPP_ANY_OPERATION
;
3538 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3539 cupsdLogMessage(CUPSD_LOG_ERROR
,
3540 "Bad IPP operation name \"%s\" on line %d!",
3546 cupsdLogMessage(CUPSD_LOG_ERROR
,
3547 "Too many operations listed on line %d!",
3550 for (value
= valptr
; isspace(*value
& 255); value
++);
3554 * If none are specified, apply the policy to all operations...
3559 ops
[0] = IPP_ANY_OPERATION
;
3564 * Add a new policy for the first operation...
3567 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3569 else if (!strcasecmp(line
, "</Limit>") && op
)
3572 * Finish the current operation limit...
3578 * Copy the policy to the other operations...
3581 for (i
= 1; i
< num_ops
; i
++)
3582 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3589 cupsdLogMessage(CUPSD_LOG_ERROR
,
3590 "Missing <Limit ops> directive before %s on line %d.",
3592 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3595 else if (!parse_aaa(op
, line
, value
, linenum
))
3598 cupsdLogMessage(CUPSD_LOG_ERROR
,
3599 "Unknown Policy Limit directive %s on line %d.",
3602 cupsdLogMessage(CUPSD_LOG_ERROR
,
3603 "Unknown Policy directive %s on line %d.",
3606 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3611 cupsdLogMessage(CUPSD_LOG_ERROR
,
3612 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3615 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3620 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".