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-2009 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 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
154 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
155 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
156 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
157 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
158 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
159 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
160 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
161 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
162 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
163 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
164 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
165 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
166 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
168 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
169 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
170 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
171 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
172 #endif /* HAVE_SSL */
173 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
174 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
175 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
176 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
177 #ifdef HAVE_AUTHORIZATION_H
178 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
179 #endif /* HAVE_AUTHORIZATION_H */
180 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
181 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
182 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
184 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
187 static const unsigned ones
[4] =
189 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
191 static const unsigned zeros
[4] =
193 0x00000000, 0x00000000, 0x00000000, 0x00000000
200 static http_addrlist_t
*get_address(const char *value
, int defport
);
201 static int get_addr_and_mask(const char *value
, unsigned *ip
,
203 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
204 char *value
, int linenum
);
205 static int parse_fatal_errors(const char *s
);
206 static int parse_groups(const char *s
);
207 static int parse_protocols(const char *s
);
208 static int read_configuration(cups_file_t
*fp
);
209 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
210 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
214 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
217 int /* O - 0 on success, -1 on error, 1 on warning */
218 cupsdCheckPermissions(
219 const char *filename
, /* I - File/directory name */
220 const char *suffix
, /* I - Additional file/directory name */
221 int mode
, /* I - Permissions */
222 int user
, /* I - Owner */
223 int group
, /* I - Group */
224 int is_dir
, /* I - 1 = directory, 0 = file */
225 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
227 int dir_created
= 0; /* Did we create a directory? */
228 char pathname
[1024]; /* File name with prefix */
229 struct stat fileinfo
; /* Stat buffer */
230 int is_symlink
; /* Is "filename" a symlink? */
234 * Prepend the given root to the filename before testing it...
239 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
244 * See if we can stat the file/directory...
247 if (lstat(filename
, &fileinfo
))
249 if (errno
== ENOENT
&& create_dir
)
252 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
255 if (mkdir(filename
, mode
))
258 cupsdLogMessage(CUPSD_LOG_ERROR
,
259 "Unable to create directory \"%s\" - %s", filename
,
262 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
269 fileinfo
.st_mode
= mode
| S_IFDIR
;
272 return (create_dir
? -1 : 1);
275 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
277 if (stat(filename
, &fileinfo
))
279 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
280 filename
, strerror(errno
));
286 * Make sure it's a regular file or a directory as needed...
289 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
291 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
295 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
298 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
300 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
306 * If the filename is a symlink, do not change permissions (STR #2937)...
313 * Fix owner, group, and mode as needed...
316 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
319 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
322 if (chown(filename
, user
, group
) && !getuid())
325 cupsdLogMessage(CUPSD_LOG_ERROR
,
326 "Unable to change ownership of \"%s\" - %s", filename
,
329 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
336 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
339 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
342 if (chmod(filename
, mode
))
345 cupsdLogMessage(CUPSD_LOG_ERROR
,
346 "Unable to change permissions of \"%s\" - %s", filename
,
349 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
357 * Everything is OK...
365 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
368 int /* O - 1 on success, 0 otherwise */
369 cupsdReadConfiguration(void)
371 int i
; /* Looping var */
372 cups_file_t
*fp
; /* Configuration file */
373 int status
; /* Return status */
374 char temp
[1024], /* Temporary buffer */
375 mimedir
[1024], /* MIME directory */
376 *slash
; /* Directory separator */
377 cups_lang_t
*language
; /* Language */
378 struct passwd
*user
; /* Default user */
379 struct group
*group
; /* Default group */
380 char *old_serverroot
, /* Old ServerRoot */
381 *old_requestroot
; /* Old RequestRoot */
382 const char *tmpdir
; /* TMPDIR environment variable */
383 struct stat tmpinfo
; /* Temporary directory info */
384 cupsd_policy_t
*p
; /* Policy */
388 * Save the old root paths...
391 old_serverroot
= NULL
;
392 cupsdSetString(&old_serverroot
, ServerRoot
);
393 old_requestroot
= NULL
;
394 cupsdSetString(&old_requestroot
, RequestRoot
);
397 * Reset the server configuration data...
400 cupsdDeleteAllLocations();
419 for (i
= 0; i
< NumRelays
; i
++)
420 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
421 free(Relays
[i
].from
.mask
.name
.name
);
428 cupsdDeleteAllListeners();
430 RemoteAccessEnabled
= 0;
436 cupsdClearString(&ServerName
);
437 cupsdClearString(&ServerAdmin
);
438 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
439 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
440 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
441 cupsdSetString(&DataDir
, CUPS_DATADIR
);
442 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
443 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
444 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
445 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
446 cupsdSetString(&PageLogFormat
,
447 "%p %j %u %T %P %C %{job-billing} "
448 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
449 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
450 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
451 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
452 cupsdSetString(&RemoteRoot
, "remroot");
453 cupsdSetString(&ServerHeader
, "CUPS/1.4");
454 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
456 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
457 #endif /* HAVE_GSSAPI */
459 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
460 PrintcapFormat
= PRINTCAP_SOLARIS
;
461 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
462 "/Library/Preferences/org.cups.printers.plist"))
463 PrintcapFormat
= PRINTCAP_PLIST
;
465 PrintcapFormat
= PRINTCAP_BSD
;
467 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
468 if ((slash
= strrchr(temp
, '/')) != NULL
)
471 cupsdSetString(&ServerRoot
, temp
);
473 cupsdClearString(&Classification
);
474 ClassifyOverride
= 0;
478 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
480 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
481 cupsdSetString(&ServerKey
, "ssl/server.key");
482 # endif /* HAVE_CDSASSL */
483 #endif /* HAVE_SSL */
485 language
= cupsLangDefault();
487 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
488 cupsdSetString(&DefaultLanguage
, "en");
490 cupsdSetString(&DefaultLanguage
, language
->language
);
492 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
494 cupsdClearString(&DefaultPaperSize
);
496 cupsdSetString(&RIPCache
, "8m");
498 cupsdSetString(&TempDir
, NULL
);
501 * Find the default user...
504 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
509 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
510 * complement number...)
519 * Find the default group...
522 group
= getgrnam(CUPS_DEFAULT_GROUP
);
526 Group
= group
->gr_gid
;
530 * Fallback to group "nobody"...
533 group
= getgrnam("nobody");
537 Group
= group
->gr_gid
;
541 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
542 * complement number...)
553 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
554 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
555 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
556 DefaultAuthType
= CUPSD_AUTH_BASIC
;
558 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
559 SSLOptions
= CUPSD_SSL_NONE
;
560 #endif /* HAVE_SSL */
561 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
563 JobRetryInterval
= 300;
568 HostNameLookups
= FALSE
;
569 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
570 ImplicitAnyClasses
= FALSE
;
571 HideImplicitMembers
= TRUE
;
573 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
574 ListenBackLog
= SOMAXCONN
;
575 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
576 LogLevel
= CUPSD_LOG_WARN
;
577 LogTimeFormat
= CUPSD_TIME_STANDARD
;
579 MaxClientsPerHost
= 0;
580 MaxLogSize
= 1024 * 1024;
581 MaxPrinterHistory
= 10;
583 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
584 ReloadTimeout
= DEFAULT_KEEPALIVE
;
585 RootCertDuration
= 300;
586 Timeout
= DEFAULT_TIMEOUT
;
589 BrowseInterval
= DEFAULT_INTERVAL
;
590 BrowsePort
= ippPort();
591 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
592 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
593 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
594 BrowseTimeout
= DEFAULT_TIMEOUT
;
596 Browsing
= CUPS_DEFAULT_BROWSING
;
597 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
599 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
600 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
602 cupsdClearString(&BrowseLocalOptions
);
603 cupsdClearString(&BrowseRemoteOptions
);
605 cupsdSetString(&ErrorPolicy
, "stop-printer");
608 cupsdClearString(&BrowseLDAPBindDN
);
609 cupsdClearString(&BrowseLDAPDN
);
610 cupsdClearString(&BrowseLDAPPassword
);
611 cupsdClearString(&BrowseLDAPServer
);
612 # ifdef HAVE_LDAP_SSL
613 cupsdClearString(&BrowseLDAPCACertFile
);
614 # endif /* HAVE_LDAP_SSL */
615 #endif /* HAVE_LDAP */
617 JobHistory
= DEFAULT_HISTORY
;
618 JobFiles
= DEFAULT_FILES
;
623 MaxJobsPerPrinter
= 0;
624 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
626 cupsdDeleteAllPolicies();
627 cupsdClearString(&DefaultPolicy
);
629 #ifdef HAVE_AUTHORIZATION_H
630 cupsdClearString(&SystemGroupAuthKey
);
631 #endif /* HAVE_AUTHORIZATION_H */
633 MaxSubscriptions
= 100;
634 MaxSubscriptionsPerJob
= 0;
635 MaxSubscriptionsPerPrinter
= 0;
636 MaxSubscriptionsPerUser
= 0;
637 DefaultLeaseDuration
= 86400;
638 MaxLeaseDuration
= 0;
641 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
642 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
643 #endif /* HAVE_LAUNCHD */
647 #endif /* __APPLE__ */
650 * Read the configuration file...
653 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
656 status
= read_configuration(fp
);
665 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
666 RemoteAccessEnabled
? "enabled" : "disabled");
669 * See if the ServerName is an IP address...
674 if (HostNameLookups
|| RemoteAccessEnabled
)
675 httpGetHostname(NULL
, temp
, sizeof(temp
));
676 else if (gethostname(temp
, sizeof(temp
)))
678 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
680 strlcpy(temp
, "localhost", sizeof(temp
));
683 cupsdSetString(&ServerName
, temp
);
686 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
688 ServerNameIsIP
= !*slash
;
691 * Make sure ServerAdmin is initialized...
695 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
698 * Use the default system group if none was supplied in cupsd.conf...
701 if (NumSystemGroups
== 0)
703 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
706 * Find the group associated with GID 0...
713 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
715 cupsdSetString(&SystemGroups
[0], "unknown");
717 SystemGroupIDs
[0] = 0;
723 * Get the access control list for browsing...
726 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
729 * Open the system log for cupsd if necessary...
733 if (!strcmp(AccessLog
, "syslog") ||
734 !strcmp(ErrorLog
, "syslog") ||
735 !strcmp(PageLog
, "syslog"))
736 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
737 #endif /* HAVE_VSYSLOG */
740 * Log the configuration file that was used...
743 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
747 * Validate the Group and SystemGroup settings - they cannot be the same,
748 * otherwise the CGI programs will be able to authenticate as root without
754 for (i
= 0; i
< NumSystemGroups
; i
++)
755 if (Group
== SystemGroupIDs
[i
])
758 if (i
< NumSystemGroups
)
761 * Log the error and reset the group to a safe value...
764 cupsdLogMessage(CUPSD_LOG_NOTICE
,
765 "Group and SystemGroup cannot use the same groups!");
766 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
768 group
= getgrnam("nobody");
772 Group
= group
->gr_gid
;
776 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
777 * complement number...)
786 * Check that we have at least one listen/port line; if not, report this
787 * as an error and exit!
790 if (cupsArrayCount(Listeners
) == 0)
796 cupsdLogMessage(CUPSD_LOG_EMERG
,
797 "No valid Listen or Port lines were found in the "
798 "configuration file!");
804 cupsdEndProcess(getpid(), 0);
808 * Set the default locale using the language and charset...
811 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
814 * Update all relative filenames to include the full path from ServerRoot...
817 if (DocumentRoot
[0] != '/')
818 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
820 if (RequestRoot
[0] != '/')
821 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
823 if (ServerBin
[0] != '/')
824 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
826 if (StateDir
[0] != '/')
827 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
829 if (CacheDir
[0] != '/')
830 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
833 if (ServerCertificate
[0] != '/')
834 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
836 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
837 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
839 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
842 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
843 if (ServerKey
[0] != '/')
844 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
846 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
847 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
848 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
850 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
851 #endif /* HAVE_SSL */
854 * Make sure that directories and config files are owned and
855 * writable by the user and group in the cupsd.conf file...
858 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
860 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
862 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
864 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
866 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
868 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
869 SystemGroupIDs
[0], 1, 1) < 0 ||
870 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
872 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
874 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
876 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
878 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
880 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
882 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
884 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
888 * Update TempDir to the default if it hasn't been set already...
893 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
896 * TMPDIR is defined, see if it is OK for us to use...
899 if (stat(tmpdir
, &tmpinfo
))
900 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
901 tmpdir
, strerror(errno
));
902 else if (!S_ISDIR(tmpinfo
.st_mode
))
903 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
905 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
906 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
907 !(tmpinfo
.st_mode
& S_IWOTH
))
908 cupsdLogMessage(CUPSD_LOG_ERROR
,
909 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
911 cupsdSetString(&TempDir
, tmpdir
);
916 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
918 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
923 * Make sure the temporary directory has the right permissions...
926 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
930 * Update ownership and permissions if the CUPS temp directory
931 * is under the spool directory or does not exist...
934 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
935 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
940 * Setup environment variables...
946 * Update default paper size setting as needed...
949 if (!DefaultPaperSize
)
952 char *paper_result
; /* Paper size name from libpaper */
954 if ((paper_result
= systempapername()) != NULL
)
955 cupsdSetString(&DefaultPaperSize
, paper_result
);
957 #endif /* HAVE_LIBPAPER */
958 if (!DefaultLanguage
||
959 !strcasecmp(DefaultLanguage
, "C") ||
960 !strcasecmp(DefaultLanguage
, "POSIX") ||
961 !strcasecmp(DefaultLanguage
, "en") ||
962 !strncasecmp(DefaultLanguage
, "en.", 3) ||
963 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
964 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
965 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
968 * These are the only locales that will default to "letter" size...
971 cupsdSetString(&DefaultPaperSize
, "Letter");
974 cupsdSetString(&DefaultPaperSize
, "A4");
978 * Update classification setting as needed...
981 if (Classification
&& !strcasecmp(Classification
, "none"))
982 cupsdClearString(&Classification
);
985 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
988 * Check the MaxClients setting, and then allocate memory for it...
991 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
994 cupsdLogMessage(CUPSD_LOG_INFO
,
995 "MaxClients limited to 1/3 (%d) of the file descriptor "
999 MaxClients
= MaxFDs
/ 3;
1002 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1006 * Check the MaxActiveJobs setting; limit to 1/3 the available
1007 * file descriptors, since we need a pipe for each job...
1010 if (MaxActiveJobs
> (MaxFDs
/ 3))
1011 MaxActiveJobs
= MaxFDs
/ 3;
1014 * Update the MaxClientsPerHost value, as needed...
1017 if (MaxClientsPerHost
<= 0)
1018 MaxClientsPerHost
= MaxClients
;
1020 if (MaxClientsPerHost
> MaxClients
)
1021 MaxClientsPerHost
= MaxClients
;
1023 cupsdLogMessage(CUPSD_LOG_INFO
,
1024 "Allowing up to %d client connections per host.",
1028 * Make sure that BrowseTimeout is at least twice the interval...
1031 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1033 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1037 BrowseTimeout
= BrowseInterval
* 2;
1039 BrowseTimeout
= DEFAULT_TIMEOUT
;
1041 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1046 * Update the default policy, as needed...
1050 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1052 DefaultPolicyPtr
= NULL
;
1054 if (!DefaultPolicyPtr
)
1056 cupsd_location_t
*po
; /* New policy operation */
1060 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1063 cupsdSetString(&DefaultPolicy
, "default");
1065 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1066 cupsdLogMessage(CUPSD_LOG_INFO
,
1067 "Using policy \"default\" as the default!");
1070 cupsdLogMessage(CUPSD_LOG_INFO
,
1071 "Creating CUPS default administrative policy:");
1073 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1075 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1076 cupsdLogMessage(CUPSD_LOG_INFO
,
1077 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1078 "Release-Job Restart-Job Purge-Jobs "
1079 "Set-Job-Attributes Create-Job-Subscription "
1080 "Renew-Subscription Cancel-Subscription "
1081 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1082 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1083 "CUPS-Authenticate-Job CUPS-Get-Document>");
1084 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1086 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1087 po
->order_type
= CUPSD_AUTH_ALLOW
;
1088 po
->level
= CUPSD_AUTH_USER
;
1090 cupsdAddName(po
, "@OWNER");
1091 cupsdAddName(po
, "@SYSTEM");
1092 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1094 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1095 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1096 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1097 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1098 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1099 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1100 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1101 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1102 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1103 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1104 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1105 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1106 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1107 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1108 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1109 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1110 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1111 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1113 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1115 cupsdLogMessage(CUPSD_LOG_INFO
,
1116 "<Limit Pause-Printer Resume-Printer "
1117 "Set-Printer-Attributes Enable-Printer "
1118 "Disable-Printer Pause-Printer-After-Current-Job "
1119 "Hold-New-Jobs Release-Held-New-Jobs "
1120 "Deactivate-Printer Activate-Printer Restart-Printer "
1121 "Shutdown-Printer Startup-Printer Promote-Job "
1122 "Schedule-Job-After CUPS-Add-Printer "
1123 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1124 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1125 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1126 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1128 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1129 po
->order_type
= CUPSD_AUTH_ALLOW
;
1130 po
->type
= CUPSD_AUTH_DEFAULT
;
1131 po
->level
= CUPSD_AUTH_USER
;
1133 cupsdAddName(po
, "@SYSTEM");
1134 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1136 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1137 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1138 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1139 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1140 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1141 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1142 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1143 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1144 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1145 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1146 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1147 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1148 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1149 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1150 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1151 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1152 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1153 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1154 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1155 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1156 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1158 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1160 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1161 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1163 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1164 po
->order_type
= CUPSD_AUTH_ALLOW
;
1166 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1167 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1171 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1172 cupsArrayCount(Policies
));
1173 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1175 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1176 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1177 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1180 * If we are doing a full reload or the server root has changed, flush
1181 * the jobs, printers, etc. and start from scratch...
1184 if (NeedReload
== RELOAD_ALL
||
1185 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1186 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1188 mime_type_t
*type
; /* Current type */
1189 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1190 /* MIME type name */
1193 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1196 * Free all memory...
1199 cupsdDeleteAllSubscriptions();
1201 cupsdDeleteAllPrinters();
1203 DefaultPrinter
= NULL
;
1205 if (MimeDatabase
!= NULL
)
1206 mimeDelete(MimeDatabase
);
1210 for (i
= 0; i
< NumMimeTypes
; i
++)
1211 _cupsStrFree(MimeTypes
[i
]);
1217 * Read the MIME type and conversion database...
1220 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1221 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1223 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1224 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1225 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1226 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1230 cupsdLogMessage(CUPSD_LOG_EMERG
,
1231 "Unable to load MIME database from \"%s\" or \"%s\"!",
1232 mimedir
, ServerRoot
);
1233 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1237 cupsdLogMessage(CUPSD_LOG_INFO
,
1238 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1239 "%d filters...", mimedir
, ServerRoot
,
1240 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1243 * Create a list of MIME types for the document-format-supported
1247 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1248 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1251 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Unable to allocate memory for %d MIME types!",
1260 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1262 i
++, type
= mimeNextType(MimeDatabase
))
1264 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1266 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1269 if (i
< NumMimeTypes
)
1270 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1273 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1275 mime_filter_t
*filter
; /* Current filter */
1278 for (type
= mimeFirstType(MimeDatabase
);
1280 type
= mimeNextType(MimeDatabase
))
1281 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1282 type
->super
, type
->type
);
1284 for (filter
= mimeFirstFilter(MimeDatabase
);
1286 filter
= mimeNextFilter(MimeDatabase
))
1287 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1288 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1289 filter
->src
->super
, filter
->src
->type
,
1290 filter
->dst
->super
, filter
->dst
->type
,
1291 filter
->cost
, filter
->filter
);
1298 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1299 cupsdLoadBanners(temp
);
1302 * Load printers and classes...
1305 cupsdLoadAllPrinters();
1306 cupsdLoadAllClasses();
1307 cupsdLoadRemoteCache();
1308 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1310 cupsdCreateCommonData();
1313 * Load queued jobs...
1319 * Load subscriptions...
1322 cupsdLoadAllSubscriptions();
1324 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1329 * Not a full reload, so recreate the common printer attributes...
1332 cupsdCreateCommonData();
1335 * Update all printers as needed...
1338 cupsdUpdatePrinters();
1339 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1341 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1345 * Reset the reload state...
1348 NeedReload
= RELOAD_NONE
;
1350 cupsdClearString(&old_serverroot
);
1351 cupsdClearString(&old_requestroot
);
1358 * 'get_address()' - Get an address + port number from a line.
1361 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1362 get_address(const char *value
, /* I - Value string */
1363 int defport
) /* I - Default port */
1365 char buffer
[1024], /* Hostname + port number buffer */
1366 defpname
[255], /* Default port name */
1367 *hostname
, /* Hostname or IP */
1368 *portname
; /* Port number or name */
1369 http_addrlist_t
*addrlist
; /* Address list */
1373 * Check for an empty value...
1378 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1383 * Grab a hostname and port number; if there is no colon and the port name
1384 * is only digits, then we have a port number by itself...
1387 strlcpy(buffer
, value
, sizeof(buffer
));
1389 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1396 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1401 * Use the default port...
1404 sprintf(defpname
, "%d", defport
);
1405 portname
= defpname
;
1411 * The buffer contains just a port number...
1419 if (hostname
&& !strcmp(hostname
, "*"))
1423 * Now lookup the address using httpAddrGetList()...
1426 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1427 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1428 hostname
? hostname
: "(nil)");
1435 * 'get_addr_and_mask()' - Get an IP address and netmask.
1438 static int /* O - 1 on success, 0 on failure */
1439 get_addr_and_mask(const char *value
, /* I - String from config file */
1440 unsigned *ip
, /* O - Address value */
1441 unsigned *mask
) /* O - Mask value */
1443 int i
, j
, /* Looping vars */
1444 family
, /* Address family */
1445 ipcount
; /* Count of fields in address */
1446 unsigned ipval
; /* Value */
1447 const char *maskval
, /* Pointer to start of mask value */
1448 *ptr
, /* Pointer into value */
1453 * Get the address...
1456 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1457 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1459 if ((maskval
= strchr(value
, '/')) != NULL
)
1462 maskval
= value
+ strlen(value
);
1466 * Check for an IPv6 address...
1472 * Parse hexadecimal IPv6 address...
1477 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1481 else if (!strncmp(ptr
, "::", 2))
1483 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1485 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1490 else if (isxdigit(*ptr
& 255))
1492 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1500 ip
[i
/ 2] |= ipval
<< 16;
1514 if (*ptr
&& *ptr
!= '/')
1518 #endif /* AF_INET6 */
1521 * Parse dotted-decimal IPv4 address...
1524 unsigned val
[4]; /* IPv4 address values */
1528 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1531 * Range check the IP numbers...
1534 for (i
= 0; i
< ipcount
; i
++)
1539 * Make sure the trailing values are zeroed, as some C libraries like
1540 * glibc apparently like to fill the unused arguments with garbage...
1543 for (i
= ipcount
; i
< 4; i
++)
1547 * Merge everything into a 32-bit IPv4 address in ip[3]...
1550 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1553 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1559 * Get the netmask value(s)...
1562 memset(mask
, 0, sizeof(unsigned) * 4);
1564 if (strchr(maskval
, '.'))
1567 * Get dotted-decimal mask...
1570 if (family
!= AF_INET
)
1573 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1576 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1577 mask
[0] = mask
[1] = mask
[2] = 0;
1582 * Get address/bits format...
1588 if (family
== AF_INET6
)
1596 mask
[0] = 0xffffffff;
1598 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1601 mask
[1] = 0xffffffff;
1605 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1608 mask
[2] = 0xffffffff;
1612 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1615 mask
[3] = 0xffffffff;
1619 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1622 #endif /* AF_INET6 */
1627 mask
[0] = 0xffffffff;
1628 mask
[1] = 0xffffffff;
1629 mask
[2] = 0xffffffff;
1632 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1634 mask
[3] = 0xffffffff;
1639 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1640 "get_addr_and_mask(value=\"%s\", "
1641 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1642 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1646 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1649 if ((ip
[0] & ~mask
[0]) != 0 ||
1650 (ip
[1] & ~mask
[1]) != 0 ||
1651 (ip
[2] & ~mask
[2]) != 0 ||
1652 (ip
[3] & ~mask
[3]) != 0)
1660 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1663 static int /* O - 1 on success, 0 on failure */
1664 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1665 char *line
, /* I - Line from file */
1666 char *value
, /* I - Start of value data */
1667 int linenum
) /* I - Current line number */
1669 char *valptr
; /* Pointer into value */
1670 unsigned ip
[4], /* IP address components */
1671 mask
[4]; /* IP netmask components */
1674 if (!strcasecmp(line
, "Encryption"))
1677 * "Encryption xxx" - set required encryption level...
1680 if (!strcasecmp(value
, "never"))
1681 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1682 else if (!strcasecmp(value
, "always"))
1684 cupsdLogMessage(CUPSD_LOG_ERROR
,
1685 "Encryption value \"%s\" on line %d is invalid in this "
1686 "context. Using \"required\" instead.", value
, linenum
);
1688 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1690 else if (!strcasecmp(value
, "required"))
1691 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1692 else if (!strcasecmp(value
, "ifrequested"))
1693 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1696 cupsdLogMessage(CUPSD_LOG_ERROR
,
1697 "Unknown Encryption value %s on line %d.", value
, linenum
);
1701 else if (!strcasecmp(line
, "Order"))
1704 * "Order Deny,Allow" or "Order Allow,Deny"...
1707 if (!strncasecmp(value
, "deny", 4))
1708 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1709 else if (!strncasecmp(value
, "allow", 5))
1710 loc
->order_type
= CUPSD_AUTH_DENY
;
1713 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1718 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1721 * Allow [From] host/ip...
1722 * Deny [From] host/ip...
1727 if (!strncasecmp(value
, "from", 4))
1730 * Strip leading "from"...
1735 while (isspace(*value
& 255))
1743 * Find the end of the value...
1746 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1748 while (isspace(*valptr
& 255))
1752 * Figure out what form the allow/deny address takes:
1763 * nnn.nnn.nnn.nnn/mm
1764 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1767 if (!strcasecmp(value
, "all"))
1773 if (!strcasecmp(line
, "Allow"))
1774 cupsdAllowIP(loc
, zeros
, zeros
);
1776 cupsdDenyIP(loc
, zeros
, zeros
);
1778 else if (!strcasecmp(value
, "none"))
1784 if (!strcasecmp(line
, "Allow"))
1785 cupsdAllowIP(loc
, ones
, zeros
);
1787 cupsdDenyIP(loc
, ones
, zeros
);
1790 else if (value
[0] == '*' || value
[0] == '.' ||
1791 (!isdigit(value
[0] & 255) && value
[0] != '['))
1793 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1794 #endif /* AF_INET6 */
1797 * Host or domain name...
1800 if (value
[0] == '*')
1803 if (!strcasecmp(line
, "Allow"))
1804 cupsdAllowHost(loc
, value
);
1806 cupsdDenyHost(loc
, value
);
1811 * One of many IP address forms...
1814 if (!get_addr_and_mask(value
, ip
, mask
))
1816 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1821 if (!strcasecmp(line
, "Allow"))
1822 cupsdAllowIP(loc
, ip
, mask
);
1824 cupsdDenyIP(loc
, ip
, mask
);
1828 * Advance to next value...
1834 else if (!strcasecmp(line
, "AuthType"))
1837 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1840 if (!strcasecmp(value
, "none"))
1842 loc
->type
= CUPSD_AUTH_NONE
;
1843 loc
->level
= CUPSD_AUTH_ANON
;
1845 else if (!strcasecmp(value
, "basic"))
1847 loc
->type
= CUPSD_AUTH_BASIC
;
1849 if (loc
->level
== CUPSD_AUTH_ANON
)
1850 loc
->level
= CUPSD_AUTH_USER
;
1852 else if (!strcasecmp(value
, "digest"))
1854 loc
->type
= CUPSD_AUTH_DIGEST
;
1856 if (loc
->level
== CUPSD_AUTH_ANON
)
1857 loc
->level
= CUPSD_AUTH_USER
;
1859 else if (!strcasecmp(value
, "basicdigest"))
1861 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1863 if (loc
->level
== CUPSD_AUTH_ANON
)
1864 loc
->level
= CUPSD_AUTH_USER
;
1866 else if (!strcasecmp(value
, "default"))
1868 loc
->type
= CUPSD_AUTH_DEFAULT
;
1870 if (loc
->level
== CUPSD_AUTH_ANON
)
1871 loc
->level
= CUPSD_AUTH_USER
;
1874 else if (!strcasecmp(value
, "negotiate"))
1876 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1878 if (loc
->level
== CUPSD_AUTH_ANON
)
1879 loc
->level
= CUPSD_AUTH_USER
;
1881 #endif /* HAVE_GSSAPI */
1884 cupsdLogMessage(CUPSD_LOG_WARN
,
1885 "Unknown authorization type %s on line %d.",
1890 else if (!strcasecmp(line
, "AuthClass"))
1893 * AuthClass anonymous, user, system, group
1896 if (!strcasecmp(value
, "anonymous"))
1898 loc
->type
= CUPSD_AUTH_NONE
;
1899 loc
->level
= CUPSD_AUTH_ANON
;
1901 cupsdLogMessage(CUPSD_LOG_WARN
,
1902 "\"AuthClass %s\" is deprecated; consider removing "
1906 else if (!strcasecmp(value
, "user"))
1908 loc
->level
= CUPSD_AUTH_USER
;
1910 cupsdLogMessage(CUPSD_LOG_WARN
,
1911 "\"AuthClass %s\" is deprecated; consider using "
1912 "\"Require valid-user\" on line %d.",
1915 else if (!strcasecmp(value
, "group"))
1917 loc
->level
= CUPSD_AUTH_GROUP
;
1919 cupsdLogMessage(CUPSD_LOG_WARN
,
1920 "\"AuthClass %s\" is deprecated; consider using "
1921 "\"Require user @groupname\" on line %d.",
1924 else if (!strcasecmp(value
, "system"))
1926 loc
->level
= CUPSD_AUTH_GROUP
;
1928 cupsdAddName(loc
, "@SYSTEM");
1930 cupsdLogMessage(CUPSD_LOG_WARN
,
1931 "\"AuthClass %s\" is deprecated; consider using "
1932 "\"Require user @SYSTEM\" on line %d.",
1937 cupsdLogMessage(CUPSD_LOG_WARN
,
1938 "Unknown authorization class %s on line %d.",
1943 else if (!strcasecmp(line
, "AuthGroupName"))
1945 cupsdAddName(loc
, value
);
1947 cupsdLogMessage(CUPSD_LOG_WARN
,
1948 "\"AuthGroupName %s\" directive is deprecated; consider "
1949 "using \"Require user @%s\" on line %d.",
1950 value
, value
, linenum
);
1952 else if (!strcasecmp(line
, "Require"))
1955 * Apache synonym for AuthClass and AuthGroupName...
1959 * Require valid-user
1960 * Require group names
1961 * Require user names
1964 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1969 if (!strcasecmp(value
, "valid-user") ||
1970 !strcasecmp(value
, "user"))
1971 loc
->level
= CUPSD_AUTH_USER
;
1972 else if (!strcasecmp(value
, "group"))
1973 loc
->level
= CUPSD_AUTH_GROUP
;
1976 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1982 * Get the list of names from the line...
1985 for (value
= valptr
; *value
;)
1987 while (isspace(*value
& 255))
1990 #ifdef HAVE_AUTHORIZATION_H
1991 if (!strncmp(value
, "@AUTHKEY(", 9))
1994 * Grab "@AUTHKEY(name)" value...
1997 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2003 #endif /* HAVE_AUTHORIZATION_H */
2004 if (*value
== '\"' || *value
== '\'')
2007 * Grab quoted name...
2010 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2017 * Grab literal name.
2020 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2026 cupsdAddName(loc
, value
);
2028 for (value
= valptr
; isspace(*value
& 255); value
++);
2031 else if (!strcasecmp(line
, "Satisfy"))
2033 if (!strcasecmp(value
, "all"))
2034 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2035 else if (!strcasecmp(value
, "any"))
2036 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2039 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2052 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2055 static int /* O - FatalErrors bits */
2056 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2058 int fatal
; /* FatalErrors bits */
2059 char value
[1024], /* Value string */
2060 *valstart
, /* Pointer into value */
2061 *valend
; /* End of value */
2065 * Empty FatalErrors line yields NULL pointer...
2069 return (CUPSD_FATAL_NONE
);
2072 * Loop through the value string,...
2075 strlcpy(value
, s
, sizeof(value
));
2077 fatal
= CUPSD_FATAL_NONE
;
2079 for (valstart
= value
; *valstart
;)
2082 * Get the current space/comma-delimited kind name...
2085 for (valend
= valstart
; *valend
; valend
++)
2086 if (isspace(*valend
& 255) || *valend
== ',')
2093 * Add the error to the bitmask...
2096 if (!strcasecmp(valstart
, "all"))
2097 fatal
= CUPSD_FATAL_ALL
;
2098 else if (!strcasecmp(valstart
, "browse"))
2099 fatal
|= CUPSD_FATAL_BROWSE
;
2100 else if (!strcasecmp(valstart
, "-browse"))
2101 fatal
&= ~CUPSD_FATAL_BROWSE
;
2102 else if (!strcasecmp(valstart
, "config"))
2103 fatal
|= CUPSD_FATAL_CONFIG
;
2104 else if (!strcasecmp(valstart
, "-config"))
2105 fatal
&= ~CUPSD_FATAL_CONFIG
;
2106 else if (!strcasecmp(valstart
, "listen"))
2107 fatal
|= CUPSD_FATAL_LISTEN
;
2108 else if (!strcasecmp(valstart
, "-listen"))
2109 fatal
&= ~CUPSD_FATAL_LISTEN
;
2110 else if (!strcasecmp(valstart
, "log"))
2111 fatal
|= CUPSD_FATAL_LOG
;
2112 else if (!strcasecmp(valstart
, "-log"))
2113 fatal
&= ~CUPSD_FATAL_LOG
;
2114 else if (!strcasecmp(valstart
, "permissions"))
2115 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2116 else if (!strcasecmp(valstart
, "-permissions"))
2117 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2118 else if (strcasecmp(valstart
, "none"))
2119 cupsdLogMessage(CUPSD_LOG_ERROR
,
2120 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2122 for (valstart
= valend
; *valstart
; valstart
++)
2123 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2132 * 'parse_groups()' - Parse system group names in a string.
2135 static int /* O - 1 on success, 0 on failure */
2136 parse_groups(const char *s
) /* I - Space-delimited groups */
2138 int status
; /* Return status */
2139 char value
[1024], /* Value string */
2140 *valstart
, /* Pointer into value */
2141 *valend
, /* End of value */
2142 quote
; /* Quote character */
2143 struct group
*group
; /* Group */
2147 * Make a copy of the string and parse out the groups...
2150 strlcpy(value
, s
, sizeof(value
));
2155 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2157 if (*valstart
== '\'' || *valstart
== '\"')
2160 * Scan quoted name...
2163 quote
= *valstart
++;
2165 for (valend
= valstart
; *valend
; valend
++)
2166 if (*valend
== quote
)
2172 * Scan space or comma-delimited name...
2175 for (valend
= valstart
; *valend
; valend
++)
2176 if (isspace(*valend
) || *valend
== ',')
2183 group
= getgrnam(valstart
);
2186 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2187 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2198 while (*valstart
== ',' || isspace(*valstart
))
2207 * 'parse_protocols()' - Parse browse protocols in a string.
2210 static int /* O - Browse protocol bits */
2211 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2213 int protocols
; /* Browse protocol bits */
2214 char value
[1024], /* Value string */
2215 *valstart
, /* Pointer into value */
2216 *valend
; /* End of value */
2220 * Empty protocol line yields NULL pointer...
2227 * Loop through the value string,...
2230 strlcpy(value
, s
, sizeof(value
));
2234 for (valstart
= value
; *valstart
;)
2237 * Get the current space/comma-delimited protocol name...
2240 for (valend
= valstart
; *valend
; valend
++)
2241 if (isspace(*valend
& 255) || *valend
== ',')
2248 * Add the protocol to the bitmask...
2251 if (!strcasecmp(valstart
, "cups"))
2252 protocols
|= BROWSE_CUPS
;
2253 else if (!strcasecmp(valstart
, "slp"))
2254 protocols
|= BROWSE_SLP
;
2255 else if (!strcasecmp(valstart
, "ldap"))
2256 protocols
|= BROWSE_LDAP
;
2257 else if (!strcasecmp(valstart
, "dnssd") ||
2258 !strcasecmp(valstart
, "dns-sd") ||
2259 !strcasecmp(valstart
, "bonjour"))
2260 protocols
|= BROWSE_DNSSD
;
2261 else if (!strcasecmp(valstart
, "lpd"))
2262 protocols
|= BROWSE_LPD
;
2263 else if (!strcasecmp(valstart
, "smb"))
2264 protocols
|= BROWSE_SMB
;
2265 else if (!strcasecmp(valstart
, "all"))
2266 protocols
|= BROWSE_ALL
;
2267 else if (strcasecmp(valstart
, "none"))
2268 cupsdLogMessage(CUPSD_LOG_ERROR
,
2269 "Unknown browse protocol \"%s\" ignored!", valstart
);
2271 for (valstart
= valend
; *valstart
; valstart
++)
2272 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2281 * 'read_configuration()' - Read a configuration file.
2284 static int /* O - 1 on success, 0 on failure */
2285 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2287 int i
; /* Looping var */
2288 int linenum
; /* Current line number */
2289 char line
[HTTP_MAX_BUFFER
],
2290 /* Line from file */
2291 temp
[HTTP_MAX_BUFFER
],
2292 /* Temporary buffer for value */
2293 temp2
[HTTP_MAX_BUFFER
],
2294 /* Temporary buffer 2 for value */
2295 *ptr
, /* Pointer into line/temp */
2296 *value
, /* Pointer to value */
2297 *valueptr
; /* Pointer into value */
2298 int valuelen
; /* Length of value */
2299 cupsd_var_t
const *var
; /* Current variable */
2300 http_addrlist_t
*addrlist
, /* Address list */
2301 *addr
; /* Current address */
2302 unsigned ip
[4], /* Address value */
2303 mask
[4]; /* Netmask value */
2304 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2305 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2306 cupsd_location_t
*location
; /* Browse location */
2307 cups_file_t
*incfile
; /* Include file */
2308 char incname
[1024]; /* Include filename */
2309 struct group
*group
; /* Group */
2313 * Loop through each line in the file...
2318 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2321 * Decode the directive...
2324 if (!strcasecmp(line
, "Include") && value
)
2330 if (value
[0] == '/')
2331 strlcpy(incname
, value
, sizeof(incname
));
2333 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2335 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2336 cupsdLogMessage(CUPSD_LOG_ERROR
,
2337 "Unable to include config file \"%s\" - %s",
2338 incname
, strerror(errno
));
2341 read_configuration(incfile
);
2342 cupsFileClose(incfile
);
2345 else if (!strcasecmp(line
, "<Location") && value
)
2351 linenum
= read_location(fp
, value
, linenum
);
2355 else if (!strcasecmp(line
, "<Policy") && value
)
2361 linenum
= read_policy(fp
, value
, linenum
);
2365 else if (!strcasecmp(line
, "FatalErrors"))
2366 FatalErrors
= parse_fatal_errors(value
);
2367 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2369 JobRetryInterval
= atoi(value
);
2370 cupsdLogMessage(CUPSD_LOG_WARN
,
2371 "FaxRetryInterval is deprecated; use "
2372 "JobRetryInterval on line %d.", linenum
);
2374 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2376 JobRetryLimit
= atoi(value
);
2377 cupsdLogMessage(CUPSD_LOG_WARN
,
2378 "FaxRetryLimit is deprecated; use "
2379 "JobRetryLimit on line %d.", linenum
);
2381 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2383 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2384 #endif /* HAVE_SSL */
2388 * Add listening address(es) to the list...
2391 cupsd_listener_t
*lis
; /* New listeners array */
2395 * Get the address list...
2398 addrlist
= get_address(value
, IPP_PORT
);
2402 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2408 * Add each address...
2411 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2414 * See if this address is already present...
2417 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2419 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2420 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2421 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2426 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2427 cupsdLogMessage(CUPSD_LOG_WARN
,
2428 "Duplicate listen address \"%s\" ignored!", temp
);
2433 * Allocate another listener...
2437 Listeners
= cupsArrayNew(NULL
, NULL
);
2441 cupsdLogMessage(CUPSD_LOG_ERROR
,
2442 "Unable to allocate %s at line %d - %s.",
2443 line
, linenum
, strerror(errno
));
2447 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2449 cupsdLogMessage(CUPSD_LOG_ERROR
,
2450 "Unable to allocate %s at line %d - %s.",
2451 line
, linenum
, strerror(errno
));
2455 cupsArrayAdd(Listeners
, lis
);
2458 * Copy the current address and log it...
2461 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2465 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2466 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2467 #endif /* HAVE_SSL */
2469 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2472 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2473 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2474 ntohs(lis
->address
.ipv6
.sin6_port
));
2476 #endif /* AF_INET6 */
2478 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2479 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2481 #endif /* AF_LOCAL */
2482 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2483 ntohs(lis
->address
.ipv4
.sin_port
));
2485 if (!httpAddrLocalhost(&(lis
->address
)))
2486 RemoteAccessEnabled
= 1;
2493 httpAddrFreeList(addrlist
);
2495 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2498 * Add a browse address to the list...
2501 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2504 if (NumBrowsers
== 0)
2505 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2507 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2511 cupsdLogMessage(CUPSD_LOG_ERROR
,
2512 "Unable to allocate BrowseAddress at line %d - %s.",
2513 linenum
, strerror(errno
));
2518 dira
+= NumBrowsers
;
2520 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2522 if (!strcasecmp(value
, "@LOCAL"))
2525 * Send browse data to all local interfaces...
2528 strcpy(dira
->iface
, "*");
2531 else if (!strncasecmp(value
, "@IF(", 4))
2534 * Send browse data to the named interface...
2537 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2539 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2545 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2548 * Only IPv4 addresses are supported...
2551 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2552 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2557 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2558 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2560 cupsdLogMessage(CUPSD_LOG_INFO
,
2561 "Sending browsing info to %s:%d (IPv4)",
2562 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2567 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2570 httpAddrFreeList(addrlist
);
2573 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2576 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2579 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2582 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2583 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2585 if (location
== NULL
)
2586 cupsdLogMessage(CUPSD_LOG_ERROR
,
2587 "Unable to initialize browse access control list!");
2588 else if (!strncasecmp(value
, "deny", 4))
2589 location
->order_type
= CUPSD_AUTH_ALLOW
;
2590 else if (!strncasecmp(value
, "allow", 5))
2591 location
->order_type
= CUPSD_AUTH_DENY
;
2593 cupsdLogMessage(CUPSD_LOG_ERROR
,
2594 "Unknown BrowseOrder value %s on line %d.",
2597 else if (!strcasecmp(line
, "BrowseProtocols") ||
2598 !strcasecmp(line
, "BrowseLocalProtocols") ||
2599 !strcasecmp(line
, "BrowseRemoteProtocols"))
2602 * "BrowseProtocols name [... name]"
2603 * "BrowseLocalProtocols name [... name]"
2604 * "BrowseRemoteProtocols name [... name]"
2607 int protocols
= parse_protocols(value
);
2611 cupsdLogMessage(CUPSD_LOG_ERROR
,
2612 "Unknown browse protocol \"%s\" on line %d.",
2617 if (strcasecmp(line
, "BrowseLocalProtocols"))
2618 BrowseRemoteProtocols
= protocols
;
2619 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2620 BrowseLocalProtocols
= protocols
;
2622 else if ((!strcasecmp(line
, "BrowseAllow") ||
2623 !strcasecmp(line
, "BrowseDeny")) && value
)
2626 * BrowseAllow [From] host/ip...
2627 * BrowseDeny [From] host/ip...
2630 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2631 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2633 if (location
== NULL
)
2634 cupsdLogMessage(CUPSD_LOG_ERROR
,
2635 "Unable to initialize browse access control list!");
2640 if (!strncasecmp(value
, "from", 4))
2643 * Strip leading "from"...
2648 while (isspace(*value
& 255))
2656 * Find the end of the value...
2659 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2661 while (isspace(*valueptr
& 255))
2665 * Figure out what form the allow/deny address takes:
2676 * nnn.nnn.nnn.nnn/mm
2677 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2680 if (!strcasecmp(value
, "all"))
2686 if (!strcasecmp(line
, "BrowseAllow"))
2687 cupsdAllowIP(location
, zeros
, zeros
);
2689 cupsdDenyIP(location
, zeros
, zeros
);
2691 else if (!strcasecmp(value
, "none"))
2697 if (!strcasecmp(line
, "BrowseAllow"))
2698 cupsdAllowIP(location
, ones
, zeros
);
2700 cupsdDenyIP(location
, ones
, zeros
);
2703 else if (value
[0] == '*' || value
[0] == '.' ||
2704 (!isdigit(value
[0] & 255) && value
[0] != '['))
2706 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2707 #endif /* AF_INET6 */
2710 * Host or domain name...
2713 if (value
[0] == '*')
2716 if (!strcasecmp(line
, "BrowseAllow"))
2717 cupsdAllowHost(location
, value
);
2719 cupsdDenyHost(location
, value
);
2724 * One of many IP address forms...
2727 if (!get_addr_and_mask(value
, ip
, mask
))
2729 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2734 if (!strcasecmp(line
, "BrowseAllow"))
2735 cupsdAllowIP(location
, ip
, mask
);
2737 cupsdDenyIP(location
, ip
, mask
);
2741 * Advance to next value...
2748 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2751 * BrowseRelay [from] source [to] destination
2755 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2757 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2761 cupsdLogMessage(CUPSD_LOG_ERROR
,
2762 "Unable to allocate BrowseRelay at line %d - %s.",
2763 linenum
, strerror(errno
));
2770 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2772 if (!strncasecmp(value
, "from ", 5))
2775 * Strip leading "from"...
2780 while (isspace(*value
))
2785 * Figure out what form the from address takes:
2794 * nnn.nnn.nnn.nnn/mm
2795 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2799 if (value
[0] == '*' || value
[0] == '.' ||
2800 (!isdigit(value
[0] & 255) && value
[0] != '['))
2802 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2803 #endif /* AF_INET6 */
2806 * Host or domain name...
2809 if (value
[0] == '*')
2812 strlcpy(temp
, value
, sizeof(temp
));
2813 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2816 relay
->from
.type
= CUPSD_AUTH_NAME
;
2818 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2820 cupsdLogMessage(CUPSD_LOG_ERROR
,
2821 "Unable to allocate BrowseRelay name at line %d - %s.",
2822 linenum
, strerror(errno
));
2826 relay
->from
.mask
.name
.length
= strlen(temp
);
2831 * One of many IP address forms...
2834 if (!get_addr_and_mask(value
, ip
, mask
))
2836 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2841 relay
->from
.type
= CUPSD_AUTH_IP
;
2842 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2843 sizeof(relay
->from
.mask
.ip
.address
));
2844 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2845 sizeof(relay
->from
.mask
.ip
.netmask
));
2849 * Skip value and trailing whitespace...
2852 for (; *value
; value
++)
2853 if (isspace(*value
))
2856 while (isspace(*value
))
2859 if (!strncasecmp(value
, "to ", 3))
2862 * Strip leading "to"...
2867 while (isspace(*value
))
2872 * Get "to" address and port...
2875 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2878 * Only IPv4 addresses are supported...
2881 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2882 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2887 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2889 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2891 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2892 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2893 relay
->from
.mask
.ip
.address
[0] >> 24,
2894 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2895 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2896 relay
->from
.mask
.ip
.address
[0] & 255,
2897 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2898 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2899 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2900 relay
->from
.mask
.ip
.netmask
[0] & 255);
2902 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2904 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2905 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2910 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2913 httpAddrFreeList(addrlist
);
2917 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2918 free(relay
->from
.mask
.name
.name
);
2920 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2924 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2927 * BrowsePoll address[:port]
2930 char *portname
; /* Port name */
2931 int portnum
; /* Port number */
2932 struct servent
*service
; /* Service */
2936 * Extract the port name from the address...
2939 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2943 if (isdigit(*portname
& 255))
2944 portnum
= atoi(portname
);
2945 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2946 portnum
= ntohs(service
->s_port
);
2949 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2955 portnum
= ippPort();
2958 * Add the poll entry...
2962 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2964 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2968 cupsdLogMessage(CUPSD_LOG_ERROR
,
2969 "Unable to allocate BrowsePoll at line %d - %s.",
2970 linenum
, strerror(errno
));
2978 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2980 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2981 pollp
->port
= portnum
;
2983 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2986 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2989 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2992 if (!strcasecmp(value
, "none"))
2993 DefaultAuthType
= CUPSD_AUTH_NONE
;
2994 else if (!strcasecmp(value
, "basic"))
2995 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2996 else if (!strcasecmp(value
, "digest"))
2997 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2998 else if (!strcasecmp(value
, "basicdigest"))
2999 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3001 else if (!strcasecmp(value
, "negotiate"))
3002 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3003 #endif /* HAVE_GSSAPI */
3006 cupsdLogMessage(CUPSD_LOG_WARN
,
3007 "Unknown default authorization type %s on line %d.",
3009 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3014 else if (!strcasecmp(line
, "DefaultEncryption"))
3017 * DefaultEncryption {Never,IfRequested,Required}
3020 if (!value
|| !strcasecmp(value
, "never"))
3021 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3022 else if (!strcasecmp(value
, "required"))
3023 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3024 else if (!strcasecmp(value
, "ifrequested"))
3025 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3028 cupsdLogMessage(CUPSD_LOG_WARN
,
3029 "Unknown default encryption %s on line %d.",
3031 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3035 #endif /* HAVE_SSL */
3037 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
3039 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
3042 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
3043 gsskrb5_register_acceptor_identity(value
);
3045 cupsdSetEnv("KRB5_KTNAME", value
);
3046 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
3048 #endif /* HAVE_GSSAPI */
3049 else if (!strcasecmp(line
, "User") && value
)
3052 * User ID to run as...
3055 if (isdigit(value
[0] & 255))
3057 int uid
= atoi(value
);
3060 cupsdLogMessage(CUPSD_LOG_ERROR
,
3061 "Will not use User 0 as specified on line %d "
3062 "for security reasons. You must use a non-"
3063 "privileged account instead.",
3070 struct passwd
*p
; /* Password information */
3073 p
= getpwnam(value
);
3078 cupsdLogMessage(CUPSD_LOG_ERROR
,
3079 "Will not use User %s (UID=0) as specified on line "
3080 "%d for security reasons. You must use a non-"
3081 "privileged account instead.",
3087 cupsdLogMessage(CUPSD_LOG_ERROR
,
3088 "Unknown User \"%s\" on line %d, ignoring!",
3092 else if (!strcasecmp(line
, "Group") && value
)
3095 * Group ID to run as...
3098 if (isdigit(value
[0]))
3099 Group
= atoi(value
);
3103 group
= getgrnam(value
);
3106 Group
= group
->gr_gid
;
3108 cupsdLogMessage(CUPSD_LOG_ERROR
,
3109 "Unknown Group \"%s\" on line %d, ignoring!",
3113 else if (!strcasecmp(line
, "SystemGroup") && value
)
3116 * SystemGroup (admin) group(s)...
3119 if (!parse_groups(value
))
3120 cupsdLogMessage(CUPSD_LOG_ERROR
,
3121 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3124 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3127 * Do hostname lookups?
3130 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3131 !strcasecmp(value
, "false"))
3132 HostNameLookups
= 0;
3133 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3134 !strcasecmp(value
, "true"))
3135 HostNameLookups
= 1;
3136 else if (!strcasecmp(value
, "double"))
3137 HostNameLookups
= 2;
3139 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3142 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3145 * Amount of logging to do to access log...
3148 if (!strcasecmp(value
, "all"))
3149 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3150 else if (!strcasecmp(value
, "actions"))
3151 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3152 else if (!strcasecmp(value
, "config"))
3153 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3155 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3158 else if (!strcasecmp(line
, "LogLevel") && value
)
3161 * Amount of logging to do to error log...
3164 if (!strcasecmp(value
, "debug2"))
3165 LogLevel
= CUPSD_LOG_DEBUG2
;
3166 else if (!strcasecmp(value
, "debug"))
3167 LogLevel
= CUPSD_LOG_DEBUG
;
3168 else if (!strcasecmp(value
, "info"))
3169 LogLevel
= CUPSD_LOG_INFO
;
3170 else if (!strcasecmp(value
, "notice"))
3171 LogLevel
= CUPSD_LOG_NOTICE
;
3172 else if (!strcasecmp(value
, "warn"))
3173 LogLevel
= CUPSD_LOG_WARN
;
3174 else if (!strcasecmp(value
, "error"))
3175 LogLevel
= CUPSD_LOG_ERROR
;
3176 else if (!strcasecmp(value
, "crit"))
3177 LogLevel
= CUPSD_LOG_CRIT
;
3178 else if (!strcasecmp(value
, "alert"))
3179 LogLevel
= CUPSD_LOG_ALERT
;
3180 else if (!strcasecmp(value
, "emerg"))
3181 LogLevel
= CUPSD_LOG_EMERG
;
3182 else if (!strcasecmp(value
, "none"))
3183 LogLevel
= CUPSD_LOG_NONE
;
3185 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3188 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3191 * Amount of logging to do to error log...
3194 if (!strcasecmp(value
, "standard"))
3195 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3196 else if (!strcasecmp(value
, "usecs"))
3197 LogTimeFormat
= CUPSD_TIME_USECS
;
3199 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3202 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3205 * Format of printcap file?
3208 if (!strcasecmp(value
, "bsd"))
3209 PrintcapFormat
= PRINTCAP_BSD
;
3210 else if (!strcasecmp(value
, "plist"))
3211 PrintcapFormat
= PRINTCAP_PLIST
;
3212 else if (!strcasecmp(value
, "solaris"))
3213 PrintcapFormat
= PRINTCAP_SOLARIS
;
3215 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3218 else if (!strcasecmp(line
, "ServerTokens") && value
)
3221 * Set the string used for the Server header...
3224 struct utsname plat
; /* Platform info */
3229 if (!strcasecmp(value
, "ProductOnly"))
3230 cupsdSetString(&ServerHeader
, "CUPS");
3231 else if (!strcasecmp(value
, "Major"))
3232 cupsdSetString(&ServerHeader
, "CUPS/1");
3233 else if (!strcasecmp(value
, "Minor"))
3234 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3235 else if (!strcasecmp(value
, "Minimal"))
3236 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3237 else if (!strcasecmp(value
, "OS"))
3238 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3239 else if (!strcasecmp(value
, "Full"))
3240 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3242 else if (!strcasecmp(value
, "None"))
3243 cupsdClearString(&ServerHeader
);
3245 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3248 else if (!strcasecmp(line
, "PassEnv") && value
)
3251 * PassEnv variable [... variable]
3256 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3257 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3260 if (value
[valuelen
])
3262 value
[valuelen
] = '\0';
3266 cupsdSetEnv(value
, NULL
);
3268 for (value
+= valuelen
; *value
; value
++)
3269 if (!isspace(*value
) || *value
!= ',')
3273 else if (!strcasecmp(line
, "SetEnv") && value
)
3276 * SetEnv variable value
3279 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3287 while (isspace(*valueptr
& 255))
3290 cupsdSetEnv(value
, valueptr
);
3293 cupsdLogMessage(CUPSD_LOG_ERROR
,
3294 "Missing value for SetEnv directive on line %d.",
3298 else if (!strcasecmp(line
, "SSLOptions"))
3301 * SSLOptions options
3304 if (!value
|| !strcasecmp(value
, "none"))
3305 SSLOptions
= CUPSD_SSL_NONE
;
3306 else if (!strcasecmp(value
, "noemptyfragments"))
3307 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3309 cupsdLogMessage(CUPSD_LOG_ERROR
,
3310 "Unknown value \"%s\" for SSLOptions directive on "
3311 "line %d.", value
, linenum
);
3313 #endif /* HAVE_SSL */
3317 * Find a simple variable in the list...
3320 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3321 if (!strcasecmp(line
, var
->name
))
3327 * Unknown directive! Output an error message and continue...
3331 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3334 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3341 case CUPSD_VARTYPE_INTEGER
:
3343 cupsdLogMessage(CUPSD_LOG_ERROR
,
3344 "Missing integer value for %s on line %d!",
3349 char *units
; /* Units */
3352 n
= strtol(value
, &units
, 0);
3354 if (units
&& *units
)
3356 if (tolower(units
[0] & 255) == 'g')
3357 n
*= 1024 * 1024 * 1024;
3358 else if (tolower(units
[0] & 255) == 'm')
3360 else if (tolower(units
[0] & 255) == 'k')
3362 else if (tolower(units
[0] & 255) == 't')
3367 cupsdLogMessage(CUPSD_LOG_ERROR
,
3368 "Bad negative integer value for %s on line %d!",
3371 *((int *)var
->ptr
) = n
;
3375 case CUPSD_VARTYPE_BOOLEAN
:
3377 cupsdLogMessage(CUPSD_LOG_ERROR
,
3378 "Missing boolean value for %s on line %d!",
3380 else if (!strcasecmp(value
, "true") ||
3381 !strcasecmp(value
, "on") ||
3382 !strcasecmp(value
, "enabled") ||
3383 !strcasecmp(value
, "yes") ||
3385 *((int *)var
->ptr
) = TRUE
;
3386 else if (!strcasecmp(value
, "false") ||
3387 !strcasecmp(value
, "off") ||
3388 !strcasecmp(value
, "disabled") ||
3389 !strcasecmp(value
, "no") ||
3390 !strcasecmp(value
, "0"))
3391 *((int *)var
->ptr
) = FALSE
;
3393 cupsdLogMessage(CUPSD_LOG_ERROR
,
3394 "Unknown boolean value %s on line %d.",
3398 case CUPSD_VARTYPE_PATHNAME
:
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Missing pathname value for %s on line %d!",
3407 if (value
[0] == '/')
3408 strlcpy(temp
, value
, sizeof(temp
));
3410 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3412 if (access(temp
, 0))
3414 cupsdLogMessage(CUPSD_LOG_ERROR
,
3415 "File or directory for \"%s %s\" on line %d "
3416 "does not exist!", line
, value
, linenum
);
3420 case CUPSD_VARTYPE_STRING
:
3421 cupsdSetString((char **)var
->ptr
, value
);
3432 * 'read_location()' - Read a <Location path> definition.
3435 static int /* O - New line number or 0 on error */
3436 read_location(cups_file_t
*fp
, /* I - Configuration file */
3437 char *location
, /* I - Location name/path */
3438 int linenum
) /* I - Current line number */
3440 cupsd_location_t
*loc
, /* New location */
3441 *parent
; /* Parent location */
3442 char line
[HTTP_MAX_BUFFER
],
3444 *value
, /* Value for directive */
3445 *valptr
; /* Pointer into value */
3448 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3451 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3454 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3457 * Decode the directive...
3460 if (!strcasecmp(line
, "</Location>"))
3462 else if (!strcasecmp(line
, "<Limit") ||
3463 !strcasecmp(line
, "<LimitExcept"))
3467 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3468 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3474 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3480 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3485 if (!strcmp(value
, "ALL"))
3486 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3487 else if (!strcmp(value
, "GET"))
3488 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3489 else if (!strcmp(value
, "HEAD"))
3490 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3491 else if (!strcmp(value
, "OPTIONS"))
3492 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3493 else if (!strcmp(value
, "POST"))
3494 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3495 else if (!strcmp(value
, "PUT"))
3496 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3497 else if (!strcmp(value
, "TRACE"))
3498 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3500 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3503 for (value
= valptr
; isspace(*value
& 255); value
++);
3506 if (!strcasecmp(line
, "<LimitExcept"))
3507 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3509 parent
->limit
&= ~loc
->limit
;
3511 else if (!strcasecmp(line
, "</Limit>") ||
3512 !strcasecmp(line
, "</LimitExcept>"))
3514 else if (!parse_aaa(loc
, line
, value
, linenum
))
3516 cupsdLogMessage(CUPSD_LOG_ERROR
,
3517 "Unknown Location directive %s on line %d.",
3519 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3524 cupsdLogMessage(CUPSD_LOG_ERROR
,
3525 "Unexpected end-of-file at line %d while reading location!",
3528 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3533 * 'read_policy()' - Read a <Policy name> definition.
3536 static int /* O - New line number or 0 on error */
3537 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3538 char *policy
, /* I - Location name/path */
3539 int linenum
) /* I - Current line number */
3541 int i
; /* Looping var */
3542 cupsd_policy_t
*pol
; /* Policy */
3543 cupsd_location_t
*op
; /* Policy operation */
3544 int num_ops
; /* Number of IPP operations */
3545 ipp_op_t ops
[100]; /* Operations */
3546 char line
[HTTP_MAX_BUFFER
],
3548 *value
, /* Value for directive */
3549 *valptr
; /* Pointer into value */
3553 * Create the policy...
3556 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3560 * Read from the file...
3566 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3569 * Decode the directive...
3572 if (!strcasecmp(line
, "</Policy>"))
3575 cupsdLogMessage(CUPSD_LOG_WARN
,
3576 "Missing </Limit> before </Policy> on line %d!",
3580 * Verify that we have an explicit policy for CUPS-Get-Document
3581 * (ensures that upgrades do not introduce new security issues...)
3584 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3585 op
->op
== IPP_ANY_OPERATION
)
3587 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3588 op
->op
!= IPP_ANY_OPERATION
)
3591 * Add a new limit for CUPS-Get-Document using the Send-Document
3592 * limit as a template...
3595 cupsdLogMessage(CUPSD_LOG_WARN
,
3596 "No limit for CUPS-Get-Document defined in policy %s "
3597 "- using Send-Document's policy", pol
->name
);
3599 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3605 else if (!strcasecmp(line
, "<Limit") && !op
)
3609 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3610 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3617 * Scan for IPP operation names...
3624 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3629 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3631 if (!strcasecmp(value
, "All"))
3632 ops
[num_ops
] = IPP_ANY_OPERATION
;
3633 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3634 cupsdLogMessage(CUPSD_LOG_ERROR
,
3635 "Bad IPP operation name \"%s\" on line %d!",
3641 cupsdLogMessage(CUPSD_LOG_ERROR
,
3642 "Too many operations listed on line %d!",
3645 for (value
= valptr
; isspace(*value
& 255); value
++);
3649 * If none are specified, apply the policy to all operations...
3654 ops
[0] = IPP_ANY_OPERATION
;
3659 * Add a new policy for the first operation...
3662 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3664 else if (!strcasecmp(line
, "</Limit>") && op
)
3667 * Finish the current operation limit...
3673 * Copy the policy to the other operations...
3676 for (i
= 1; i
< num_ops
; i
++)
3677 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3684 cupsdLogMessage(CUPSD_LOG_ERROR
,
3685 "Missing <Limit ops> directive before %s on line %d.",
3687 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3690 else if (!parse_aaa(op
, line
, value
, linenum
))
3693 cupsdLogMessage(CUPSD_LOG_ERROR
,
3694 "Unknown Policy Limit directive %s on line %d.",
3697 cupsdLogMessage(CUPSD_LOG_ERROR
,
3698 "Unknown Policy directive %s on line %d.",
3701 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3706 cupsdLogMessage(CUPSD_LOG_ERROR
,
3707 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3710 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3715 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".