2 * "$Id: conf.c 7694 2008-06-26 00:23: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 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
99 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
100 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
101 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
102 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
103 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
104 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
105 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
106 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
107 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
108 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
109 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
110 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
111 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
112 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
113 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
114 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
115 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
116 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
117 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
119 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
120 #endif /* HAVE_GSSAPI */
121 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
122 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
123 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
124 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
125 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
126 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
127 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
129 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
130 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
131 #endif /* HAVE_LAUNCHD */
132 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
133 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
134 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
135 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
136 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
152 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
153 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
154 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
155 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
156 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
157 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
158 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
159 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
160 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
161 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
162 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
163 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
164 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
166 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
167 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
168 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
169 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
170 #endif /* HAVE_SSL */
171 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
172 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
173 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
174 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
175 #ifdef HAVE_AUTHORIZATION_H
176 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
177 #endif /* HAVE_AUTHORIZATION_H */
178 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
179 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
180 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
182 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
185 static const unsigned ones
[4] =
187 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
189 static const unsigned zeros
[4] =
191 0x00000000, 0x00000000, 0x00000000, 0x00000000
198 static http_addrlist_t
*get_address(const char *value
, int defport
);
199 static int get_addr_and_mask(const char *value
, unsigned *ip
,
201 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
202 char *value
, int linenum
);
203 static int parse_fatal_errors(const char *s
);
204 static int parse_groups(const char *s
);
205 static int parse_protocols(const char *s
);
206 static int read_configuration(cups_file_t
*fp
);
207 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
208 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
212 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
215 int /* O - 0 on success, -1 on error, 1 on warning */
216 cupsdCheckPermissions(
217 const char *filename
, /* I - File/directory name */
218 const char *suffix
, /* I - Additional file/directory name */
219 int mode
, /* I - Permissions */
220 int user
, /* I - Owner */
221 int group
, /* I - Group */
222 int is_dir
, /* I - 1 = directory, 0 = file */
223 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
225 int dir_created
= 0; /* Did we create a directory? */
226 char pathname
[1024]; /* File name with prefix */
227 struct stat fileinfo
; /* Stat buffer */
228 int is_symlink
; /* Is "filename" a symlink? */
232 * Prepend the given root to the filename before testing it...
237 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
242 * See if we can stat the file/directory...
245 if (lstat(filename
, &fileinfo
))
247 if (errno
== ENOENT
&& create_dir
)
250 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
253 if (mkdir(filename
, mode
))
256 cupsdLogMessage(CUPSD_LOG_ERROR
,
257 "Unable to create directory \"%s\" - %s", filename
,
260 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
269 return (create_dir
? -1 : 1);
272 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
274 if (stat(filename
, &fileinfo
))
276 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
277 filename
, strerror(errno
));
283 * Make sure it's a regular file or a directory as needed...
286 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
288 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
292 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
295 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
297 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
303 * If the filename is a symlink, do not change permissions (STR #2937)...
310 * Fix owner, group, and mode as needed...
313 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
316 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
319 if (chown(filename
, user
, group
) && !getuid())
322 cupsdLogMessage(CUPSD_LOG_ERROR
,
323 "Unable to change ownership of \"%s\" - %s", filename
,
326 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
333 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
336 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
339 if (chmod(filename
, mode
))
342 cupsdLogMessage(CUPSD_LOG_ERROR
,
343 "Unable to change permissions of \"%s\" - %s", filename
,
346 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
354 * Everything is OK...
362 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
365 int /* O - 1 on success, 0 otherwise */
366 cupsdReadConfiguration(void)
368 int i
; /* Looping var */
369 cups_file_t
*fp
; /* Configuration file */
370 int status
; /* Return status */
371 char temp
[1024], /* Temporary buffer */
372 mimedir
[1024], /* MIME directory */
373 *slash
; /* Directory separator */
374 cups_lang_t
*language
; /* Language */
375 struct passwd
*user
; /* Default user */
376 struct group
*group
; /* Default group */
377 char *old_serverroot
, /* Old ServerRoot */
378 *old_requestroot
; /* Old RequestRoot */
379 const char *tmpdir
; /* TMPDIR environment variable */
380 struct stat tmpinfo
; /* Temporary directory info */
381 cupsd_policy_t
*p
; /* Policy */
385 * Save the old root paths...
388 old_serverroot
= NULL
;
389 cupsdSetString(&old_serverroot
, ServerRoot
);
390 old_requestroot
= NULL
;
391 cupsdSetString(&old_requestroot
, RequestRoot
);
394 * Reset the server configuration data...
397 cupsdDeleteAllLocations();
416 for (i
= 0; i
< NumRelays
; i
++)
417 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
418 free(Relays
[i
].from
.mask
.name
.name
);
425 cupsdDeleteAllListeners();
431 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
432 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
433 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
434 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
435 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
436 cupsdSetString(&DataDir
, CUPS_DATADIR
);
437 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
438 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
439 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
440 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
441 cupsdSetString(&PageLogFormat
,
442 "%p %j %u %T %P %C %{job-billing} "
443 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
444 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
445 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
446 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
447 cupsdSetString(&RemoteRoot
, "remroot");
448 cupsdSetString(&ServerHeader
, "CUPS/1.4");
449 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
451 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
452 #endif /* HAVE_GSSAPI */
454 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
455 PrintcapFormat
= PRINTCAP_SOLARIS
;
457 PrintcapFormat
= PRINTCAP_BSD
;
459 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
460 if ((slash
= strrchr(temp
, '/')) != NULL
)
463 cupsdSetString(&ServerRoot
, temp
);
465 cupsdClearString(&Classification
);
466 ClassifyOverride
= 0;
470 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
472 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
473 cupsdSetString(&ServerKey
, "ssl/server.key");
474 # endif /* HAVE_CDSASSL */
475 #endif /* HAVE_SSL */
477 language
= cupsLangDefault();
479 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
480 cupsdSetString(&DefaultLanguage
, "en");
482 cupsdSetString(&DefaultLanguage
, language
->language
);
484 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
486 cupsdClearString(&DefaultPaperSize
);
488 cupsdSetString(&RIPCache
, "8m");
490 cupsdSetString(&TempDir
, NULL
);
493 * Find the default user...
496 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
501 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
502 * complement number...)
511 * Find the default group...
514 group
= getgrnam(CUPS_DEFAULT_GROUP
);
518 Group
= group
->gr_gid
;
522 * Fallback to group "nobody"...
525 group
= getgrnam("nobody");
529 Group
= group
->gr_gid
;
533 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
534 * complement number...)
545 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
546 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
547 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
548 DefaultAuthType
= CUPSD_AUTH_BASIC
;
550 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
551 #endif /* HAVE_SSL */
552 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
554 JobRetryInterval
= 300;
559 HostNameLookups
= FALSE
;
560 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
561 ImplicitAnyClasses
= FALSE
;
562 HideImplicitMembers
= TRUE
;
564 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
565 ListenBackLog
= SOMAXCONN
;
566 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
567 LogLevel
= CUPSD_LOG_WARN
;
569 MaxClientsPerHost
= 0;
570 MaxLogSize
= 1024 * 1024;
571 MaxPrinterHistory
= 10;
573 ReloadTimeout
= DEFAULT_KEEPALIVE
;
574 RootCertDuration
= 300;
575 Timeout
= DEFAULT_TIMEOUT
;
578 BrowseInterval
= DEFAULT_INTERVAL
;
579 BrowsePort
= ippPort();
580 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
581 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
582 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
583 BrowseTimeout
= DEFAULT_TIMEOUT
;
584 Browsing
= CUPS_DEFAULT_BROWSING
;
585 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
587 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
588 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
590 cupsdClearString(&BrowseLocalOptions
);
591 cupsdClearString(&BrowseRemoteOptions
);
593 cupsdSetString(&ErrorPolicy
, "stop-printer");
596 cupsdClearString(&BrowseLDAPBindDN
);
597 cupsdClearString(&BrowseLDAPDN
);
598 cupsdClearString(&BrowseLDAPPassword
);
599 cupsdClearString(&BrowseLDAPServer
);
600 # ifdef HAVE_LDAP_SSL
601 cupsdClearString(&BrowseLDAPCACertFile
);
602 # endif /* HAVE_LDAP_SSL */
603 #endif /* HAVE_LDAP */
605 JobHistory
= DEFAULT_HISTORY
;
606 JobFiles
= DEFAULT_FILES
;
611 MaxJobsPerPrinter
= 0;
612 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
614 cupsdDeleteAllPolicies();
615 cupsdClearString(&DefaultPolicy
);
617 #ifdef HAVE_AUTHORIZATION_H
618 cupsdClearString(&SystemGroupAuthKey
);
619 #endif /* HAVE_AUTHORIZATION_H */
621 MaxSubscriptions
= 100;
622 MaxSubscriptionsPerJob
= 0;
623 MaxSubscriptionsPerPrinter
= 0;
624 MaxSubscriptionsPerUser
= 0;
625 DefaultLeaseDuration
= 86400;
626 MaxLeaseDuration
= 0;
629 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
630 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
631 #endif /* HAVE_LAUNCHD */
635 #endif /* __APPLE__ */
638 * Read the configuration file...
641 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
644 status
= read_configuration(fp
);
654 * See if the ServerName is an IP address...
657 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
659 ServerNameIsIP
= !*slash
;
662 * Use the default system group if none was supplied in cupsd.conf...
665 if (NumSystemGroups
== 0)
667 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
670 * Find the group associated with GID 0...
677 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
679 cupsdSetString(&SystemGroups
[0], "unknown");
681 SystemGroupIDs
[0] = 0;
687 * Get the access control list for browsing...
690 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
693 * Open the system log for cupsd if necessary...
697 if (!strcmp(AccessLog
, "syslog") ||
698 !strcmp(ErrorLog
, "syslog") ||
699 !strcmp(PageLog
, "syslog"))
700 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
701 #endif /* HAVE_VSYSLOG */
704 * Log the configuration file that was used...
707 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
711 * Validate the Group and SystemGroup settings - they cannot be the same,
712 * otherwise the CGI programs will be able to authenticate as root without
718 for (i
= 0; i
< NumSystemGroups
; i
++)
719 if (Group
== SystemGroupIDs
[i
])
722 if (i
< NumSystemGroups
)
725 * Log the error and reset the group to a safe value...
728 cupsdLogMessage(CUPSD_LOG_NOTICE
,
729 "Group and SystemGroup cannot use the same groups!");
730 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
732 group
= getgrnam("nobody");
736 Group
= group
->gr_gid
;
740 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
741 * complement number...)
750 * Check that we have at least one listen/port line; if not, report this
751 * as an error and exit!
754 if (cupsArrayCount(Listeners
) == 0)
760 cupsdLogMessage(CUPSD_LOG_EMERG
,
761 "No valid Listen or Port lines were found in the "
762 "configuration file!");
768 cupsdEndProcess(getpid(), 0);
772 * Set the default locale using the language and charset...
775 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
778 * Update all relative filenames to include the full path from ServerRoot...
781 if (DocumentRoot
[0] != '/')
782 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
784 if (RequestRoot
[0] != '/')
785 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
787 if (ServerBin
[0] != '/')
788 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
790 if (StateDir
[0] != '/')
791 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
793 if (CacheDir
[0] != '/')
794 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
797 if (ServerCertificate
[0] != '/')
798 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
800 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
801 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
803 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
806 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
807 if (ServerKey
[0] != '/')
808 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
810 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
811 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
812 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
814 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
815 #endif /* HAVE_SSL */
818 * Make sure that directories and config files are owned and
819 * writable by the user and group in the cupsd.conf file...
822 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
824 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
826 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
828 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
830 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
832 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
833 SystemGroupIDs
[0], 1, 1) < 0 ||
834 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
836 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
838 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
840 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
842 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
844 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
846 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
848 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
852 * Update TempDir to the default if it hasn't been set already...
857 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
860 * TMPDIR is defined, see if it is OK for us to use...
863 if (stat(tmpdir
, &tmpinfo
))
864 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
865 tmpdir
, strerror(errno
));
866 else if (!S_ISDIR(tmpinfo
.st_mode
))
867 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
869 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
870 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
871 !(tmpinfo
.st_mode
& S_IWOTH
))
872 cupsdLogMessage(CUPSD_LOG_ERROR
,
873 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
875 cupsdSetString(&TempDir
, tmpdir
);
880 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
882 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
887 * Make sure the temporary directory has the right permissions...
890 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
894 * Update ownership and permissions if the CUPS temp directory
895 * is under the spool directory or does not exist...
898 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
899 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
904 * Setup environment variables...
910 * Update default paper size setting as needed...
913 if (!DefaultPaperSize
)
916 char *paper_result
; /* Paper size name from libpaper */
918 if ((paper_result
= systempapername()) != NULL
)
919 cupsdSetString(&DefaultPaperSize
, paper_result
);
921 #endif /* HAVE_LIBPAPER */
922 if (!DefaultLanguage
||
923 !strcasecmp(DefaultLanguage
, "C") ||
924 !strcasecmp(DefaultLanguage
, "POSIX") ||
925 !strcasecmp(DefaultLanguage
, "en") ||
926 !strncasecmp(DefaultLanguage
, "en.", 3) ||
927 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
928 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
929 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
932 * These are the only locales that will default to "letter" size...
935 cupsdSetString(&DefaultPaperSize
, "Letter");
938 cupsdSetString(&DefaultPaperSize
, "A4");
942 * Update classification setting as needed...
945 if (Classification
&& !strcasecmp(Classification
, "none"))
946 cupsdClearString(&Classification
);
949 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
952 * Check the MaxClients setting, and then allocate memory for it...
955 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
958 cupsdLogMessage(CUPSD_LOG_INFO
,
959 "MaxClients limited to 1/3 (%d) of the file descriptor "
963 MaxClients
= MaxFDs
/ 3;
966 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
970 * Check the MaxActiveJobs setting; limit to 1/3 the available
971 * file descriptors, since we need a pipe for each job...
974 if (MaxActiveJobs
> (MaxFDs
/ 3))
975 MaxActiveJobs
= MaxFDs
/ 3;
978 * Update the MaxClientsPerHost value, as needed...
981 if (MaxClientsPerHost
<= 0)
982 MaxClientsPerHost
= MaxClients
;
984 if (MaxClientsPerHost
> MaxClients
)
985 MaxClientsPerHost
= MaxClients
;
987 cupsdLogMessage(CUPSD_LOG_INFO
,
988 "Allowing up to %d client connections per host.",
992 * Make sure that BrowseTimeout is at least twice the interval...
995 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
997 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1001 BrowseTimeout
= BrowseInterval
* 2;
1003 BrowseTimeout
= DEFAULT_TIMEOUT
;
1005 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1010 * Update the default policy, as needed...
1014 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1016 DefaultPolicyPtr
= NULL
;
1018 if (!DefaultPolicyPtr
)
1020 cupsd_location_t
*po
; /* New policy operation */
1024 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1027 cupsdSetString(&DefaultPolicy
, "default");
1029 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1030 cupsdLogMessage(CUPSD_LOG_INFO
,
1031 "Using policy \"default\" as the default!");
1034 cupsdLogMessage(CUPSD_LOG_INFO
,
1035 "Creating CUPS default administrative policy:");
1037 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1039 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1040 cupsdLogMessage(CUPSD_LOG_INFO
,
1041 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1042 "Release-Job Restart-Job Purge-Jobs "
1043 "Set-Job-Attributes Create-Job-Subscription "
1044 "Renew-Subscription Cancel-Subscription "
1045 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1046 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1047 "CUPS-Authenticate-Job CUPS-Get-Document>");
1048 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1050 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1051 po
->order_type
= CUPSD_AUTH_ALLOW
;
1052 po
->level
= CUPSD_AUTH_USER
;
1054 cupsdAddName(po
, "@OWNER");
1055 cupsdAddName(po
, "@SYSTEM");
1056 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1058 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1059 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1060 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1061 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1062 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1063 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1064 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1065 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1066 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1067 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1068 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1069 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1070 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1071 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1072 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1073 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1074 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1075 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1077 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1079 cupsdLogMessage(CUPSD_LOG_INFO
,
1080 "<Limit Pause-Printer Resume-Printer "
1081 "Set-Printer-Attributes Enable-Printer "
1082 "Disable-Printer Pause-Printer-After-Current-Job "
1083 "Hold-New-Jobs Release-Held-New-Jobs "
1084 "Deactivate-Printer Activate-Printer Restart-Printer "
1085 "Shutdown-Printer Startup-Printer Promote-Job "
1086 "Schedule-Job-After CUPS-Add-Printer "
1087 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1088 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1089 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1090 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1092 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1093 po
->order_type
= CUPSD_AUTH_ALLOW
;
1094 po
->type
= CUPSD_AUTH_DEFAULT
;
1095 po
->level
= CUPSD_AUTH_USER
;
1097 cupsdAddName(po
, "@SYSTEM");
1098 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1100 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1101 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1102 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1103 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1104 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1105 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1106 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1107 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1108 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1109 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1110 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1111 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1112 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1113 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1114 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1115 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1116 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1117 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1118 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1119 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1120 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1122 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1124 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1125 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1127 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1128 po
->order_type
= CUPSD_AUTH_ALLOW
;
1130 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1131 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1135 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1136 cupsArrayCount(Policies
));
1137 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1139 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1140 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1141 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1144 * If we are doing a full reload or the server root has changed, flush
1145 * the jobs, printers, etc. and start from scratch...
1148 if (NeedReload
== RELOAD_ALL
||
1149 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1150 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1152 mime_type_t
*type
; /* Current type */
1153 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1154 /* MIME type name */
1157 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1160 * Free all memory...
1163 cupsdDeleteAllSubscriptions();
1165 cupsdDeleteAllClasses();
1166 cupsdDeleteAllPrinters();
1168 DefaultPrinter
= NULL
;
1170 if (MimeDatabase
!= NULL
)
1171 mimeDelete(MimeDatabase
);
1175 for (i
= 0; i
< NumMimeTypes
; i
++)
1176 _cupsStrFree(MimeTypes
[i
]);
1182 * Read the MIME type and conversion database...
1185 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1186 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1188 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1189 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1190 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1191 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1195 cupsdLogMessage(CUPSD_LOG_EMERG
,
1196 "Unable to load MIME database from \"%s\" or \"%s\"!",
1197 mimedir
, ServerRoot
);
1198 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1202 cupsdLogMessage(CUPSD_LOG_INFO
,
1203 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1204 "%d filters...", mimedir
, ServerRoot
,
1205 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1208 * Create a list of MIME types for the document-format-supported
1212 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1213 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1216 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1218 cupsdLogMessage(CUPSD_LOG_ERROR
,
1219 "Unable to allocate memory for %d MIME types!",
1225 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1227 i
++, type
= mimeNextType(MimeDatabase
))
1229 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1231 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1234 if (i
< NumMimeTypes
)
1235 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1238 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1240 mime_filter_t
*filter
; /* Current filter */
1243 for (type
= mimeFirstType(MimeDatabase
);
1245 type
= mimeNextType(MimeDatabase
))
1246 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1247 type
->super
, type
->type
);
1249 for (filter
= mimeFirstFilter(MimeDatabase
);
1251 filter
= mimeNextFilter(MimeDatabase
))
1252 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1253 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1254 filter
->src
->super
, filter
->src
->type
,
1255 filter
->dst
->super
, filter
->dst
->type
,
1256 filter
->cost
, filter
->filter
);
1263 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1264 cupsdLoadBanners(temp
);
1267 * Load printers and classes...
1270 cupsdLoadAllPrinters();
1271 cupsdLoadAllClasses();
1272 cupsdLoadRemoteCache();
1273 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1275 cupsdCreateCommonData();
1278 * Load queued jobs...
1284 * Load subscriptions...
1287 cupsdLoadAllSubscriptions();
1289 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1294 * Not a full reload, so recreate the common printer attributes...
1297 cupsdCreateCommonData();
1300 * Update all printers as needed...
1303 cupsdUpdatePrinters();
1304 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1306 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1310 * Reset the reload state...
1313 NeedReload
= RELOAD_NONE
;
1315 cupsdClearString(&old_serverroot
);
1316 cupsdClearString(&old_requestroot
);
1323 * 'get_address()' - Get an address + port number from a line.
1326 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1327 get_address(const char *value
, /* I - Value string */
1328 int defport
) /* I - Default port */
1330 char buffer
[1024], /* Hostname + port number buffer */
1331 defpname
[255], /* Default port name */
1332 *hostname
, /* Hostname or IP */
1333 *portname
; /* Port number or name */
1334 http_addrlist_t
*addrlist
; /* Address list */
1338 * Check for an empty value...
1343 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1348 * Grab a hostname and port number; if there is no colon and the port name
1349 * is only digits, then we have a port number by itself...
1352 strlcpy(buffer
, value
, sizeof(buffer
));
1354 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1361 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1366 * Use the default port...
1369 sprintf(defpname
, "%d", defport
);
1370 portname
= defpname
;
1376 * The buffer contains just a port number...
1384 if (hostname
&& !strcmp(hostname
, "*"))
1388 * Now lookup the address using httpAddrGetList()...
1391 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1392 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1393 hostname
? hostname
: "(nil)");
1400 * 'get_addr_and_mask()' - Get an IP address and netmask.
1403 static int /* O - 1 on success, 0 on failure */
1404 get_addr_and_mask(const char *value
, /* I - String from config file */
1405 unsigned *ip
, /* O - Address value */
1406 unsigned *mask
) /* O - Mask value */
1408 int i
, j
, /* Looping vars */
1409 family
, /* Address family */
1410 ipcount
; /* Count of fields in address */
1411 unsigned ipval
; /* Value */
1412 const char *maskval
, /* Pointer to start of mask value */
1413 *ptr
, /* Pointer into value */
1418 * Get the address...
1421 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1422 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1424 if ((maskval
= strchr(value
, '/')) != NULL
)
1427 maskval
= value
+ strlen(value
);
1431 * Check for an IPv6 address...
1437 * Parse hexadecimal IPv6 address...
1442 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1446 else if (!strncmp(ptr
, "::", 2))
1448 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1450 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1455 else if (isxdigit(*ptr
& 255))
1457 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1465 ip
[i
/ 2] |= ipval
<< 16;
1479 if (*ptr
&& *ptr
!= '/')
1483 #endif /* AF_INET6 */
1486 * Parse dotted-decimal IPv4 address...
1489 unsigned val
[4]; /* IPv4 address values */
1493 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1496 * Range check the IP numbers...
1499 for (i
= 0; i
< ipcount
; i
++)
1504 * Make sure the trailing values are zeroed, as some C libraries like
1505 * glibc apparently like to fill the unused arguments with garbage...
1508 for (i
= ipcount
; i
< 4; i
++)
1512 * Merge everything into a 32-bit IPv4 address in ip[3]...
1515 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1518 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1524 * Get the netmask value(s)...
1527 memset(mask
, 0, sizeof(unsigned) * 4);
1529 if (strchr(maskval
, '.'))
1532 * Get dotted-decimal mask...
1535 if (family
!= AF_INET
)
1538 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1541 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1542 mask
[0] = mask
[1] = mask
[2] = 0;
1547 * Get address/bits format...
1553 if (family
== AF_INET6
)
1561 mask
[0] = 0xffffffff;
1563 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1566 mask
[1] = 0xffffffff;
1570 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1573 mask
[2] = 0xffffffff;
1577 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1580 mask
[3] = 0xffffffff;
1584 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1587 #endif /* AF_INET6 */
1592 mask
[0] = 0xffffffff;
1593 mask
[1] = 0xffffffff;
1594 mask
[2] = 0xffffffff;
1597 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1599 mask
[3] = 0xffffffff;
1604 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1605 "get_addr_and_mask(value=\"%s\", "
1606 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1607 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1611 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1614 if ((ip
[0] & ~mask
[0]) != 0 ||
1615 (ip
[1] & ~mask
[1]) != 0 ||
1616 (ip
[2] & ~mask
[2]) != 0 ||
1617 (ip
[3] & ~mask
[3]) != 0)
1625 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1628 static int /* O - 1 on success, 0 on failure */
1629 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1630 char *line
, /* I - Line from file */
1631 char *value
, /* I - Start of value data */
1632 int linenum
) /* I - Current line number */
1634 char *valptr
; /* Pointer into value */
1635 unsigned ip
[4], /* IP address components */
1636 mask
[4]; /* IP netmask components */
1639 if (!strcasecmp(line
, "Encryption"))
1642 * "Encryption xxx" - set required encryption level...
1645 if (!strcasecmp(value
, "never"))
1646 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1647 else if (!strcasecmp(value
, "always"))
1649 cupsdLogMessage(CUPSD_LOG_ERROR
,
1650 "Encryption value \"%s\" on line %d is invalid in this "
1651 "context. Using \"required\" instead.", value
, linenum
);
1653 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1655 else if (!strcasecmp(value
, "required"))
1656 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1657 else if (!strcasecmp(value
, "ifrequested"))
1658 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1661 cupsdLogMessage(CUPSD_LOG_ERROR
,
1662 "Unknown Encryption value %s on line %d.", value
, linenum
);
1666 else if (!strcasecmp(line
, "Order"))
1669 * "Order Deny,Allow" or "Order Allow,Deny"...
1672 if (!strncasecmp(value
, "deny", 4))
1673 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1674 else if (!strncasecmp(value
, "allow", 5))
1675 loc
->order_type
= CUPSD_AUTH_DENY
;
1678 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1683 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1686 * Allow [From] host/ip...
1687 * Deny [From] host/ip...
1690 if (!strncasecmp(value
, "from", 4))
1693 * Strip leading "from"...
1698 while (isspace(*value
& 255))
1703 * Figure out what form the allow/deny address takes:
1714 * nnn.nnn.nnn.nnn/mm
1715 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1718 if (!strcasecmp(value
, "all"))
1724 if (!strcasecmp(line
, "Allow"))
1725 cupsdAllowIP(loc
, zeros
, zeros
);
1727 cupsdDenyIP(loc
, zeros
, zeros
);
1729 else if (!strcasecmp(value
, "none"))
1735 if (!strcasecmp(line
, "Allow"))
1736 cupsdAllowIP(loc
, ones
, zeros
);
1738 cupsdDenyIP(loc
, ones
, zeros
);
1741 else if (value
[0] == '*' || value
[0] == '.' ||
1742 (!isdigit(value
[0] & 255) && value
[0] != '['))
1744 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1745 #endif /* AF_INET6 */
1748 * Host or domain name...
1751 if (value
[0] == '*')
1754 if (!strcasecmp(line
, "Allow"))
1755 cupsdAllowHost(loc
, value
);
1757 cupsdDenyHost(loc
, value
);
1762 * One of many IP address forms...
1765 if (!get_addr_and_mask(value
, ip
, mask
))
1767 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1772 if (!strcasecmp(line
, "Allow"))
1773 cupsdAllowIP(loc
, ip
, mask
);
1775 cupsdDenyIP(loc
, ip
, mask
);
1778 else if (!strcasecmp(line
, "AuthType"))
1781 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1784 if (!strcasecmp(value
, "none"))
1786 loc
->type
= CUPSD_AUTH_NONE
;
1787 loc
->level
= CUPSD_AUTH_ANON
;
1789 else if (!strcasecmp(value
, "basic"))
1791 loc
->type
= CUPSD_AUTH_BASIC
;
1793 if (loc
->level
== CUPSD_AUTH_ANON
)
1794 loc
->level
= CUPSD_AUTH_USER
;
1796 else if (!strcasecmp(value
, "digest"))
1798 loc
->type
= CUPSD_AUTH_DIGEST
;
1800 if (loc
->level
== CUPSD_AUTH_ANON
)
1801 loc
->level
= CUPSD_AUTH_USER
;
1803 else if (!strcasecmp(value
, "basicdigest"))
1805 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1807 if (loc
->level
== CUPSD_AUTH_ANON
)
1808 loc
->level
= CUPSD_AUTH_USER
;
1810 else if (!strcasecmp(value
, "default"))
1812 loc
->type
= CUPSD_AUTH_DEFAULT
;
1814 if (loc
->level
== CUPSD_AUTH_ANON
)
1815 loc
->level
= CUPSD_AUTH_USER
;
1818 else if (!strcasecmp(value
, "negotiate"))
1820 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1822 if (loc
->level
== CUPSD_AUTH_ANON
)
1823 loc
->level
= CUPSD_AUTH_USER
;
1825 #endif /* HAVE_GSSAPI */
1828 cupsdLogMessage(CUPSD_LOG_WARN
,
1829 "Unknown authorization type %s on line %d.",
1834 else if (!strcasecmp(line
, "AuthClass"))
1837 * AuthClass anonymous, user, system, group
1840 if (!strcasecmp(value
, "anonymous"))
1842 loc
->type
= CUPSD_AUTH_NONE
;
1843 loc
->level
= CUPSD_AUTH_ANON
;
1845 cupsdLogMessage(CUPSD_LOG_WARN
,
1846 "\"AuthClass %s\" is deprecated; consider removing "
1850 else if (!strcasecmp(value
, "user"))
1852 loc
->level
= CUPSD_AUTH_USER
;
1854 cupsdLogMessage(CUPSD_LOG_WARN
,
1855 "\"AuthClass %s\" is deprecated; consider using "
1856 "\"Require valid-user\" on line %d.",
1859 else if (!strcasecmp(value
, "group"))
1861 loc
->level
= CUPSD_AUTH_GROUP
;
1863 cupsdLogMessage(CUPSD_LOG_WARN
,
1864 "\"AuthClass %s\" is deprecated; consider using "
1865 "\"Require user @groupname\" on line %d.",
1868 else if (!strcasecmp(value
, "system"))
1870 loc
->level
= CUPSD_AUTH_GROUP
;
1872 cupsdAddName(loc
, "@SYSTEM");
1874 cupsdLogMessage(CUPSD_LOG_WARN
,
1875 "\"AuthClass %s\" is deprecated; consider using "
1876 "\"Require user @SYSTEM\" on line %d.",
1881 cupsdLogMessage(CUPSD_LOG_WARN
,
1882 "Unknown authorization class %s on line %d.",
1887 else if (!strcasecmp(line
, "AuthGroupName"))
1889 cupsdAddName(loc
, value
);
1891 cupsdLogMessage(CUPSD_LOG_WARN
,
1892 "\"AuthGroupName %s\" directive is deprecated; consider "
1893 "using \"Require user @%s\" on line %d.",
1894 value
, value
, linenum
);
1896 else if (!strcasecmp(line
, "Require"))
1899 * Apache synonym for AuthClass and AuthGroupName...
1903 * Require valid-user
1904 * Require group names
1905 * Require user names
1908 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1913 if (!strcasecmp(value
, "valid-user") ||
1914 !strcasecmp(value
, "user"))
1915 loc
->level
= CUPSD_AUTH_USER
;
1916 else if (!strcasecmp(value
, "group"))
1917 loc
->level
= CUPSD_AUTH_GROUP
;
1920 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1926 * Get the list of names from the line...
1929 for (value
= valptr
; *value
;)
1931 while (isspace(*value
& 255))
1934 #ifdef HAVE_AUTHORIZATION_H
1935 if (!strncmp(value
, "@AUTHKEY(", 9))
1938 * Grab "@AUTHKEY(name)" value...
1941 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1947 #endif /* HAVE_AUTHORIZATION_H */
1948 if (*value
== '\"' || *value
== '\'')
1951 * Grab quoted name...
1954 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1961 * Grab literal name.
1964 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1970 cupsdAddName(loc
, value
);
1972 for (value
= valptr
; isspace(*value
& 255); value
++);
1975 else if (!strcasecmp(line
, "Satisfy"))
1977 if (!strcasecmp(value
, "all"))
1978 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
1979 else if (!strcasecmp(value
, "any"))
1980 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
1983 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1996 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
1999 static int /* O - FatalErrors bits */
2000 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2002 int fatal
; /* FatalErrors bits */
2003 char value
[1024], /* Value string */
2004 *valstart
, /* Pointer into value */
2005 *valend
; /* End of value */
2009 * Empty FatalErrors line yields NULL pointer...
2013 return (CUPSD_FATAL_NONE
);
2016 * Loop through the value string,...
2019 strlcpy(value
, s
, sizeof(value
));
2021 fatal
= CUPSD_FATAL_NONE
;
2023 for (valstart
= value
; *valstart
;)
2026 * Get the current space/comma-delimited kind name...
2029 for (valend
= valstart
; *valend
; valend
++)
2030 if (isspace(*valend
& 255) || *valend
== ',')
2037 * Add the error to the bitmask...
2040 if (!strcasecmp(valstart
, "all"))
2041 fatal
= CUPSD_FATAL_ALL
;
2042 else if (!strcasecmp(valstart
, "browse"))
2043 fatal
|= CUPSD_FATAL_BROWSE
;
2044 else if (!strcasecmp(valstart
, "-browse"))
2045 fatal
&= ~CUPSD_FATAL_BROWSE
;
2046 else if (!strcasecmp(valstart
, "config"))
2047 fatal
|= CUPSD_FATAL_CONFIG
;
2048 else if (!strcasecmp(valstart
, "-config"))
2049 fatal
&= ~CUPSD_FATAL_CONFIG
;
2050 else if (!strcasecmp(valstart
, "listen"))
2051 fatal
|= CUPSD_FATAL_LISTEN
;
2052 else if (!strcasecmp(valstart
, "-listen"))
2053 fatal
&= ~CUPSD_FATAL_LISTEN
;
2054 else if (!strcasecmp(valstart
, "log"))
2055 fatal
|= CUPSD_FATAL_LOG
;
2056 else if (!strcasecmp(valstart
, "-log"))
2057 fatal
&= ~CUPSD_FATAL_LOG
;
2058 else if (!strcasecmp(valstart
, "permissions"))
2059 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2060 else if (!strcasecmp(valstart
, "-permissions"))
2061 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2062 else if (strcasecmp(valstart
, "none"))
2063 cupsdLogMessage(CUPSD_LOG_ERROR
,
2064 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2066 for (valstart
= valend
; *valstart
; valstart
++)
2067 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2076 * 'parse_groups()' - Parse system group names in a string.
2079 static int /* O - 1 on success, 0 on failure */
2080 parse_groups(const char *s
) /* I - Space-delimited groups */
2082 int status
; /* Return status */
2083 char value
[1024], /* Value string */
2084 *valstart
, /* Pointer into value */
2085 *valend
, /* End of value */
2086 quote
; /* Quote character */
2087 struct group
*group
; /* Group */
2091 * Make a copy of the string and parse out the groups...
2094 strlcpy(value
, s
, sizeof(value
));
2099 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2101 if (*valstart
== '\'' || *valstart
== '\"')
2104 * Scan quoted name...
2107 quote
= *valstart
++;
2109 for (valend
= valstart
; *valend
; valend
++)
2110 if (*valend
== quote
)
2116 * Scan space or comma-delimited name...
2119 for (valend
= valstart
; *valend
; valend
++)
2120 if (isspace(*valend
) || *valend
== ',')
2127 group
= getgrnam(valstart
);
2130 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2131 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2142 while (*valstart
== ',' || isspace(*valstart
))
2151 * 'parse_protocols()' - Parse browse protocols in a string.
2154 static int /* O - Browse protocol bits */
2155 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2157 int protocols
; /* Browse protocol bits */
2158 char value
[1024], /* Value string */
2159 *valstart
, /* Pointer into value */
2160 *valend
; /* End of value */
2164 * Empty protocol line yields NULL pointer...
2171 * Loop through the value string,...
2174 strlcpy(value
, s
, sizeof(value
));
2178 for (valstart
= value
; *valstart
;)
2181 * Get the current space/comma-delimited protocol name...
2184 for (valend
= valstart
; *valend
; valend
++)
2185 if (isspace(*valend
& 255) || *valend
== ',')
2192 * Add the protocol to the bitmask...
2195 if (!strcasecmp(valstart
, "cups"))
2196 protocols
|= BROWSE_CUPS
;
2197 else if (!strcasecmp(valstart
, "slp"))
2198 protocols
|= BROWSE_SLP
;
2199 else if (!strcasecmp(valstart
, "ldap"))
2200 protocols
|= BROWSE_LDAP
;
2201 else if (!strcasecmp(valstart
, "dnssd") ||
2202 !strcasecmp(valstart
, "dns-sd") ||
2203 !strcasecmp(valstart
, "bonjour"))
2204 protocols
|= BROWSE_DNSSD
;
2205 else if (!strcasecmp(valstart
, "lpd"))
2206 protocols
|= BROWSE_LPD
;
2207 else if (!strcasecmp(valstart
, "smb"))
2208 protocols
|= BROWSE_SMB
;
2209 else if (!strcasecmp(valstart
, "all"))
2210 protocols
|= BROWSE_ALL
;
2211 else if (strcasecmp(valstart
, "none"))
2212 cupsdLogMessage(CUPSD_LOG_ERROR
,
2213 "Unknown browse protocol \"%s\" ignored!", valstart
);
2215 for (valstart
= valend
; *valstart
; valstart
++)
2216 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2225 * 'read_configuration()' - Read a configuration file.
2228 static int /* O - 1 on success, 0 on failure */
2229 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2231 int i
; /* Looping var */
2232 int linenum
; /* Current line number */
2233 char line
[HTTP_MAX_BUFFER
],
2234 /* Line from file */
2235 temp
[HTTP_MAX_BUFFER
],
2236 /* Temporary buffer for value */
2237 temp2
[HTTP_MAX_BUFFER
],
2238 /* Temporary buffer 2 for value */
2239 *ptr
, /* Pointer into line/temp */
2240 *value
, /* Pointer to value */
2241 *valueptr
; /* Pointer into value */
2242 int valuelen
; /* Length of value */
2243 cupsd_var_t
const *var
; /* Current variable */
2244 http_addrlist_t
*addrlist
, /* Address list */
2245 *addr
; /* Current address */
2246 unsigned ip
[4], /* Address value */
2247 mask
[4]; /* Netmask value */
2248 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2249 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2250 cupsd_location_t
*location
; /* Browse location */
2251 cups_file_t
*incfile
; /* Include file */
2252 char incname
[1024]; /* Include filename */
2253 struct group
*group
; /* Group */
2257 * Loop through each line in the file...
2262 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2265 * Decode the directive...
2268 if (!strcasecmp(line
, "Include") && value
)
2274 if (value
[0] == '/')
2275 strlcpy(incname
, value
, sizeof(incname
));
2277 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2279 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2280 cupsdLogMessage(CUPSD_LOG_ERROR
,
2281 "Unable to include config file \"%s\" - %s",
2282 incname
, strerror(errno
));
2285 read_configuration(incfile
);
2286 cupsFileClose(incfile
);
2289 else if (!strcasecmp(line
, "<Location") && value
)
2295 linenum
= read_location(fp
, value
, linenum
);
2299 else if (!strcasecmp(line
, "<Policy") && value
)
2305 linenum
= read_policy(fp
, value
, linenum
);
2309 else if (!strcasecmp(line
, "FatalErrors"))
2310 FatalErrors
= parse_fatal_errors(value
);
2311 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2313 JobRetryInterval
= atoi(value
);
2314 cupsdLogMessage(CUPSD_LOG_WARN
,
2315 "FaxRetryInterval is deprecated; use "
2316 "JobRetryInterval on line %d.", linenum
);
2318 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2320 JobRetryLimit
= atoi(value
);
2321 cupsdLogMessage(CUPSD_LOG_WARN
,
2322 "FaxRetryLimit is deprecated; use "
2323 "JobRetryLimit on line %d.", linenum
);
2325 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2327 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2328 #endif /* HAVE_SSL */
2332 * Add listening address(es) to the list...
2335 cupsd_listener_t
*lis
; /* New listeners array */
2339 * Get the address list...
2342 addrlist
= get_address(value
, IPP_PORT
);
2346 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2352 * Add each address...
2355 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2358 * See if this address is already present...
2361 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2363 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2364 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2365 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2370 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2371 cupsdLogMessage(CUPSD_LOG_WARN
,
2372 "Duplicate listen address \"%s\" ignored!", temp
);
2377 * Allocate another listener...
2381 Listeners
= cupsArrayNew(NULL
, NULL
);
2385 cupsdLogMessage(CUPSD_LOG_ERROR
,
2386 "Unable to allocate %s at line %d - %s.",
2387 line
, linenum
, strerror(errno
));
2391 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2393 cupsdLogMessage(CUPSD_LOG_ERROR
,
2394 "Unable to allocate %s at line %d - %s.",
2395 line
, linenum
, strerror(errno
));
2399 cupsArrayAdd(Listeners
, lis
);
2402 * Copy the current address and log it...
2405 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2409 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2410 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2411 #endif /* HAVE_SSL */
2413 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2416 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2417 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2418 ntohs(lis
->address
.ipv6
.sin6_port
));
2420 #endif /* AF_INET6 */
2422 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2423 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2425 #endif /* AF_LOCAL */
2426 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2427 ntohs(lis
->address
.ipv4
.sin_port
));
2434 httpAddrFreeList(addrlist
);
2436 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2439 * Add a browse address to the list...
2442 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2445 if (NumBrowsers
== 0)
2446 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2448 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2452 cupsdLogMessage(CUPSD_LOG_ERROR
,
2453 "Unable to allocate BrowseAddress at line %d - %s.",
2454 linenum
, strerror(errno
));
2459 dira
+= NumBrowsers
;
2461 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2463 if (!strcasecmp(value
, "@LOCAL"))
2466 * Send browse data to all local interfaces...
2469 strcpy(dira
->iface
, "*");
2472 else if (!strncasecmp(value
, "@IF(", 4))
2475 * Send browse data to the named interface...
2478 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2480 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2486 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2489 * Only IPv4 addresses are supported...
2492 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2493 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2498 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2499 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2501 cupsdLogMessage(CUPSD_LOG_INFO
,
2502 "Sending browsing info to %s:%d (IPv4)",
2503 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2508 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2511 httpAddrFreeList(addrlist
);
2514 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2517 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2520 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2523 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2524 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2526 if (location
== NULL
)
2527 cupsdLogMessage(CUPSD_LOG_ERROR
,
2528 "Unable to initialize browse access control list!");
2529 else if (!strncasecmp(value
, "deny", 4))
2530 location
->order_type
= CUPSD_AUTH_ALLOW
;
2531 else if (!strncasecmp(value
, "allow", 5))
2532 location
->order_type
= CUPSD_AUTH_DENY
;
2534 cupsdLogMessage(CUPSD_LOG_ERROR
,
2535 "Unknown BrowseOrder value %s on line %d.",
2538 else if (!strcasecmp(line
, "BrowseProtocols") ||
2539 !strcasecmp(line
, "BrowseLocalProtocols") ||
2540 !strcasecmp(line
, "BrowseRemoteProtocols"))
2543 * "BrowseProtocols name [... name]"
2544 * "BrowseLocalProtocols name [... name]"
2545 * "BrowseRemoteProtocols name [... name]"
2548 int protocols
= parse_protocols(value
);
2552 cupsdLogMessage(CUPSD_LOG_ERROR
,
2553 "Unknown browse protocol \"%s\" on line %d.",
2558 if (strcasecmp(line
, "BrowseLocalProtocols"))
2559 BrowseRemoteProtocols
= protocols
;
2560 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2561 BrowseLocalProtocols
= protocols
;
2563 else if ((!strcasecmp(line
, "BrowseAllow") ||
2564 !strcasecmp(line
, "BrowseDeny")) && value
)
2567 * BrowseAllow [From] host/ip...
2568 * BrowseDeny [From] host/ip...
2571 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2572 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2574 if (location
== NULL
)
2575 cupsdLogMessage(CUPSD_LOG_ERROR
,
2576 "Unable to initialize browse access control list!");
2579 if (!strncasecmp(value
, "from ", 5))
2582 * Strip leading "from"...
2587 while (isspace(*value
))
2592 * Figure out what form the allow/deny address takes:
2603 * nnn.nnn.nnn.nnn/mm
2604 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2607 if (!strcasecmp(value
, "all"))
2613 if (!strcasecmp(line
, "BrowseAllow"))
2614 cupsdAllowIP(location
, zeros
, zeros
);
2616 cupsdDenyIP(location
, zeros
, zeros
);
2618 else if (!strcasecmp(value
, "none"))
2624 if (!strcasecmp(line
, "BrowseAllow"))
2625 cupsdAllowIP(location
, ones
, zeros
);
2627 cupsdDenyIP(location
, ones
, zeros
);
2630 else if (value
[0] == '*' || value
[0] == '.' ||
2631 (!isdigit(value
[0] & 255) && value
[0] != '['))
2633 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2634 #endif /* AF_INET6 */
2637 * Host or domain name...
2640 if (value
[0] == '*')
2643 if (!strcasecmp(line
, "BrowseAllow"))
2644 cupsdAllowHost(location
, value
);
2646 cupsdDenyHost(location
, value
);
2651 * One of many IP address forms...
2654 if (!get_addr_and_mask(value
, ip
, mask
))
2656 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2661 if (!strcasecmp(line
, "BrowseAllow"))
2662 cupsdAllowIP(location
, ip
, mask
);
2664 cupsdDenyIP(location
, ip
, mask
);
2668 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2671 * BrowseRelay [from] source [to] destination
2675 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2677 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2681 cupsdLogMessage(CUPSD_LOG_ERROR
,
2682 "Unable to allocate BrowseRelay at line %d - %s.",
2683 linenum
, strerror(errno
));
2690 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2692 if (!strncasecmp(value
, "from ", 5))
2695 * Strip leading "from"...
2700 while (isspace(*value
))
2705 * Figure out what form the from address takes:
2714 * nnn.nnn.nnn.nnn/mm
2715 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2719 if (value
[0] == '*' || value
[0] == '.' ||
2720 (!isdigit(value
[0] & 255) && value
[0] != '['))
2722 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2723 #endif /* AF_INET6 */
2726 * Host or domain name...
2729 if (value
[0] == '*')
2732 strlcpy(temp
, value
, sizeof(temp
));
2733 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2736 relay
->from
.type
= CUPSD_AUTH_NAME
;
2738 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2740 cupsdLogMessage(CUPSD_LOG_ERROR
,
2741 "Unable to allocate BrowseRelay name at line %d - %s.",
2742 linenum
, strerror(errno
));
2746 relay
->from
.mask
.name
.length
= strlen(temp
);
2751 * One of many IP address forms...
2754 if (!get_addr_and_mask(value
, ip
, mask
))
2756 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2761 relay
->from
.type
= CUPSD_AUTH_IP
;
2762 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2763 sizeof(relay
->from
.mask
.ip
.address
));
2764 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2765 sizeof(relay
->from
.mask
.ip
.netmask
));
2769 * Skip value and trailing whitespace...
2772 for (; *value
; value
++)
2773 if (isspace(*value
))
2776 while (isspace(*value
))
2779 if (!strncasecmp(value
, "to ", 3))
2782 * Strip leading "to"...
2787 while (isspace(*value
))
2792 * Get "to" address and port...
2795 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2798 * Only IPv4 addresses are supported...
2801 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2802 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2807 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2809 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2811 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2812 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2813 relay
->from
.mask
.ip
.address
[0] >> 24,
2814 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2815 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2816 relay
->from
.mask
.ip
.address
[0] & 255,
2817 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2818 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2819 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2820 relay
->from
.mask
.ip
.netmask
[0] & 255);
2822 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2824 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2825 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2830 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2833 httpAddrFreeList(addrlist
);
2837 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
2838 free(relay
->from
.mask
.name
.name
);
2840 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2844 else if (!strcasecmp(line
, "BrowsePoll") && value
)
2847 * BrowsePoll address[:port]
2850 char *portname
; /* Port name */
2851 int portnum
; /* Port number */
2852 struct servent
*service
; /* Service */
2856 * Extract the port name from the address...
2859 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2863 if (isdigit(*portname
& 255))
2864 portnum
= atoi(portname
);
2865 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2866 portnum
= ntohs(service
->s_port
);
2869 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2875 portnum
= ippPort();
2878 * Add the poll entry...
2882 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2884 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2888 cupsdLogMessage(CUPSD_LOG_ERROR
,
2889 "Unable to allocate BrowsePoll at line %d - %s.",
2890 linenum
, strerror(errno
));
2898 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2900 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2901 pollp
->port
= portnum
;
2903 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2906 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
2909 * DefaultAuthType {basic,digest,basicdigest,negotiate}
2912 if (!strcasecmp(value
, "none"))
2913 DefaultAuthType
= CUPSD_AUTH_NONE
;
2914 else if (!strcasecmp(value
, "basic"))
2915 DefaultAuthType
= CUPSD_AUTH_BASIC
;
2916 else if (!strcasecmp(value
, "digest"))
2917 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
2918 else if (!strcasecmp(value
, "basicdigest"))
2919 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
2921 else if (!strcasecmp(value
, "negotiate"))
2922 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
2923 #endif /* HAVE_GSSAPI */
2926 cupsdLogMessage(CUPSD_LOG_WARN
,
2927 "Unknown default authorization type %s on line %d.",
2929 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2934 else if (!strcasecmp(line
, "DefaultEncryption"))
2937 * DefaultEncryption {Never,IfRequested,Required}
2940 if (!value
|| !strcasecmp(value
, "never"))
2941 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2942 else if (!strcasecmp(value
, "required"))
2943 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2944 else if (!strcasecmp(value
, "ifrequested"))
2945 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2948 cupsdLogMessage(CUPSD_LOG_WARN
,
2949 "Unknown default encryption %s on line %d.",
2951 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2955 #endif /* HAVE_SSL */
2957 else if (!strcasecmp(line
, "Krb5Keytab") && value
)
2959 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2962 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2963 gsskrb5_register_acceptor_identity(value
);
2965 cupsdSetEnv("KRB5_KTNAME", value
);
2966 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2968 #endif /* HAVE_GSSAPI */
2969 else if (!strcasecmp(line
, "User") && value
)
2972 * User ID to run as...
2975 if (isdigit(value
[0] & 255))
2977 int uid
= atoi(value
);
2980 cupsdLogMessage(CUPSD_LOG_ERROR
,
2981 "Will not use User 0 as specified on line %d "
2982 "for security reasons. You must use a non-"
2983 "privileged account instead.",
2990 struct passwd
*p
; /* Password information */
2993 p
= getpwnam(value
);
2998 cupsdLogMessage(CUPSD_LOG_ERROR
,
2999 "Will not use User %s (UID=0) as specified on line "
3000 "%d for security reasons. You must use a non-"
3001 "privileged account instead.",
3007 cupsdLogMessage(CUPSD_LOG_ERROR
,
3008 "Unknown User \"%s\" on line %d, ignoring!",
3012 else if (!strcasecmp(line
, "Group") && value
)
3015 * Group ID to run as...
3018 if (isdigit(value
[0]))
3019 Group
= atoi(value
);
3023 group
= getgrnam(value
);
3026 Group
= group
->gr_gid
;
3028 cupsdLogMessage(CUPSD_LOG_ERROR
,
3029 "Unknown Group \"%s\" on line %d, ignoring!",
3033 else if (!strcasecmp(line
, "SystemGroup") && value
)
3036 * SystemGroup (admin) group(s)...
3039 if (!parse_groups(value
))
3040 cupsdLogMessage(CUPSD_LOG_ERROR
,
3041 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3044 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3047 * Do hostname lookups?
3050 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3051 !strcasecmp(value
, "false"))
3052 HostNameLookups
= 0;
3053 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3054 !strcasecmp(value
, "true"))
3055 HostNameLookups
= 1;
3056 else if (!strcasecmp(value
, "double"))
3057 HostNameLookups
= 2;
3059 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3062 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3065 * Amount of logging to do to access log...
3068 if (!strcasecmp(value
, "all"))
3069 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3070 else if (!strcasecmp(value
, "actions"))
3071 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3072 else if (!strcasecmp(value
, "config"))
3073 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3075 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3078 else if (!strcasecmp(line
, "LogLevel") && value
)
3081 * Amount of logging to do to error log...
3084 if (!strcasecmp(value
, "debug2"))
3085 LogLevel
= CUPSD_LOG_DEBUG2
;
3086 else if (!strcasecmp(value
, "debug"))
3087 LogLevel
= CUPSD_LOG_DEBUG
;
3088 else if (!strcasecmp(value
, "info"))
3089 LogLevel
= CUPSD_LOG_INFO
;
3090 else if (!strcasecmp(value
, "notice"))
3091 LogLevel
= CUPSD_LOG_NOTICE
;
3092 else if (!strcasecmp(value
, "warn"))
3093 LogLevel
= CUPSD_LOG_WARN
;
3094 else if (!strcasecmp(value
, "error"))
3095 LogLevel
= CUPSD_LOG_ERROR
;
3096 else if (!strcasecmp(value
, "crit"))
3097 LogLevel
= CUPSD_LOG_CRIT
;
3098 else if (!strcasecmp(value
, "alert"))
3099 LogLevel
= CUPSD_LOG_ALERT
;
3100 else if (!strcasecmp(value
, "emerg"))
3101 LogLevel
= CUPSD_LOG_EMERG
;
3102 else if (!strcasecmp(value
, "none"))
3103 LogLevel
= CUPSD_LOG_NONE
;
3105 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3108 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3111 * Format of printcap file?
3114 if (!strcasecmp(value
, "bsd"))
3115 PrintcapFormat
= PRINTCAP_BSD
;
3116 else if (!strcasecmp(value
, "solaris"))
3117 PrintcapFormat
= PRINTCAP_SOLARIS
;
3119 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3122 else if (!strcasecmp(line
, "ServerTokens") && value
)
3125 * Set the string used for the Server header...
3128 struct utsname plat
; /* Platform info */
3133 if (!strcasecmp(value
, "ProductOnly"))
3134 cupsdSetString(&ServerHeader
, "CUPS");
3135 else if (!strcasecmp(value
, "Major"))
3136 cupsdSetString(&ServerHeader
, "CUPS/1");
3137 else if (!strcasecmp(value
, "Minor"))
3138 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3139 else if (!strcasecmp(value
, "Minimal"))
3140 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3141 else if (!strcasecmp(value
, "OS"))
3142 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3143 else if (!strcasecmp(value
, "Full"))
3144 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3146 else if (!strcasecmp(value
, "None"))
3147 cupsdClearString(&ServerHeader
);
3149 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3152 else if (!strcasecmp(line
, "PassEnv") && value
)
3155 * PassEnv variable [... variable]
3160 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3161 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3164 if (value
[valuelen
])
3166 value
[valuelen
] = '\0';
3170 cupsdSetEnv(value
, NULL
);
3172 for (value
+= valuelen
; *value
; value
++)
3173 if (!isspace(*value
) || *value
!= ',')
3177 else if (!strcasecmp(line
, "SetEnv") && value
)
3180 * SetEnv variable value
3183 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3191 while (isspace(*valueptr
& 255))
3194 cupsdSetEnv(value
, valueptr
);
3197 cupsdLogMessage(CUPSD_LOG_ERROR
,
3198 "Missing value for SetEnv directive on line %d.",
3204 * Find a simple variable in the list...
3207 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3208 if (!strcasecmp(line
, var
->name
))
3214 * Unknown directive! Output an error message and continue...
3218 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3221 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3228 case CUPSD_VARTYPE_INTEGER
:
3230 cupsdLogMessage(CUPSD_LOG_ERROR
,
3231 "Missing integer value for %s on line %d!",
3236 char *units
; /* Units */
3239 n
= strtol(value
, &units
, 0);
3241 if (units
&& *units
)
3243 if (tolower(units
[0] & 255) == 'g')
3244 n
*= 1024 * 1024 * 1024;
3245 else if (tolower(units
[0] & 255) == 'm')
3247 else if (tolower(units
[0] & 255) == 'k')
3249 else if (tolower(units
[0] & 255) == 't')
3254 cupsdLogMessage(CUPSD_LOG_ERROR
,
3255 "Bad negative integer value for %s on line %d!",
3258 *((int *)var
->ptr
) = n
;
3262 case CUPSD_VARTYPE_BOOLEAN
:
3264 cupsdLogMessage(CUPSD_LOG_ERROR
,
3265 "Missing boolean value for %s on line %d!",
3267 else if (!strcasecmp(value
, "true") ||
3268 !strcasecmp(value
, "on") ||
3269 !strcasecmp(value
, "enabled") ||
3270 !strcasecmp(value
, "yes") ||
3272 *((int *)var
->ptr
) = TRUE
;
3273 else if (!strcasecmp(value
, "false") ||
3274 !strcasecmp(value
, "off") ||
3275 !strcasecmp(value
, "disabled") ||
3276 !strcasecmp(value
, "no") ||
3277 !strcasecmp(value
, "0"))
3278 *((int *)var
->ptr
) = FALSE
;
3280 cupsdLogMessage(CUPSD_LOG_ERROR
,
3281 "Unknown boolean value %s on line %d.",
3285 case CUPSD_VARTYPE_PATHNAME
:
3288 cupsdLogMessage(CUPSD_LOG_ERROR
,
3289 "Missing pathname value for %s on line %d!",
3294 if (value
[0] == '/')
3295 strlcpy(temp
, value
, sizeof(temp
));
3297 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3299 if (access(temp
, 0))
3301 cupsdLogMessage(CUPSD_LOG_ERROR
,
3302 "File or directory for \"%s %s\" on line %d "
3303 "does not exist!", line
, value
, linenum
);
3307 case CUPSD_VARTYPE_STRING
:
3308 cupsdSetString((char **)var
->ptr
, value
);
3319 * 'read_location()' - Read a <Location path> definition.
3322 static int /* O - New line number or 0 on error */
3323 read_location(cups_file_t
*fp
, /* I - Configuration file */
3324 char *location
, /* I - Location name/path */
3325 int linenum
) /* I - Current line number */
3327 cupsd_location_t
*loc
, /* New location */
3328 *parent
; /* Parent location */
3329 char line
[HTTP_MAX_BUFFER
],
3331 *value
, /* Value for directive */
3332 *valptr
; /* Pointer into value */
3335 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3338 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3341 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3344 * Decode the directive...
3347 if (!strcasecmp(line
, "</Location>"))
3349 else if (!strcasecmp(line
, "<Limit") ||
3350 !strcasecmp(line
, "<LimitExcept"))
3354 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3355 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3359 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3365 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3370 if (!strcmp(value
, "ALL"))
3371 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3372 else if (!strcmp(value
, "GET"))
3373 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3374 else if (!strcmp(value
, "HEAD"))
3375 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3376 else if (!strcmp(value
, "OPTIONS"))
3377 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3378 else if (!strcmp(value
, "POST"))
3379 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3380 else if (!strcmp(value
, "PUT"))
3381 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3382 else if (!strcmp(value
, "TRACE"))
3383 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3385 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3388 for (value
= valptr
; isspace(*value
& 255); value
++);
3391 if (!strcasecmp(line
, "<LimitExcept"))
3392 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3394 parent
->limit
&= ~loc
->limit
;
3396 else if (!strcasecmp(line
, "</Limit>") ||
3397 !strcasecmp(line
, "</LimitExcept>"))
3399 else if (!parse_aaa(loc
, line
, value
, linenum
))
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Unknown Location directive %s on line %d.",
3404 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3409 cupsdLogMessage(CUPSD_LOG_ERROR
,
3410 "Unexpected end-of-file at line %d while reading location!",
3413 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3418 * 'read_policy()' - Read a <Policy name> definition.
3421 static int /* O - New line number or 0 on error */
3422 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3423 char *policy
, /* I - Location name/path */
3424 int linenum
) /* I - Current line number */
3426 int i
; /* Looping var */
3427 cupsd_policy_t
*pol
; /* Policy */
3428 cupsd_location_t
*op
; /* Policy operation */
3429 int num_ops
; /* Number of IPP operations */
3430 ipp_op_t ops
[100]; /* Operations */
3431 char line
[HTTP_MAX_BUFFER
],
3433 *value
, /* Value for directive */
3434 *valptr
; /* Pointer into value */
3438 * Create the policy...
3441 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3445 * Read from the file...
3451 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3454 * Decode the directive...
3457 if (!strcasecmp(line
, "</Policy>"))
3460 cupsdLogMessage(CUPSD_LOG_WARN
,
3461 "Missing </Limit> before </Policy> on line %d!",
3465 * Verify that we have an explicit policy for CUPS-Get-Document
3466 * (ensures that upgrades do not introduce new security issues...)
3469 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3470 op
->op
== IPP_ANY_OPERATION
)
3472 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3473 op
->op
!= IPP_ANY_OPERATION
)
3476 * Add a new limit for CUPS-Get-Document using the Send-Document
3477 * limit as a template...
3480 cupsdLogMessage(CUPSD_LOG_WARN
,
3481 "No limit for CUPS-Get-Document defined in policy %s "
3482 "- using Send-Document's policy", pol
->name
);
3484 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3490 else if (!strcasecmp(line
, "<Limit") && !op
)
3494 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3495 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3500 * Scan for IPP operation names...
3507 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3512 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3514 if (!strcasecmp(value
, "All"))
3515 ops
[num_ops
] = IPP_ANY_OPERATION
;
3516 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3517 cupsdLogMessage(CUPSD_LOG_ERROR
,
3518 "Bad IPP operation name \"%s\" on line %d!",
3524 cupsdLogMessage(CUPSD_LOG_ERROR
,
3525 "Too many operations listed on line %d!",
3528 for (value
= valptr
; isspace(*value
& 255); value
++);
3532 * If none are specified, apply the policy to all operations...
3537 ops
[0] = IPP_ANY_OPERATION
;
3542 * Add a new policy for the first operation...
3545 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3547 else if (!strcasecmp(line
, "</Limit>") && op
)
3550 * Finish the current operation limit...
3556 * Copy the policy to the other operations...
3559 for (i
= 1; i
< num_ops
; i
++)
3560 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3567 cupsdLogMessage(CUPSD_LOG_ERROR
,
3568 "Missing <Limit ops> directive before %s on line %d.",
3570 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3573 else if (!parse_aaa(op
, line
, value
, linenum
))
3576 cupsdLogMessage(CUPSD_LOG_ERROR
,
3577 "Unknown Policy Limit directive %s on line %d.",
3580 cupsdLogMessage(CUPSD_LOG_ERROR
,
3581 "Unknown Policy directive %s on line %d.",
3584 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3589 cupsdLogMessage(CUPSD_LOG_ERROR
,
3590 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3593 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3598 * End of "$Id: conf.c 7694 2008-06-26 00:23:20Z mike $".